refactor(deps): replace winapi with windows

This commit is contained in:
Andre Toerien
2025-09-20 16:33:17 +02:00
committed by Gideon
parent 0dee534f84
commit f4ac809dff
3 changed files with 125 additions and 15 deletions

View File

@@ -1,22 +1,21 @@
//! A stub for Ctrl + C handling.
use crate::ctrlc::interrupted::set_interrupted;
use tracing::error;
use winapi::shared::minwindef::{BOOL, DWORD, FALSE, TRUE};
use winapi::um::consoleapi::SetConsoleCtrlHandler;
use winapi::um::wincon::CTRL_C_EVENT;
use windows::core::BOOL;
use windows::Win32::System::Console::{SetConsoleCtrlHandler, CTRL_C_EVENT};
extern "system" fn handler(ctrl_type: DWORD) -> BOOL {
extern "system" fn handler(ctrl_type: u32) -> BOOL {
match ctrl_type {
CTRL_C_EVENT => {
set_interrupted();
TRUE
true.into()
}
_ => FALSE,
_ => false.into(),
}
}
pub fn set_handler() {
if 0 == unsafe { SetConsoleCtrlHandler(Some(handler), TRUE) } {
error!("Cannot set a control C handler")
if let Err(e) = unsafe { SetConsoleCtrlHandler(Some(handler), true) } {
error!("Cannot set a control C handler: {e}")
}
}