i'm trying to add a backbuffer to my small small app but it is a weird problem which i cant explain so i just add a .rar file to this post and you have a look on it if you want to.
Posted on 2004-03-21 05:18:32 by bj1500
You use EBX... but it doesn't seem like you're preserving it?
Posted on 2004-03-21 08:14:14 by f0dder
Where do i use EBX and dont preserving it? cant find it!
the problem is that my dlg is transparant, why?
Posted on 2004-03-22 10:30:41 by bj1500
The routine paintback make use of ebx. On my 2k machine,

IDD_DLG: grap1.exe - Application Error
The instruction at "0x77e28c30" referenced memory at "0x00000233". The memory could not be "read".

Click on OK to terminate the program
Click on CANCEL to debug the program
OK Cancel
Posted on 2004-03-22 10:58:23 by roticv
Hum, weird :/
Can you please take a look at it? cause i dont get that error on XP :(
Posted on 2004-03-22 12:10:23 by bj1500
Just preserve ebx before using it in paintblack like what f0dder had mentioned. The gpf is because you did not preserve ebx.
Posted on 2004-03-23 06:49:58 by roticv
xor ebx,ebx

mov EBX, Winrect.bottom
invoke PaintBack,hhdc,hMemDC,hWnd ; PaintBack doesn't preserve
mov ebx, Winrect.bottom

You only *have* to preserve in DlgProc, but generally it's a good idea to follow the win32 calling convention in all your procs. Direction Flag must be left clear, EBX,ESI,EDI,EBP,ESP must be preserved, ESP must be 4byte-aligned, etc. Of course this stuff doesn't mean to blindy push/pop all the registers and cld before returning, it's means preserving if you change anything. EAX,ECX,EDX are freely trashable, and you must assume that any proc call will trash them.
Posted on 2004-03-23 08:17:56 by f0dder
NOW it works! I totaly rewrote my PaintBack to:

PaintBack proc MemDC:HDC
invoke CreateCompatibleDC,MemDC
mov memDC,eax
mov Y,0
mov X,0
.WHILE Y < 547
mov X,0
.WHILE X < 781
invoke SelectObject,memDC,BackMask
invoke BitBlt,MemDC,X,Y,32,32,memDC,0,0,SRCAND
invoke SelectObject,memDC,Back
invoke BitBlt,MemDC,X,Y,32,32,memDC,0,0,SRCPAINT
add X,32
add Y,32
invoke SelectObject,memDC,Pic1Mask
invoke BitBlt,MemDC,gubbeX,gubbeY,32,32,memDC,0,0,SRCAND
invoke SelectObject,memDC,Pic1
invoke BitBlt,MemDC,gubbeX,gubbeY,32,32,memDC,0,0,SRCPAINT

invoke DeleteObject,memDC
PaintBack endp

Posted on 2004-03-23 11:23:34 by bj1500
Did you also fix your DlgProc to preserve EBX? Otherwise, you've won a kick in the nuts ^_^
Posted on 2004-03-23 11:34:49 by f0dder
Well, I dont see why i should preserve EBX now? :)
Posted on 2004-03-23 11:39:38 by bj1500
You had a bunch of code in your WndProc that messed with EBX, without doing preservation... unless you changed that code to use another register, yes, you will have to preserve ebx. Remember, you must always restore <the aforementioned registers> if you modify them in callbacks (wndproc, dlgproc, and a bunch of other things).
Posted on 2004-03-23 11:49:19 by f0dder