Jump to content
  • Advertisement
Sign in to follow this  

WinAPI - LoadImage sometimes crashes

This topic is 4254 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I use the LoadImage function from the WinAPI to load images. Most of the time LoadImage works correct but sometimes the bits per pixels are wrong it is said that the image only consits of 1 bit per pixel although it consists of 24. The weired thing is that I always load the same image so there shouldnt be the error sometimes. Where could go wrong?
HBITMAP hImage = (HBITMAP) LoadImage(NULL,

// Could not load bitmap
if (!hImage) 

// Get info about bitmap
DIBSECTION dibSection;
if (dibSection.dsBm.bmBitsPixel == 1) cout << "only consits of one pixe"<<endl; 
Thanks a lot!!!

Share this post

Link to post
Share on other sites
The docs for GetObject indicate that the DIBSECTION structure is used with bitmaps returned from CreateDIBSection. Try using the BITMAP structure instead. I realize that the first member of the DIBSECTION structure is a BITMAP structure, but that's what I'd try first just the same - even though you specified LR_CREATEDIBSECTION in the LoadImage call.

See also HOWTO: How To Use LoadImage() to Read a BMP File

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!