• ### Popular Now

• 9
• 16
• 15
• 12
• 9

#### Archived

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

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

## 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

weird
try this one:

good luck

Arkon
[QSoft Systems]

##### 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 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 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 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 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