3

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.

OddCore
  • 1,534
  • 6
  • 19
  • 32

2 Answers2

5

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 chars you'll need at compile time, use TCHAR, which is either a CHAR or a WCHAR depending on whether UNICODE is defined.

Blindy
  • 65,249
  • 10
  • 91
  • 131
1

If you're using Visual Studio, try changing the project to use Multi byte charset.

Kien Truong
  • 11,179
  • 2
  • 30
  • 36
  • That got rid of the error, but now I am getting loads of linker errors that might or might not have something to do with my messing about with the project. Unless I have missed something, all my dependencies are ok, and my files where they should be....makes no sense... – OddCore Apr 21 '11 at 09:16
  • 1
    Then you should open another question, with detail errors. DevIL has 2 set of library, one is unicode compatible and one is not. Make sure you use the right one. If you set your project to Multi byte, then use the unicode NOT compatible one – Kien Truong Apr 21 '11 at 10:09