From 76a6b4e09edc38d882cb4a85768644757cbcc213 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Mon, 17 Jul 2023 18:52:43 +0800 Subject: [PATCH] alloc_console does work, but it create another cmd window, seems not better than dialog --- src/platform/windows.cc | 4 ++++ src/platform/windows.rs | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/platform/windows.cc b/src/platform/windows.cc index c4286ebdd..4ffa6eeeb 100644 --- a/src/platform/windows.cc +++ b/src/platform/windows.cc @@ -628,4 +628,8 @@ extern "C" return bSystem; } + void alloc_console_and_redirect() { + AllocConsole(); + freopen("CONOUT$", "w", stdout); + } } // end of extern "C" \ No newline at end of file diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 6e79873a7..8734cccf7 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -455,6 +455,7 @@ extern "C" { fn win_stop_system_key_propagate(v: BOOL); fn is_win_down() -> BOOL; fn is_local_system() -> BOOL; + fn alloc_console_and_redirect(); } extern "system" { @@ -2383,3 +2384,9 @@ pub fn message_box(text: &str) { .collect::>(); unsafe { MessageBoxW(std::ptr::null_mut(), text.as_ptr(), caption.as_ptr(), MB_OK) }; } + +pub fn alloc_console() { + unsafe { + alloc_console_and_redirect(); + } +}