From e75f3a7278c85685067fc22148270d8575e01082 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 13 Dec 2019 23:22:11 +1100 Subject: [PATCH] [c-host] windows: fix --help output in command prompt --- c-host/platform/Windows/src/platform.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/c-host/platform/Windows/src/platform.c b/c-host/platform/Windows/src/platform.c index 0a0e20fc..b175151d 100644 --- a/c-host/platform/Windows/src/platform.c +++ b/c-host/platform/Windows/src/platform.c @@ -24,6 +24,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #include #include +#include +#include #include "interface/platform.h" #include "common/debug.h" @@ -157,6 +159,21 @@ static BOOL WINAPI CtrlHandler(DWORD dwCtrlType) int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { + /* this is a bit of a hack but without this --help will produce no output in a windows command prompt */ + if (AttachConsole(ATTACH_PARENT_PROCESS)) + { + HANDLE std_err = GetStdHandle(STD_ERROR_HANDLE); + HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE); + int std_err_fd = _open_osfhandle((intptr_t)std_err, _O_TEXT); + int std_out_fd = _open_osfhandle((intptr_t)std_out, _O_TEXT); + + if (std_err_fd > 0) + *stderr = *_fdopen(std_err_fd, "w"); + + if (std_out_fd > 0) + *stdout = *_fdopen(std_out_fd, "w"); + } + int result = 0; app.hInst = hInstance;