|
int nLen = 0; int nMemLen = 0;
CString str(_T("C:\\中文字符测试\\jpg")); nLen = str.GetLength(); //字符串转换 CString 转为 char* const UINT wLen = str.GetLength() + 1; UINT aLen = WideCharToMultiByte(CP_ACP,0,str,wLen,NULL,0,NULL,NULL); //alen为20,包含了最后的 \0 char* pChar = new char[aLen]; WideCharToMultiByte(CP_ACP,0,str,wLen,pChar,aLen,NULL,NULL); nLen = strlen(pChar); //nLen 为 19 strlen不包含 \0 nMemLen = sizeof(char)*nLen;
//将lpa使用memcpy拷贝到新申请的char中去 char* pCharDest = new char[nLen+1]; memcpy(pCharDest,pChar,nLen); pCharDest[nLen]='\0';//最后要加上一个\0 nLen = strlen(pCharDest);
//将CString 拷贝到wchar数组中 TCHAR* pWChar = str.GetBuffer(); nLen = _tcslen(pWChar); //这个长度和str的长度是一样的,都是13
TCHAR* pWCharDest = new TCHAR[nLen+1]; wmemcpy(pWCharDest,pWChar,nLen); pWCharDest[nLen]=_T('\0'); nLen = _tcslen(pWCharDest); nMemLen = sizeof(TCHAR)*nLen;
|