In order for a module to use a procedure or function that is in a DLL, it must import the procedure or function using andeclaration.
In imported procedures and functions, the external directive takes the place of the declaration and statement parts that would otherwise be present.
Imported procedures and functions behave just like normal ones, except they must use the far call model (use aprocedure directive or a .)
Borland Pascal provides three ways to import procedures and functions:
Although a DLL can have variables, it is not possible to import them in to other modules. Any access to a DLL's variables must take place through a procedural interface.
This external declaration imports the function GlobalAlloc from the DLL called KERNEL (the Windows kernel):
function GlobalAlloc(Flags: Word; Bytes: Longint): THandle; far; external
'KERNEL' index 15;
Note: The DLL name specified after the external keyword and the new name specified in ado not have to be string literals. Any constant string expression is allowed.
Likewise, the ordinal number specified in ancan be any constant-integer expression. For example:
TestLib = 'TESTLIB';
Ordinal = 5;
procedure ImportByName; external TestLib;
procedure ImportByNewName; external TestLib name 'REALNAME';
procedure ImportByOrdinal; external TestLib index Ordinal;
There are two ways to access and call a DLL function.
1. Using an external declaration in your program.
2. Using GetProcAddress to initialize procedure pointers in your program.