CString转换为const char * 或者CString转换为char*

char* WideChartoAnsi(wchar_t * pWideChar)
{
if (NULL == pWideChar)
return NULL;
char* pAnsi = NULL;
int needBytes = WideCharToMultiByte(CP_ACP, 0, pWideChar, -1, NULL, 0, NULL, NULL);
if (needBytes > 0)
{
pAnsi = new char[needBytes + 1];
ZeroMemory(pAnsi, needBytes + 1);
WideCharToMultiByte(CP_ACP, 0, pWideChar, -1, pAnsi, needBytes, NULL, NULL);
}
return pAnsi;

}

得到的就是char * 或者const char*

你可能感兴趣的:(CString转换为const char * 或者CString转换为char*)