Skip to content

Commit

Permalink
win32: support logging to command line
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed Apr 26, 2024
1 parent 8691fde commit 0efc15e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/win32/yass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
return -1;
}

// This function is primarily useful to applications that were linked with /SUBSYSTEM:WINDOWS,
// which implies to the operating system that a console is not needed
// before entering the program's main method.
if (AttachConsole(ATTACH_PARENT_PROCESS) != 0) {
FILE* unusedFile;
// Swap to the new out/err streams
freopen_s(&unusedFile, "CONOUT$", "w", stdout);
freopen_s(&unusedFile, "CONOUT$", "w", stderr);
std::cout.clear();
std::clog.clear();
std::cerr.clear();
fprintf(stderr, "attached to parent process\n");
fflush(stderr);
}

if (!SetUTF8Locale()) {
LOG(WARNING) << "Failed to set up utf-8 locale";
}
Expand Down

0 comments on commit 0efc15e

Please sign in to comment.