编译出错,获取本地计算机主机名和 IP 地址
程序代码:
//Get_IP.c #include<winsock.h> #include"resource.h" int WSA_return; WSADATA WSAData; HOSTENT *host_entry; char host_name[256]; char host_address[256]; BOOL APIENTRY Hostname_ipDlgPro(HWND hDlg,UINT message,WPARAM wParam,LPARAM IParam); int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hrevInstance,LPSTR lpCmdLine,int nCmdShow) { WSA_return = WSAStartup(0x0101,&WSAData); if(WSA_return == 0) { gethostname(host_name,256); host_entry = gethostbyname(host_name); if(host_entry !=0) { wsprintf(host_address,"%d.%d.%d.%d", (host_entry->h_addr_list[0][0]&0x00ff), (host_entry->h_addr_list[0][1]&0x00ff), (host_entry->h_addr_list[0][2]&0x00ff), (host_entry->h_addr_list[0][3]&0x00ff)); } } WSACleanup(); DialogBox(hInstance,"DIALOG1",NULL,(DLGPROC)Hostname_ipDlgPro); return 0; } BOOL APIENTRY Hostname_ipDlgPro(HWND hDlg,UINT message,WPARAM wParam,LPARAM IParam) { switch(message) { case WM_INITDIALOG: return(TRUE); case WM_COMMAND: if(LOWORD(wParam)==IDOK) { SetDlgItemText(hDlg,IDC_EDIT1,host_name); SetDlgItemText(hDlg,IDC_EDIT2,host_address); SetDlgItemText(hDlg,IDCANCEL,"确定"); } if(LOWORD(wParam)== IDCANCEL) EndDialog(hDlg,TRUE); return (TRUE); break; } return(FALSE); }
--------------------Configuration: ceshi - Win32 Debug--------------------
Linking...
ceshi.obj : error LNK2001: unresolved external symbol __imp__DialogBoxParamA@20
ceshi.obj : error LNK2001: unresolved external symbol __imp__wsprintfA
ceshi.obj : error LNK2001: unresolved external symbol __imp__EndDialog@8
ceshi.obj : error LNK2001: unresolved external symbol __imp__SetDlgItemTextA@12
Debug/ceshi.exe : fatal error LNK1120: 4 unresolved externals
编译器vc++6.0 加了wsock32.lib
不知道为什么无法编译,是那里错了吗