Skip to content

Commit 35157d8

Browse files
authored
Allow for non-HRESULT return types in COM (#1595)
1 parent 1960c00 commit 35157d8

File tree

2 files changed

+10
-7
lines changed
  • crates

2 files changed

+10
-7
lines changed

crates/libs/interface/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ impl Interface {
111111
quote! { #pat }
112112
})
113113
.collect::<Vec<_>>();
114+
let ret = &m.ret;
114115
quote! {
115-
#vis unsafe fn #name(&self, #(#args),*) -> ::windows::core::HRESULT {
116+
#vis unsafe fn #name(&self, #(#args),*) #ret {
116117
(::windows::core::Interface::vtable(self).#name)(::core::mem::transmute_copy(self), #(#params),*)
117118
}
118119
}
@@ -135,9 +136,10 @@ impl Interface {
135136
let name = &m.name;
136137
let docs = &m.docs;
137138
let args = m.gen_args();
139+
let ret = &m.ret;
138140
quote! {
139141
#(#docs)*
140-
unsafe fn #name(&self, #(#args),*) -> ::windows::core::HRESULT;
142+
unsafe fn #name(&self, #(#args),*) #ret;
141143
}
142144
})
143145
.collect::<Vec<_>>();
@@ -181,8 +183,9 @@ impl Interface {
181183
quote! { #pat }
182184
})
183185
.collect::<Vec<_>>();
186+
let ret = &m.ret;
184187
quote! {
185-
unsafe extern "system" fn #name<Identity: ::windows::core::IUnknownImpl, Impl: #trait_name, const OFFSET: isize>(this: *mut ::core::ffi::c_void, #(#args),*) -> ::windows::core::HRESULT {
188+
unsafe extern "system" fn #name<Identity: ::windows::core::IUnknownImpl, Impl: #trait_name, const OFFSET: isize>(this: *mut ::core::ffi::c_void, #(#args),*) #ret {
186189
let this = (this as *mut ::windows::core::RawPtr).offset(OFFSET) as *mut Identity;
187190
let this = (*this).get_impl() as *mut Impl;
188191
(*this).#name(#(#params),*).into()

crates/tests/nightly_interface/tests/com.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ pub unsafe trait ICustomUri: IUnknown {
88
unsafe fn GetPropertyBSTR(&self, property: Uri_PROPERTY, value: *mut BSTR, flags: u32) -> HRESULT;
99
unsafe fn GetPropertyLength(&self) -> HRESULT;
1010
unsafe fn GetPropertyDWORD(&self, property: Uri_PROPERTY, value: *mut u32, flags: u32) -> HRESULT;
11-
unsafe fn HasProperty(&self) -> HRESULT;
11+
unsafe fn HasProperty(&self); // Note: this definition is missing its return value
1212
unsafe fn GetAbsoluteUri(&self) -> HRESULT;
1313
unsafe fn GetAuthority(&self) -> HRESULT;
14-
unsafe fn GetDisplayUri(&self) -> HRESULT;
14+
unsafe fn GetDisplayUri(&self) -> i32;
1515
unsafe fn GetDomain(&self, value: *mut BSTR) -> HRESULT;
1616
// etc
1717
}
@@ -35,7 +35,7 @@ impl ICustomUri_Impl for CustomUri {
3535
*value = 123;
3636
S_OK
3737
}
38-
unsafe fn HasProperty(&self) -> HRESULT {
38+
unsafe fn HasProperty(&self) {
3939
todo!()
4040
}
4141
unsafe fn GetAbsoluteUri(&self) -> HRESULT {
@@ -44,7 +44,7 @@ impl ICustomUri_Impl for CustomUri {
4444
unsafe fn GetAuthority(&self) -> HRESULT {
4545
todo!()
4646
}
47-
unsafe fn GetDisplayUri(&self) -> HRESULT {
47+
unsafe fn GetDisplayUri(&self) -> i32 {
4848
todo!()
4949
}
5050
unsafe fn GetDomain(&self, value: *mut BSTR) -> HRESULT {

0 commit comments

Comments
 (0)