Final Definition Code in DLL

I move some functions to a common DLL (I want some to be called as a Windows hook).

Actual functions are currently in unit, and happens to be, some initializationand some finalization.

At first I thought about doing a direct conversion from unitto library. So I moved the code initializationbetween the main beginand end.. But then I realized that I have nowhere to move the code finalization. Instead, I have to create and register a special DLL entry point.

My question is. Can I leave unitwith all the features and codes initialization, and finalizationsimply create a plug librarythat usesdevice? whether it will be finalization?

+5
source share
4 answers

The code in the blocks initialization sections in the DLL will execute when the DLL is first loaded into the process. Finalization sections start when the DLL is unloaded from the process.

Eugene is right that you can have a finer-grained control using DLLProc, but this is usually only necessary for stream resources, for example. local stream storage.

, , DLLMain, , , , / , . MSDN , - , . , kernel32. !

, , MSDN DLLMain, , Microsoft DLL.

, MSDN, , , DLL. , DLL. comctl32.dll , . InitCommonControlsEx.

. . , . , / .

, , , .

+8

, .

.

, , .

+4

, DLLMain ( , ..), / . / , DLL . , , DLL / / ( , ).

0

It happened to me. I found out that I have a block, this initialization section, which creates a thread or does some things when the DLL is registered.

I deleted this initialization section and it worked fine.

Since initialization is required for the .exe application, but not for the dll application, there is a variable flag in the system utility called ModuleIsLib just do:

initialization

if not ModuleIsLib then
 begin
// initialization stuff for .exe file
 end;

This can also be done for the finishing section.

hope this helped ..!

0
source

All Articles