[PATCH 2/4] programs/regsvr32: Add WriteFile fallback if WriteConsole fails
Hugh McMaster
hugh.mcmaster at outlook.com
Tue Jun 23 06:27:23 CDT 2015
---
programs/regsvr32/regsvr32.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c
index cdf64ae..e9fc1d1 100644
--- a/programs/regsvr32/regsvr32.c
+++ b/programs/regsvr32/regsvr32.c
@@ -94,9 +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 use an OEM codepage and call WriteFile.
+ */
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, lenA, &nOut, FALSE);
+ HeapFree(GetProcessHeap(), 0, strA);
+ }
LocalFree(str);
}
--
1.9.1
More information about the wine-patches
mailing list