Difference between revisions of "Hostlib.resource"

From Freepascal Amiga wiki
Jump to: navigation, search
(minor cradle correction)
(the unit: Added unit)
Line 22: Line 22:
  
 
<source lang="pascal">
 
<source lang="pascal">
 +
 +
unit aros_hostlib;
 +
 +
{
 +
  Hostlib.resource
 +
}
 +
 +
interface
 +
 +
uses
 +
  exec;
 +
 
 +
Const
 +
  HOSTLIBNAME      = 'hostlib.resource';
 +
 +
 +
type
 +
  pvoid            = pointer; 
 +
 +
 +
  function  HostLib_Open(const filename: pchar; error: ppchar): pvoid;
 +
  function  HostLib_Close(handle: pvoid; error: ppchar): integer;
 +
  function  HostLib_GetPointer(handle: pvoid; const symbol: pchar; error: ppchar): pvoid;
 +
  procedure HostLib_FreeErrorStr(error: ppchar);
 +
  function  HostLib_GetInterface(handle: pvoid; const symbols: ppchar; unresolved: PULONG): pAPTR;
 +
  procedure HostLib_DropInterface(interface_: pAPTR);
 +
  procedure HostLib_Lock;
 +
  procedure HostLib_Unlock;
 +
 
 +
var
 +
  HostLibBase : pLibrary;
 +
 +
 +
implementation
 +
 +
 +
function HostLib_Open(const filename: pchar; error: ppchar): pvoid;
 +
type
 +
  TLocalCall = function(const filename: pchar; error: ppchar; LibBase: Pointer): pvoid; cdecl;
 +
var
 +
  Call: TLocalCall;
 +
begin
 +
  Call := TLocalCall(GetLibAdress(HostLibBase, 1));
 +
  HostLib_Open := Call(filename, error, HostLibBase);
 +
end;
 +
 +
 +
function  HostLib_Close(handle: pvoid; error: ppchar): integer;
 +
type
 +
  TLocalCall = function(handle: pvoid; error: ppchar; LibBase: Pointer): integer; cdecl;
 +
var
 +
  Call: TLocalCall;
 +
begin
 +
  Call := TLocalCall(GetLibAdress(HostLibBase, 2));
 +
  HostLib_Close := Call(handle, error, HostLibBase);
 +
end;
 +
 +
 +
function  HostLib_GetPointer(handle: pvoid; const symbol: pchar; error: ppchar): pvoid;
 +
type
 +
  TLocalCall = function(handle: pvoid; const symbol: pchar; error: ppchar; LibBase: Pointer): pvoid; cdecl;
 +
var
 +
  Call: TLocalCall;
 +
begin
 +
  Call := TLocalCall(GetLibAdress(HostLibBase, 3));
 +
  HostLib_GetPointer := Call(handle, symbol, error, HostLibBase);
 +
end;
 +
 +
 +
procedure HostLib_FreeErrorStr(error: ppchar);
 +
type
 +
  TLocalCall = procedure(error: ppchar; LibBase: Pointer); cdecl;
 +
var
 +
  Call: TLocalCall;
 +
begin
 +
  Call := TLocalCall(GetLibAdress(HostLibBase, 4));
 +
  Call(error, HostLibBase);
 +
end;
 +
 +
 +
function  HostLib_GetInterface(handle: pvoid; const symbols: ppchar; unresolved: PULONG): pAPTR;
 +
type
 +
  TLocalCall = function(handle: pvoid; const symbols: ppchar; unresolved: pulong; LibBase: Pointer): pAPTR; cdecl;
 +
var
 +
  Call: TLocalCall;
 +
begin
 +
  Call := TLocalCall(GetLibAdress(HostLibBase, 5));
 +
  HostLib_GetInterface := Call(handle, symbols, unresolved, HostLibBase);
 +
end;
 +
 +
 +
procedure HostLib_DropInterface(interface_: pAPTR);
 +
type
 +
  TLocalCall = procedure(interface_: pAPTR; LibBase: Pointer); cdecl;
 +
var
 +
  Call: TLocalCall;
 +
begin
 +
  Call := TLocalCall(GetLibAdress(HostLibBase, 6));
 +
  Call(interface_, HostLibBase);
 +
end;
 +
 +
 +
procedure HostLib_Lock;
 +
type
 +
  TLocalCall = procedure(LibBase: Pointer); cdecl;
 +
var
 +
  Call: TLocalCall;
 +
begin
 +
  Call := TLocalCall(GetLibAdress(HostLibBase, 7));
 +
  Call(HostLibBase);
 +
end;
 +
 +
 +
procedure HostLib_Unlock;
 +
type
 +
  TLocalCall = procedure(LibBase: Pointer); cdecl;
 +
var
 +
  Call: TLocalCall;
 +
begin
 +
  Call := TLocalCall(GetLibAdress(HostLibBase, 8));
 +
  Call(HostLibBase);
 +
end;
 +
 +
Initialization
 +
  HostLibBase := OpenResource(HOSTLIBNAME);
 +
 +
finalization
 +
  // resources do not need to be closed
 +
end.
 
</source>
 
</source>
 +
  
 
=== unit documentation ===
 
=== unit documentation ===

Revision as of 23:44, 20 September 2014

hostlib.resource

[insert background information here]

examples

Example: 1

Example: 2

Example: 3

the unit

unit aros_hostlib;

{
  Hostlib.resource
}

interface

uses
  exec;
  
Const
  HOSTLIBNAME       = 'hostlib.resource';


type
  pvoid             = pointer;  


  function  HostLib_Open(const filename: pchar; error: ppchar): pvoid;
  function  HostLib_Close(handle: pvoid; error: ppchar): integer;
  function  HostLib_GetPointer(handle: pvoid; const symbol: pchar; error: ppchar): pvoid;
  procedure HostLib_FreeErrorStr(error: ppchar);
  function  HostLib_GetInterface(handle: pvoid; const symbols: ppchar; unresolved: PULONG): pAPTR;
  procedure HostLib_DropInterface(interface_: pAPTR);
  procedure HostLib_Lock;
  procedure HostLib_Unlock;
  
var
  HostLibBase : pLibrary;


implementation


function HostLib_Open(const filename: pchar; error: ppchar): pvoid;
type
  TLocalCall = function(const filename: pchar; error: ppchar; LibBase: Pointer): pvoid; cdecl;
var
  Call: TLocalCall;
begin
  Call := TLocalCall(GetLibAdress(HostLibBase, 1));
  HostLib_Open := Call(filename, error, HostLibBase);
end;


function  HostLib_Close(handle: pvoid; error: ppchar): integer;
type
  TLocalCall = function(handle: pvoid; error: ppchar; LibBase: Pointer): integer; cdecl;
var
  Call: TLocalCall;
begin
  Call := TLocalCall(GetLibAdress(HostLibBase, 2));
  HostLib_Close := Call(handle, error, HostLibBase);
end;


function  HostLib_GetPointer(handle: pvoid; const symbol: pchar; error: ppchar): pvoid;
type
  TLocalCall = function(handle: pvoid; const symbol: pchar; error: ppchar; LibBase: Pointer): pvoid; cdecl;
var
  Call: TLocalCall;
begin
  Call := TLocalCall(GetLibAdress(HostLibBase, 3));
  HostLib_GetPointer := Call(handle, symbol, error, HostLibBase);
end;


procedure HostLib_FreeErrorStr(error: ppchar);
type
  TLocalCall = procedure(error: ppchar; LibBase: Pointer); cdecl;
var
  Call: TLocalCall;
begin
  Call := TLocalCall(GetLibAdress(HostLibBase, 4));
  Call(error, HostLibBase);
end;


function  HostLib_GetInterface(handle: pvoid; const symbols: ppchar; unresolved: PULONG): pAPTR;
type
  TLocalCall = function(handle: pvoid; const symbols: ppchar; unresolved: pulong; LibBase: Pointer): pAPTR; cdecl;
var
  Call: TLocalCall;
begin
  Call := TLocalCall(GetLibAdress(HostLibBase, 5));
  HostLib_GetInterface := Call(handle, symbols, unresolved, HostLibBase);
end;


procedure HostLib_DropInterface(interface_: pAPTR);
type
  TLocalCall = procedure(interface_: pAPTR; LibBase: Pointer); cdecl;
var
  Call: TLocalCall;
begin
  Call := TLocalCall(GetLibAdress(HostLibBase, 6));
  Call(interface_, HostLibBase);
end;


procedure HostLib_Lock;
type
  TLocalCall = procedure(LibBase: Pointer); cdecl;
var
  Call: TLocalCall;
begin
  Call := TLocalCall(GetLibAdress(HostLibBase, 7));
  Call(HostLibBase);
end;


procedure HostLib_Unlock;
type
  TLocalCall = procedure(LibBase: Pointer); cdecl;
var
  Call: TLocalCall;
begin
  Call := TLocalCall(GetLibAdress(HostLibBase, 8));
  Call(HostLibBase);
end;

Initialization
  HostLibBase := OpenResource(HOSTLIBNAME);

finalization
  // resources do not need to be closed
end.


unit documentation

[insert unit documentation here]