很简单,只需在DllMain中使用GetModuleFileName即可.
代码大致如下:
#define STR_SZ 256
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{

 TCHAR str[STR_SZ]={0};

    switch( fdwReason )
    {
        case DLL_PROCESS_ATTACH:
            GetModuleFileName(hinstDLL, str, STR_SZ);   // hinstDLL就是本DLL的句柄
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
            break;
    }
    return TRUE;
}
然后,str[STR_SZ]中就保存有类似"d:\XXX\xxx.dll",自己从中提取出xxx.dll就行了!

值得注意的是,在DllMain之外以GetModuleFileName(GetModuleHandle(0), str, STR_SZ),可以获得dll被载入的进程的名称,
str[STR_SZ]中有类似"d:\XXX\YYY.exe".