From 8d75ba4d642fd7e616a39c72d1e92bc9ee98ad54 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Tue, 14 Feb 2012 05:28:35 +0100 Subject: [PATCH] Add console output on windows --- src/main.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b561d21f8..1c20c03a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,10 +36,38 @@ #include "breakpad/BreakPad.h" #endif +#ifdef Q_OS_WIN +#include +#define argc __argc +#define argv __argv +// code taken from AbiWord, (c) AbiSource Inc. + +int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, + PSTR szCmdLine, int iCmdShow) +{ + if (fileno (stdout) != -1 && _get_osfhandle (fileno (stdout)) != -1) + { + /* stdout is fine, presumably redirected to a file or pipe */ + } + else + { + typedef BOOL (WINAPI * AttachConsole_t) (DWORD); + + AttachConsole_t p_AttachConsole = (AttachConsole_t) GetProcAddress (GetModuleHandleW(L"kernel32.dll"), "AttachConsole"); + + if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS)) + { + _wfreopen (L"CONOUT$", L"w", stdout); + dup2 (fileno (stdout), 1); + _wfreopen (L"CONOUT$", L"w", stderr); + dup2 (fileno (stderr), 2); + } + } +#else // Q_OS_WIN int main( int argc, char *argv[] ) { -#ifdef Q_WS_MAC + #ifdef Q_WS_MAC // Do Mac specific startup to get media keys working. // This must go before QApplication initialisation. Tomahawk::macMain(); @@ -47,7 +75,8 @@ main( int argc, char *argv[] ) // used for url handler AEEventHandlerUPP h = AEEventHandlerUPP( appleEventHandler ); AEInstallEventHandler( 'GURL', 'GURL', h, 0, false ); -#endif + #endif // Q_WS_MAC +#endif //Q_OS_WIN /* // Unity hack taken from Clementine's main.cpp #ifdef Q_OS_LINUX