Creating Instance Data in a Win32s DLL

Last reviewed: January 15, 1997
Article ID: 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 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:

   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
KBSubcategory: W32s
Additional reference words: 1.00 1.10 1.20 1.30


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 15, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.