INFO: Uniqueness Values in User and GDI Handles

Last reviewed: January 5, 1998
Article ID: Q94917
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with: - Microsoft Windows NT versions 3.1, 3.5

SUMMARY

Windows NT versions prior to Windows NT 4.0 divide the User and GDI handles into the following two parts:

  • The lower 16-bits is an index into a system table of handle structures, which includes information such as the type of handle (window, menu, cursor, and so forth), as well as a value called the uniqueness.
  • The upper 16-bits contain the same uniqueness value.

MORE INFORMATION

The first time a handle is issued by the system, the uniqueness value is 0 (zero). It is incremented each time the handle is re-used. In Windows NT 3.1, if you pass in a value of 0xFFFF for the uniqueness, the client side (that is, User32.dll) will look up the correct uniqueness value in shared memory and use the correct handle. In Windows NT 3.5, use 0x0000 for the uniqueness value.

This is important because it alleviates potential conflicts with re-used handles. For example, when a window is destroyed, its handle is reused by the system. The uniqueness value prevents an old handle to a destroyed window from being misinterpreted by the system as the handle to a new object, which was given the same handle value.

Windows NT 4.0 no longer uses uniqueness values. All User and GDI handles are unique 32-bit values where the entire value is an index into the system table of handle structures. In the case of 16-bit applications, the Windows On Windows (WOW) subsystem automatically converts the 16-bit handles to 32- bit values and back again.

In Win32s, use 0x0000 in the upper 16 bits for the uniqueness.

Keywords          : UsrMisc
Platform          : winnt
Issue type        : kbinfo


================================================================================


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 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.