Hugh McMaster : regsvr32: Add WriteFile fallback if WriteConsole fails.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Jun 24 09:51:05 CDT 2015


Module: wine
Branch: master
Commit: 485b8dfcf2e4865b2633ce10f046d7689db68d05
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=485b8dfcf2e4865b2633ce10f046d7689db68d05

Author: Hugh McMaster <hugh.mcmaster at outlook.com>
Date:   Tue Jun 23 21:27:23 2015 +1000

regsvr32: Add WriteFile fallback if WriteConsole fails.

---

 programs/regsvr32/regsvr32.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c
index 1c9d1b0..2e7af5b 100644
--- a/programs/regsvr32/regsvr32.c
+++ b/programs/regsvr32/regsvr32.c
@@ -93,9 +93,23 @@ 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)
+        {
+            WideCharToMultiByte(GetConsoleOutputCP(), 0, str, len, strA, lenA, NULL, NULL);
+            WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), strA, lenA, &nOut, FALSE);
+            HeapFree(GetProcessHeap(), 0, strA);
+        }
+    }
     LocalFree(str);
 }
 




More information about the wine-cvs mailing list