Skip to content

Commit 4541933

Browse files
AaronRobinsonMSFTdirecthex
authored andcommitted
Update the TypeLib embedding and add comments on API use (#105416)
There is an undocumented semantic of Win32 Resource APIs. The missing semantic is that all resource type/name strings are transparently converted to uppercase when calling any of the Win32 Resource APIs. We don't want to apply this undocumented semantic to the reader/writer API so we document it instead. We are avoiding applying the behavior since ReadyToRun scenarios are designed to be a byte for byte copy of the resource, including name as it was written by other tooling.
1 parent a16097d commit 4541933

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

src/coreclr/tools/Common/Compiler/Win32Resources/ResourceData.UpdateResourceDataModel.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections;
6+
using System.Diagnostics;
67

78
#if HOST_MODEL
89
namespace Microsoft.NET.HostModel.Win32Resources
@@ -26,6 +27,7 @@ private void AddResourceInternal(object name, object type, ushort language, byte
2627
}
2728
else
2829
{
30+
Debug.Assert(type is string);
2931
if (!_resTypeHeadName.TryGetValue((string)type, out resType))
3032
{
3133
resType = new ResType();
@@ -45,6 +47,7 @@ private void AddResourceInternal(object name, object type, ushort language, byte
4547
}
4648
else
4749
{
50+
Debug.Assert(name is string);
4851
if (!resType.NameHeadName.TryGetValue((string)name, out resName))
4952
{
5053
resName = new ResName();
@@ -57,28 +60,30 @@ private void AddResourceInternal(object name, object type, ushort language, byte
5760

5861
private byte[] FindResourceInternal(object name, object type, ushort language)
5962
{
60-
ResType resType = null;
63+
ResType resType;
6164

6265
if (type is ushort)
6366
{
6467
_resTypeHeadID.TryGetValue((ushort)type, out resType);
6568
}
66-
if (type is string)
69+
else
6770
{
71+
Debug.Assert(type is string);
6872
_resTypeHeadName.TryGetValue((string)type, out resType);
6973
}
7074

7175
if (resType == null)
7276
return null;
7377

74-
ResName resName = null;
78+
ResName resName;
7579

7680
if (name is ushort)
7781
{
7882
resType.NameHeadID.TryGetValue((ushort)name, out resName);
7983
}
80-
if (name is string)
84+
else
8185
{
86+
Debug.Assert(name is string);
8287
resType.NameHeadName.TryGetValue((string)name, out resName);
8388
}
8489

src/coreclr/tools/Common/Compiler/Win32Resources/ResourceData.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public ResourceData(Internal.TypeSystem.Ecma.EcmaModule ecmaModule, Func<object,
6060
/// <summary>
6161
/// Find a resource in the resource data
6262
/// </summary>
63+
/// <remarks>
64+
/// The Win32 APIs typcially perform an uppercase transform on string arguments - during add and find.
65+
/// If the resource will be read by Win32 APIs, it is recommended to make the resource name upper case.
66+
/// </remarks>
6367
public byte[] FindResource(string name, string type, ushort language)
6468
{
6569
return FindResourceInternal(name, type, language);
@@ -68,6 +72,10 @@ public byte[] FindResource(string name, string type, ushort language)
6872
/// <summary>
6973
/// Find a resource in the resource data
7074
/// </summary>
75+
/// <remarks>
76+
/// The Win32 APIs typcially perform an uppercase transform on string arguments - during add and find.
77+
/// If the resource will be read by Win32 APIs, it is recommended to make the resource name upper case.
78+
/// </remarks>
7179
public byte[] FindResource(ushort name, string type, ushort language)
7280
{
7381
return FindResourceInternal(name, type, language);
@@ -76,6 +84,10 @@ public byte[] FindResource(ushort name, string type, ushort language)
7684
/// <summary>
7785
/// Find a resource in the resource data
7886
/// </summary>
87+
/// <remarks>
88+
/// The Win32 APIs typcially perform an uppercase transform on string arguments - during add and find.
89+
/// If the resource will be read by Win32 APIs, it is recommended to make the resource name upper case.
90+
/// </remarks>
7991
public byte[] FindResource(string name, ushort type, ushort language)
8092
{
8193
return FindResourceInternal(name, type, language);
@@ -92,16 +104,28 @@ public byte[] FindResource(ushort name, ushort type, ushort language)
92104
/// <summary>
93105
/// Add or update resource
94106
/// </summary>
107+
/// <remarks>
108+
/// The Win32 APIs typcially perform an uppercase transform on string arguments - during add and find.
109+
/// If the resource will be read by Win32 APIs, it is recommended to make the resource name upper case.
110+
/// </remarks>
95111
public void AddResource(string name, string type, ushort language, byte[] data) => AddResourceInternal(name, type, language, data);
96112

97113
/// <summary>
98114
/// Add or update resource
99115
/// </summary>
116+
/// <remarks>
117+
/// The Win32 APIs typcially perform an uppercase transform on string arguments - during add and find.
118+
/// If the resource will be read by Win32 APIs, it is recommended to make the resource name upper case.
119+
/// </remarks>
100120
public void AddResource(string name, ushort type, ushort language, byte[] data) => AddResourceInternal(name, type, language, data);
101121

102122
/// <summary>
103123
/// Add or update resource
104124
/// </summary>
125+
/// <remarks>
126+
/// The Win32 APIs typcially perform an uppercase transform on string arguments - during add and find.
127+
/// If the resource will be read by Win32 APIs, it is recommended to make the resource name upper case.
128+
/// </remarks>
105129
public void AddResource(ushort name, string type, ushort language, byte[] data) => AddResourceInternal(name, type, language, data);
106130

107131
/// <summary>

src/installer/managed/Microsoft.NET.HostModel/ComHost/ComHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void Create(
5757
if (tlbFileBytes.Length == 0)
5858
throw new InvalidTypeLibraryException(typeLibrary.Value);
5959

60-
updater.AddResource(tlbFileBytes, "typelib", (IntPtr)typeLibrary.Key);
60+
updater.AddResource(tlbFileBytes, "TYPELIB", (IntPtr)typeLibrary.Key);
6161
}
6262
catch (FileNotFoundException ex)
6363
{

0 commit comments

Comments
 (0)