简体   繁体   English

如何获取DLL的文件名?

[英]How to get the filename of a DLL?

I have a C++ Windows application myapp.exe which loads several plug-ins. 我有一个C ++ Windows应用程序myapp.exe,它加载了几个插件。

Plug-ins need to find the path to their DLLs. 插件需要找到其DLL的路径。 I can use GetModuleFileName for this, but it need the handle for the plug-in DLL. 我可以使用GetModuleFileName,但它需要插件DLL的句柄。 I don't know where to get this handle. 我不知道从哪里得到这个句柄。 GetModuleHandle(NULL) returns the handle to the executable. GetModuleHandle(NULL)返回可执行文件的句柄。

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. 一种选择是使用GetModuleHandle(GetModuleHandle(“myplugin.dll”)),但这需要硬编码插件的名称,我想避免。

Any help is appreciated. 任何帮助表示赞赏。

Paul 保罗

I don't know where to get this handle 我不知道从哪里得到这个句柄

It's passed as a parameter to your DLLMain() entry function. 它作为参数传递给您的DLLMain()入口函数。

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. 如果插件无法访问其DLLMain()入口函数,它可以在自己的一块内存上使用VirtualQuery函数,并使用填充的MEMORY_BASIC_INFORMATION结构的AllocationBase字段作为其HMODULE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM