See below code please:
Even with using heapallocate for DTAIN and DTAOUT, when I
invoke SetDlgItemText,hWin,1003,addr DTAOUT
right after loading data into the DTAIN, DTAOUT displays the DTAIN and not garbage as expected. What did I do wrong now???


Thanks.





..
..
.data?
DTAIN DD ?
DTAOUT DD ?
..
LOCAL hF:DWORD

invoke CreateFile, addr fname, GENERIC_READ,0,0,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
mov hF,eax
invoke ReadFile,hF,addr DTAIN,511,OFFSET bread,NULL
invoke CloseHandle,hF

invoke SetDlgItemInt,hWin,1004,bread,NULL ;display count, works as expected

invoke lstrcat,addr DTAIN,0 ;null-terminate, may not be needed
;;;; invoke lstrcpy,addr DTAIN, addr DTAOUT <commented out

invoke SetDlgItemText,hWin,1003,addr DTAOUT
;still displays DTAIN when should contain garbage or even crash
Posted on 2005-03-08 07:58:11 by drarem
It should display all bar the first 4 bytes of DTAIN, you're reading 511 bytes, but have only allocated 4 (DTAIN DD ? is 4 bytes).

If DTAIN is the result of a heapalloc, then remove the addr from the places you use it.

Mirno
Posted on 2005-03-08 10:36:15 by Mirno
Right, DTAIN is meant as a pointer and is passed to heapalloc.

What I have to do is something like:

mov , DTAIN
invoke ReadFile, hF, eax, 511, OFFSET bread, NULL

but then when I do the ReadFile, followed by close and SetDlgItemText,
that will corrupt one or more registers - ReadFile being the most blatant - won't the return value from ReadFile overlay the pointer which I previously defined? Can I use another register which wouldn't be overlaid?

Yes I see where I could do it statically, but I would prefer loading a file and then defining the data storage dynamically for the pointers.


here is heap function:


heapallocate proc

invoke GetProcessHeap
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,512*DWORD
mov [DTAIN],eax

invoke GetProcessHeap
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,512*DWORD
mov [DTAOUT],eax

ret
heapallocate endp
Posted on 2005-03-08 11:55:26 by drarem
That was it Mirno, thanks. I would have gotten it the first time with your reply but inadvertently commented out my file handle :/

Seems like everytime I put masm down to rest a bit and come back to it, I'm having to relearn some of it.
Posted on 2005-03-08 21:11:02 by drarem