Call Library

From Freepascal Amiga wiki
Revision as of 18:28, 25 August 2013 by Alb42 (talk | contribs) (activated syntax highlighting)
Jump to navigation Jump to search

How to call a library function:

As Example the AddTail function of the Exec.library. first you need the parameter line and the offset of the function in the library both you can find in the includes of AROS for example: Includes/clib/exec_protos.h you will find this lines:

  AROS_LP2(void, AddTail,
         AROS_LPA(struct List *, list, A0),
         AROS_LPA(struct Node *, node, A1),
         LIBBASETYPEPTR, SysBase, 41, Exec

This means its has 2 parameters (LP2),no return value (void) so its a procedure, the name is AddTail first parameter is a Pointer to a List (Pascal its a PList) with name list and so on. Most important the Library Base (SysBase = ExecBase) and Offset = 41. Now we bring all this together to a small function in pascal:

  procedure AddTail(list: PList; Node: PNode);
    TLocalCall = procedure(List: PList; Node: PNode; LibBase: Pointer); cdecl;
    Call: TLocalCall;
    Call := TLocalCall(GetLibAdress(AOS_ExecBase, 41));
    Call(List, Node, AOS_ExecBase);

Now this Library function can be used all over freepascal.

Take care with other libraries the Base must be open before using, ExecBase is an exception its always open to the program and accessible via AOS_ExecBase