问题描述
我正在编写一个DLL来插入另一个(第三方)应用程序。该DLL将需要依赖于另一组DLL(由于许可证原因,我无法静态链接)。我希望我的DLL是xcopy可部署到任何目录。我也不想要将该目录添加到路径。
如果我只是通常的方式构建DLL,Windows将拒绝加载DLL,因为它不能找到当前进程旁边的DLL。
帮助Windows找到DLL有什么好的选择吗?
要回答一些问题:
- DLL是用C ++编写的。
- 额外的DLL是QT-dll。
- 我想将额外的DLL放在与我的插件DLL相同的文件夹中。我可以从
GetModuleFileName
获取该文件夹的名称。 - 该应用程序是Firefox,该DLL是PKCS#11安全模块。
- 应用程序使用DLL的完整路径加载DLL(用户在安装插件时提供此功能)。
- 要求DLL为放置在System32或应用程序旁边的工作将会起作用,但是它有点混乱,可能会导致卸载程序出现问题。
-
LoadLibrary
GetProcAddress
当然可以工作,但在我的情况下并不真正可行。我在其他DLL中使用数百种(如果不是数千种)方法。我真的需要使用import-libraries。
我曾考虑过使用延迟加载的dll与 in DllMain的。有人试过这样的东西吗?
我可以想到3种方法。
- 将dll放在与应用程序相同的文件夹中(您不能这样做?)
- 使用运行时链接。
LoadLibrary()
和GetProcAddress()
- 使用清单
但是如果dll与.exe不在同一个文件夹中你怎么知道它在哪里?忘记Windows不知道,你怎么样知道?
I am writing a DLL to plug into another (3rd party) application. The DLL will need to depend on another set of DLLs (for license reasons I cannot link statically).
I would like my DLL to be "xcopy-deployable" to any directory. I would also like not to require adding this directory to the path.
If I just build the DLL the usual way, Windows will refuse to load the DLL, since it cannot find the DLLs next to the current process.
Are there any good options for helping Windows locate the DLL?
To answer some questions:
- The DLL is written in C++.
- The extra DLLs are QT-dlls.
- I would like to place the extra DLLs in the same folder as my plugin DLL. I can get the name of that folder from
GetModuleFileName
. - The application is Firefox, the DLL is a PKCS#11 security module.
- The application loads the DLL using the full path to the DLL (the user supplies it when installing the plugin).
- Requiring that the DLLs be placed in System32 or next to the application would work, but it is a bit messy and could cause problems with uninstallers.
LoadLibrary
andGetProcAddress
would of course work, but is not really feasible in my case. I am using hundreds, if not thousands, of methods in the other DLLs. I really need to use the import-libraries.
I had thought about using delay-loaded dlls combined with SetDllDirectory
in DllMain. Have anyone tried anything like this?
I can think of 3 ways.
- put the dlls in the same folder as your application (you cannot do this?)
- Use runtime linking.
LoadLibrary()
andGetProcAddress()
- Use a manifest http://msdn.microsoft.com/en-us/library/aa374182(VS.85).aspx
But if the dll isn't in the same folder as the .exe, how are you going to know where it is? forget Windows not knowing, how do you know?
这篇关于插件DLL依赖于其他DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!