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.

.data
overlap OVERLAPPED <>
AmountRead dd 0

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