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 */  
System Programming

Avatar of undefined
Last Comment
DanRollins

8/22/2022 - Mon
jkr

How is 'waiters' declared and how are you filling it?
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
jkr

Err, what about some more - details. How is 'waiters' in

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

declared and how are you filling it?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
DanRollins

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.