[fpc-pascal] How to make a binding or wrapper ?

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Tue Nov 15 10:22:29 CET 2005

On 11/14/05, Koenraad Lelong <fpascal at brouwerij.homelinux.net> wrote:
> Hi,
> I'm making an application but to have it work like I want I need to make
> a binding or a wrapper (is there a diiference ?) to some external
> software. Are there documents that can be used to learn how to do this ?
> Regards,
> Koenraad Lelong.

Basicaly the external software can either be:

- A Library (*.dll, *.so, ......)
- An Application (*.exe, +x on unix, ...)

I will supose you are talking about libraryes

Linking to a library is easier. You just need to get the header files
for the lib, translate them to pascal, and start using the libs

The hardware tutorial on the lazarus wiki explains how to link
dinamically on Windows to a library and statically to a glibc
function: http://wiki.lazarus.freepascal.org/index.php/Hardware_Access

Here is an example of the most common link, the static library binding:

function ioperm(from: Cardinal; num: Cardinal; turn_on: Integer):
Integer; cdecl; external 'libc';

The "external" directive tells the compiler the function
implementation is in an external file. In this case "libc.so". Notice
that c functions usually use cdecl calling convention.

Notice that when declaring the function you will need to translate all
those c types to equivalent pascal types (suposing it is a library and
it is written in c). It helps a lot if you know c well.

There are other techniches to talk to an application (DDE, XML via
HTTP, System Messages, ...), but they are so many that you really need
to read the software documentation to find out witch one he uses then
we can go from there.

Basically in order to help more we need to know the nature of the
external software (language and if it is a lib or an app). =)
Felipe Monteiro de Carvalho

More information about the fpc-pascal mailing list