1.定义的全局变量
DWORD WINAPI ClientThread(LPVOID lpParam);
struct ClientInfo
{
SOCKET sock;
SOCKADDR_IN clientAddr;////定义地址族
};2.使用方法
HANDLE hThread;
DWORD dwThread;struct ClientInfo *pClientInfo=NULL;
pClientInfo=(struct ClientInfo *)malloc(sizeof(struct ClientInfo));
hThread = CreateThread(NULL,0,ClientThread,(LPVOID)pClientInfo,0,&dwThread);
//free(pClientInfo);
if(hThread==NULL)
{
AfxMessageBox("Thread Creat Failed! ");
return;
}CloseHandle(hThread);
3.线程函数的实现
DWORD WINAPI ClientThread(LPVOID lpParam)
{
struct ClientInfo *pClinetInfo=(struct ClientInfo *)lpParam;
SOCKET sock = pClinetInfo->sock;
SOCKADDR_IN addrClient=pClinetInfo->clientAddr;
free(lpParam);
CTCPServerDlg *dlg=(CTCPServerDlg*)AfxGetApp()->GetMainWnd();while(1)
{
.....
Sleep(200);
}
return 0;
}