I am writting an application which talks ( reads and rwrites ) from a serial port. I am using overlapped file I/o asynchronously. I keep getting an invalid handle message from my WaitForMultipleObjects code and cannot figure out why. Here is the offending code:
DWORD result = ::WaitForMultipleObjects(2, waiters, FALSE, INFINITE);
switch(result)
{ /* wait */
case WAIT_OBJECT_0: // shutdown
{
::CancelIo(parms->hCom);
shutdown = ERROR_SUCCESS; // clean shutdown
running = FALSE;
continue;
}
case WAIT_OBJECT_0 + 1: // I/O complete
{
ok = ::GetOverlappedResult(parms->hCom, &ovl, &bytesRead, TRUE);
if(!ok)
{ /* GetOverlappedResult failed */
DWORD err = ::GetLastError();
running = FALSE;
continue;
} /* GetOverlappedResult failed */
break;
}
default:
{ /* trouble */
shutdown = ::GetLastError();
/////// This GetLastError returns 6, which means invalid handle. Is it the CEvent handle, or my serial port handle?
I am stumped.
Thanks
ASSERT(FALSE); // failure
running = FALSE;
continue;
} /* trouble */
} /* wait */