diff --git a/reactos/base/applications/clipbrd/winutils.c b/reactos/base/applications/clipbrd/winutils.c index 71b0e40b3e9..43697d53e94 100644 --- a/reactos/base/applications/clipbrd/winutils.c +++ b/reactos/base/applications/clipbrd/winutils.c @@ -14,9 +14,21 @@ void ShowLastWin32Error(HWND hwndParent) LPWSTR lpMsgBuf = NULL; dwError = GetLastError(); + if (dwError == ERROR_SUCCESS) + return; + + if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dwError, + LANG_USER_DEFAULT, + (LPWSTR)&lpMsgBuf, + 0, NULL)) + { + return; + } - FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, dwError, 0, (LPWSTR)&lpMsgBuf, 0, NULL); MessageBoxW(hwndParent, lpMsgBuf, NULL, MB_OK | MB_ICONERROR); LocalFree(lpMsgBuf); } diff --git a/reactos/base/applications/mplay32/mplay32.c b/reactos/base/applications/mplay32/mplay32.c index 7845c427fc8..1a2e347de3e 100644 --- a/reactos/base/applications/mplay32/mplay32.c +++ b/reactos/base/applications/mplay32/mplay32.c @@ -209,16 +209,23 @@ ShowLastWin32Error(HWND hwnd) LPTSTR lpMessageBuffer; DWORD dwError = GetLastError(); - if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - dwError, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&lpMessageBuffer, - 0, NULL) != 0) + if (dwError == ERROR_SUCCESS) + return; + + if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dwError, + LANG_USER_DEFAULT, + (LPTSTR)&lpMessageBuffer, + 0, NULL)) { - MessageBox(hwnd, lpMessageBuffer, szAppTitle, MB_OK | MB_ICONERROR); - if (lpMessageBuffer) LocalFree(lpMessageBuffer); + return; } + + MessageBox(hwnd, lpMessageBuffer, szAppTitle, MB_OK | MB_ICONERROR); + LocalFree(lpMessageBuffer); } static VOID diff --git a/reactos/base/applications/mscutils/eventvwr/eventvwr.c b/reactos/base/applications/mscutils/eventvwr/eventvwr.c index 96c8fd06156..74d43e6042c 100644 --- a/reactos/base/applications/mscutils/eventvwr/eventvwr.c +++ b/reactos/base/applications/mscutils/eventvwr/eventvwr.c @@ -245,13 +245,20 @@ ShowLastWin32Error(VOID) LPWSTR lpMessageBuffer; dwError = GetLastError(); - FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - dwError, - 0, - (LPWSTR)&lpMessageBuffer, - 0, - NULL); + if (dwError == ERROR_SUCCESS) + return; + + if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dwError, + LANG_USER_DEFAULT, + (LPWSTR)&lpMessageBuffer, + 0, NULL)) + { + return; + } MessageBoxW(hwndMainWindow, lpMessageBuffer, szTitle, MB_OK | MB_ICONERROR); LocalFree(lpMessageBuffer); diff --git a/reactos/base/setup/welcome/welcome.c b/reactos/base/setup/welcome/welcome.c index f0a2732d871..bae244ac5e1 100644 --- a/reactos/base/setup/welcome/welcome.c +++ b/reactos/base/setup/welcome/welcome.c @@ -113,20 +113,23 @@ ShowLastWin32Error(HWND hWnd) LPTSTR lpMessageBuffer = NULL; DWORD dwError = GetLastError(); - if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - dwError, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&lpMessageBuffer, - 0, NULL)) + if (dwError == ERROR_SUCCESS) + return; + + if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dwError, + LANG_USER_DEFAULT, + (LPTSTR)&lpMessageBuffer, + 0, NULL)) { - MessageBox(hWnd, lpMessageBuffer, szAppTitle, MB_OK | MB_ICONERROR); + return; } - if (lpMessageBuffer) - { - LocalFree(lpMessageBuffer); - } + MessageBox(hWnd, lpMessageBuffer, szAppTitle, MB_OK | MB_ICONERROR); + LocalFree(lpMessageBuffer); } #endif diff --git a/reactos/dll/cpl/sysdm/general.c b/reactos/dll/cpl/sysdm/general.c index 33e209acbd9..9516c33756e 100644 --- a/reactos/dll/cpl/sysdm/general.c +++ b/reactos/dll/cpl/sysdm/general.c @@ -35,23 +35,23 @@ VOID ShowLastWin32Error(HWND hWndOwner) DWORD LastError; LastError = GetLastError(); + if (LastError == ERROR_SUCCESS) + return; - if ((LastError == 0) || - !FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - LastError, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&lpMsg, - 0, - NULL)) + if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + LastError, + LANG_USER_DEFAULT, + (LPTSTR)&lpMsg, + 0, NULL)) { return; } MessageBox(hWndOwner, lpMsg, NULL, MB_OK | MB_ICONERROR); - - LocalFree((LPVOID)lpMsg); + LocalFree(lpMsg); }