Global variables in System.pas in applications using DLLs

If Delphi applications use DLLs (also created using Delphi), will there be multiple versions of variables declared in System.pas?

I just read How to determine if I am running as a console application? (Delphi on Win32) , and the commentary explains that there can be several versions, for example System.IsConsole, which have different values ​​- True in EXE and False in DLL (if they were compiled using $ APPTYPE CONSOLE).

But other variables are apparently intended for application scale values, like

MainInstance: LongWord; { Handle of the main(.EXE) HInstance } CPUCount: Integer; { Number of CPU Cores detected } 

How can developers see which values ​​will be assigned at the application level and which variables are modular (and therefore may have different values ​​in DLLs and EXEs)?

Or am I misunderstanding these global variables? For example, the documentation for System.BeginThread says that it sets the global variable System.IsMultiThread - but how can it be a global variable and System.IsConsole?

+4
source share
1 answer

If you do not associate your DLL with RTL.bpl or the user-defined "core" BPL containing the system unit, your DLL will have its own set of global system variables. They are initialized when the DLL loads. CPUCount does not need an EXE to fill it. The DLL populates it, asking Windows about its value. The DLL also has its own IsMultiThread variable (unless you bind your DLL with RTL.bpl ...). That way, your EXE can have multiple threads, and the IsMultiThread variable for the DLL still says False.

+9
source

Source: https://habr.com/ru/post/1368930/


All Articles