Const char * to LPTSTR
3 answers
LPTSTR is a non-const pointer to TCHAR. TCHAR, in turn, is defined as char in ANSI assemblies, and wchar_t in Unicode strings (with UNICODE and / or _UNICODE characters defined).
So LPTSTR is equivalent to:
TCHAR foo[] = _T("bar");
Just like non-const, you cannot safely call it a literal - literals can be allocated to read-only memory segments, and LPTSTR is a signal that the caller can change the contents of the string, for example
void truncate(LPTSTR s)
{
if (_tcslen(s) > 4)
s[3] = _T('\0');
}
It would work if you passed in a literal when compiled with Visual C ++ 2008.
+1
source to share