I use the API GetModuleFileName to get the full path of my executable and need to read some appended data from it, so I allocated memory which is as big as my file and try to read the whole file into this memory block. But when I use MessageBox to display the memory block I always see an empty box although I should see at least MZ. To open the file I use CreateFile but do I have to set any special flag to read from my own file when it is running?

Code I use for CreateFile:


push NULL
push FILE_ATTRIBUTE_NORMAL
push OPEN_EXISTING
push NULL
push FILE_SHARE_READ
push GENERIC_READ
push offset BUFFER
call CreateFile ; does NOT return INVALID_HANDLE_VALUE


Code I use to allocate memory:


push eax
push GMEM_MOVEABLE or GMEM_ZEROINIT
call GlobalAlloc ; No errors
test eax,eax
je @b
mov MEM_HANDLE,eax
push eax
call GlobalLock ; No errors


Code for ReadFile:


push NULL
push SIZERW
push MEM_SIZE
push MEM_POINTER
push FILE_HANDLE ; Running EXE
call ReadFile


And if I use MessageBox to display MEM_POINTER I don't see MZ.....
Posted on 2004-11-18 06:33:46 by asmpower
IIRC fourth parameter of ReadFile has to be a pointer to a DWORD.
Posted on 2004-11-18 07:39:35 by japheth