//使用过后必须释放
char* ConvertToLPCSTR(CString swString)
{
#ifdef _UNICODE
char* szBuf = NULL;
UINT nLen = NULL;
nLen = WideCharToMultiByte(CP_ACP, 0, swString/*wszString*/, -1, NULL, 0, NULL, NULL);
szBuf = (char*)malloc(nLen + 1);
int nRet = WideCharToMultiByte(CP_ACP, 0, swString, -1, szBuf, nLen, NULL, NULL);
if (0 == nRet)
{
free(szBuf);
szBuf = NULL;
}
return szBuf;
#else
char* szBuf = NULL;
int nLen=swString.GetLength()+1;
szBuf = (char*)malloc(nLen + 1);
strcpy(szBuf,swString);
return szBuf;
#endif
}
注意:使用过后必须使用free释放


杭州格原