Supposed I have something like this
readFile(.....&ol) //with overlapped
while(1){
////////.....
waitforsingleobject(//ol.hevent);
/开发者_如何学编程///
readfile(.....&ol)
}
I noticed that both readfiles read from the beginning of the file...why? In a normal readfile without overlapped/asynchronization the second readfile would start off where the first ended..
When using overlapped I/O on a file, you pass a pointer to an OVERLAPPED
object, in this case ol
.
The OVERLAPPED
struct has two variables, Offset
and OffsetHigh
. These two variables are combined into a 64-bit integer, with Offset
being the lower-order DWORD and OffsetHigh
being the high-order DWORD, and used as the offset to perform the I/O operation at.
So, for example, if you wanted to start a ReadFile
at the 8th byte of the file, you would set the Offset
variable to 8 and the OffsetHigh
variable to 0 before passing the OVERLAPPED
to ReadFile
.
精彩评论