Archived

This topic is now archived and is closed to further replies.

Weird Win32 LoadImage problem

This topic is 6018 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

Strange problem alert..... HBITMAP hbmp = (HBITMAP)LoadImage (NULL, Filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE); // Returns NULL DWORD errID = GetLastError (); // Returns 0 which is "ERROR_SUCCESS" !!!?! I copied this line of code directly from another project which works fine! I''ve tried rebooting as well. I''m using win2k. Filename is valid, and _getcwd (current working directory) is right...so.....WTF????? ----------------------------- -cow_in_the_well ''When in doubt, empty your magazine.'' - Murphy''s Combat Law

Share this post


Link to post
Share on other sites
Well....it turns out that the bitmap i was trying to load (which loads fine into mspaint and photoshop) was not liked by loadimage. It works fine now. I still don''t understand why GetLastError was returning success....oh well...

Oh yeah, and you don''t need to supply HINSTANCE.

-----------------------------
-cow_in_the_well

''When in doubt, empty your magazine.'' - Murphy''s Combat Law

Share this post


Link to post
Share on other sites
Right, you only need to specify an instance handle when the resource is located in a module.

Try this:
  
HBITMAP hbm = (HBITMAP)LoadImage(NULL, Filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);


Forget LR_CREATEDIBSECTION; there should rarely be a need for that. If you specify LR_DEFAULTSIZE, a "default" size is used, rather than the actual resource''s dimensions when you specify 0 and 0 as the dimensions.

The only other thing I can think of is that perhaps the working directory of your resource is not correct so LoadImage really can''t find your file. Check that. If that doesn''t change anything, try putting the file in the root directory of, say, the C drive. Then give LoadImage the full path of that file; in this case it should be something like "C:\myimage.bmp". See if that makes it work.

Share this post


Link to post
Share on other sites
Like I said, i checked that with _getcwd (get current working directory). I''m gonna try not using the DEFAULTSIZE flag. Its still strange ''cause it only doesn''t work with that ONE bitmap.

-----------------------------
-cow_in_the_well

''When in doubt, empty your magazine.'' - Murphy''s Combat Law

Share this post


Link to post
Share on other sites