From: Hugh McMaster Subject: [Patch 2/2] regsvr32: Add WriteFile() fallback (resend) Message-Id: <9CB7F20010CADE479EB89B7DCEDFB64269FACD5D23@VMBX112.ihostexchange.net> Date: Wed, 25 Jun 2014 07:34:13 -0400 This patch adds WriteFile() fallback to the output_write function, should WriteFile() fail due to its output being redirected. From 0ec80a571fd7b37f9502a7b2a2493a3479d389dc Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Wed, 25 Jun 2014 21:24:54 +1000 Subject: regsvr32: Add WriteFile() fallback to output_write --- 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 4171d75..eb7b890 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); + /* WriteConsole fails if its output is redirected to a file. + * If this occurs, 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