diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index acb7a3146e..59f18832ce 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -241,10 +241,16 @@ jobs: run: cargo clippy -p test_reference - name: Clippy test_reference_client run: cargo clippy -p test_reference_client - - name: Clippy test_reference_default - run: cargo clippy -p test_reference_default + - name: Clippy test_reference_custom + run: cargo clippy -p test_reference_custom - name: Clippy test_reference_float run: cargo clippy -p test_reference_float + - name: Clippy test_reference_no_deps + run: cargo clippy -p test_reference_no_deps + - name: Clippy test_reference_no_windows + run: cargo clippy -p test_reference_no_windows + - name: Clippy test_reference_windows + run: cargo clippy -p test_reference_windows - name: Clippy test_registry run: cargo clippy -p test_registry - name: Clippy test_registry_default diff --git a/.github/workflows/raw-dylib.yml b/.github/workflows/raw-dylib.yml index ba4fabb6fc..55c26adb8f 100644 --- a/.github/workflows/raw-dylib.yml +++ b/.github/workflows/raw-dylib.yml @@ -272,10 +272,16 @@ jobs: run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_reference_client run: cargo test -p test_reference_client --target ${{ matrix.target }} ${{ matrix.etc }} - - name: Test test_reference_default - run: cargo test -p test_reference_default --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_reference_custom + run: cargo test -p test_reference_custom --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_reference_float run: cargo test -p test_reference_float --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_reference_no_deps + run: cargo test -p test_reference_no_deps --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_reference_no_windows + run: cargo test -p test_reference_no_windows --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_reference_windows + run: cargo test -p test_reference_windows --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_registry run: cargo test -p test_registry --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_registry_default @@ -358,14 +364,14 @@ jobs: run: cargo test -p windows-result --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows-strings run: cargo test -p windows-strings --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Clean + run: cargo clean - name: Test windows-sys run: cargo test -p windows-sys --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows-targets run: cargo test -p windows-targets --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows-version run: cargo test -p windows-version --target ${{ matrix.target }} ${{ matrix.etc }} - - name: Clean - run: cargo clean - name: Test windows_aarch64_gnullvm run: cargo test -p windows_aarch64_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows_aarch64_msvc diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 756e30fc72..9420c8763a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -269,10 +269,16 @@ jobs: run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_reference_client run: cargo test -p test_reference_client --target ${{ matrix.target }} ${{ matrix.etc }} - - name: Test test_reference_default - run: cargo test -p test_reference_default --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_reference_custom + run: cargo test -p test_reference_custom --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_reference_float run: cargo test -p test_reference_float --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_reference_no_deps + run: cargo test -p test_reference_no_deps --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_reference_no_windows + run: cargo test -p test_reference_no_windows --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_reference_windows + run: cargo test -p test_reference_windows --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_registry run: cargo test -p test_registry --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_registry_default @@ -355,14 +361,14 @@ jobs: run: cargo test -p windows-result --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows-strings run: cargo test -p windows-strings --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Clean + run: cargo clean - name: Test windows-sys run: cargo test -p windows-sys --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows-targets run: cargo test -p windows-targets --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows-version run: cargo test -p windows-version --target ${{ matrix.target }} ${{ matrix.etc }} - - name: Clean - run: cargo clean - name: Test windows_aarch64_gnullvm run: cargo test -p windows_aarch64_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test windows_aarch64_msvc diff --git a/crates/libs/bindgen/src/references.rs b/crates/libs/bindgen/src/references.rs index be4c02f876..f8c9b90c07 100644 --- a/crates/libs/bindgen/src/references.rs +++ b/crates/libs/bindgen/src/references.rs @@ -23,7 +23,11 @@ impl Default for ReferenceStage { impl ReferenceStage { #[track_caller] - pub fn parse(arg: &str) -> Self { + pub fn parse(mut arg: &str) -> Self { + if arg == "windows" { + arg = "windows,skip-root,Windows" + } + let arg: Vec<_> = arg.split(',').collect(); if arg.len() != 3 { @@ -60,7 +64,7 @@ impl ReferenceStyle { #[derive(Debug)] pub struct Reference { pub name: String, // crate name like "windows" - pub types: TypeMap, // what this reference provides + pub filter: Filter, // what this reference provides pub style: ReferenceStyle, // how to generate the type path } @@ -74,12 +78,11 @@ impl References { .into_iter() .map(|stage| { let filter = Filter::new(reader, &[&stage.path], &[]); - let types = TypeMap::filter(reader, &filter, &References::default()); Reference { name: stage.name, style: stage.style, - types, + filter, } }) .collect(), @@ -89,6 +92,6 @@ impl References { pub fn contains(&self, name: TypeName) -> Option<&Reference> { self.0 .iter() - .find(|reference| reference.types.contains_key(&name)) + .find(|reference| reference.filter.includes_type_name(name)) } } diff --git a/crates/tests/bindgen/src/reference_dependent_flat.rs b/crates/tests/bindgen/src/reference_dependent_flat.rs index 173079c1f4..ed84c44ba6 100644 --- a/crates/tests/bindgen/src/reference_dependent_flat.rs +++ b/crates/tests/bindgen/src/reference_dependent_flat.rs @@ -8,6 +8,62 @@ pub mod Windows { pub mod Foundation { + windows_core::imp::define_interface!( + IClosable, + IClosable_Vtbl, + 0x30d5a829_7fa4_4026_83bb_d75bae4ea99e + ); + impl windows_core::RuntimeType for IClosable { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); + } + windows_core::imp::interface_hierarchy!( + IClosable, + windows_core::IUnknown, + windows_core::IInspectable + ); + impl IClosable { + pub fn Close(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw( + this, + )) + .ok() + } + } + } + impl windows_core::RuntimeName for IClosable { + const NAME: &'static str = "Windows.Foundation.IClosable"; + } + pub trait IClosable_Impl: windows_core::IUnknownImpl { + fn Close(&self) -> windows_core::Result<()>; + } + impl IClosable_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn Close( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IClosable_Impl::Close(this).into() + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + Close: Close::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } + } + #[repr(C)] + pub struct IClosable_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Close: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + } windows_core::imp::define_interface!( IMemoryBuffer, IMemoryBuffer_Vtbl, @@ -22,10 +78,7 @@ pub mod Windows { windows_core::IUnknown, windows_core::IInspectable ); - windows_core::imp::required_hierarchy!( - IMemoryBuffer, - crate::reference_dependency_flat::IClosable - ); + windows_core::imp::required_hierarchy!(IMemoryBuffer, IClosable); impl IMemoryBuffer { pub fn CreateReference( &self, @@ -42,9 +95,7 @@ pub mod Windows { } } pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::< - crate::reference_dependency_flat::IClosable, - >(self)?; + let this = &windows_core::Interface::cast::(self)?; unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw( this, @@ -56,7 +107,7 @@ pub mod Windows { impl windows_core::RuntimeName for IMemoryBuffer { const NAME: &'static str = "Windows.Foundation.IMemoryBuffer"; } - pub trait IMemoryBuffer_Impl: crate::reference_dependency_flat::IClosable_Impl { + pub trait IMemoryBuffer_Impl: IClosable_Impl { fn CreateReference( &self, ) -> windows_core::Result; diff --git a/crates/tests/bindgen/src/reference_dependent_full.rs b/crates/tests/bindgen/src/reference_dependent_full.rs index 0b7cb436fd..bcfe37d3af 100644 --- a/crates/tests/bindgen/src/reference_dependent_full.rs +++ b/crates/tests/bindgen/src/reference_dependent_full.rs @@ -8,6 +8,62 @@ pub mod Windows { pub mod Foundation { + windows_core::imp::define_interface!( + IClosable, + IClosable_Vtbl, + 0x30d5a829_7fa4_4026_83bb_d75bae4ea99e + ); + impl windows_core::RuntimeType for IClosable { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); + } + windows_core::imp::interface_hierarchy!( + IClosable, + windows_core::IUnknown, + windows_core::IInspectable + ); + impl IClosable { + pub fn Close(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw( + this, + )) + .ok() + } + } + } + impl windows_core::RuntimeName for IClosable { + const NAME: &'static str = "Windows.Foundation.IClosable"; + } + pub trait IClosable_Impl: windows_core::IUnknownImpl { + fn Close(&self) -> windows_core::Result<()>; + } + impl IClosable_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn Close( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IClosable_Impl::Close(this).into() + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + Close: Close::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } + } + #[repr(C)] + pub struct IClosable_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Close: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + } windows_core::imp::define_interface!( IMemoryBuffer, IMemoryBuffer_Vtbl, @@ -22,10 +78,7 @@ pub mod Windows { windows_core::IUnknown, windows_core::IInspectable ); - windows_core::imp::required_hierarchy!( - IMemoryBuffer, - crate::reference_dependency_full::Windows::Foundation::IClosable - ); + windows_core::imp::required_hierarchy!(IMemoryBuffer, IClosable); impl IMemoryBuffer { pub fn CreateReference( &self, @@ -43,9 +96,7 @@ pub mod Windows { } } pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::< - crate::reference_dependency_full::Windows::Foundation::IClosable, - >(self)?; + let this = &windows_core::Interface::cast::(self)?; unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw( this, @@ -57,9 +108,7 @@ pub mod Windows { impl windows_core::RuntimeName for IMemoryBuffer { const NAME: &'static str = "Windows.Foundation.IMemoryBuffer"; } - pub trait IMemoryBuffer_Impl: - crate::reference_dependency_full::Windows::Foundation::IClosable_Impl - { + pub trait IMemoryBuffer_Impl: IClosable_Impl { fn CreateReference( &self, ) -> windows_core::Result< diff --git a/crates/tests/bindgen/src/reference_dependent_skip_root.rs b/crates/tests/bindgen/src/reference_dependent_skip_root.rs index d7248aeca8..5dfdef1768 100644 --- a/crates/tests/bindgen/src/reference_dependent_skip_root.rs +++ b/crates/tests/bindgen/src/reference_dependent_skip_root.rs @@ -8,6 +8,62 @@ pub mod Windows { pub mod Foundation { + windows_core::imp::define_interface!( + IClosable, + IClosable_Vtbl, + 0x30d5a829_7fa4_4026_83bb_d75bae4ea99e + ); + impl windows_core::RuntimeType for IClosable { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); + } + windows_core::imp::interface_hierarchy!( + IClosable, + windows_core::IUnknown, + windows_core::IInspectable + ); + impl IClosable { + pub fn Close(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw( + this, + )) + .ok() + } + } + } + impl windows_core::RuntimeName for IClosable { + const NAME: &'static str = "Windows.Foundation.IClosable"; + } + pub trait IClosable_Impl: windows_core::IUnknownImpl { + fn Close(&self) -> windows_core::Result<()>; + } + impl IClosable_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn Close( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IClosable_Impl::Close(this).into() + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + Close: Close::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } + } + #[repr(C)] + pub struct IClosable_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Close: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + } windows_core::imp::define_interface!( IMemoryBuffer, IMemoryBuffer_Vtbl, @@ -22,10 +78,7 @@ pub mod Windows { windows_core::IUnknown, windows_core::IInspectable ); - windows_core::imp::required_hierarchy!( - IMemoryBuffer, - crate::reference_dependency_skip_root::Windows::Foundation::IClosable - ); + windows_core::imp::required_hierarchy!(IMemoryBuffer, IClosable); impl IMemoryBuffer { pub fn CreateReference( &self, @@ -43,9 +96,7 @@ pub mod Windows { } } pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::< - crate::reference_dependency_skip_root::Windows::Foundation::IClosable, - >(self)?; + let this = &windows_core::Interface::cast::(self)?; unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw( this, @@ -57,9 +108,7 @@ pub mod Windows { impl windows_core::RuntimeName for IMemoryBuffer { const NAME: &'static str = "Windows.Foundation.IMemoryBuffer"; } - pub trait IMemoryBuffer_Impl: - crate::reference_dependency_skip_root::Windows::Foundation::IClosable_Impl - { + pub trait IMemoryBuffer_Impl: IClosable_Impl { fn CreateReference( &self, ) -> windows_core::Result< diff --git a/crates/tests/misc/component/build.rs b/crates/tests/misc/component/build.rs index 668f440d6b..f944753b1c 100644 --- a/crates/tests/misc/component/build.rs +++ b/crates/tests/misc/component/build.rs @@ -32,6 +32,6 @@ fn main() { "--implement", "--no-comment", "--reference", - "windows,skip-root,Windows.Foundation", + "windows", ]); } diff --git a/crates/tests/misc/component_client/build.rs b/crates/tests/misc/component_client/build.rs index d874368300..7346b84fa3 100644 --- a/crates/tests/misc/component_client/build.rs +++ b/crates/tests/misc/component_client/build.rs @@ -10,6 +10,6 @@ fn main() { "--no-comment", "--flat", "--reference", - "windows,skip-root,Windows.Foundation", + "windows", ]); } diff --git a/crates/tests/winrt/events/build.rs b/crates/tests/winrt/events/build.rs index eac24b1b3d..f48913f6eb 100644 --- a/crates/tests/winrt/events/build.rs +++ b/crates/tests/winrt/events/build.rs @@ -32,6 +32,6 @@ fn main() { "--no-comment", "--flat", "--reference", - "windows,skip-root,Windows", + "windows", ]); } diff --git a/crates/tests/winrt/events_client/build.rs b/crates/tests/winrt/events_client/build.rs index fc5df736cf..5209838145 100644 --- a/crates/tests/winrt/events_client/build.rs +++ b/crates/tests/winrt/events_client/build.rs @@ -12,6 +12,6 @@ fn main() { "--no-comment", "--flat", "--reference", - "windows,skip-root,Windows", + "windows", ]); } diff --git a/crates/tests/winrt/reference/build.rs b/crates/tests/winrt/reference/build.rs index a23c8522df..e6fc431133 100644 --- a/crates/tests/winrt/reference/build.rs +++ b/crates/tests/winrt/reference/build.rs @@ -30,6 +30,6 @@ fn main() { "--no-comment", "--flat", "--reference", - "windows,skip-root,Windows", + "windows", ]); } diff --git a/crates/tests/winrt/reference_client/build.rs b/crates/tests/winrt/reference_client/build.rs index 55ddd26a2f..20c7ad2df9 100644 --- a/crates/tests/winrt/reference_client/build.rs +++ b/crates/tests/winrt/reference_client/build.rs @@ -10,6 +10,6 @@ fn main() { "--no-comment", "--flat", "--reference", - "windows,skip-root,Windows", + "windows", ]); } diff --git a/crates/tests/winrt/reference_custom/Cargo.toml b/crates/tests/winrt/reference_custom/Cargo.toml new file mode 100644 index 0000000000..0d75744c53 --- /dev/null +++ b/crates/tests/winrt/reference_custom/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "test_reference_custom" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +doc = false +doctest = false + +[dependencies.windows-core] +workspace = true + +[dependencies.windows] +workspace = true +features = [ + "Foundation" +] + +[build-dependencies.windows-bindgen] +workspace = true diff --git a/crates/tests/winrt/reference_custom/build.rs b/crates/tests/winrt/reference_custom/build.rs new file mode 100644 index 0000000000..3a08f1ec4b --- /dev/null +++ b/crates/tests/winrt/reference_custom/build.rs @@ -0,0 +1,40 @@ +fn main() { + println!("cargo:rerun-if-changed=src/test.idl"); + 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", + "test.winmd", + "src/test.idl", + ]); + + if !command.status().unwrap().success() { + panic!("Failed to run midlrt"); + } + + windows_bindgen::bindgen([ + "--in", + "default", + "test.winmd", + "--out", + "src/bindings.rs", + "--filter", + "Test", + "Vector2", + "IVector", + "IAsyncAction", + "--implement", + "--flat", + "--no-deps", + "--reference", + "windows,skip-root,Windows.Foundation.IStringable", + ]); +} diff --git a/crates/tests/winrt/reference_custom/src/bindings.rs b/crates/tests/winrt/reference_custom/src/bindings.rs new file mode 100644 index 0000000000..1486603785 --- /dev/null +++ b/crates/tests/winrt/reference_custom/src/bindings.rs @@ -0,0 +1,1243 @@ +// Bindings generated by `windows-bindgen` 0.59.0 + +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +windows_core::imp::define_interface!( + IAsyncAction, + IAsyncAction_Vtbl, + 0x5a648006_843a_4da9_865b_9d26e5dfad7b +); +impl windows_core::RuntimeType for IAsyncAction { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +windows_core::imp::interface_hierarchy!( + IAsyncAction, + windows_core::IUnknown, + windows_core::IInspectable +); +windows_core::imp::required_hierarchy!(IAsyncAction, IAsyncInfo); +impl IAsyncAction { + pub fn GetResults(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw( + this, + )) + .ok() + } + } + pub fn Id(&self) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Id)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn ErrorCode(&self) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).ErrorCode)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn Cancel(&self) -> windows_core::Result<()> { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)) + .ok() + } + } + pub fn Close(&self) -> windows_core::Result<()> { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)) + .ok() + } + } +} +unsafe impl Send for IAsyncAction {} +unsafe impl Sync for IAsyncAction {} +impl windows_core::RuntimeName for IAsyncAction { + const NAME: &'static str = "Windows.Foundation.IAsyncAction"; +} +pub trait IAsyncAction_Impl: IAsyncInfo_Impl { + fn GetResults(&self) -> windows_core::Result<()>; +} +impl IAsyncAction_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn GetResults( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IAsyncAction_Impl::GetResults(this).into() + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + SetCompleted: 0, + Completed: 0, + GetResults: GetResults::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct IAsyncAction_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + SetCompleted: usize, + Completed: usize, + pub GetResults: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!( + IAsyncInfo, + IAsyncInfo_Vtbl, + 0x00000036_0000_0000_c000_000000000046 +); +impl windows_core::RuntimeType for IAsyncInfo { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +windows_core::imp::interface_hierarchy!( + IAsyncInfo, + windows_core::IUnknown, + windows_core::IInspectable +); +impl IAsyncInfo { + pub fn Id(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Id)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn ErrorCode(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).ErrorCode)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn Cancel(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)) + .ok() + } + } + pub fn Close(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)) + .ok() + } + } +} +impl windows_core::RuntimeName for IAsyncInfo { + const NAME: &'static str = "Windows.Foundation.IAsyncInfo"; +} +pub trait IAsyncInfo_Impl: windows_core::IUnknownImpl { + fn Id(&self) -> windows_core::Result; + fn ErrorCode(&self) -> windows_core::Result; + fn Cancel(&self) -> windows_core::Result<()>; + fn Close(&self) -> windows_core::Result<()>; +} +impl IAsyncInfo_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn Id( + this: *mut core::ffi::c_void, + result__: *mut u32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IAsyncInfo_Impl::Id(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn ErrorCode( + this: *mut core::ffi::c_void, + result__: *mut windows_core::HRESULT, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IAsyncInfo_Impl::ErrorCode(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn Cancel( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IAsyncInfo_Impl::Cancel(this).into() + } + } + unsafe extern "system" fn Close( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IAsyncInfo_Impl::Close(this).into() + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + Id: Id::, + Status: 0, + ErrorCode: ErrorCode::, + Cancel: Cancel::, + Close: Close::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +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, + Status: usize, + pub ErrorCode: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut windows_core::HRESULT, + ) -> windows_core::HRESULT, + pub Cancel: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + pub Close: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, +} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct IIterable(windows_core::IUnknown, core::marker::PhantomData) +where + T: windows_core::RuntimeType + 'static; +impl windows_core::imp::CanInto + for IIterable +{ +} +impl windows_core::imp::CanInto + for IIterable +{ +} +unsafe impl windows_core::Interface for IIterable { + type Vtable = IIterable_Vtbl; + const IID: windows_core::GUID = + windows_core::GUID::from_signature(::SIGNATURE); +} +impl windows_core::RuntimeType for IIterable { + const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::new() + .push_slice(b"pinterface({faa585ea-6214-4217-afda-7f46de5869b3}") + .push_slice(b";") + .push_other(T::SIGNATURE) + .push_slice(b")"); +} +impl IIterable { + pub fn First(&self) -> windows_core::Result> { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).First)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .and_then(|| windows_core::Type::from_abi(result__)) + } + } +} +impl windows_core::RuntimeName for IIterable { + const NAME: &'static str = "Windows.Foundation.Collections.IIterable"; +} +pub trait IIterable_Impl: windows_core::IUnknownImpl +where + T: windows_core::RuntimeType + 'static, +{ + fn First(&self) -> windows_core::Result>; +} +impl IIterable_Vtbl { + pub const fn new, const OFFSET: isize>() -> Self { + unsafe extern "system" fn First< + T: windows_core::RuntimeType + 'static, + Identity: IIterable_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IIterable_Impl::First(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + core::mem::forget(ok__); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::, OFFSET>(), + First: First::, + T: core::marker::PhantomData::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == & as windows_core::Interface>::IID + } +} +#[repr(C)] +pub struct IIterable_Vtbl +where + T: windows_core::RuntimeType + 'static, +{ + pub base__: windows_core::IInspectable_Vtbl, + pub First: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT, + T: core::marker::PhantomData, +} +impl IntoIterator for IIterable { + type Item = T; + type IntoIter = IIterator; + fn into_iter(self) -> Self::IntoIter { + IntoIterator::into_iter(&self) + } +} +impl IntoIterator for &IIterable { + type Item = T; + type IntoIter = IIterator; + fn into_iter(self) -> Self::IntoIter { + self.First().unwrap() + } +} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct IIterator(windows_core::IUnknown, core::marker::PhantomData) +where + T: windows_core::RuntimeType + 'static; +impl windows_core::imp::CanInto + for IIterator +{ +} +impl windows_core::imp::CanInto + for IIterator +{ +} +unsafe impl windows_core::Interface for IIterator { + type Vtable = IIterator_Vtbl; + const IID: windows_core::GUID = + windows_core::GUID::from_signature(::SIGNATURE); +} +impl windows_core::RuntimeType for IIterator { + const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::new() + .push_slice(b"pinterface({6a79e863-4300-459a-9966-cbb660963ee1}") + .push_slice(b";") + .push_other(T::SIGNATURE) + .push_slice(b")"); +} +impl IIterator { + pub fn Current(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Current)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .and_then(|| windows_core::Type::from_abi(result__)) + } + } + pub fn HasCurrent(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).HasCurrent)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn MoveNext(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MoveNext)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn GetMany( + &self, + items: &mut [>::Default], + ) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).GetMany)( + windows_core::Interface::as_raw(this), + items.len().try_into().unwrap(), + core::mem::transmute_copy(&items), + &mut result__, + ) + .map(|| result__) + } + } +} +impl windows_core::RuntimeName for IIterator { + const NAME: &'static str = "Windows.Foundation.Collections.IIterator"; +} +pub trait IIterator_Impl: windows_core::IUnknownImpl +where + T: windows_core::RuntimeType + 'static, +{ + fn Current(&self) -> windows_core::Result; + fn HasCurrent(&self) -> windows_core::Result; + fn MoveNext(&self) -> windows_core::Result; + fn GetMany( + &self, + items: &mut [>::Default], + ) -> windows_core::Result; +} +impl IIterator_Vtbl { + pub const fn new, const OFFSET: isize>() -> Self { + unsafe extern "system" fn Current< + T: windows_core::RuntimeType + 'static, + Identity: IIterator_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut windows_core::AbiType, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IIterator_Impl::Current(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + core::mem::forget(ok__); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn HasCurrent< + T: windows_core::RuntimeType + 'static, + Identity: IIterator_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IIterator_Impl::HasCurrent(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn MoveNext< + T: windows_core::RuntimeType + 'static, + Identity: IIterator_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IIterator_Impl::MoveNext(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn GetMany< + T: windows_core::RuntimeType + 'static, + Identity: IIterator_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + items_array_size: u32, + items: *mut T, + result__: *mut u32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IIterator_Impl::GetMany( + this, + core::slice::from_raw_parts_mut( + core::mem::transmute_copy(&items), + items_array_size as usize, + ), + ) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::, OFFSET>(), + Current: Current::, + HasCurrent: HasCurrent::, + MoveNext: MoveNext::, + GetMany: GetMany::, + T: core::marker::PhantomData::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == & as windows_core::Interface>::IID + } +} +#[repr(C)] +pub struct IIterator_Vtbl +where + T: windows_core::RuntimeType + 'static, +{ + pub base__: windows_core::IInspectable_Vtbl, + pub Current: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut windows_core::AbiType, + ) -> windows_core::HRESULT, + pub HasCurrent: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut bool) -> windows_core::HRESULT, + pub MoveNext: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut bool) -> windows_core::HRESULT, + pub GetMany: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + *mut T, + *mut u32, + ) -> windows_core::HRESULT, + T: core::marker::PhantomData, +} +impl Iterator for IIterator { + type Item = T; + fn next(&mut self) -> Option { + let result = if self.HasCurrent().unwrap_or(false) { + self.Current().ok() + } else { + None + }; + if result.is_some() { + self.MoveNext().ok()?; + } + result + } +} +windows_core::imp::define_interface!(ITest, ITest_Vtbl, 0x92862ee6_aff5_58df_8c9e_7e82f8aefe6b); +impl windows_core::RuntimeType for ITest { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +windows_core::imp::interface_hierarchy!(ITest, windows_core::IUnknown, windows_core::IInspectable); +impl ITest { + pub fn Numerics(&self, n: Vector2) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Numerics)( + windows_core::Interface::as_raw(this), + n, + ) + .ok() + } + } + pub fn Collections(&self, c: P0) -> windows_core::Result<()> + where + P0: windows_core::Param>, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Collections)( + windows_core::Interface::as_raw(this), + c.param().abi(), + ) + .ok() + } + } + pub fn Async(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Async)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .and_then(|| windows_core::Type::from_abi(result__)) + } + } + pub fn Windows(&self, s: P0) -> windows_core::Result<()> + where + P0: windows_core::Param, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Windows)( + windows_core::Interface::as_raw(this), + s.param().abi(), + ) + .ok() + } + } +} +impl windows_core::RuntimeName for ITest { + const NAME: &'static str = "Test.ITest"; +} +pub trait ITest_Impl: windows_core::IUnknownImpl { + fn Numerics(&self, n: &Vector2) -> windows_core::Result<()>; + fn Collections(&self, c: windows_core::Ref<'_, IVector>) -> windows_core::Result<()>; + fn Async(&self) -> windows_core::Result; + fn Windows( + &self, + s: windows_core::Ref<'_, windows::Foundation::IStringable>, + ) -> windows_core::Result<()>; +} +impl ITest_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn Numerics( + this: *mut core::ffi::c_void, + n: Vector2, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + ITest_Impl::Numerics(this, core::mem::transmute(&n)).into() + } + } + unsafe extern "system" fn Collections( + this: *mut core::ffi::c_void, + c: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + ITest_Impl::Collections(this, core::mem::transmute_copy(&c)).into() + } + } + unsafe extern "system" fn Async( + this: *mut core::ffi::c_void, + result__: *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match ITest_Impl::Async(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + core::mem::forget(ok__); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn Windows( + this: *mut core::ffi::c_void, + s: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + ITest_Impl::Windows(this, core::mem::transmute_copy(&s)).into() + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + Numerics: Numerics::, + Collections: Collections::, + Async: Async::, + Windows: Windows::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct ITest_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Numerics: + unsafe extern "system" fn(*mut core::ffi::c_void, Vector2) -> windows_core::HRESULT, + pub Collections: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut core::ffi::c_void, + ) -> windows_core::HRESULT, + pub Async: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT, + pub Windows: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut core::ffi::c_void, + ) -> windows_core::HRESULT, +} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct IVector(windows_core::IUnknown, core::marker::PhantomData) +where + T: windows_core::RuntimeType + 'static; +impl windows_core::imp::CanInto + for IVector +{ +} +impl windows_core::imp::CanInto + for IVector +{ +} +unsafe impl windows_core::Interface for IVector { + type Vtable = IVector_Vtbl; + const IID: windows_core::GUID = + windows_core::GUID::from_signature(::SIGNATURE); +} +impl windows_core::RuntimeType for IVector { + const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::new() + .push_slice(b"pinterface({913337e9-11a1-4345-a3a2-4e7f956e222d}") + .push_slice(b";") + .push_other(T::SIGNATURE) + .push_slice(b")"); +} +impl windows_core::imp::CanInto> + for IVector +{ + const QUERY: bool = true; +} +impl IVector { + pub fn GetAt(&self, index: u32) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).GetAt)( + windows_core::Interface::as_raw(this), + index, + &mut result__, + ) + .and_then(|| windows_core::Type::from_abi(result__)) + } + } + pub fn Size(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Size)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn IndexOf(&self, value: P0, index: &mut u32) -> windows_core::Result + where + P0: windows_core::Param, + { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).IndexOf)( + windows_core::Interface::as_raw(this), + value.param().abi(), + index, + &mut result__, + ) + .map(|| result__) + } + } + pub fn SetAt(&self, index: u32, value: P1) -> windows_core::Result<()> + where + P1: windows_core::Param, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).SetAt)( + windows_core::Interface::as_raw(this), + index, + value.param().abi(), + ) + .ok() + } + } + pub fn InsertAt(&self, index: u32, value: P1) -> windows_core::Result<()> + where + P1: windows_core::Param, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).InsertAt)( + windows_core::Interface::as_raw(this), + index, + value.param().abi(), + ) + .ok() + } + } + pub fn RemoveAt(&self, index: u32) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).RemoveAt)( + windows_core::Interface::as_raw(this), + index, + ) + .ok() + } + } + pub fn Append(&self, value: P0) -> windows_core::Result<()> + where + P0: windows_core::Param, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Append)( + windows_core::Interface::as_raw(this), + value.param().abi(), + ) + .ok() + } + } + pub fn RemoveAtEnd(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).RemoveAtEnd)(windows_core::Interface::as_raw( + this, + )) + .ok() + } + } + pub fn Clear(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Clear)(windows_core::Interface::as_raw(this)) + .ok() + } + } + pub fn GetMany( + &self, + startindex: u32, + items: &mut [>::Default], + ) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).GetMany)( + windows_core::Interface::as_raw(this), + startindex, + items.len().try_into().unwrap(), + core::mem::transmute_copy(&items), + &mut result__, + ) + .map(|| result__) + } + } + pub fn ReplaceAll( + &self, + items: &[>::Default], + ) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).ReplaceAll)( + windows_core::Interface::as_raw(this), + items.len().try_into().unwrap(), + core::mem::transmute(items.as_ptr()), + ) + .ok() + } + } + pub fn First(&self) -> windows_core::Result> { + let this = &windows_core::Interface::cast::>(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).First)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .and_then(|| windows_core::Type::from_abi(result__)) + } + } +} +impl IntoIterator for IVector { + type Item = T; + type IntoIter = IIterator; + fn into_iter(self) -> Self::IntoIter { + IntoIterator::into_iter(&self) + } +} +impl IntoIterator for &IVector { + type Item = T; + type IntoIter = IIterator; + fn into_iter(self) -> Self::IntoIter { + self.First().unwrap() + } +} +impl windows_core::RuntimeName for IVector { + const NAME: &'static str = "Windows.Foundation.Collections.IVector"; +} +pub trait IVector_Impl: IIterable_Impl +where + T: windows_core::RuntimeType + 'static, +{ + fn GetAt(&self, index: u32) -> windows_core::Result; + fn Size(&self) -> windows_core::Result; + fn IndexOf( + &self, + value: windows_core::Ref<'_, T>, + index: &mut u32, + ) -> windows_core::Result; + fn SetAt(&self, index: u32, value: windows_core::Ref<'_, T>) -> windows_core::Result<()>; + fn InsertAt(&self, index: u32, value: windows_core::Ref<'_, T>) -> windows_core::Result<()>; + fn RemoveAt(&self, index: u32) -> windows_core::Result<()>; + fn Append(&self, value: windows_core::Ref<'_, T>) -> windows_core::Result<()>; + fn RemoveAtEnd(&self) -> windows_core::Result<()>; + fn Clear(&self) -> windows_core::Result<()>; + fn GetMany( + &self, + startIndex: u32, + items: &mut [>::Default], + ) -> windows_core::Result; + fn ReplaceAll( + &self, + items: &[>::Default], + ) -> windows_core::Result<()>; +} +impl IVector_Vtbl { + pub const fn new, const OFFSET: isize>() -> Self { + unsafe extern "system" fn GetAt< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + index: u32, + result__: *mut windows_core::AbiType, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IVector_Impl::GetAt(this, index) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + core::mem::forget(ok__); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn Size< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut u32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IVector_Impl::Size(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn IndexOf< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: windows_core::AbiType, + index: *mut u32, + result__: *mut bool, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IVector_Impl::IndexOf( + this, + core::mem::transmute_copy(&value), + core::mem::transmute_copy(&index), + ) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn SetAt< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + index: u32, + value: windows_core::AbiType, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::SetAt(this, index, core::mem::transmute_copy(&value)).into() + } + } + unsafe extern "system" fn InsertAt< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + index: u32, + value: windows_core::AbiType, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::InsertAt(this, index, core::mem::transmute_copy(&value)).into() + } + } + unsafe extern "system" fn RemoveAt< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + index: u32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::RemoveAt(this, index).into() + } + } + unsafe extern "system" fn Append< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: windows_core::AbiType, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::Append(this, core::mem::transmute_copy(&value)).into() + } + } + unsafe extern "system" fn RemoveAtEnd< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::RemoveAtEnd(this).into() + } + } + unsafe extern "system" fn Clear< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::Clear(this).into() + } + } + unsafe extern "system" fn GetMany< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + startindex: u32, + items_array_size: u32, + items: *mut T, + result__: *mut u32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IVector_Impl::GetMany( + this, + startindex, + core::slice::from_raw_parts_mut( + core::mem::transmute_copy(&items), + items_array_size as usize, + ), + ) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn ReplaceAll< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + items_array_size: u32, + items: *const T, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::ReplaceAll( + this, + core::slice::from_raw_parts( + core::mem::transmute_copy(&items), + items_array_size as usize, + ), + ) + .into() + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::, OFFSET>(), + GetAt: GetAt::, + Size: Size::, + GetView: 0, + IndexOf: IndexOf::, + SetAt: SetAt::, + InsertAt: InsertAt::, + RemoveAt: RemoveAt::, + Append: Append::, + RemoveAtEnd: RemoveAtEnd::, + Clear: Clear::, + GetMany: GetMany::, + ReplaceAll: ReplaceAll::, + T: core::marker::PhantomData::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == & as windows_core::Interface>::IID + } +} +#[repr(C)] +pub struct IVector_Vtbl +where + T: windows_core::RuntimeType + 'static, +{ + pub base__: windows_core::IInspectable_Vtbl, + pub GetAt: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + *mut windows_core::AbiType, + ) -> windows_core::HRESULT, + pub Size: unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32) -> windows_core::HRESULT, + GetView: usize, + pub IndexOf: unsafe extern "system" fn( + *mut core::ffi::c_void, + windows_core::AbiType, + *mut u32, + *mut bool, + ) -> windows_core::HRESULT, + pub SetAt: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + windows_core::AbiType, + ) -> windows_core::HRESULT, + pub InsertAt: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + windows_core::AbiType, + ) -> windows_core::HRESULT, + pub RemoveAt: unsafe extern "system" fn(*mut core::ffi::c_void, u32) -> windows_core::HRESULT, + pub Append: unsafe extern "system" fn( + *mut core::ffi::c_void, + windows_core::AbiType, + ) -> windows_core::HRESULT, + pub RemoveAtEnd: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + pub Clear: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + pub GetMany: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + u32, + *mut T, + *mut u32, + ) -> windows_core::HRESULT, + pub ReplaceAll: + unsafe extern "system" fn(*mut core::ffi::c_void, u32, *const T) -> windows_core::HRESULT, + T: core::marker::PhantomData, +} +#[repr(C)] +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct Vector2 { + pub X: f32, + pub Y: f32, +} +impl windows_core::TypeKind for Vector2 { + type TypeKind = windows_core::CopyType; +} +impl windows_core::RuntimeType for Vector2 { + const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::from_slice( + b"struct(Windows.Foundation.Numerics.Vector2;f4;f4)", + ); +} diff --git a/crates/tests/winrt/reference_default/src/lib.rs b/crates/tests/winrt/reference_custom/src/lib.rs similarity index 100% rename from crates/tests/winrt/reference_default/src/lib.rs rename to crates/tests/winrt/reference_custom/src/lib.rs diff --git a/crates/tests/winrt/reference_default/src/test.idl b/crates/tests/winrt/reference_custom/src/test.idl similarity index 100% rename from crates/tests/winrt/reference_default/src/test.idl rename to crates/tests/winrt/reference_custom/src/test.idl diff --git a/crates/tests/winrt/reference_no_deps/Cargo.toml b/crates/tests/winrt/reference_no_deps/Cargo.toml new file mode 100644 index 0000000000..244e28e5b6 --- /dev/null +++ b/crates/tests/winrt/reference_no_deps/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "test_reference_no_deps" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +doc = false +doctest = false + +[dependencies.windows-core] +workspace = true + +[build-dependencies.windows-bindgen] +workspace = true diff --git a/crates/tests/winrt/reference_no_deps/build.rs b/crates/tests/winrt/reference_no_deps/build.rs new file mode 100644 index 0000000000..3c147390c4 --- /dev/null +++ b/crates/tests/winrt/reference_no_deps/build.rs @@ -0,0 +1,39 @@ +fn main() { + println!("cargo:rerun-if-changed=src/test.idl"); + 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", + "test.winmd", + "src/test.idl", + ]); + + if !command.status().unwrap().success() { + panic!("Failed to run midlrt"); + } + + windows_bindgen::bindgen([ + "--in", + "default", + "test.winmd", + "--out", + "src/bindings.rs", + "--filter", + "Test", + "IStringable", + "Vector2", + "IVector", + "IAsyncAction", + "--implement", + "--flat", + "--no-deps", + ]); +} diff --git a/crates/tests/winrt/reference_no_deps/src/bindings.rs b/crates/tests/winrt/reference_no_deps/src/bindings.rs new file mode 100644 index 0000000000..ed3e6ef2fa --- /dev/null +++ b/crates/tests/winrt/reference_no_deps/src/bindings.rs @@ -0,0 +1,1309 @@ +// Bindings generated by `windows-bindgen` 0.59.0 + +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +windows_core::imp::define_interface!( + IAsyncAction, + IAsyncAction_Vtbl, + 0x5a648006_843a_4da9_865b_9d26e5dfad7b +); +impl windows_core::RuntimeType for IAsyncAction { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +windows_core::imp::interface_hierarchy!( + IAsyncAction, + windows_core::IUnknown, + windows_core::IInspectable +); +windows_core::imp::required_hierarchy!(IAsyncAction, IAsyncInfo); +impl IAsyncAction { + pub fn GetResults(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw( + this, + )) + .ok() + } + } + pub fn Id(&self) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Id)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn ErrorCode(&self) -> windows_core::Result { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).ErrorCode)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn Cancel(&self) -> windows_core::Result<()> { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)) + .ok() + } + } + pub fn Close(&self) -> windows_core::Result<()> { + let this = &windows_core::Interface::cast::(self)?; + unsafe { + (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)) + .ok() + } + } +} +unsafe impl Send for IAsyncAction {} +unsafe impl Sync for IAsyncAction {} +impl windows_core::RuntimeName for IAsyncAction { + const NAME: &'static str = "Windows.Foundation.IAsyncAction"; +} +pub trait IAsyncAction_Impl: IAsyncInfo_Impl { + fn GetResults(&self) -> windows_core::Result<()>; +} +impl IAsyncAction_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn GetResults( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IAsyncAction_Impl::GetResults(this).into() + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + SetCompleted: 0, + Completed: 0, + GetResults: GetResults::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct IAsyncAction_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + SetCompleted: usize, + Completed: usize, + pub GetResults: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!( + IAsyncInfo, + IAsyncInfo_Vtbl, + 0x00000036_0000_0000_c000_000000000046 +); +impl windows_core::RuntimeType for IAsyncInfo { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +windows_core::imp::interface_hierarchy!( + IAsyncInfo, + windows_core::IUnknown, + windows_core::IInspectable +); +impl IAsyncInfo { + pub fn Id(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Id)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn ErrorCode(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).ErrorCode)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn Cancel(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)) + .ok() + } + } + pub fn Close(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)) + .ok() + } + } +} +impl windows_core::RuntimeName for IAsyncInfo { + const NAME: &'static str = "Windows.Foundation.IAsyncInfo"; +} +pub trait IAsyncInfo_Impl: windows_core::IUnknownImpl { + fn Id(&self) -> windows_core::Result; + fn ErrorCode(&self) -> windows_core::Result; + fn Cancel(&self) -> windows_core::Result<()>; + fn Close(&self) -> windows_core::Result<()>; +} +impl IAsyncInfo_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn Id( + this: *mut core::ffi::c_void, + result__: *mut u32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IAsyncInfo_Impl::Id(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn ErrorCode( + this: *mut core::ffi::c_void, + result__: *mut windows_core::HRESULT, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IAsyncInfo_Impl::ErrorCode(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn Cancel( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IAsyncInfo_Impl::Cancel(this).into() + } + } + unsafe extern "system" fn Close( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IAsyncInfo_Impl::Close(this).into() + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + Id: Id::, + Status: 0, + ErrorCode: ErrorCode::, + Cancel: Cancel::, + Close: Close::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +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, + Status: usize, + pub ErrorCode: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut windows_core::HRESULT, + ) -> windows_core::HRESULT, + pub Cancel: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + pub Close: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, +} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct IIterable(windows_core::IUnknown, core::marker::PhantomData) +where + T: windows_core::RuntimeType + 'static; +impl windows_core::imp::CanInto + for IIterable +{ +} +impl windows_core::imp::CanInto + for IIterable +{ +} +unsafe impl windows_core::Interface for IIterable { + type Vtable = IIterable_Vtbl; + const IID: windows_core::GUID = + windows_core::GUID::from_signature(::SIGNATURE); +} +impl windows_core::RuntimeType for IIterable { + const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::new() + .push_slice(b"pinterface({faa585ea-6214-4217-afda-7f46de5869b3}") + .push_slice(b";") + .push_other(T::SIGNATURE) + .push_slice(b")"); +} +impl IIterable { + pub fn First(&self) -> windows_core::Result> { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).First)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .and_then(|| windows_core::Type::from_abi(result__)) + } + } +} +impl windows_core::RuntimeName for IIterable { + const NAME: &'static str = "Windows.Foundation.Collections.IIterable"; +} +pub trait IIterable_Impl: windows_core::IUnknownImpl +where + T: windows_core::RuntimeType + 'static, +{ + fn First(&self) -> windows_core::Result>; +} +impl IIterable_Vtbl { + pub const fn new, const OFFSET: isize>() -> Self { + unsafe extern "system" fn First< + T: windows_core::RuntimeType + 'static, + Identity: IIterable_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IIterable_Impl::First(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + core::mem::forget(ok__); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::, OFFSET>(), + First: First::, + T: core::marker::PhantomData::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == & as windows_core::Interface>::IID + } +} +#[repr(C)] +pub struct IIterable_Vtbl +where + T: windows_core::RuntimeType + 'static, +{ + pub base__: windows_core::IInspectable_Vtbl, + pub First: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT, + T: core::marker::PhantomData, +} +impl IntoIterator for IIterable { + type Item = T; + type IntoIter = IIterator; + fn into_iter(self) -> Self::IntoIter { + IntoIterator::into_iter(&self) + } +} +impl IntoIterator for &IIterable { + type Item = T; + type IntoIter = IIterator; + fn into_iter(self) -> Self::IntoIter { + self.First().unwrap() + } +} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct IIterator(windows_core::IUnknown, core::marker::PhantomData) +where + T: windows_core::RuntimeType + 'static; +impl windows_core::imp::CanInto + for IIterator +{ +} +impl windows_core::imp::CanInto + for IIterator +{ +} +unsafe impl windows_core::Interface for IIterator { + type Vtable = IIterator_Vtbl; + const IID: windows_core::GUID = + windows_core::GUID::from_signature(::SIGNATURE); +} +impl windows_core::RuntimeType for IIterator { + const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::new() + .push_slice(b"pinterface({6a79e863-4300-459a-9966-cbb660963ee1}") + .push_slice(b";") + .push_other(T::SIGNATURE) + .push_slice(b")"); +} +impl IIterator { + pub fn Current(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Current)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .and_then(|| windows_core::Type::from_abi(result__)) + } + } + pub fn HasCurrent(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).HasCurrent)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn MoveNext(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).MoveNext)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn GetMany( + &self, + items: &mut [>::Default], + ) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).GetMany)( + windows_core::Interface::as_raw(this), + items.len().try_into().unwrap(), + core::mem::transmute_copy(&items), + &mut result__, + ) + .map(|| result__) + } + } +} +impl windows_core::RuntimeName for IIterator { + const NAME: &'static str = "Windows.Foundation.Collections.IIterator"; +} +pub trait IIterator_Impl: windows_core::IUnknownImpl +where + T: windows_core::RuntimeType + 'static, +{ + fn Current(&self) -> windows_core::Result; + fn HasCurrent(&self) -> windows_core::Result; + fn MoveNext(&self) -> windows_core::Result; + fn GetMany( + &self, + items: &mut [>::Default], + ) -> windows_core::Result; +} +impl IIterator_Vtbl { + pub const fn new, const OFFSET: isize>() -> Self { + unsafe extern "system" fn Current< + T: windows_core::RuntimeType + 'static, + Identity: IIterator_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut windows_core::AbiType, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IIterator_Impl::Current(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + core::mem::forget(ok__); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn HasCurrent< + T: windows_core::RuntimeType + 'static, + Identity: IIterator_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IIterator_Impl::HasCurrent(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn MoveNext< + T: windows_core::RuntimeType + 'static, + Identity: IIterator_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IIterator_Impl::MoveNext(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn GetMany< + T: windows_core::RuntimeType + 'static, + Identity: IIterator_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + items_array_size: u32, + items: *mut T, + result__: *mut u32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IIterator_Impl::GetMany( + this, + core::slice::from_raw_parts_mut( + core::mem::transmute_copy(&items), + items_array_size as usize, + ), + ) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::, OFFSET>(), + Current: Current::, + HasCurrent: HasCurrent::, + MoveNext: MoveNext::, + GetMany: GetMany::, + T: core::marker::PhantomData::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == & as windows_core::Interface>::IID + } +} +#[repr(C)] +pub struct IIterator_Vtbl +where + T: windows_core::RuntimeType + 'static, +{ + pub base__: windows_core::IInspectable_Vtbl, + pub Current: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut windows_core::AbiType, + ) -> windows_core::HRESULT, + pub HasCurrent: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut bool) -> windows_core::HRESULT, + pub MoveNext: + unsafe extern "system" fn(*mut core::ffi::c_void, *mut bool) -> windows_core::HRESULT, + pub GetMany: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + *mut T, + *mut u32, + ) -> windows_core::HRESULT, + T: core::marker::PhantomData, +} +impl Iterator for IIterator { + type Item = T; + fn next(&mut self) -> Option { + let result = if self.HasCurrent().unwrap_or(false) { + self.Current().ok() + } else { + None + }; + if result.is_some() { + self.MoveNext().ok()?; + } + result + } +} +windows_core::imp::define_interface!( + IStringable, + IStringable_Vtbl, + 0x96369f54_8eb6_48f0_abce_c1b211e627c3 +); +impl windows_core::RuntimeType for IStringable { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +windows_core::imp::interface_hierarchy!( + IStringable, + windows_core::IUnknown, + windows_core::IInspectable +); +impl IStringable { + pub fn ToString(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).ToString)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| core::mem::transmute(result__)) + } + } +} +impl windows_core::RuntimeName for IStringable { + const NAME: &'static str = "Windows.Foundation.IStringable"; +} +pub trait IStringable_Impl: windows_core::IUnknownImpl { + fn ToString(&self) -> windows_core::Result; +} +impl IStringable_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn ToString( + this: *mut core::ffi::c_void, + result__: *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IStringable_Impl::ToString(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + core::mem::forget(ok__); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + ToString: ToString::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct IStringable_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub ToString: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(ITest, ITest_Vtbl, 0x92862ee6_aff5_58df_8c9e_7e82f8aefe6b); +impl windows_core::RuntimeType for ITest { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +windows_core::imp::interface_hierarchy!(ITest, windows_core::IUnknown, windows_core::IInspectable); +impl ITest { + pub fn Numerics(&self, n: Vector2) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Numerics)( + windows_core::Interface::as_raw(this), + n, + ) + .ok() + } + } + pub fn Collections(&self, c: P0) -> windows_core::Result<()> + where + P0: windows_core::Param>, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Collections)( + windows_core::Interface::as_raw(this), + c.param().abi(), + ) + .ok() + } + } + pub fn Async(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Async)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .and_then(|| windows_core::Type::from_abi(result__)) + } + } + pub fn Windows(&self, s: P0) -> windows_core::Result<()> + where + P0: windows_core::Param, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Windows)( + windows_core::Interface::as_raw(this), + s.param().abi(), + ) + .ok() + } + } +} +impl windows_core::RuntimeName for ITest { + const NAME: &'static str = "Test.ITest"; +} +pub trait ITest_Impl: windows_core::IUnknownImpl { + fn Numerics(&self, n: &Vector2) -> windows_core::Result<()>; + fn Collections(&self, c: windows_core::Ref<'_, IVector>) -> windows_core::Result<()>; + fn Async(&self) -> windows_core::Result; + fn Windows(&self, s: windows_core::Ref<'_, IStringable>) -> windows_core::Result<()>; +} +impl ITest_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn Numerics( + this: *mut core::ffi::c_void, + n: Vector2, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + ITest_Impl::Numerics(this, core::mem::transmute(&n)).into() + } + } + unsafe extern "system" fn Collections( + this: *mut core::ffi::c_void, + c: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + ITest_Impl::Collections(this, core::mem::transmute_copy(&c)).into() + } + } + unsafe extern "system" fn Async( + this: *mut core::ffi::c_void, + result__: *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match ITest_Impl::Async(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + core::mem::forget(ok__); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn Windows( + this: *mut core::ffi::c_void, + s: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + ITest_Impl::Windows(this, core::mem::transmute_copy(&s)).into() + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + Numerics: Numerics::, + Collections: Collections::, + Async: Async::, + Windows: Windows::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct ITest_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Numerics: + unsafe extern "system" fn(*mut core::ffi::c_void, Vector2) -> windows_core::HRESULT, + pub Collections: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut core::ffi::c_void, + ) -> windows_core::HRESULT, + pub Async: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT, + pub Windows: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut core::ffi::c_void, + ) -> windows_core::HRESULT, +} +#[repr(transparent)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct IVector(windows_core::IUnknown, core::marker::PhantomData) +where + T: windows_core::RuntimeType + 'static; +impl windows_core::imp::CanInto + for IVector +{ +} +impl windows_core::imp::CanInto + for IVector +{ +} +unsafe impl windows_core::Interface for IVector { + type Vtable = IVector_Vtbl; + const IID: windows_core::GUID = + windows_core::GUID::from_signature(::SIGNATURE); +} +impl windows_core::RuntimeType for IVector { + const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::new() + .push_slice(b"pinterface({913337e9-11a1-4345-a3a2-4e7f956e222d}") + .push_slice(b";") + .push_other(T::SIGNATURE) + .push_slice(b")"); +} +impl windows_core::imp::CanInto> + for IVector +{ + const QUERY: bool = true; +} +impl IVector { + pub fn GetAt(&self, index: u32) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).GetAt)( + windows_core::Interface::as_raw(this), + index, + &mut result__, + ) + .and_then(|| windows_core::Type::from_abi(result__)) + } + } + pub fn Size(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Size)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + } + } + pub fn IndexOf(&self, value: P0, index: &mut u32) -> windows_core::Result + where + P0: windows_core::Param, + { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).IndexOf)( + windows_core::Interface::as_raw(this), + value.param().abi(), + index, + &mut result__, + ) + .map(|| result__) + } + } + pub fn SetAt(&self, index: u32, value: P1) -> windows_core::Result<()> + where + P1: windows_core::Param, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).SetAt)( + windows_core::Interface::as_raw(this), + index, + value.param().abi(), + ) + .ok() + } + } + pub fn InsertAt(&self, index: u32, value: P1) -> windows_core::Result<()> + where + P1: windows_core::Param, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).InsertAt)( + windows_core::Interface::as_raw(this), + index, + value.param().abi(), + ) + .ok() + } + } + pub fn RemoveAt(&self, index: u32) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).RemoveAt)( + windows_core::Interface::as_raw(this), + index, + ) + .ok() + } + } + pub fn Append(&self, value: P0) -> windows_core::Result<()> + where + P0: windows_core::Param, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Append)( + windows_core::Interface::as_raw(this), + value.param().abi(), + ) + .ok() + } + } + pub fn RemoveAtEnd(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).RemoveAtEnd)(windows_core::Interface::as_raw( + this, + )) + .ok() + } + } + pub fn Clear(&self) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Clear)(windows_core::Interface::as_raw(this)) + .ok() + } + } + pub fn GetMany( + &self, + startindex: u32, + items: &mut [>::Default], + ) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).GetMany)( + windows_core::Interface::as_raw(this), + startindex, + items.len().try_into().unwrap(), + core::mem::transmute_copy(&items), + &mut result__, + ) + .map(|| result__) + } + } + pub fn ReplaceAll( + &self, + items: &[>::Default], + ) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).ReplaceAll)( + windows_core::Interface::as_raw(this), + items.len().try_into().unwrap(), + core::mem::transmute(items.as_ptr()), + ) + .ok() + } + } + pub fn First(&self) -> windows_core::Result> { + let this = &windows_core::Interface::cast::>(self)?; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).First)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .and_then(|| windows_core::Type::from_abi(result__)) + } + } +} +impl IntoIterator for IVector { + type Item = T; + type IntoIter = IIterator; + fn into_iter(self) -> Self::IntoIter { + IntoIterator::into_iter(&self) + } +} +impl IntoIterator for &IVector { + type Item = T; + type IntoIter = IIterator; + fn into_iter(self) -> Self::IntoIter { + self.First().unwrap() + } +} +impl windows_core::RuntimeName for IVector { + const NAME: &'static str = "Windows.Foundation.Collections.IVector"; +} +pub trait IVector_Impl: IIterable_Impl +where + T: windows_core::RuntimeType + 'static, +{ + fn GetAt(&self, index: u32) -> windows_core::Result; + fn Size(&self) -> windows_core::Result; + fn IndexOf( + &self, + value: windows_core::Ref<'_, T>, + index: &mut u32, + ) -> windows_core::Result; + fn SetAt(&self, index: u32, value: windows_core::Ref<'_, T>) -> windows_core::Result<()>; + fn InsertAt(&self, index: u32, value: windows_core::Ref<'_, T>) -> windows_core::Result<()>; + fn RemoveAt(&self, index: u32) -> windows_core::Result<()>; + fn Append(&self, value: windows_core::Ref<'_, T>) -> windows_core::Result<()>; + fn RemoveAtEnd(&self) -> windows_core::Result<()>; + fn Clear(&self) -> windows_core::Result<()>; + fn GetMany( + &self, + startIndex: u32, + items: &mut [>::Default], + ) -> windows_core::Result; + fn ReplaceAll( + &self, + items: &[>::Default], + ) -> windows_core::Result<()>; +} +impl IVector_Vtbl { + pub const fn new, const OFFSET: isize>() -> Self { + unsafe extern "system" fn GetAt< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + index: u32, + result__: *mut windows_core::AbiType, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IVector_Impl::GetAt(this, index) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + core::mem::forget(ok__); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn Size< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut u32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IVector_Impl::Size(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn IndexOf< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: windows_core::AbiType, + index: *mut u32, + result__: *mut bool, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IVector_Impl::IndexOf( + this, + core::mem::transmute_copy(&value), + core::mem::transmute_copy(&index), + ) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn SetAt< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + index: u32, + value: windows_core::AbiType, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::SetAt(this, index, core::mem::transmute_copy(&value)).into() + } + } + unsafe extern "system" fn InsertAt< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + index: u32, + value: windows_core::AbiType, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::InsertAt(this, index, core::mem::transmute_copy(&value)).into() + } + } + unsafe extern "system" fn RemoveAt< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + index: u32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::RemoveAt(this, index).into() + } + } + unsafe extern "system" fn Append< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: windows_core::AbiType, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::Append(this, core::mem::transmute_copy(&value)).into() + } + } + unsafe extern "system" fn RemoveAtEnd< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::RemoveAtEnd(this).into() + } + } + unsafe extern "system" fn Clear< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::Clear(this).into() + } + } + unsafe extern "system" fn GetMany< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + startindex: u32, + items_array_size: u32, + items: *mut T, + result__: *mut u32, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IVector_Impl::GetMany( + this, + startindex, + core::slice::from_raw_parts_mut( + core::mem::transmute_copy(&items), + items_array_size as usize, + ), + ) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn ReplaceAll< + T: windows_core::RuntimeType + 'static, + Identity: IVector_Impl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + items_array_size: u32, + items: *const T, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IVector_Impl::ReplaceAll( + this, + core::slice::from_raw_parts( + core::mem::transmute_copy(&items), + items_array_size as usize, + ), + ) + .into() + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::, OFFSET>(), + GetAt: GetAt::, + Size: Size::, + GetView: 0, + IndexOf: IndexOf::, + SetAt: SetAt::, + InsertAt: InsertAt::, + RemoveAt: RemoveAt::, + Append: Append::, + RemoveAtEnd: RemoveAtEnd::, + Clear: Clear::, + GetMany: GetMany::, + ReplaceAll: ReplaceAll::, + T: core::marker::PhantomData::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == & as windows_core::Interface>::IID + } +} +#[repr(C)] +pub struct IVector_Vtbl +where + T: windows_core::RuntimeType + 'static, +{ + pub base__: windows_core::IInspectable_Vtbl, + pub GetAt: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + *mut windows_core::AbiType, + ) -> windows_core::HRESULT, + pub Size: unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32) -> windows_core::HRESULT, + GetView: usize, + pub IndexOf: unsafe extern "system" fn( + *mut core::ffi::c_void, + windows_core::AbiType, + *mut u32, + *mut bool, + ) -> windows_core::HRESULT, + pub SetAt: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + windows_core::AbiType, + ) -> windows_core::HRESULT, + pub InsertAt: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + windows_core::AbiType, + ) -> windows_core::HRESULT, + pub RemoveAt: unsafe extern "system" fn(*mut core::ffi::c_void, u32) -> windows_core::HRESULT, + pub Append: unsafe extern "system" fn( + *mut core::ffi::c_void, + windows_core::AbiType, + ) -> windows_core::HRESULT, + pub RemoveAtEnd: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + pub Clear: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + pub GetMany: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + u32, + *mut T, + *mut u32, + ) -> windows_core::HRESULT, + pub ReplaceAll: + unsafe extern "system" fn(*mut core::ffi::c_void, u32, *const T) -> windows_core::HRESULT, + T: core::marker::PhantomData, +} +#[repr(C)] +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct Vector2 { + pub X: f32, + pub Y: f32, +} +impl windows_core::TypeKind for Vector2 { + type TypeKind = windows_core::CopyType; +} +impl windows_core::RuntimeType for Vector2 { + const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::from_slice( + b"struct(Windows.Foundation.Numerics.Vector2;f4;f4)", + ); +} diff --git a/crates/tests/winrt/reference_no_deps/src/lib.rs b/crates/tests/winrt/reference_no_deps/src/lib.rs new file mode 100644 index 0000000000..d67ec8857c --- /dev/null +++ b/crates/tests/winrt/reference_no_deps/src/lib.rs @@ -0,0 +1,2 @@ +mod bindings; +pub use bindings::*; diff --git a/crates/tests/winrt/reference_no_deps/src/test.idl b/crates/tests/winrt/reference_no_deps/src/test.idl new file mode 100644 index 0000000000..d774b3f07b --- /dev/null +++ b/crates/tests/winrt/reference_no_deps/src/test.idl @@ -0,0 +1,10 @@ +namespace Test +{ + interface ITest + { + void Numerics(Windows.Foundation.Numerics.Vector2 n); + void Collections(Windows.Foundation.Collections.IVector c); + Windows.Foundation.IAsyncAction Async(); + void Windows(Windows.Foundation.IStringable s); + } +} diff --git a/crates/tests/winrt/reference_no_windows/Cargo.toml b/crates/tests/winrt/reference_no_windows/Cargo.toml new file mode 100644 index 0000000000..5fb8f0f130 --- /dev/null +++ b/crates/tests/winrt/reference_no_windows/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "test_reference_no_windows" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +doc = false +doctest = false + +[dependencies.windows-core] +workspace = true + +[dependencies.windows-numerics] +workspace = true + +[dependencies.windows-collections] +workspace = true + +[dependencies.windows-future] +workspace = true + +[build-dependencies.windows-bindgen] +workspace = true diff --git a/crates/tests/winrt/reference_no_windows/build.rs b/crates/tests/winrt/reference_no_windows/build.rs new file mode 100644 index 0000000000..70b68090e3 --- /dev/null +++ b/crates/tests/winrt/reference_no_windows/build.rs @@ -0,0 +1,35 @@ +fn main() { + println!("cargo:rerun-if-changed=src/test.idl"); + 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", + "test.winmd", + "src/test.idl", + ]); + + if !command.status().unwrap().success() { + panic!("Failed to run midlrt"); + } + + windows_bindgen::bindgen([ + "--in", + "default", + "test.winmd", + "--out", + "src/bindings.rs", + "--filter", + "Test", + "IStringable", + "--implement", + "--flat", + ]); +} diff --git a/crates/tests/winrt/reference_no_windows/src/bindings.rs b/crates/tests/winrt/reference_no_windows/src/bindings.rs new file mode 100644 index 0000000000..fb21c35642 --- /dev/null +++ b/crates/tests/winrt/reference_no_windows/src/bindings.rs @@ -0,0 +1,227 @@ +// Bindings generated by `windows-bindgen` 0.59.0 + +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +windows_core::imp::define_interface!( + IStringable, + IStringable_Vtbl, + 0x96369f54_8eb6_48f0_abce_c1b211e627c3 +); +impl windows_core::RuntimeType for IStringable { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +windows_core::imp::interface_hierarchy!( + IStringable, + windows_core::IUnknown, + windows_core::IInspectable +); +impl IStringable { + pub fn ToString(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).ToString)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| core::mem::transmute(result__)) + } + } +} +impl windows_core::RuntimeName for IStringable { + const NAME: &'static str = "Windows.Foundation.IStringable"; +} +pub trait IStringable_Impl: windows_core::IUnknownImpl { + fn ToString(&self) -> windows_core::Result; +} +impl IStringable_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn ToString( + this: *mut core::ffi::c_void, + result__: *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IStringable_Impl::ToString(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + core::mem::forget(ok__); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + ToString: ToString::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct IStringable_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub ToString: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT, +} +windows_core::imp::define_interface!(ITest, ITest_Vtbl, 0x92862ee6_aff5_58df_8c9e_7e82f8aefe6b); +impl windows_core::RuntimeType for ITest { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); +} +windows_core::imp::interface_hierarchy!(ITest, windows_core::IUnknown, windows_core::IInspectable); +impl ITest { + pub fn Numerics(&self, n: windows_numerics::Vector2) -> windows_core::Result<()> { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Numerics)( + windows_core::Interface::as_raw(this), + n, + ) + .ok() + } + } + pub fn Collections(&self, c: P0) -> windows_core::Result<()> + where + P0: windows_core::Param>, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Collections)( + windows_core::Interface::as_raw(this), + c.param().abi(), + ) + .ok() + } + } + pub fn Async(&self) -> windows_core::Result { + let this = self; + unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Async)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .and_then(|| windows_core::Type::from_abi(result__)) + } + } + pub fn Windows(&self, s: P0) -> windows_core::Result<()> + where + P0: windows_core::Param, + { + let this = self; + unsafe { + (windows_core::Interface::vtable(this).Windows)( + windows_core::Interface::as_raw(this), + s.param().abi(), + ) + .ok() + } + } +} +impl windows_core::RuntimeName for ITest { + const NAME: &'static str = "Test.ITest"; +} +pub trait ITest_Impl: windows_core::IUnknownImpl { + fn Numerics(&self, n: &windows_numerics::Vector2) -> windows_core::Result<()>; + fn Collections( + &self, + c: windows_core::Ref<'_, windows_collections::IVector>, + ) -> windows_core::Result<()>; + fn Async(&self) -> windows_core::Result; + fn Windows(&self, s: windows_core::Ref<'_, IStringable>) -> windows_core::Result<()>; +} +impl ITest_Vtbl { + pub const fn new() -> Self { + unsafe extern "system" fn Numerics( + this: *mut core::ffi::c_void, + n: windows_numerics::Vector2, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + ITest_Impl::Numerics(this, core::mem::transmute(&n)).into() + } + } + unsafe extern "system" fn Collections( + this: *mut core::ffi::c_void, + c: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + ITest_Impl::Collections(this, core::mem::transmute_copy(&c)).into() + } + } + unsafe extern "system" fn Async( + this: *mut core::ffi::c_void, + result__: *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match ITest_Impl::Async(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + core::mem::forget(ok__); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + } + unsafe extern "system" fn Windows( + this: *mut core::ffi::c_void, + s: *mut core::ffi::c_void, + ) -> windows_core::HRESULT { + unsafe { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + ITest_Impl::Windows(this, core::mem::transmute_copy(&s)).into() + } + } + Self { + base__: windows_core::IInspectable_Vtbl::new::(), + Numerics: Numerics::, + Collections: Collections::, + Async: Async::, + Windows: Windows::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } +} +#[repr(C)] +pub struct ITest_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub Numerics: unsafe extern "system" fn( + *mut core::ffi::c_void, + windows_numerics::Vector2, + ) -> windows_core::HRESULT, + pub Collections: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut core::ffi::c_void, + ) -> windows_core::HRESULT, + pub Async: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT, + pub Windows: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut core::ffi::c_void, + ) -> windows_core::HRESULT, +} diff --git a/crates/tests/winrt/reference_no_windows/src/lib.rs b/crates/tests/winrt/reference_no_windows/src/lib.rs new file mode 100644 index 0000000000..d67ec8857c --- /dev/null +++ b/crates/tests/winrt/reference_no_windows/src/lib.rs @@ -0,0 +1,2 @@ +mod bindings; +pub use bindings::*; diff --git a/crates/tests/winrt/reference_no_windows/src/test.idl b/crates/tests/winrt/reference_no_windows/src/test.idl new file mode 100644 index 0000000000..d774b3f07b --- /dev/null +++ b/crates/tests/winrt/reference_no_windows/src/test.idl @@ -0,0 +1,10 @@ +namespace Test +{ + interface ITest + { + void Numerics(Windows.Foundation.Numerics.Vector2 n); + void Collections(Windows.Foundation.Collections.IVector c); + Windows.Foundation.IAsyncAction Async(); + void Windows(Windows.Foundation.IStringable s); + } +} diff --git a/crates/tests/winrt/reference_default/Cargo.toml b/crates/tests/winrt/reference_windows/Cargo.toml similarity index 92% rename from crates/tests/winrt/reference_default/Cargo.toml rename to crates/tests/winrt/reference_windows/Cargo.toml index 005e9ebfba..c681b7f247 100644 --- a/crates/tests/winrt/reference_default/Cargo.toml +++ b/crates/tests/winrt/reference_windows/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "test_reference_default" +name = "test_reference_windows" version = "0.0.0" edition = "2021" publish = false diff --git a/crates/tests/winrt/reference_default/build.rs b/crates/tests/winrt/reference_windows/build.rs similarity index 94% rename from crates/tests/winrt/reference_default/build.rs rename to crates/tests/winrt/reference_windows/build.rs index 35ecdad56c..3bafc98643 100644 --- a/crates/tests/winrt/reference_default/build.rs +++ b/crates/tests/winrt/reference_windows/build.rs @@ -31,6 +31,6 @@ fn main() { "--implement", "--flat", "--reference", - "windows,skip-root,Windows.Foundation", + "windows", ]); } diff --git a/crates/tests/winrt/reference_default/src/bindings.rs b/crates/tests/winrt/reference_windows/src/bindings.rs similarity index 100% rename from crates/tests/winrt/reference_default/src/bindings.rs rename to crates/tests/winrt/reference_windows/src/bindings.rs diff --git a/crates/tests/winrt/reference_windows/src/lib.rs b/crates/tests/winrt/reference_windows/src/lib.rs new file mode 100644 index 0000000000..d67ec8857c --- /dev/null +++ b/crates/tests/winrt/reference_windows/src/lib.rs @@ -0,0 +1,2 @@ +mod bindings; +pub use bindings::*; diff --git a/crates/tests/winrt/reference_windows/src/test.idl b/crates/tests/winrt/reference_windows/src/test.idl new file mode 100644 index 0000000000..d774b3f07b --- /dev/null +++ b/crates/tests/winrt/reference_windows/src/test.idl @@ -0,0 +1,10 @@ +namespace Test +{ + interface ITest + { + void Numerics(Windows.Foundation.Numerics.Vector2 n); + void Collections(Windows.Foundation.Collections.IVector c); + Windows.Foundation.IAsyncAction Async(); + void Windows(Windows.Foundation.IStringable s); + } +}