I write function and it can exchange a CString to const char *.if you meet a trouble and want exchange CString to int.only use atoi,VC will warn that wchar * can't exchange to const char *.
function
int CStringToInt(const CString &/* str*/)
{
char *ch=0;
size_t convertedChars = 0;
size_t sizeInBytes = ((str.GetLength() + 1) * 2);
ch=(char *)malloc(sizeInBytes);
errno_t err = 0;
err = wcstombs_s(&convertedChars,
ch, sizeInBytes,
strHostTemp.GetBuffer(), sizeInBytes);
int ip=atoi(ch);
ASSERT(ch);
free(ch);
return ip;
}
function
int CStringToInt(const CString &/* str*/)
{
char *ch=0;
size_t convertedChars = 0;
size_t sizeInBytes = ((str.GetLength() + 1) * 2);
ch=(char *)malloc(sizeInBytes);
errno_t err = 0;
err = wcstombs_s(&convertedChars,
ch, sizeInBytes,
strHostTemp.GetBuffer(), sizeInBytes);
int ip=atoi(ch);
ASSERT(ch);
free(ch);
return ip;
}