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

Add AgileReference #1474

Merged
merged 10 commits into from Feb 2, 2022
Merged

Add AgileReference #1474

merged 10 commits into from Feb 2, 2022

Conversation

Nerixyz
Copy link
Contributor

@Nerixyz Nerixyz commented Jan 28, 2022

This is my attempt at adding an AgileReference to send references across threads, fixes #236.

AgileReference is generic over the type it's wrapping as this ensures the type wrapped remains the same.

In AgileReference::resolve I wasn't too sure how to return the correct type. I made the pointer, IUnknown is wrapping, public for the module, so i can construct a new instance (maybe transmuting would be fine as well, as long as ptr isn't null).
It returns the result of the cast. I can't directly transmute to the T since the size of T isn't known (even though it should always be the size of a pointer).

A better test and documentation is still missing.

@microsoft-cla
Copy link

microsoft-cla bot commented Jan 28, 2022

CLA assistant check
All CLA requirements met.

@kennykerr
Copy link
Collaborator

kennykerr commented Jan 29, 2022

Thanks @Nerixyz! I'll take a closer look soon when I have a moment.

@Nerixyz
Copy link
Contributor Author

Nerixyz commented Feb 1, 2022

I'd like to add an example to the docs but I'm not sure how to do it. Specifically, I'd like to replicate the C#/WinRT example.

This is the example:

use windows::{core::AgileReference, UI::Popups::PopupMenu};

let non_agile = PopupMenu::new().unwrap();
let agile_reference = AgileReference::new(&non_agile).unwrap();

std::thread::spawn(move || {
    let popup = agile_reference.resolve().unwrap();
});

This doesn't compile, because the UI_Popups feature isn't enabled.

@kennykerr
Copy link
Collaborator

kennykerr commented Feb 1, 2022

#1429 discusses the same problem. I'm not yet sure how to resolve that, but let's leave the example for now. I have to think a bit more about how to tackle documentation.

kennykerr
kennykerr previously approved these changes Feb 1, 2022
Copy link
Collaborator

@kennykerr kennykerr left a comment

Looks great - thanks!

@Nerixyz Nerixyz marked this pull request as ready for review Feb 1, 2022
@kennykerr kennykerr merged commit 4fc9e3b into microsoft:master Feb 2, 2022
15 checks passed
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.

3 participants