Article View: borland.public.cppbuilder.nativeapi
Article #16318Re: borland c++ builder and windows api
From: giorgio
Date: Wed, 21 May 2003 16:48
Date: Wed, 21 May 2003 16:48
149 lines
4850 bytes
4850 bytes
"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> ha scritto nel messaggio
news:3eca6dff@newsgroups.borland.com...
> Hi,
>
> you can call any Windows API function from within your VCL
> application, provided you include the right header files etc..
> Most Windows API stuff is ready to be used in C++Builder with the
> header files you find in the <include> directory.
> So what exactly is the problem?
>
> regards,
> Nick
>
>
Hi Nick,
I want to use,in my application, SENDARP function, this function is included
in iphdpapi.dll.
In microsoft web site i see this exemple:
Example Code
The following code demonstrates how to obtain the media access control (MAC)
address associated with a specified IP address.
//
// Link with ws2_32.lib and iphlpapi.lib
//
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <iphlpapi.h>
int __cdecl main()
{
HRESULT hr;
IPAddr ipAddr;
ULONG pulMac[2];
ULONG ulLen;
ipAddr = inet_addr ("192.168.25.31");
memset (pulMac, 0xff, sizeof (pulMac));
ulLen = 6;
hr = SendARP (ipAddr, 0, pulMac, &ulLen);
printf ("Return %08x, length %8d\n", hr, ulLen);
size_t i, j;
char * szMac = new char[ulLen*3];
PBYTE pbHexMac = (PBYTE) pulMac;
//
// Convert the binary MAC address into human-readable
//
for (i = 0, j = 0; i < ulLen - 1; ++i) {
j += sprintf (szMac + j, "%02X:", pbHexMac[i]);
}
sprintf (szMac + j, "%02X", pbHexMac[i]);
printf ("MAC address %s\n", szMac);
delete [] szMac;
return 0;
}
//----------------------------
I use Borland c++ 5 builder and The following code is my application:
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//-------------------
#include <winsock2.h>
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <iphlpapi.h>
//------------------------------------
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
WSADATA wsa = {0};
if( WSAStartup(MAKEWORD(2, 0), &wsa) != 0 )
ShowMessage("winsock2 non present");
// the requested WinSock version is not available
}
//--------------------------------------------------------------------------
-
---------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//int __cdecl main()
//{
HRESULT hr;
IPAddr ipAddr;
IPAddr ipAddr2;
ULONG pulMac[2];
ULONG ulLen;
ipAddr = inet_addr ("10.10.50.2");
ipAddr2 = inet_addr ("10.10.50.3");
memset (pulMac, 0xff, sizeof (pulMac));
ulLen = 6;
hr = SendARP (ipAddr, ipAddr2, pulMac, &ulLen);
printf ("Return %08x, length %8d\n", hr, ulLen);
size_t i, j;
char * szMac = new char[ulLen*3];
PBYTE pbHexMac = (PBYTE) pulMac;
//
// Convert the binary MAC address into human-readable
//
for (i = 0, j = 0; i < ulLen - 1; ++i) {
j += sprintf (szMac + j, "%02X:", pbHexMac[i]);
}
sprintf (szMac + j, "%02X", pbHexMac[i]);
printf ("MAC address %s\n", szMac);
delete [] szMac;
// return 0;
//}
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
WSACleanup();
}
//------------------------------
when i run I have this error:
[Linker Error] Unresolved external 'SendARP' referenced from
C:\MACADDRESS4\UNIT1.OBJ
I don't understand where is the problem..
Tahnks for all Nick
Technical Details
Message-ID:
<3ecbaa30@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3ec9e39b@newsgroups.borland.com> <3eca041d@newsgroups.borland.com> <3eca314b@newsgroups.borland.com> <3eca6dff@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,3ad9d0d2179ea58e X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-05-21 09:38:28 PST Reply-To: "giorgio" <antonio.buonanno@cablelettra.it> From: "giorgio" <jocker99@iol.it> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ec9e39b@newsgroups.borland.com> <3eca041d@newsgroups.borland.com> <3eca314b@newsgroups.borland.com> <3eca6dff@newsgroups.borland.com> Subject: Re: borland c++ builder and windows api Date: Wed, 21 May 2003 18:48:55 +0200 Lines: 153 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 213.26.6.6 Message-ID: <3ecbaa30@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1053534768 213.26.6.6 (21 May 2003 09:32:48 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail