// only try to read number of bytes in queue
ClearCommError(m_gphdCom, &dwErrorFlags, &ComStat) ;
//dwLength = min( (DWORD) nMaxLength, ComStat.cbInQue ) ;
dwLength=nMaxLength;
if (dwLength > 0)
{
if (olap==TRUE)
{
fReadStat = ReadFile(m_gphdCom,buf, dwLength, &dwLength,&READ_OS) ;
if (!fReadStat)
{
if (GetLastError() == ERROR_IO_PENDING)
{
OutputDebugString("\n\rIO Pending");
while(!GetOverlappedResult(m_gphdCom, &READ_OS,
&dwLength, TRUE ))
{
dwError = GetLastError();
if(dwError == ERROR_IO_INCOMPLETE) continue;
else
{
// an error occurred, try to recover
ClearCommError(m_gphdCom,&dwErrorFlags, &ComStat ) ;
break;
}
}
}
else // end-----if (GetLastError() == ERROR_IO_PENDING)
{
// some other error occurred