GetModuleHandle

Started by
6 comments, last by LessBread 18 years, 11 months ago
Hey, When using GetModuleHandle with NULL as the argument which instance do I recieve? Is it the same one as the one which is parsed to you through WinMain??
Advertisement
if your calling it from an .exe yes, its the same as the one in winmain. If you call it from a DLL you get the main program's instance, not the DLL you call the function from. I could be wrong, but I believe thats correct.
moe.ron
From MSDN:

If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process.
Translate please ;)
Quote:Original post by BRooksWackerman
From MSDN:

If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process.


I'm almost positive it doesn't work like that for DLLs, however. It will return the process that is using the DLL

As for what it means, it means it gets the handle to the .exe, or calling process
moe.ron
The file used to create the calling process is your program (if you're writing an exe) or the program that loaded your dll (if you're writing a dll) - as moeron pointed out. GetModuleHandle(NULL) typically returns the value 0x00400000. This is where the program itself is loaded into the memory address space of the process.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Thx for answering so quickly :D

It means that GetModuleHandle is the one to use together with a window wrapper class ?
It will work. HINSTANCE and HMODULE are the same thing. HINSTANCE is leftover from the dark days of 16 bit Windows.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement