// set up overlapped structure fields // to simplify this sample, we'll eschew an event handle gOverLapped.Offset = 0; gOverLapped.OffsetHigh = 0; gOverLapped.hEvent = NULL;
// if there was a problem, or the async. operation's still pending ... if (!bResult) { // deal with the error code switch (dwError = GetLastError()) { case ERROR_HANDLE_EOF: { // we're reached the end of the file // during the call to ReadFile
// code to handle that }
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're reached the end of the file //during asynchronous operation }
nCount如果累积到了GetLength()的长度就结束了。
// to simplify this sample, we'll eschew an event handle
gOverLapped.Offset = 0;
gOverLapped.OffsetHigh = 0;
gOverLapped.hEvent = NULL;
// attempt an asynchronous read operation
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead,
&gOverlapped) ;
// if there was a problem, or the async. operation's still pending ...
if (!bResult)
{
// deal with the error code
switch (dwError = GetLastError())
{
case ERROR_HANDLE_EOF:
{
// we're reached the end of the file
// during the call to ReadFile
// code to handle that
}
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're reached the end of the file
//during asynchronous operation
}
// deal with other error cases
}
}
} // end case
// deal with other error cases
} // end switch
} // end if
{
fclose(fp)
}