Microsoft KB Archive/109620

From BetaArchive Wiki

Creating Instance Data in a Win32s DLL

Q109620



The information in this article applies to:


  • Microsoft Win32s versions 1.0, 1.1, 1.2, 1.3





SUMMARY

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[ASCII 146]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 INFORMATION

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:

Q109619 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;
} 

Additional query words: 1.00 1.10 1.20

Keywords : kbOSWin32s
Issue type :
Technology : kbWin32sSearch kbWin32s100 kbWin32s110 kbWin32s120 kbWin32s130


Last Reviewed: January 16, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.