コード例 #1
0
ファイル: Form1.cs プロジェクト: rojac07/COM
        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());
        }