I have problem with this code, when I load 8 bit BMP file.
HBITMAP hbm = LoadImageW(NULL, L"C:\\Test.bmp", IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE);
But HBITMAP is 0 and GetLastError also returns 0.
Where is the problem ?
I see similar questions on stackoverflow, but this code only failed in 8 bit bitmaps.
MSDN say nothing about this behavior.
Thanks for answer or any suggestion.
EDIT: Same bitmap loaded as resource work fine.
Operating system: Windows XP SP2
EDIT 2: I tested opening this image yesterday with Photoshop – fine, MSPAINT – fine, Microsoft Agent Character Editor – failed, my app – failed! Tested today – now works!!! Tested again 10 minutes ago – do not work. Probably some kind of lock? I found similar question: http://social.msdn.microsoft.com/Forums/pl-PL/vcmfcatl/thread/df4aa858-6d59-402d-8d96-6414774fed31.
OK. I found what caused problem.
Problem was incorrect set biSizeImage member of the BITMAPINFOHEADER.
But after unsleeped night when I tested two images (80×80, 128×128), I found interesting things.
LoadImage still successfully load image with incorrect biSizeImage from 0 to real size + 1052. For example for 80×80 image, biSizeImage must be 6400, but LoadImage loads image with biSizeImage set to 0 or 1, or 6401, or 6402…but failed after setting 7453.
Still remains question, why LoadImage successed load image from resource with any biSizeImage value.