vc6到 vs2008 char* 与 CString 之间 字符串转换函数 .
从vc6到 vs2008 字符串转换是表麻烦,于是参考相关资料,写了两个函数。
char*与CString的转换
char*与CString的转换
CString MCharToCString(char* szChar)
{
CString strValue;
int nLen=0;
nLen= MultiByteToWideChar(CP_ACP, 0, szChar, -1, NULL, 0);
WCHAR wBuf[1024];
MultiByteToWideChar(CP_ACP, 0, szChar, -1, wBuf, nLen);
strValue.Format(_T("%s"),wBuf);
return strValue;
}
CString与char*的转换 char* CStringToMChar(CString str)
{
char szChar[1024];
int nlen=0;
memset(szChar,0x00,1024);
nlen=WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, str, -1, szChar, nlen, NULL, NULL);
return szChar;
}
{
CString strValue;
int nLen=0;
nLen= MultiByteToWideChar(CP_ACP, 0, szChar, -1, NULL, 0);
WCHAR wBuf[1024];
MultiByteToWideChar(CP_ACP, 0, szChar, -1, wBuf, nLen);
strValue.Format(_T("%s"),wBuf);
return strValue;
}
CString与char*的转换 char* CStringToMChar(CString str)
{
char szChar[1024];
int nlen=0;
memset(szChar,0x00,1024);
nlen=WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, str, -1, szChar, nlen, NULL, NULL);
return szChar;
}