Use shared windows-console setup code
This commit is contained in:
parent
25bd4b8ec7
commit
f386d1334a
@ -43,6 +43,7 @@
|
||||
#include "pbd/failed_constructor.h"
|
||||
#include "pbd/pathexpand.h"
|
||||
#include "pbd/pthread_utils.h"
|
||||
#include "pbd/win_console.h"
|
||||
#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
|
||||
#include "pbd/boost_debug.h"
|
||||
#endif
|
||||
@ -186,71 +187,10 @@ sigpipe_handler (int /*signal*/)
|
||||
|
||||
#if (!defined COMPILER_MSVC && defined PLATFORM_WINDOWS)
|
||||
|
||||
static FILE* pStdOut = 0;
|
||||
static FILE* pStdErr = 0;
|
||||
static BOOL bConsole;
|
||||
static HANDLE hStdOut;
|
||||
|
||||
static bool
|
||||
IsAConsolePort (HANDLE handle)
|
||||
{
|
||||
DWORD mode;
|
||||
return (GetConsoleMode(handle, &mode) != 0);
|
||||
}
|
||||
|
||||
static void
|
||||
console_madness_begin ()
|
||||
{
|
||||
bConsole = AttachConsole(ATTACH_PARENT_PROCESS);
|
||||
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
/* re-attach to the console so we can see 'printf()' output etc.
|
||||
* for MSVC see gtk2_ardour/msvc/winmain.cc
|
||||
*/
|
||||
|
||||
if ((bConsole) && (IsAConsolePort(hStdOut))) {
|
||||
pStdOut = freopen( "CONOUT$", "w", stdout );
|
||||
pStdErr = freopen( "CONOUT$", "w", stderr );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
console_madness_end ()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
static void command_line_parse_error (int *argc, char** argv[]) {}
|
||||
|
||||
#elif (defined(COMPILER_MSVC) && defined(NDEBUG) && !defined(RDC_BUILD))
|
||||
|
||||
// these are not used here. for MSVC see gtk2_ardour/msvc/winmain.cc
|
||||
static void console_madness_begin () {}
|
||||
static void console_madness_end () {}
|
||||
|
||||
static void command_line_parse_error (int *argc, char** argv[]) {
|
||||
// Since we don't ordinarily have access to stdout and stderr with
|
||||
// an MSVC app, let the user know we encountered a parsing error.
|
||||
@ -263,8 +203,6 @@ static void command_line_parse_error (int *argc, char** argv[]) {
|
||||
}
|
||||
|
||||
#else
|
||||
static void console_madness_begin () {}
|
||||
static void console_madness_end () {}
|
||||
static void command_line_parse_error (int *argc, char** argv[]) {}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user