[PATCH 3/3] programs/regsvr32: Add WriteFile fallback in case WriteConsole fails (version 2)

Hugh McMaster hugh.mcmaster at outlook.com
Thu Jun 18 04:48:42 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 7301b1a..6469576 100644
--- a/programs/regsvr32/regsvr32.c
+++ b/programs/regsvr32/regsvr32.c
@@ -93,9 +93,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, lenA, &nOut, FALSE);
+        HeapFree(GetProcessHeap(), 0, strA);
+    }
     LocalFree(str);
 }
 
-- 
1.9.1




More information about the wine-patches mailing list