由于VS中字符编码分为Unicode字符集和多字节字符集,所以字符串转char*的情况分为两种,要分别对待。
int CStrToUChar(unsigned char * pChar, CString &pCString)
{
#if CHARACTER_CODEDING_UNICODE
//Unicode 字符集
int len;
len = WideCharToMultiByte(CP_ACP,0,pCString,-1,NULL,0,NULL,NULL);
len = WideCharToMultiByte(CP_ACP,0,pCString,-1,(LPSTR)pChar,len,NULL,NULL );
return (len-1);
#else
//多字节 字符集
memcpy(pChar, pCString.GetBuffer(), pCString.GetLength());
return pCString.GetLength();
#endif
}