-
Notifications
You must be signed in to change notification settings - Fork 506
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
Simplify use of VARIANT
#539
Comments
Thanks! This depends on #417, which I'll be wrapping up soon. |
Unions are now supported. VARIANT though has union members that need to be dropped. While the union's memory layout is now correct, it doesn't provide support for dropping, so I'll leave this issue open until I add that. |
Wrapping members in ManuallyDrop, as you mention in the other issue, sounds plausible. But in the specific case of VARIANT, should we (additionally) manually |
Yes, the code gen should inject a Drop impl for that. It already does that for BSTR. |
One more request to finish fleshing out |
Also eagerly awaiting this. Will be very helpful for my upcoming implementation of UI Automation provider interfaces in AccessKit. |
I'm getting closer to being able to tackle this. 😉 |
I just implemented Raymond Chen's How can I launch an unelevated process from my elevated process and vice versa using windows-rs, which required VARIANT for the ShellExecute call. It took a while, and I have no idea if I did the ManuallyDrop stuff correctly. Here's the result, with a basic VARIANT helper: https://gist.github.com/lunixbochs/c55f6a3b3184d800f096b52997421113 I would love first-party VARIANT, I think it would've saved me a lot of time. If anyone else needs VARIANT support in the meantime for more than just |
A related issue I've had in this area: propvarutil.h has a bunch of VARIANT helpers but it seems like they're not all present in For example, |
@rgwood See the Remarks on that page and this FAQ entry. 👍
|
VARIANT
data type
Seeing as this is not completed yet I am hoping that someone here could help me out and tell me if I'm headed in the correct direction... here's what I have for creating a boolean VARIANT: use windows::Win32::System::Variant::{VARIANT, VARIANT_0, VARIANT_0_0, VARIANT_0_0_0, VT_BOOL};
use windows::Win32::Foundation::VARIANT_BOOL;
let b = true;
VARIANT {
Anonymous: VARIANT_0 {
Anonymous: ManuallyDrop::new(VARIANT_0_0 {
vt: VT_BOOL,
wReserved1: 0,
wReserved2: 0,
wReserved3: 0,
Anonymous: VARIANT_0_0_0 {
boolVal: VARIANT_BOOL::from(b),
},
})
},
} |
Also... I am getting unsafe access warnings when trying to access the innards of this Variant, like when I need to check the value of something inside. The compiler tells me I need to wrap my code in unsafe blocks. Is there a way around this? How should I be accessing this? More specifically, if I call a COM method that returns a VARIANT that contains an IDispatch, how can I safely unwrap that and do I need to manually dispose of any memory? |
@hcldan
The code you have properly instantiates a
That is correct. Unions in Rust can be initialized from safe Rust, but reading and writing union fields is an inherently unsafe operation. This cannot be changed, and the only way around this would be a safe abstraction (which is what this issue is about).
You cannot touch union fields in safe Rust. An |
In the meantime while |
See #2780 for |
Need support for VARIANT type for use with certain COM objects
From #536
The text was updated successfully, but these errors were encountered: