Previous: 2.2.11.2. Using DLL's To the Table of Contents Next: 2.2.11.4. Global variables in DLL's
2.2.11.2. Using DLL's Table of Contents 2.2.11.4. Global variables in DLL's

- 2.2.11.3. -
Table of Contents
2. TMT Pascal Language Description
2.2. Pascal Language Structure
2.2.11. Dynamic-Link Libraries (DLL's)
2.2.11.3. Writing DLL's


2.2.11.3. 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: 2.2.11.2. Using DLL's To the Table of Contents Next: 2.2.11.4. Global variables in DLL's
2.2.11.2. Using DLL's Table of Contents 2.2.11.4. Global variables in DLL's

- 2.2.11.3. -