-
Notifications
You must be signed in to change notification settings - Fork 52
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
winapi interfaces interoperability #180
Comments
Hey! Two small things:
That should get the segfaults solved. Consider using Oh, and a sidenote for @rylev: with winapi being relatively stale, here's hoping it's going to be revived at some point with all interfaces consistently converted to com-rs, which I assume is part of Microsofts effort to provide good Windows support in Rust? |
Hi, here is an updated version of my code that seems to work: let o = MyObject::allocate(10);
let mut i = o.query_interface::<ISomeInterface>().unwrap();
let p_i: *mut ISomeInterface = &mut i;
let p = p_i as *mut c_void;
let p_wi = p as *mut *mut crate::winapi_interfaces::ISomeInterface;
let mut v = 0u8;
(**p_wi).GetValue(&mut v as *mut _);
println!("{}", v); Thank you @MarijnS95 for your help, the I also agree with you on the winapi part and I expressed my concerns on retep998/winapi-rs#867. Regards. |
@DataTriny Awesome, glad I could help! Note that these casts/transmutes are undefined behaviour unless the interface struct is marked as |
@MarijnS95 all the wrapper structs in com-rs are |
@rylev Ah never mind I was looking at the wrong line, the interface is indeed com-rs/macros/support/src/interface/interface.rs Lines 26 to 29 in dd7c97b
Sorry for that. Still, would it make sense to have a way to pull this pointer out without casts/transmutes? @DataTriny In that case it's probably more natural to write |
@MarijnS95 I initially used |
@DataTriny. |
Makes sence. Thanks @rylev for clarifying. |
Hello,
I need to define COM objects that implement COM interfaces that I can pass to functions declared by the winapi crate.
Let's pretend that winapi defines a function and an interface like:
Because winapi doesn't provide an easy way to implement interfaces for objects, I would like to use this crate to help me deal with virtual table management.
So I tried re-defining the interface above using the
com::interface!
macro:And convert it to its winapi counterpart:
But it always fail at runtime:
I have checked that all three pointers point to the same memory address, I have used the
-Zprint-type-sizes
flag to make sure that the memory layout of both versions of the interface are the same.The only differences I can see are the name of both virtual table field (which I don't think matter), and the calling convention of the virtual table functions (
stdcall
for com,system
for winapi, so it could differ).What am I doing wrong? Since I am a beginner with COM, does my conversion code even make sence?
Many thanks.
Best regards.
The text was updated successfully, but these errors were encountered: