1.2.3 How Windows Determines the Owner of a Class

Windows determines class ownership from the hInstance field of the WNDCLASS structure passed to the RegisterClass function when the application or library registers the class. For Windows libraries, this must be the instance handle of the library. When the application that registered the class terminates or the library that registered the class is unloaded, the class is destroyed. For this reason, all windows using the class must be destroyed before the application or library terminates.