Skip to content

Commit

Permalink
Merge pull request #827 from microsoft/fix751
Browse files Browse the repository at this point in the history
Bring back Vtbl for IUnknown and IDispatch
  • Loading branch information
AArnott authored Dec 9, 2022
2 parents 187018b + b038ed7 commit 7ff965b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Microsoft.Windows.CsWin32/Generator.Com.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,15 @@ void AddCcwThunk(params StatementSyntax[] thunkInvokeAndReturn)
members.Add(propertyOrMethod);
}

// We expose the vtbl struct to support CCWs.
IdentifierNameSyntax vtblStructName = IdentifierName("Vtbl");
StructDeclarationSyntax? vtblStruct = StructDeclaration(Identifier("Vtbl")).WithTrailingTrivia(Space)
.AddMembers(vtblMembers.ToArray())
.AddModifiers(TokenWithSpace(this.Visibility));
members.Add(vtblStruct);

if (ccwThisParameter is not null)
{
// We expose the vtbl struct to support CCWs
IdentifierNameSyntax vtblStructName = IdentifierName("Vtbl");
StructDeclarationSyntax? vtblStruct = StructDeclaration(Identifier("Vtbl")).WithTrailingTrivia(Space)
.AddMembers(vtblMembers.ToArray())
.AddModifiers(TokenWithSpace(this.Visibility));
members.Add(vtblStruct);

// internal static void PopulateVTable(Vtbl* vtable)
MethodDeclarationSyntax populateVtblMethodDecl = MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier("PopulateVTable"))
.AddModifiers(Token(this.Visibility), Token(SyntaxKind.StaticKeyword))
Expand Down
8 changes: 8 additions & 0 deletions test/GenerationSandbox.Unmarshalled.Tests/GeneratedForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#pragma warning disable CA1812 // dead code
#pragma warning disable CS0168 // Variable is declared but never used

using Windows.Win32;
using Windows.Win32.Foundation;
Expand All @@ -26,4 +27,11 @@ private static unsafe void COMStructsPreserveSig()
hr = o.get_MachineName(out SysFreeStringSafeHandle sh);
o.MachineName = bstr;
}

private static unsafe void IUnknownGetsVtbl()
{
// WinForms needs the v-table to be declared for these base interfaces.
IUnknown.Vtbl v;
IDispatch.Vtbl v2;
}
}

0 comments on commit 7ff965b

Please sign in to comment.