Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the MIT license. See License.txt in the project root for full license information. -->
<Project>
<PropertyGroup>
<VersionPrefix>17.14.13</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<VersionPrefix>17.14.14</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<PackageValidationBaselineVersion>17.13.9</PackageValidationBaselineVersion>
<AssemblyVersion>15.1.0.0</AssemblyVersion>
<PreReleaseVersionLabel>servicing</PreReleaseVersionLabel>
Expand Down
118 changes: 69 additions & 49 deletions src/Tasks/ManifestUtil/ComImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
using System.Globalization;
using System.Resources;
using System.Runtime.InteropServices;
#if RUNTIME_TYPE_NETCORE
using System.Runtime.InteropServices.ComTypes;
#endif
using ComTypes = System.Runtime.InteropServices.ComTypes;
using System.Runtime.Versioning;

#nullable disable
Expand Down Expand Up @@ -55,64 +53,86 @@ public ComImporter(string path, OutputMessageCollection outputMessages, string o
catch (COMException) { }

#pragma warning disable 618
#if RUNTIME_TYPE_NETCORE
ITypeLib tlib = (ITypeLib)obj;
#else
UCOMITypeLib tlib = (UCOMITypeLib)obj;
#endif
ComTypes.ITypeLib tlib = (ComTypes.ITypeLib)obj;
if (tlib != null)
{
IntPtr typeLibAttrPtr = IntPtr.Zero;
tlib.GetLibAttr(out typeLibAttrPtr);
var typeLibAttr = (TYPELIBATTR)Marshal.PtrToStructure(typeLibAttrPtr, typeof(TYPELIBATTR));
tlib.ReleaseTLibAttr(typeLibAttrPtr);
Guid tlbid = typeLibAttr.guid;

tlib.GetDocumentation(-1, out _, out string docString, out _, out string 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));

var comClassList = new List<ComClass>();
int count = tlib.GetTypeInfoCount();
for (int i = 0; i < count; ++i)
try
{
tlib.GetTypeInfoType(i, out TYPEKIND tkind);
if (tkind == TYPEKIND.TKIND_COCLASS)
{
#if RUNTIME_TYPE_NETCORE
tlib.GetTypeInfo(i, out ITypeInfo tinfo);
#else
tlib.GetTypeInfo(i, out UCOMITypeInfo tinfo);
#endif
tlib.GetLibAttr(out typeLibAttrPtr);
var typeLibAttr = (ComTypes.TYPELIBATTR)Marshal.PtrToStructure(typeLibAttrPtr, typeof(ComTypes.TYPELIBATTR));
Guid tlbid = typeLibAttr.guid;

IntPtr tinfoAttrPtr = IntPtr.Zero;
tinfo.GetTypeAttr(out tinfoAttrPtr);
TYPEATTR tinfoAttr = (TYPEATTR)Marshal.PtrToStructure(tinfoAttrPtr, typeof(TYPEATTR));
tinfo.ReleaseTypeAttr(tinfoAttrPtr);
Guid clsid = tinfoAttr.guid;
tlib.GetDocumentation(-1, out _, out string docString, out _, out string helpFile);
string helpdir = Util.FilterNonprintableChars(helpFile); // Path.GetDirectoryName(helpFile);

tlib.GetDocumentation(i, out _, out docString, out _, out helpFile);
string description = Util.FilterNonprintableChars(docString);
TypeLib = new TypeLib(tlbid, new Version(typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum), helpdir, typeLibAttr.lcid, Convert.ToInt32(typeLibAttr.wLibFlags, CultureInfo.InvariantCulture));

ClassInfo info = GetRegisteredClassInfo(clsid);
if (info == null)
var comClassList = new List<ComClass>();
int count = tlib.GetTypeInfoCount();
for (int i = 0; i < count; ++i)
{
tlib.GetTypeInfoType(i, out ComTypes.TYPEKIND tkind);
if (tkind == ComTypes.TYPEKIND.TKIND_COCLASS)
{
continue;
IntPtr tinfoAttrPtr = IntPtr.Zero;
tlib.GetTypeInfo(i, out ComTypes.ITypeInfo tinfo);
try
{
tinfo.GetTypeAttr(out tinfoAttrPtr);
ComTypes.TYPEATTR tinfoAttr = (ComTypes.TYPEATTR)Marshal.PtrToStructure(tinfoAttrPtr, typeof(ComTypes.TYPEATTR));
Guid clsid = tinfoAttr.guid;

tlib.GetDocumentation(i, out _, out docString, out _, 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));
}
finally
{
try
{
if (tinfoAttrPtr != IntPtr.Zero)
{
tinfo.ReleaseTypeAttr(tinfoAttrPtr);
}
Marshal.ReleaseComObject(tinfo);
tinfo = null;
}
// Ignore COM exceptions when releasing type attributes.
catch (COMException) {}
}
}

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;
}
}
if (comClassList.Count > 0)
{
ComClasses = comClassList.ToArray();
Success = true;
}
else
finally
{
outputMessages.AddErrorMessage("GenerateManifest.ComImport", outputDisplayName, _resources.GetString("ComImporter.NoRegisteredClasses"));
Success = false;
try
{
if (typeLibAttrPtr != IntPtr.Zero)
{
tlib.ReleaseTLibAttr(typeLibAttrPtr);
}
Marshal.ReleaseComObject(tlib);
tlib = null;
}
// Ignore COM exceptions when releasing type attributes.
catch (COMException) {}
}
}
else
Expand Down