小弟从网上下了二个源程序来学习,一个是在状态条上显示时间,另一个是获得主机名和IP的,我想二个合为一个做一个类,却出现在这个鸟错误,我是菜鸟,还请大狭门求救!
void CClockStatusBar::GetHostInfo()
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup();
}
m_Hostname=name;
m_HostIP=ip;
}
在Stdafx.h 已加入 #include <winsock2.h>
二个都可以正常运行,就是我合在一起后就不行。
Linking...
ClockStatusBar.obj : error LNK2001: unresolved external symbol __imp__WSACleanup@0
ClockStatusBar.obj : error LNK2001: unresolved external symbol __imp__inet_ntoa@4
ClockStatusBar.obj : error LNK2001: unresolved external symbol __imp__gethostbyname@4
ClockStatusBar.obj : error LNK2001: unresolved external symbol __imp__gethostname@8
ClockStatusBar.obj : error LNK2001: unresolved external symbol __imp__WSAStartup@8
Debug/ShowClockInStatusBar.exe : fatal error LNK1120: 5 unresolved externals
Error executing link.exe.
void CClockStatusBar::GetHostInfo()
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup();
}
m_Hostname=name;
m_HostIP=ip;
}
在Stdafx.h 已加入 #include <winsock2.h>
二个都可以正常运行,就是我合在一起后就不行。
Linking...
ClockStatusBar.obj : error LNK2001: unresolved external symbol __imp__WSACleanup@0
ClockStatusBar.obj : error LNK2001: unresolved external symbol __imp__inet_ntoa@4
ClockStatusBar.obj : error LNK2001: unresolved external symbol __imp__gethostbyname@4
ClockStatusBar.obj : error LNK2001: unresolved external symbol __imp__gethostname@8
ClockStatusBar.obj : error LNK2001: unresolved external symbol __imp__WSAStartup@8
Debug/ShowClockInStatusBar.exe : fatal error LNK1120: 5 unresolved externals
Error executing link.exe.
下面加入ws2_32.lib