C++将 dll 文件从根文件夹移动到子文件夹

发布于 2024-10-16 13:31:47 字数 322 浏览 2 评论 0原文

我正在用 Visual C++ 编写一个程序。该程序依赖于一些dll文件,我不想将其放置在system32中。现在 dll 文件与我的 .exe 位于同一文件夹中,但我想将它们移动到子文件夹中。问题是,如果我移动文件,我的应用程序将无法启动,并出现以下错误消息:


MyProgram.exe - 无法找到组件

此应用程序无法启动,因为找不到 myDll.dll。重新安装应用程序可能会解决该问题。


我以前也遇到过同样的问题,如果找到解决方案,其中包括向注册表添加一些内容,但我忘记了它是如何工作的,现在我再也找不到指南了。

有人可以帮我吗?

I'm making a program in visual c++. The program relies on some dll files, which I don't want to place in system32. Now the dll files is in the same folder as my .exe, but i would like to move them to a sub folder. The problem is, if I move the files, my application fails to start and comes with this error message:


MyProgram.exe - Unable to Locate Component

This application has failed to start because myDll.dll was not found. Re-installing the application may fix the problem.


I have had the same problem before, where if found a solution, which included adding something to the registry, but i forgot how it worked, and now I can't find the guide again.

Can someone please help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

水水月牙 2024-10-23 13:31:47

解决这个问题的方法不止一种。正如其他人提到的,您可以在注册表中修改应用程序的搜索路径。有时,您没有权限写入注册表,或者由于其他原因无法执行此操作,那么您可以显式设置dll路径,WinAPI函数是SetDllDirectory,请参见MSDN

There is more than one way to solve this problem. As other mentioned you can modify search path for your application in registry. Sometimes, you don't have rights to write to the registry, or you cannot do it for other reasons, then you can set dll path explicitly, the WinAPI function for that is SetDllDirectory, see MSDN.

溺渁∝ 2024-10-23 13:31:47

听起来您正在寻找 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths 键。请参阅此处了解完整信息。简而言之,名为Path的字符串指向DLL搜索路径。例如,如果您的应用程序名为“MyApp”,则像这样的 .reg 文件就可以解决问题:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppPaths\MyApp.exe]
@="C:\\Program Files\\MyCompany\\MyApp\\MyApp.exe"
"Path"="C:\\Program Files\\MyCompany\\MyApp\\DLLs"

Sounds like you're after the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths key. See here for complete information. In short, a string called Path points to a DLL search path. For example if your application was called "MyApp" a .reg file like this would do the trick:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppPaths\MyApp.exe]
@="C:\\Program Files\\MyCompany\\MyApp\\MyApp.exe"
"Path"="C:\\Program Files\\MyCompany\\MyApp\\DLLs"
自由如风 2024-10-23 13:31:47

我相信这就是您正在寻找的文章:

http://www .codeguru.com/Cpp/WP/dll/article.php/c99

每个应用程序现在可以将其自己的路径存储在以下注册表项下:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\应用程序路径

使用应用程序路径,使用上面示例中的 ONE.EXE 为您的应用程序设置密钥:

HKEY_LOCAL_MACHINE...\CurrentVersion\App Paths\ONE.exe

将(默认)值设置为可执行文件的完整路径,例如:

C:\Program Files\ONE\ONE.exe

添加名为 Path 的子项

I believe this is the article you are looking for:

http://www.codeguru.com/Cpp/W-P/dll/article.php/c99

Each application can now store it own path the registry under the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

The use the application path, set a key for your application, using ONE.EXE from the example above:

HKEY_LOCAL_MACHINE...\CurrentVersion\App Paths\ONE.exe

Set the (Default) value to the full path of your executable, for example:

C:\Program Files\ONE\ONE.exe

Add a sub-key named Path

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文