Fix windows.rs

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>
This commit is contained in:
Jiahao XU 2024-08-03 13:50:51 +10:00 committed by GitHub
parent 51e475293e
commit 1add356939
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,4 @@
use std::mem; use std::{mem, ptr};
use windows_sys::Win32::{ use windows_sys::Win32::{
Foundation::{FreeLibrary, HMODULE, S_OK}, Foundation::{FreeLibrary, HMODULE, S_OK},
System::{ System::{
@ -16,7 +16,7 @@ struct LibraryHandle(HMODULE);
impl LibraryHandle { impl LibraryHandle {
fn new(name: &[u8]) -> Option<Self> { fn new(name: &[u8]) -> Option<Self> {
let handle = unsafe { LoadLibraryA(name.as_ptr() as _) }; let handle = unsafe { LoadLibraryA(name.as_ptr() as _) };
(handle != 0).then(|| Self(handle)) (handle != ptr::null_mut()).then(|| Self(handle))
} }
/// Get a function pointer to a function in the library. /// Get a function pointer to a function in the library.