Previous: 6.8. Application Entry-Point Function To the Table of Contents Next: 6.10. Using Dinamic-Link Libraries (DLLs)
6.8. Application Entry-Point Function Table of Contents 6.10. Using Dinamic-Link Libraries (DLLs)

- 6.9. -
Table of Contents
6. Win32 Programming
6.9. Writing Dinamic-Link Libraries (DLLs)


6.9. Writing Dinamic-Link Libraries (DLLs)


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: 6.8. Application Entry-Point Function To the Table of Contents Next: 6.10. Using Dinamic-Link Libraries (DLLs)
6.8. Application Entry-Point Function Table of Contents 6.10. Using Dinamic-Link Libraries (DLLs)

- 6.9. -