From 86ebd5eee06c6d6b351dcad1154243acaf8f4fdf Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Fri, 15 Jul 2016 07:49:58 +0000 Subject: [PATCH] regedit: Use Unicode when printing system error messages. Signed-off-by: Hugh McMaster Signed-off-by: Alexandre Julliard --- programs/regedit/regedit.c | 2 +- programs/regedit/regproc.c | 23 ++++++++++++----------- programs/regedit/regproc.h | 1 + 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/programs/regedit/regedit.c b/programs/regedit/regedit.c index 55f2b8dc424..c0a1eab46e4 100644 --- a/programs/regedit/regedit.c +++ b/programs/regedit/regedit.c @@ -28,7 +28,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(regedit); -static void output_writeconsole(const WCHAR *str, DWORD wlen) +void output_writeconsole(const WCHAR *str, DWORD wlen) { DWORD count, ret; diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c index f0726505a2a..4a27bd56562 100644 --- a/programs/regedit/regproc.c +++ b/programs/regedit/regproc.c @@ -31,8 +31,11 @@ #include #include #include +#include #include "regproc.h" +WINE_DEFAULT_DEBUG_CHANNEL(regedit); + #define REG_VAL_BUF_SIZE 4096 /* maximal number of characters in hexadecimal data line, @@ -856,20 +859,18 @@ static void processRegLinesW(FILE *in) static void REGPROC_print_error(void) { - LPVOID lpMsgBuf; - DWORD error_code; - int status; + WCHAR *str; + DWORD error_code, len; - error_code = GetLastError (); - status = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, error_code, 0, (LPSTR) &lpMsgBuf, 0, NULL); - if (!status) { - fprintf(stderr, "regedit: Cannot display message for error %d, status %d\n", - error_code, GetLastError()); + error_code = GetLastError(); + len = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error_code, 0, (WCHAR *)&str, 0, NULL); + if (len == 0 && GetLastError() != NO_ERROR) { + WINE_FIXME("FormatMessage failed: le=%u, previous=%u\n", GetLastError(), error_code); exit(1); } - puts(lpMsgBuf); - LocalFree(lpMsgBuf); + output_writeconsole(str, len); + LocalFree(str); exit(1); } diff --git a/programs/regedit/regproc.h b/programs/regedit/regproc.h index aff4beebf04..bc460099ca5 100644 --- a/programs/regedit/regproc.h +++ b/programs/regedit/regproc.h @@ -24,6 +24,7 @@ #define REG_FORMAT_5 1 #define REG_FORMAT_4 2 +void output_writeconsole(const WCHAR *str, DWORD wlen); void __cdecl output_message(unsigned int id, ...); BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format);