-const char *wxSysErrorMsg(unsigned long nErrCode)
-{
- if ( nErrCode == 0 )
- nErrCode = wxSysErrorCode();
-
- #ifdef __WXMSW__
- #ifdef __WIN32__
- static char s_szBuf[LOG_BUFFER_SIZE / 2];
-
- // get error message from system
- LPVOID lpMsgBuf;
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, nErrCode,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR)&lpMsgBuf,
- 0, NULL);
-
- // copy it to our buffer and free memory
- strncpy(s_szBuf, (const char *)lpMsgBuf, WXSIZEOF(s_szBuf) - 1);
- s_szBuf[WXSIZEOF(s_szBuf) - 1] = '\0';
- LocalFree(lpMsgBuf);
-
- // returned string is capitalized and ended with '\r\n' - bad
- s_szBuf[0] = (char)wxToLower(s_szBuf[0]);
- size_t len = strlen(s_szBuf);
- if ( len > 0 ) {
- // truncate string
- if ( s_szBuf[len - 2] == '\r' )
- s_szBuf[len - 2] = '\0';
- }
-
- return s_szBuf;
- #else //Win16
- // TODO @@@@
- return NULL;
- #endif // Win16/32
- #else // Unix
- return strerror(nErrCode);
- #endif // Win/Unix
-}
-
-// ----------------------------------------------------------------------------
-// debug helper
-// ----------------------------------------------------------------------------
-
-#ifdef __WXDEBUG__
-
-void Trap()
-{
- #ifdef __WXMSW__
- DebugBreak();
- #else // Unix
- raise(SIGTRAP);
- #endif // Win/Unix
-}
-
-// this function is called when an assert fails
-void wxOnAssert(const char *szFile, int nLine, const char *szMsg)
-{
- // this variable can be set to true to suppress "assert failure" messages
- static bool s_bNoAsserts = FALSE;
- static bool s_bInAssert = FALSE;
-
- if ( s_bInAssert ) {
- // He-e-e-e-elp!! we're trapped in endless loop
- Trap();
- }
-
- s_bInAssert = TRUE;
-
- char szBuf[LOG_BUFFER_SIZE];
- sprintf(szBuf, _("Assert failed in file %s at line %d"), szFile, nLine);
- if ( szMsg != NULL ) {
- strcat(szBuf, ": ");
- strcat(szBuf, szMsg);
- }
- else {
- strcat(szBuf, ".");
- }
-
- if ( !s_bNoAsserts ) {
- // send it to the normal log destination
- wxLogDebug(szBuf);
+const wxChar *wxSysErrorMsg(unsigned long nErrCode)
+{
+ if ( nErrCode == 0 )
+ nErrCode = wxSysErrorCode();
+
+#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
+ static wxChar s_szBuf[LOG_BUFFER_SIZE / 2];
+
+ // get error message from system
+ LPVOID lpMsgBuf;
+ if ( ::FormatMessage
+ (
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ nErrCode,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR)&lpMsgBuf,
+ 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;
+ }