Look at the win32.hlp file that came with the compiler and
MicroSofts website is searchable too.
~ JD
if you really want to use pure Windows API have a look at this
website:
http://www.winprog.org/tutorial/
For a really good book search for: Charles Petzold, Programming
Windows
C++Builder comes with the VCL (Visual Component Library) which wraps
many parts of the Windows API and lets you create applications much
faster. For examples using the VCL look up the C++Builder help file.
In my C++Builder 5 there is a chapter 'Quickstart: Tutorials' with a
'Text Editor' tutorial. This should get you started.
Good luck,
Nick
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
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
the linker tells you the function is unresolved meaning he can't find
the implementation. The implementation is in the DLL you mentioned,
but the linker doesn't know about the DLL (it's name etc).
What is needed besides the header file is an "import library" (.lib)
for this DLL. C++Builder already has most of the lib files in his lib
directory. If one is missing you can use the implib.exe console tool.
For example:
implib iphlpapi.lib c:\windows\system\iphlpapi.dll
(if the dll is in this path)
Once you have the import library, copy it to your project folder. You
unfortunately then have to add the library to your project by hand.
"Project->Add to Project".
Now it should work.
Nick
>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
>//
>
>when i run I have this error:
>[Linker Error] Unresolved external 'SendARP' referenced from
The problem is answered in the first line of Microsoft's example that
you showed:
>// Link with ws2_32.lib and iphlpapi.lib
^^^^^^^^^^^^^^
iphlpapi.lib is in your psdk directory: ..\lib\psdk
Include that lib in your build.