Your early versions of the question checked the return value of LoadImage
but then did nothing more. The documentation says this:
If the function fails, the return value is
NULL
. To get extended error information, callGetLastError
.
So, if the function fails, call GetLastError
to find out why. When you do so, you obtain the error code ERROR_FILE_NOT_FOUND
. Which is pretty conclusive. The filename that you specified does not exist.
Do note that the code in the latest update to the question calls GetLastError
unconditionally. That is a mistake, one that is seen all too frequently here on Stack Overflow. The documentation only tells you to call GetLastError
when the call to LoadImage
fails. If the call to LoadImage
succeeds, then the value return by GetLastError
is meaningless. Error handling in Win32 is largely handled in the same way as LoadImage
does it, but not always. So you have to read the documentation very carefully.
Perhaps instead of
C:\\Users\\Tim\documents\\...
you meant
C:\\Users\\Tim\\documents\\...
OK, now you've got the path right. The call to LoadImage
returns NULL
, but GetLastError
is no longer helpful and returns ERROR_SUCCESS
. Which is weird in itself.
I believe that the problem is that your image uses a format that LoadImage
does not understand. I took your .bmp file, loaded it in Paint.net and then re-saved it. Once I did that, the re-saved image was loaded successfully.
Rather than trying to load this from a file it would make far more sense to link the image as a resource and load it that way.