Click here to Skip to main content
15,893,588 members

error LNK2019: unresolved external symbol _GetIpAddrTable@12

amityadav4a asked:

Open original thread
#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 ==========
Tags: C++, Visual Basic (Visual Basic 9 (2008)), Visual Studio, Errors

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900