Heya - I needed to write a helper proc for reading data from a given offset in a file.
I've never used OVERLAPPED before, does this look right?
I don't care that it won't return early...

;The following procedure performs OVERLAPPED FILE READ
;It will NOT RETURN until the Read is completed, but it wasn't designed to be sexy.

overlap OVERLAPPED <>
AmountRead dd 0

_Read proc hfile, pdata, _size, _offset
.if !overlap.hEvent
mov overlap.hEvent, $invoke (CreateEvent, NULL, TRUE, FALSE, NULL)
m2m overlap.Offset,_offset
invoke ReadFile, hfile, pdata ,_size, addr AmountRead, addr overlap
.if eax==FALSE
invoke GetLastError
invoke WaitForSingleObject,overlap.hEvent, INFINITE
invoke MessageBox,0,CTEXT("Something wrong during File Read"),CTEXT("Error!"),MB_OK+MB_ICONERROR
invoke ResetEvent, overlap.hEvent
_Read endp
Posted on 2003-12-27 09:03:50 by Homer