错误LNK2019:无法解析的外部符号_GetIpAddrTable @ 12 [英] error LNK2019: unresolved external symbol _GetIpAddrTable@12

查看:98
本文介绍了错误LNK2019:无法解析的外部符号_GetIpAddrTable @ 12的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include"windows.h"
#include"iphlpapi.h"//IP帮助器api

LRESULT回调WndProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
PSTR szCmdLine,int iCmdShow)
{
静态TCHAR szAppName [] = TEXT("Ip地址");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;

wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;

如果(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT(此程序需要Windows NT!")),
szAppName,MB_ICONERROR);
返回0;
}

hwnd = CreateWindow(szAppName,//窗口类名称
TEXT("IP地址"),//窗口标题
WS_OVERLAPPEDWINDOW,//窗口样式
CW_USEDEFAULT,//初始x位置
CW_USEDEFAULT,//初始y位置
CW_USEDEFAULT,//初始x大小
CW_USEDEFAULT,//初始y大小
NULL,//父窗口句柄
NULL,//窗口菜单句柄
hInstance,//程序实例句柄
无效的) ; //创建参数

ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
返回msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT消息,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
DWORD i;
TCHAR szName [] = TEXT("IP地址");

MIB_IPADDRTABLE * pIPAddrTable;
DWORD dwSize = 0;
DWORD dwRetVal;

//对于错误:GetIpAddrTable调用失败
int iLength;
TCHAR szBuffer [40],szBuffer1 [40],szBuffer2 [40],szBuffer3 [40],szBuffer4 [40],szBuffer5 [40];

开关(消息)
{

案例WM_PAINT:
hdc = BeginPaint(hwnd,&ps);

GetClientRect(hwnd,&rect);

TextOut(hdc,0,1,szName,lstrlen(szName));

pIPAddrTable =(MIB_IPADDRTABLE *)malloc(sizeof(MIB_IPADDRTABLE));


/*获取GetIpAddrTable()所需的大小*/
//GetIpAddrTable函数检索接口到IPv4的地址映射表.
如果(GetIpAddrTable(pIPAddrTable,&dwSize,0)== ERROR_INSUFFICIENT_BUFFER)
{
free(pIPAddrTable);
pIPAddrTable =(MIB_IPADDRTABLE *)malloc(dwSize);
}

if((dwRetVal = GetIpAddrTable(pIPAddrTable,&dwSize,0))!= NO_ERROR)
{
TextOut(hdc,0,20,szBuffer,iLength = wsprintf(szBuffer,TEXT("GetIpAddrTable调用失败,出现%d"),dwRetVal));
}

TextOut(hdc,0,20,szBuffer1,iLength = wsprintf(szBuffer1,TEXT("IP地址:%ld \ n"),pIPAddrTable-> table [0] .dwAddr));
TextOut(hdc,0,40,szBuffer2,iLength = wsprintf(szBuffer2,TEXT("IP Mask:%ld \ n"),pIPAddrTable-> table [0] .dwMask));
TextOut(hdc,0,60,szBuffer3,iLength = wsprintf(szBuffer3,TEXT("IF Index:%ld \ n"),pIPAddrTable-> table [0] .dwIndex));
TextOut(hdc,0,80,szBuffer4,iLength = wsprintf(szBuffer4,TEXT("Broadcast Addr:%ld \ n"),pIPAddrTable-> table [0] .dwBCastAddr));
TextOut(hdc,0,100,szBuffer5,iLength = wsprintf(szBuffer5,TEXT("Re-assembly size:%ld \ n"),pIPAddrTable-> table [0] .dwReasmSize));

EndPaint(hwnd,&ps);
返回0;

案例WM_DESTROY:
PostQuitMessage(0);
返回0;
}
返回DefWindowProc(hwnd,消息,wParam,lParam);
}


我收到此错误"

1> ------构建开始:项目:iptrace,配置:Debug Win32 ------
1>正在编译...
1> iptrace.cpp
1>.\ iptrace.cpp(67):警告C4101:"i":未引用的局部变量
1>正在链接...
1> iptrace.obj:错误LNK2019:函数"long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)"中引用的未解析的外部符号_GetIpAddrTable @ 12(?WndProc @@ YGJPAUHWND __ @@ IIJ @ Z)
1> C:\ Documents and Settings \ Amit \ My Documents \ Visual Studio 2008 \ Projects \ iptrace \ Debug \ iptrace.exe:致命错误LNK1120:1无法解析的外部
1>生成日志保存在文件://c:\ Documents and Settings \ Amit \ My Documents \ Visual Studio 2008 \ Projects \ iptrace \ iptrace \ Debug \ BuildLog.htm"
1> iptrace-2个错误,1个警告
==========构建:0成功,1失败,0最新,跳过0 ===========

#include "windows.h"
#include "iphlpapi.h" //IP Helper api

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("Ip Address") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;

wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;

if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}

hwnd = CreateWindow (szAppName, // window class name
TEXT ("Ip Address"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters

ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;

while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
DWORD i;
TCHAR szName[] = TEXT ("IP ADDRESS") ;

MIB_IPADDRTABLE *pIPAddrTable;
DWORD dwSize = 0;
DWORD dwRetVal;

//For error : GetIpAddrTable call failed
int iLength;
TCHAR szBuffer[40],szBuffer1[40],szBuffer2[40],szBuffer3[40],szBuffer4[40],szBuffer5[40];

switch (message)
{

case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;

GetClientRect (hwnd, &rect) ;

TextOut(hdc,0,1,szName,lstrlen(szName));

pIPAddrTable = (MIB_IPADDRTABLE*) malloc( sizeof(MIB_IPADDRTABLE) );


/* Get size required by GetIpAddrTable() */
//The GetIpAddrTable function retrieves the interface–to–IPv4 address mapping table.
if (GetIpAddrTable(pIPAddrTable,&dwSize, 0) == ERROR_INSUFFICIENT_BUFFER)
{
free( pIPAddrTable );
pIPAddrTable = (MIB_IPADDRTABLE *) malloc ( dwSize );
}

if ( (dwRetVal = GetIpAddrTable( pIPAddrTable, &dwSize, 0 )) != NO_ERROR )
{
TextOut(hdc,0,20,szBuffer,iLength = wsprintf(szBuffer, TEXT("GetIpAddrTable call failed with %d"),dwRetVal));
}

TextOut(hdc,0,20,szBuffer1,iLength = wsprintf(szBuffer1, TEXT("IP Address: %ld\n"), pIPAddrTable->table[0].dwAddr));
TextOut(hdc,0,40,szBuffer2,iLength = wsprintf(szBuffer2, TEXT("IP Mask: %ld\n"), pIPAddrTable->table[0].dwMask));
TextOut(hdc,0,60,szBuffer3,iLength = wsprintf(szBuffer3, TEXT("IF Index: %ld\n"), pIPAddrTable->table[0].dwIndex));
TextOut(hdc,0,80,szBuffer4,iLength = wsprintf(szBuffer4, TEXT("Broadcast Addr: %ld\n"), pIPAddrTable->table[0].dwBCastAddr));
TextOut(hdc,0,100,szBuffer5,iLength = wsprintf(szBuffer5, TEXT("Re-assembly size: %ld\n"), pIPAddrTable->table[0].dwReasmSize));

EndPaint (hwnd, &ps) ;
return 0 ;

case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}


"I am getting this error "

1>------ Build started: Project: iptrace, Configuration: Debug Win32 ------
1>Compiling...
1>iptrace.cpp
1>.\iptrace.cpp(67) : warning C4101: ''i'' : unreferenced local variable
1>Linking...
1>iptrace.obj : error LNK2019: unresolved external symbol _GetIpAddrTable@12 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
1>C:\Documents and Settings\Amit\My Documents\Visual Studio 2008\Projects\iptrace\Debug\iptrace.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\Amit\My Documents\Visual Studio 2008\Projects\iptrace\iptrace\Debug\BuildLog.htm"
1>iptrace - 2 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

推荐答案

链接器错误消息很简单.只需查看MSDN帮助页面,找出可能缺少的链接库.

您可能没有链接库"Iphlpapi.lib".请参阅:
http://msdn.microsoft.com/zh-我们/library/windows/desktop/aa365949%28v=vs.85%29.aspx [
The linker error message is straightforward. Just look at the MSDN help page to find out which link library could be missing.

You probably did not link the library "Iphlpapi.lib". Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365949%28v=vs.85%29.aspx[^].

See also the code sample on this page.

—SA


问题已解决
添加了#pragma注释(lib,"IPHlpApi.Lib")

在代码中,现在[问题已解决.

但是我没有通过GetIpAddrTable获取正确的IP地址.
Problem solved
Added #pragma comment(lib,"IPHlpApi.Lib")

in the code and now [problem is solved.

But i am not getting the correct ip address by GetIpAddrTable.


这篇关于错误LNK2019:无法解析的外部符号_GetIpAddrTable @ 12的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆