+ // Win32 console redirection, because MS and their band of super geniuses
+ // decided that nobody would ever launch an app from the command line. :-P
+ // [Unfortunately, this doesn't seem to work on Vista/7. :-(]
+#ifdef __GCCWIN32__
+ BOOL (WINAPI * AttachConsole)(DWORD dwProcessId);
+
+ AttachConsole = (BOOL (WINAPI *)(DWORD))
+ GetProcAddress(LoadLibraryA("kernel32.dll"), "AttachConsole");
+
+ if (AttachConsole != NULL && AttachConsole(((DWORD)-1)))
+ {
+ if (_fileno(stdout) == -1)
+ freopen("CONOUT$", "wb", stdout);
+ if (_fileno(stderr) == -1)
+ freopen("CONOUT$", "wb", stderr);
+ if (_fileno(stdin) == -1)
+ freopen("CONIN$", "rb", stdin);
+
+ // Fix C++
+ std::ios::sync_with_stdio();
+ }
+#endif
+