A Windows desktop application is passed its HINSTANCE as a parameter to the WinMain function. This HINSTANCE would be saved in the global hInst variable when the application starts running and it would then be available to the CreateWindowEx function.
Child windows example code problem
Adam Berridge
21
Reputation points
In https://learn.microsoft.com/en-us/windows/win32/winmsg/using-windows the example code creating three child windows has hinst passed as a parameter of CreateWindowEx but where did this come from? It isn't a parameter of the containing function or defined within it's scope.
Windows development | Windows API - Win32
Answer accepted by question author
Answer accepted by question author
3 additional answers
Sort by: Most helpful
-
Castorix31 91,866 Reputation points2020-12-29T14:47:14.743+00:00 hInst is from WinMain, like :
HINSTANCE hInst; int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { hInst = hInstance; // ... -
Adam Berridge 21 Reputation points
2020-12-29T14:58:40.267+00:00 OK, but this isn't clear in the example.
-
Adam Berridge 21 Reputation points
2020-12-29T14:50:04.197+00:00 Except that the call to CreateWindowEx in the example is in the message callback function, not WinMain.