Article ID: 109619 - Last Review: March 1, 2005 - Revision: 3.4 How To Share All Data in a DLL
This article was previously published under Q109619 SUMMARY
Win32 dynamic-link libraries (DLLs) use instance data by default, meaning that each application that uses a DLL gets its own copy of the DLL's
data. However, it is possible to share the DLL data among all applications that use the DLL.
If you need to share only some of the DLL data, Microsoft recommends creating a new section and sharing it instead. If you want to share all of the DLL static data, it is important to do two things:
The system tries to load the shared memory block at the same address in each process. However, if the block cannot be loaded into the same memory address, the system maps the shared section into a different memory address. The memory is still shared. Note that the pointers inside the shared section are invalid under this circumstance and cannot be placed in shared sections. MORE INFORMATION
The C run-time uses global variables. If the CRT is statically linked to
the DLL, these variables will be shared among all clients of the DLL and
will most likely cause an exception c0000005.
You need to specify both .data and .bss as shared because they each hold different types of data. The .data section holds initialized data and the .bss section holds the uninitialized data. One reason for sharing all data in a DLL is to have consistent behavior in the DLL between Win32 (running on Windows NT) and Win32s (running on Windows 3.1). When running on Win32s, a 32-bit DLL shares its data among all of the processes that use the DLL. Note that it is not necessary to share all data to behave identically between Win32 and Win32s. The DLL can use thread local storage (TLS) on Win32s to store variables as instance data. For additional information, please see the following article in the Microsoft Knowledge Base: 109620
(http://support.microsoft.com/kb/109620/EN-US/
)
Creating Instance Data in a Win32s DLL
APPLIES TO
| Other Resources Other Support Sites
CommunityArticle Translations |






Windows Live
Facebook
Twitter
Linkedin
Digg it
Yahoo
Delicious
StumbleUpon
Yammer
Reddit
Technorati
FriendFeed
Email
Back to the top