The external directive

The external directive specifies that the function or procedure being declared is located outside of the program, and the function or procedure body is omitted from the declaraion. Currently the only external functions and procedures supported are functions and procedures located in Windows DLLs.

Example

The following external function declaration is taken from the winuser.inc include file, and declares the Windows MessageBox function.

   function MessageBox(hWnd : _HWND; lpText, lpCaption : LPSTR; uType : UINT) : integer;
      external dll='user32.dll' name='MessageBoxA' stdcall;

Syntax

The syntax for declaring external functions and procedures is given below (NOTE: for clarity some parts of the syntax are omitted, see Irie Pascal Grammar for the full syntax):

   function-declaration = function-heading ';' external-directive

   procedure-declaration = procedure-heading ';' external-directive

   dllname = string-literal

   external-directive = 'external' 'dll' '=' dllname [ 'name' '=' name ] [ 'stdcall' | 'cdecl' ]

   function-heading = 'function' identifier [ formal-parameter-list ] ':' result-type

   name = identifier

   procedure-heading = 'procedure' identifier [ formal-parameter-list ]

   result-type = type-identifier

dllname is a string literal that is the name of the Windows DLL to call.

name is the name of the function or procedure in the DLL. If name is not specified then the name of the function or procedure in the DLL is assumed to be the same as the name of the function or procedure in the declaration.

stdcall specifies that the stdcall calling convention should be used (This is the default).

cdecl specifies that the cdecl calling convention should be used.