[PATCH 3/4] programs/chcp.com: write redirected output in UTF8

Eric Pouech eric.pouech at gmail.com
Fri Apr 15 07:48:36 CDT 2022


Signed-off-by: Eric Pouech <eric.pouech at gmail.com>

---
 programs/chcp.com/main.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/programs/chcp.com/main.c b/programs/chcp.com/main.c
index 6c5864d0e19..b7299d05437 100644
--- a/programs/chcp.com/main.c
+++ b/programs/chcp.com/main.c
@@ -34,14 +34,13 @@ static void output_writeconsole(const WCHAR *str, DWORD wlen)
         DWORD len;
         char  *msgA;
 
-        /* On Windows WriteConsoleW() fails if the output is redirected. So fall
-         * back to WriteFile(), assuming the console encoding is still the right
-         * one in that case.
+        /* WriteConsoleW() fails if the output is redirected. So fall back to WriteFile(),
+         * using UTF8 encoding.
          */
-        len = WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, NULL, 0, NULL, NULL);
+        len = WideCharToMultiByte(CP_UTF8, 0, str, wlen, NULL, 0, NULL, NULL);
         msgA = malloc(len);
 
-        WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, msgA, len, NULL, NULL);
+        WideCharToMultiByte(CP_UTF8, 0, str, wlen, msgA, len, NULL, NULL);
         WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
         free(msgA);
     }




More information about the wine-devel mailing list