char caHostName[128];
int h;
CString str;
char FAR * hello;
struct hostent FAR * pHost;
int namelen=18;
gethostname(caHostName,namelen);
pHost = gethostbyname(caHostName);//获得主机结构
/* hello = inet_ntoa(*((in_addr *)pHost->h_addr));
*/ if ((h=gethostname(caHostName,namelen)) == NULL)
{
AfxMessageBox("open haha error!");
}
str.Format("int:%d",h);
AfxMessageBox(str);
为什么运行返回-1啊?
int h;
CString str;
char FAR * hello;
struct hostent FAR * pHost;
int namelen=18;
gethostname(caHostName,namelen);
pHost = gethostbyname(caHostName);//获得主机结构
/* hello = inet_ntoa(*((in_addr *)pHost->h_addr));
*/ if ((h=gethostname(caHostName,namelen)) == NULL)
{
AfxMessageBox("open haha error!");
}
str.Format("int:%d",h);
AfxMessageBox(str);
为什么运行返回-1啊?
If no error occurs, this function returns zero. If an error occurs, it returns SOCKET_ERROR, and a specific error code can be retrieved by calling WSAGetLastError. The following table shows the possible error codes.#define SOCKET_ERROR (-1)