I'm converting programs written on Visual C++.NET 2003 to Visual C++ 2005. While building them with Visual Studio 2005, I got hundreds of errors like: "cannot convert parameter 1 from 'LPCTSTR' to 'const char *'" or "cannot convert parameter 1 from 'const char *' to 'LPCTSTR'". I wrote a simple application to duplicate it (see below):
#include "stdafx.h"
#include "windows.h"
int Work(LPCTSTR s)
{
return strlen(s);
}
int _tmain(int argc, _TCHAR* argv[])
{
const char s[] = "ABCDE";
const char *p = s;
Work(p);
return 0;
}
Does anyone know how to solve it I don't want to add explicit
conversion because there are too many places in too many files.
Thanks in advance!

LPCTSTR in VC++ 2005
Gerardicus
One slight ammendment to this. In the function work you also can't use strlen just in case UNICODE is defined. With all the tchar mappings there is also mappings for the general string functions too, ie strlen/wcslen -> _tcslen. So in this case you would need to use _tcslen in Work as follows.
int Work(LPCTSTR s)
{
return _tcslen(s);
}
Keith Swem
LPCTSTR is a const char* string if UNICODE is not defined. And it is a const wchar_t * if UNICODE is defined.
You project defines UNICODE, so a char[] can not match a wchar_t[]!
Your program works if you use the full TCHAR way! This will work UNICODE defined and without UNICODE defined!
#include "stdafx.h"
#include "windows.h"
int Work(LPCTSTR s)
{
return _tcslen(s);
}
int _tmain(int argc, _TCHAR* argv[])
{
const TCHAR s[] = _T("ABCDE");
const TCHAR *p = s; // or LPCTSTR *p = s;
Work(p);
return 0;
}
Peter Fitzgibbons