don't crash if FormatMessage() fails in wxSysErrorMsg()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34554 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2005-06-06 22:05:16 +00:00
parent cd39c77a7b
commit d0822e56c6

View File

@ -737,14 +737,26 @@ const wxChar *wxSysErrorMsg(unsigned long nErrCode)
// get error message from system
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, nErrCode,
if ( ::FormatMessage
(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
nErrCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0, NULL);
0,
NULL
) == 0 )
{
// if this happens, something is seriously wrong, so don't use _() here
// for safety
wxSprintf(s_szBuf, _T("unknown error %lx"), nErrCode);
return s_szBuf;
}
// copy it to our buffer and free memory
// Crashes on SmartPhone
// Crashes on SmartPhone (FIXME)
#if !defined(__SMARTPHONE__) /* of WinCE */
if( lpMsgBuf != 0 ) {
wxStrncpy(s_szBuf, (const wxChar *)lpMsgBuf, WXSIZEOF(s_szBuf) - 1);