From 743580b4c029e200b1390075a1328ab314973bc2 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 17 Feb 2019 13:59:17 +0000 Subject: ash: updated support for hiding console Move the code to hide the console to a separate function in win32/mingw.c. Use lazy loading to avoid problems on platforms where the require APIs aren't supported (PR #70). Enable console hiding in the default 64-bit configuration. --- configs/mingw64_defconfig | 2 +- include/mingw.h | 1 + shell/ash.c | 12 +++--------- win32/mingw.c | 16 ++++++++++++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/configs/mingw64_defconfig b/configs/mingw64_defconfig index a0569b23a..2f85f2883 100644 --- a/configs/mingw64_defconfig +++ b/configs/mingw64_defconfig @@ -1112,7 +1112,7 @@ CONFIG_ASH_TEST=y CONFIG_ASH_HELP=y CONFIG_ASH_GETOPTS=y CONFIG_ASH_CMDCMD=y -# CONFIG_ASH_NOCONSOLE is not set +CONFIG_ASH_NOCONSOLE=y # CONFIG_CTTYHACK is not set # CONFIG_HUSH is not set # CONFIG_HUSH_BASH_COMPAT is not set diff --git a/include/mingw.h b/include/mingw.h index 0f403b993..f8e833138 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -513,3 +513,4 @@ ULONGLONG CompatGetTickCount64(void); ssize_t get_random_bytes(void *buf, ssize_t count); int enumerate_links(const char *file, char *name); +void hide_console(void); diff --git a/shell/ash.c b/shell/ash.c index 0040fd3c8..89bd886d3 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -172,8 +172,7 @@ //config: Enable support for the 'noconsole' option, which attempts to //config: hide the console normally associated with a command line //config: application. This may be useful when running a shell script -//config: from a GUI application. Disable this if your platform doesn't -//config: support the required APIs. +//config: from a GUI application. //config: //config:endif # ash options @@ -14917,13 +14916,8 @@ int ash_main(int argc UNUSED_PARAM, char **argv) #endif #if ENABLE_ASH_NOCONSOLE - if ( noconsole ) { - DWORD dummy; - - if ( GetConsoleProcessList(&dummy, 1) == 1 ) { - ShowWindow(GetConsoleWindow(), SW_HIDE); - } - } + if (noconsole) + hide_console(); #endif if (login_sh) { diff --git a/win32/mingw.c b/win32/mingw.c index 03636a04b..5cfba22f7 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -1397,3 +1397,19 @@ int enumerate_links(const char *file, char *name) return 1; } #endif + +#if ENABLE_ASH_NOCONSOLE +void hide_console(void) +{ + DWORD dummy; + DECLARE_PROC_ADDR(DWORD, GetConsoleProcessList, LPDWORD, DWORD); + DECLARE_PROC_ADDR(BOOL, ShowWindow, HWND, int); + + if (INIT_PROC_ADDR(kernel32.dll, GetConsoleProcessList) && + INIT_PROC_ADDR(user32.dll, ShowWindow)) { + if (GetConsoleProcessList(&dummy, 1) == 1) { + ShowWindow(GetConsoleWindow(), SW_HIDE); + } + } +} +#endif -- cgit v1.2.3-55-g6feb