private void AddTypeLibAttr(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib)
        {
            if (this.tlbAttrs == null)
            {
                this.tlbAttrs = new ArrayList();
            }
            IntPtr invalidIntPtr = System.Design.NativeMethods.InvalidIntPtr;

            typeLib.GetLibAttr(out invalidIntPtr);
            if (invalidIntPtr != System.Design.NativeMethods.InvalidIntPtr)
            {
                System.Runtime.InteropServices.TYPELIBATTR typelibattr = (System.Runtime.InteropServices.TYPELIBATTR)Marshal.PtrToStructure(invalidIntPtr, typeof(System.Runtime.InteropServices.TYPELIBATTR));
                this.tlbAttrs.Add(typelibattr);
                typeLib.ReleaseTLibAttr(invalidIntPtr);
            }
        }
        internal Assembly GetPrimaryInteropAssembly(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib, TypeLibConverter tlbConverter)
        {
            Assembly assem = this.FindRCW(typeLib);

            if (assem == null)
            {
                IntPtr invalidIntPtr = System.Design.NativeMethods.InvalidIntPtr;
                typeLib.GetLibAttr(out invalidIntPtr);
                if (!(invalidIntPtr != System.Design.NativeMethods.InvalidIntPtr))
                {
                    return(assem);
                }
                System.Runtime.InteropServices.TYPELIBATTR typelibattr = (System.Runtime.InteropServices.TYPELIBATTR)Marshal.PtrToStructure(invalidIntPtr, typeof(System.Runtime.InteropServices.TYPELIBATTR));
                string asmName     = null;
                string asmCodeBase = null;
                try
                {
                    tlbConverter.GetPrimaryInteropAssembly(typelibattr.guid, typelibattr.wMajorVerNum, typelibattr.wMinorVerNum, typelibattr.lcid, out asmName, out asmCodeBase);
                    if ((asmName != null) && (asmCodeBase == null))
                    {
                        try
                        {
                            assem       = Assembly.ReflectionOnlyLoad(asmName);
                            asmCodeBase = this.GetLocalPath(assem.EscapedCodeBase);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else if (asmCodeBase != null)
                    {
                        asmCodeBase = this.GetLocalPath(asmCodeBase);
                        assem       = Assembly.ReflectionOnlyLoadFrom(asmCodeBase);
                    }
                    if (assem != null)
                    {
                        this.AddRCW(typeLib, assem);
                        this.AddReferencedAssembly(asmCodeBase);
                    }
                }
                finally
                {
                    typeLib.ReleaseTLibAttr(invalidIntPtr);
                }
            }
            return(assem);
        }
        public static string GetFileOfTypeLib(ref System.Runtime.InteropServices.TYPELIBATTR tlibattr)
        {
            string path = null;

            path = System.Design.NativeMethods.QueryPathOfRegTypeLib(ref tlibattr.guid, tlibattr.wMajorVerNum, tlibattr.wMinorVerNum, tlibattr.lcid);
            if (path.Length <= 0)
            {
                return(path);
            }
            int index = path.IndexOf('\0');

            if (index > -1)
            {
                path = path.Substring(0, index);
            }
            if (File.Exists(path))
            {
                return(path);
            }
            int length = path.LastIndexOf(Path.DirectorySeparatorChar);

            if (length != -1)
            {
                bool flag = true;
                for (int i = length + 1; i < path.Length; i++)
                {
                    if ((path[i] != '\0') && !char.IsDigit(path[i]))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    path = path.Substring(0, length);
                    if (!File.Exists(path))
                    {
                        path = null;
                    }
                    return(path);
                }
            }
            return(null);
        }
        private static string GetFileOfTypeLib(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib)
        {
            IntPtr invalidIntPtr = System.Design.NativeMethods.InvalidIntPtr;

            typeLib.GetLibAttr(out invalidIntPtr);
            if (invalidIntPtr != System.Design.NativeMethods.InvalidIntPtr)
            {
                System.Runtime.InteropServices.TYPELIBATTR tlibattr = (System.Runtime.InteropServices.TYPELIBATTR)Marshal.PtrToStructure(invalidIntPtr, typeof(System.Runtime.InteropServices.TYPELIBATTR));
                try
                {
                    return(GetFileOfTypeLib(ref tlibattr));
                }
                finally
                {
                    typeLib.ReleaseTLibAttr(invalidIntPtr);
                }
            }
            return(null);
        }
 internal Assembly FindRCW(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib)
 {
     if (this.rcwCache != null)
     {
         IntPtr invalidIntPtr = System.Design.NativeMethods.InvalidIntPtr;
         typeLib.GetLibAttr(out invalidIntPtr);
         try
         {
             if (invalidIntPtr != System.Design.NativeMethods.InvalidIntPtr)
             {
                 System.Runtime.InteropServices.TYPELIBATTR typelibattr = (System.Runtime.InteropServices.TYPELIBATTR)Marshal.PtrToStructure(invalidIntPtr, typeof(System.Runtime.InteropServices.TYPELIBATTR));
                 return((Assembly)this.rcwCache[typelibattr.guid]);
             }
         }
         finally
         {
             typeLib.ReleaseTLibAttr(invalidIntPtr);
         }
     }
     return(null);
 }
        internal void AddRCW(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib, Assembly assem)
        {
            if (this.rcwCache == null)
            {
                this.rcwCache = new Hashtable();
            }
            IntPtr invalidIntPtr = System.Design.NativeMethods.InvalidIntPtr;

            typeLib.GetLibAttr(out invalidIntPtr);
            try
            {
                if (invalidIntPtr != System.Design.NativeMethods.InvalidIntPtr)
                {
                    System.Runtime.InteropServices.TYPELIBATTR typelibattr = (System.Runtime.InteropServices.TYPELIBATTR)Marshal.PtrToStructure(invalidIntPtr, typeof(System.Runtime.InteropServices.TYPELIBATTR));
                    this.rcwCache.Add(typelibattr.guid, assem);
                }
            }
            finally
            {
                typeLib.ReleaseTLibAttr(invalidIntPtr);
            }
        }
Beispiel #7
0
        private void LoadTypeLibrary(string typeLibFile)
        {
            // Load type library via DllImported COM f(x).
            LoadTypeLibEx(typeLibFile, REGKIND.REGKIND_DEFAULT, out theTypeLib);

            // Get a managed version of type lib attributes.
            string typLibStats;
            TYPELIBATTR libAtts = new TYPELIBATTR();
            Type TYPELIBATTRType = libAtts.GetType();
            int structSize = Marshal.SizeOf(TYPELIBATTRType);
            IntPtr ptr = IntPtr.Zero;
            ptr = Marshal.AllocHGlobal(structSize);
            theTypeLib.GetLibAttr(out ptr);
            libAtts = (TYPELIBATTR) Marshal.PtrToStructure(ptr, TYPELIBATTRType);

            // Print out stats and release memory.
            typLibStats = "LIBID: " + libAtts.guid.ToString()
                        + "\nVersion (Major): " + libAtts.wMajorVerNum.ToString()
                        + "\nVersion (Minor): " + libAtts.wMinorVerNum.ToString();
            lblTypeLibStats.Text = typLibStats;
            theTypeLib.ReleaseTLibAttr(ptr);
            Marshal.DestroyStructure(ptr, libAtts.GetType());
        }
Beispiel #8
0
		public static string GetFileOfTypeLib (ref TYPELIBATTR tlibattr)
		{
			throw new NotImplementedException ();
		}
		internal static TypeLibKey GetTypeLibKey(TYPELIBATTR typeLibAttr)
		{
			TypeLibKey typeLibKey = new TypeLibKey(typeLibAttr.guid,
				typeLibAttr.wMajorVerNum + "." + typeLibAttr.wMinorVerNum);
			TraceUtil.WriteLineInfo(null, "TypeLibKey: " + typeLibKey);
			return typeLibKey;
		}