Skip to content

Commit

Permalink
Merge pull request #96 from peamaeq/main
Browse files Browse the repository at this point in the history
The scope of the unsafe block can be appropriately reduced
  • Loading branch information
haimgel authored May 29, 2022
2 parents 2b7cdcc + 7aa4470 commit bc8de45
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/platform/pnp_detect_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ impl PnPDetectWindows {

/// Create an invisible window to handle WM_DEVICECHANGE message
fn create_window(&mut self) {
unsafe {
let winapi_class_name: Vec<u16> = OsStr::new("DisplaySwitchPnPDetectWindowClass")
.encode_wide()
.chain(once(0))
.collect();
let hinstance = GetModuleHandleW(std::ptr::null());
let hinstance = unsafe { GetModuleHandleW(std::ptr::null()) };

let wc = WNDCLASSW {
style: 0,
Expand All @@ -126,15 +125,15 @@ impl PnPDetectWindows {
lpszClassName: winapi_class_name.as_ptr(),
};

let error_code = RegisterClassW(&wc);
let error_code = unsafe { RegisterClassW(&wc) };
assert_ne!(error_code, 0, "failed to register the window class");

let window_name: Vec<u16> = OsStr::new("DisplaySwitchPnPDetectWindow")
.encode_wide()
.chain(once(0))
.collect();

let hwnd = CreateWindowExW(
let hwnd = unsafe { CreateWindowExW(
0,
winapi_class_name.as_ptr(),
window_name.as_ptr(),
Expand All @@ -148,12 +147,12 @@ impl PnPDetectWindows {
hinstance,
self as *mut Self as *mut winapi::ctypes::c_void,
//std::ptr::null_mut(),
);
) };

if hwnd.is_null() {
panic!("Something went wrong while creating a window");
}
self.hwnd = hwnd;
}

}
}

0 comments on commit bc8de45

Please sign in to comment.