DWORD dwEvtMask = 0; OVERLAPPED ov; ZeroMemory(&ov, sizeof(OVERLAPPED)); ov.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); if(!WaitCommEvent(hComm, &dwEvtMask, &ov)) { // si toujours en attente if(GetLastError() == ERROR_IO_PENDING) { // on attent que l'opération se termine ou qu'elle soit interrompue // (lors de l'appel à SetCommMask(0) à la deconnexion par exemple) DWORD dwResult; while(!GetOverlappedResult(hComm), &ov,&dwResult, TRUE)) { if(GetLastError() != ERROR_IO_INCOMPLETE) break; } } }
// lecture si des caractères ont été reçus if(dwEvtMask & EV_RXCHAR) { }
Le port doit avoir été ouvert avec FILE_FLAG_OVERLAPPED
|