CString str = _T("str");
LPCSTR lpcstr;
lpcstr ?需要打开UNICODE支持!
试过用str.GetBuffer()和(LPCTSTR)str都不行!

解决方案 »

  1.   

    LPCSTR 是const char*
    LPCTSTR 是const wchar_t *
    不能直接转换的,用WideCharToMultiByte吧。或者用ATL的W2T之类的宏
      

  2.   

    需要用int WideCharToMultiByte(
      UINT CodePage,            // code page
      DWORD dwFlags,            // performance and mapping flags
      LPCWSTR lpWideCharStr,    // wide-character string
      int cchWideChar,          // number of chars in string
      LPSTR lpMultiByteStr,     // buffer for new string
      int cbMultiByte,          // size of buffer
      LPCSTR lpDefaultChar,     // default for unmappable chars
      LPBOOL lpUsedDefaultChar  // set when default char used
    );
    这个函数转换
      

  3.   

    http://www.newebug.com/article/cpp/2357.shtml
    CString 操作指南
      

  4.   

    我的代码是这样的:
    CString m_strName = _T("TEST");
    int mlen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strName, nTextLen + 1, NULL, 0); 错误 3 error C2664: 'MultiByteToWideChar' : cannot convert parameter 3 from 'CString' to 'LPCSTR'
      

  5.   

    我的代码是这样的:
    CString m_strName = _T("TEST");
    int nTextLen = _tcslen(m_strName);
    int mlen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strName, nTextLen + 1, NULL, 0); 错误 3 error C2664: 'MultiByteToWideChar' : cannot convert parameter 3 from 'CString' to 'LPCSTR'
      

  6.   

    m_strName 本来就是宽字节的,为什么还要用MultiByteToWideChar?
      

  7.   

    晕的用WideCharToMultiByte,不是用MultiByteToWideChar
      

  8.   

    我明白你们的意思,这个程序是我从CodeProject上下载下来的,原来的代码是在VC6.0下面编译的,我把它换到VS2005上来,不打开UNICODE支持我已经可以正常运行,但是我想把它改为支持UNICODE,作者原来完整的代码是这样的:int nTextLen = _tcslen(m_strName);
    int mlen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strName, nTextLen + 1, NULL, 0); 
    WCHAR* output = new WCHAR[mlen];
    if(output)
    {
      MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strName, nTextLen + 1, output, mlen);
      g_xpStyle.DrawThemeText(hTheme, pDC->m_hDC, EBP_NORMALGROUPHEAD, 0, output, -1, DT_LEFT|DT_VCENTER | DT_SINGLELINE|DT_END_ELLIPSIS, 0, &rcHeaderTextArea);
      delete output;
    }打开UNICODE支持时,编译出错,意思是MultiByteToWideChar函数的第三个参数m_strName不能从CString转换为LPCSTR。
      

  9.   

    改成这样
    #ifndef UNICODE
    int nTextLen = _tcslen(m_strName);
    int mlen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strName, nTextLen + 1, NULL, 0); 
    WCHAR* output = new WCHAR[mlen];
    if(output)
    {
      MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strName, nTextLen + 1, output, mlen);
      g_xpStyle.DrawThemeText(hTheme, pDC->m_hDC, EBP_NORMALGROUPHEAD, 0, output, -1, DT_LEFT|DT_VCENTER | DT_SINGLELINE|DT_END_ELLIPSIS, 0, &rcHeaderTextArea);
      delete output;
    }
    #else
    g_xpStyle.DrawThemeText(hTheme, pDC->m_hDC, EBP_NORMALGROUPHEAD, 0, m_strName, -1, DT_LEFT|DT_VCENTER | DT_SINGLELINE|DT_END_ELLIPSIS, 0, &rcHeaderTextArea);
    #endif