summaryrefslogtreecommitdiff
path: root/gtk2_ardour/main.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2015-01-06 02:04:12 +0100
committerRobin Gareus <robin@gareus.org>2015-01-06 02:04:12 +0100
commit9988f661fad12a526923af485f49d2fd685782e1 (patch)
treef76c8a28d9194cd5a53388441181670609cfb0c8 /gtk2_ardour/main.cc
parentb56905b9a79c48548f8100ab77c28533a5820ab3 (diff)
windows: re-attach to the console with -mwindows
Diffstat (limited to 'gtk2_ardour/main.cc')
-rw-r--r--gtk2_ardour/main.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc
index b4f5a36521..7e7d3a0c35 100644
--- a/gtk2_ardour/main.cc
+++ b/gtk2_ardour/main.cc
@@ -58,6 +58,7 @@
#ifdef PLATFORM_WINDOWS
#include <fcntl.h> // Needed for '_fmode'
+#include <shellapi.h> // console
#endif
#ifdef WAF_BUILD
@@ -146,6 +147,16 @@ sigpipe_handler (int /*signal*/)
}
#endif
+
+#if (!defined COMPILER_MSVC && defined PLATFORM_WINDOWS && defined NDEBUG)
+static bool IsAConsolePort (HANDLE handle)
+{
+ DWORD mode;
+ return (GetConsoleMode(handle, &mode) != 0);
+}
+#endif
+
+
#if (defined(COMPILER_MSVC) && defined(NDEBUG) && !defined(RDC_BUILD))
/*
* Release build with MSVC uses ardour_main()
@@ -181,6 +192,20 @@ int main (int argc, char *argv[])
gtk_set_locale ();
#endif
+#if (!defined COMPILER_MSVC && defined PLATFORM_WINDOWS && defined NDEBUG)
+ /* re-attach to the console so we can see 'printf()' output etc.
+ * for MSVC see gtk2_ardour/msvc/winmain.cc
+ */
+ FILE *pStdOut = 0, *pStdErr = 0;
+ BOOL bConsole = AttachConsole(ATTACH_PARENT_PROCESS);
+ HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
+
+ if ((bConsole) && (IsAConsolePort(hStdOut))) {
+ pStdOut = freopen( "CONOUT$", "w", stdout );
+ pStdErr = freopen( "CONOUT$", "w", stderr );
+ }
+#endif
+
#if (defined WINDOWS_VST_SUPPORT && !defined PLATFORM_WINDOWS)
/* this does some magic that is needed to make GTK and X11 client interact properly.
* the platform dependent code is in windows_vst_plugin_ui.cc
@@ -285,6 +310,33 @@ int main (int argc, char *argv[])
ARDOUR::cleanup ();
pthread_cancel_all ();
+#if (!defined COMPILER_MSVC && defined PLATFORM_WINDOWS && defined NDEBUG)
+ if (pStdOut) {
+ fclose (pStdOut);
+ }
+ if (pStdErr) {
+ fclose (pStdErr);
+ }
+
+ if (bConsole) {
+ // Detach and free the console from our application
+ INPUT_RECORD input_record;
+
+ input_record.EventType = KEY_EVENT;
+ input_record.Event.KeyEvent.bKeyDown = TRUE;
+ input_record.Event.KeyEvent.dwControlKeyState = 0;
+ input_record.Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
+ input_record.Event.KeyEvent.wRepeatCount = 1;
+ input_record.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
+ input_record.Event.KeyEvent.wVirtualScanCode = MapVirtualKey( VK_RETURN, 0 );
+
+ DWORD written = 0;
+ WriteConsoleInput( GetStdHandle( STD_INPUT_HANDLE ), &input_record, 1, &written );
+
+ FreeConsole();
+ }
+#endif
+
return 0;
}
#if (defined WINDOWS_VST_SUPPORT && !defined PLATFORM_WINDOWS)