-
Notifications
You must be signed in to change notification settings - Fork 507
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
Dynamic casting to COM implementation #3055
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As discussed offline, we can extend the windows-rs/crates/libs/implement/src/lib.rs Line 132 in 40d35fa
|
kennykerr
changed the title
Dynamic casting to implementation
Dynamic casting to COM implementation
May 24, 2024
kennykerr
reviewed
May 24, 2024
kennykerr
reviewed
May 24, 2024
kennykerr
reviewed
May 24, 2024
kennykerr
reviewed
May 24, 2024
kennykerr
reviewed
May 24, 2024
kennykerr
reviewed
May 24, 2024
dpaoliello
previously approved these changes
May 24, 2024
dpaoliello
reviewed
May 24, 2024
This provides a new feature for COM developers using the windows-rs crate. It allows for safe dynamic casting from IUnknown to an implementation object. It is based on Rust's Any trait. Any type that is marked with #[implement], except for those that contain non-static lifetimes, can be used with dynamic casting. Example: ```rust struct MyApp { ... } fn main() { let my_app = ComObject::new(MyApp { ... }); let iunknown: IUnknown = my_app.to_interface(); do_stuff(&iunknown); } fn do_stuff(unknown: &IUnknown) -> Result<()> { let my_app: ComObject<MyApp> = unknown.cast_object()?; my_app.internal_method(); Ok(()) } ```
sivadeilra
force-pushed
the
user/ardavis/any
branch
from
May 24, 2024 21:57
33b066f
to
692c4b6
Compare
dpaoliello
approved these changes
May 24, 2024
riverar
approved these changes
May 25, 2024
mati865
pushed a commit
to mati865/windows-rs
that referenced
this pull request
Jun 15, 2024
This provides a new feature for COM developers using the windows-rs crate. It allows for safe dynamic casting from IUnknown to an implementation object. It is based on Rust's Any trait. Any type that is marked with #[implement], except for those that contain non-static lifetimes, can be used with dynamic casting. Example: ```rust struct MyApp { ... } fn main() { let my_app = ComObject::new(MyApp { ... }); let iunknown: IUnknown = my_app.to_interface(); do_stuff(&iunknown); } fn do_stuff(unknown: &IUnknown) -> Result<()> { let my_app: ComObject<MyApp> = unknown.cast_object()?; my_app.internal_method(); Ok(()) } ``` Co-authored-by: Arlie Davis <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This provides a new feature for COM developers using the windows-rs crate. It allows for safe dynamic casting from IUnknown to an implementation object. It is based on Rust's Any trait.
Any type that is marked with #[implement], except for those that contain non-static lifetimes, can be used with dynamic casting.
Example: