Hi, I'm looking for a function that will convert CString to char*, I found the function
char* ConvertToChar(const CString &s)
{
int nSize = s.GetLength();
char *pAnsiString = new char[nSize+1];
memset(pAnsiString,0,nSize+1);
wcstombs(pAnsiString, s, nSize+1);
return pAnsiString;
}
The problem is you cann see that there is the use of new operator in the line:
char *pAnsiString = new char[nSize+1];
This can cause memory leak in the future, also in C++ after using new we must use delete, the problem is if I use delete in the function the function returns NULL.
Ideas?
Thanks