diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 5c32f2bb35..a923845bfc 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -227,6 +227,10 @@ jobs: run: cargo clippy -p test_noexcept - name: Clippy test_not_dll run: cargo clippy -p test_not_dll + - name: Clippy test_overloads + run: cargo clippy -p test_overloads + - name: Clippy test_overloads_client + run: cargo clippy -p test_overloads_client - name: Clippy test_query_signature run: cargo clippy -p test_query_signature - name: Clippy test_readme diff --git a/.github/workflows/raw-dylib.yml b/.github/workflows/raw-dylib.yml index d0b70a1601..fb348cac2b 100644 --- a/.github/workflows/raw-dylib.yml +++ b/.github/workflows/raw-dylib.yml @@ -256,14 +256,18 @@ jobs: run: cargo test -p test_noexcept --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_not_dll run: cargo test -p test_not_dll --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_overloads + run: cargo test -p test_overloads --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_overloads_client + run: cargo test -p test_overloads_client --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_query_signature run: cargo test -p test_query_signature --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Clean + run: cargo clean - name: Test test_readme run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_ref_params run: cargo test -p test_ref_params --target ${{ matrix.target }} ${{ matrix.etc }} - - name: Clean - run: cargo clean - name: Test test_reference run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_reference_client @@ -360,12 +364,12 @@ jobs: run: cargo test -p windows_i686_gnu --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows_i686_gnullvm run: cargo test -p windows_i686_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Clean + run: cargo clean - name: Test windows_i686_msvc run: cargo test -p windows_i686_msvc --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows_x86_64_gnu run: cargo test -p windows_x86_64_gnu --target ${{ matrix.target }} ${{ matrix.etc }} - - name: Clean - run: cargo clean - name: Test windows_x86_64_gnullvm run: cargo test -p windows_x86_64_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows_x86_64_msvc diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 883a679220..8b97bdb925 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -253,14 +253,18 @@ jobs: run: cargo test -p test_noexcept --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_not_dll run: cargo test -p test_not_dll --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_overloads + run: cargo test -p test_overloads --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_overloads_client + run: cargo test -p test_overloads_client --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_query_signature run: cargo test -p test_query_signature --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Clean + run: cargo clean - name: Test test_readme run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_ref_params run: cargo test -p test_ref_params --target ${{ matrix.target }} ${{ matrix.etc }} - - name: Clean - run: cargo clean - name: Test test_reference run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_reference_client @@ -357,12 +361,12 @@ jobs: run: cargo test -p windows_i686_gnu --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows_i686_gnullvm run: cargo test -p windows_i686_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Clean + run: cargo clean - name: Test windows_i686_msvc run: cargo test -p windows_i686_msvc --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows_x86_64_gnu run: cargo test -p windows_x86_64_gnu --target ${{ matrix.target }} ${{ matrix.etc }} - - name: Clean - run: cargo clean - name: Test windows_x86_64_gnullvm run: cargo test -p windows_x86_64_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows_x86_64_msvc diff --git a/crates/libs/bindgen/src/filter.rs b/crates/libs/bindgen/src/filter.rs index 6666e4d863..6173e774b3 100644 --- a/crates/libs/bindgen/src/filter.rs +++ b/crates/libs/bindgen/src/filter.rs @@ -4,6 +4,7 @@ use super::*; pub struct Filter(Vec<(String, bool)>); impl Filter { + #[track_caller] pub fn new(reader: &Reader, include: &[&str], exclude: &[&str]) -> Self { let mut rules = vec![]; @@ -68,6 +69,7 @@ impl Filter { } } +#[track_caller] fn push_filter(reader: &Reader, rules: &mut Vec<(String, bool)>, filter: &str, include: bool) { if reader.contains_key(filter) { rules.push((filter.to_string(), include)); diff --git a/crates/libs/bindgen/src/method_names.rs b/crates/libs/bindgen/src/method_names.rs index cf4cc6de4a..31319d1fd5 100644 --- a/crates/libs/bindgen/src/method_names.rs +++ b/crates/libs/bindgen/src/method_names.rs @@ -36,8 +36,15 @@ fn method_def_special_name(row: MethodDef) -> String { } else { if let Some(attribute) = row.find_attribute("OverloadAttribute") { for (_, arg) in attribute.args() { - if let Value::Str(name) = arg { - return name.to_string(); + if let Value::Str(overload) = arg { + // Detect generated overload and revert back to original name. + if let Some(suffix) = overload.strip_prefix(name) { + if suffix.parse::().is_ok() { + return name.to_string(); + } + } + + return overload.to_string(); } } } diff --git a/crates/libs/bindgen/src/types/cpp_interface.rs b/crates/libs/bindgen/src/types/cpp_interface.rs index 3da2deb783..df2dd22d99 100644 --- a/crates/libs/bindgen/src/types/cpp_interface.rs +++ b/crates/libs/bindgen/src/types/cpp_interface.rs @@ -3,7 +3,7 @@ use super::*; #[derive(Clone, Debug)] pub enum CppMethodOrName { Method(CppMethod), - Name(&'static str), + Name(MethodDef), } #[derive(Clone, Debug, Hash, PartialEq, Eq)] @@ -38,7 +38,7 @@ impl CppInterface { if method.dependencies.included(writer.config) { CppMethodOrName::Method(method) } else { - CppMethodOrName::Name(method.def.name()) + CppMethodOrName::Name(method.def) } }) .collect() @@ -104,8 +104,8 @@ impl CppInterface { } } } - CppMethodOrName::Name(name) => { - let name = to_ident(name); + CppMethodOrName::Name(method) => { + let name = names.add(*method); quote! { #name: usize, } } }); @@ -256,8 +256,8 @@ impl CppInterface { quote! { #name: #name::, } } } - CppMethodOrName::Name(name) => { - let name = to_ident(name); + CppMethodOrName::Name(method) => { + let name = names.add(*method); quote! { #name: 0, } } }) diff --git a/crates/libs/bindgen/src/types/interface.rs b/crates/libs/bindgen/src/types/interface.rs index ddb8873ab8..381f0bd548 100644 --- a/crates/libs/bindgen/src/types/interface.rs +++ b/crates/libs/bindgen/src/types/interface.rs @@ -12,7 +12,7 @@ pub enum InterfaceKind { #[derive(Clone, Debug)] pub enum MethodOrName { Method(Method), - Name(&'static str), + Name(MethodDef), } #[derive(Clone, Debug)] @@ -61,7 +61,7 @@ impl Interface { if method.dependencies.included(writer.config) { MethodOrName::Method(method) } else { - MethodOrName::Name(method.def.name()) + MethodOrName::Name(method.def) } }) .collect() @@ -120,8 +120,8 @@ impl Interface { } } } - MethodOrName::Name(name) => { - let name = to_ident(name); + MethodOrName::Name(method) => { + let name = virtual_names.add(*method); quote! { #name: usize, } } }); @@ -373,8 +373,8 @@ impl Interface { let name = names.add(method.def); quote! { #name: #name::<#(#generics,)* Identity, OFFSET>, } } - MethodOrName::Name(name) => { - let name = to_ident(name); + MethodOrName::Name(method) => { + let name = names.add(*method); quote! { #name: 0, } } }) diff --git a/crates/libs/windows/src/Windows/ApplicationModel/Chat/mod.rs b/crates/libs/windows/src/Windows/ApplicationModel/Chat/mod.rs index 07986ad2b4..6d9f7e891b 100644 --- a/crates/libs/windows/src/Windows/ApplicationModel/Chat/mod.rs +++ b/crates/libs/windows/src/Windows/ApplicationModel/Chat/mod.rs @@ -1234,11 +1234,11 @@ impl ChatMessageStore { (windows_core::Interface::vtable(this).GetMessageAsync)(windows_core::Interface::as_raw(this), core::mem::transmute_copy(localchatmessageid), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) } } - pub fn GetMessageReader1(&self) -> windows_core::Result { + pub fn GetMessageReader(&self) -> windows_core::Result { let this = self; unsafe { let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).GetMessageReader1)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) + (windows_core::Interface::vtable(this).GetMessageReader)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) } } pub fn GetMessageReader2(&self, recenttimelimit: super::super::Foundation::TimeSpan) -> windows_core::Result { @@ -2497,7 +2497,7 @@ pub struct IChatMessageStore_Vtbl { pub DeleteMessageAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, pub DownloadMessageAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, pub GetMessageAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, - pub GetMessageReader1: unsafe extern "system" fn(*mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, + pub GetMessageReader: unsafe extern "system" fn(*mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, pub GetMessageReader2: unsafe extern "system" fn(*mut core::ffi::c_void, super::super::Foundation::TimeSpan, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, pub MarkMessageReadAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, pub RetrySendMessageAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, diff --git a/crates/libs/windows/src/Windows/Networking/ServiceDiscovery/Dnssd/mod.rs b/crates/libs/windows/src/Windows/Networking/ServiceDiscovery/Dnssd/mod.rs index dc85a64bf5..066534d38e 100644 --- a/crates/libs/windows/src/Windows/Networking/ServiceDiscovery/Dnssd/mod.rs +++ b/crates/libs/windows/src/Windows/Networking/ServiceDiscovery/Dnssd/mod.rs @@ -140,14 +140,14 @@ impl DnssdServiceInstance { } } #[cfg(feature = "Networking_Sockets")] - pub fn RegisterStreamSocketListenerAsync1(&self, socket: P0) -> windows_core::Result> + pub fn RegisterStreamSocketListenerAsync(&self, socket: P0) -> windows_core::Result> where P0: windows_core::Param, { let this = self; unsafe { let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).RegisterStreamSocketListenerAsync1)(windows_core::Interface::as_raw(this), socket.param().abi(), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) + (windows_core::Interface::vtable(this).RegisterStreamSocketListenerAsync)(windows_core::Interface::as_raw(this), socket.param().abi(), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) } } #[cfg(all(feature = "Networking_Connectivity", feature = "Networking_Sockets"))] @@ -163,14 +163,14 @@ impl DnssdServiceInstance { } } #[cfg(feature = "Networking_Sockets")] - pub fn RegisterDatagramSocketAsync1(&self, socket: P0) -> windows_core::Result> + pub fn RegisterDatagramSocketAsync(&self, socket: P0) -> windows_core::Result> where P0: windows_core::Param, { let this = self; unsafe { let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).RegisterDatagramSocketAsync1)(windows_core::Interface::as_raw(this), socket.param().abi(), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) + (windows_core::Interface::vtable(this).RegisterDatagramSocketAsync)(windows_core::Interface::as_raw(this), socket.param().abi(), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) } } #[cfg(all(feature = "Networking_Connectivity", feature = "Networking_Sockets"))] @@ -425,17 +425,17 @@ pub struct IDnssdServiceInstance_Vtbl { #[cfg(not(feature = "Foundation_Collections"))] TextAttributes: usize, #[cfg(feature = "Networking_Sockets")] - pub RegisterStreamSocketListenerAsync1: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, + pub RegisterStreamSocketListenerAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, #[cfg(not(feature = "Networking_Sockets"))] - RegisterStreamSocketListenerAsync1: usize, + RegisterStreamSocketListenerAsync: usize, #[cfg(all(feature = "Networking_Connectivity", feature = "Networking_Sockets"))] pub RegisterStreamSocketListenerAsync2: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, #[cfg(not(all(feature = "Networking_Connectivity", feature = "Networking_Sockets")))] RegisterStreamSocketListenerAsync2: usize, #[cfg(feature = "Networking_Sockets")] - pub RegisterDatagramSocketAsync1: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, + pub RegisterDatagramSocketAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, #[cfg(not(feature = "Networking_Sockets"))] - RegisterDatagramSocketAsync1: usize, + RegisterDatagramSocketAsync: usize, #[cfg(all(feature = "Networking_Connectivity", feature = "Networking_Sockets"))] pub RegisterDatagramSocketAsync2: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, #[cfg(not(all(feature = "Networking_Connectivity", feature = "Networking_Sockets")))] diff --git a/crates/libs/windows/src/Windows/UI/Input/Inking/mod.rs b/crates/libs/windows/src/Windows/UI/Input/Inking/mod.rs index fab68e19d3..494ccf9e7c 100644 --- a/crates/libs/windows/src/Windows/UI/Input/Inking/mod.rs +++ b/crates/libs/windows/src/Windows/UI/Input/Inking/mod.rs @@ -150,9 +150,9 @@ pub struct IInkManager_Vtbl { pub ProcessPointerUp: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut super::super::super::Foundation::Rect) -> windows_core::HRESULT, pub SetDefaultDrawingAttributes: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void) -> windows_core::HRESULT, #[cfg(feature = "Foundation_Collections")] - pub RecognizeAsync2: unsafe extern "system" fn(*mut core::ffi::c_void, InkRecognitionTarget, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, + pub RecognizeAsync: unsafe extern "system" fn(*mut core::ffi::c_void, InkRecognitionTarget, *mut *mut core::ffi::c_void) -> windows_core::HRESULT, #[cfg(not(feature = "Foundation_Collections"))] - RecognizeAsync2: usize, + RecognizeAsync: usize, } windows_core::imp::define_interface!(IInkModelerAttributes, IInkModelerAttributes_Vtbl, 0xbad31f27_0cd9_4bfd_b6f3_9e03ba8d7454); impl windows_core::RuntimeType for IInkModelerAttributes { @@ -1749,11 +1749,11 @@ impl InkManager { unsafe { (windows_core::Interface::vtable(this).SetDefaultDrawingAttributes)(windows_core::Interface::as_raw(this), drawingattributes.param().abi()).ok() } } #[cfg(feature = "Foundation_Collections")] - pub fn RecognizeAsync2(&self, recognitiontarget: InkRecognitionTarget) -> windows_core::Result>> { + pub fn RecognizeAsync(&self, recognitiontarget: InkRecognitionTarget) -> windows_core::Result>> { let this = self; unsafe { let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).RecognizeAsync2)(windows_core::Interface::as_raw(this), recognitiontarget, &mut result__).and_then(|| windows_core::Type::from_abi(result__)) + (windows_core::Interface::vtable(this).RecognizeAsync)(windows_core::Interface::as_raw(this), recognitiontarget, &mut result__).and_then(|| windows_core::Type::from_abi(result__)) } } pub fn SetDefaultRecognizer(&self, recognizer: P0) -> windows_core::Result<()> @@ -1764,7 +1764,7 @@ impl InkManager { unsafe { (windows_core::Interface::vtable(this).SetDefaultRecognizer)(windows_core::Interface::as_raw(this), recognizer.param().abi()).ok() } } #[cfg(feature = "Foundation_Collections")] - pub fn RecognizeAsync(&self, strokecollection: P0, recognitiontarget: InkRecognitionTarget) -> windows_core::Result>> + pub fn RecognizeAsync2(&self, strokecollection: P0, recognitiontarget: InkRecognitionTarget) -> windows_core::Result>> where P0: windows_core::Param, { diff --git a/crates/tests/bindgen/src/interface_generic.rs b/crates/tests/bindgen/src/interface_generic.rs index e771cc1bdb..36be4a75d9 100644 --- a/crates/tests/bindgen/src/interface_generic.rs +++ b/crates/tests/bindgen/src/interface_generic.rs @@ -122,7 +122,7 @@ impl IAsyncInfo_Vtbl { Self { base__: windows_core::IInspectable_Vtbl::new::(), Id: Id::, - get_Status: 0, + Status: 0, ErrorCode: ErrorCode::, Cancel: Cancel::, Close: Close::, @@ -136,7 +136,7 @@ impl IAsyncInfo_Vtbl { pub struct IAsyncInfo_Vtbl { pub base__: windows_core::IInspectable_Vtbl, pub Id: unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32) -> windows_core::HRESULT, - get_Status: usize, + Status: usize, pub ErrorCode: unsafe extern "system" fn( *mut core::ffi::c_void, *mut windows_core::HRESULT, @@ -269,8 +269,8 @@ impl IAsyncOperation_Vtbl IAsyncOperation, OFFSET, >(), - put_Completed: 0, - get_Completed: 0, + SetCompleted: 0, + Completed: 0, GetResults: GetResults::, TResult: core::marker::PhantomData::, } @@ -285,8 +285,8 @@ where TResult: windows_core::RuntimeType + 'static, { pub base__: windows_core::IInspectable_Vtbl, - put_Completed: usize, - get_Completed: usize, + SetCompleted: usize, + Completed: usize, pub GetResults: unsafe extern "system" fn( *mut core::ffi::c_void, *mut windows_core::AbiType, diff --git a/crates/tests/bindgen/src/interface_required.rs b/crates/tests/bindgen/src/interface_required.rs index 7ce9bb76cb..542ff32be4 100644 --- a/crates/tests/bindgen/src/interface_required.rs +++ b/crates/tests/bindgen/src/interface_required.rs @@ -89,8 +89,8 @@ impl IAsyncAction_Vtbl { } Self { base__: windows_core::IInspectable_Vtbl::new::(), - put_Completed: 0, - get_Completed: 0, + SetCompleted: 0, + Completed: 0, GetResults: GetResults::, } } @@ -101,8 +101,8 @@ impl IAsyncAction_Vtbl { #[repr(C)] pub struct IAsyncAction_Vtbl { pub base__: windows_core::IInspectable_Vtbl, - put_Completed: usize, - get_Completed: usize, + SetCompleted: usize, + Completed: usize, pub GetResults: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, } windows_core::imp::define_interface!( @@ -221,7 +221,7 @@ impl IAsyncInfo_Vtbl { Self { base__: windows_core::IInspectable_Vtbl::new::(), Id: Id::, - get_Status: 0, + Status: 0, ErrorCode: ErrorCode::, Cancel: Cancel::, Close: Close::, @@ -235,7 +235,7 @@ impl IAsyncInfo_Vtbl { pub struct IAsyncInfo_Vtbl { pub base__: windows_core::IInspectable_Vtbl, pub Id: unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32) -> windows_core::HRESULT, - get_Status: usize, + Status: usize, pub ErrorCode: unsafe extern "system" fn( *mut core::ffi::c_void, *mut windows_core::HRESULT, diff --git a/crates/tests/bindgen/src/interface_required_sys.rs b/crates/tests/bindgen/src/interface_required_sys.rs index 7959994429..2782da361a 100644 --- a/crates/tests/bindgen/src/interface_required_sys.rs +++ b/crates/tests/bindgen/src/interface_required_sys.rs @@ -11,8 +11,8 @@ pub const IID_IAsyncAction: windows_sys::core::GUID = #[repr(C)] pub struct IAsyncAction_Vtbl { pub base__: windows_sys::core::IInspectable_Vtbl, - put_Completed: usize, - get_Completed: usize, + SetCompleted: usize, + Completed: usize, pub GetResults: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_sys::core::HRESULT, } pub const IID_IAsyncInfo: windows_sys::core::GUID = @@ -22,7 +22,7 @@ pub struct IAsyncInfo_Vtbl { pub base__: windows_sys::core::IInspectable_Vtbl, pub Id: unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32) -> windows_sys::core::HRESULT, - get_Status: usize, + Status: usize, pub ErrorCode: unsafe extern "system" fn( *mut core::ffi::c_void, *mut windows_sys::core::HRESULT, diff --git a/crates/tests/bindgen/src/interface_required_with_method.rs b/crates/tests/bindgen/src/interface_required_with_method.rs index 5873a5a2ce..9c339c7f51 100644 --- a/crates/tests/bindgen/src/interface_required_with_method.rs +++ b/crates/tests/bindgen/src/interface_required_with_method.rs @@ -116,8 +116,8 @@ impl IAsyncAction_Vtbl { } Self { base__: windows_core::IInspectable_Vtbl::new::(), - put_Completed: 0, - get_Completed: 0, + SetCompleted: 0, + Completed: 0, GetResults: GetResults::, } } @@ -128,8 +128,8 @@ impl IAsyncAction_Vtbl { #[repr(C)] pub struct IAsyncAction_Vtbl { pub base__: windows_core::IInspectable_Vtbl, - put_Completed: usize, - get_Completed: usize, + SetCompleted: usize, + Completed: usize, pub GetResults: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, } windows_core::imp::define_interface!( diff --git a/crates/tests/bindgen/src/interface_required_with_method_sys.rs b/crates/tests/bindgen/src/interface_required_with_method_sys.rs index f85e379af3..d02343e13e 100644 --- a/crates/tests/bindgen/src/interface_required_with_method_sys.rs +++ b/crates/tests/bindgen/src/interface_required_with_method_sys.rs @@ -20,8 +20,8 @@ pub const IID_IAsyncAction: windows_sys::core::GUID = #[repr(C)] pub struct IAsyncAction_Vtbl { pub base__: windows_sys::core::IInspectable_Vtbl, - put_Completed: usize, - get_Completed: usize, + SetCompleted: usize, + Completed: usize, pub GetResults: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_sys::core::HRESULT, } pub const IID_IAsyncInfo: windows_sys::core::GUID = diff --git a/crates/tests/bindgen/src/reference_async_action.rs b/crates/tests/bindgen/src/reference_async_action.rs index 7ce9bb76cb..542ff32be4 100644 --- a/crates/tests/bindgen/src/reference_async_action.rs +++ b/crates/tests/bindgen/src/reference_async_action.rs @@ -89,8 +89,8 @@ impl IAsyncAction_Vtbl { } Self { base__: windows_core::IInspectable_Vtbl::new::(), - put_Completed: 0, - get_Completed: 0, + SetCompleted: 0, + Completed: 0, GetResults: GetResults::, } } @@ -101,8 +101,8 @@ impl IAsyncAction_Vtbl { #[repr(C)] pub struct IAsyncAction_Vtbl { pub base__: windows_core::IInspectable_Vtbl, - put_Completed: usize, - get_Completed: usize, + SetCompleted: usize, + Completed: usize, pub GetResults: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, } windows_core::imp::define_interface!( @@ -221,7 +221,7 @@ impl IAsyncInfo_Vtbl { Self { base__: windows_core::IInspectable_Vtbl::new::(), Id: Id::, - get_Status: 0, + Status: 0, ErrorCode: ErrorCode::, Cancel: Cancel::, Close: Close::, @@ -235,7 +235,7 @@ impl IAsyncInfo_Vtbl { pub struct IAsyncInfo_Vtbl { pub base__: windows_core::IInspectable_Vtbl, pub Id: unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32) -> windows_core::HRESULT, - get_Status: usize, + Status: usize, pub ErrorCode: unsafe extern "system" fn( *mut core::ffi::c_void, *mut windows_core::HRESULT, diff --git a/crates/tests/bindgen/src/reference_async_action_reference_type.rs b/crates/tests/bindgen/src/reference_async_action_reference_type.rs index 5dc3c64eb2..ad1602389a 100644 --- a/crates/tests/bindgen/src/reference_async_action_reference_type.rs +++ b/crates/tests/bindgen/src/reference_async_action_reference_type.rs @@ -89,8 +89,8 @@ impl IAsyncAction_Vtbl { } Self { base__: windows_core::IInspectable_Vtbl::new::(), - put_Completed: 0, - get_Completed: 0, + SetCompleted: 0, + Completed: 0, GetResults: GetResults::, } } @@ -101,7 +101,7 @@ impl IAsyncAction_Vtbl { #[repr(C)] pub struct IAsyncAction_Vtbl { pub base__: windows_core::IInspectable_Vtbl, - put_Completed: usize, - get_Completed: usize, + SetCompleted: usize, + Completed: usize, pub GetResults: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, } diff --git a/crates/tests/bindgen/src/reference_async_info_no_status.rs b/crates/tests/bindgen/src/reference_async_info_no_status.rs index b83ce5804a..9ade187c0b 100644 --- a/crates/tests/bindgen/src/reference_async_info_no_status.rs +++ b/crates/tests/bindgen/src/reference_async_info_no_status.rs @@ -122,7 +122,7 @@ impl IAsyncInfo_Vtbl { Self { base__: windows_core::IInspectable_Vtbl::new::(), Id: Id::, - get_Status: 0, + Status: 0, ErrorCode: ErrorCode::, Cancel: Cancel::, Close: Close::, @@ -136,7 +136,7 @@ impl IAsyncInfo_Vtbl { pub struct IAsyncInfo_Vtbl { pub base__: windows_core::IInspectable_Vtbl, pub Id: unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32) -> windows_core::HRESULT, - get_Status: usize, + Status: usize, pub ErrorCode: unsafe extern "system" fn( *mut core::ffi::c_void, *mut windows_core::HRESULT, diff --git a/crates/tests/bindgen/src/reference_dependency_flat.rs b/crates/tests/bindgen/src/reference_dependency_flat.rs index 55cc603d97..255a5f7363 100644 --- a/crates/tests/bindgen/src/reference_dependency_flat.rs +++ b/crates/tests/bindgen/src/reference_dependency_flat.rs @@ -150,7 +150,7 @@ impl IMemoryBufferReference_Vtbl { base__: windows_core::IInspectable_Vtbl::new::( ), Capacity: Capacity::, - add_Closed: 0, + Closed: 0, RemoveClosed: RemoveClosed::, } } @@ -163,7 +163,7 @@ pub struct IMemoryBufferReference_Vtbl { pub base__: windows_core::IInspectable_Vtbl, pub Capacity: unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32) -> windows_core::HRESULT, - add_Closed: usize, + Closed: usize, pub RemoveClosed: unsafe extern "system" fn(*mut core::ffi::c_void, i64) -> windows_core::HRESULT, } diff --git a/crates/tests/bindgen/src/reference_dependency_full.rs b/crates/tests/bindgen/src/reference_dependency_full.rs index bfc4768db4..19bdd60cdb 100644 --- a/crates/tests/bindgen/src/reference_dependency_full.rs +++ b/crates/tests/bindgen/src/reference_dependency_full.rs @@ -159,7 +159,7 @@ pub mod Windows { OFFSET, >(), Capacity: Capacity::, - add_Closed: 0, + Closed: 0, RemoveClosed: RemoveClosed::, } } @@ -174,7 +174,7 @@ pub mod Windows { *mut core::ffi::c_void, *mut u32, ) -> windows_core::HRESULT, - add_Closed: usize, + Closed: usize, pub RemoveClosed: unsafe extern "system" fn(*mut core::ffi::c_void, i64) -> windows_core::HRESULT, } diff --git a/crates/tests/bindgen/src/reference_dependency_skip_root.rs b/crates/tests/bindgen/src/reference_dependency_skip_root.rs index bfc4768db4..19bdd60cdb 100644 --- a/crates/tests/bindgen/src/reference_dependency_skip_root.rs +++ b/crates/tests/bindgen/src/reference_dependency_skip_root.rs @@ -159,7 +159,7 @@ pub mod Windows { OFFSET, >(), Capacity: Capacity::, - add_Closed: 0, + Closed: 0, RemoveClosed: RemoveClosed::, } } @@ -174,7 +174,7 @@ pub mod Windows { *mut core::ffi::c_void, *mut u32, ) -> windows_core::HRESULT, - add_Closed: usize, + Closed: usize, pub RemoveClosed: unsafe extern "system" fn(*mut core::ffi::c_void, i64) -> windows_core::HRESULT, } diff --git a/crates/tests/bindgen/src/struct_with_generic.rs b/crates/tests/bindgen/src/struct_with_generic.rs index dada4c8ef0..fbacc95008 100644 --- a/crates/tests/bindgen/src/struct_with_generic.rs +++ b/crates/tests/bindgen/src/struct_with_generic.rs @@ -962,7 +962,7 @@ impl IPropertyValue_Vtbl { } Self { base__: windows_core::IInspectable_Vtbl::new::(), - get_Type: 0, + Type: 0, IsNumericScalar: IsNumericScalar::, GetUInt8: GetUInt8::, GetInt16: GetInt16::, @@ -1010,7 +1010,7 @@ impl IPropertyValue_Vtbl { #[repr(C)] pub struct IPropertyValue_Vtbl { pub base__: windows_core::IInspectable_Vtbl, - get_Type: usize, + Type: usize, pub IsNumericScalar: unsafe extern "system" fn(*mut core::ffi::c_void, *mut bool) -> windows_core::HRESULT, pub GetUInt8: diff --git a/crates/tests/misc/standalone/src/b_calendar.rs b/crates/tests/misc/standalone/src/b_calendar.rs index 827c0faf9d..0f4953a721 100644 --- a/crates/tests/misc/standalone/src/b_calendar.rs +++ b/crates/tests/misc/standalone/src/b_calendar.rs @@ -1162,7 +1162,7 @@ pub struct ICalendar_Vtbl { ) -> windows_core::HRESULT, pub SetToMin: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, pub SetToMax: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, - get_Languages: usize, + Languages: usize, pub NumeralSystem: unsafe extern "system" fn( *mut core::ffi::c_void, *mut *mut core::ffi::c_void, @@ -1286,7 +1286,7 @@ pub struct ICalendar_Vtbl { i32, *mut *mut core::ffi::c_void, ) -> windows_core::HRESULT, - get_DayOfWeek: usize, + DayOfWeek: usize, pub DayOfWeekAsFullString: unsafe extern "system" fn( *mut core::ffi::c_void, *mut *mut core::ffi::c_void, diff --git a/crates/tests/misc/standalone/src/b_uri.rs b/crates/tests/misc/standalone/src/b_uri.rs index bef12f8dc7..2f52d4a601 100644 --- a/crates/tests/misc/standalone/src/b_uri.rs +++ b/crates/tests/misc/standalone/src/b_uri.rs @@ -146,7 +146,7 @@ pub struct IUriRuntimeClass_Vtbl { *mut core::ffi::c_void, *mut *mut core::ffi::c_void, ) -> windows_core::HRESULT, - get_QueryParsed: usize, + QueryParsed: usize, pub RawUri: unsafe extern "system" fn( *mut core::ffi::c_void, *mut *mut core::ffi::c_void, diff --git a/crates/tests/winrt/overloads/Cargo.toml b/crates/tests/winrt/overloads/Cargo.toml new file mode 100644 index 0000000000..5011b5d8f4 --- /dev/null +++ b/crates/tests/winrt/overloads/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "test_overloads" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib"] +doc = false +doctest = false + +[build-dependencies.windows-bindgen] +workspace = true + +[dependencies.windows-core] +workspace = true + +[dependencies.windows] +workspace = true +features = [ + "Foundation", + "Win32_System_WinRT", +] diff --git a/crates/tests/winrt/overloads/build.rs b/crates/tests/winrt/overloads/build.rs new file mode 100644 index 0000000000..de58c48395 --- /dev/null +++ b/crates/tests/winrt/overloads/build.rs @@ -0,0 +1,33 @@ +fn main() { + let mut command = std::process::Command::new("midlrt.exe"); + command.args([ + "/winrt", + "/nomidl", + "/h", + "nul", + "/metadata_dir", + "../../../libs/bindgen/default", + "/reference", + "../../../libs/bindgen/default/Windows.winmd", + "/winmd", + "metadata.winmd", + "src/metadata.idl", + ]); + + if !command.status().unwrap().success() { + panic!("Failed to run midlrt"); + } + + windows_bindgen::bindgen([ + "--in", + "metadata.winmd", + "../../../libs/bindgen/default", + "--out", + "src/bindings.rs", + "--filter", + "test_overloads", + "--implement", + "--no-comment", + "--flat", + ]); +} diff --git a/crates/tests/winrt/overloads/src/bindings.rs b/crates/tests/winrt/overloads/src/bindings.rs new file mode 100644 index 0000000000..411b2ecdf8 --- /dev/null +++ b/crates/tests/winrt/overloads/src/bindings.rs @@ -0,0 +1,818 @@ +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct A(windows_core::IUnknown); +windows_core::imp::interface_hierarchy!(A, windows_core::IUnknown, windows_core::IInspectable); +impl A { + pub fn new() -> windows_core::Result { + Self::IActivationFactory(|f| f.ActivateInstance::()) + } + fn IActivationFactory< + R, + F: FnOnce(&windows_core::imp::IGenericFactory) -> windows_core::Result, + >( + callback: F, + ) -> windows_core::Result { + static SHARED: windows_core::imp::FactoryCache = + windows_core::imp::FactoryCache::new(); + SHARED.call(callback) + } + pub fn Method(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn Method2(&self, a: i32) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method2)( + windows_core::Interface::as_raw(this), + a, + &mut result__, + ) + .map(|| result__) + } + } +} +impl windows_core::RuntimeType for A { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_class::(); +} +unsafe impl windows_core::Interface for A { + type Vtable = ::Vtable; + const IID: windows_core::GUID = ::IID; +} +impl windows_core::RuntimeName for A { + const NAME: &'static str = "test_overloads.A"; +} +unsafe impl Send for A {} +unsafe impl Sync for A {} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct B(windows_core::IUnknown); +windows_core::imp::interface_hierarchy!(B, windows_core::IUnknown, windows_core::IInspectable); +impl B { + pub fn new() -> windows_core::Result { + Self::IActivationFactory(|f| f.ActivateInstance::()) + } + fn IActivationFactory< + R, + F: FnOnce(&windows_core::imp::IGenericFactory) -> windows_core::Result, + >( + callback: F, + ) -> windows_core::Result { + static SHARED: windows_core::imp::FactoryCache = + windows_core::imp::FactoryCache::new(); + SHARED.call(callback) + } + pub fn MethodOne(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MethodOne)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn MethodTwo(&self, a: i32) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MethodTwo)( + windows_core::Interface::as_raw(this), + a, + &mut result__, + ) + .map(|| result__) + } + } +} +impl windows_core::RuntimeType for B { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_class::(); +} +unsafe impl windows_core::Interface for B { + type Vtable = ::Vtable; + const IID: windows_core::GUID = ::IID; +} +impl windows_core::RuntimeName for B { + const NAME: &'static str = "test_overloads.B"; +} +unsafe impl Send for B {} +unsafe impl Sync for B {} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct C(windows_core::IUnknown); +windows_core::imp::interface_hierarchy!(C, windows_core::IUnknown, windows_core::IInspectable); +impl C { + pub fn new() -> windows_core::Result { + Self::IActivationFactory(|f| f.ActivateInstance::()) + } + fn IActivationFactory< + R, + F: FnOnce(&windows_core::imp::IGenericFactory) -> windows_core::Result, + >( + callback: F, + ) -> windows_core::Result { + static SHARED: windows_core::imp::FactoryCache = + windows_core::imp::FactoryCache::new(); + SHARED.call(callback) + } + pub fn Method(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn Method2(&self, a: i32) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method2)( + windows_core::Interface::as_raw(this), + a, + &mut result__, + ) + .map(|| result__) + } + } +} +impl windows_core::RuntimeType for C { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_class::(); +} +unsafe impl windows_core::Interface for C { + type Vtable = ::Vtable; + const IID: windows_core::GUID = ::IID; +} +impl windows_core::RuntimeName for C { + const NAME: &'static str = "test_overloads.C"; +} +unsafe impl Send for C {} +unsafe impl Sync for C {} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct D(windows_core::IUnknown); +windows_core::imp::interface_hierarchy!(D, windows_core::IUnknown, windows_core::IInspectable); +impl D { + pub fn new() -> windows_core::Result { + Self::IActivationFactory(|f| f.ActivateInstance::()) + } + fn IActivationFactory< + R, + F: FnOnce(&windows_core::imp::IGenericFactory) -> windows_core::Result, + >( + callback: F, + ) -> windows_core::Result { + static SHARED: windows_core::imp::FactoryCache = + windows_core::imp::FactoryCache::new(); + SHARED.call(callback) + } + pub fn Method(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn Method2(&self, a: i32) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method2)( + windows_core::Interface::as_raw(this), + a, + &mut result__, + ) + .map(|| result__) + } + } + pub fn Method3(&self, a: i32, b: i32) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method)( + windows_core::Interface::as_raw(this), + a, + b, + &mut result__, + ) + .map(|| result__) + } + } + pub fn Method4(&self, a: i32, b: i32, c: i32) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method2)( + windows_core::Interface::as_raw(this), + a, + b, + c, + &mut result__, + ) + .map(|| result__) + } + } +} +impl windows_core::RuntimeType for D { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_class::(); +} +unsafe impl windows_core::Interface for D { + type Vtable = ::Vtable; + const IID: windows_core::GUID = ::IID; +} +impl windows_core::RuntimeName for D { + const NAME: &'static str = "test_overloads.D"; +} +unsafe impl Send for D {} +unsafe impl Sync for D {} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct E(windows_core::IUnknown); +windows_core::imp::interface_hierarchy!(E, windows_core::IUnknown, windows_core::IInspectable); +impl E { + pub fn new() -> windows_core::Result { + Self::IActivationFactory(|f| f.ActivateInstance::()) + } + fn IActivationFactory< + R, + F: FnOnce(&windows_core::imp::IGenericFactory) -> windows_core::Result, + >( + callback: F, + ) -> windows_core::Result { + static SHARED: windows_core::imp::FactoryCache = + windows_core::imp::FactoryCache::new(); + SHARED.call(callback) + } + pub fn MethodOne(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MethodOne)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn MethodTwo(&self, a: i32) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MethodTwo)( + windows_core::Interface::as_raw(this), + a, + &mut result__, + ) + .map(|| result__) + } + } + pub fn MethodThree(&self, a: i32, b: i32) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MethodThree)( + windows_core::Interface::as_raw(this), + a, + b, + &mut result__, + ) + .map(|| result__) + } + } + pub fn MethodFour(&self, a: i32, b: i32, c: i32) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MethodFour)( + windows_core::Interface::as_raw(this), + a, + b, + c, + &mut result__, + ) + .map(|| result__) + } + } +} +impl windows_core::RuntimeType for E { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_class::(); +} +unsafe impl windows_core::Interface for E { + type Vtable = ::Vtable; + const IID: windows_core::GUID = ::IID; +} +impl windows_core::RuntimeName for E { + const NAME: &'static str = "test_overloads.E"; +} +unsafe impl Send for E {} +unsafe impl Sync for E {} +windows_core::imp::define_interface!(IA, IA_Vtbl, 0xea3ed6f8_2f81_5cfc_a281_4bf0d7535521); +impl windows_core::RuntimeType for IA { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +impl windows_core::RuntimeName for IA { + const NAME: &'static str = "test_overloads.IA"; +} +pub trait IA_Impl: windows_core::IUnknownImpl { + fn Method(&self) -> windows_core::Result; + fn Method2(&self, a: i32) -> windows_core::Result; +} +impl IA_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn Method( + this: *mut core::ffi::c_void, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IA_Impl::Method(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn Method2( + this: *mut core::ffi::c_void, + a: i32, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IA_Impl::Method2(this, a) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + Method: Method::, + Method2: Method2::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct IA_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Method: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut i32) -> windows_core::HRESULT, + pub Method2: + unsafe extern "system" fn(*mut core::ffi::c_void, i32, *mut i32) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(IB, IB_Vtbl, 0xc6f02ea8_68b6_5a1c_86fe_f8c0c0d655c4); +impl windows_core::RuntimeType for IB { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +impl windows_core::RuntimeName for IB { + const NAME: &'static str = "test_overloads.IB"; +} +pub trait IB_Impl: windows_core::IUnknownImpl { + fn MethodOne(&self) -> windows_core::Result; + fn MethodTwo(&self, a: i32) -> windows_core::Result; +} +impl IB_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn MethodOne( + this: *mut core::ffi::c_void, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IB_Impl::MethodOne(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn MethodTwo( + this: *mut core::ffi::c_void, + a: i32, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IB_Impl::MethodTwo(this, a) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + MethodOne: MethodOne::, + MethodTwo: MethodTwo::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct IB_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub MethodOne: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut i32) -> windows_core::HRESULT, + pub MethodTwo: + unsafe extern "system" fn(*mut core::ffi::c_void, i32, *mut i32) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(IC, IC_Vtbl, 0xdf8ad52f_5629_5e9b_a662_5723833b59e5); +impl windows_core::RuntimeType for IC { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +impl windows_core::RuntimeName for IC { + const NAME: &'static str = "test_overloads.IC"; +} +pub trait IC_Impl: windows_core::IUnknownImpl { + fn Method(&self) -> windows_core::Result; + fn Method2(&self, a: i32) -> windows_core::Result; +} +impl IC_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn Method( + this: *mut core::ffi::c_void, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IC_Impl::Method(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn Method2( + this: *mut core::ffi::c_void, + a: i32, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IC_Impl::Method2(this, a) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + Method: Method::, + Method2: Method2::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct IC_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Method: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut i32) -> windows_core::HRESULT, + pub Method2: + unsafe extern "system" fn(*mut core::ffi::c_void, i32, *mut i32) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(ID, ID_Vtbl, 0xa9cf9a9f_9389_5f27_bb69_a094144cad72); +impl windows_core::RuntimeType for ID { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +impl windows_core::RuntimeName for ID { + const NAME: &'static str = "test_overloads.ID"; +} +pub trait ID_Impl: windows_core::IUnknownImpl { + fn Method(&self) -> windows_core::Result; + fn Method2(&self, a: i32) -> windows_core::Result; +} +impl ID_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn Method( + this: *mut core::ffi::c_void, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match ID_Impl::Method(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn Method2( + this: *mut core::ffi::c_void, + a: i32, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match ID_Impl::Method2(this, a) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + Method: Method::, + Method2: Method2::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct ID_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Method: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut i32) -> windows_core::HRESULT, + pub Method2: + unsafe extern "system" fn(*mut core::ffi::c_void, i32, *mut i32) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(ID2, ID2_Vtbl, 0x5cbf6f2f_250f_57a9_82d9_d773fd84fbe9); +impl windows_core::RuntimeType for ID2 { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +impl windows_core::RuntimeName for ID2 { + const NAME: &'static str = "test_overloads.ID2"; +} +pub trait ID2_Impl: windows_core::IUnknownImpl { + fn Method(&self, a: i32, b: i32) -> windows_core::Result; + fn Method2(&self, a: i32, b: i32, c: i32) -> windows_core::Result; +} +impl ID2_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn Method( + this: *mut core::ffi::c_void, + a: i32, + b: i32, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match ID2_Impl::Method(this, a, b) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn Method2( + this: *mut core::ffi::c_void, + a: i32, + b: i32, + c: i32, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match ID2_Impl::Method2(this, a, b, c) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + Method: Method::, + Method2: Method2::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct ID2_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Method: unsafe extern "system" fn( + *mut core::ffi::c_void, + i32, + i32, + *mut i32, + ) -> windows_core::HRESULT, + pub Method2: unsafe extern "system" fn( + *mut core::ffi::c_void, + i32, + i32, + i32, + *mut i32, + ) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(IE, IE_Vtbl, 0x179af921_706b_5a49_8624_7889b2eff9c1); +impl windows_core::RuntimeType for IE { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +impl windows_core::RuntimeName for IE { + const NAME: &'static str = "test_overloads.IE"; +} +pub trait IE_Impl: windows_core::IUnknownImpl { + fn MethodOne(&self) -> windows_core::Result; + fn MethodTwo(&self, a: i32) -> windows_core::Result; +} +impl IE_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn MethodOne( + this: *mut core::ffi::c_void, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IE_Impl::MethodOne(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn MethodTwo( + this: *mut core::ffi::c_void, + a: i32, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IE_Impl::MethodTwo(this, a) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + MethodOne: MethodOne::, + MethodTwo: MethodTwo::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct IE_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub MethodOne: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut i32) -> windows_core::HRESULT, + pub MethodTwo: + unsafe extern "system" fn(*mut core::ffi::c_void, i32, *mut i32) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(IE2, IE2_Vtbl, 0x9e8f2cad_09de_5f31_b940_8189d6323a19); +impl windows_core::RuntimeType for IE2 { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +impl windows_core::RuntimeName for IE2 { + const NAME: &'static str = "test_overloads.IE2"; +} +pub trait IE2_Impl: windows_core::IUnknownImpl { + fn MethodThree(&self, a: i32, b: i32) -> windows_core::Result; + fn MethodFour(&self, a: i32, b: i32, c: i32) -> windows_core::Result; +} +impl IE2_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn MethodThree( + this: *mut core::ffi::c_void, + a: i32, + b: i32, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IE2_Impl::MethodThree(this, a, b) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn MethodFour( + this: *mut core::ffi::c_void, + a: i32, + b: i32, + c: i32, + result__: *mut i32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IE2_Impl::MethodFour(this, a, b, c) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + MethodThree: MethodThree::, + MethodFour: MethodFour::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct IE2_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub MethodThree: unsafe extern "system" fn( + *mut core::ffi::c_void, + i32, + i32, + *mut i32, + ) -> windows_core::HRESULT, + pub MethodFour: unsafe extern "system" fn( + *mut core::ffi::c_void, + i32, + i32, + i32, + *mut i32, + ) -> windows_core::HRESULT, +} diff --git a/crates/tests/winrt/overloads/src/lib.rs b/crates/tests/winrt/overloads/src/lib.rs new file mode 100644 index 0000000000..01fcaadfd2 --- /dev/null +++ b/crates/tests/winrt/overloads/src/lib.rs @@ -0,0 +1,130 @@ +mod bindings; + +use windows::{core::*, Win32::Foundation::*, Win32::System::WinRT::*}; + +#[no_mangle] +unsafe extern "system" fn DllGetActivationFactory( + name: Ref, + factory: OutRef, +) -> HRESULT { + if *name == "test_overloads.A" { + factory.write(Some(FA.into())).into() + } else if *name == "test_overloads.B" { + factory.write(Some(FB.into())).into() + } else if *name == "test_overloads.C" { + factory.write(Some(FC.into())).into() + } else if *name == "test_overloads.D" { + factory.write(Some(FD.into())).into() + } else if *name == "test_overloads.E" { + factory.write(Some(FE.into())).into() + } else { + _ = factory.write(None); + CLASS_E_CLASSNOTAVAILABLE + } +} + +#[implement(IActivationFactory)] +struct FA; +#[implement(bindings::A)] +struct A; +impl IActivationFactory_Impl for FA_Impl { + fn ActivateInstance(&self) -> Result { + Ok(A.into()) + } +} +impl bindings::IA_Impl for A_Impl { + fn Method(&self) -> Result { + Ok(1) + } + fn Method2(&self, _: i32) -> Result { + Ok(2) + } +} + +#[implement(IActivationFactory)] +struct FB; +#[implement(bindings::B)] +struct B; +impl IActivationFactory_Impl for FB_Impl { + fn ActivateInstance(&self) -> Result { + Ok(B.into()) + } +} +impl bindings::IB_Impl for B_Impl { + fn MethodOne(&self) -> Result { + Ok(3) + } + fn MethodTwo(&self, _: i32) -> Result { + Ok(4) + } +} + +#[implement(IActivationFactory)] +struct FC; +#[implement(bindings::C)] +struct C; +impl IActivationFactory_Impl for FC_Impl { + fn ActivateInstance(&self) -> Result { + Ok(C.into()) + } +} +impl bindings::IC_Impl for C_Impl { + fn Method(&self) -> Result { + Ok(5) + } + fn Method2(&self, _: i32) -> Result { + Ok(6) + } +} + +#[implement(IActivationFactory)] +struct FD; +#[implement(bindings::D, bindings::ID2)] // TODO: https://github.com/microsoft/windows-rs/issues/3258 +struct D; +impl IActivationFactory_Impl for FD_Impl { + fn ActivateInstance(&self) -> Result { + Ok(D.into()) + } +} +impl bindings::ID_Impl for D_Impl { + fn Method(&self) -> Result { + Ok(7) + } + fn Method2(&self, _: i32) -> Result { + Ok(8) + } +} +impl bindings::ID2_Impl for D_Impl { + fn Method(&self, _: i32, _: i32) -> Result { + Ok(9) + } + fn Method2(&self, _: i32, _: i32, _: i32) -> Result { + Ok(10) + } +} + +#[implement(IActivationFactory)] +struct FE; +#[implement(bindings::E, bindings::IE2)] // TODO: https://github.com/microsoft/windows-rs/issues/3258 +struct E; +impl IActivationFactory_Impl for FE_Impl { + fn ActivateInstance(&self) -> Result { + Ok(E.into()) + } +} +impl bindings::IE_Impl for E_Impl { + fn MethodOne(&self) -> Result { + Ok(11) + } + fn MethodTwo(&self, _: i32) -> Result { + Ok(12) + } +} +impl bindings::IE2_Impl for E_Impl { + fn MethodThree(&self, _: i32, _: i32) -> Result { + Ok(13) + } + fn MethodFour(&self, _: i32, _: i32, _: i32) -> Result { + Ok(14) + } +} diff --git a/crates/tests/winrt/overloads/src/metadata.idl b/crates/tests/winrt/overloads/src/metadata.idl new file mode 100644 index 0000000000..8ea6b2e8b2 --- /dev/null +++ b/crates/tests/winrt/overloads/src/metadata.idl @@ -0,0 +1,60 @@ +namespace test_overloads { + // `A` will have overloads generated by MIDLRT. + + runtimeclass A { + A(); + Int32 Method(); + Int32 Method(Int32 a); + } + + // `B` defines overloads explicitly. + + runtimeclass B { + B(); + [method_name("MethodOne")] Int32 Method(); + [method_name("MethodTwo")] Int32 Method(Int32 a); + } + + // `C` defines overloads explicitly but since they're just numeric suffixes they will be ignored + // and windows-bindgen will generate contextually sensitive overloads. + + runtimeclass C { + C(); + [method_name("Method123")] Int32 Method(); + [method_name("Method456")] Int32 Method(Int32 a); + } + + // `D` implements two exclusive interfaces that have their overloads generated by MIDLRT but it doesn't + // correctly deal with overloads in the context of the class so windows-bindgen will again generate + // contextually sensitive overloads as with `C`. + + [exclusiveto(D)] + interface ID { + Int32 Method(); + Int32 Method(Int32 a); + } + [exclusiveto(D)] + interface ID2 { + Int32 Method(Int32 a, Int32 b); + Int32 Method(Int32 a, Int32 b, Int32 c); + } + runtimeclass D: [default] ID, ID2 { + D(); + } + + // `E` defines overloads explicitly and all is well. + + [exclusiveto(E)] + interface IE { + [method_name("MethodOne")] Int32 Method(); + [method_name("MethodTwo")] Int32 Method(Int32 a); + } + [exclusiveto(E)] + interface IE2 { + [method_name("MethodThree")] Int32 Method(Int32 a, Int32 b); + [method_name("MethodFour")] Int32 Method(Int32 a, Int32 b, Int32 c); + } + runtimeclass E: [default] IE, IE2 { + E(); + } + } diff --git a/crates/tests/winrt/overloads_client/Cargo.toml b/crates/tests/winrt/overloads_client/Cargo.toml new file mode 100644 index 0000000000..eedc6c352e --- /dev/null +++ b/crates/tests/winrt/overloads_client/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "test_overloads_client" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +doc = false +doctest = false + +[build-dependencies.windows-bindgen] +workspace = true + +[dependencies.windows-core] +workspace = true + +[dependencies.windows] +workspace = true +features = [ + "Foundation", + "Win32_Foundation", +] + +# The build needs the output (.dll) of the component. This causes a warning about lack of linkage target. +# Cargo doesn't understand cdylib targets. https://github.com/rust-lang/cargo/issues/7825 +[dependencies.test_overloads] +path = "../overloads" diff --git a/crates/tests/winrt/overloads_client/build.rs b/crates/tests/winrt/overloads_client/build.rs new file mode 100644 index 0000000000..a000026736 --- /dev/null +++ b/crates/tests/winrt/overloads_client/build.rs @@ -0,0 +1,13 @@ +fn main() { + windows_bindgen::bindgen([ + "--in", + "../overloads/metadata.winmd", + "../../../libs/bindgen/default", + "--out", + "src/bindings.rs", + "--filter", + "test_overloads", + "--no-comment", + "--flat", + ]); +} diff --git a/crates/tests/winrt/overloads_client/src/bindings.rs b/crates/tests/winrt/overloads_client/src/bindings.rs new file mode 100644 index 0000000000..cf19868b2b --- /dev/null +++ b/crates/tests/winrt/overloads_client/src/bindings.rs @@ -0,0 +1,446 @@ +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct A(windows_core::IUnknown); +windows_core::imp::interface_hierarchy!(A, windows_core::IUnknown, windows_core::IInspectable); +impl A { + pub fn new() -> windows_core::Result { + Self::IActivationFactory(|f| f.ActivateInstance::()) + } + fn IActivationFactory< + R, + F: FnOnce(&windows_core::imp::IGenericFactory) -> windows_core::Result, + >( + callback: F, + ) -> windows_core::Result { + static SHARED: windows_core::imp::FactoryCache = + windows_core::imp::FactoryCache::new(); + SHARED.call(callback) + } + pub fn Method(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn Method2(&self, a: i32) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method2)( + windows_core::Interface::as_raw(this), + a, + &mut result__, + ) + .map(|| result__) + } + } +} +impl windows_core::RuntimeType for A { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_class::(); +} +unsafe impl windows_core::Interface for A { + type Vtable = ::Vtable; + const IID: windows_core::GUID = ::IID; +} +impl windows_core::RuntimeName for A { + const NAME: &'static str = "test_overloads.A"; +} +unsafe impl Send for A {} +unsafe impl Sync for A {} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct B(windows_core::IUnknown); +windows_core::imp::interface_hierarchy!(B, windows_core::IUnknown, windows_core::IInspectable); +impl B { + pub fn new() -> windows_core::Result { + Self::IActivationFactory(|f| f.ActivateInstance::()) + } + fn IActivationFactory< + R, + F: FnOnce(&windows_core::imp::IGenericFactory) -> windows_core::Result, + >( + callback: F, + ) -> windows_core::Result { + static SHARED: windows_core::imp::FactoryCache = + windows_core::imp::FactoryCache::new(); + SHARED.call(callback) + } + pub fn MethodOne(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MethodOne)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn MethodTwo(&self, a: i32) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MethodTwo)( + windows_core::Interface::as_raw(this), + a, + &mut result__, + ) + .map(|| result__) + } + } +} +impl windows_core::RuntimeType for B { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_class::(); +} +unsafe impl windows_core::Interface for B { + type Vtable = ::Vtable; + const IID: windows_core::GUID = ::IID; +} +impl windows_core::RuntimeName for B { + const NAME: &'static str = "test_overloads.B"; +} +unsafe impl Send for B {} +unsafe impl Sync for B {} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct C(windows_core::IUnknown); +windows_core::imp::interface_hierarchy!(C, windows_core::IUnknown, windows_core::IInspectable); +impl C { + pub fn new() -> windows_core::Result { + Self::IActivationFactory(|f| f.ActivateInstance::()) + } + fn IActivationFactory< + R, + F: FnOnce(&windows_core::imp::IGenericFactory) -> windows_core::Result, + >( + callback: F, + ) -> windows_core::Result { + static SHARED: windows_core::imp::FactoryCache = + windows_core::imp::FactoryCache::new(); + SHARED.call(callback) + } + pub fn Method(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn Method2(&self, a: i32) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method2)( + windows_core::Interface::as_raw(this), + a, + &mut result__, + ) + .map(|| result__) + } + } +} +impl windows_core::RuntimeType for C { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_class::(); +} +unsafe impl windows_core::Interface for C { + type Vtable = ::Vtable; + const IID: windows_core::GUID = ::IID; +} +impl windows_core::RuntimeName for C { + const NAME: &'static str = "test_overloads.C"; +} +unsafe impl Send for C {} +unsafe impl Sync for C {} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct D(windows_core::IUnknown); +windows_core::imp::interface_hierarchy!(D, windows_core::IUnknown, windows_core::IInspectable); +impl D { + pub fn new() -> windows_core::Result { + Self::IActivationFactory(|f| f.ActivateInstance::()) + } + fn IActivationFactory< + R, + F: FnOnce(&windows_core::imp::IGenericFactory) -> windows_core::Result, + >( + callback: F, + ) -> windows_core::Result { + static SHARED: windows_core::imp::FactoryCache = + windows_core::imp::FactoryCache::new(); + SHARED.call(callback) + } + pub fn Method(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn Method2(&self, a: i32) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method2)( + windows_core::Interface::as_raw(this), + a, + &mut result__, + ) + .map(|| result__) + } + } + pub fn Method3(&self, a: i32, b: i32) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method)( + windows_core::Interface::as_raw(this), + a, + b, + &mut result__, + ) + .map(|| result__) + } + } + pub fn Method4(&self, a: i32, b: i32, c: i32) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Method2)( + windows_core::Interface::as_raw(this), + a, + b, + c, + &mut result__, + ) + .map(|| result__) + } + } +} +impl windows_core::RuntimeType for D { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_class::(); +} +unsafe impl windows_core::Interface for D { + type Vtable = ::Vtable; + const IID: windows_core::GUID = ::IID; +} +impl windows_core::RuntimeName for D { + const NAME: &'static str = "test_overloads.D"; +} +unsafe impl Send for D {} +unsafe impl Sync for D {} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct E(windows_core::IUnknown); +windows_core::imp::interface_hierarchy!(E, windows_core::IUnknown, windows_core::IInspectable); +impl E { + pub fn new() -> windows_core::Result { + Self::IActivationFactory(|f| f.ActivateInstance::()) + } + fn IActivationFactory< + R, + F: FnOnce(&windows_core::imp::IGenericFactory) -> windows_core::Result, + >( + callback: F, + ) -> windows_core::Result { + static SHARED: windows_core::imp::FactoryCache = + windows_core::imp::FactoryCache::new(); + SHARED.call(callback) + } + pub fn MethodOne(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MethodOne)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn MethodTwo(&self, a: i32) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MethodTwo)( + windows_core::Interface::as_raw(this), + a, + &mut result__, + ) + .map(|| result__) + } + } + pub fn MethodThree(&self, a: i32, b: i32) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MethodThree)( + windows_core::Interface::as_raw(this), + a, + b, + &mut result__, + ) + .map(|| result__) + } + } + pub fn MethodFour(&self, a: i32, b: i32, c: i32) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MethodFour)( + windows_core::Interface::as_raw(this), + a, + b, + c, + &mut result__, + ) + .map(|| result__) + } + } +} +impl windows_core::RuntimeType for E { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_class::(); +} +unsafe impl windows_core::Interface for E { + type Vtable = ::Vtable; + const IID: windows_core::GUID = ::IID; +} +impl windows_core::RuntimeName for E { + const NAME: &'static str = "test_overloads.E"; +} +unsafe impl Send for E {} +unsafe impl Sync for E {} +windows_core::imp::define_interface!(IA, IA_Vtbl, 0xea3ed6f8_2f81_5cfc_a281_4bf0d7535521); +impl windows_core::RuntimeType for IA { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +#[repr(C)] +pub struct IA_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Method: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut i32) -> windows_core::HRESULT, + pub Method2: + unsafe extern "system" fn(*mut core::ffi::c_void, i32, *mut i32) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(IB, IB_Vtbl, 0xc6f02ea8_68b6_5a1c_86fe_f8c0c0d655c4); +impl windows_core::RuntimeType for IB { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +#[repr(C)] +pub struct IB_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub MethodOne: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut i32) -> windows_core::HRESULT, + pub MethodTwo: + unsafe extern "system" fn(*mut core::ffi::c_void, i32, *mut i32) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(IC, IC_Vtbl, 0xdf8ad52f_5629_5e9b_a662_5723833b59e5); +impl windows_core::RuntimeType for IC { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +#[repr(C)] +pub struct IC_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Method: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut i32) -> windows_core::HRESULT, + pub Method2: + unsafe extern "system" fn(*mut core::ffi::c_void, i32, *mut i32) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(ID, ID_Vtbl, 0xa9cf9a9f_9389_5f27_bb69_a094144cad72); +impl windows_core::RuntimeType for ID { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +#[repr(C)] +pub struct ID_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Method: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut i32) -> windows_core::HRESULT, + pub Method2: + unsafe extern "system" fn(*mut core::ffi::c_void, i32, *mut i32) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(ID2, ID2_Vtbl, 0x5cbf6f2f_250f_57a9_82d9_d773fd84fbe9); +impl windows_core::RuntimeType for ID2 { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +#[repr(C)] +pub struct ID2_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Method: unsafe extern "system" fn( + *mut core::ffi::c_void, + i32, + i32, + *mut i32, + ) -> windows_core::HRESULT, + pub Method2: unsafe extern "system" fn( + *mut core::ffi::c_void, + i32, + i32, + i32, + *mut i32, + ) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(IE, IE_Vtbl, 0x179af921_706b_5a49_8624_7889b2eff9c1); +impl windows_core::RuntimeType for IE { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +#[repr(C)] +pub struct IE_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub MethodOne: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut i32) -> windows_core::HRESULT, + pub MethodTwo: + unsafe extern "system" fn(*mut core::ffi::c_void, i32, *mut i32) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(IE2, IE2_Vtbl, 0x9e8f2cad_09de_5f31_b940_8189d6323a19); +impl windows_core::RuntimeType for IE2 { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +#[repr(C)] +pub struct IE2_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub MethodThree: unsafe extern "system" fn( + *mut core::ffi::c_void, + i32, + i32, + *mut i32, + ) -> windows_core::HRESULT, + pub MethodFour: unsafe extern "system" fn( + *mut core::ffi::c_void, + i32, + i32, + i32, + *mut i32, + ) -> windows_core::HRESULT, +} diff --git a/crates/tests/winrt/overloads_client/src/lib.rs b/crates/tests/winrt/overloads_client/src/lib.rs new file mode 100644 index 0000000000..c4305894e0 --- /dev/null +++ b/crates/tests/winrt/overloads_client/src/lib.rs @@ -0,0 +1,60 @@ +#![cfg(target_env = "msvc")] +#![cfg(test)] + +mod bindings; +use bindings::*; +use windows_core::*; + +#[test] +fn a() -> Result<()> { + let test = A::new()?; + + assert_eq!(test.Method()?, 1); + assert_eq!(test.Method2(0)?, 2); + + Ok(()) +} + +#[test] +fn b() -> Result<()> { + let test = B::new()?; + + assert_eq!(test.MethodOne()?, 3); + assert_eq!(test.MethodTwo(0)?, 4); + + Ok(()) +} + +#[test] +fn c() -> Result<()> { + let test = C::new()?; + + assert_eq!(test.Method()?, 5); + assert_eq!(test.Method2(0)?, 6); + + Ok(()) +} + +#[test] +fn d() -> Result<()> { + let test = D::new()?; + + assert_eq!(test.Method()?, 7); + assert_eq!(test.Method2(0)?, 8); + assert_eq!(test.Method3(0, 0)?, 9); + assert_eq!(test.Method4(0, 0, 0)?, 10); + + Ok(()) +} + +#[test] +fn e() -> Result<()> { + let test = E::new()?; + + assert_eq!(test.MethodOne()?, 11); + assert_eq!(test.MethodTwo(0)?, 12); + assert_eq!(test.MethodThree(0, 0)?, 13); + assert_eq!(test.MethodFour(0, 0, 0)?, 14); + + Ok(()) +} diff --git a/crates/tests/winrt/reference_float/src/bindings.rs b/crates/tests/winrt/reference_float/src/bindings.rs index 4e9bbd5dda..d20cbde773 100644 --- a/crates/tests/winrt/reference_float/src/bindings.rs +++ b/crates/tests/winrt/reference_float/src/bindings.rs @@ -924,7 +924,7 @@ impl IPropertyValue_Vtbl { } Self { base__: windows_core::IInspectable_Vtbl::new::(), - get_Type: 0, + Type: 0, IsNumericScalar: IsNumericScalar::, GetUInt8: GetUInt8::, GetInt16: GetInt16::, @@ -972,7 +972,7 @@ impl IPropertyValue_Vtbl { #[repr(C)] pub struct IPropertyValue_Vtbl { pub base__: windows_core::IInspectable_Vtbl, - get_Type: usize, + Type: usize, pub IsNumericScalar: unsafe extern "system" fn(*mut core::ffi::c_void, *mut bool) -> windows_core::HRESULT, pub GetUInt8: