Sign in to follow this  
compugeekpro

LoadImage returning null

Recommended Posts

I am trying to make an application skin using bitmaps. I have tried both of these functions in order to get my application to load the bitmap before blitting it to the screen: m_hSkinBitmap = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_MYPIC),IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS|LR_DEFAULTCOLOR); --and-- m_hSkinBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_MYPIC)); When I check if my HBITMAP variable is valid using : if(!m_hSkinBitmap) MessageBox(m_hWindow, "Could not load bitmap", "Image Error", MB_OK | MB_ICONERROR); and run the program...my program always displays the error message box. I have tried just putting "mypic.bmp" in place of the MAKEINTRESOURCE(IDB_MYPIC) because the picture is in the same directory as the executable, but my check still returns false and no image is blitted to the screen...just the default window look. I have a resource.h file to define the resources and a resource.rc file to name the location of the bitmap image for the resource. Just to let you know, I followed all of FlipCodes instructions, but I still have this problem. Can anyone help me? -Sean G.-

Share this post


Link to post
Share on other sites
What error code does GetLastError() return?

Have you tried LoadImage(hInstance,"c://fullpath//blah//pic.bmp",IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE);?

What happens when you use:
LoadImage(hInst,MAKEINTRESOURCE(IDB_MYPIC),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);?

Good Luck



Share this post


Link to post
Share on other sites
Quote:
Original post by compugeekpro
I have tried just putting "mypic.bmp" in place of the MAKEINTRESOURCE(IDB_MYPIC) because the picture is in the same directory as the executable, but my check still returns false


that won't work at all for LoadBitmap, because LoadBitmap always expects a resource identifier (whether you are using string or integer identifiers). it should work for LoadImage, however, as long as you specify the load from file flag with a NULL HINSTANCE parameter.

couple things to watch out for:
1.) make sure your rc file is included in your project files (i've seen people on here forget to add it to their project and then wonder why their resources don't load). unlike .h and .cpp files, you shouldn't won't get any linker errors if you forget to include your resource files.
2.) if using integral resource identifiers, make sure your ids are less than an unsigned short.
3.) for LR_LOADMAP3DCOLORS, make sure your bitmap's color format is 8-bits or less.
4.) if not using integral resource identifiers, and using strings instead, do not use MAKEINTRESOURCE. just pass the name of the resource as a string directly to the function.

Share this post


Link to post
Share on other sites
Thank you...I got the load from file option to work. I was messing with resources so much that I forgot I could just load straight from the file. As far as resources go, I am going to try it right now. Thanks for the replies.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this