internal bool ImportComComponent(string path, OutputMessageCollection outputMessages, string outputDisplayName) { ComImporter importer = new ComImporter(path, outputMessages, outputDisplayName); if (importer.Success) { ArrayList list = new ArrayList(); // Add TypeLib objects from importer... if (_typeLibs != null) { list.AddRange(_typeLibs); } if (importer.TypeLib != null) { list.Add(importer.TypeLib); } _typeLibs = (TypeLib[])list.ToArray(typeof(TypeLib)); // Add ComClass objects from importer... list.Clear(); if (_comClasses != null) { list.AddRange(_comClasses); } if (importer.ComClasses != null) { list.AddRange(importer.ComClasses); } _comClasses = (ComClass[])list.ToArray(typeof(ComClass)); } return(importer.Success); }
internal bool ImportComComponent(string path, OutputMessageCollection outputMessages, string outputDisplayName) { var importer = new ComImporter(path, outputMessages, outputDisplayName); if (importer.Success) { var typeLibs = new List <TypeLib>(); // Add TypeLib objects from importer... if (_typeLibs != null) { typeLibs.AddRange(_typeLibs); } if (importer.TypeLib != null) { typeLibs.Add(importer.TypeLib); } _typeLibs = typeLibs.ToArray(); // Add ComClass objects from importer... var comClasses = new List <ComClass>(); if (_comClasses != null) { comClasses.AddRange(_comClasses); } if (importer.ComClasses != null) { comClasses.AddRange(importer.ComClasses); } _comClasses = comClasses.ToArray(); } return(importer.Success); }
internal bool ImportComComponent(string path, OutputMessageCollection outputMessages, string outputDisplayName) { ComImporter importer = new ComImporter(path, outputMessages, outputDisplayName); if (importer.Success) { ArrayList list = new ArrayList(); if (this.typeLibs != null) { list.AddRange(this.typeLibs); } if (importer.TypeLib != null) { list.Add(importer.TypeLib); } this.typeLibs = (TypeLib[]) list.ToArray(typeof(TypeLib)); list.Clear(); if (this.comClasses != null) { list.AddRange(this.comClasses); } if (importer.ComClasses != null) { list.AddRange(importer.ComClasses); } this.comClasses = (ComClass[]) list.ToArray(typeof(ComClass)); } return importer.Success; }
public ComImporter(string path, OutputMessageCollection outputMessages, string outputDisplayName) { _outputMessages = outputMessages; _outputDisplayName = outputDisplayName; if (NativeMethods.SfcIsFileProtected(IntPtr.Zero, path) != 0) { outputMessages.AddWarningMessage("GenerateManifest.ComImport", outputDisplayName, _resources.GetString("ComImporter.ProtectedFile")); } object obj = null; try { NativeMethods.LoadTypeLibEx(path, NativeMethods.RegKind.RegKind_None, out obj); } catch (COMException) { } #pragma warning disable 618 UCOMITypeLib tlib = (UCOMITypeLib)obj; if (tlib != null) { IntPtr typeLibAttrPtr = IntPtr.Zero; tlib.GetLibAttr(out typeLibAttrPtr); TYPELIBATTR typeLibAttr = (TYPELIBATTR)Marshal.PtrToStructure(typeLibAttrPtr, typeof(TYPELIBATTR)); tlib.ReleaseTLibAttr(typeLibAttrPtr); Guid tlbid = typeLibAttr.guid; string name, docString, helpFile; int helpContext; tlib.GetDocumentation(-1, out name, out docString, out helpContext, out helpFile); string helpdir = Util.FilterNonprintableChars(helpFile); //Path.GetDirectoryName(helpFile); _typeLib = new TypeLib(tlbid, new Version(typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum), helpdir, typeLibAttr.lcid, Convert.ToInt32(typeLibAttr.wLibFlags, CultureInfo.InvariantCulture)); List <ComClass> comClassList = new List <ComClass>(); int count = tlib.GetTypeInfoCount(); for (int i = 0; i < count; ++i) { TYPEKIND tkind; tlib.GetTypeInfoType(i, out tkind); if (tkind == TYPEKIND.TKIND_COCLASS) { UCOMITypeInfo tinfo; tlib.GetTypeInfo(i, out tinfo); IntPtr tinfoAttrPtr = IntPtr.Zero; tinfo.GetTypeAttr(out tinfoAttrPtr); TYPEATTR tinfoAttr = (TYPEATTR)Marshal.PtrToStructure(tinfoAttrPtr, typeof(TYPEATTR)); tinfo.ReleaseTypeAttr(tinfoAttrPtr); Guid clsid = tinfoAttr.guid; string sclsid = clsid.ToString("B"); tlib.GetDocumentation(i, out name, out docString, out helpContext, out helpFile); string description = Util.FilterNonprintableChars(docString); ClassInfo info = GetRegisteredClassInfo(clsid); if (info == null) { continue; } comClassList.Add(new ComClass(tlbid, clsid, info.Progid, info.ThreadingModel, description)); } } if (comClassList.Count > 0) { _comClasses = comClassList.ToArray(); _success = true; } else { outputMessages.AddErrorMessage("GenerateManifest.ComImport", outputDisplayName, _resources.GetString("ComImporter.NoRegisteredClasses")); _success = false; } } else { outputMessages.AddErrorMessage("GenerateManifest.ComImport", outputDisplayName, _resources.GetString("ComImporter.TypeLibraryLoadFailure")); _success = false; } #pragma warning restore 618 }
public ComImporter(string path, OutputMessageCollection outputMessages, string outputDisplayName) { _outputMessages = outputMessages; _outputDisplayName = outputDisplayName; if (NativeMethods.SfcIsFileProtected(IntPtr.Zero, path) != 0) outputMessages.AddWarningMessage("GenerateManifest.ComImport", outputDisplayName, _resources.GetString("ComImporter.ProtectedFile")); object obj = null; try { NativeMethods.LoadTypeLibEx(path, NativeMethods.RegKind.RegKind_None, out obj); } catch (COMException) { } #pragma warning disable 618 UCOMITypeLib tlib = (UCOMITypeLib)obj; if (tlib != null) { IntPtr typeLibAttrPtr = IntPtr.Zero; tlib.GetLibAttr(out typeLibAttrPtr); TYPELIBATTR typeLibAttr = (TYPELIBATTR)Marshal.PtrToStructure(typeLibAttrPtr, typeof(TYPELIBATTR)); tlib.ReleaseTLibAttr(typeLibAttrPtr); Guid tlbid = typeLibAttr.guid; string name, docString, helpFile; int helpContext; tlib.GetDocumentation(-1, out name, out docString, out helpContext, out helpFile); string helpdir = Util.FilterNonprintableChars(helpFile); //Path.GetDirectoryName(helpFile); _typeLib = new TypeLib(tlbid, new Version(typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum), helpdir, typeLibAttr.lcid, Convert.ToInt32(typeLibAttr.wLibFlags, CultureInfo.InvariantCulture)); List<ComClass> comClassList = new List<ComClass>(); int count = tlib.GetTypeInfoCount(); for (int i = 0; i < count; ++i) { TYPEKIND tkind; tlib.GetTypeInfoType(i, out tkind); if (tkind == TYPEKIND.TKIND_COCLASS) { UCOMITypeInfo tinfo; tlib.GetTypeInfo(i, out tinfo); IntPtr tinfoAttrPtr = IntPtr.Zero; tinfo.GetTypeAttr(out tinfoAttrPtr); TYPEATTR tinfoAttr = (TYPEATTR)Marshal.PtrToStructure(tinfoAttrPtr, typeof(TYPEATTR)); tinfo.ReleaseTypeAttr(tinfoAttrPtr); Guid clsid = tinfoAttr.guid; string sclsid = clsid.ToString("B"); tlib.GetDocumentation(i, out name, out docString, out helpContext, out helpFile); string description = Util.FilterNonprintableChars(docString); ClassInfo info = GetRegisteredClassInfo(clsid); if (info == null) continue; comClassList.Add(new ComClass(tlbid, clsid, info.Progid, info.ThreadingModel, description)); } } if (comClassList.Count > 0) { _comClasses = comClassList.ToArray(); _success = true; } else { outputMessages.AddErrorMessage("GenerateManifest.ComImport", outputDisplayName, _resources.GetString("ComImporter.NoRegisteredClasses")); _success = false; } } else { outputMessages.AddErrorMessage("GenerateManifest.ComImport", outputDisplayName, _resources.GetString("ComImporter.TypeLibraryLoadFailure")); _success = false; } #pragma warning restore 618 }
public ComImporter(string path, OutputMessageCollection outputMessages, string outputDisplayName) { this.outputMessages = outputMessages; this.outputDisplayName = outputDisplayName; if (Microsoft.Build.Tasks.Deployment.ManifestUtilities.NativeMethods.SfcIsFileProtected(IntPtr.Zero, path) != 0) { outputMessages.AddWarningMessage("GenerateManifest.ComImport", new string[] { outputDisplayName, this.resources.GetString("ComImporter.ProtectedFile") }); } object typeLib = null; try { Microsoft.Build.Tasks.Deployment.ManifestUtilities.NativeMethods.LoadTypeLibEx(path, Microsoft.Build.Tasks.Deployment.ManifestUtilities.NativeMethods.RegKind.RegKind_None, out typeLib); } catch (COMException) { } UCOMITypeLib lib = (UCOMITypeLib) typeLib; if (lib != null) { string str; string str2; string str3; int num; IntPtr zero = IntPtr.Zero; lib.GetLibAttr(out zero); TYPELIBATTR typelibattr = (TYPELIBATTR) Marshal.PtrToStructure(zero, typeof(TYPELIBATTR)); lib.ReleaseTLibAttr(zero); Guid tlbId = typelibattr.guid; lib.GetDocumentation(-1, out str, out str2, out num, out str3); string helpDirectory = Microsoft.Build.Tasks.Deployment.ManifestUtilities.Util.FilterNonprintableChars(str3); this.typeLib = new Microsoft.Build.Tasks.Deployment.ManifestUtilities.TypeLib(tlbId, new Version(typelibattr.wMajorVerNum, typelibattr.wMinorVerNum), helpDirectory, typelibattr.lcid, Convert.ToInt32(typelibattr.wLibFlags, CultureInfo.InvariantCulture)); List<ComClass> list = new List<ComClass>(); int typeInfoCount = lib.GetTypeInfoCount(); for (int i = 0; i < typeInfoCount; i++) { TYPEKIND typekind; lib.GetTypeInfoType(i, out typekind); if (typekind == TYPEKIND.TKIND_COCLASS) { UCOMITypeInfo info; lib.GetTypeInfo(i, out info); IntPtr ppTypeAttr = IntPtr.Zero; info.GetTypeAttr(out ppTypeAttr); TYPEATTR typeattr = (TYPEATTR) Marshal.PtrToStructure(ppTypeAttr, typeof(TYPEATTR)); info.ReleaseTypeAttr(ppTypeAttr); Guid guid = typeattr.guid; guid.ToString("B"); lib.GetDocumentation(i, out str, out str2, out num, out str3); string description = Microsoft.Build.Tasks.Deployment.ManifestUtilities.Util.FilterNonprintableChars(str2); ClassInfo registeredClassInfo = this.GetRegisteredClassInfo(guid); if (registeredClassInfo != null) { list.Add(new ComClass(tlbId, guid, registeredClassInfo.Progid, registeredClassInfo.ThreadingModel, description)); } } } if (list.Count > 0) { this.comClasses = list.ToArray(); this.success = true; } else { outputMessages.AddErrorMessage("GenerateManifest.ComImport", new string[] { outputDisplayName, this.resources.GetString("ComImporter.NoRegisteredClasses") }); this.success = false; } } else { outputMessages.AddErrorMessage("GenerateManifest.ComImport", new string[] { outputDisplayName, this.resources.GetString("ComImporter.TypeLibraryLoadFailure") }); this.success = false; } }
public ComImporter(string path, OutputMessageCollection outputMessages, string outputDisplayName) { this.outputMessages = outputMessages; this.outputDisplayName = outputDisplayName; if (Microsoft.Build.Tasks.Deployment.ManifestUtilities.NativeMethods.SfcIsFileProtected(IntPtr.Zero, path) != 0) { outputMessages.AddWarningMessage("GenerateManifest.ComImport", new string[] { outputDisplayName, this.resources.GetString("ComImporter.ProtectedFile") }); } object typeLib = null; try { Microsoft.Build.Tasks.Deployment.ManifestUtilities.NativeMethods.LoadTypeLibEx(path, Microsoft.Build.Tasks.Deployment.ManifestUtilities.NativeMethods.RegKind.RegKind_None, out typeLib); } catch (COMException) { } UCOMITypeLib lib = (UCOMITypeLib)typeLib; if (lib != null) { string str; string str2; string str3; int num; IntPtr zero = IntPtr.Zero; lib.GetLibAttr(out zero); TYPELIBATTR typelibattr = (TYPELIBATTR)Marshal.PtrToStructure(zero, typeof(TYPELIBATTR)); lib.ReleaseTLibAttr(zero); Guid tlbId = typelibattr.guid; lib.GetDocumentation(-1, out str, out str2, out num, out str3); string helpDirectory = Microsoft.Build.Tasks.Deployment.ManifestUtilities.Util.FilterNonprintableChars(str3); this.typeLib = new Microsoft.Build.Tasks.Deployment.ManifestUtilities.TypeLib(tlbId, new Version(typelibattr.wMajorVerNum, typelibattr.wMinorVerNum), helpDirectory, typelibattr.lcid, Convert.ToInt32(typelibattr.wLibFlags, CultureInfo.InvariantCulture)); List <ComClass> list = new List <ComClass>(); int typeInfoCount = lib.GetTypeInfoCount(); for (int i = 0; i < typeInfoCount; i++) { TYPEKIND typekind; lib.GetTypeInfoType(i, out typekind); if (typekind == TYPEKIND.TKIND_COCLASS) { UCOMITypeInfo info; lib.GetTypeInfo(i, out info); IntPtr ppTypeAttr = IntPtr.Zero; info.GetTypeAttr(out ppTypeAttr); TYPEATTR typeattr = (TYPEATTR)Marshal.PtrToStructure(ppTypeAttr, typeof(TYPEATTR)); info.ReleaseTypeAttr(ppTypeAttr); Guid guid = typeattr.guid; guid.ToString("B"); lib.GetDocumentation(i, out str, out str2, out num, out str3); string description = Microsoft.Build.Tasks.Deployment.ManifestUtilities.Util.FilterNonprintableChars(str2); ClassInfo registeredClassInfo = this.GetRegisteredClassInfo(guid); if (registeredClassInfo != null) { list.Add(new ComClass(tlbId, guid, registeredClassInfo.Progid, registeredClassInfo.ThreadingModel, description)); } } } if (list.Count > 0) { this.comClasses = list.ToArray(); this.success = true; } else { outputMessages.AddErrorMessage("GenerateManifest.ComImport", new string[] { outputDisplayName, this.resources.GetString("ComImporter.NoRegisteredClasses") }); this.success = false; } } else { outputMessages.AddErrorMessage("GenerateManifest.ComImport", new string[] { outputDisplayName, this.resources.GetString("ComImporter.TypeLibraryLoadFailure") }); this.success = false; } }