Skip to content

Commit 22d9475

Browse files
authored
Merge pull request #1337 from microsoft/fix1332
Fix build break when friendly methods are turned off and IUnknown is generated
2 parents c5a4ec4 + 84f9c6e commit 22d9475

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/Microsoft.Windows.CsWin32/Generator.Com.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ static ExpressionSyntax ThisPointer(PointerTypeSyntax? typedPointer = null)
499499
}
500500

501501
// Add helper methods when appropriate.
502-
if (hasIUnknownMembers)
502+
if (hasIUnknownMembers && this.Options.FriendlyOverloads.Enabled)
503503
{
504504
members.AddRange(this.ExtractMembersFromTemplate("IUnknownHelperMethods"));
505505
}

src/Microsoft.Windows.CsWin32/templates/IUnknownHelperMethods.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
internal unsafe global::Windows.Win32.Foundation.HRESULT QueryInterface<T>(out T* ppv)
44
where T : unmanaged
55
{
6-
var hr = this.QueryInterface(typeof(T).GUID, out void* pv);
6+
Guid guid = typeof(T).GUID;
7+
void* pv;
8+
var hr = this.QueryInterface(&guid, &pv);
79
if (hr.Succeeded)
810
{
911
ppv = (T*)pv;

test/Microsoft.Windows.CsWin32.Tests/COMTests.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,14 @@ a is
457457
}));
458458
}
459459

460-
[Fact]
461-
public void IUnknown_QueryInterfaceGenericHelper()
460+
[Theory, PairwiseData]
461+
public void IUnknown_QueryInterfaceGenericHelper(bool friendlyOverloads)
462462
{
463-
this.generator = this.CreateGenerator(new GeneratorOptions { AllowMarshaling = false });
463+
this.generator = this.CreateGenerator(new GeneratorOptions { AllowMarshaling = false, FriendlyOverloads = new GeneratorOptions.FriendlyOverloadOptions { Enabled = friendlyOverloads } });
464464

465465
this.GenerateApi("IUnknown");
466-
Assert.Contains(this.FindGeneratedMethod("QueryInterface"), m => m.TypeParameterList?.Parameters.Count == 1);
466+
bool matchFound = this.FindGeneratedMethod("QueryInterface").Any(m => m.TypeParameterList?.Parameters.Count == 1);
467+
Assert.Equal(friendlyOverloads, matchFound);
467468
}
468469

469470
[Fact]

0 commit comments

Comments
 (0)