mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +00:00
[CLIPBRD][EVENTVWR][MPLAY32][WELCOME][SYSDM]
Fix the ShowLastWin32Error helpers: - don't display the last error string if it's ERROR_SUCCESS (since the code usually expects to display the last error message in case of errors); - *always* call FormatMessage with the FORMAT_MESSAGE_IGNORE_INSERTS flag enabled. Indeed if it happens that the message string associated to an error ID contains insert parameter placeholders, and since we don't give here FormatMessage any argument array, the call would result into a crash without this flag. svn path=/trunk/; revision=72897
This commit is contained in:
parent
eb94308bbb
commit
1c4750792d
5 changed files with 68 additions and 39 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue