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
OVERLAPPEDobject, in this caseol.The
OVERLAPPEDstruct has two variables,OffsetandOffsetHigh. These two variables are combined into a 64-bit integer, withOffsetbeing the lower-order DWORD andOffsetHighbeing 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
ReadFileat the 8th byte of the file, you would set theOffsetvariable to 8 and theOffsetHighvariable to 0 before passing theOVERLAPPEDtoReadFile.