From: Hugh McMaster Subject: [3/4] regsvr32: Add WriteFile support Message-Id: <9CB7F20010CADE479EB89B7DCEDFB642687E60AE62@VMBX112.ihostexchange.net> Date: Tue, 29 Apr 2014 02:05:39 -0400 This patch adds WriteFile() support to regsvr32's output_write() function. It is used in the event that WriteConsoleW() fails. This patch is the third of a series of four: 1. Implement new argument/flag handler. 2. Convert source to Unicode. 3. Add WriteFile() support if WriteConsoleW() fails. 4. Improve source comments (e.g. spelling, grammar, etc.) From 2ef6097ebf83c3b30282fa48e9104e4d3c18e0fa Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Mon, 28 Apr 2014 20:20:31 +1000 Subject: regsvr32-writefile --- programs/regsvr32/regsvr32.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c index 4d0ec0c..1134ac1 100644 --- a/programs/regsvr32/regsvr32.c +++ b/programs/regsvr32/regsvr32.c @@ -94,8 +94,25 @@ static void __cdecl output_write(UINT id, ...) ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, len, &nOut, NULL); + /* WriteConsoleW() fails if its output is redirected to a file. + * If this happens, we should call WriteFile() for I/O and use an OEM codepage. */ if (!ret) - WINE_WARN("regsvr32: WriteConsoleW() failed.\n"); + { + DWORD lenA; + char *strA; + + lenA = WideCharToMultiByte(GetConsoleOutputCP(), 0, str, len, NULL, 0, NULL, NULL); + strA = HeapAlloc(GetProcessHeap(), 0, lenA); + if (!strA) + { + LocalFree(str); + return; + } + + WideCharToMultiByte(GetConsoleOutputCP(), 0, str, len, strA, lenA, NULL, NULL); + WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), strA, len, &nOut, FALSE); + HeapFree(GetProcessHeap(), 0, strA); + } LocalFree(str); } -- 1.8.3.2