ID: Q109620
1.00 1.10 1.20 1.30 WINDOWS kbprg
The information in this article applies to:
The 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.
One 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
/* 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 KBSubcategory: W32s Additional reference words: 1.00 1.10 1.20 1.30
Keywords : kbWin32s
Version : 1.00 1.10 1.20 1.30
Platform : WINDOWS
Last Reviewed: January 17, 1997