I'm getting a memory write error, I suspect I am not pointing to my buffer array correctly somewhere but not sure. Running it under memproof, I am releasing the heap correctly. I am storing DWORDS btw.





.data?
gBUFF DWORD ? ;pointer to heap of memory hopefully

.code
....
INITIALIZE:
invoke GetProcessHeap
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,330000*sizeof(DWORD) ;size of bitmap in pixels
mov gBUFF,eax

CLEANUP:
invoke GetProcessHeap
invoke HeapFree, eax, 0, gBUFF


WRITE PROCESS:
InitArray proc BDC:DWORD,w:DWORD, h:DWORD
LOCAL ex:DWORD
LOCAL fx:DWORD

m2m ex,0
m2m fx,0
mov esi, OFFSET gBUFF
mov ecx,0
lj2:
push ecx
invoke GetPixel,BDC,ex,fx
pop ecx
mov [esi+ecx*4],eax
inc ecx
inc ex
cmp ex,w
jnge lj2
mov ex,0
inc fx
cmp fx,h
jnge lj2

ret
InitArray endp
Posted on 2003-09-25 13:02:37 by drarem
why are you releassing the heap before you even use it... try putting that after you finish using it..

also have you try to check if the API's return a error i dont see any error check code there..
Posted on 2003-09-25 13:26:15 by devilsclaw
HeapFree is in the WM_CLOSE portion, it is not being released before usage.
Posted on 2003-09-25 13:29:10 by drarem
since its not a structure and since its already a pointer to the memory allocated i dont think you need to do
mov esi, OFFSET gBUFF

you should just do
mov esi, gBUFF
Posted on 2003-09-25 13:45:58 by devilsclaw
thanks, it seems to have worked.. but why...
Posted on 2003-09-25 13:53:28 by drarem
you would only move the offset of structure so that you could get the pointer to its memory... since its already a pointer to the memory location, it ends up pointing to the dword of the location the dword is stored and starts writing there
Posted on 2003-09-25 13:59:05 by devilsclaw
mov esi,OFFSET gBuff loads the address of gBuff.

So when ECX is 0, mov ,eax overwrites gBuff, not the buffer pointed to by gBuff.
Posted on 2003-09-25 18:16:37 by tenkey