diff --git a/OpenFlipper.cc b/OpenFlipper.cc index 4e52dd91051f3c448b3ddcd293e73037eca61f16..915c5fee5ebb159ff76804da94fb2e15478d5a5f 100644 --- a/OpenFlipper.cc +++ b/OpenFlipper.cc @@ -111,62 +111,42 @@ #ifdef WIN32 +#define CONNECT_CONSOLE \ + FILE* check = freopen("CONIN$", "r", stdin); \ + if (check) { \ + std::cerr << "Error reopening stdin" << std::endl; \ + } \ + check = freopen("CONOUT$", "w", stdout); \ + if (check) { \ + std::cerr << "Error reopening stdout" << std::endl; \ + } \ + check = freopen("CONOUT$", "w", stderr); \ + if (check) { \ + std::cerr << "Error reopening stderr" << std::endl; \ + } + void attachConsole() { //try to attach the console of the parent process if (AttachConsole(-1)) { //if the console was attached change stdinput and output - FILE* check = freopen("CONIN$", "r", stdin); - if (check) { - std::cerr << "Error reopening stdin" << std::endl; - } - check = freopen("CONOUT$", "w", stdout); - if (check) { - std::cerr << "Error reopening stdout" << std::endl; - } - check = freopen("CONOUT$", "w", stderr); - if (check) { - std::cerr << "Error reopening stderr" << std::endl; - } + CONNECT_CONSOLE } else { //create and attach a new console if needed #ifndef NDEBUG //always open a console in debug mode - AllocConsole(); + AllocConsole(); + CONNECT_CONSOLE - FILE* check = freopen("CONIN$", "r", stdin); - if (check) { - std::cerr << "Error reopening stdin" << std::endl; - } - check = freopen("CONOUT$", "w", stdout); - if (check) { - std::cerr << "Error reopening stdout" << std::endl; - } - check = freopen("CONOUT$", "w", stderr); - if (check) { - std::cerr << "Error reopening stderr" << std::endl; - } return; #endif if (OpenFlipper::Options::logToConsole()) { AllocConsole(); - - FILE* check = freopen("CONIN$", "r", stdin); - if (check) { - std::cerr << "Error reopening stdin" << std::endl; - } - check = freopen("CONOUT$", "w", stdout); - if (check) { - std::cerr << "Error reopening stdout" << std::endl; - } - check = freopen("CONOUT$", "w", stderr); - if (check) { - std::cerr << "Error reopening stderr" << std::endl; - } + CONNECT_CONSOLE } } }