// Create a ComReferenceNode via a string to a TLB internal ComReferenceNode(ProjectNode root, string filePath) : base(root) { object otypeLib = null; ComTypes.ITypeLib typeLib = null; IntPtr ptrToLibAttr = IntPtr.Zero; try { LoadTypeLibEx(filePath, RegKind.RegKind_None, out otypeLib); typeLib = (ComTypes.ITypeLib)otypeLib; if (typeLib == null) { throw new ArgumentException(); } ComTypes.TYPELIBATTR typeAttr = new ComTypes.TYPELIBATTR(); typeLib.GetLibAttr(out ptrToLibAttr); typeAttr = (ComTypes.TYPELIBATTR)Marshal.PtrToStructure(ptrToLibAttr, typeAttr.GetType()); // Initialize state this.typeGuid = typeAttr.guid; this.majorVersionNumber = typeAttr.wMajorVerNum.ToString(CultureInfo.InvariantCulture); this.minorVersionNumber = typeAttr.wMinorVerNum.ToString(CultureInfo.InvariantCulture); this.lcid = typeAttr.lcid.ToString(CultureInfo.InvariantCulture); // Check to see if the COM object actually exists. this.SetInstalledFilePath(); // If the value cannot be set throw. if (String.IsNullOrEmpty(this.installedFilePath)) { throw new ArgumentException(); } } finally { if (typeLib != null) { typeLib.ReleaseTLibAttr(ptrToLibAttr); } } }
// Create a ComReferenceNode via a string to a TLB internal ComReferenceNode(ProjectNode root, string filePath) : base(root) { object otypeLib = null; ComTypes.ITypeLib typeLib = null; IntPtr ptrToLibAttr = IntPtr.Zero; try { LoadTypeLibEx( filePath, RegKind.RegKind_None, out otypeLib ); typeLib = (ComTypes.ITypeLib)otypeLib; if (typeLib == null) { throw new ArgumentException(); } ComTypes.TYPELIBATTR typeAttr = new ComTypes.TYPELIBATTR(); typeLib.GetLibAttr(out ptrToLibAttr); typeAttr = (ComTypes.TYPELIBATTR)Marshal.PtrToStructure(ptrToLibAttr, typeAttr.GetType()); // Initialize state this.typeGuid = typeAttr.guid; this.majorVersionNumber = typeAttr.wMajorVerNum.ToString(CultureInfo.InvariantCulture); this.minorVersionNumber = typeAttr.wMinorVerNum.ToString(CultureInfo.InvariantCulture); this.lcid = typeAttr.lcid; // Check to see if the COM object actually exists. this.SetInstalledFilePath(); // If the value cannot be set throw. if (String.IsNullOrEmpty(this.installedFilePath)) { var message = string.Format(SR.GetString(SR.ReferenceCouldNotBeAdded, CultureInfo.CurrentUICulture), filePath); throw new InvalidOperationException(message); } } finally { if (typeLib != null) typeLib.ReleaseTLibAttr(ptrToLibAttr); } }