1、CString转char*
<pre name="code" class="cpp">char* CCommonCheckMethod::CStringToChar(CString csBuffer)
{
int iLen = 0;
char *pBuf = NULL;
/** Convert wide char into char */
iLen = WideCharToMultiByte(CP_ACP, NULL, csBuffer, -1, NULL, 0, NULL, FALSE);
/** Create char pointer space */
pBuf = new char[iLen];
if ( pBuf != NULL )
{
WideCharToMultiByte(CP_ACP, NULL, csBuffer, -1, pBuf, iLen, NULL, FALSE);
}
return pBuf;
}
2、char*转CString
CString CCommonCheckMethod::CharToCString(char* pBuf)
{
int iLength = MultiByteToWideChar(CP_ACP, 0, pBuf, -1, NULL, 0);
TCHAR *pBuffer = new TCHAR[iLength];
if ( pBuffer != NULL )
{
MultiByteToWideChar(CP_ACP, 0, pBuf, -1, pBuffer, iLength);
}
return pBuffer;
}
在wince平台出现了WideCharToMultiByte失败,需要转换的为汉字,但是区域和语言为日语,切换到中文就OK了。