1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| OVERLAPPED gOverlapped;
// Set up overlapped structure fields.
gOverlapped.Offset = 0;
gOverlapped.OffsetHigh = 0;
gOverlapped.hEvent = hEvent;
// Verify that sizeof(inBuffer <= nBytestoRead).
// Attempt an asynchronous read operation.
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead,
&gOverlapped) ;
// If there was a problem, or if the asynchronous operation
// is still pending.
if (!bResult)
{
// Deal with the error code.
switch (dwError = GetLastError())
{
case ERROR_HANDLE_EOF:
{
// WCode to handle the end of the file
// during the call to ReadFile
}
case ERROR_IO_PENDING:
{
// Asynchronous I/O is still in progress
// Do something else for a while
GoDoSomethingElse() ;
// Check on the results of the asynchronous read.
bResult = GetOverlappedResult(hFile, &gOverlapped,
&nBytesRead, FALSE) ;
// If there was a problem
if (!bResult)
{
// Deal with the error code.
switch (dwError = GetLastError())
{
case ERROR_HANDLE_EOF:
{
// We have reached the end of
// the file during asynchronous
// operation.
}
// Deal with other error cases.
} //end switch (dwError = GetLastError())
}
} // end case
// Deal with other error cases, such as the default.
} // end switch (dwError = GetLastError())
} // end if |
Partager