强制从给定目录静态加载 dll
在我们的应用程序中,我们动态加载一个 dll 文件,该文件又静态绑定到其他 dll。
到目前为止,所有这些 dll 都位于我们的应用程序文件夹中。从现在开始,我们要将这些 dll 移动到目录结构中。 dll应该从哪个文件夹加载是在运行时决定的。 (版本控制/动态更新...)
问题 1:强制动态加载库在给定文件夹中查找静态加载库的最佳方法是什么?
问题 2:如果旧版本的库遗留在应用程序文件夹中,我们如何防止它从应用程序文件夹加载静态库?
(顺便说一句,这是一个 win32 应用程序...)
In our application, we dynamically load a dll file, which again has static bindings to other dlls.
Until now, all this dlls have been in our application folder. From now on, we want to move these dlls into a directory structure. Which folder the dll should be loaded from is to be decided at runtime. (versioning / dynamic updates...)
Question 1: What is the best way of forcing the dynamically loaded library to look for static loaded libraries in a given folder?
Question 2: How can we prevent that it loads the static libraries from the application folder if a older version of the libraries is left behind there?
(btw, it's a win32 application...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于第一季度,您应该查看
SetDllDirectory
。它会影响所有后续的 DLL 搜索,但应用程序文件夹中的 DLL(例如旧的 DLL)仍然优先。问题 2 立即得到解答:如果您不希望这样,请不要使用隐式 DLL 加载。使用
LoadLibraryEx
,并使用完整路径。这是阻止 Windows 搜索的唯一方法。For Q1 you should be looking into
SetDllDirectory
. It affects all subsequent DLL searches, with the proviso that DLLs in the application folder (such as your old DLLs) still take precedence.Question 2 is then immediately answered: if you don't want that, don't use implicit DLL loading. Use
LoadLibraryEx
, and use a full path. That's the only way to prevent Windows from searching.