* @brief Attaches the application to the parent console and redirects stdout/stderr. */
| 225 | * @brief Attaches the application to the parent console and redirects stdout/stderr. |
| 226 | */ |
| 227 | static void attachToConsole() |
| 228 | { |
| 229 | if (handleIsRedirected(STD_OUTPUT_HANDLE)) { |
| 230 | bindStreamToStdHandle(STD_OUTPUT_HANDLE, stdout); |
| 231 | bindStreamToStdHandle(STD_ERROR_HANDLE, stderr); |
| 232 | return; |
| 233 | } |
| 234 | |
| 235 | if (AttachConsole(ATTACH_PARENT_PROCESS)) { |
| 236 | FILE* fp = nullptr; |
| 237 | (void)freopen_s(&fp, "CONOUT$", "w", stdout); |
| 238 | (void)freopen_s(&fp, "CONOUT$", "w", stderr); |
| 239 | // code-verify off -- raw stdio is the only path before Qt is up |
| 240 | printf("\n"); |
| 241 | // code-verify on |
| 242 | |
| 243 | std::atexit(redrawConsolePromptAtExit); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * @brief Pins the process to a stable Windows AppUserModelID. |
no test coverage detected