From 15dcd63e728c40bfd01ac013a99bdd9b38c27134 Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 22 Apr 2020 13:19:28 +0200 Subject: [PATCH] Console is now only initialized when the emulator is started with the -D / --debug parameter. --- src/win/win.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/win/win.c b/src/win/win.c index e79844528..e8d2af475 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -233,7 +233,8 @@ CreateConsole(int init) int i; if (! init) { - FreeConsole(); + if (force_debug) + FreeConsole(); return; } @@ -271,6 +272,13 @@ CreateConsole(int init) } +static void +CloseConsole(void) +{ + CreateConsole(0); +} + + /* Process the commandline, and create standard argc/argv array. */ static int ProcessCommandLine(wchar_t ***argw) @@ -362,7 +370,8 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) set_language(0x0409); /* Create console window. */ - CreateConsole(1); + if (force_debug) + CreateConsole(1); /* Process the command line for options. */ argc = ProcessCommandLine(&argw); @@ -370,7 +379,8 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) /* Pre-initialize the system, this loads the config file. */ if (! pc_init(argc, argw)) { /* Detach from console. */ - CreateConsole(0); + if (force_debug) + CreateConsole(0); if (source_hwnd) PostMessage((HWND) (uintptr_t) source_hwnd, WM_HAS_SHUTDOWN, (WPARAM) 0, (LPARAM) hwndMain); @@ -380,9 +390,8 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) return(1); } - /* Cleanup: we may no longer need the console. */ - if (! force_debug) - CreateConsole(0); + if (force_debug) + atexit(CloseConsole); /* Handle our GUI. */ i = ui_init(nCmdShow);