As already said you need a conversion instead of a casting. The
CString
class can do that for you:
CString strData1 = L"ABCDE";
CStringA strData1A = strData1;
LPCSTR spData = strData1A.GetString();
MessageBox(NULL, strData1.GetString(), L"CString strData", MB_OK);
MessageBox(NULL, CString(spData).GetString(), L"LPCSTR spData", MB_OK);
You should also avoid using C style castings. Use the C++ casting operators instead (see
Type conversions - C++ Tutorials[
^] and
Casting Operators[
^]).