Skip to content

Commit

Permalink
Merge pull request #828 from microsoft/fix751
Browse files Browse the repository at this point in the history
Touch-up CCW generation
  • Loading branch information
AArnott committed Dec 9, 2022
2 parents 7ff965b + 1d5df5a commit d1c2fd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Microsoft.Windows.CsWin32/Generator.Com.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ private TypeDeclarationSyntax DeclareInterfaceAsStruct(TypeDefinitionHandle type
List<QualifiedMethodDefinitionHandle> ccwMethodsToSkip = new();
IdentifierNameSyntax vtblParamName = IdentifierName("vtable");
BlockSyntax populateVTableBody = Block();
IdentifierNameSyntax objectLocal = IdentifierName("@object");
IdentifierNameSyntax hrLocal = IdentifierName("hr");
IdentifierNameSyntax objectLocal = IdentifierName("__object");
IdentifierNameSyntax hrLocal = IdentifierName("__hr");
StatementSyntax returnSOK = ReturnStatement(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, HresultTypeSyntax, IdentifierName("S_OK")));

// It is imperative that we generate methods for all base interfaces as well, ahead of any implemented by *this* interface.
Expand Down Expand Up @@ -456,9 +456,10 @@ void AddCcwThunk(params StatementSyntax[] thunkInvokeAndReturn)

if (ccwThisParameter is not null)
{
// internal static void PopulateVTable(Vtbl* vtable)
// PopulateVTable must be public in order to (implicitly) implement an interface that WinForms declares.
// public static void PopulateVTable(Vtbl* vtable)
MethodDeclarationSyntax populateVtblMethodDecl = MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier("PopulateVTable"))
.AddModifiers(Token(this.Visibility), Token(SyntaxKind.StaticKeyword))
.AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword))
.AddParameterListParameters(Parameter(vtblParamName.Identifier).WithType(PointerType(vtblStructName).WithTrailingTrivia(Space)))
.WithBody(populateVTableBody);
members.Add(populateVtblMethodDecl);
Expand Down
10 changes: 10 additions & 0 deletions test/Microsoft.Windows.CsWin32.Tests/COMTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ public void WinRTInterfaceWithWinRTOutObjectUsesMarshaler()
Assert.Single(this.FindGeneratedType(WinRTCustomMarshalerClass));
}

[Fact]
public void MethodWithHRParameter()
{
this.compilation = this.starterCompilations["net6.0"];
this.generator = this.CreateGenerator(DefaultTestGeneratorOptions with { AllowMarshaling = false });
Assert.True(this.generator.TryGenerate("IFileOpenDialog", CancellationToken.None));
this.CollectGeneratedCode(this.generator);
this.AssertNoDiagnostics();
}

[Fact]
public void ComOutPtrTypedAsOutObject()
{
Expand Down

0 comments on commit d1c2fd7

Please sign in to comment.