I want to write me a small window framework for OpenGL on windows. I know there are a lot of good window libraries but I like to do it myself. But I have a small problem, if I want to create a window with the Win32 API I need the parameters like "hInstance" .... How I get this needed variables in a Window.class ? How the other Window libraries do it ?
Asked
Active
Viewed 6,382 times
5
-
I probably missed the point of the question, but is there something stopping you from requiring the "client" of your library initiate setup steps by *providing* required data, such as the `hInstance` of the module? – WhozCraig Aug 21 '14 at 16:58
-
All the `WinMain` parameters are available without having a `WinMain` -- http://stackoverflow.com/a/25250854/103167 – Ben Voigt Aug 21 '14 at 20:42
1 Answers
6
You can use GetModuleHandle(0);
to get the programs hInstance
. Just passing 0
as the hInstance
parameter worked for me.
"Passing 0 retrieves the handle of the calling process, not the calling module. If the library/framework is implemented as a DLL, you would end up with the wrong handle. Use the handle passed to DllMain()
or DllEntryPoint()
instead. – Remy Lebeau"
-
1Passing 0 retrieves the handle of the calling **process**, not the calling **module**. If the library/framework is implemented as a DLL, you would end up with the wrong handle. Use the handle passed to `DllMain()` or `DllEntryPoint()` instead. – Remy Lebeau Aug 21 '14 at 17:03
-
Saying "worked for me" is kind of pointless when the documentation you link to explains what happens when 0 is passed: *If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process (.exe file).* – chris Aug 21 '14 at 17:08
-
@chris I meant as the hInstance parameter, not as the parameter to `GetModuleHandle`. I edited to make that clear. – nwp Aug 21 '14 at 17:12
-
http://stackoverflow.com/a/11785762/1462718 @OP doesn't mention that they're framework is in a dll. They did not tag dll or dynamic link library either. It's SAFE to assume they are just replacing winmain with main and so `GetModuleHandle(0)` is fine for that purpose. – Brandon Aug 21 '14 at 17:29