|
|
struct hostent FAR *lpHost=gethostbyname(strHostName);
if(lpHost==NULL)
{
AddMessageToMessageBar("得到IP失败");
return FALSE;
}
LPSTR lpstr=lpHost->h_addr_list[0];
if(lpstr==NULL)
{
AddMessageToMessageBar("得到IP失败");
return FALSE;
}
struct in_addr inaddr;
memmove(&inaddr,lpstr,sizeof(inaddr));
strHostIP=inet_ntoa(inaddr);
return TRUE;
//////////////////////////////////////////////////////////////////////////
使用前在项目的InitInstance函数里加上初始化代码
if (!AfxSocketInit())
{
AfxMessageBox("socket init fail!");
return FALSE;
}
__________________
if(有电&&有电脑)
{
Programing();
}
else
{
Sleeping();
}
|
|