Difference between revisions of "Call Library"

From Freepascal Amiga wiki
Jump to navigation Jump to search
(activated syntax highlighting)
(Libcall needs update for syscall)
Line 1: Line 1:
 +
{{OldVersion|text=TODO: Syscall should be described here, GetLibAddress should not be used anymore}}
 
=== How to call a library function: ===
 
=== How to call a library function: ===
  

Revision as of 12:45, 22 September 2014

This informations refers to an old version. Needs an update
TODO: Syscall should be described here, GetLibAddress should not be used anymore

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);
  type
    TLocalCall = procedure(List: PList; Node: PNode; LibBase: Pointer); cdecl;
  var
    Call: TLocalCall;
  begin
    Call := TLocalCall(GetLibAdress(AOS_ExecBase, 41));
    Call(List, Node, AOS_ExecBase);
  end;

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