Delta_Fore
Delta_Fore

Reputation: 3261

ImageList_LoadImage doesn't find bitmap

Trying to load a bitmap using ImageList_LoadImage but fails with ErrorCode 1814 - Could not find resource However these lines preceeding it work

HRSRC myResource = FindResource(NULL, MAKEINTRESOURCE(IDB_BITMAP1), RT_BITMAP);
auto imageResDataHandle = LoadResource(NULL, myResource);
TRACE("Error %d", GetLastError()); // All OK

auto hImageList = ::ImageList_LoadImage(NULL, MAKEINTRESOURCE(IDB_BITMAP1), 16, 2, CLR_DEFAULT, IMAGE_BITMAP, 0); 
TRACE("Error %d", GetLastError()); // Fail, error code 1814

The file is a 32x16 bmp file saved as "bitmap1.bmp" as a resource created within VS.

As it finds the resource in the first line, I think it's compiled into the binary fine.

Upvotes: 0

Views: 360

Answers (1)

user7881131
user7881131

Reputation:

I assume that with this call

auto hImageList = ::ImageList_LoadImage(NULL, MAKEINTRESOURCE(IDB_BITMAP1), 16, 2, CLR_DEFAULT, IMAGE_BITMAP, 0);

You're assuming that the NULL value for the HINSTANCE will make the function search through the current module. This is not so for this function, according to the documentation.

To get the HINSTANCE of the current module, you can call GetModuleHandle(NULL). Replace the NULL in your code with that call and it should work.

auto hImageList = ::ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1), 16, 2, CLR_DEFAULT, IMAGE_BITMAP, 0);

Upvotes: 3

Related Questions