I have an MFC DLL that is loaded by a 3rd party application. How can I get the DLL filename from within the code of the DLL? That is, for example, if the DLL’s name is mycode.dll, in code I want to be able to retrieve the string “mycode.dll”.
I should add that if the DLL file name is changed on disk then I would like to get the current name on disk (I don’t mean changed during run-time but changed between invocations of the main program).
My DLL is implemented as a CWinApp class, my code has no explicit DllMain.
You can call
AfxGetStaticModuleStateto get a pointer to anAFX_MODULE_STATEstructure, which has a memberm_lpszCurrentAppNamecontaining the module name (app or DLL depending on where it’s called from).