Click to See Complete Forum and Search --> : how to retrieve the Handle of a dll from inside the dll when it has no DllMain


subhadas
February 4th, 2009, 04:44 AM
I have created a dll. The dll has no DllMain() function. Now from inside the dll I need to retrieve the handle of the dll. The handle is required to retrieve the name of the dll.

Please suggest how to retrieve the Handle of a dll from inside the dll when it has no DllMain.

ovidiucucu
February 4th, 2009, 06:40 AM
Now from inside the dll I need to retrieve the handle of the dll. The handle is required to retrieve the name of the dll.

If you are inside the dll for sure you know the name of the dll, isn't it?

Igor Vartanov
February 4th, 2009, 09:56 AM
The snippet:
HMODULE GetThisModuleHandle()
{
static MEMORY_BASIC_INFORMATION mbi = { 0 };
HMODULE hModule = NULL;
SIZE_T ret = 0;

ret = VirtualQuery ((LPCVOID) &mbi, &mbi, sizeof (MEMORY_BASIC_INFORMATION));
if (ret)
{
hModule = (HMODULE) mbi.AllocationBase;
}

return hModule;
}

Igor Vartanov
February 5th, 2009, 03:33 AM
If you are inside the dll for sure you know the name of the dll, isn't it?Well, generally speaking yes. But not always, you know, not always for sure. ;)

ovidiucucu
February 5th, 2009, 08:58 AM
Well, generally speaking yes. But not always, you know, not always for sure. ;)
The habitants of delta quadrant use the foot to scratch the head because it's not sure they have a hand. :D
Well, generally speaking, you're right. ;)

Codeplug
February 5th, 2009, 09:00 AM
Other tricks: http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx

gg

Igor Vartanov
February 5th, 2009, 10:50 AM
The habitants of delta quadrant use the foot to scratch the head because it's not sure they have a hand. :D
Well, generally speaking, you're right. ;)Habitant of delta quadrant may discover himself renamed in the morning, so scratching head is the most common technique for a wakeup, you know. ;)