Difference between revisions of "Call Library"
(Created page with "=== 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 b...") |
(activated syntax highlighting) |
||
Line 4: | Line 4: | ||
first you need the parameter line and the offset of the function in the 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: | both you can find in the includes of AROS for example: Includes/clib/exec_protos.h you will find this lines: | ||
− | + | <source lang="C"> | |
AROS_LP2(void, AddTail, | AROS_LP2(void, AddTail, | ||
AROS_LPA(struct List *, list, A0), | AROS_LPA(struct List *, list, A0), | ||
AROS_LPA(struct Node *, node, A1), | AROS_LPA(struct Node *, node, A1), | ||
LIBBASETYPEPTR, SysBase, 41, Exec | LIBBASETYPEPTR, SysBase, 41, Exec | ||
− | + | </source> | |
This means its has 2 parameters (LP2),no return value (void) so its a procedure, the name is AddTail | 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. | 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. | Most important the Library Base (SysBase = ExecBase) and Offset = 41. | ||
Now we bring all this together to a small function in pascal: | Now we bring all this together to a small function in pascal: | ||
− | + | <source lang="pascal"> | |
procedure AddTail(list: PList; Node: PNode); | procedure AddTail(list: PList; Node: PNode); | ||
type | type | ||
Line 24: | Line 24: | ||
Call(List, Node, AOS_ExecBase); | Call(List, Node, AOS_ExecBase); | ||
end; | end; | ||
− | + | </source> | |
Now this Library function can be used all over freepascal. | 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 | 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 |
Revision as of 17:28, 25 August 2013
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