Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build break when friendly methods are turned off and IUnknown is generated #1337

Merged
merged 2 commits into from
Jan 22, 2025
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 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