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; } }