-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
317 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#![allow( | ||
non_snake_case, | ||
non_upper_case_globals, | ||
non_camel_case_types, | ||
dead_code, | ||
clippy::all | ||
)] | ||
|
||
#[inline] | ||
pub unsafe fn CreateEventW<P3>( | ||
lpeventattributes: Option<*const SECURITY_ATTRIBUTES>, | ||
bmanualreset: bool, | ||
binitialstate: bool, | ||
lpname: P3, | ||
) -> windows_core::Result<HANDLE> | ||
where | ||
P3: windows_core::Param<windows_core::PCWSTR>, | ||
{ | ||
windows_targets::link!("kernel32.dll" "system" fn CreateEventW(lpeventattributes : *const SECURITY_ATTRIBUTES, bmanualreset : windows_core::BOOL, binitialstate : windows_core::BOOL, lpname : windows_core::PCWSTR) -> HANDLE); | ||
let result__ = unsafe { | ||
CreateEventW( | ||
lpeventattributes.unwrap_or(core::mem::zeroed()) as _, | ||
bmanualreset.into(), | ||
binitialstate.into(), | ||
lpname.param().abi(), | ||
) | ||
}; | ||
(!result__.is_invalid()) | ||
.then_some(result__) | ||
.ok_or_else(windows_core::Error::from_win32) | ||
} | ||
#[inline] | ||
pub unsafe fn NtWaitForSingleObject( | ||
handle: HANDLE, | ||
alertable: bool, | ||
timeout: *mut i64, | ||
) -> NTSTATUS { | ||
windows_targets::link!("ntdll.dll" "system" fn NtWaitForSingleObject(handle : HANDLE, alertable : bool, timeout : *mut i64) -> NTSTATUS); | ||
unsafe { NtWaitForSingleObject(handle, alertable, timeout as _) } | ||
} | ||
#[inline] | ||
pub unsafe fn SetEvent(hevent: HANDLE) -> windows_core::Result<()> { | ||
windows_targets::link!("kernel32.dll" "system" fn SetEvent(hevent : HANDLE) -> windows_core::BOOL); | ||
unsafe { SetEvent(hevent).ok() } | ||
} | ||
#[inline] | ||
pub unsafe fn WaitForSingleObjectEx( | ||
hhandle: HANDLE, | ||
dwmilliseconds: u32, | ||
balertable: bool, | ||
) -> WAIT_EVENT { | ||
windows_targets::link!("kernel32.dll" "system" fn WaitForSingleObjectEx(hhandle : HANDLE, dwmilliseconds : u32, balertable : windows_core::BOOL) -> WAIT_EVENT); | ||
unsafe { WaitForSingleObjectEx(hhandle, dwmilliseconds, balertable.into()) } | ||
} | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub struct HANDLE(pub *mut core::ffi::c_void); | ||
impl HANDLE { | ||
pub fn is_invalid(&self) -> bool { | ||
self.0 == -1 as _ || self.0 == 0 as _ | ||
} | ||
} | ||
impl windows_core::Free for HANDLE { | ||
#[inline] | ||
unsafe fn free(&mut self) { | ||
if !self.is_invalid() { | ||
windows_targets::link!("kernel32.dll" "system" fn CloseHandle(hobject : *mut core::ffi::c_void) -> i32); | ||
unsafe { | ||
CloseHandle(self.0); | ||
} | ||
} | ||
} | ||
} | ||
impl Default for HANDLE { | ||
fn default() -> Self { | ||
unsafe { core::mem::zeroed() } | ||
} | ||
} | ||
#[must_use] | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] | ||
pub struct NTSTATUS(pub i32); | ||
#[repr(C)] | ||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub struct SECURITY_ATTRIBUTES { | ||
pub nLength: u32, | ||
pub lpSecurityDescriptor: *mut core::ffi::c_void, | ||
pub bInheritHandle: windows_core::BOOL, | ||
} | ||
impl Default for SECURITY_ATTRIBUTES { | ||
fn default() -> Self { | ||
unsafe { core::mem::zeroed() } | ||
} | ||
} | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] | ||
pub struct WAIT_EVENT(pub u32); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![allow( | ||
non_snake_case, | ||
non_upper_case_globals, | ||
non_camel_case_types, | ||
dead_code, | ||
clippy::all | ||
)] | ||
|
||
windows_targets::link!("user32.dll" "system" fn EnableMouseInPointer(fenable : windows_sys::core::BOOL) -> windows_sys::core::BOOL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![allow( | ||
non_snake_case, | ||
non_upper_case_globals, | ||
non_camel_case_types, | ||
dead_code, | ||
clippy::all | ||
)] | ||
|
||
windows_targets::link!("user32.dll" "system" fn EnableMouseInPointer(fenable : BOOL) -> BOOL); | ||
pub type BOOL = i32; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#![allow( | ||
non_snake_case, | ||
non_upper_case_globals, | ||
non_camel_case_types, | ||
dead_code, | ||
clippy::all | ||
)] | ||
|
||
#[inline] | ||
pub unsafe fn EnumWindows(lpenumfunc: WNDENUMPROC, lparam: LPARAM) -> windows_core::Result<()> { | ||
windows_targets::link!("user32.dll" "system" fn EnumWindows(lpenumfunc : WNDENUMPROC, lparam : LPARAM) -> windows_core::BOOL); | ||
unsafe { EnumWindows(lpenumfunc, lparam).ok() } | ||
} | ||
#[inline] | ||
pub unsafe fn GetProcAddress<P1>(hmodule: HMODULE, lpprocname: P1) -> FARPROC | ||
where | ||
P1: windows_core::Param<windows_core::PCSTR>, | ||
{ | ||
windows_targets::link!("kernel32.dll" "system" fn GetProcAddress(hmodule : HMODULE, lpprocname : windows_core::PCSTR) -> FARPROC); | ||
unsafe { GetProcAddress(hmodule, lpprocname.param().abi()) } | ||
} | ||
pub type FARPROC = Option<unsafe extern "system" fn() -> isize>; | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub struct HANDLE(pub *mut core::ffi::c_void); | ||
impl HANDLE { | ||
pub fn is_invalid(&self) -> bool { | ||
self.0 == -1 as _ || self.0 == 0 as _ | ||
} | ||
} | ||
impl windows_core::Free for HANDLE { | ||
#[inline] | ||
unsafe fn free(&mut self) { | ||
if !self.is_invalid() { | ||
windows_targets::link!("kernel32.dll" "system" fn CloseHandle(hobject : *mut core::ffi::c_void) -> i32); | ||
unsafe { | ||
CloseHandle(self.0); | ||
} | ||
} | ||
} | ||
} | ||
impl Default for HANDLE { | ||
fn default() -> Self { | ||
unsafe { core::mem::zeroed() } | ||
} | ||
} | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub struct HINSTANCE(pub *mut core::ffi::c_void); | ||
impl HINSTANCE { | ||
pub fn is_invalid(&self) -> bool { | ||
self.0.is_null() | ||
} | ||
} | ||
impl windows_core::Free for HINSTANCE { | ||
#[inline] | ||
unsafe fn free(&mut self) { | ||
if !self.is_invalid() { | ||
windows_targets::link!("kernel32.dll" "system" fn FreeLibrary(hlibmodule : *mut core::ffi::c_void) -> i32); | ||
unsafe { | ||
FreeLibrary(self.0); | ||
} | ||
} | ||
} | ||
} | ||
impl Default for HINSTANCE { | ||
fn default() -> Self { | ||
unsafe { core::mem::zeroed() } | ||
} | ||
} | ||
impl windows_core::imp::CanInto<HMODULE> for HINSTANCE {} | ||
impl From<HINSTANCE> for HMODULE { | ||
fn from(value: HINSTANCE) -> Self { | ||
Self(value.0) | ||
} | ||
} | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub struct HMODULE(pub *mut core::ffi::c_void); | ||
impl HMODULE { | ||
pub fn is_invalid(&self) -> bool { | ||
self.0.is_null() | ||
} | ||
} | ||
impl windows_core::Free for HMODULE { | ||
#[inline] | ||
unsafe fn free(&mut self) { | ||
if !self.is_invalid() { | ||
windows_targets::link!("kernel32.dll" "system" fn FreeLibrary(hlibmodule : *mut core::ffi::c_void) -> i32); | ||
unsafe { | ||
FreeLibrary(self.0); | ||
} | ||
} | ||
} | ||
} | ||
impl Default for HMODULE { | ||
fn default() -> Self { | ||
unsafe { core::mem::zeroed() } | ||
} | ||
} | ||
impl windows_core::imp::CanInto<HINSTANCE> for HMODULE {} | ||
impl From<HMODULE> for HINSTANCE { | ||
fn from(value: HMODULE) -> Self { | ||
Self(value.0) | ||
} | ||
} | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub struct HWND(pub *mut core::ffi::c_void); | ||
impl HWND { | ||
pub fn is_invalid(&self) -> bool { | ||
self.0.is_null() | ||
} | ||
} | ||
impl Default for HWND { | ||
fn default() -> Self { | ||
unsafe { core::mem::zeroed() } | ||
} | ||
} | ||
impl windows_core::imp::CanInto<HANDLE> for HWND {} | ||
impl From<HWND> for HANDLE { | ||
fn from(value: HWND) -> Self { | ||
Self(value.0) | ||
} | ||
} | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] | ||
pub struct LPARAM(pub isize); | ||
pub type WNDENUMPROC = | ||
Option<unsafe extern "system" fn(param0: HWND, param1: LPARAM) -> windows_core::BOOL>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.