You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’ve added the API below through an extension trait. Do you think it would make sense to have as inherent methods in this crate? I can send a PR. I’m not sure about the method names, though.
impl<T:Interface>ComPtr<T>{/// For use with APIs that "return" a new COM object through a `*mut *mut c_void` out-parameter.////// # Safety////// `T` must be a COM interface that inherits from `IUnknown`./// If the closure makes the inner pointer non-null,/// it must point to a valid COM object that implements `T`./// Ownership of that object is taken.unsafefnfrom_void_out_param<F>(f:F) -> Result<Self,HRESULT>whereF:FnOnce(*mut*mutc_void) -> HRESULT{Self::from_out_param(|ptr| f(ptr as_))}/// For use with APIs that "return" a new COM object through a `*mut *mut T` out-parameter.////// # Safety////// `T` must be a COM interface that inherits from `IUnknown`./// If the closure makes the inner pointer non-null,/// it must point to a valid COM object that implements `T`./// Ownership of that object is taken.unsafefnfrom_out_param<F>(f:F) -> Result<Self,HRESULT>whereF:FnOnce(*mut*mutT) -> HRESULT{letmut ptr = ptr::null_mut();let status = f(&mut ptr);ifSUCCEEDED(status){Ok(ComPtr::from_raw(ptr))}else{if !ptr.is_null(){let ptr = ptr as*mutIUnknown;(*ptr).Release();}Err(status)}}}
The text was updated successfully, but these errors were encountered:
Interesting approach. I'd suggest checking explicitly against S_OK in from_out_param. COM APIs are known to return S_FALSE sometimes without actually filling in the out param. In that case the caller should probably treat S_FALSE like an error and handle it differently.
That’s not quite the same. That put() method doen’t do the whole “create a (null) pointer, then mutate it through a callback, then check whether return value indicates an error” dance.
I’ve added the API below through an extension trait. Do you think it would make sense to have as inherent methods in this crate? I can send a PR. I’m not sure about the method names, though.
The text was updated successfully, but these errors were encountered: