Creating Instance Data in a Win32s DLLLast reviewed: January 15, 1997Article ID: Q109620 |
The information in this article applies to:
SUMMARYThe Win32 dynamic-link libraries (DLLs) that are running on Win32s use shared data by default. This means that any global data in the DLL is shared by all processes that use the DLL. Thread local storage (TLS) can be used to create instance data; that is, data in the DLL that is specific to each process. The Win32s "Programmer s Reference" mentions that TLS can be used to create instance data, but provides no details. The sample code below shows the source for a DLL that uses instance data on both Win32 and Win32s. The sample code was built using Microsoft Visual C++, 32-bit edition. If you use a development environment that does not have similar support for TLS, you should still be able to use the API (application programming interface) calls. The API calls for TLS are TlsAlloc, TlsGetValue, TlsSetValue, and TlsFree.
MORE INFORMATIONOne reason for wanting to create instance data on Win32s is to create a DLL that behaves identically on Win32s and Win32 (although it introduces extra overhead on Windows NT and Windows 95). Another way to create a DLL that behaves identically on Win32s and Win32 is to share all of the data in the Win32-based DLL. For additional information, please see the following article(s) in the Microsoft Knowledge Base:
ARTICLE-ID: Q109619 TITLE : Sharing All Data in a DLL Sample Code
/* Compile options used: /LD /MD */ int __declspec(thread) nVar = 0; // Variables should be initialized int __declspec(dllexport) GetVar(){ return nVar;}
void __declspec(dllexport) SetVar(int nNew){ nVar = nNew;}
|
KBCategory: kbprg
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |