As the title suggests, I am trying to load an image using DevIL, before passing it to OpenGL. I am using this piece of code as error control
const char* filename = "back.bmp";
if (!ilLoadImage(filename))
{
throw runtime_error(std::string("Unable to load image") +filename);
}
which, for the if statement, returns the error
error C2664: 'ilLoadImage' : cannot convert parameter 1 from 'const char *' to 'const wchar_t *'
If I define filename
as const wchar_t* filename
, I get the error
error C2664: 'ilLoadImage' : cannot convert parameter 1 from 'const char *' to 'const wchar_t *'
So for now I will not tire you with my curiosity of why a [filename].bmp file is of type wchar_t*, or what wchar_t is, which Google confused me over, and I will only ask what I must to make it work: Why is it not working? What have I missed? There must be a very short solution for this, I am sure. It just looks like that kind of error.
Thank you.
If you use Unicode functions, you have to use Unicode text. Specifically, L
will return the wide char representation of static text:
ilLoadImage(L"back.bmp");
If you're compiling code for both ANSI and wide strings, use _T()
instead, which returns the correct type of string:
ilLoadImage(_T("back.bmp"));
If you're in the latter case and don't know what types of char
s you'll need at compile time, use TCHAR
, which is either a CHAR
or a WCHAR
depending on whether UNICODE
is defined.