There are lots of sane ways to close a thread... TerminateThread() isn't one of them.
If it has no message handler (i.e. is not tossing messages) the easiest way is to set a global variable ... ThreadStop or such... and use that as the condition in a while() statement... When the stop condition is met you exit your loop and let the thread function return normally.
Code:
// at global scope
BOOL ThreadStop = FALSE;
// inside the threadproc
while (!ThreadStop)
{
// do winsock stuff
}
// here you close your ports
ExitThread(0);
}
// user clicks stop button (in main message loop)
case id_Stop :
ThreadStop = 1;
Of course if the thread is tossing window messages you can just post a message to the message proc that tells it to exit.