Previous: Using DLL's To the Table of Content Next: Global variables in DLL's

- 2.2.11.3 -
TMT Pascal Language Description
Pascal Language Structure
Dynamic-Link Libraries (DLL's)

Writing DLL's

Targets: OS/2, Win32


The structure of a TMT Pascal DLL is identical to that of a program, except that a DLL starts with a library header (Library) instead of a program header (Program).

All procedures and functions which to be exported by a DLL, must be compiled with the export procedure directive.

If you want your DLL to be available to applications written in other languages, it’s safest to specify arg_stdcall calling convention in the declarations of exported functions. Other languages may not support TMT Pascal’s default register calling convention.

Example:
// This implements a very simple DLL
// with two exported functions:

library ARCs;

// The export procedure directive prepares ArcCos
// and ArcSin for exporting

uses Math;

{$ifdef __WIN32__}
  function ArcCos conv  arg_stdcall (X: Extended): Extended;
{$else}
  function ArcCos conv arg_os2 (X: Extended): Extended;
{$endif}

begin
  Result := RadToDeg(ArcTan2(Sqrt(1 - X * X), X));
end;

{$ifdef __WIN32__}
  function ArcSin conv arg_stdcall ( X: Extended): Extended;
{$else}
  function ArcSin conv arg_os2 ( X: Extended): Extended;
{$endif}

begin
  Result := RadToDeg(ArcTan2(X, Sqrt(1 - X * X)));
end;

// The exports clause actually exports the two routines,
// supplying an optional ordinal number for each of them

exports

  ArcCos name 'ArcCos',  // export by name
  ArcSin index 1;        // export by index

begin
  // Do nothing
end.



Previous: Using DLL's To the Table of Content Next: Global variables in DLL's
Using DLL's Table of Content Global variables in DLL's

- 2.2.11.3 -