Importing Functions from Libraries To import routines from a dynamically loadable library (.DLL), attach a directive of the form
external
stringConstant;
to the end of a normal procedure or function header, where stringConstant is the name of the library file in single
quotation marks. For example, on Win32
function SomeFunction(S: string): string; external 'strlib.dll';
imports a function called
SomeFunction
from strlib.dll.
You can import a routine under a different name from the one it has in the library. If you do this, specify the original
name in the external directive:
external
stringConstant1namestringConstant2; where the first stringConstant gives the name of the library file and the second stringConstant is the routine's original
name.
The following declaration imports a function from user32.dll (part of the Win32 API).
function MessageBox(HWnd: Integer; Text, Caption: PChar; Flags: Integer): Integer; stdcall;
external 'user32.dll' name 'MessageBoxA';
The function's original name is
MessageBoxA
, but it is imported as
MessageBox
.
Instead of a name, you can use a number to identify the routine you want to import:
externalstringConstantindexintegerConstant; where integerConstant is the routine's index in the export table.
In your importing declaration, be sure to match the exact spelling and case of the routine's name. Later, when you
call the imported routine, the name is case-insensitive.