This commit is contained in:
shenjack 2024-04-13 16:22:15 +08:00
parent 1393fa3c74
commit a70961e3f3
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 9 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#[allow(unused)]
// #[cfg(not(windows))]
mod other;
#[allow(unused)]
#[cfg(windows)]
mod win;
@ -10,6 +11,8 @@ mod win;
mod config;
mod reader;
pub static mut VERBOSE: bool = false;
pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");
pub const SHOW_CONSOLE: bool = false;

View File

@ -3,6 +3,7 @@ use std::{os::windows::process::CommandExt, process::Command};
use winapi::um::{processthreadsapi, wincon, winuser};
pub static mut FROM_CONSOLE: bool = false;
pub static mut ATTACHED_CONSOLE: bool = false;
fn is_launched_from_console() -> bool {
unsafe {
@ -18,12 +19,17 @@ fn is_launched_from_console() -> bool {
pub fn attach_console() {
unsafe {
if ATTACHED_CONSOLE {
return;
}
let _out = wincon::AttachConsole(wincon::ATTACH_PARENT_PROCESS);
if _out == 0 {
// GetLastError!
use std::io::Error;
let e = Error::last_os_error();
println!("AttachConsole failed: {}", e);
} else {
println!("AttachConsole success");
}
}
}