i'm having trouble with this bit of code.



invoke GetDC, hDlg
mov ebx, eax
invoke GetCurrentObject, ebx, OBJ_BITMAP
mov edi, eax
invoke GetObject, edi, sizeof(BITMAP), ADDR bm
.if eax==0
invoke Beep, 440, 200
.endif


edi always seems to be an invalid handle. even if i select a bitmap in to the DC or not. any ideas?
Posted on 2002-02-05 14:24:38 by Sloat
If I were you I would try using a variable instead of edi. Try



invoke GetCurrentObject, ebx, OBJ_BITMAP
mov HandleOfObject, eax
invoke GetObject, addr HandleOfObject, sizeof(BITMAP), ADDR bm


...Just trying to be helpful...
Posted on 2002-02-05 19:36:23 by CodeLover
Using a variable instead of edi will not do any difference.
GetObject wants a HANDLE as its first parameter, not a pointer to
a handle, so sloat's code is correct there.

As to why the code fails... *shrug*. Does GetDC return a reasonable value?
Perhaps try calling GetObject twice... first with a NULL buffer, this should
return the amount of bytes needed to store the item. Then alloc
a buffer and call GetObject again. Shouldn't be necessary, but never
say never :). Of course this will not help if GetCurrentObject fails...

The dc *does* have a bitmap selected in it, doesn't it?
Posted on 2002-02-05 19:45:51 by f0dder
GetCurrentObject isn't failing. it's just returning a bad handle, whether there's a bitmap selected or not.
Posted on 2002-02-05 22:21:49 by Sloat
Well, "returning a bad handle" is the same a "failing". Faulting, on
the other hand, means crash and burn.
Posted on 2002-02-05 22:24:12 by f0dder
I think (but may be mistaken) that you can only get bitmaps or dibsections from memory DCs.

I say this because I've used GetCurrentObject and GetObject the same way as you just have many times with memory DCs and never had a problem.
Posted on 2002-02-06 03:45:02 by Eóin