之前在这里发过关于TRACE宏输出不全的问题,无人解决,后来自己试验发现,在UNICODE编码下,TRACE无法输出中文。
于是为了知道原因,去翻MFC的源代码,今天在翻到CDumpContext的定义源代码时,看到下面一段很郁闷的代码(位于AFX.H):
// Operations
CDumpContext& operator<<(LPCTSTR lpsz);
#ifdef _UNICODE
CDumpContext& operator<<(LPCSTR lpsz); // automatically widened
#else
CDumpContext& operator<<(LPCWSTR lpsz); // automatically thinned
#endif 如上面所示,不知道为什么MFC要这么做,也不清楚是否是这个导致了在UNICODE模式下无法输出中文。
希望高手解答!
thx
于是为了知道原因,去翻MFC的源代码,今天在翻到CDumpContext的定义源代码时,看到下面一段很郁闷的代码(位于AFX.H):
// Operations
CDumpContext& operator<<(LPCTSTR lpsz);
#ifdef _UNICODE
CDumpContext& operator<<(LPCSTR lpsz); // automatically widened
#else
CDumpContext& operator<<(LPCWSTR lpsz); // automatically thinned
#endif 如上面所示,不知道为什么MFC要这么做,也不清楚是否是这个导致了在UNICODE模式下无法输出中文。
希望高手解答!
thx
// 把CDumpContext& operator<<(LPCTSTR lpsz);里面的T按照#ifdef _UNICODE展开看
#ifdef _UNICODE
CDumpContext& operator<<(LPCWSTR lpsz); // LPCTSTR -> LPCWSTR
CDumpContext& operator<<(LPCSTR lpsz); // automatically widened
#else
CDumpContext& operator<<(LPCSTR lpsz); // LPCTSTR -> LPCSTR
CDumpContext& operator<<(LPCWSTR lpsz); // automatically thinned
#endif