char* CPage2::GetAnsiString(const CString &unicodeString)
{
int iLen = unicodeString.GetLength() + 1;
char *pAnsi = new char[iLen];
memset(pAnsi, 0, iLen);
WideCharToMultiByte(CP_ACP,0,unicodeString,-1,pAnsi,iLen,NULL,NULL); return pAnsi;
}CStringA CPage2::GetAnsiStringA(const CString &unicodeString)
{
USES_CONVERSION;
return (W2A(unicodeString));
}第一个报错:
page2.cpp(613): error C2440: “=” : 无法从“const CString”转换为“LPCWSTR”   (最好不要强转,也不要改参数)
第二个报错:
page2.cpp(605): error C2664: “WideCharToMultiByte” : 不能将参数 3 从“const CString”转换为“LPCWSTR”  (也一样不要强换和换参数)

解决方案 »

  1.   

    CString.GetString()
    注意定义为CStringW
    另外你这样写尤其是第一种肯定不对。内存泄露。又不是托管编程,new 了又不delete用不了多久你就会死得很难看。
    这种写法有点像VB这种高级语言的写法。建议搂主还是要尽快转换思维模式哦。
      

  2.   

    而且把它DELETE了那怎么返回啊.....
    我也想DELETE
      

  3.   

    给你个代码做参考
    int CPage2::GetAnsiString(CString strSrc, BYTE *pDest/*Out*/)
    {
    int nSrcLen = strSrc.GetLength();
    int   index=0;
    char *pszSrc = NULL;
    pszSrc = new char[nSrcLen+2];
    ZeroMemory(pszSrc, nSrcLen+2);
    memcpy(pszSrc, strSrc, nSrcLen);

    int nDstLength;
    WCHAR wchar[1024] = {0};
    ZeroMemory(wchar,sizeof(wchar)); nDstLength = MultiByteToWideChar(CP_ACP, 0, pszSrc, -1,wchar, 0);
    MultiByteToWideChar(CP_ACP,0,pszSrc,-1,wchar,nDstLength);

    nDstLength = nDstLength*sizeof(WCHAR);
    memcpy(pDest, wchar, nDstLength);    delete pszSrc;
    pszSrc = NULL;
    return nDstLength;
    }
      

  4.   

    谢谢, 但是你怎么用的是MultiByteToWideChar