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
AbiTransferable on complex structures in winapi crate #197
Comments
This is an issue I came across as well. I ended up making a really quick and dirty #[repr(transparent)]
#[derive(Copy, Clone, Debug)]
struct AbiWrapper<T: Clone>(T);
unsafe impl<T: Clone> com::AbiTransferable for AbiWrapper<T> {
type Abi = T;
fn get_abi(&self) -> Self::Abi {
self.0.clone()
}
fn set_abi(&mut self) -> *mut Self::Abi {
&mut self.0
}
} I'm sure someone else can polish this into something more correct and polished. For completeness, here's the com::interfaces! {
#[uuid("40CD37D4-C756-4B0C-8C6F-BDDFEEB13B50")]
unsafe interface IChangeEventHandler: IUnknown {
fn HandlePropertyChangedEvent(
&self,
sender: *mut std::ffi::c_void,
propertyid: AbiWrapper<UIA_PROPERTY_ID>,
newvalue: AbiWrapper<VARIANT>,
) -> ::windows::core::HRESULT;
}
}
com::class! {
pub class EventHandler: IChangeEventHandler {}
impl IChangeEventHandler for EventHandler {
fn HandlePropertyChangedEvent(&self, _sender: *mut std::ffi::c_void, _propertyid: AbiWrapper<UIA_PROPERTY_ID>, newvalue: AbiWrapper<VARIANT>) -> windows::core::HRESULT {
let new_scroll_value = unsafe { newvalue.0.Anonymous.Anonymous.Anonymous.dblVal };
tracing::debug!("scroll event: {}", new_scroll_value);
windows::core::Result::Ok(()).into()
}
}
} |
are you sure? Defining your own interface in the same way the generator does (if you cannot produce a |
This has been supported for years. 😀 |
@MarijnS95 @kennykerr sorry y'all, I just found about #[windows_implement::implement(IUIAutomationPropertyChangedEventHandler)]
struct ScrollEventHandler {
/* fields */
}
impl IUIAutomationPropertyChangedEventHandler_Impl for ScrollEventHandler {
fn HandlePropertyChangedEvent(
&self,
sender: Option<&IUIAutomationElement>,
propertyid: UIA_PROPERTY_ID,
newvalue: &VARIANT,
) -> windows::core::Result<()> {
/* impl */
}
} I found out about One thing I don't understand is, I was under the impression that COM instances must be heap allocated and pinned in memory. The The safety docs for the |
Exactly, ran into this while writing the above reply and filed an issue for it: microsoft/windows-rs#2694.
Perhaps there's nothing happening to the contents of these boxes that would make the pointer move around? |
I'm trying to build something that interfaces with DirectShow at the moment, and when describing the needed interfaces, I need a lot of types like
LPCWSTR
.winapi
comes in handy by defining these types so I don't have to construct them myself. I'm running into problems with some of the types though, e.g.winapi::shared::ntdef::LARGE_INTEGER
. This type is not just a simple alias of a core type, thereforecom
requires it to beAbiTransferable
, which is not implemented onLARGE_INTEGER
.What is the best method to get those types to work with
com
, ideally without rewriting them?Thanks in advance for any feedback you can provide :)
The text was updated successfully, but these errors were encountered: