# HG changeset patch # User Daniel Atallah # Date 1158706427 0 # Node ID 209e187246c5a351e2960b2a51c81d9eed662676 # Parent 78f121689460111b7d46b884af3402e3cecf820d [gaim-migrate @ 17322] Fix stdout redirection to work for the wingaim executable even when running in the non-debug GUI subsystem. This has annoyed me for quite some time. committer: Tailor Script diff -r 78f121689460 -r 209e187246c5 gtk/win32/win_gaim.c --- a/gtk/win32/win_gaim.c Tue Sep 19 01:01:20 2006 +0000 +++ b/gtk/win32/win_gaim.c Tue Sep 19 22:53:47 2006 +0000 @@ -224,7 +224,7 @@ printf("Trying to set SafeDllSearchMode to 0\n"); regval = 0; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, - "System\\CurrentControlSet\\Control\\Session Manager", + "System\\CurrentControlSet\\Control\\Session Manager", 0, KEY_SET_VALUE, &hkey ) == ERROR_SUCCESS) { if (RegSetValueEx(hkey, @@ -511,15 +511,21 @@ /* If debug or help or version flag used, create console for output */ if (strstr(lpszCmdLine, "-d") || strstr(lpszCmdLine, "-h") || strstr(lpszCmdLine, "-v")) { - LPFNATTACHCONSOLE MyAttachConsole = NULL; - if ((hmod = GetModuleHandle("kernel32.dll"))) { - MyAttachConsole = - (LPFNATTACHCONSOLE) - GetProcAddress(hmod, "AttachConsole"); + /* If stdout hasn't been redirected to a file, alloc a console + * (_istty() doesn't work for stuff using the GUI subsystem) */ + if (_fileno(stdout) == -1) { + LPFNATTACHCONSOLE MyAttachConsole = NULL; + if ((hmod = GetModuleHandle("kernel32.dll"))) { + MyAttachConsole = + (LPFNATTACHCONSOLE) + GetProcAddress(hmod, "AttachConsole"); + } + if ((MyAttachConsole && MyAttachConsole(ATTACH_PARENT_PROCESS)) + || AllocConsole()) { + freopen("CONOUT$", "w", stdout); + freopen("CONOUT$", "w", stderr); + } } - if ((MyAttachConsole && MyAttachConsole(ATTACH_PARENT_PROCESS)) - || AllocConsole()) - freopen("CONOUT$", "w", stdout); } /* Load exception handler if we have it */