From ae0b2b2e35c9ac7851bb7d12f72f33ac996030a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Tue, 1 Jan 2013 14:55:53 +0000 Subject: [PATCH] [REGEDIT] Fix totally broken InfoMessageBox function. ~=~=\|/ **** Happy New Year 2013 !!!! **** \|/=~=~ svn path=/trunk/; revision=58085 --- reactos/base/applications/regedit/error.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/reactos/base/applications/regedit/error.c b/reactos/base/applications/regedit/error.c index 631359154df..cd4ba993e80 100644 --- a/reactos/base/applications/regedit/error.c +++ b/reactos/base/applications/regedit/error.c @@ -40,7 +40,7 @@ int ErrorMessageBox(HWND hWnd, LPCWSTR lpTitle, DWORD dwErrorCode, ...) va_end(args); - iRet = MessageBoxW(hWnd, (Status && lpMsgBuf ? lpMsgBuf : L"Error displaying error message.\n"), lpTitle, MB_OK | MB_ICONERROR); + iRet = MessageBoxW(hWnd, (Status && lpMsgBuf ? lpMsgBuf : L"Error displaying error message."), lpTitle, MB_OK | MB_ICONERROR); if (lpMsgBuf) LocalFree(lpMsgBuf); @@ -52,22 +52,25 @@ int InfoMessageBox(HWND hWnd, UINT uType, LPCWSTR lpTitle, LPCWSTR lpMessage, .. { int iRet = 0; LPWSTR lpMsgBuf = NULL; - DWORD Status = 0; va_list args = NULL; va_start(args, lpMessage); - Status = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING, - lpMessage, - 0, - 0, - (LPWSTR)&lpMsgBuf, - 0, - &args); + if (lpMessage) + { + SIZE_T strLen = _vscwprintf(lpMessage, args); + + /* Create a buffer on the heap and zero-out it (LPTR) */ + lpMsgBuf = (LPWSTR)LocalAlloc(LPTR, (strLen + 1) * sizeof(WCHAR)); + if (lpMsgBuf) + { + _vsnwprintf(lpMsgBuf, strLen, lpMessage, args); + } + } va_end(args); - iRet = MessageBoxW(hWnd, (Status && lpMsgBuf ? lpMsgBuf : L"Error displaying error message.\n"), lpTitle, uType); + iRet = MessageBoxW(hWnd, (lpMessage && lpMsgBuf ? lpMsgBuf : L"Error displaying info message."), lpTitle, uType); if (lpMsgBuf) LocalFree(lpMsgBuf);