diff --git a/crates/samples/windows-sys/create_window/src/main.rs b/crates/samples/windows-sys/create_window/src/main.rs index 085c1b8282..097db44294 100644 --- a/crates/samples/windows-sys/create_window/src/main.rs +++ b/crates/samples/windows-sys/create_window/src/main.rs @@ -6,20 +6,20 @@ use windows_sys::{ fn main() { unsafe { let instance = GetModuleHandleA(std::ptr::null()); - debug_assert!(instance != 0); + debug_assert!(!instance.is_null()); let window_class = s!("window"); let wc = WNDCLASSA { - hCursor: LoadCursorW(0, IDC_ARROW), + hCursor: LoadCursorW(core::ptr::null_mut(), IDC_ARROW), hInstance: instance, lpszClassName: window_class, style: CS_HREDRAW | CS_VREDRAW, lpfnWndProc: Some(wndproc), cbClsExtra: 0, cbWndExtra: 0, - hIcon: 0, - hbrBackground: 0, + hIcon: core::ptr::null_mut(), + hbrBackground: core::ptr::null_mut(), lpszMenuName: std::ptr::null(), }; @@ -35,15 +35,15 @@ fn main() { CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - 0, - 0, + core::ptr::null_mut(), + core::ptr::null_mut(), instance, std::ptr::null(), ); let mut message = std::mem::zeroed(); - while GetMessageA(&mut message, 0, 0, 0) != 0 { + while GetMessageA(&mut message, core::ptr::null_mut(), 0, 0) != 0 { DispatchMessageA(&message); } } diff --git a/crates/samples/windows-sys/delay_load/src/main.rs b/crates/samples/windows-sys/delay_load/src/main.rs index a047d31754..6f6691e3fd 100644 --- a/crates/samples/windows-sys/delay_load/src/main.rs +++ b/crates/samples/windows-sys/delay_load/src/main.rs @@ -4,9 +4,13 @@ use windows_sys::{core::*, Win32::Foundation::*, Win32::System::LibraryLoader::* /// /// The `PCSTR` parameters need to be valid for reads up until and including the next `\0`. pub unsafe fn delay_load(library: PCSTR, function: PCSTR) -> Option { - let library = LoadLibraryExA(library, 0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); + let library = LoadLibraryExA( + library, + core::ptr::null_mut(), + LOAD_LIBRARY_SEARCH_DEFAULT_DIRS, + ); - if library == 0 { + if library.is_null() { return None; } diff --git a/crates/samples/windows-sys/message_box/src/main.rs b/crates/samples/windows-sys/message_box/src/main.rs index f397631ff0..f33cff6e99 100644 --- a/crates/samples/windows-sys/message_box/src/main.rs +++ b/crates/samples/windows-sys/message_box/src/main.rs @@ -2,7 +2,14 @@ use windows_sys::{core::*, Win32::UI::Shell::*, Win32::UI::WindowsAndMessaging:: fn main() { unsafe { - MessageBoxA(0, s!("Ansi"), s!("World"), MB_OK); - ShellMessageBoxW(0, 0, w!("Wide"), w!("World"), MB_ICONERROR); + MessageBoxA(core::ptr::null_mut(), s!("Ansi"), s!("World"), MB_OK); + + ShellMessageBoxW( + core::ptr::null_mut(), + core::ptr::null_mut(), + w!("Wide"), + w!("World"), + MB_ICONERROR, + ); } } diff --git a/crates/samples/windows-sys/privileges/src/main.rs b/crates/samples/windows-sys/privileges/src/main.rs index 5961d6543c..00810f708f 100644 --- a/crates/samples/windows-sys/privileges/src/main.rs +++ b/crates/samples/windows-sys/privileges/src/main.rs @@ -4,7 +4,7 @@ use windows_sys::{ fn main() { unsafe { - let mut token = 0; + let mut token = core::ptr::null_mut(); OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token); let mut bytes_required = 0; diff --git a/crates/samples/windows/consent/src/main.rs b/crates/samples/windows/consent/src/main.rs index 21a03de64c..f70c5a684f 100644 --- a/crates/samples/windows/consent/src/main.rs +++ b/crates/samples/windows/consent/src/main.rs @@ -7,7 +7,7 @@ fn main() -> Result<()> { unsafe { let interop = factory::()?; - let window = HWND(0); // <== replace with your app's window handle + let window = HWND::default(); // <== replace with your app's window handle let operation: IAsyncOperation = interop.RequestVerificationForWindowAsync(window, h!("Hello from Rust"))?; diff --git a/crates/samples/windows/create_window/src/main.rs b/crates/samples/windows/create_window/src/main.rs index 73c097968b..35dc18b344 100644 --- a/crates/samples/windows/create_window/src/main.rs +++ b/crates/samples/windows/create_window/src/main.rs @@ -6,8 +6,6 @@ use windows::{ fn main() -> Result<()> { unsafe { let instance = GetModuleHandleA(None)?; - debug_assert!(instance.0 != 0); - let window_class = s!("window"); let wc = WNDCLASSA { @@ -36,7 +34,7 @@ fn main() -> Result<()> { None, instance, None, - ); + )?; let mut message = MSG::default(); diff --git a/crates/samples/windows/dcomp/src/main.rs b/crates/samples/windows/dcomp/src/main.rs index 4bc08aaf61..bf9c685e06 100644 --- a/crates/samples/windows/dcomp/src/main.rs +++ b/crates/samples/windows/dcomp/src/main.rs @@ -103,7 +103,7 @@ impl Window { CoCreateInstance(&UIAnimationTransitionLibrary2, None, CLSCTX_INPROC_SERVER)?; Ok(Window { - handle: HWND(0), + handle: Default::default(), dpi: (0.0, 0.0), format: create_text_format()?, image: create_image()?, @@ -446,13 +446,13 @@ impl Window { None, instance, Some(self as *mut _ as _), - ); + )?; - debug_assert!(handle.0 != 0); + debug_assert!(!handle.is_invalid()); debug_assert!(handle == self.handle); let mut message = MSG::default(); - while GetMessageA(&mut message, HWND(0), 0, 0).into() { + while GetMessageA(&mut message, HWND::default(), 0, 0).into() { DispatchMessageA(&message); } diff --git a/crates/samples/windows/direct2d/src/main.rs b/crates/samples/windows/direct2d/src/main.rs index b1ae0b0eeb..32757d457d 100644 --- a/crates/samples/windows/direct2d/src/main.rs +++ b/crates/samples/windows/direct2d/src/main.rs @@ -83,7 +83,7 @@ impl Window { }; Ok(Window { - handle: HWND(0), + handle: Default::default(), factory, dxfactory, style, @@ -125,7 +125,7 @@ impl Window { target.EndDraw(None, None)?; } - if let Err(error) = self.present(1, 0) { + if let Err(error) = self.present(1, DXGI_PRESENT(0)) { if error.code() == DXGI_STATUS_OCCLUDED { self.occlusion = unsafe { self.dxfactory @@ -152,7 +152,7 @@ impl Window { self.shadow = None; } - fn present(&self, sync: u32, flags: u32) -> Result<()> { + fn present(&self, sync: u32, flags: DXGI_PRESENT) -> Result<()> { unsafe { self.swapchain.as_ref().unwrap().Present(sync, flags).ok() } } @@ -320,7 +320,7 @@ impl Window { if unsafe { swapchain - .ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0) + .ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG(0)) .is_ok() } { create_swapchain_bitmap(swapchain, target)?; @@ -379,7 +379,6 @@ impl Window { fn run(&mut self) -> Result<()> { unsafe { let instance = GetModuleHandleA(None)?; - debug_assert!(instance.0 != 0); let window_class = s!("window"); let wc = WNDCLASSA { @@ -408,9 +407,9 @@ impl Window { None, instance, Some(self as *mut _ as _), - ); + )?; - debug_assert!(handle.0 != 0); + debug_assert!(!handle.is_invalid()); debug_assert!(handle == self.handle); let mut message = MSG::default(); diff --git a/crates/samples/windows/direct3d12/src/main.rs b/crates/samples/windows/direct3d12/src/main.rs index 3e0b2d323e..05edb03e9c 100644 --- a/crates/samples/windows/direct3d12/src/main.rs +++ b/crates/samples/windows/direct3d12/src/main.rs @@ -100,7 +100,7 @@ where instance, Some(&mut sample as *mut _ as _), ) - }; + }?; sample.bind_to_window(&hwnd)?; unsafe { _ = ShowWindow(hwnd, SW_SHOW) }; @@ -179,11 +179,9 @@ extern "system" fn wndproc( fn get_hardware_adapter(factory: &IDXGIFactory4) -> Result { for i in 0.. { let adapter = unsafe { factory.EnumAdapters1(i)? }; + let desc = unsafe { adapter.GetDesc1()? }; - let mut desc = Default::default(); - unsafe { adapter.GetDesc1(&mut desc)? }; - - if (DXGI_ADAPTER_FLAG(desc.Flags as i32) & DXGI_ADAPTER_FLAG_SOFTWARE) + if (DXGI_ADAPTER_FLAG(desc.Flags as _) & DXGI_ADAPTER_FLAG_SOFTWARE) != DXGI_ADAPTER_FLAG_NONE { // Don't select the Basic Render Driver adapter. If you want a @@ -415,7 +413,9 @@ mod d3d12_hello_triangle { unsafe { resources.command_queue.ExecuteCommandLists(&[command_list]) }; // Present the frame. - unsafe { resources.swap_chain.Present(1, 0) }.ok().unwrap(); + unsafe { resources.swap_chain.Present(1, DXGI_PRESENT(0)) } + .ok() + .unwrap(); wait_for_previous_frame(resources); } @@ -515,7 +515,7 @@ mod d3d12_hello_triangle { let dxgi_factory_flags = if cfg!(debug_assertions) { DXGI_CREATE_FACTORY_DEBUG } else { - 0 + DXGI_CREATE_FACTORY_FLAGS(0) }; let dxgi_factory: IDXGIFactory4 = unsafe { CreateDXGIFactory2(dxgi_factory_flags) }?; diff --git a/crates/samples/windows/uiautomation/src/main.rs b/crates/samples/windows/uiautomation/src/main.rs index ec78ab20d3..ba00d741d2 100644 --- a/crates/samples/windows/uiautomation/src/main.rs +++ b/crates/samples/windows/uiautomation/src/main.rs @@ -6,7 +6,7 @@ use windows::{ fn main() -> Result<()> { unsafe { CoInitializeEx(None, COINIT_MULTITHREADED).ok()?; - let window = FindWindowA(None, s!("Calculator")); + let window = FindWindowA(None, s!("Calculator"))?; // Start with COM API let automation: IUIAutomation = CoCreateInstance(&CUIAutomation, None, CLSCTX_ALL)?;