Jump to content
  • Advertisement

Archived

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

cow_in_the_well

Weird Win32 LoadImage problem

This topic is 6236 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
Advertisement
weird
try this one:
HBITMAP hBitmap = (HBITMAP)LoadImage(hInstance, "myimage.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

good luck

Arkon
[QSoft Systems]

Share this post


Link to post
Share on other sites
You need to supply the HINSTANCE parameter, else it doesn''t work, regardless of whether it is from a resource or from a file.

It is weird.

Share this post


Link to post
Share on other sites
I think that might depend on which version of windows you''re running; it works for me without the HINSTANCE parameter, and I have win98...

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
What happens if you save one of the other images under the name as the image that doesn''t work? Does it work then?

Share this post


Link to post
Share on other sites

  • 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!