CStringW 和CStringA互转

来源:互联网 发布:三生三世知乎 编辑:程序博客网 时间:2024/06/05 21:51
CStringA CUserPacketToolDlg::CStrW2CStrA(const CStringW &cstrSrcW)  {  int len = WideCharToMultiByte(CP_ACP, 0, LPCTSTR(cstrSrcW), -1, NULL, 0, NULL, NULL);  char *str = new char[len];  memset(str, 0, len * sizeof(char));  WideCharToMultiByte(CP_ACP, 0, LPCWSTR(cstrSrcW), -1, str, len, NULL, NULL);  CStringA cstrDestA = str;  delete str;  return cstrDestA;  }  CStringW CUserPacketToolDlg::CStrA2CStrW(const CStringA &cstrSrcA)  {  int len = MultiByteToWideChar(CP_ACP, 0, LPCSTR(cstrSrcA), -1, NULL, 0);  wchar_t *wstr = new wchar_t[len];  memset(wstr, 0, len * sizeof(wchar_t));  MultiByteToWideChar(CP_ACP, 0, LPCSTR(cstrSrcA), -1, wstr, len);  CStringW cstrDestW = wstr;  delete wstr;  return cstrDestW;  }  

0 0
原创粉丝点击