> Using DLLs


   Using DLLs

In order for a module to use a procedure or function that is in a DLL, it must import the procedure or function using an external declaration.

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 a far procedure directive or a {$F+} compiler directive.)

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 a name clause do not have to be string literals. Any constant string expression is allowed.

Likewise, the ordinal number specified in an index clause can 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.

See Also

  Writing DLLs
  Import units

 К началу страницы 
Тэги: Libraries DLLs

Код для вставки: :: :: :: ГОСТ ::
Поделиться: //

Хостинг предоставлен компанией "Веб Сервис Центр" при поддержке компании "ДокЛаб"