From: Hugh McMaster Subject: [1/4] regsvr32: Insert unicode print function Message-Id: <9CB7F20010CADE479EB89B7DCEDFB64268076ED6E7@VMBX112.ihostexchange.net> Date: Mon, 10 Mar 2014 22:13:27 -0400 This patch inserts a new print function into regsvr32.c. It is called in patch (3). Thank you to Akihiro Sagawa for reviewing this patch series. From 537aeb2e53e72efdb96f64e9ff864af74cebe397 Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Mon, 10 Mar 2014 22:11:50 +1100 Subject: Insert output_write function --- programs/regsvr32/regsvr32.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c index 3536e93..94db5f2 100644 --- a/programs/regsvr32/regsvr32.c +++ b/programs/regsvr32/regsvr32.c @@ -55,6 +55,9 @@ #include #include #include +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(regsvr32); typedef HRESULT (*DLLREGISTER) (void); typedef HRESULT (*DLLUNREGISTER) (void); @@ -74,6 +77,56 @@ static int Usage(void) return 0; } +static void __cdecl output_write(UINT id, ...) +{ + static WCHAR fmt[1024]; + __ms_va_list va_args; + WCHAR *str; + DWORD len, nOut, ret; + + if (Silent) return; + + if (!LoadStringW(GetModuleHandleW(NULL), id, fmt, sizeof(fmt)/sizeof(WCHAR))) + { + WINE_FIXME("LoadString failed with %d\n", GetLastError()); + return; + } + + __ms_va_start(va_args, id); + SetLastError(NO_ERROR); + len = FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER, + fmt, 0, 0, (LPWSTR)&str, 0, &va_args); + __ms_va_end(va_args); + if (len == 0 && GetLastError() != NO_ERROR) + { + WINE_FIXME("Could not format string: le=%u, fmt=%s\n", GetLastError(), wine_dbgstr_w(fmt)); + return; + } + + ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, len, &nOut, NULL); + + /* WriteConsoleW() fails if the output is redirected. + * If this happens, we should call WriteFile() and use the OEM codepage. */ + if (!ret) + { + 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); +} + /** * Loads procedure. * -- 1.8.3.2