CString to TCHAR
CString is a very useful MFC class for string management. But, sometimes we want to convert CString data to TCHAR or something.
here is one small code snippet for performing this operation.
CString csData(_T(“”));
LPTSTR szData = csData.GetBuffer();
csData.ReleaseBuffer();
LPTSTR szData = csData.GetBuffer();
csData.ReleaseBuffer();
or like this
CString csTemp( "Sample data" ); LPTSTR lpszData = new TCHAR[csTemp.GetLength()+1]; _tcscpy(lpszData , csTemp); delete[] lpszData;// don't forget to do this.
Categories: Visual C++
Thanks, just a quick thing I was looking for!
Don’t forget to clean up however!
lpszData variablename is not correct in last line
Oh.. sorry urlich von jungingen..I updated it.
Thanks for correcting me..Its my mistake