The WNDCLASSEX
structure has an hInstance
field.
I have created a DLL which will register a window class (WNDCLASSEX wcex
) and create a window using this class.
Will it be right not to define wcex.hInstance
field (zero it) before calling RegisterClassExW(&wcex)
?
Or I should define it, getting when DLL is loaded?
Yes, you should provide your DLL's HINSTANCE
when registering any window class inside of your DLL. This way, the window manager can differentiate your class name if another DLL or the host EXE happens to register the same name for a different class.
Later, when creating a window, the caller can then specify which HINSTANCE
the deisred class comes from.
Raymond Chen has blogged about this very topic and why it is important:
What is the HINSTANCE passed to CreateWindow and RegisterClass used for?
Using the wrong HINSTANCE in RegisterClass is like identity theft