KEMBAR78
Use `Ref` and `OutRef` for C++ delegates by kennykerr · Pull Request #3447 · microsoft/windows-rs · GitHub
Skip to content

Conversation

@kennykerr
Copy link
Collaborator

This fixes the issue of C++ delegates (C++ function pointer/callback types) are generated with parameters that assume ownership is passed into the function. This is fine for sys-style bindings where all types are copyable but not so for regular bindings where some times might require ownership or lifetime management. That's exactly what Ref and OutRef handle so that's what these delegates now use for their parameters.

A somewhat contrived test is provided that implements PFNGETACTIVATIONFACTORY to verify that such delegates can be both implemented and called in Rust. This highlighted a limitation in the fact that Ref now has no lifetime parameter (#3433 #3435) and thus makes it unsafe to construct on the call side. This is unfortunate, so I'll rethink Ref and see if we can reintroduce the lifetime for cases where this needs to be called safely.

Fixes: #3446

@kennykerr kennykerr merged commit 68b029e into master Jan 15, 2025
75 checks passed
@kennykerr kennykerr deleted the cpp-delegate-params branch January 15, 2025 19:47
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.

windows-bindgen should use Ref for certain delegate parameters

1 participant