[PATCH 5/6] regsvr32: Add WriteFile fallback in case WriteConsole fails

Hugh McMaster hugh.mcmaster at outlook.com
Sun Jun 7 06:13:58 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 1c71736..6d1f957 100644
--- a/programs/regsvr32/regsvr32.c
+++ b/programs/regsvr32/regsvr32.c
@@ -94,8 +94,24 @@ 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.9.1




More information about the wine-patches mailing list