DLL依赖问题/ SetDLLDirectory [英] DLL dependency question / SetDLLDirectory

查看:4171
本文介绍了DLL依赖问题/ SetDLLDirectory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况,无法找到任何好的解决方案。

I have the following situation and can't come up with any good solution.

我有一个C ++应用程序(app.exe)安装在C:\ ProgFiles\ MyApp。它需要一堆DLL,我安装在C:\ProgFiles\MyApp \bin。我想将它们放在一个子文件夹中,因为有这么多。

I have a C++ application (app.exe) installed in C:\ProgFiles\MyApp. It needs a bunch of DLLs, which I install in C:\ProgFiles\MyApp\bin. I'd like to put them in a subfolder because there are so many of them.

现在当我启动app.exe时,需要让Windows知道所需的DLL是。在过去,我使用PATH环境变量为此,但我不能这样做,因为我将创建另一个应用程序与单独的安装程序,它使用许多相同的名称的DLL。

Now when I start app.exe, something needs to let Windows know where the required DLLs are. In the past I was using the PATH environment variable for this, but I can't do this anymore because I will create another application with a separate installer, which uses many of the DLLs that have the same name.

我想在应用程序开头调用SetDLLDirectory - 但是我忘记了因为所需的DLLs缺失,它在失败之前到达那里。

I was thinking of calling SetDLLDirectory at the beginning of the app - but I forgot that because required DLLs are missing, it fails before getting there.

有任何建议吗?

推荐答案

查看来自Microsoft的本文,其中讨论了DLL搜索路径和相关问题。

See this article from Microsoft which discusses the DLL search path and related issues.

如果您不将它们放在应用程序的目录中,当前目录优先,这是一个安全漏洞。

In particular, notice that if you do not put them in your app’s directory the current directory takes precedence, which is a security hole.

一个解决方案是使用 LoadLibrary (具有完全限定路径),然后 GetProcAddress

One solution would be to use LoadLibrary (with a fully-qualified path), then GetProcAddress. That would be kind of painful.

没有正常的用户会在 C:\Program Files\YourApp 这是你应该把它们,除非你有一个很好的理由不。

No normal user is going to go digging around in C:\Program Files\YourApp and that is where you should put them unless you have a good reason not to.

这篇关于DLL依赖问题/ SetDLLDirectory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆