doublemax wrote:
So when you trace into the wxLog functions, the one that is actually used in your case is the one taking wxChar * as argument (so it was wrong what i said before about changing to char *).
Even so it was a good advise for the MyLog class function, because it allows me to call it without the L prefix. I did use wxChar* in my initial version with quite unsatisfactory results. Thanks for the hint with the wxArgNormaizer class which I did not see. Maybe I am doing things not right, but I find it quite a nightmare to debug though code that makes such heavy use of macros. Maybe the code looks quite clear, but the dynamics of it...
I would recommend to forget about chaining into the vararg list and use the "proper" wx way: Create your own log target by deriving from wxLog.
Makes sense. In that particular case it would bring just too much change in the application, however.
So here is what I have now and what is working for me:
Header
Code: Select all
class DLL_IMP_EXP CMyLog
{
public:
CMyLog();
virtual ~CMyLog();
void wxLogDebugTs(const char* pszFormat, ...); // variable args as printf()
private:
void SendLogDebug(wxString strLogText); // sends a ID_LOG_MSG message
wxWindow* m_pMsgTarget;
};
Implementation
Code: Select all
void CMyLog::wxLogDebugTs(const char* szFormat, ...)
{
wxString strOutput;
va_list argptr;
va_start(argptr, szFormat);
strOutput = wxString::FormatV(szFormat, argptr);
SendLogDebug(strOutput);
va_end(argptr);
}
Only drawback beside the plattform dependency is the need to call it with wc_str() like below. That means I must change all string arguments when I migrate code.
Code: Select all
wxLogDebugTs( "Test is %s", strTest.wc_str() );
Although its working now and my problem is solved, I am still left with the (more academic) question that I could not fully mimic the build-in wxLogDebug behaviour which would be either plattform independent and get rid of the wx_str() postfix.
So I'd still be interested in case anyone could post a modified version of my above function which exactly accepts the wxLogDebug's arguments.
Thanks
Tiger