From 83c7c30e3d23683e075f556aef505af609460362 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Tue, 27 Feb 2024 08:53:02 -0600 Subject: [PATCH] LocalFree --- crates/libs/bindgen/src/rust/functions.rs | 4 ++++ crates/libs/windows/src/Windows/Win32/Foundation/mod.rs | 5 ++--- crates/samples/windows/privileges/src/main.rs | 2 +- crates/tests/resources/tests/sys.rs | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/libs/bindgen/src/rust/functions.rs b/crates/libs/bindgen/src/rust/functions.rs index 9f9ac4d11e..61e9c86030 100644 --- a/crates/libs/bindgen/src/rust/functions.rs +++ b/crates/libs/bindgen/src/rust/functions.rs @@ -258,6 +258,10 @@ fn handle_last_error(def: metadata::MethodDef, signature: &metadata::Signature) if map.flags().contains(metadata::PInvokeAttributes::SupportsLastError) { if let metadata::Type::TypeDef(return_type, _) = &signature.return_type { if metadata::type_def_is_handle(*return_type) { + // https://github.com/microsoft/windows-rs/issues/2392#issuecomment-1477765781 + if def.name() == "LocalFree" { + return false; + } if return_type.underlying_type().is_pointer() { return true; } diff --git a/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs b/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs index 57701734a3..0b8bc75a77 100644 --- a/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs +++ b/crates/libs/windows/src/Windows/Win32/Foundation/mod.rs @@ -57,13 +57,12 @@ where (!result__.is_invalid()).then(|| result__).ok_or_else(::windows_core::Error::from_win32) } #[inline] -pub unsafe fn LocalFree(hmem: P0) -> ::windows_core::Result +pub unsafe fn LocalFree(hmem: P0) -> HLOCAL where P0: ::windows_core::IntoParam, { ::windows_targets::link!("kernel32.dll" "system" fn LocalFree(hmem : HLOCAL) -> HLOCAL); - let result__ = LocalFree(hmem.into_param().abi()); - (!result__.is_invalid()).then(|| result__).ok_or_else(::windows_core::Error::from_win32) + LocalFree(hmem.into_param().abi()) } #[inline] pub unsafe fn RtlNtStatusToDosError(status: P0) -> u32 diff --git a/crates/samples/windows/privileges/src/main.rs b/crates/samples/windows/privileges/src/main.rs index 7cbfe5021b..4ba4c753bf 100644 --- a/crates/samples/windows/privileges/src/main.rs +++ b/crates/samples/windows/privileges/src/main.rs @@ -37,7 +37,7 @@ fn main() -> Result<()> { println!("{}", name.display()) } - _ = LocalFree(buffer); + LocalFree(buffer); Ok(()) } } diff --git a/crates/tests/resources/tests/sys.rs b/crates/tests/resources/tests/sys.rs index 6647fa400f..2bcd36f135 100644 --- a/crates/tests/resources/tests/sys.rs +++ b/crates/tests/resources/tests/sys.rs @@ -8,6 +8,7 @@ use windows_sys::{ #[test] fn sys() { unsafe { + SetLastError(0); assert_eq!(IDI_APPLICATION as u16, 32512); assert_ne!(LoadIconW(0, IDI_APPLICATION), 0); assert_eq!(GetLastError(), 0);