If I have a dll called "foo.dll" and the end user renames it to "bar.dll" and LoadLibrary's it, how can I get the name "bar.dll" from inside my dll?
Is it GetModuleFilename(hModule, buffer); ?
If I have a dll called "foo.dll" and the end user renames it to "bar.dll" and LoadLibrary's it, how can I get the name "bar.dll" from inside my dll?
Is it GetModuleFilename(hModule, buffer); ?
yes, you need to store hModule in DllMain
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (hinstDLL)
{
case DLL_PROCESS_ATTACH:
hModule = hinstDLL
break;
}
}
You need to provide DllMain function, store the module handle you get passed in a static variable, and then use that variable to call GetModuleFilename. You should avoid calling GetModuleFilename (or any other function) in DllMain itself, as Windows is very picky about what you can and can't do in there.