Fix console output text encoding for win32.

This commit is contained in:
halx99 2021-05-26 00:24:39 +08:00
parent 99cdafb661
commit 026c3ab7c5
1 changed files with 6 additions and 3 deletions

View File

@ -158,10 +158,13 @@ void log(const char * format, ...)
OutputDebugStringW(wbuf.c_str());
#if CC_LOG_TO_CONSOLE
if (GetStdHandle(STD_INPUT_HANDLE)) {
auto hStdout = ::GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdout) {
// print to console if possible
wprintf(L"%s", wbuf.c_str());
fflush(stdout);
// since we use win32 API, the ::fflush call doesn't required.
// see: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-flushfilebuffers#return-value
DWORD wcch = static_cast<DWORD>(wbuf.size());
::WriteConsoleW(hStdout, wbuf.c_str(), wcch, nullptr, 0);
}
#endif