使用A2W,A2T这些宏函数是常见的方法,但是中文会乱码,所以采用MultiByteToWideChar进行转换

 

//计算char *数组大小,以字节为单位,一个汉字占两个字节
    int charLen = strlen(sText);
    //计算多字节字符的大小,按字符计算。
    int len = MultiByteToWideChar(CP_ACP,0,sText,charLen,NULL,0);
    //为宽字节字符数组申请空间,数组大小为按字节计算的多字节字符大小
    TCHAR *buf = new TCHAR[len + 1];
    //多字节编码转换成宽字节编码
    MultiByteToWideChar(CP_ACP,0,sText,charLen,buf,len);
    buf[len] = '\0'; //添加字符串结尾,注意不是len+1
    //将TCHAR数组转换为CString
    CString pWideChar;
    pWideChar.Append(buf);
    //删除缓冲区
    delete []buf;

相关文章:

  • 2022-02-16
  • 2022-12-23
  • 2021-06-07
  • 2021-07-06
  • 2022-12-23
  • 2021-07-30
  • 2021-09-19
猜你喜欢
  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2021-06-06
相关资源
相似解决方案