Weird Win32 LoadImage problem
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:
HBITMAP hBitmap = (HBITMAP)LoadImage(hInstance, "myimage.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
good luck
Arkon
[QSoft Systems]
try this one:
HBITMAP hBitmap = (HBITMAP)LoadImage(hInstance, "myimage.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
good luck
Arkon
[QSoft Systems]
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.
It is weird.
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...
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
Oh yeah, and you don''t need to supply HINSTANCE.
-----------------------------
-cow_in_the_well
''When in doubt, empty your magazine.'' - Murphy''s Combat Law
Right, you only need to specify an instance handle when the resource is located in a module.
Try this:
Forget
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.
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.
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
-----------------------------
-cow_in_the_well
''When in doubt, empty your magazine.'' - Murphy''s Combat Law
What happens if you save one of the other images under the name as the image that doesn''t work? Does it work then?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement