From 86792df7531a63c6ea818d68e8e134960d12f218 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sat, 29 Jan 2022 00:36:26 +0100 Subject: [PATCH 01/10] feat: add AgileReference --- .../libs/windows/src/core/agile_reference.rs | 32 +++++++ crates/libs/windows/src/core/bindings.rs | 91 +++++++++++++++++++ crates/libs/windows/src/core/mod.rs | 2 + crates/libs/windows/src/core/unknown.rs | 2 +- crates/tests/agile_reference/Cargo.toml | 13 +++ crates/tests/agile_reference/src/lib.rs | 1 + crates/tests/agile_reference/tests/tests.rs | 15 +++ crates/tools/bindings/src/main.rs | 3 + 8 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 crates/libs/windows/src/core/agile_reference.rs create mode 100644 crates/tests/agile_reference/Cargo.toml create mode 100644 crates/tests/agile_reference/src/lib.rs create mode 100644 crates/tests/agile_reference/tests/tests.rs diff --git a/crates/libs/windows/src/core/agile_reference.rs b/crates/libs/windows/src/core/agile_reference.rs new file mode 100644 index 0000000000..21e9b6d403 --- /dev/null +++ b/crates/libs/windows/src/core/agile_reference.rs @@ -0,0 +1,32 @@ +use super::*; +use bindings::*; +use core::marker::PhantomData; + +pub struct AgileReference { + reference: IAgileReference, + _marker: PhantomData, +} + +impl AgileReference { + pub fn new<'a, R>(from_ref: R) -> Result + where + R: IntoParam<'a, T> + IntoParam<'a, IUnknown>, + { + let reference = unsafe { RoGetAgileReference(AGILEREFERENCE_DEFAULT, &T::IID, from_ref)? }; + Ok(Self { reference, _marker: Default::default() }) + } + + pub fn resolve(&self) -> Result { + unsafe { + let mut ptr = core::ptr::null_mut(); + self.reference.Resolve(&T::IID, &mut ptr)?; + + let resolved = IUnknown(core::ptr::NonNull::new(ptr).ok_or_else(|| Error::from(E_NOINTERFACE))?); + + resolved.cast() + } + } +} + +unsafe impl Send for AgileReference {} +unsafe impl Sync for AgileReference {} diff --git a/crates/libs/windows/src/core/bindings.rs b/crates/libs/windows/src/core/bindings.rs index d206d01002..ae6d216473 100644 --- a/crates/libs/windows/src/core/bindings.rs +++ b/crates/libs/windows/src/core/bindings.rs @@ -2098,6 +2098,97 @@ pub unsafe fn WaitForSingleObject<'a, Param0: ::windows::core::IntoParam<'a, HAN unimplemented!("Unsupported target OS"); } #[repr(transparent)] +pub struct IAgileReference(::windows::core::IUnknown); +impl IAgileReference { + pub unsafe fn Resolve(&self, riid: *const ::windows::core::GUID, ppvobjectreference: *mut *mut ::core::ffi::c_void) -> ::windows::core::Result<()> { + (::windows::core::Interface::vtable(self).Resolve)(::core::mem::transmute_copy(self), ::core::mem::transmute(riid), ::core::mem::transmute(ppvobjectreference)).ok() + } +} +impl ::core::convert::From for ::windows::core::IUnknown { + fn from(value: IAgileReference) -> Self { + unsafe { ::core::mem::transmute(value) } + } +} +impl ::core::convert::From<&IAgileReference> for ::windows::core::IUnknown { + fn from(value: &IAgileReference) -> Self { + ::core::convert::From::from(::core::clone::Clone::clone(value)) + } +} +impl<'a> ::windows::core::IntoParam<'a, ::windows::core::IUnknown> for IAgileReference { + fn into_param(self) -> ::windows::core::Param<'a, ::windows::core::IUnknown> { + ::windows::core::Param::Owned(unsafe { ::core::mem::transmute(self) }) + } +} +impl<'a> ::windows::core::IntoParam<'a, ::windows::core::IUnknown> for &IAgileReference { + fn into_param(self) -> ::windows::core::Param<'a, ::windows::core::IUnknown> { + ::windows::core::Param::Borrowed(unsafe { ::core::mem::transmute(self) }) + } +} +impl ::core::clone::Clone for IAgileReference { + fn clone(&self) -> Self { + Self(self.0.clone()) + } +} +impl ::core::cmp::PartialEq for IAgileReference { + fn eq(&self, other: &Self) -> bool { + self.0 == other.0 + } +} +impl ::core::cmp::Eq for IAgileReference {} +impl ::core::fmt::Debug for IAgileReference { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_tuple("IAgileReference").field(&self.0).finish() + } +} +unsafe impl ::windows::core::Interface for IAgileReference { + type Vtable = IAgileReference_Vtbl; + const IID: ::windows::core::GUID = ::windows::core::GUID::from_u128(0xc03f6a43_65a4_9818_987e_e0b810d2a6f2); +} +#[repr(C)] +#[doc(hidden)] +pub struct IAgileReference_Vtbl { + pub base: ::windows::core::IUnknownVtbl, + pub Resolve: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, riid: *const ::windows::core::GUID, ppvobjectreference: *mut *mut ::core::ffi::c_void) -> ::windows::core::HRESULT, +} +#[repr(transparent)] +#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)] +pub struct AgileReferenceOptions(pub i32); +pub const AGILEREFERENCE_DEFAULT: AgileReferenceOptions = AgileReferenceOptions(0i32); +pub const AGILEREFERENCE_DELAYEDMARSHAL: AgileReferenceOptions = AgileReferenceOptions(1i32); +impl ::core::marker::Copy for AgileReferenceOptions {} +impl ::core::clone::Clone for AgileReferenceOptions { + fn clone(&self) -> Self { + *self + } +} +impl ::core::default::Default for AgileReferenceOptions { + fn default() -> Self { + Self(0) + } +} +unsafe impl ::windows::core::Abi for AgileReferenceOptions { + type Abi = Self; +} +impl ::core::fmt::Debug for AgileReferenceOptions { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_tuple("AgileReferenceOptions").field(&self.0).finish() + } +} +#[inline] +pub unsafe fn RoGetAgileReference<'a, Param2: ::windows::core::IntoParam<'a, ::windows::core::IUnknown>>(options: AgileReferenceOptions, riid: *const ::windows::core::GUID, punk: Param2) -> ::windows::core::Result { + #[cfg(windows)] + { + #[link(name = "windows")] + extern "system" { + fn RoGetAgileReference(options: AgileReferenceOptions, riid: *const ::windows::core::GUID, punk: *mut ::core::ffi::c_void, ppagilereference: *mut ::windows::core::RawPtr) -> ::windows::core::HRESULT; + } + let mut result__: ::windows::core::RawPtr = ::core::mem::zeroed(); + RoGetAgileReference(::core::mem::transmute(options), ::core::mem::transmute(riid), punk.into_param().abi(), ::core::mem::transmute(&mut result__)).from_abi::(result__) + } + #[cfg(not(windows))] + unimplemented!("Unsupported target OS"); +} +#[repr(transparent)] pub struct ILanguageExceptionErrorInfo(::windows::core::IUnknown); impl ILanguageExceptionErrorInfo { pub unsafe fn GetLanguageException(&self) -> ::windows::core::Result<::windows::core::IUnknown> { diff --git a/crates/libs/windows/src/core/mod.rs b/crates/libs/windows/src/core/mod.rs index 8625215db2..cf23f6f6e6 100644 --- a/crates/libs/windows/src/core/mod.rs +++ b/crates/libs/windows/src/core/mod.rs @@ -1,5 +1,6 @@ mod abi; mod activation_factory; +mod agile_reference; mod array; pub(crate) mod bindings; mod compose; @@ -28,6 +29,7 @@ mod weak_ref_count; pub use abi::*; #[doc(hidden)] pub use activation_factory::*; +pub use agile_reference::*; pub use array::*; #[doc(hidden)] pub use compose::*; diff --git a/crates/libs/windows/src/core/unknown.rs b/crates/libs/windows/src/core/unknown.rs index aa84728625..9651cc18ad 100644 --- a/crates/libs/windows/src/core/unknown.rs +++ b/crates/libs/windows/src/core/unknown.rs @@ -5,7 +5,7 @@ use super::*; /// under the hood to provide reference-counted lifetime management as well as the ability /// to query for additional interfaces that the object may implement. #[repr(transparent)] -pub struct IUnknown(core::ptr::NonNull); +pub struct IUnknown(pub(super) core::ptr::NonNull); #[doc(hidden)] #[repr(C)] diff --git a/crates/tests/agile_reference/Cargo.toml b/crates/tests/agile_reference/Cargo.toml new file mode 100644 index 0000000000..3a1efbbfdd --- /dev/null +++ b/crates/tests/agile_reference/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "agile_reference" +version = "0.0.0" +authors = ["Microsoft"] +edition = "2018" + +[dependencies.windows] +path = "../../libs/windows" +features = [ + "Foundation", + "Media_Control", + "Foundation_Collections" +] diff --git a/crates/tests/agile_reference/src/lib.rs b/crates/tests/agile_reference/src/lib.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/crates/tests/agile_reference/src/lib.rs @@ -0,0 +1 @@ + diff --git a/crates/tests/agile_reference/tests/tests.rs b/crates/tests/agile_reference/tests/tests.rs new file mode 100644 index 0000000000..0b4c3d1b20 --- /dev/null +++ b/crates/tests/agile_reference/tests/tests.rs @@ -0,0 +1,15 @@ +use windows::core::AgileReference; +use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager; + +#[test] +fn test() { + let manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().unwrap().get().unwrap(); + let reference = AgileReference::::new(manager).unwrap(); + + let handle = std::thread::spawn(move || { + let manager = reference.resolve().unwrap(); + + manager.GetSessions().unwrap(); + }); + handle.join().unwrap(); +} diff --git a/crates/tools/bindings/src/main.rs b/crates/tools/bindings/src/main.rs index 152d2361e6..833943c0fd 100644 --- a/crates/tools/bindings/src/main.rs +++ b/crates/tools/bindings/src/main.rs @@ -50,6 +50,9 @@ fn main() -> std::io::Result<()> { "Windows.Win32.System.Threading.CreateEventA", "Windows.Win32.System.Threading.SetEvent", "Windows.Win32.System.Threading.WaitForSingleObject", + "Windows.Win32.System.WinRT.IAgileReference", + "Windows.Win32.System.WinRT.AgileReferenceOptions", + "Windows.Win32.System.WinRT.RoGetAgileReference", "Windows.Win32.System.WinRT.ILanguageExceptionErrorInfo", "Windows.Win32.System.WinRT.ILanguageExceptionErrorInfo2", "Windows.Win32.System.WinRT.IRestrictedErrorInfo", From 4538e42eb4e7ad6fbc0ca5cd49fcd332203e1c5f Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sat, 29 Jan 2022 00:44:21 +0100 Subject: [PATCH 02/10] fix: ::new constraints --- crates/libs/windows/src/core/agile_reference.rs | 4 ++-- crates/tests/agile_reference/tests/tests.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/libs/windows/src/core/agile_reference.rs b/crates/libs/windows/src/core/agile_reference.rs index 21e9b6d403..e046ce24d6 100644 --- a/crates/libs/windows/src/core/agile_reference.rs +++ b/crates/libs/windows/src/core/agile_reference.rs @@ -8,9 +8,9 @@ pub struct AgileReference { } impl AgileReference { - pub fn new<'a, R>(from_ref: R) -> Result + pub fn new<'a>(from_ref: &'a T) -> Result where - R: IntoParam<'a, T> + IntoParam<'a, IUnknown>, + &'a T: IntoParam<'a, IUnknown>, { let reference = unsafe { RoGetAgileReference(AGILEREFERENCE_DEFAULT, &T::IID, from_ref)? }; Ok(Self { reference, _marker: Default::default() }) diff --git a/crates/tests/agile_reference/tests/tests.rs b/crates/tests/agile_reference/tests/tests.rs index 0b4c3d1b20..673a135614 100644 --- a/crates/tests/agile_reference/tests/tests.rs +++ b/crates/tests/agile_reference/tests/tests.rs @@ -4,7 +4,7 @@ use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager; #[test] fn test() { let manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().unwrap().get().unwrap(); - let reference = AgileReference::::new(manager).unwrap(); + let reference = AgileReference::new(&manager).unwrap(); let handle = std::thread::spawn(move || { let manager = reference.resolve().unwrap(); From 6f82da58d053b9500ce1253178737b64184dc7bd Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sat, 29 Jan 2022 11:07:14 +0100 Subject: [PATCH 03/10] fix: test crate --- .github/workflows/test.yml | 2 +- crates/tests/agile_reference/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2af12cc4f1..2bd7cf212e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -70,6 +70,7 @@ jobs: cargo test --target ${{ matrix.target }} -p windows_x86_64_gnu && cargo test --target ${{ matrix.target }} -p windows_x86_64_msvc && cargo test --target ${{ matrix.target }} -p test_agile && + cargo test --target ${{ matrix.target }} -p test_agile_reference && cargo test --target ${{ matrix.target }} -p test_alternate_success_code && cargo test --target ${{ matrix.target }} -p test_arch && cargo test --target ${{ matrix.target }} -p test_arch_feature && @@ -136,4 +137,3 @@ jobs: cargo test --target ${{ matrix.target }} -p test_implement_properties && cargo test --target ${{ matrix.target }} -p test_implement_winrt if: matrix.version == 'nightly' - \ No newline at end of file diff --git a/crates/tests/agile_reference/Cargo.toml b/crates/tests/agile_reference/Cargo.toml index 3a1efbbfdd..cbed3efda8 100644 --- a/crates/tests/agile_reference/Cargo.toml +++ b/crates/tests/agile_reference/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "agile_reference" +name = "test_agile_reference" version = "0.0.0" authors = ["Microsoft"] edition = "2018" From 8beb854ba7ca65383363cfd22d5c5ec032c907c1 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Mon, 31 Jan 2022 18:15:20 +0100 Subject: [PATCH 04/10] fix: use Result::map --- crates/libs/windows/src/core/agile_reference.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/libs/windows/src/core/agile_reference.rs b/crates/libs/windows/src/core/agile_reference.rs index e046ce24d6..0d0edb7143 100644 --- a/crates/libs/windows/src/core/agile_reference.rs +++ b/crates/libs/windows/src/core/agile_reference.rs @@ -12,8 +12,7 @@ impl AgileReference { where &'a T: IntoParam<'a, IUnknown>, { - let reference = unsafe { RoGetAgileReference(AGILEREFERENCE_DEFAULT, &T::IID, from_ref)? }; - Ok(Self { reference, _marker: Default::default() }) + unsafe { RoGetAgileReference(AGILEREFERENCE_DEFAULT, &T::IID, from_ref).map(|reference| Self { reference, _marker: Default::default() }) } } pub fn resolve(&self) -> Result { From 9e098d281d62d254265e82c5c5865712327b7bb8 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Tue, 1 Feb 2022 19:53:06 +0100 Subject: [PATCH 05/10] fix: update bindings to use the proper IAgileReference::Resolve --- crates/libs/windows/src/core/agile_reference.rs | 9 +-------- crates/libs/windows/src/core/bindings.rs | 5 +++-- crates/libs/windows/src/core/unknown.rs | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/crates/libs/windows/src/core/agile_reference.rs b/crates/libs/windows/src/core/agile_reference.rs index 0d0edb7143..f7ee4171eb 100644 --- a/crates/libs/windows/src/core/agile_reference.rs +++ b/crates/libs/windows/src/core/agile_reference.rs @@ -16,14 +16,7 @@ impl AgileReference { } pub fn resolve(&self) -> Result { - unsafe { - let mut ptr = core::ptr::null_mut(); - self.reference.Resolve(&T::IID, &mut ptr)?; - - let resolved = IUnknown(core::ptr::NonNull::new(ptr).ok_or_else(|| Error::from(E_NOINTERFACE))?); - - resolved.cast() - } + unsafe { self.reference.Resolve() } } } diff --git a/crates/libs/windows/src/core/bindings.rs b/crates/libs/windows/src/core/bindings.rs index ae6d216473..ae40145ec7 100644 --- a/crates/libs/windows/src/core/bindings.rs +++ b/crates/libs/windows/src/core/bindings.rs @@ -2100,8 +2100,9 @@ pub unsafe fn WaitForSingleObject<'a, Param0: ::windows::core::IntoParam<'a, HAN #[repr(transparent)] pub struct IAgileReference(::windows::core::IUnknown); impl IAgileReference { - pub unsafe fn Resolve(&self, riid: *const ::windows::core::GUID, ppvobjectreference: *mut *mut ::core::ffi::c_void) -> ::windows::core::Result<()> { - (::windows::core::Interface::vtable(self).Resolve)(::core::mem::transmute_copy(self), ::core::mem::transmute(riid), ::core::mem::transmute(ppvobjectreference)).ok() + pub unsafe fn Resolve(&self) -> ::windows::core::Result { + let mut result__ = ::core::option::Option::None; + (::windows::core::Interface::vtable(self).Resolve)(::core::mem::transmute_copy(self), &::IID, &mut result__ as *mut _ as *mut _).and_some(result__) } } impl ::core::convert::From for ::windows::core::IUnknown { diff --git a/crates/libs/windows/src/core/unknown.rs b/crates/libs/windows/src/core/unknown.rs index 9651cc18ad..aa84728625 100644 --- a/crates/libs/windows/src/core/unknown.rs +++ b/crates/libs/windows/src/core/unknown.rs @@ -5,7 +5,7 @@ use super::*; /// under the hood to provide reference-counted lifetime management as well as the ability /// to query for additional interfaces that the object may implement. #[repr(transparent)] -pub struct IUnknown(pub(super) core::ptr::NonNull); +pub struct IUnknown(core::ptr::NonNull); #[doc(hidden)] #[repr(C)] From 29e150f6e47e076a0523340652f46af80dffca02 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Tue, 1 Feb 2022 20:43:33 +0100 Subject: [PATCH 06/10] docs: add basic documentation for `AgileReference` --- crates/libs/windows/src/core/agile_reference.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/libs/windows/src/core/agile_reference.rs b/crates/libs/windows/src/core/agile_reference.rs index f7ee4171eb..1eba0baa24 100644 --- a/crates/libs/windows/src/core/agile_reference.rs +++ b/crates/libs/windows/src/core/agile_reference.rs @@ -2,12 +2,17 @@ use super::*; use bindings::*; use core::marker::PhantomData; +/// A safe wrapper around WinRT interfaces. +/// +/// Some interfaces are not marked as agile thus then don't implement [`Send`]. +/// These interfaces can be made agile through this `AgileReference`. pub struct AgileReference { reference: IAgileReference, _marker: PhantomData, } impl AgileReference { + /// Creates a new wrapper around the reference pub fn new<'a>(from_ref: &'a T) -> Result where &'a T: IntoParam<'a, IUnknown>, @@ -15,6 +20,7 @@ impl AgileReference { unsafe { RoGetAgileReference(AGILEREFERENCE_DEFAULT, &T::IID, from_ref).map(|reference| Self { reference, _marker: Default::default() }) } } + /// Resolves the reference for the current thread. pub fn resolve(&self) -> Result { unsafe { self.reference.Resolve() } } From 70bf3cbd90437be8cc0ffd2c921f21f62f4d7079 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Tue, 1 Feb 2022 22:48:16 +0100 Subject: [PATCH 07/10] fix: apply suggestions --- .../libs/windows/src/core/agile_reference.rs | 25 +++++++------------ crates/tests/agile_reference/tests/tests.rs | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/crates/libs/windows/src/core/agile_reference.rs b/crates/libs/windows/src/core/agile_reference.rs index 1eba0baa24..f11876ab4a 100644 --- a/crates/libs/windows/src/core/agile_reference.rs +++ b/crates/libs/windows/src/core/agile_reference.rs @@ -2,27 +2,20 @@ use super::*; use bindings::*; use core::marker::PhantomData; -/// A safe wrapper around WinRT interfaces. -/// -/// Some interfaces are not marked as agile thus then don't implement [`Send`]. -/// These interfaces can be made agile through this `AgileReference`. -pub struct AgileReference { - reference: IAgileReference, - _marker: PhantomData, -} +/// A type representing an agile reference to a COM/WinRT object. +#[repr(transparent)] +#[derive(Clone, PartialEq, Eq)] +pub struct AgileReference(IAgileReference, PhantomData); impl AgileReference { - /// Creates a new wrapper around the reference - pub fn new<'a>(from_ref: &'a T) -> Result - where - &'a T: IntoParam<'a, IUnknown>, - { - unsafe { RoGetAgileReference(AGILEREFERENCE_DEFAULT, &T::IID, from_ref).map(|reference| Self { reference, _marker: Default::default() }) } + /// Creates an agile reference to the object. + pub fn new<'a, O: IntoParam<'a, IUnknown>>(object: O) -> Result { + unsafe { RoGetAgileReference(AGILEREFERENCE_DEFAULT, &T::IID, object).map(|reference| Self(reference, Default::default())) } } - /// Resolves the reference for the current thread. + /// Retrieves a proxy to the target of the `AgileReference` object that may safely be used within any thread context in which get is called. pub fn resolve(&self) -> Result { - unsafe { self.reference.Resolve() } + unsafe { self.0.Resolve() } } } diff --git a/crates/tests/agile_reference/tests/tests.rs b/crates/tests/agile_reference/tests/tests.rs index 673a135614..edcfa174ca 100644 --- a/crates/tests/agile_reference/tests/tests.rs +++ b/crates/tests/agile_reference/tests/tests.rs @@ -4,7 +4,7 @@ use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager; #[test] fn test() { let manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().unwrap().get().unwrap(); - let reference = AgileReference::new(&manager).unwrap(); + let reference = AgileReference::::new(&manager).unwrap(); let handle = std::thread::spawn(move || { let manager = reference.resolve().unwrap(); From d5f27916d4934916be00a2e9c7cbc7c3425b1dae Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Tue, 1 Feb 2022 23:02:29 +0100 Subject: [PATCH 08/10] fix: run tool_yml --- .github/workflows/build.yml | 1 + .github/workflows/test.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 69444def95..199d9f35a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -101,6 +101,7 @@ jobs: cargo clippy -p windows_x86_64_gnu && cargo clippy -p windows_x86_64_msvc && cargo clippy -p test_agile && + cargo clippy -p test_agile_reference && cargo clippy -p test_alternate_success_code && cargo clippy -p test_arch && cargo clippy -p test_arch_feature && diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2bd7cf212e..e5e19d8815 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -137,3 +137,4 @@ jobs: cargo test --target ${{ matrix.target }} -p test_implement_properties && cargo test --target ${{ matrix.target }} -p test_implement_winrt if: matrix.version == 'nightly' + \ No newline at end of file From 8243dfd75393b3990c7083237d4cbaa45c0915e9 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Wed, 2 Feb 2022 13:38:35 +0100 Subject: [PATCH 09/10] fix: use result in test --- crates/tests/agile_reference/tests/tests.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/tests/agile_reference/tests/tests.rs b/crates/tests/agile_reference/tests/tests.rs index edcfa174ca..88141b8305 100644 --- a/crates/tests/agile_reference/tests/tests.rs +++ b/crates/tests/agile_reference/tests/tests.rs @@ -1,15 +1,16 @@ -use windows::core::AgileReference; +use windows::core::{AgileReference, Result}; use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager; #[test] -fn test() { - let manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().unwrap().get().unwrap(); - let reference = AgileReference::::new(&manager).unwrap(); +fn test() -> Result<()> { + let manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync()?.get()?; + let reference = AgileReference::::new(&manager)?; let handle = std::thread::spawn(move || { - let manager = reference.resolve().unwrap(); + let manager = reference.resolve()?; - manager.GetSessions().unwrap(); + manager.GetSessions()?; + Ok(()) }); - handle.join().unwrap(); + handle.join().unwrap() } From aa36b9144c3c21be8a8d71c861a4b5500e48a3b4 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Wed, 2 Feb 2022 17:04:55 +0100 Subject: [PATCH 10/10] fix: use reference to T in ::new --- crates/libs/windows/src/core/agile_reference.rs | 5 ++++- crates/tests/agile_reference/tests/tests.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/libs/windows/src/core/agile_reference.rs b/crates/libs/windows/src/core/agile_reference.rs index f11876ab4a..9f626c495b 100644 --- a/crates/libs/windows/src/core/agile_reference.rs +++ b/crates/libs/windows/src/core/agile_reference.rs @@ -9,7 +9,10 @@ pub struct AgileReference(IAgileReference, PhantomData); impl AgileReference { /// Creates an agile reference to the object. - pub fn new<'a, O: IntoParam<'a, IUnknown>>(object: O) -> Result { + pub fn new<'a>(object: &'a T) -> Result + where + &'a T: IntoParam<'a, IUnknown>, + { unsafe { RoGetAgileReference(AGILEREFERENCE_DEFAULT, &T::IID, object).map(|reference| Self(reference, Default::default())) } } diff --git a/crates/tests/agile_reference/tests/tests.rs b/crates/tests/agile_reference/tests/tests.rs index 88141b8305..91ed3befb2 100644 --- a/crates/tests/agile_reference/tests/tests.rs +++ b/crates/tests/agile_reference/tests/tests.rs @@ -4,7 +4,7 @@ use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager; #[test] fn test() -> Result<()> { let manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync()?.get()?; - let reference = AgileReference::::new(&manager)?; + let reference = AgileReference::new(&manager)?; let handle = std::thread::spawn(move || { let manager = reference.resolve()?;