diff --git a/crates/libs/bindgen/src/metadata.rs b/crates/libs/bindgen/src/metadata.rs index b678c4b32bb..74230e054d5 100644 --- a/crates/libs/bindgen/src/metadata.rs +++ b/crates/libs/bindgen/src/metadata.rs @@ -152,7 +152,7 @@ impl SignatureParam { impl Signature { pub fn kind(&self) -> SignatureKind { - if self.def.has_attribute("CanReturnMultipleSuccessValuesAttribute") { + if self.def.has_attribute("CanReturnMultipleSuccessValuesAttribute") || self.def.has_attribute("CanReturnErrorsAsSuccessAttribute") { return SignatureKind::PreserveSig; } match &self.return_type { diff --git a/crates/libs/core/src/inspectable.rs b/crates/libs/core/src/inspectable.rs index a632a216eac..f6d1e943890 100644 --- a/crates/libs/core/src/inspectable.rs +++ b/crates/libs/core/src/inspectable.rs @@ -17,6 +17,15 @@ impl IInspectable { Ok(std::mem::transmute(abi)) } } + + /// Gets the trust level of the current object. + pub fn GetTrustLevel(&self) -> Result { + unsafe { + let mut value = 0; + (self.vtable().GetTrustLevel)(std::mem::transmute_copy(self), &mut value).ok()?; + Ok(value) + } + } } #[doc(hidden)] @@ -60,14 +69,16 @@ impl IInspectable_Vtbl { *value = std::mem::transmute(h); HRESULT(0) } - unsafe extern "system" fn GetTrustLevel(_: *mut std::ffi::c_void, value: *mut i32) -> HRESULT { - // Note: even if we end up implementing this in future, it still doesn't need a this pointer - // since the data to be returned is type- not instance-specific so can be shared for all - // interfaces. - *value = 0; - HRESULT(0) + unsafe extern "system" fn GetTrustLevel(this: *mut std::ffi::c_void, value: *mut i32) -> HRESULT { + let this = (this as *mut *mut std::ffi::c_void).offset(OFFSET) as *mut T; + (*this).GetTrustLevel(value) + } + Self { + base: IUnknown_Vtbl::new::(), + GetIids, + GetRuntimeClassName: GetRuntimeClassName::, + GetTrustLevel: GetTrustLevel::, } - Self { base: IUnknown_Vtbl::new::(), GetIids, GetRuntimeClassName: GetRuntimeClassName::, GetTrustLevel } } } diff --git a/crates/libs/core/src/unknown.rs b/crates/libs/core/src/unknown.rs index 3d3e6d92e66..a6f62e00e0b 100644 --- a/crates/libs/core/src/unknown.rs +++ b/crates/libs/core/src/unknown.rs @@ -72,8 +72,10 @@ pub trait IUnknownImpl { /// This function is safe to call as long as the interface pointer is non-null and valid for writes /// of an interface pointer. unsafe fn QueryInterface(&self, iid: *const GUID, interface: *mut *mut std::ffi::c_void) -> HRESULT; + /// Increments the reference count of the interface fn AddRef(&self) -> u32; + /// Decrements the reference count causing the interface's memory to be freed when the count is 0 /// /// # Safety @@ -81,6 +83,9 @@ pub trait IUnknownImpl { /// This function should only be called when the interfacer pointer is no longer used as calling `Release` /// on a non-aliased interface pointer and then using that interface pointer may result in use after free. unsafe fn Release(&self) -> u32; + + /// Gets the trust level of the current object. + unsafe fn GetTrustLevel(&self, value: *mut i32) -> HRESULT; } #[cfg(feature = "implement")] diff --git a/crates/libs/implement/src/lib.rs b/crates/libs/implement/src/lib.rs index 23e23134fe1..297e202ad96 100644 --- a/crates/libs/implement/src/lib.rs +++ b/crates/libs/implement/src/lib.rs @@ -74,6 +74,8 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro: } }); + let trust_level = proc_macro2::Literal::usize_unsuffixed(attributes.trust_level); + let conversions = attributes.implement.iter().enumerate().map(|(enumerate, implement)| { let interface_ident = implement.to_ident(); let offset = proc_macro2::Literal::usize_unsuffixed(enumerate); @@ -162,6 +164,13 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro: } remaining } + unsafe fn GetTrustLevel(&self, value: *mut i32) -> ::windows::core::HRESULT { + if value.is_null() { + return ::windows::core::HRESULT(-2147467261); // E_POINTER + } + *value = #trust_level; + ::windows::core::HRESULT(0) + } } impl #generics #original_ident::#generics where #constraints { /// Try casting as the provided interface @@ -225,6 +234,7 @@ impl ImplementType { #[derive(Default)] struct ImplementAttributes { pub implement: Vec, + pub trust_level: usize, } impl syn::parse::Parse for ImplementAttributes { @@ -269,6 +279,7 @@ impl ImplementAttributes { self.walk_implement(tree, namespace)?; } } + UseTree2::TrustLevel(input) => self.trust_level = *input, } Ok(()) @@ -279,6 +290,7 @@ enum UseTree2 { Path(UsePath2), Name(UseName2), Group(UseGroup2), + TrustLevel(usize), } impl UseTree2 { @@ -308,6 +320,7 @@ impl UseTree2 { Ok(ImplementType { type_name, generics }) } UseTree2::Group(input) => Err(syn::parse::Error::new(input.brace_token.span.join(), "Syntax not supported")), + _ => unimplemented!(), } } } @@ -336,6 +349,18 @@ impl syn::parse::Parse for UseTree2 { if input.peek(syn::Token![::]) { input.parse::()?; Ok(UseTree2::Path(UsePath2 { ident, tree: Box::new(input.parse()?) })) + } else if input.peek(syn::Token![=]) { + if ident != "TrustLevel" { + return Err(syn::parse::Error::new(ident.span(), "Unrecognized key-value pair")); + } + input.parse::()?; + let span = input.span(); + let value = input.call(syn::Ident::parse_any)?; + match value.to_string().as_str() { + "Partial" => Ok(UseTree2::TrustLevel(1)), + "Full" => Ok(UseTree2::TrustLevel(2)), + _ => Err(syn::parse::Error::new(span, "`TrustLevel` must be `Partial` or `Full`")), + } } else { let generics = if input.peek(syn::Token![<]) { input.parse::()?; diff --git a/crates/libs/windows/src/Windows/Win32/Graphics/Direct2D/impl.rs b/crates/libs/windows/src/Windows/Win32/Graphics/Direct2D/impl.rs index e35efeb7b95..58ba6dcb6fc 100644 --- a/crates/libs/windows/src/Windows/Win32/Graphics/Direct2D/impl.rs +++ b/crates/libs/windows/src/Windows/Win32/Graphics/Direct2D/impl.rs @@ -4492,7 +4492,7 @@ pub trait ID2D1RenderTarget_Impl: Sized + ID2D1Resource_Impl { fn PopAxisAlignedClip(&self); fn Clear(&self, clearcolor: *const Common::D2D1_COLOR_F); fn BeginDraw(&self); - fn EndDraw(&self, tag1: *mut u64, tag2: *mut u64) -> ::windows_core::Result<()>; + fn EndDraw(&self, tag1: *mut u64, tag2: *mut u64) -> ::windows_core::HRESULT; fn GetPixelFormat(&self) -> Common::D2D1_PIXEL_FORMAT; fn SetDpi(&self, dpix: f32, dpiy: f32); fn GetDpi(&self, dpix: *mut f32, dpiy: *mut f32); @@ -4794,7 +4794,7 @@ impl ID2D1RenderTarget_Vtbl { unsafe extern "system" fn EndDraw, Impl: ID2D1RenderTarget_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, tag1: *mut u64, tag2: *mut u64) -> ::windows_core::HRESULT { let this = (this as *const *const ()).offset(OFFSET) as *const Identity; let this = (*this).get_impl(); - this.EndDraw(::core::mem::transmute_copy(&tag1), ::core::mem::transmute_copy(&tag2)).into() + this.EndDraw(::core::mem::transmute_copy(&tag1), ::core::mem::transmute_copy(&tag2)) } unsafe extern "system" fn GetPixelFormat, Impl: ID2D1RenderTarget_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, result__: *mut Common::D2D1_PIXEL_FORMAT) { let this = (this as *const *const ()).offset(OFFSET) as *const Identity; diff --git a/crates/libs/windows/src/Windows/Win32/Graphics/Direct2D/mod.rs b/crates/libs/windows/src/Windows/Win32/Graphics/Direct2D/mod.rs index bc2276eacb8..2a16cd4b253 100644 --- a/crates/libs/windows/src/Windows/Win32/Graphics/Direct2D/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/Graphics/Direct2D/mod.rs @@ -760,8 +760,8 @@ impl ID2D1BitmapRenderTarget { pub unsafe fn BeginDraw(&self) { (::windows_core::Interface::vtable(self).base__.BeginDraw)(::windows_core::Interface::as_raw(self)) } - pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::Result<()> { - (::windows_core::Interface::vtable(self).base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))).ok() + pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))) } #[doc = "Required features: `\"Win32_Graphics_Direct2D_Common\"`, `\"Win32_Graphics_Dxgi_Common\"`"] #[cfg(all(feature = "Win32_Graphics_Direct2D_Common", feature = "Win32_Graphics_Dxgi_Common"))] @@ -2781,8 +2781,8 @@ impl ID2D1DCRenderTarget { pub unsafe fn BeginDraw(&self) { (::windows_core::Interface::vtable(self).base__.BeginDraw)(::windows_core::Interface::as_raw(self)) } - pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::Result<()> { - (::windows_core::Interface::vtable(self).base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))).ok() + pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))) } #[doc = "Required features: `\"Win32_Graphics_Direct2D_Common\"`, `\"Win32_Graphics_Dxgi_Common\"`"] #[cfg(all(feature = "Win32_Graphics_Direct2D_Common", feature = "Win32_Graphics_Dxgi_Common"))] @@ -3691,8 +3691,8 @@ impl ID2D1DeviceContext { pub unsafe fn BeginDraw(&self) { (::windows_core::Interface::vtable(self).base__.BeginDraw)(::windows_core::Interface::as_raw(self)) } - pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::Result<()> { - (::windows_core::Interface::vtable(self).base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))).ok() + pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))) } #[doc = "Required features: `\"Win32_Graphics_Direct2D_Common\"`, `\"Win32_Graphics_Dxgi_Common\"`"] #[cfg(all(feature = "Win32_Graphics_Direct2D_Common", feature = "Win32_Graphics_Dxgi_Common"))] @@ -4373,8 +4373,8 @@ impl ID2D1DeviceContext1 { pub unsafe fn BeginDraw(&self) { (::windows_core::Interface::vtable(self).base__.base__.BeginDraw)(::windows_core::Interface::as_raw(self)) } - pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::Result<()> { - (::windows_core::Interface::vtable(self).base__.base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))).ok() + pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))) } #[doc = "Required features: `\"Win32_Graphics_Direct2D_Common\"`, `\"Win32_Graphics_Dxgi_Common\"`"] #[cfg(all(feature = "Win32_Graphics_Direct2D_Common", feature = "Win32_Graphics_Dxgi_Common"))] @@ -4976,8 +4976,8 @@ impl ID2D1DeviceContext2 { pub unsafe fn BeginDraw(&self) { (::windows_core::Interface::vtable(self).base__.base__.base__.BeginDraw)(::windows_core::Interface::as_raw(self)) } - pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::Result<()> { - (::windows_core::Interface::vtable(self).base__.base__.base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))).ok() + pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))) } #[doc = "Required features: `\"Win32_Graphics_Direct2D_Common\"`, `\"Win32_Graphics_Dxgi_Common\"`"] #[cfg(all(feature = "Win32_Graphics_Direct2D_Common", feature = "Win32_Graphics_Dxgi_Common"))] @@ -5678,8 +5678,8 @@ impl ID2D1DeviceContext3 { pub unsafe fn BeginDraw(&self) { (::windows_core::Interface::vtable(self).base__.base__.base__.base__.BeginDraw)(::windows_core::Interface::as_raw(self)) } - pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::Result<()> { - (::windows_core::Interface::vtable(self).base__.base__.base__.base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))).ok() + pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.base__.base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))) } #[doc = "Required features: `\"Win32_Graphics_Direct2D_Common\"`, `\"Win32_Graphics_Dxgi_Common\"`"] #[cfg(all(feature = "Win32_Graphics_Direct2D_Common", feature = "Win32_Graphics_Dxgi_Common"))] @@ -6364,8 +6364,8 @@ impl ID2D1DeviceContext4 { pub unsafe fn BeginDraw(&self) { (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.BeginDraw)(::windows_core::Interface::as_raw(self)) } - pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::Result<()> { - (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))).ok() + pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))) } #[doc = "Required features: `\"Win32_Graphics_Direct2D_Common\"`, `\"Win32_Graphics_Dxgi_Common\"`"] #[cfg(all(feature = "Win32_Graphics_Direct2D_Common", feature = "Win32_Graphics_Dxgi_Common"))] @@ -7131,8 +7131,8 @@ impl ID2D1DeviceContext5 { pub unsafe fn BeginDraw(&self) { (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.base__.BeginDraw)(::windows_core::Interface::as_raw(self)) } - pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::Result<()> { - (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))).ok() + pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))) } #[doc = "Required features: `\"Win32_Graphics_Direct2D_Common\"`, `\"Win32_Graphics_Dxgi_Common\"`"] #[cfg(all(feature = "Win32_Graphics_Direct2D_Common", feature = "Win32_Graphics_Dxgi_Common"))] @@ -7913,8 +7913,8 @@ impl ID2D1DeviceContext6 { pub unsafe fn BeginDraw(&self) { (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.base__.base__.BeginDraw)(::windows_core::Interface::as_raw(self)) } - pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::Result<()> { - (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.base__.base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))).ok() + pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.base__.base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))) } #[doc = "Required features: `\"Win32_Graphics_Direct2D_Common\"`, `\"Win32_Graphics_Dxgi_Common\"`"] #[cfg(all(feature = "Win32_Graphics_Direct2D_Common", feature = "Win32_Graphics_Dxgi_Common"))] @@ -11927,8 +11927,8 @@ impl ID2D1HwndRenderTarget { pub unsafe fn BeginDraw(&self) { (::windows_core::Interface::vtable(self).base__.BeginDraw)(::windows_core::Interface::as_raw(self)) } - pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::Result<()> { - (::windows_core::Interface::vtable(self).base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))).ok() + pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))) } #[doc = "Required features: `\"Win32_Graphics_Direct2D_Common\"`, `\"Win32_Graphics_Dxgi_Common\"`"] #[cfg(all(feature = "Win32_Graphics_Direct2D_Common", feature = "Win32_Graphics_Dxgi_Common"))] @@ -13598,8 +13598,8 @@ impl ID2D1RenderTarget { pub unsafe fn BeginDraw(&self) { (::windows_core::Interface::vtable(self).BeginDraw)(::windows_core::Interface::as_raw(self)) } - pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::Result<()> { - (::windows_core::Interface::vtable(self).EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))).ok() + pub unsafe fn EndDraw(&self, tag1: ::core::option::Option<*mut u64>, tag2: ::core::option::Option<*mut u64>) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).EndDraw)(::windows_core::Interface::as_raw(self), ::core::mem::transmute(tag1.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(tag2.unwrap_or(::std::ptr::null_mut()))) } #[doc = "Required features: `\"Win32_Graphics_Direct2D_Common\"`, `\"Win32_Graphics_Dxgi_Common\"`"] #[cfg(all(feature = "Win32_Graphics_Direct2D_Common", feature = "Win32_Graphics_Dxgi_Common"))] diff --git a/crates/libs/windows/src/Windows/Win32/Graphics/Dxgi/impl.rs b/crates/libs/windows/src/Windows/Win32/Graphics/Dxgi/impl.rs index 76d69b2e6d9..12d0e21716a 100644 --- a/crates/libs/windows/src/Windows/Win32/Graphics/Dxgi/impl.rs +++ b/crates/libs/windows/src/Windows/Win32/Graphics/Dxgi/impl.rs @@ -1,7 +1,7 @@ #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] pub trait IDXGIAdapter_Impl: Sized + IDXGIObject_Impl { - fn EnumOutputs(&self, output: u32) -> ::windows_core::Result; + fn EnumOutputs(&self, output: u32, ppoutput: *mut ::core::option::Option) -> ::windows_core::HRESULT; fn GetDesc(&self, pdesc: *mut DXGI_ADAPTER_DESC) -> ::windows_core::Result<()>; fn CheckInterfaceSupport(&self, interfacename: *const ::windows_core::GUID) -> ::windows_core::Result; } @@ -13,13 +13,7 @@ impl IDXGIAdapter_Vtbl { unsafe extern "system" fn EnumOutputs, Impl: IDXGIAdapter_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, output: u32, ppoutput: *mut *mut ::core::ffi::c_void) -> ::windows_core::HRESULT { let this = (this as *const *const ()).offset(OFFSET) as *const Identity; let this = (*this).get_impl(); - match this.EnumOutputs(::core::mem::transmute_copy(&output)) { - ::core::result::Result::Ok(ok__) => { - ::core::ptr::write(ppoutput, ::core::mem::transmute(ok__)); - ::windows_core::HRESULT(0) - } - ::core::result::Result::Err(err) => err.into(), - } + this.EnumOutputs(::core::mem::transmute_copy(&output), ::core::mem::transmute_copy(&ppoutput)) } unsafe extern "system" fn GetDesc, Impl: IDXGIAdapter_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, pdesc: *mut DXGI_ADAPTER_DESC) -> ::windows_core::HRESULT { let this = (this as *const *const ()).offset(OFFSET) as *const Identity; @@ -641,7 +635,7 @@ impl IDXGIFactory_Vtbl { #[doc = "Required features: `\"Win32_Foundation\"`, `\"Win32_Graphics_Dxgi_Common\"`"] #[cfg(all(feature = "Win32_Foundation", feature = "Win32_Graphics_Dxgi_Common"))] pub trait IDXGIFactory1_Impl: Sized + IDXGIFactory_Impl { - fn EnumAdapters1(&self, adapter: u32) -> ::windows_core::Result; + fn EnumAdapters1(&self, adapter: u32, ppadapter: *mut ::core::option::Option) -> ::windows_core::HRESULT; fn IsCurrent(&self) -> super::super::Foundation::BOOL; } #[cfg(all(feature = "Win32_Foundation", feature = "Win32_Graphics_Dxgi_Common"))] @@ -652,13 +646,7 @@ impl IDXGIFactory1_Vtbl { unsafe extern "system" fn EnumAdapters1, Impl: IDXGIFactory1_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, adapter: u32, ppadapter: *mut *mut ::core::ffi::c_void) -> ::windows_core::HRESULT { let this = (this as *const *const ()).offset(OFFSET) as *const Identity; let this = (*this).get_impl(); - match this.EnumAdapters1(::core::mem::transmute_copy(&adapter)) { - ::core::result::Result::Ok(ok__) => { - ::core::ptr::write(ppadapter, ::core::mem::transmute(ok__)); - ::windows_core::HRESULT(0) - } - ::core::result::Result::Err(err) => err.into(), - } + this.EnumAdapters1(::core::mem::transmute_copy(&adapter), ::core::mem::transmute_copy(&ppadapter)) } unsafe extern "system" fn IsCurrent, Impl: IDXGIFactory1_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void) -> super::super::Foundation::BOOL { let this = (this as *const *const ()).offset(OFFSET) as *const Identity; diff --git a/crates/libs/windows/src/Windows/Win32/Graphics/Dxgi/mod.rs b/crates/libs/windows/src/Windows/Win32/Graphics/Dxgi/mod.rs index 48435450836..eecc55e1798 100644 --- a/crates/libs/windows/src/Windows/Win32/Graphics/Dxgi/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/Graphics/Dxgi/mod.rs @@ -70,9 +70,8 @@ impl IDXGIAdapter { let mut result__ = ::std::ptr::null_mut(); (::windows_core::Interface::vtable(self).base__.GetParent)(::windows_core::Interface::as_raw(self), &::IID, &mut result__).from_abi(result__) } - pub unsafe fn EnumOutputs(&self, output: u32) -> ::windows_core::Result { - let mut result__ = ::std::mem::zeroed(); - (::windows_core::Interface::vtable(self).EnumOutputs)(::windows_core::Interface::as_raw(self), output, &mut result__).from_abi(result__) + pub unsafe fn EnumOutputs(&self, output: u32, ppoutput: *mut ::core::option::Option) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).EnumOutputs)(::windows_core::Interface::as_raw(self), output, ::core::mem::transmute(ppoutput)) } #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] @@ -127,9 +126,8 @@ impl IDXGIAdapter1 { let mut result__ = ::std::ptr::null_mut(); (::windows_core::Interface::vtable(self).base__.base__.GetParent)(::windows_core::Interface::as_raw(self), &::IID, &mut result__).from_abi(result__) } - pub unsafe fn EnumOutputs(&self, output: u32) -> ::windows_core::Result { - let mut result__ = ::std::mem::zeroed(); - (::windows_core::Interface::vtable(self).base__.EnumOutputs)(::windows_core::Interface::as_raw(self), output, &mut result__).from_abi(result__) + pub unsafe fn EnumOutputs(&self, output: u32, ppoutput: *mut ::core::option::Option) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.EnumOutputs)(::windows_core::Interface::as_raw(self), output, ::core::mem::transmute(ppoutput)) } #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] @@ -187,9 +185,8 @@ impl IDXGIAdapter2 { let mut result__ = ::std::ptr::null_mut(); (::windows_core::Interface::vtable(self).base__.base__.base__.GetParent)(::windows_core::Interface::as_raw(self), &::IID, &mut result__).from_abi(result__) } - pub unsafe fn EnumOutputs(&self, output: u32) -> ::windows_core::Result { - let mut result__ = ::std::mem::zeroed(); - (::windows_core::Interface::vtable(self).base__.base__.EnumOutputs)(::windows_core::Interface::as_raw(self), output, &mut result__).from_abi(result__) + pub unsafe fn EnumOutputs(&self, output: u32, ppoutput: *mut ::core::option::Option) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.EnumOutputs)(::windows_core::Interface::as_raw(self), output, ::core::mem::transmute(ppoutput)) } #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] @@ -252,9 +249,8 @@ impl IDXGIAdapter3 { let mut result__ = ::std::ptr::null_mut(); (::windows_core::Interface::vtable(self).base__.base__.base__.base__.GetParent)(::windows_core::Interface::as_raw(self), &::IID, &mut result__).from_abi(result__) } - pub unsafe fn EnumOutputs(&self, output: u32) -> ::windows_core::Result { - let mut result__ = ::std::mem::zeroed(); - (::windows_core::Interface::vtable(self).base__.base__.base__.EnumOutputs)(::windows_core::Interface::as_raw(self), output, &mut result__).from_abi(result__) + pub unsafe fn EnumOutputs(&self, output: u32, ppoutput: *mut ::core::option::Option) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.base__.EnumOutputs)(::windows_core::Interface::as_raw(self), output, ::core::mem::transmute(ppoutput)) } #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] @@ -355,9 +351,8 @@ impl IDXGIAdapter4 { let mut result__ = ::std::ptr::null_mut(); (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.GetParent)(::windows_core::Interface::as_raw(self), &::IID, &mut result__).from_abi(result__) } - pub unsafe fn EnumOutputs(&self, output: u32) -> ::windows_core::Result { - let mut result__ = ::std::mem::zeroed(); - (::windows_core::Interface::vtable(self).base__.base__.base__.base__.EnumOutputs)(::windows_core::Interface::as_raw(self), output, &mut result__).from_abi(result__) + pub unsafe fn EnumOutputs(&self, output: u32, ppoutput: *mut ::core::option::Option) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.base__.base__.EnumOutputs)(::windows_core::Interface::as_raw(self), output, ::core::mem::transmute(ppoutput)) } #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] @@ -1200,9 +1195,8 @@ impl IDXGIFactory1 { let mut result__ = ::std::mem::zeroed(); (::windows_core::Interface::vtable(self).base__.CreateSoftwareAdapter)(::windows_core::Interface::as_raw(self), module.into_param().abi(), &mut result__).from_abi(result__) } - pub unsafe fn EnumAdapters1(&self, adapter: u32) -> ::windows_core::Result { - let mut result__ = ::std::mem::zeroed(); - (::windows_core::Interface::vtable(self).EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, &mut result__).from_abi(result__) + pub unsafe fn EnumAdapters1(&self, adapter: u32, ppadapter: *mut ::core::option::Option) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, ::core::mem::transmute(ppadapter)) } #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] @@ -1287,9 +1281,8 @@ impl IDXGIFactory2 { let mut result__ = ::std::mem::zeroed(); (::windows_core::Interface::vtable(self).base__.base__.CreateSoftwareAdapter)(::windows_core::Interface::as_raw(self), module.into_param().abi(), &mut result__).from_abi(result__) } - pub unsafe fn EnumAdapters1(&self, adapter: u32) -> ::windows_core::Result { - let mut result__ = ::std::mem::zeroed(); - (::windows_core::Interface::vtable(self).base__.EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, &mut result__).from_abi(result__) + pub unsafe fn EnumAdapters1(&self, adapter: u32, ppadapter: *mut ::core::option::Option) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, ::core::mem::transmute(ppadapter)) } #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] @@ -1495,9 +1488,8 @@ impl IDXGIFactory3 { let mut result__ = ::std::mem::zeroed(); (::windows_core::Interface::vtable(self).base__.base__.base__.CreateSoftwareAdapter)(::windows_core::Interface::as_raw(self), module.into_param().abi(), &mut result__).from_abi(result__) } - pub unsafe fn EnumAdapters1(&self, adapter: u32) -> ::windows_core::Result { - let mut result__ = ::std::mem::zeroed(); - (::windows_core::Interface::vtable(self).base__.base__.EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, &mut result__).from_abi(result__) + pub unsafe fn EnumAdapters1(&self, adapter: u32, ppadapter: *mut ::core::option::Option) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, ::core::mem::transmute(ppadapter)) } #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] @@ -1669,9 +1661,8 @@ impl IDXGIFactory4 { let mut result__ = ::std::mem::zeroed(); (::windows_core::Interface::vtable(self).base__.base__.base__.base__.CreateSoftwareAdapter)(::windows_core::Interface::as_raw(self), module.into_param().abi(), &mut result__).from_abi(result__) } - pub unsafe fn EnumAdapters1(&self, adapter: u32) -> ::windows_core::Result { - let mut result__ = ::std::mem::zeroed(); - (::windows_core::Interface::vtable(self).base__.base__.base__.EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, &mut result__).from_abi(result__) + pub unsafe fn EnumAdapters1(&self, adapter: u32, ppadapter: *mut ::core::option::Option) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.base__.EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, ::core::mem::transmute(ppadapter)) } #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] @@ -1863,9 +1854,8 @@ impl IDXGIFactory5 { let mut result__ = ::std::mem::zeroed(); (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.CreateSoftwareAdapter)(::windows_core::Interface::as_raw(self), module.into_param().abi(), &mut result__).from_abi(result__) } - pub unsafe fn EnumAdapters1(&self, adapter: u32) -> ::windows_core::Result { - let mut result__ = ::std::mem::zeroed(); - (::windows_core::Interface::vtable(self).base__.base__.base__.base__.EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, &mut result__).from_abi(result__) + pub unsafe fn EnumAdapters1(&self, adapter: u32, ppadapter: *mut ::core::option::Option) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.base__.base__.EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, ::core::mem::transmute(ppadapter)) } #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] @@ -2056,9 +2046,8 @@ impl IDXGIFactory6 { let mut result__ = ::std::mem::zeroed(); (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.base__.CreateSoftwareAdapter)(::windows_core::Interface::as_raw(self), module.into_param().abi(), &mut result__).from_abi(result__) } - pub unsafe fn EnumAdapters1(&self, adapter: u32) -> ::windows_core::Result { - let mut result__ = ::std::mem::zeroed(); - (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, &mut result__).from_abi(result__) + pub unsafe fn EnumAdapters1(&self, adapter: u32, ppadapter: *mut ::core::option::Option) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, ::core::mem::transmute(ppadapter)) } #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] @@ -2256,9 +2245,8 @@ impl IDXGIFactory7 { let mut result__ = ::std::mem::zeroed(); (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.base__.base__.CreateSoftwareAdapter)(::windows_core::Interface::as_raw(self), module.into_param().abi(), &mut result__).from_abi(result__) } - pub unsafe fn EnumAdapters1(&self, adapter: u32) -> ::windows_core::Result { - let mut result__ = ::std::mem::zeroed(); - (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.base__.EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, &mut result__).from_abi(result__) + pub unsafe fn EnumAdapters1(&self, adapter: u32, ppadapter: *mut ::core::option::Option) -> ::windows_core::HRESULT { + (::windows_core::Interface::vtable(self).base__.base__.base__.base__.base__.base__.EnumAdapters1)(::windows_core::Interface::as_raw(self), adapter, ::core::mem::transmute(ppadapter)) } #[doc = "Required features: `\"Win32_Foundation\"`"] #[cfg(feature = "Win32_Foundation")] diff --git a/crates/tests/implement/tests/trust_level.rs b/crates/tests/implement/tests/trust_level.rs new file mode 100644 index 00000000000..aae60ddd7b3 --- /dev/null +++ b/crates/tests/implement/tests/trust_level.rs @@ -0,0 +1,54 @@ +#![allow(non_snake_case)] + +use windows::core::*; +use windows::Foundation::*; + +#[implement(IStringable)] +struct BaseTrust; + +impl IStringable_Impl for BaseTrust { + fn ToString(&self) -> Result { + Ok("BaseTrust".into()) + } +} + +#[implement(IClosable, TrustLevel = Partial, IStringable)] +struct PartialTrust; + +impl IStringable_Impl for PartialTrust { + fn ToString(&self) -> Result { + Ok("PartialTrust".into()) + } +} + +impl IClosable_Impl for PartialTrust { + fn Close(&self) -> Result<()> { + Ok(()) + } +} + +#[implement(IStringable, TrustLevel = Full)] +struct FullTrust; + +impl IStringable_Impl for FullTrust { + fn ToString(&self) -> Result { + Ok("FullTrust".into()) + } +} + +#[test] +fn test() -> Result<()> { + let base: IStringable = BaseTrust.into(); + assert_eq!(base.ToString()?, "BaseTrust"); + assert_eq!(base.cast::()?.GetTrustLevel()?, 0); + + let partial: IStringable = PartialTrust.into(); + assert_eq!(partial.ToString()?, "PartialTrust"); + assert_eq!(partial.cast::()?.GetTrustLevel()?, 1); + + let full: IStringable = FullTrust.into(); + assert_eq!(full.ToString()?, "FullTrust"); + assert_eq!(full.cast::()?.GetTrustLevel()?, 2); + + Ok(()) +}