public static List <KeyValuePair <string, string> > GetclsidsfromTLB(string filename) { List <KeyValuePair <string, string> > ret = new List <KeyValuePair <string, string> >(); try { TLI.TLIApplication tli = new TLI.TLIApplication(); TypeLibInfo ti = tli.TypeLibInfoFromFile(filename); foreach (CoClassInfo cc in ti.CoClasses) { Guid clsid = new Guid(cc.GUID); string progid = ""; ProgIDFromCLSID(ref clsid, out progid); if (progid == null) { progid = ti.Name + "." + cc.Name; } ret.Add(new KeyValuePair <string, string>(clsid.ToString("B"), progid)); } } catch { } return(ret); }
/// <summary> /// Attempts to load the specified type lib and return it's parsed metadata. /// </summary> /// <param name="typeLibPath"></param> /// <returns></returns> bool TryLoadTypeLibFromPathInternal(string path, out TypeLibInfo info) { info = null; if (string.IsNullOrWhiteSpace(path)) { return(false); } Log.LogMessage("TryLoadTypeLibFromPath: {0}", path); ITypeLib typeLib = null; var typeLibPtr = IntPtr.Zero; try { typeLib = LoadTypeLib(path); if (typeLib != null) { typeLib.GetLibAttr(out typeLibPtr); if (typeLibPtr != IntPtr.Zero) { // marshal pointer into struct var ta = (System.Runtime.InteropServices.ComTypes.TYPELIBATTR)Marshal.PtrToStructure(typeLibPtr, typeof(System.Runtime.InteropServices.ComTypes.TYPELIBATTR)); // obtain information from typelib typeLib.GetDocumentation(-1, out var name, out var docString, out var helpContext, out var helpFile); // generate information info = new TypeLibInfo() { Name = name, Description = docString, Guid = ta.guid, MajorVersion = ta.wMajorVerNum, MinorVersion = ta.wMinorVerNum, Lcid = ta.lcid, TypeLibPath = NormalizePath(path), TypeLibFilePath = GetTypeLibFilePath(path), }; // success return(true); } } } catch (COMException e) { Log.LogMessage(MessageImportance.Low, "LoadTypeLib error: {0}; {1}", path, e.Message); } finally { if (typeLib != null && typeLibPtr != IntPtr.Zero) { typeLib.ReleaseTLibAttr(typeLibPtr); } } return(false); }
static void Main(string[] args) { TypeLibInfo tli = new TypeLibInfo(); tli.ContainingFile = @"c:\windows\system32\mshtml.tlb"; foreach (TypeInfo ti in tli.TypeInfos) { Console.WriteLine(ti.Name); // etc... } }
/// <summary> /// Attempts to load the specified type lib and return it's parsed metadata. /// </summary> /// <param name="path"></param> /// <param name="info"></param> /// <returns></returns> bool TryLoadTypeLibFromPath(string path, out TypeLibInfo info) { info = null; if (string.IsNullOrWhiteSpace(path)) { return(false); } // try from cache if (typeLibCache.TryGetValue(path, out var cached)) { info = cached.Item2; return(cached.Item1); } // attempt to load actual path var b = TryLoadTypeLibFromPathInternal(path, out info); typeLibCache[path] = Tuple.Create(b, info); return(b); }
private static void DetectDependencies(TLIApplication typeLibApplication, string fileName, XmlDocument returnDocument) { TypeLibInfo libInfo = typeLibApplication.TypeLibInfoFromFile(fileName); CoClasses classInfos = libInfo.CoClasses; foreach (CoClassInfo itemInfo in classInfos) { DetectMembers(typeLibApplication, fileName, returnDocument, itemInfo.DefaultInterface.Members); Marshal.ReleaseComObject(itemInfo); } Marshal.ReleaseComObject(classInfos); Interfaces faceInfos = libInfo.Interfaces; foreach (InterfaceInfo itemInfo in faceInfos) { DetectMembers(typeLibApplication, fileName, returnDocument, itemInfo.Members); Marshal.ReleaseComObject(itemInfo); } Marshal.ReleaseComObject(faceInfos); Marshal.ReleaseComObject(libInfo); }
private TSRootNamespaceDescription ToNamespace(TypeLibInfo tli) { var coclasses = tli.CoClasses.Cast().ToList(); var @namespace = tli.Name; var ret = new TSRootNamespaceDescription(); tli.Constants.Cast().Select(ToTSEnumDescription).AddRangeTo(ret.Enums); coclasses.Select(ToTSInterfaceDescription).AddInterfacesTo(ret); if (tli.Declarations.Cast().Any()) { //not sure what these are, if they are accessible from JScript //there is one in the Excel object library } if (tli.Unions.Cast().Any()) { //not sure what these are, if they are accessible from JScript //there are a few in the DirectX transforms library } buildActiveX(@namespace, ret, coclasses); var guid = tli.GUID; var tld = TypeLibDetails.FromRegistry.Value.Where(x => x.TypeLibID == guid).OrderByDescending(x => x.MajorVersion).ThenBy(x => x.MinorVersion).FirstOrDefault(); if (tld != null) { ret.Description = tld.Name; ret.MajorVersion = tld.MajorVersion; ret.MinorVersion = tld.MinorVersion; } return(ret); }
static void GatherDataFromTLB(Comobjectstorage comobj) { TLI.TLIApplication tli = new TLI.TLIApplication(); TypeLibInfo ti = tli.TypeLibInfoFromFile(comobj.path); foreach (CoClassInfo cc in ti.CoClasses) { string progid = comobj.progid; if (progid != "") { int k = progid.IndexOf('.'); if (k != -1) { comobj.namesp = progid.Substring(0, k); comobj.name = progid.Substring(k + 1).Replace('.', '_'); } } if (comobj.clsid.ToString("B").ToLower() != cc.GUID.ToLower()) { continue; } comobj.clsid = new Guid(cc.GUID); comobj.wcfclsid = Guid.NewGuid(); foreach (TLI.MemberInfo minf in cc.DefaultInterface.Members) { if (minf.AttributeMask != 0) { continue; } InvokeKinds functype = minf.InvokeKind; if (functype != TLI.InvokeKinds.INVOKE_FUNC && functype != TLI.InvokeKinds.INVOKE_PROPERTYGET && functype != TLI.InvokeKinds.INVOKE_PROPERTYPUT && functype != TLI.InvokeKinds.INVOKE_PROPERTYPUTREF) { continue; } if (functype != TLI.InvokeKinds.INVOKE_FUNC) { Comobjectstorage.classprops prop = comobj.findproperty(minf.Name); if (prop == null) { prop = new Comobjectstorage.classprops(); prop.name = minf.Name; prop.returntype = VarianttoManaged(minf.ReturnType); comobj.props.Add(prop); } if (functype == TLI.InvokeKinds.INVOKE_PROPERTYGET) { prop.bget = true; } else if (functype == TLI.InvokeKinds.INVOKE_PROPERTYPUT || functype == TLI.InvokeKinds.INVOKE_PROPERTYPUTREF) { prop.bset = true; } foreach (TLI.ParameterInfo pmi in minf.Parameters) { Comobjectstorage.paramtr par = new Comobjectstorage.paramtr(); par.name = pmi.Name; par.vartype = VarianttoManaged(pmi.VarTypeInfo); par.bref = false; if (pmi.VarTypeInfo.PointerLevel != 0) { par.bref = true; } (functype == TLI.InvokeKinds.INVOKE_PROPERTYGET ? prop.getpars : prop.setpars).Add(par); } } else { Comobjectstorage.classmtds mtd = new Comobjectstorage.classmtds(); mtd.name = minf.Name; mtd.returntype = VarianttoManaged(minf.ReturnType); foreach (TLI.ParameterInfo pmi in minf.Parameters) { if (pmi.Name == "OptionalArgs" && !bincoptional) { continue; } Comobjectstorage.paramtr par = new Comobjectstorage.paramtr(); par.name = pmi.Name; par.vartype = VarianttoManaged(pmi.VarTypeInfo); par.bref = false; if (pmi.VarTypeInfo.PointerLevel != 0) { par.bref = true; } mtd.pars.Add(par); } comobj.mtds.Add(mtd); } } } }