I am trying to load an image resource using the LoadImageA()
function, yet it doesn't work and I don't understand why.
Here's a bit of my code :
bool isRessource = IS_INTRESOURCE(107);
// Load the resource to the HGLOBAL.
HGLOBAL imageResDataHandle = LoadImageA(
NULL,
MAKEINTRESOURCEA(107),
IMAGE_BITMAP,
0,
0,
LR_SHARED
);
HRESULT hr = (imageResDataHandle ? S_OK : E_FAIL);
The image I want to load is a bitmap saved in the resources, and represented as such within resources.h
:
#define IDB_BITMAP1 107
When I execute the code, isRessource
is equal to true
, yet hr
is equal to E_FAIL
.
Any idea as to why this is happening? I am using Visual Studio 2019, and I made the image using Gimp.
IS_INTRESOURCE()
the way you are is useless, it will always returntrue
. So just get rid of it. As forLoadImage()
, when it returns NULL, you can useGetLastError()
to find out why. But offhand, one thing I notice is that your ID saysPNG
, but you are loading the resource asIMAGE_BITMAP
. What is the actual type for your resource in your.rc
file ? Is itBITMAP
, or something else?hInst
: To load an OEM image, set this parameter to NULL." - You aren't loading an OEM image, so you need to set the value to the appropriate module handle that contains the resource.GetModuleHandle (NULL)
instead, to load a resource from your .exe