C++字符串中UTF和GBK编码的相互转换
CString UTFtoGBK(unsigned char* chSMS)
{ int len=MultiByteToWideChar(CP_UTF8,0,(LPCCH)chSMS,-1,NULL,0);wchar_t* wstr=new wchar_t[len+1];memset(wstr,0,len+1);
MultiByteToWideChar(CP_UTF8,0,(LPCCH)chSMS,-1,wstr,len);
len=WideCharToMultiByte(CP_ACP, 0,wstr,-1,NULL,0,NULL,NULL);char* str=new char[len+1];memset(str,0,len+1);
WideCharToMultiByte(CP_ACP, 0,wstr,-1,str,len,NULL,NULL);
if (wstr) delete[] wstr;CString hzs(str); return hzs;}
CString GBKtoUTF(unsigned char* chSMS)
{ int len=MultiByteToWideChar(CP_ACP, 0,(LPCCH)chSMS,-1,NULL,0);wchar_t* wstr=new wchar_t[len+1];memset(wstr,0,len+1);
MultiByteToWideChar(CP_ACP, 0,(LPCCH)chSMS,-1,wstr,len);
len=WideCharToMultiByte(CP_UTF8,0,wstr,-1,NULL,0,NULL,NULL);char* str=new char[len+1];memset(str,0,len+1);
WideCharToMultiByte(CP_UTF8,0,wstr,-1,str,len,NULL,NULL);
if (wstr) delete[] wstr;CString hzs(str); return hzs;}