Click to See Complete Forum and Search --> : Getting the name of dll when dll is loaded by an exe


raj_cg
June 16th, 2005, 02:04 AM
Hi,
For one of my application, i need to load the dll's name inside some piece of code in the dll. Based on the dll's name certain actions are performed.

GetModuleFileName gives the name of the exe that loads the dll .... :(
But i need to get the dll's name..

Plz suggest how to do this.
Thanks

pengch
June 16th, 2005, 02:32 AM
Save the hInstance at DllMain.
use the hInstance when you call GetModuleFileName .


HINSTANCE g_hInstance;
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
{
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
g_hInstance = hinstDLL;
return;
...
}


// Get the Dll Name:

GetModuleFileName(g_hInstance, ....);

raj_cg
June 16th, 2005, 03:01 AM
Thanks...it works fine...:)