How can I register a window class in my DLL so that the window class can be used in the EXE program?
From this:
hInstance (Type: HINSTANCE): A handle to the instance that contains the window procedure for the class.
And also this:
The system passes an instance handle to the entry-point function of each executable (see WinMain) and .dll (see DllMain). The executable or .dll assigns this instance handle to the class by copying it to the hInstance member of the WNDCLASSEX structure.
I should set the hInstance member of WNDCLASS to my DLL instance handle.
But according to this
The class name can be any name registered with RegisterClass or RegisterClassEx, provided that the module that registers the class is also the module that creates the window.
So because my DLL registers the window class (regardless of the value of hInstance member of WNDCLASS?) only my own DLL can create a window from that window class?
So how can this be accomplished?
The usual answer is to have a function in your DLL that registers the window classes, just as InitCommonControls from Comctl32.dll does for the common controls. That function will use the HINSTANCE passed to the library's DllMain as the HINSTANCE in WNDCLASS/WNDCLASSEX.
When the loading application wishes to create a window it will use the HINSTANCE returned by LoadLibrary as the HINSTANCE parameter to CreateWindow/CreateWindowEx. It is assumed that the class name is already shared between the application and library code (again just as the control names are shared between Comctl32.dll and any using code).