How to get the filename of a DLL?

半世苍凉 提交于 2020-01-14 08:45:20

问题


I have a C++ Windows application myapp.exe which loads several plug-ins.

Plug-ins need to find the path to their DLLs. I can use GetModuleFileName for this, but it need the handle for the plug-in DLL. I don't know where to get this handle. GetModuleHandle(NULL) returns the handle to the executable.

One option is to use GetModuleHandle (GetModuleHandle("myplugin.dll") ) , but this requires the name of the plugin to be hardcoded which I want to avoid.

Any help is appreciated.

Paul


回答1:


I don't know where to get this handle

It's passed as a parameter to your DLLMain() entry function.

If the plugin can't access its DLLMain() entry function, it can use the VirtualQuery function on a piece of its own memory and use the AllocationBase field of the filled-in MEMORY_BASIC_INFORMATION structure as its HMODULE.



来源:https://stackoverflow.com/questions/846044/how-to-get-the-filename-of-a-dll

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!