Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

borland c++ builder and windows api

711 views
Skip to first unread message

giorgio

unread,
May 20, 2003, 4:23:45 AM5/20/03
to
Hi, I am newbie to develop windows api whit borland c++ 5 builder.
do you know documents or exemple?
thanks for all
p.s. excuse me for my bad english


JD

unread,
May 20, 2003, 4:36:43 AM5/20/03
to

Look at the win32.hlp file that came with the compiler and
MicroSofts website is searchable too.

~ JD

nicolasr

unread,
May 20, 2003, 6:32:44 AM5/20/03
to
Hi Giorgio,

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


giorgio

unread,
May 20, 2003, 9:55:17 AM5/20/03
to

"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> ha scritto nel messaggio
news:3eca...@newsgroups.borland.com...
Hi Nick , tanks for the book, it's very interesting.
may be you didn't understand my problem, I want create a program that use
VCL and Windows API,
for example in my appllication when i click a button run WINAPI functions
starts as if it was a normal class/function.
good bye


nicolasr

unread,
May 20, 2003, 2:04:30 PM5/20/03
to
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


giorgio

unread,
May 21, 2003, 12:48:55 PM5/21/03
to

"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> ha scritto nel messaggio
news:3eca...@newsgroups.borland.com...
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

nicolasr

unread,
May 21, 2003, 3:23:55 PM5/21/03
to
Hi Giorgio,

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


Bob Gonder

unread,
May 21, 2003, 6:11:26 PM5/21/03
to
"giorgio" <jock...@iol.it> wrote:

>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.

giorgio

unread,
May 22, 2003, 9:20:32 AM5/22/03
to

"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> ha scritto nel messaggio
news:3ecbd218$1...@newsgroups.borland.com...
It's all ok TANKS NICK
regards,
Giorgio


0 new messages