1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/log.cpp
3 // Purpose: Assorted wxLogXXX functions, and wxLog (sink for logs)
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
33 #include "wx/arrstr.h"
35 #include "wx/string.h"
39 #include "wx/apptrait.h"
40 #include "wx/datetime.h"
42 #include "wx/msgout.h"
43 #include "wx/textfile.h"
44 #include "wx/thread.h"
45 #include "wx/private/threadinfo.h"
47 #include "wx/vector.h"
49 // other standard headers
60 #include "wx/msw/wince/time.h"
62 #endif /* ! __WXPALMOS5__ */
64 #if defined(__WINDOWS__)
65 #include "wx/msw/private.h" // includes windows.h
68 #undef wxLOG_COMPONENT
69 const char *wxLOG_COMPONENT
= "";
71 // this macro allows to define an object which will be initialized before any
72 // other function in this file is called: this is necessary to allow log
73 // functions to be used during static initialization (this is not advisable
74 // anyhow but we should at least try to not crash) and to also ensure that they
75 // are initialized by the time static initialization is done, i.e. before any
76 // threads are created hopefully
78 // the net effect of all this is that you can use Get##name() function to
79 // access the object without worrying about it being not initialized
81 // see also WX_DEFINE_GLOBAL_CONV2() in src/common/strconv.cpp
82 #define WX_DEFINE_GLOBAL_VAR(type, name) \
83 inline type& Get##name() \
85 static type s_##name; \
89 type *gs_##name##Ptr = &Get##name()
93 wxTLS_TYPE(wxThreadSpecificInfo
) wxThreadInfoVar
;
98 // contains messages logged by the other threads and waiting to be shown until
99 // Flush() is called in the main one
100 typedef wxVector
<wxLogRecord
> wxLogRecords
;
101 wxLogRecords gs_bufferedLogRecords
;
103 #define WX_DEFINE_LOG_CS(name) WX_DEFINE_GLOBAL_VAR(wxCriticalSection, name##CS)
105 // this critical section is used for buffering the messages from threads other
106 // than main, i.e. it protects all accesses to gs_bufferedLogRecords above
107 WX_DEFINE_LOG_CS(BackgroundLog
);
109 // this one is used for protecting TraceMasks() from concurrent access
110 WX_DEFINE_LOG_CS(TraceMask
);
112 // and this one is used for GetComponentLevels()
113 WX_DEFINE_LOG_CS(Levels
);
115 } // anonymous namespace
117 #endif // wxUSE_THREADS
119 // ----------------------------------------------------------------------------
120 // non member functions
121 // ----------------------------------------------------------------------------
123 // define this to enable wrapping of log messages
124 //#define LOG_PRETTY_WRAP
126 #ifdef LOG_PRETTY_WRAP
127 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
);
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
137 // this struct is used to store information about the previous log message used
138 // by OnLog() to (optionally) avoid logging multiple copies of the same message
139 struct PreviousLogInfo
147 // previous message itself
153 // other information about it
154 wxLogRecordInfo info
;
156 // the number of times it was already repeated
157 unsigned numRepeated
;
160 PreviousLogInfo gs_prevLog
;
163 // map containing all components for which log level was explicitly set
165 // NB: all accesses to it must be protected by GetLevelsCS() critical section
166 WX_DEFINE_GLOBAL_VAR(wxStringToNumHashMap
, ComponentLevels
);
168 // ----------------------------------------------------------------------------
169 // wxLogOutputBest: wxLog wrapper around wxMessageOutputBest
170 // ----------------------------------------------------------------------------
172 class wxLogOutputBest
: public wxLog
175 wxLogOutputBest() { }
178 virtual void DoLogText(const wxString
& msg
)
180 wxMessageOutputBest().Output(msg
);
184 wxDECLARE_NO_COPY_CLASS(wxLogOutputBest
);
187 } // anonymous namespace
189 // ============================================================================
191 // ============================================================================
193 // ----------------------------------------------------------------------------
194 // helper global functions
195 // ----------------------------------------------------------------------------
197 void wxSafeShowMessage(const wxString
& title
, const wxString
& text
)
200 ::MessageBox(NULL
, text
.t_str(), title
.t_str(), MB_OK
| MB_ICONSTOP
);
202 wxFprintf(stderr
, wxS("%s: %s\n"), title
.c_str(), text
.c_str());
207 // ----------------------------------------------------------------------------
208 // wxLog class implementation
209 // ----------------------------------------------------------------------------
211 unsigned wxLog::LogLastRepeatIfNeeded()
213 const unsigned count
= gs_prevLog
.numRepeated
;
215 if ( gs_prevLog
.numRepeated
)
219 if ( gs_prevLog
.numRepeated
== 1 )
221 // We use a separate message for this case as "repeated 1 time"
222 // looks somewhat strange.
223 msg
= _("The previous message repeated once.");
227 // Notice that we still use wxPLURAL() to ensure that multiple
228 // numbers of times are correctly formatted, even though we never
229 // actually use the singular string.
230 msg
.Printf(wxPLURAL("The previous message repeated %lu time.",
231 "The previous message repeated %lu times.",
232 gs_prevLog
.numRepeated
),
233 gs_prevLog
.numRepeated
);
236 msg
.Printf(wxS("The previous message was repeated %lu time(s)."),
237 gs_prevLog
.numRepeated
);
239 gs_prevLog
.numRepeated
= 0;
240 gs_prevLog
.msg
.clear();
241 DoLogRecord(gs_prevLog
.level
, msg
, gs_prevLog
.info
);
249 // Flush() must be called before destroying the object as otherwise some
250 // messages could be lost
251 if ( gs_prevLog
.numRepeated
)
253 wxMessageOutputDebug().Printf
258 "Last repeated message (\"%s\", %lu time) wasn't output",
259 "Last repeated message (\"%s\", %lu times) wasn't output",
260 gs_prevLog
.numRepeated
263 wxS("Last repeated message (\"%s\", %lu time(s)) wasn't output"),
266 gs_prevLog
.numRepeated
271 // ----------------------------------------------------------------------------
272 // wxLog logging functions
273 // ----------------------------------------------------------------------------
277 wxLog::OnLog(wxLogLevel level
, const wxString
& msg
, time_t t
)
279 wxLogRecordInfo info
;
282 info
.threadId
= wxThread::GetCurrentId();
283 #endif // wxUSE_THREADS
285 OnLog(level
, msg
, info
);
290 wxLog::OnLog(wxLogLevel level
,
292 const wxLogRecordInfo
& info
)
294 // fatal errors can't be suppressed nor handled by the custom log target
295 // and always terminate the program
296 if ( level
== wxLOG_FatalError
)
298 wxSafeShowMessage(wxS("Fatal Error"), msg
);
310 if ( !wxThread::IsMain() )
312 logger
= wxThreadInfo
.logger
;
317 // buffer the messages until they can be shown from the main
319 wxCriticalSectionLocker
lock(GetBackgroundLogCS());
321 gs_bufferedLogRecords
.push_back(wxLogRecord(level
, msg
, info
));
323 // ensure that our Flush() will be called soon
326 //else: we don't have any logger at all, there is no need to log
331 //else: we have a thread-specific logger, we can send messages to it
335 #endif // wxUSE_THREADS
337 logger
= GetMainThreadActiveTarget();
342 logger
->CallDoLogNow(level
, msg
, info
);
346 wxLog::CallDoLogNow(wxLogLevel level
,
348 const wxLogRecordInfo
& info
)
350 if ( GetRepetitionCounting() )
352 if ( msg
== gs_prevLog
.msg
)
354 gs_prevLog
.numRepeated
++;
356 // nothing else to do, in particular, don't log the
361 LogLastRepeatIfNeeded();
363 // reset repetition counter for a new message
364 gs_prevLog
.msg
= msg
;
365 gs_prevLog
.level
= level
;
366 gs_prevLog
.info
= info
;
369 // handle extra data which may be passed to us by wxLogXXX()
370 wxString prefix
, suffix
;
372 if ( info
.GetNumValue(wxLOG_KEY_SYS_ERROR_CODE
, &num
) )
374 const long err
= static_cast<long>(num
);
376 suffix
.Printf(_(" (error %ld: %s)"), err
, wxSysErrorMsg(err
));
381 if ( level
== wxLOG_Trace
&& info
.GetStrValue(wxLOG_KEY_TRACE_MASK
, &str
) )
383 prefix
= "(" + str
+ ") ";
385 #endif // wxUSE_LOG_TRACE
387 DoLogRecord(level
, prefix
+ msg
+ suffix
, info
);
390 void wxLog::DoLogRecord(wxLogLevel level
,
392 const wxLogRecordInfo
& info
)
394 #if WXWIN_COMPATIBILITY_2_8
395 // call the old DoLog() to ensure that existing custom log classes still
398 // as the user code could have defined it as either taking "const char *"
399 // (in ANSI build) or "const wxChar *" (in ANSI/Unicode), we have no choice
400 // but to call both of them
401 DoLog(level
, (const char*)msg
.mb_str(), info
.timestamp
);
402 DoLog(level
, (const wchar_t*)msg
.wc_str(), info
.timestamp
);
403 #else // !WXWIN_COMPATIBILITY_2_8
405 #endif // WXWIN_COMPATIBILITY_2_8/!WXWIN_COMPATIBILITY_2_8
408 // TODO: it would be better to extract message formatting in a separate
409 // wxLogFormatter class but for now we hard code formatting here
413 // don't time stamp debug messages under MSW as debug viewers usually
414 // already have an option to do it
416 if ( level
!= wxLOG_Debug
&& level
!= wxLOG_Trace
)
420 // TODO: use the other wxLogRecordInfo fields
425 prefix
+= _("Error: ");
429 prefix
+= _("Warning: ");
432 // don't prepend "debug/trace" prefix under MSW as it goes to the debug
433 // window anyhow and so can't be confused with something else
436 // this prefix (as well as the one below) is intentionally not
437 // translated as nobody translates debug messages anyhow
447 DoLogTextAtLevel(level
, prefix
+ msg
);
450 void wxLog::DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
)
452 // we know about debug messages (because using wxMessageOutputDebug is the
453 // right thing to do in 99% of all cases and also for compatibility) but
454 // anything else needs to be handled in the derived class
455 if ( level
== wxLOG_Debug
|| level
== wxLOG_Trace
)
457 wxMessageOutputDebug().Output(msg
+ wxS('\n'));
465 void wxLog::DoLogText(const wxString
& WXUNUSED(msg
))
467 // in 2.8-compatible build the derived class might override DoLog() or
468 // DoLogString() instead so we can't have this assert there
469 #if !WXWIN_COMPATIBILITY_2_8
470 wxFAIL_MSG( "must be overridden if it is called" );
471 #endif // WXWIN_COMPATIBILITY_2_8
474 #if WXWIN_COMPATIBILITY_2_8
476 void wxLog::DoLog(wxLogLevel
WXUNUSED(level
), const char *szString
, time_t t
)
478 DoLogString(szString
, t
);
481 void wxLog::DoLog(wxLogLevel
WXUNUSED(level
), const wchar_t *wzString
, time_t t
)
483 DoLogString(wzString
, t
);
486 #endif // WXWIN_COMPATIBILITY_2_8
488 // ----------------------------------------------------------------------------
489 // wxLog active target management
490 // ----------------------------------------------------------------------------
492 wxLog
*wxLog::GetActiveTarget()
495 if ( !wxThread::IsMain() )
497 // check if we have a thread-specific log target
498 wxLog
* const logger
= wxThreadInfo
.logger
;
500 // the code below should be only executed for the main thread as
501 // CreateLogTarget() is not meant for auto-creating log targets for
502 // worker threads so skip it in any case
503 return logger
? logger
: ms_pLogger
;
505 #endif // wxUSE_THREADS
507 return GetMainThreadActiveTarget();
511 wxLog
*wxLog::GetMainThreadActiveTarget()
513 if ( ms_bAutoCreate
&& ms_pLogger
== NULL
) {
514 // prevent infinite recursion if someone calls wxLogXXX() from
515 // wxApp::CreateLogTarget()
516 static bool s_bInGetActiveTarget
= false;
517 if ( !s_bInGetActiveTarget
) {
518 s_bInGetActiveTarget
= true;
520 // ask the application to create a log target for us
521 if ( wxTheApp
!= NULL
)
522 ms_pLogger
= wxTheApp
->GetTraits()->CreateLogTarget();
524 ms_pLogger
= new wxLogOutputBest
;
526 s_bInGetActiveTarget
= false;
528 // do nothing if it fails - what can we do?
535 wxLog
*wxLog::SetActiveTarget(wxLog
*pLogger
)
537 if ( ms_pLogger
!= NULL
) {
538 // flush the old messages before changing because otherwise they might
539 // get lost later if this target is not restored
543 wxLog
*pOldLogger
= ms_pLogger
;
544 ms_pLogger
= pLogger
;
551 wxLog
*wxLog::SetThreadActiveTarget(wxLog
*logger
)
553 wxASSERT_MSG( !wxThread::IsMain(), "use SetActiveTarget() for main thread" );
555 wxLog
* const oldLogger
= wxThreadInfo
.logger
;
559 wxThreadInfo
.logger
= logger
;
563 #endif // wxUSE_THREADS
565 void wxLog::DontCreateOnDemand()
567 ms_bAutoCreate
= false;
569 // this is usually called at the end of the program and we assume that it
570 // is *always* called at the end - so we free memory here to avoid false
571 // memory leak reports from wxWin memory tracking code
575 void wxLog::DoCreateOnDemand()
577 ms_bAutoCreate
= true;
580 // ----------------------------------------------------------------------------
581 // wxLog components levels
582 // ----------------------------------------------------------------------------
585 void wxLog::SetComponentLevel(const wxString
& component
, wxLogLevel level
)
587 if ( component
.empty() )
593 wxCRIT_SECT_LOCKER(lock
, GetLevelsCS());
595 GetComponentLevels()[component
] = level
;
600 wxLogLevel
wxLog::GetComponentLevel(wxString component
)
602 wxCRIT_SECT_LOCKER(lock
, GetLevelsCS());
604 const wxStringToNumHashMap
& componentLevels
= GetComponentLevels();
605 while ( !component
.empty() )
607 wxStringToNumHashMap::const_iterator
608 it
= componentLevels
.find(component
);
609 if ( it
!= componentLevels
.end() )
610 return static_cast<wxLogLevel
>(it
->second
);
612 component
= component
.BeforeLast('/');
615 return GetLogLevel();
618 // ----------------------------------------------------------------------------
620 // ----------------------------------------------------------------------------
625 // because IsAllowedTraceMask() may be called during static initialization
626 // (this is not recommended but it may still happen, see #11592) we can't use a
627 // simple static variable which might be not initialized itself just yet to
628 // store the trace masks, but need this accessor function which will ensure
629 // that the variable is always correctly initialized before being accessed
631 // notice that this doesn't make accessing it MT-safe, of course, you need to
632 // serialize accesses to it using GetTraceMaskCS() for this
633 wxArrayString
& TraceMasks()
635 static wxArrayString s_traceMasks
;
640 } // anonymous namespace
642 /* static */ const wxArrayString
& wxLog::GetTraceMasks()
644 // because of this function signature (it returns a reference, not the
645 // object), it is inherently MT-unsafe so there is no need to acquire the
651 void wxLog::AddTraceMask(const wxString
& str
)
653 wxCRIT_SECT_LOCKER(lock
, GetTraceMaskCS());
655 TraceMasks().push_back(str
);
658 void wxLog::RemoveTraceMask(const wxString
& str
)
660 wxCRIT_SECT_LOCKER(lock
, GetTraceMaskCS());
662 int index
= TraceMasks().Index(str
);
663 if ( index
!= wxNOT_FOUND
)
664 TraceMasks().RemoveAt((size_t)index
);
667 void wxLog::ClearTraceMasks()
669 wxCRIT_SECT_LOCKER(lock
, GetTraceMaskCS());
671 TraceMasks().Clear();
674 /*static*/ bool wxLog::IsAllowedTraceMask(const wxString
& mask
)
676 wxCRIT_SECT_LOCKER(lock
, GetTraceMaskCS());
678 const wxArrayString
& masks
= GetTraceMasks();
679 for ( wxArrayString::const_iterator it
= masks
.begin(),
691 // ----------------------------------------------------------------------------
692 // wxLog miscellaneous other methods
693 // ----------------------------------------------------------------------------
695 void wxLog::TimeStamp(wxString
*str
)
698 if ( !ms_timestamp
.empty() )
700 *str
= wxDateTime::UNow().Format(ms_timestamp
);
703 #endif // wxUSE_DATETIME
708 void wxLog::FlushThreadMessages()
710 // check if we have queued messages from other threads
711 wxLogRecords bufferedLogRecords
;
714 wxCriticalSectionLocker
lock(GetBackgroundLogCS());
715 bufferedLogRecords
.swap(gs_bufferedLogRecords
);
717 // release the lock now to not keep it while we are logging the
718 // messages below, allowing background threads to run
721 if ( !bufferedLogRecords
.empty() )
723 for ( wxLogRecords::const_iterator it
= bufferedLogRecords
.begin();
724 it
!= bufferedLogRecords
.end();
727 CallDoLogNow(it
->level
, it
->msg
, it
->info
);
733 bool wxLog::IsThreadLoggingEnabled()
735 return !wxThreadInfo
.loggingDisabled
;
739 bool wxLog::EnableThreadLogging(bool enable
)
741 const bool wasEnabled
= !wxThreadInfo
.loggingDisabled
;
742 wxThreadInfo
.loggingDisabled
= !enable
;
746 #endif // wxUSE_THREADS
750 LogLastRepeatIfNeeded();
754 void wxLog::FlushActive()
756 if ( ms_suspendCount
)
759 wxLog
* const log
= GetActiveTarget();
763 if ( wxThread::IsMain() )
764 log
->FlushThreadMessages();
765 #endif // wxUSE_THREADS
771 // ----------------------------------------------------------------------------
772 // wxLogBuffer implementation
773 // ----------------------------------------------------------------------------
775 void wxLogBuffer::Flush()
779 if ( !m_str
.empty() )
781 wxMessageOutputBest out
;
782 out
.Printf(wxS("%s"), m_str
.c_str());
787 void wxLogBuffer::DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
)
789 // don't put debug messages in the buffer, we don't want to show
790 // them to the user in a msg box, log them immediately
795 wxLog::DoLogTextAtLevel(level
, msg
);
799 m_str
<< msg
<< wxS("\n");
803 // ----------------------------------------------------------------------------
804 // wxLogStderr class implementation
805 // ----------------------------------------------------------------------------
807 wxLogStderr::wxLogStderr(FILE *fp
)
815 void wxLogStderr::DoLogText(const wxString
& msg
)
817 wxFputs(msg
+ '\n', m_fp
);
820 // under GUI systems such as Windows or Mac, programs usually don't have
821 // stderr at all, so show the messages also somewhere else, typically in
822 // the debugger window so that they go at least somewhere instead of being
824 if ( m_fp
== stderr
)
826 wxAppTraits
*traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
827 if ( traits
&& !traits
->HasStderr() )
829 wxMessageOutputDebug().Output(msg
+ wxS('\n'));
834 // ----------------------------------------------------------------------------
835 // wxLogStream implementation
836 // ----------------------------------------------------------------------------
838 #if wxUSE_STD_IOSTREAM
839 #include "wx/ioswrap.h"
840 wxLogStream::wxLogStream(wxSTD ostream
*ostr
)
843 m_ostr
= &wxSTD cerr
;
848 void wxLogStream::DoLogText(const wxString
& msg
)
850 (*m_ostr
) << msg
<< wxSTD endl
;
852 #endif // wxUSE_STD_IOSTREAM
854 // ----------------------------------------------------------------------------
856 // ----------------------------------------------------------------------------
858 wxLogChain::wxLogChain(wxLog
*logger
)
860 m_bPassMessages
= true;
863 m_logOld
= wxLog::SetActiveTarget(this);
866 wxLogChain::~wxLogChain()
868 wxLog::SetActiveTarget(m_logOld
);
870 if ( m_logNew
!= this )
874 void wxLogChain::SetLog(wxLog
*logger
)
876 if ( m_logNew
!= this )
882 void wxLogChain::Flush()
887 // be careful to avoid infinite recursion
888 if ( m_logNew
&& m_logNew
!= this )
892 void wxLogChain::DoLogRecord(wxLogLevel level
,
894 const wxLogRecordInfo
& info
)
896 // let the previous logger show it
897 if ( m_logOld
&& IsPassingMessages() )
898 m_logOld
->LogRecord(level
, msg
, info
);
900 // and also send it to the new one
903 // don't call m_logNew->LogRecord() to avoid infinite recursion when
904 // m_logNew is this object itself
905 if ( m_logNew
!= this )
906 m_logNew
->LogRecord(level
, msg
, info
);
908 wxLog::DoLogRecord(level
, msg
, info
);
913 // "'this' : used in base member initializer list" - so what?
914 #pragma warning(disable:4355)
917 // ----------------------------------------------------------------------------
919 // ----------------------------------------------------------------------------
921 wxLogInterposer::wxLogInterposer()
926 // ----------------------------------------------------------------------------
927 // wxLogInterposerTemp
928 // ----------------------------------------------------------------------------
930 wxLogInterposerTemp::wxLogInterposerTemp()
937 #pragma warning(default:4355)
940 // ============================================================================
941 // Global functions/variables
942 // ============================================================================
944 // ----------------------------------------------------------------------------
946 // ----------------------------------------------------------------------------
948 bool wxLog::ms_bRepetCounting
= false;
950 wxLog
*wxLog::ms_pLogger
= NULL
;
951 bool wxLog::ms_doLog
= true;
952 bool wxLog::ms_bAutoCreate
= true;
953 bool wxLog::ms_bVerbose
= false;
955 wxLogLevel
wxLog::ms_logLevel
= wxLOG_Max
; // log everything by default
957 size_t wxLog::ms_suspendCount
= 0;
959 wxString
wxLog::ms_timestamp(wxS("%X")); // time only, no date
961 #if WXWIN_COMPATIBILITY_2_8
962 wxTraceMask
wxLog::ms_ulTraceMask
= (wxTraceMask
)0;
963 #endif // wxDEBUG_LEVEL
965 // ----------------------------------------------------------------------------
966 // stdout error logging helper
967 // ----------------------------------------------------------------------------
969 // helper function: wraps the message and justifies it under given position
970 // (looks more pretty on the terminal). Also adds newline at the end.
972 // TODO this is now disabled until I find a portable way of determining the
973 // terminal window size (ok, I found it but does anybody really cares?)
974 #ifdef LOG_PRETTY_WRAP
975 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
)
977 size_t nMax
= 80; // FIXME
978 size_t nStart
= strlen(pszPrefix
);
982 while ( *psz
!= '\0' ) {
983 for ( n
= nStart
; (n
< nMax
) && (*psz
!= '\0'); n
++ )
987 if ( *psz
!= '\0' ) {
989 for ( n
= 0; n
< nStart
; n
++ )
992 // as we wrapped, squeeze all white space
993 while ( isspace(*psz
) )
1000 #endif //LOG_PRETTY_WRAP
1002 // ----------------------------------------------------------------------------
1003 // error code/error message retrieval functions
1004 // ----------------------------------------------------------------------------
1006 // get error code from syste
1007 unsigned long wxSysErrorCode()
1009 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
1010 return ::GetLastError();
1016 // get error message from system
1017 const wxChar
*wxSysErrorMsg(unsigned long nErrCode
)
1019 if ( nErrCode
== 0 )
1020 nErrCode
= wxSysErrorCode();
1022 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
1023 static wxChar s_szBuf
[1024];
1025 // get error message from system
1027 if ( ::FormatMessage
1029 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
1032 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
1038 // if this happens, something is seriously wrong, so don't use _() here
1040 wxSprintf(s_szBuf
, wxS("unknown error %lx"), nErrCode
);
1045 // copy it to our buffer and free memory
1046 // Crashes on SmartPhone (FIXME)
1047 #if !defined(__SMARTPHONE__) /* of WinCE */
1050 wxStrlcpy(s_szBuf
, (const wxChar
*)lpMsgBuf
, WXSIZEOF(s_szBuf
));
1052 LocalFree(lpMsgBuf
);
1054 // returned string is capitalized and ended with '\r\n' - bad
1055 s_szBuf
[0] = (wxChar
)wxTolower(s_szBuf
[0]);
1056 size_t len
= wxStrlen(s_szBuf
);
1059 if ( s_szBuf
[len
- 2] == wxS('\r') )
1060 s_szBuf
[len
- 2] = wxS('\0');
1064 #endif // !__SMARTPHONE__
1066 s_szBuf
[0] = wxS('\0');
1072 static wchar_t s_wzBuf
[1024];
1073 wxConvCurrent
->MB2WC(s_wzBuf
, strerror((int)nErrCode
),
1074 WXSIZEOF(s_wzBuf
) - 1);
1077 return strerror((int)nErrCode
);
1079 #endif // __WXMSW__/!__WXMSW__