This repository was archived by the owner on Sep 11, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +17
-15
lines changed Expand file tree Collapse file tree 5 files changed +17
-15
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: ComInterface ;
2
2
3
- use std:: ptr:: NonNull ;
4
-
5
- use std:: ffi:: c_void;
6
3
use std:: marker:: PhantomData ;
4
+ use std:: ptr:: NonNull ;
7
5
8
6
/// A transparent ptr to a COM interface.
9
7
///
@@ -13,7 +11,7 @@ use std::marker::PhantomData;
13
11
///
14
12
/// [`InterfaceRc`]: struct.InterfaceRc.html
15
13
pub struct InterfacePtr < T : ?Sized + ComInterface > {
16
- ptr : NonNull < c_void > ,
14
+ ptr : NonNull < * mut < T as ComInterface > :: VTable > ,
17
15
phantom : PhantomData < T > ,
18
16
}
19
17
@@ -32,7 +30,7 @@ impl<T: ?Sized + ComInterface> InterfacePtr<T> {
32
30
/// # Panics
33
31
///
34
32
/// Panics if `ptr` is null
35
- pub unsafe fn new ( ptr : * mut c_void ) -> InterfacePtr < T > {
33
+ pub unsafe fn new ( ptr : * mut * mut < T as ComInterface > :: VTable ) -> InterfacePtr < T > {
36
34
InterfacePtr {
37
35
ptr : NonNull :: new ( ptr) . expect ( "ptr was null" ) ,
38
36
phantom : PhantomData ,
@@ -41,7 +39,7 @@ impl<T: ?Sized + ComInterface> InterfacePtr<T> {
41
39
42
40
/// Gets the underlying interface ptr. This ptr is only guarnteed to live for
43
41
/// as long as the current `InterfacePtr` is alive.
44
- pub fn as_raw ( & self ) -> * mut c_void {
42
+ pub fn as_raw ( & self ) -> * mut * mut < T as ComInterface > :: VTable {
45
43
self . ptr . as_ptr ( )
46
44
}
47
45
}
Original file line number Diff line number Diff line change @@ -21,9 +21,13 @@ impl<T: ?Sized + ComInterface> InterfaceRc<T> {
21
21
InterfaceRc { ptr }
22
22
}
23
23
24
+ pub unsafe fn from_raw ( ptr : * mut * mut <T as ComInterface >:: VTable ) -> Self {
25
+ Self :: new ( InterfacePtr :: new ( ptr) )
26
+ }
27
+
24
28
/// Gets the underlying interface ptr. This ptr is only guarnteed to live for
25
29
/// as long as the current `InterfaceRc` is alive.
26
- pub fn as_raw ( & self ) -> * mut c_void {
30
+ pub fn as_raw ( & self ) -> * mut * mut < T as ComInterface > :: VTable {
27
31
self . ptr . as_raw ( )
28
32
}
29
33
@@ -41,7 +45,9 @@ impl<T: ?Sized + ComInterface> InterfaceRc<T> {
41
45
return None ;
42
46
}
43
47
assert ! ( !ppv. is_null( ) , "The pointer to the interface returned from a successful call to QueryInterface was null" ) ;
44
- Some ( InterfaceRc :: new ( unsafe { InterfacePtr :: new ( ppv) } ) )
48
+ Some ( InterfaceRc :: new ( unsafe {
49
+ InterfacePtr :: new ( ppv as * mut * mut _ )
50
+ } ) )
45
51
}
46
52
}
47
53
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use std::ffi::c_void;
4
4
5
5
use crate :: {
6
6
interfaces:: iunknown:: { IUnknown , IUnknownVPtr } ,
7
- ComInterface , InterfacePtr , InterfaceRc ,
7
+ ComInterface , InterfaceRc ,
8
8
} ;
9
9
10
10
#[ com_interface( "00000001-0000-0000-c000-000000000046" ) ]
@@ -27,6 +27,6 @@ impl InterfaceRc<dyn IClassFactory> {
27
27
// TODO: decide what failures are possible
28
28
return None ;
29
29
}
30
- Some ( InterfaceRc :: new ( unsafe { InterfacePtr :: new ( ppv) } ) )
30
+ Some ( unsafe { InterfaceRc :: from_raw ( ppv as * mut _ ) } )
31
31
}
32
32
}
Original file line number Diff line number Diff line change @@ -50,9 +50,7 @@ impl ApartmentThreadedRuntime {
50
50
return Err ( hr) ;
51
51
}
52
52
53
- Ok ( InterfaceRc :: new ( unsafe {
54
- InterfacePtr :: new ( class_factory)
55
- } ) )
53
+ Ok ( unsafe { InterfaceRc :: from_raw ( class_factory as * mut * mut _ ) } )
56
54
}
57
55
58
56
pub fn create_instance < T : ComInterface + ?Sized > (
@@ -91,7 +89,7 @@ impl ApartmentThreadedRuntime {
91
89
return Err ( hr) ;
92
90
}
93
91
94
- Ok ( InterfacePtr :: new ( instance) )
92
+ Ok ( InterfacePtr :: new ( instance as * mut _ ) )
95
93
}
96
94
}
97
95
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ pub const COINIT_APARTMENTTHREADED: u32 = 0x2;
21
21
pub const CLSCTX_INPROC_SERVER : u32 = 0x1 ;
22
22
23
23
#[ repr( C ) ]
24
- #[ derive( PartialEq ) ]
24
+ #[ derive( Copy , Clone , PartialEq ) ]
25
25
pub struct IID {
26
26
pub data1 : u32 ,
27
27
pub data2 : u16 ,
You can’t perform that action at this time.
0 commit comments