先贴代码:
_beginthread(&ThreadStart,0,NULL);
bool TestConnection(CString IP, unsigned int port)
{
CSocket *psocket;
psocket = new CSocket;
if (psocket == NULL)return false;
if ( !psocket->Create() )
{
delete psocket;
psocket = NULL;
return false;
}
while ( !psocket->Connect(IP,port) )
{
delete psocket;
psocket = NULL;
return false;
}
delete psocket;
return true;
}
void __cdecl ThreadStart(LPVOID lpvoidvar)
{
TestConnection("127.0.0.1",119);
//MessageBox(NULL,NULL,NULL,0);
OutputDebugString("ThreadStart\n");
Sleep(1000);
return;
}
编译运行出现以下提示:
单步调试发现是TestConnection函数中的
if ( !psocket->Create() )
这一行出错。
这是为什么呢?