之前在这里发过关于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

解决方案 »

  1.   

    这个没问题啊,其实相当于同时定义了两个指针的<<操作符:
        // 把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
      

  2.   

    嗯,LS正解,看了src,的确如此~