コード例 #1
0
        internal static ComTypeLibDesc GetFromTypeLib(ComTypes.ITypeLib typeLib)
        {
            // check whether we have already loaded this type library
            ComTypes.TYPELIBATTR typeLibAttr = ComRuntimeHelpers.GetTypeAttrForTypeLib(typeLib);
            ComTypeLibDesc       typeLibDesc;

            lock (s_cachedTypeLibDesc)
            {
                if (s_cachedTypeLibDesc.TryGetValue(typeLibAttr.guid, out typeLibDesc))
                {
                    return(typeLibDesc);
                }
            }

            typeLibDesc = new ComTypeLibDesc();

            typeLibDesc.Name = ComRuntimeHelpers.GetNameOfLib(typeLib);
            typeLibDesc._typeLibAttributes = typeLibAttr;

            int countTypes = typeLib.GetTypeInfoCount();

            for (int i = 0; i < countTypes; i++)
            {
                ComTypes.TYPEKIND typeKind;
                typeLib.GetTypeInfoType(i, out typeKind);

                ComTypes.ITypeInfo typeInfo;
                typeLib.GetTypeInfo(i, out typeInfo);
                if (typeKind == ComTypes.TYPEKIND.TKIND_COCLASS)
                {
                    ComTypeClassDesc classDesc = new ComTypeClassDesc(typeInfo, typeLibDesc);
                    typeLibDesc._classes.AddLast(classDesc);
                }
                else if (typeKind == ComTypes.TYPEKIND.TKIND_ENUM)
                {
                    ComTypeEnumDesc enumDesc = new ComTypeEnumDesc(typeInfo, typeLibDesc);
                    typeLibDesc._enums.Add(enumDesc.TypeName, enumDesc);
                }
                else if (typeKind == ComTypes.TYPEKIND.TKIND_ALIAS)
                {
                    ComTypes.TYPEATTR typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);
                    if (typeAttr.tdescAlias.vt == (short)VarEnum.VT_USERDEFINED)
                    {
                        string aliasName, documentation;
                        ComRuntimeHelpers.GetInfoFromType(typeInfo, out aliasName, out documentation);

                        ComTypes.ITypeInfo referencedTypeInfo;
                        typeInfo.GetRefTypeInfo(typeAttr.tdescAlias.lpValue.ToInt32(), out referencedTypeInfo);

                        ComTypes.TYPEATTR referencedTypeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(referencedTypeInfo);
                        ComTypes.TYPEKIND referencedTypeKind = referencedTypeAttr.typekind;

                        if (referencedTypeKind == ComTypes.TYPEKIND.TKIND_ENUM)
                        {
                            ComTypeEnumDesc enumDesc = new ComTypeEnumDesc(referencedTypeInfo, typeLibDesc);
                            typeLibDesc._enums.Add(aliasName, enumDesc);
                        }
                    }
                }
            }

            // cached the typelib using the guid as the dictionary key
            lock (s_cachedTypeLibDesc)
            {
                s_cachedTypeLibDesc.Add(typeLibAttr.guid, typeLibDesc);
            }

            return(typeLibDesc);
        }
コード例 #2
0
 public static extern int LoadTypeLib(
     [In, MarshalAs(UnmanagedType.LPWStr)] string fileName,
     out ComTypes.ITypeLib typeLib);
コード例 #3
0
 public static extern int RegisterTypeLibForUser(
     ComTypes.ITypeLib ptlib,
     [In, MarshalAs(UnmanagedType.LPWStr)] string pwszFullPath,
     [In, MarshalAs(UnmanagedType.LPWStr)] string pwszHelpDir);
コード例 #4
0
 static extern int LoadTypeLib(string fileName, out System.Runtime.InteropServices.ComTypes.ITypeLib typeLib);
コード例 #5
0
 internal static string GetNameOfLib(ComTypes.ITypeLib typeLib)
 {
     typeLib.GetDocumentation(-1, out string name, out string _, out int _, out string _);
     return(name);
 }
コード例 #6
0
 static extern IntPtr LoadTypeLib(string fileName, out ComTypes.ITypeLib typeLib);
コード例 #7
0
 public ComTypeLibrary(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib)
 {
     _typeLib = typeLib;
     _typeLib.GetLibAttr(out _pTypeLibAttr);
     _typeLib.GetDocumentation(-1, out _Name, out _Description, out _HelpContext, out _HelpFile);
 }
コード例 #8
0
 internal TypeLibrary(ComTypes.ITypeLib typeLib, TypeLibraries typeLibraries)
     : this("", typeLib, typeLibraries)
 {
 }
コード例 #9
0
ファイル: ComTypeLibrary.cs プロジェクト: shellscape/Lumen
 public ComTypeLibrary(System.Runtime.InteropServices.ComTypes.ITypeLib typeLib)
 {
     _typeLib = typeLib;
     _typeLib.GetLibAttr(out _pTypeLibAttr);
     _typeLib.GetDocumentation(-1, out _Name, out _Description, out _HelpContext, out _HelpFile);
 }
コード例 #10
0
        internal string GenerateFromActiveXClsid(Guid clsid)
        {
            string      name = @"CLSID\{" + clsid.ToString() + "}";
            RegistryKey key  = Registry.ClassesRoot.OpenSubKey(name);

            if (key == null)
            {
                throw new ArgumentException(System.Design.SR.GetString("AXNotRegistered", new object[] { name.ToString() }));
            }
            System.Runtime.InteropServices.ComTypes.ITypeLib o = null;
            Guid        empty = Guid.Empty;
            RegistryKey key2  = key.OpenSubKey("TypeLib");

            if (key2 != null)
            {
                RegistryKey key3         = key.OpenSubKey("Version");
                short       majorVersion = -1;
                short       minorVersion = -1;
                string      s            = (string)key3.GetValue("");
                int         index        = s.IndexOf('.');
                if (index == -1)
                {
                    majorVersion = short.Parse(s, CultureInfo.InvariantCulture);
                    minorVersion = 0;
                }
                else
                {
                    majorVersion = short.Parse(s.Substring(0, index), CultureInfo.InvariantCulture);
                    minorVersion = short.Parse(s.Substring(index + 1, (s.Length - index) - 1), CultureInfo.InvariantCulture);
                }
                key3.Close();
                object obj2 = key2.GetValue("");
                empty = new Guid((string)obj2);
                key2.Close();
                try
                {
                    o = System.Design.NativeMethods.LoadRegTypeLib(ref empty, majorVersion, minorVersion, Application.CurrentCulture.LCID);
                }
                catch (Exception)
                {
                }
            }
            if (o == null)
            {
                RegistryKey key4 = key.OpenSubKey("InprocServer32");
                if (key4 != null)
                {
                    string typelib = (string)key4.GetValue("");
                    key4.Close();
                    o = System.Design.NativeMethods.LoadTypeLib(typelib);
                }
            }
            key.Close();
            if (o != null)
            {
                try
                {
                    return(this.GenerateFromTypeLibrary((UCOMITypeLib)o, clsid));
                }
                finally
                {
                    Marshal.ReleaseComObject(o);
                }
            }
            throw new ArgumentException(System.Design.SR.GetString("AXNotRegistered", new object[] { name.ToString() }));
        }