[fpc-devel] a shared library suggestion

Joost van der Sluis joost at cnoc.nl
Wed May 10 00:26:25 CEST 2006


On Tue, 2006-05-09 at 21:26 +0100, peter green wrote:
> > > What i'd like to see is compiler level support for loading
> > dynamic libraries
> > > and binding thier functions on demand.
> >
> > Like the database-base packages do? (example:
> > packages/base/ibase/ibase60dyn.pp)
> ok that unit really confuses me, it seems to treat procedures declared
> external as if they were pointers. what exactly is going on?!

It defines the procedures as variables, like this:

var
  isc_attach_database : function(param:integer):integer; extdecl;

And then it assigns the external-procedure to it - at runtime - with
this commands:

begin
  IBaseLibraryHandle:=LoadLibrary(LibraryName);
  pointer(isc_attach_database) := 
     GetProcedureAddress(IBaseLibraryHandle,'isc_attach_database');
end;

And when that is done, you can simply call:

i := isc_attach_database(param);

Maybe you could get confused by the ifdef's and 'extdecl' term.
'extdecl' is just a macro defined as cdecl or stdcall, dependent on the
OS.

And the include-file can be used for dynamical loading, and statical. So
all proceduress are defined twice. Once statical and once dynamical.
Which one is compiled is dependent on the LinkDynamically define.

Joost.





More information about the fpc-devel mailing list