private DeclarationType GetDeclarationType(ITypeLib typeLibrary, int i) { TYPEKIND typeKind; typeLibrary.GetTypeInfoType(i, out typeKind); DeclarationType typeDeclarationType = DeclarationType.Control; // todo: a better default if (typeKind == TYPEKIND.TKIND_ENUM) { typeDeclarationType = DeclarationType.Enumeration; } else if (typeKind == TYPEKIND.TKIND_COCLASS || typeKind == TYPEKIND.TKIND_INTERFACE || typeKind == TYPEKIND.TKIND_ALIAS || typeKind == TYPEKIND.TKIND_DISPATCH) { typeDeclarationType = DeclarationType.ClassModule; } else if (typeKind == TYPEKIND.TKIND_RECORD) { typeDeclarationType = DeclarationType.UserDefinedType; } else if (typeKind == TYPEKIND.TKIND_MODULE) { typeDeclarationType = DeclarationType.ProceduralModule; } return(typeDeclarationType); }
public override void asCommandLine(Dictionary <string, string> args) { _typeLibrary = (string)args["TypeLibrary"]; //_typeLibrary = @"C:\Peach3\ComTest\Release\ComTest.dll"; if (!File.Exists(_typeLibrary)) { throw new PeachException("Error, the TypeLibrary was not found."); } ITypeLib typeLib = null; int ret = LoadTypeLib(_typeLibrary, out typeLib); if (ret != 0) { throw new PeachException("Error loading TypeLibrary. LoadTypeLib returned " + ret); } if (typeLib == null) { throw new PeachException("Error, LoadTypeLib returned a null ITypeLib interface."); } string name; string doc; int helpid; string helpfile; string [] arrClassification = new string [] { "Enum", "Struct", "Module", "Interface", "Dispinterface", "Coclass", "Typedef", "Union" }; typeLib.GetDocumentation(-1, out name, out doc, out helpid, out helpfile); Console.WriteLine(name); ITypeInfo typeInfo = null; for (int cnt = 0; cnt < typeLib.GetTypeInfoCount(); cnt++) { // http://www.codeguru.com/cpp/com-tech/activex/misc/article.php/c2569 Console.WriteLine(" ------------- "); typeInfo = null; typeLib.GetTypeInfo(cnt, out typeInfo); if (typeInfo == null) { Console.WriteLine("typeInfo was null, continue!"); continue; } typeLib.GetDocumentation(cnt, out name, out doc, out helpid, out helpfile); Console.WriteLine(" " + name); System.Runtime.InteropServices.ComTypes.TYPEKIND typeKind; typeLib.GetTypeInfoType(cnt, out typeKind); Console.WriteLine(" " + arrClassification[(int)typeKind]); IntPtr ppTypeAttributes; typeInfo.GetTypeAttr(out ppTypeAttributes); var typeAttributes = (System.Runtime.InteropServices.ComTypes.TYPEATTR)Marshal.PtrToStructure(ppTypeAttributes, typeof(System.Runtime.InteropServices.ComTypes.TYPEATTR)); for (int cntFuncs = 0; cntFuncs < typeAttributes.cFuncs; cntFuncs++) { IntPtr ppFuncDesc; typeInfo.GetFuncDesc(cntFuncs, out ppFuncDesc); var funcDesc = (System.Runtime.InteropServices.ComTypes.FUNCDESC)Marshal.PtrToStructure(ppFuncDesc, typeof(System.Runtime.InteropServices.ComTypes.FUNCDESC)); int memberID = funcDesc.memid; //var elemDesc = funcDesc.elemdescFunc; typeInfo.GetDocumentation(memberID, out name, out doc, out helpid, out helpfile); Console.WriteLine(" " + name); //funcDesc. typeInfo.ReleaseFuncDesc(ppFuncDesc); } for (int cntVars = 0; cntVars < typeAttributes.cVars; cntVars++) { IntPtr ppVarDesc; typeInfo.GetVarDesc(cntVars, out ppVarDesc); var varDesc = (System.Runtime.InteropServices.ComTypes.VARDESC)Marshal.PtrToStructure(ppVarDesc, typeof(System.Runtime.InteropServices.ComTypes.VARDESC)); int memberID = varDesc.memid; typeInfo.GetDocumentation(memberID, out name, out doc, out helpid, out helpfile); Console.WriteLine(" " + name); typeInfo.ReleaseVarDesc(ppVarDesc); } typeInfo.ReleaseTypeAttr(ppTypeAttributes); } }