Most DLLs will contain some data. Whereas DLL code is shared by all processes that use it, DLL data can be shared or not shared by all processes that use it. Data that is specific to each process that uses the DLL (that is, to each instance of the DLL) is called instance data. Data that is shared by all processes that use the DLL is called shared or global data.
The first time a process references a DLL (and it is loaded or its usage count is incremented because it is already loaded), a separate copy of the DLL's instance data is created. Modifications to the instance data for one process do not affect the instance data for any other process. The system, however, maintains only one copy of a DLL's shared data for all processes that use the DLL. Every process that uses the DLL can access the same data. If one process modifies the data (increments a count, for example), the data will be modified for all processes that use the DLL.
Because changes to shared DLL data by one process are visible to the DLL code when called by another process, shared data provides DLLs with a mechanism for tracking processes that use it. This is crucial to subsystems, which are DLLs that manage resources (for example, devices, queues, and so forth).
There usually is only one data and one code object, or segment, defined in a C source file. This means that a DLL that has instance and shared data is built from more than one C source file, with a default automatic data segment and with named data segments. How data is defined is determined by how the DLL is built. A DLL is built like an application, using a DEF file. The DATA statement in a DEF file describes the attributes of application or DLL data. Following is a list of the available options for the DATA statement:
Options
ÚÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄ¿³ Process A ³ ³ Process B ³ ÀÄÄÂÄÄÄÄÄÂÄÄÙ ÀÄÄÂÄÄÄÄÄÂÄÄÙ ³ ³ ³ ³ ³ ³ ³ ³ ÚÄÄÅÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÅÄÄ¿ ³ ³ ³ Dynamic Link ³ ³ ³ ³ ³ ³ Functions ³ ³ ³ ÀÄÄÅÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÅÄÄÙ ³ ³ ³ ³ ³ ³ ÚÄÄÄÄÄÄÄ¿ ³ ³ ³ ³ ³Shared ³ ³ ³ ³ ÀÄÄÄÄij Data ³ÄÄÄÄÄÄÄÄÄÙ ³ ³ ÀÄÄÄÄÄÄÄÙ ³ ³ ÚÄÄÄÄÄÄÄÄÄ¿ ³ ³ ³Process B³ ³ ³ ÚÄÁÄÄÄÄÄÄÄ¿ ³ÄÄÄÄÄÄÄÄÄÄÄÙ ³ ³Process A³ ³ ÀÄÄÄÄÄÄÄÄÄÄijInstance ÃÄÙ ³ Data ³ ÀÄÄÄÄÄÄÄÄÄÙ
DLL Data
You also can create a DLL with both shared and instance data. For more information, see Using Shared and Instance Data