I've got a problem with canceling WaitCommEvent() under windows 2000. This piece of code below works fine under win95.
Im creating several threads, one for each com port to listen to.
Below you can find the method DoJob wich is in the thread. It contains the WaitCommEvent function. Also in the thread a method called End.
And it is in the End method that I want to cancel the waitcommevent. If I just triy to destroy the thereads the threads wont terminate until waitcommevent cancels. So I tried to use SetCommMask to cancel. This works fine under win95 but now I want the program to work on win 2000.
I've tried SetCommMask, PurgeComm, TransmitCommChar. Nothing works. The program just hangs whenever I'm using the comport handler.
DWORD dwErrorFlags, dwEvtMask = 0;
overlapped.hEvent = CreateEvent(
NULL, // no security attributes
TRUE, // auto reset event
FALSE, // not signaled
NULL // no name
m_sFilterList = "NONE";
m_sFilterList = "RP570";
m_sFilterList = "R4E2";
m_sFilterList = "RIP";
m_sFilterList = "ASCII";
m_sFilterList = "HEX";
/* CONNECT TO SERIAL PORT */
m_tComm = CreateFile( sFormatedSerialPort,GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
/* CHECK IF SELECTED PORT EXISTS OR IS IN USE*/
if (m_tComm == INVALID_HANDLE_VALUE)
//CAN DISPLAY ERROR MSG HERE
/* SET WHAT TO WAIT FOR "EV_RXCHAR = A character was received and placed in the input buffer. " */
::SetupComm(m_tComm, 4096, 4096);
::PurgeComm(m_tComm, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RX CLEAR);
WaitCommEvent(m_tComm, &dwEvtMask, &overlapped);
::ClearCommError(m_tComm, &dwErrorFlags, &ComStat);
DWORD dwLength = min((DWORD)MAX_RXBLOCK, ComStat.cbInQue);
/* READ FROM SERIAL PORT. PLACES IN sBuffer */
BOOL bReadStat = ReadFile ( m_tComm, &sBuffer, dwLength, &dwLength, &overlapped);
SetCommMask ( m_tComm, 0 ) ;
//Close handle to comport