changeset 14595:209e187246c5

[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 <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 19 Sep 2006 22:53:47 +0000
parents 78f121689460
children 56cdf406ff31
files gtk/win32/win_gaim.c
diffstat 1 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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 */