CFileImageLoader (LPCTSTR lpszFileName);

I have a class that expects LPCTSTR.

When I call: new CFileImageLoader (_T ("Splash02.png")) OR new CFileImageLoader ("Splash02.png")

both don't work. What for? I'm new to cpp ... thanks to Jonathan D.

0


source to share


3 answers


This issue is a combination of C ++ issues and Windows related issues.

C ++ defines two types of strings: regular and wide. The correct line looks like this:

const char *str = "regular string";

      

while the wide line looks like this:

const wchar_t *wstr = L"wide string";

      

With 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 it is actually a regular (char *) or wide (wchar_t *) string depends on whether you are compiling the code for Unicode or not.

Since the function is listed as accepting LPCTSTR, it must be called with the appropriate type for how you compile.

If you know you are only going to build with or without Unicode support, you can skip all the TCHAR stuff and use either wchar_t or char directly, respectively.

Since it CFileImageLoader("Splash02.png")

doesn't work, you have to compile it with Unicode support. You can change this to CFileImageLoader(L"Splash02.png")

and commit always with Unicode, or you can change it to CFileImageLoader(_T("Splash02.png"))

and let the macro magic do the job.

+1


source


"both don't work" - could you be tiny, tiny a little more specific?

If you are compiling with _UNICODE, then the second one should not compile.



You are also just passing in the filename, not the full path. Perhaps your image loader class cannot find the file because it is using a different CWD path as you would expect. Try to pass the full path.

0


source


  • Your image library may not be able to support PNG format file.
  • Try to pass the full path.
  • Perhaps you need to call some of the initialization functions that your image library provides.
0


source







All Articles