Link to home
Start Free TrialLog in
Avatar of JoeBarryTwinstar
JoeBarryTwinstar

asked on

I am writting an application which talks ( reads and rwrites ) from a serial port. I am using overlapped file I/o

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 */  
Avatar of jkr
jkr
Flag of Germany image

How is 'waiters' declared and how are you filling it?
Avatar of JoeBarryTwinstar
JoeBarryTwinstar

ASKER

It has 2 handles

I is 0x0000 and is named shutdown
the other looks like a valid handle and came from CreateEvent in an overlapped i/o structure
Err, what about some more - details. How is 'waiters' in

DWORD result = ::WaitForMultipleObjects(2, waiters, FALSE, INFINITE);

declared and how are you filling it?
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial