Skip to content

Conversation

@AArnott
Copy link
Member

@AArnott AArnott commented Oct 4, 2022

This change does two things:

  1. Exposes the Vtbl struct itself. This may be useful for CCW generation, although that is outside the scope of CsWin32 (at present, at least.)
  2. Makes the generated code more trimmable by not using the Vtbl struct at all. Each method directly indexes into the vtbl by pointers and then casts the desired pointer to the appropriate unmanaged delegate for invocation.

For example, here is the effective code change:

 internal uint AddRef()
 {
     fixed (ISpellChecker* pThis = &this)
-        return lpVtbl->AddRef_2(pThis);
+        return ((delegate *unmanaged [Stdcall]<IUnknown_unmanaged*,uint>)lpVtbl[1])(pThis);
 }

-private Vtbl* lpVtbl;
+private void** lpVtbl;

-private struct Vtbl
+internal struct Vtbl

This PR has no effect on generated code when allowMarshaling: true.

Closes #668

In particular, while we *may* still generate the vtbl struct itself, we don't use it. Instead, each method directly indexes into the v-table and casts the pointer to the unmanaged delegate type and invokes it.

Closes #668
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-marshaling COM structs and vtbl fields to be replaced with trim-friendly approach

2 participants