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

Unmarshaled COM 'interface' struct trimmability #706

Merged
merged 2 commits into from
Oct 4, 2022
Merged

Unmarshaled COM 'interface' struct trimmability #706

merged 2 commits into from
Oct 4, 2022

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
@AArnott AArnott enabled auto-merge October 4, 2022 03:45
@AArnott AArnott merged commit 2e5cb71 into main Oct 4, 2022
@AArnott AArnott deleted the comStructs branch October 4, 2022 05:04
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
1 participant