From 6e9e448f6a8b0e7afcaa9a93bb41bbb29ea854d4 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Fri, 9 Dec 2022 12:41:23 -0700 Subject: [PATCH 1/2] Fix `hr` local colliding with parameter name --- src/Microsoft.Windows.CsWin32/Generator.Com.cs | 4 ++-- test/Microsoft.Windows.CsWin32.Tests/COMTests.cs | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Windows.CsWin32/Generator.Com.cs b/src/Microsoft.Windows.CsWin32/Generator.Com.cs index f48572f1..033b6a38 100644 --- a/src/Microsoft.Windows.CsWin32/Generator.Com.cs +++ b/src/Microsoft.Windows.CsWin32/Generator.Com.cs @@ -103,8 +103,8 @@ private TypeDeclarationSyntax DeclareInterfaceAsStruct(TypeDefinitionHandle type List 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. diff --git a/test/Microsoft.Windows.CsWin32.Tests/COMTests.cs b/test/Microsoft.Windows.CsWin32.Tests/COMTests.cs index d2243dd4..dcd21371 100644 --- a/test/Microsoft.Windows.CsWin32.Tests/COMTests.cs +++ b/test/Microsoft.Windows.CsWin32.Tests/COMTests.cs @@ -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() { From 1d5df5a14bce44cfba18aff264716c2ae255cb09 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Fri, 9 Dec 2022 12:51:21 -0700 Subject: [PATCH 2/2] Declare PopulateVTable as a `public` method --- src/Microsoft.Windows.CsWin32/Generator.Com.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Windows.CsWin32/Generator.Com.cs b/src/Microsoft.Windows.CsWin32/Generator.Com.cs index 033b6a38..9584f577 100644 --- a/src/Microsoft.Windows.CsWin32/Generator.Com.cs +++ b/src/Microsoft.Windows.CsWin32/Generator.Com.cs @@ -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);