Ok, thanks, heres what that loop looks like now:
Code:
while (!SERVER_STOP)
{
PeekMessage(&Message, NULL, WM_USER, WM_USER, PM_NOREMOVE);
// Get message(s) if there is one
if(PeekMessage(&Message, NULL, 0, 0, PM_REMOVE))
{
if(Message.message == WM_QUIT)
break;
TranslateMessage(&Message);
DispatchMessage(&Message);
}
else
{
// Handle some requests
SFD_New = accept(SFD_Listen, (struct sockaddr *) &ClientAddress, &Size);
DWORD dwThreadId; // Info for the thead
HANDLE hThread;
// Create a structure of type ARGUMENT to be passed to the new thread
ARGUMENT Argument;
Argument.CLA = ClientAddress;
Argument.SFD = SFD_New;
// CreateThread and process the request
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
ProcessRequest, // thread function
&Argument, // argument to thread function
0, // use default creation flags
&dwThreadId
); // returns the thread identifier
if (hThread != NULL) // If the thread was created, destroy it
{
CloseHandle( hThread );
}
}
}
It still didn't shut the application down though...