Hi,
I'm trying to load a bitmap by ID from resources (which works fine - I can then display it) and then get its dimensions with GetObject function. However, GetObject always returns NULL, which denotes an error. A call to GetLastError also returns NULL, which denotes NO error... Any idea what might be wrong?
I'm trying to load a bitmap by ID from resources (which works fine - I can then display it) and then get its dimensions with GetObject function. However, GetObject always returns NULL, which denotes an error. A call to GetLastError also returns NULL, which denotes NO error... Any idea what might be wrong?
How about showing us how you are doing it ? It should be like this
Replace DIBSECTION for BITMAP if you are not using DIB sections.
.data
hBmp dd ?
dibstruct DIBSECTION <>
.code
invoke LoadImage, [hInstance], IDR_IMAGE, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION
mov [hBmp], eax
invoke GetObject, [hBmp], SIZEOF DIBSECTION, offset dibstruct
mov eax, [dibstruct.dsBm.bmBits]
mov [pDIBits], eax
Replace DIBSECTION for BITMAP if you are not using DIB sections.
Thanks for the answer. I'm doing it almost the same way:
bm BITMAP <>
invoke LoadBitmap, edi, 2 ; edi = hInstance, 2 = RESOURCE_ID
mov , eax ; the bitmap actually gets loaded with no errors - I can display it
invoke GetObject, eax, (sizeof BITMAP), (offset bm) ; this call fails - it returns 0
invoke GetLastError ; this call also returns 0, which means no error
I copied and pasted your code and it also doesn't work, however GetLastError now returns 8 (not enough memory). My bitmap seems OK because the same happens with another one.
bm BITMAP <>
invoke LoadBitmap, edi, 2 ; edi = hInstance, 2 = RESOURCE_ID
mov , eax ; the bitmap actually gets loaded with no errors - I can display it
invoke GetObject, eax, (sizeof BITMAP), (offset bm) ; this call fails - it returns 0
invoke GetLastError ; this call also returns 0, which means no error
I copied and pasted your code and it also doesn't work, however GetLastError now returns 8 (not enough memory). My bitmap seems OK because the same happens with another one.
The high level code certainly looks correct, but I have a quick question...
invoke GetObject, eax, (sizeof BITMAP), (offset bm) ; this call fails - it returns 0
Doesnt offset use eax behind the scenes? Perhaps your over writing (eax-hWnd)
by accident. Then again maybe not, I thought the compiler warned of such things...
invoke GetObject, eax, (sizeof BITMAP), (offset bm) ; this call fails - it returns 0
Doesnt offset use eax behind the scenes? Perhaps your over writing (eax-hWnd)
by accident. Then again maybe not, I thought the compiler warned of such things...
Hi Graebel,
That's ADDR that can use EAX (lea eax,etc...), offset is equivalent to an immediate.
Hi marcinbu,
I don't ever use LoadBitmap (I only ever use DIB sections) but a quick test shows that I have no problem with the following code, it returns 24:
So I can't really help, sorry
That's ADDR that can use EAX (lea eax,etc...), offset is equivalent to an immediate.
Hi marcinbu,
I don't ever use LoadBitmap (I only ever use DIB sections) but a quick test shows that I have no problem with the following code, it returns 24:
invoke LoadBitmap,[hInstance],IDR_TBBITMAP
push eax
invoke GetObject,eax,SIZEOF BITMAP,offset sbmp
PrintDec(eax)
pop eax
invoke DeleteObject,eax
So I can't really help, sorry
I've got no idea what might be wrong.... Anyways, thanks for your help.
Hi :)
How about calling GetObject with a NULL pointer, to see how many bytes you need to allocate? That might give you a hint on what's going on. :?:
How about calling GetObject with a NULL pointer, to see how many bytes you need to allocate? That might give you a hint on what's going on. :?:
Hi Qvasimodo,
It should always be SIZEOF BITMAP, that is the only valid value for a bitmap handle. I would suggest that you run the program under NT/2K or XP so that GetLastError will tell you what the problem is. I assume that as part of the older GDI that GetLastError does not work under Win9x, as is the case in many of those kind of functions.
It should always be SIZEOF BITMAP, that is the only valid value for a bitmap handle. I would suggest that you run the program under NT/2K or XP so that GetLastError will tell you what the problem is. I assume that as part of the older GDI that GetLastError does not work under Win9x, as is the case in many of those kind of functions.
Forgot to mention: I'm running XP. I even tested it on another XP machine. In both cases GetObject returns 0 and GetLastError also returns null. How about if I sent you my executable so you can run it under a debugger and see it for yourself?
Got it! :) This is pretty odd but described situation happens if the BITMAP structure which is to be filled by GetObject is located at na odd address - align it to a word boundary and everything works fine... Seems I discovered a bug in Windows or something.... Anyways, I'd like to thank you all of you for trying to solve the problem with me.
Most of data used by Windows must be DWORD aligned ;)
Hi,
Yeah, not a bug but a rule.
I try to avoid misaligned data like the plague. It slows down your program by an enormous degree. Usually I put ALIGN 4 (ALIGN 16 for SIMD stuff) after strings have been declared, I wrote an article for the Wiki book about it, what ever happened to that thing ???
Yeah, not a bug but a rule.
I try to avoid misaligned data like the plague. It slows down your program by an enormous degree. Usually I put ALIGN 4 (ALIGN 16 for SIMD stuff) after strings have been declared, I wrote an article for the Wiki book about it, what ever happened to that thing ???
the wiki? or your article?
have a nice day or night.
have a nice day or night.
Both really,
But I found it...
MissAlign
It's grown a bit since I wrote it, there was a big push for the book for a while and now it seems mostly silent about it. Don't hear much at all anymore.
But I found it...
MissAlign
It's grown a bit since I wrote it, there was a big push for the book for a while and now it seems mostly silent about it. Don't hear much at all anymore.
Yes, I still have some ideas :) but first before write it, I need read a book that I see time a go :) a big one. Also there are things mostly time :S. But hey... if I write for answer a post, for what not write in the book other time ;).
Have a nice day or night
Have a nice day or night