- Instance Handle of a DLL
- Posted by Spikinsson on July 17th, 2003
My question is very simple, how do I get the instance handle (HINSTANCE) of the currently
running DLL. In an exe I would just get the hInstance parameter from:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int
nCmdShow);
But a DLL only has this:
bool WINAPI DllMain ( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved );
Now how do I get the hInstance of this DLL? Do I have to use the hModule to retreive the
hInstance with some API function? I really have no clue, any help is greatly
appreciated...
- Posted by Jakob Bieling on July 17th, 2003
"Spikinsson" <not@gonna.tell.ya> wrote in message
news:f7BRa.16417$F92.1930@afrodite.telenet-ops.be...
As far as I know, the hModule can be ued whenever a hInstance is
requested. Though I remember someone saying, that even though you can do
that, you cannot say they are 'the same'. But I neither remember who said
it, nor whether I just dreamt this.
hth
--
jb
(replace y with x if you want to reply by e-mail)
- Posted by Tim Robinson on July 17th, 2003
"Jakob Bieling" <netsurf@gmy.net> wrote in message
news:bf6ne0$8tn$04$1@news.t-online.com...
In Win32 they are the same. They are both the base address of that EXE or
DLL.
--
Tim Robinson (MVP, Windows SDK)
http://www.themobius.co.uk/
- Posted by Spikinsson on July 17th, 2003
"Tim Robinson" <tim.at.gaat.freeserve.co.uk@invalid.com> schreef in bericht
news:bf6qes$bugrj$1@ID-103400.news.uni-berlin.de...
Ok thanks guys!
- Posted by Jochen Kalmbach on July 18th, 2003
Tim Robinson wrote:
it is right that you can use hModule as hInstance...
But, you cannot say that this address is the base address of the DLL.. This
is only true while calling DllMain. After this the base address might
change due to collisions with other DLLs (also called relocation)... So be
sure you use the value given in DllMain!
--
Greetings
Jochen
Do you need a memory-leak finder ?
http://www.codeproject.com/useritems/leakfinder.asp