Libraries and System Variables

Several variables declared in the System unit are of special interest to those programming libraries. Use IsLibrary to determine whether code is executing in an application or in a library; IsLibrary is always False in an application and True in a library. During a library's lifetime, Hinstance contains its instance handle. CmdLine is always nil in a library.

The DLLProc variable allows a library to monitor calls that the operating system makes to the library entry point. This feature is normally used only by libraries that support multithreading. DLLProc is available on both Windows and Linux but its use differs on each. On Win32, DLLProc is used in multithreading applications.; on Linux, it is used to determine when your library is being unloaded. You should use finalization sections, rather than exit procedures, for all exit behavior.

To monitor operating-system calls, create a callback procedure that takes a single integer parameterfor example, procedure DLLHandler(Reason: Integer);

and assign the address of the procedure to the DLLProc variable. When the procedure is called, it passes to it one of the following values.

DLL_PROCESS_DETACHIndicates that the library is detaching from the address space of the calling process as a result of a clean exit or a call to FreeLibrary.

DLL_PROCESS_ATTACH Indicates that the library is attaching to the address space of the calling process as the result of a call to LoadLibrary.

DLL_THREAD_ATTACH Indicates that the current process is creating a new thread. DLL_THREAD_DETACH Indicates that a thread is exiting cleanly.

In the body of the procedure, you can specify actions to take depending on which parameter is passed to the procedure.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment