Skip to content

Commit

Permalink
Merge pull request #1337 from microsoft/fix1332
Browse files Browse the repository at this point in the history
Fix build break when friendly methods are turned off and IUnknown is generated
  • Loading branch information
AArnott authored Jan 22, 2025
2 parents c5a4ec4 + 84f9c6e commit 22d9475
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Microsoft.Windows.CsWin32/Generator.Com.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ static ExpressionSyntax ThisPointer(PointerTypeSyntax? typedPointer = null)
}

// Add helper methods when appropriate.
if (hasIUnknownMembers)
if (hasIUnknownMembers && this.Options.FriendlyOverloads.Enabled)
{
members.AddRange(this.ExtractMembersFromTemplate("IUnknownHelperMethods"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
internal unsafe global::Windows.Win32.Foundation.HRESULT QueryInterface<T>(out T* ppv)
where T : unmanaged
{
var hr = this.QueryInterface(typeof(T).GUID, out void* pv);
Guid guid = typeof(T).GUID;
void* pv;
var hr = this.QueryInterface(&guid, &pv);
if (hr.Succeeded)
{
ppv = (T*)pv;
Expand Down
9 changes: 5 additions & 4 deletions test/Microsoft.Windows.CsWin32.Tests/COMTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,14 @@ a is
}));
}

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

this.GenerateApi("IUnknown");
Assert.Contains(this.FindGeneratedMethod("QueryInterface"), m => m.TypeParameterList?.Parameters.Count == 1);
bool matchFound = this.FindGeneratedMethod("QueryInterface").Any(m => m.TypeParameterList?.Parameters.Count == 1);
Assert.Equal(friendlyOverloads, matchFound);
}

[Fact]
Expand Down

0 comments on commit 22d9475

Please sign in to comment.