From 5bc1aff578f1754a1834d221ae9fe6fcefbcef5f Mon Sep 17 00:00:00 2001 From: Francois Gouget Date: Wed, 24 Aug 2011 14:29:31 +0200 Subject: [PATCH] programs: Document the reason for the WriteConsole() fall back. --- programs/hostname/hostname.c | 4 ++++ programs/ipconfig/ipconfig.c | 4 ++++ programs/reg/reg.c | 4 ++++ programs/taskkill/taskkill.c | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/programs/hostname/hostname.c b/programs/hostname/hostname.c index 77ff23b42fd..8bf8676a971 100644 --- a/programs/hostname/hostname.c +++ b/programs/hostname/hostname.c @@ -53,6 +53,10 @@ static int hostname_vprintfW(const WCHAR *msg, va_list va_args) 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. + */ len = WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, NULL, 0, NULL, NULL); msgA = HeapAlloc(GetProcessHeap(), 0, len); diff --git a/programs/ipconfig/ipconfig.c b/programs/ipconfig/ipconfig.c index 14974ae8369..37e709931e7 100644 --- a/programs/ipconfig/ipconfig.c +++ b/programs/ipconfig/ipconfig.c @@ -40,6 +40,10 @@ static int ipconfig_vprintfW(const WCHAR *msg, va_list va_args) 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. + */ len = WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, NULL, 0, NULL, NULL); msgA = HeapAlloc(GetProcessHeap(), 0, len); diff --git a/programs/reg/reg.c b/programs/reg/reg.c index 0f8aa151b79..8a6ffc44fcd 100644 --- a/programs/reg/reg.c +++ b/programs/reg/reg.c @@ -38,6 +38,10 @@ static int reg_printfW(const WCHAR *msg, ...) 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. + */ len = WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, NULL, 0, NULL, NULL); msgA = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char)); diff --git a/programs/taskkill/taskkill.c b/programs/taskkill/taskkill.c index 1dc1fccc512..c6423c4b534 100644 --- a/programs/taskkill/taskkill.c +++ b/programs/taskkill/taskkill.c @@ -50,6 +50,10 @@ static int taskkill_vprintfW(const WCHAR *msg, va_list va_args) 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. + */ len = WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, NULL, 0, NULL, NULL); msgA = HeapAlloc(GetProcessHeap(), 0, len);