9.3 Object Handles

Under Win3, a handle to a window or menu object can be shared among applications and used by any application without having to “open” a reference to the object. To retain these semantics, a “handle” to any USER32 object is in reality an opaque pointer to the object body whose most-significant byte is set to a serial number. Such a handle can then be passed around to any application.

Under USER32, applications are not allowed to indiscriminately use an object, even if they have a handle to that object. For an application to use an object it must “open” a reference to it. The “open” is actually an access check to verify that the application is allowed to use object. If applicable, an object is opened to the application as part of object creation. For applications that get an object handle through other means (window enumeration, messages, dde, etc.), USER32 attempts to open that object the first time the application tries to use it. In this case, access may be denied, which could result in some strange behavior if the application is not prepared for this kind of error.