I have a dialog box with 2 buttons : 'START' and 'STOP'.
Pressing 'start' will create a serial port connection, and start a thread that will read characters from the connection.
Pressing 'stop' must end the reading thread.
This can be necessary in the case where the port is opened successfully, but no characters come in because of a disconnected device. (--> so, I must be able to interrupt the WaitCommEvent command)
afxBeginThread returns a usefull value in which will allow you to terminate the thread. This value is the handle to the thread. Use GetExitCodeThread to get the exit code of the thread and use that to terminate the thread using afxEndThread.
If that doesn't work create a variable shared by 2 threads when you start the second thread have it set the variable with the handle to the thread using GetCurrentThread(). Use GetExitCodeThread() to get the exit code and then afxEndThread() to endit.
---------------------------------------------------------------------------------
To end the thread, call AfxEndThread from within the thread, or return from the controlling function of the worker thread.
---------------------------------------------------------------------------------
But that isn't possible if the thread is locked by the WaitCommEvent()-function ...
Bookmarks