netstat: Use OEM code page for output.

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Eric Pouech 2022-04-28 11:22:40 +02:00 committed by Alexandre Julliard
parent 9ac9ea5914
commit b421477d33
2 changed files with 6 additions and 8 deletions

View File

@ -125,7 +125,7 @@ static int WINAPIV NETSTAT_wprintf(const WCHAR *format, ...)
} }
/* Convert to OEM, then output */ /* Convert to OEM, then output */
convertedChars = WideCharToMultiByte(GetConsoleOutputCP(), 0, output_bufW, convertedChars = WideCharToMultiByte(GetOEMCP(), 0, output_bufW,
len, output_bufA, MAX_WRITECONSOLE_SIZE, len, output_bufA, MAX_WRITECONSOLE_SIZE,
"?", &usedDefaultChar); "?", &usedDefaultChar);
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), output_bufA, convertedChars, WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), output_bufA, convertedChars,

View File

@ -51,22 +51,20 @@ const struct reg_type_rels type_rels[] =
void output_writeconsole(const WCHAR *str, DWORD wlen) void output_writeconsole(const WCHAR *str, DWORD wlen)
{ {
DWORD count, ret; DWORD count;
ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, wlen, &count, NULL); if (!WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, wlen, &count, NULL))
if (!ret)
{ {
DWORD len; DWORD len;
char *msgA; char *msgA;
/* On Windows WriteConsoleW() fails if the output is redirected. So fall /* On Windows WriteConsoleW() fails if the output is redirected. So fall
* back to WriteFile(), assuming the console encoding is still the right * back to WriteFile() with OEM code page.
* one in that case.
*/ */
len = WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, NULL, 0, NULL, NULL); len = WideCharToMultiByte(GetOEMCP(), 0, str, wlen, NULL, 0, NULL, NULL);
msgA = malloc(len); msgA = malloc(len);
WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, msgA, len, NULL, NULL); WideCharToMultiByte(GetOEMCP(), 0, str, wlen, msgA, len, NULL, NULL);
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE); WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
free(msgA); free(msgA);
} }