Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions examples/common/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,28 @@ static void print_utf8(FILE* stream, const char* utf8) {
? GetStdHandle(STD_ERROR_HANDLE)
: GetStdHandle(STD_OUTPUT_HANDLE);

int wlen = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
if (wlen <= 0)
return;
DWORD mode;
BOOL is_console = GetConsoleMode(h, &mode);

if (is_console) {
int wlen = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
if (wlen <= 0)
return;

wchar_t* wbuf = (wchar_t*)malloc(wlen * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wbuf, wlen);
wchar_t* wbuf = (wchar_t*)malloc(wlen * sizeof(wchar_t));
if (!wbuf)
return;

DWORD written;
WriteConsoleW(h, wbuf, wlen - 1, &written, NULL);
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wbuf, wlen);

free(wbuf);
DWORD written;
WriteConsoleW(h, wbuf, wlen - 1, &written, NULL);

free(wbuf);
} else {
DWORD written;
WriteFile(h, utf8, (DWORD)strlen(utf8), &written, NULL);
}
#else
fputs(utf8, stream);
#endif
Expand Down
Loading