Skip to content

Commit 4fd41a2

Browse files
committed
Make from_fn infer pointer type
1 parent be241c5 commit 4fd41a2

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/com.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::fmt::{Debug, Error as FmtError, Formatter};
77
use std::mem::forget;
88
use std::ops::Deref;
99
use std::ptr::{null_mut, NonNull};
10-
use winapi::ctypes::c_void;
1110
use winapi::um::unknwnbase::IUnknown;
1211
use winapi::shared::guiddef::GUID;
1312
use winapi::shared::winerror::HRESULT;
@@ -43,7 +42,6 @@ macro_rules! com_ptr_from_fn {
4342
|$(($guid:pat, $ptr:ident)),+ $(,)?| $init:expr
4443
) => {{
4544
use winapi::Interface;
46-
use winapi::ctypes::c_void;
4745
use winapi::shared::guiddef::GUID;
4846

4947
// hack to get the GUID through type inference
@@ -61,7 +59,7 @@ macro_rules! com_ptr_from_fn {
6159
let result: winapi::shared::winerror::HRESULT = {
6260
$(
6361
let $guid = &$ptr.guid();
64-
let $ptr = &mut *(&mut ($ptr.0) as *mut *mut _ as *mut *mut c_void);
62+
let $ptr = &mut *(&mut ($ptr.0) as *mut *mut _ as *mut *mut _);
6563
)+
6664
(|| $init)()
6765
};
@@ -118,10 +116,10 @@ impl<T> ComPtr<T> {
118116
///
119117
/// If you're calling a COM function that generates multiple COM objects, use the
120118
/// [`com_ptr_from_fn!`](../macro.com_ptr_from_fn.html) macro.
121-
pub unsafe fn from_fn<F>(fun: F) -> Result<ComPtr<T>, HRESULT>
119+
pub unsafe fn from_fn<F, P>(fun: F) -> Result<ComPtr<T>, HRESULT>
122120
where
123121
T: Interface,
124-
F: FnOnce(&GUID, &mut *mut c_void) -> HRESULT
122+
F: FnOnce(&GUID, &mut *mut P) -> HRESULT
125123
{
126124
match com_ptr_from_fn!(|(guid, ptr)| fun(guid, ptr)) {
127125
Ok((p,)) => Ok(p),

0 commit comments

Comments
 (0)