I have a class which expects a LPCTSTR.
When i call : new CFileImageLoader(_T("Splash02.png")) OR new CFileImageLoader("Splash02.png")
both don't work. Why ? I'm new to cpp... Thanks Jonathan d.
I have a class which expects a LPCTSTR.
When i call : new CFileImageLoader(_T("Splash02.png")) OR new CFileImageLoader("Splash02.png")
both don't work. Why ? I'm new to cpp... Thanks Jonathan d.
"both don't work" - could you maybe be a tiny, tiny little bit more specific?
If you compile with _UNICODE defined, then the second shouldn't even compile.
You're also just passing a filename, not a full path. Maybe your image loader class can't find the file because it uses a differen CWD path as you expect. Try passing the full path instead.
This issue is a combination of C++ issues and Windows specific issues.
C++ defines two types of strings, regular and wide. A regular string looks like:
const char *str = "regular string";
while a wide string looks like:
const wchar_t *wstr = L"wide string";
With just standard C++, you have to decide when you write your library whether to use regular or wide strings.
Windows has defined a pseudo type called tchar. With tchar you write something like:
LPCTSTR tstr = _T("regular or wide string");
Whether this is actually a regular (char *) or a wide (wchar_t *) string depends on whether you compile your code for Unicode or not.
Since the function is specified as taking an LPCTSTR, it needs to be called with the appropriate type for how you are compiling.
If you know you are only going to be building with or without Unicode support, you can skip all the TCHAR stuff and directly use either wchar_t or char respectively.
Since CFileImageLoader("Splash02.png")
is not working, you must be compiling with Unicode support enabled. You can change that to CFileImageLoader(L"Splash02.png")
and commit to always using Unicode or you can change it to CFileImageLoader(_T("Splash02.png"))
and let the macro magic do the work.