Skip to main content
GameDev.net gamedev.net
🔒 Locked

Weird Win32 LoadImage problem

Started by cow_in_the_well Jun 24, 2001 at 4:45 AM 6 replies 1.2k views
Original Post
cow_in_the_well
cow_in_the_well
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
Arkon
Arkon
weird
try this one:
HBITMAP hBitmap = (HBITMAP)LoadImage(hInstance, "myimage.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

good luck

Arkon
[QSoft Systems]
NuffSaid
NuffSaid
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.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Beer Hunter
Beer Hunter
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...
cow_in_the_well
cow_in_the_well
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
merlin9x9
merlin9x9
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.
cow_in_the_well
cow_in_the_well
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
merlin9x9
merlin9x9
What happens if you save one of the other images under the name as the image that doesn''t work? Does it work then?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.