Programming Tips - How can I get the name of the current DLL?

Date: 2012jul25 OS: Windows Platform: win32 Language: C/C++ Q. How can I get the name of the current DLL? A. Call GetModuleFileName() in DllMain() like this:
char szDll[MAX_PATH]; BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID) { switch(fdwReason) { case DLL_PROCESS_ATTACH: GetModuleFileName(hInstDLL, szDll, sizeof(szDll)); break; case DLL_PROCESS_DETACH: break; } return TRUE; }