Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə210/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   206   207   208   209   210   211   212   213   ...   294
DelphiLanguageGuide

Library Initialization Code
The statements in a library's block constitute the library's initialization code. These statements are executed once
every time the library is loaded. They typically perform tasks like registering window classes and initializing variables.
Library initialization code can also install an entry point procedure using the 
DllProc
 variable. The 
DllProc
variable is similar to an exit procedure, which is described in Exit procedures; the entry point procedure executes
when the library is loaded or unloaded.
Library initialization code can signal an error by setting the 
ExitCode
 variable to a nonzero value. ExitCode is
declared in the 
System
 unit and defaults to zero, indicating successful initialization. If a library's initialization code
sets 
ExitCode
 to another value, the library is unloaded and the calling application is notified of the failure. Similarly,
if an unhandled exception occurs during execution of the initialization code, the calling application is notified of a
failure to load the library.
Here is an example of a library with initialization code and an entry point procedure.
library Test;
var
 SaveDllProc: Pointer;
 procedure LibExit(Reason: Integer);
begin
 if Reason = DLL_PROCESS_DETACH then
  begin
    .
                .   // library exit code
                . 
  end;
   SaveDllProc(Reason);        // call saved entry point procedure
  end;
 begin
    .
                .              // library initialization code
                .
  SaveDllProc := DllProc;        // save exit procedure chain
  DllProc := @LibExit;        // install LibExit exit procedure
 end.
183


DllProc
 is called when the library is first loaded into memory, when a thread starts or stops, or when the library is
unloaded. The initialization parts of all units used by a library are executed before the library's initialization code,
and the finalization parts of those units are executed after the library's entry point procedure.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   206   207   208   209   210   211   212   213   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin