C++将 dll 文件从根文件夹移动到子文件夹
我正在用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决这个问题的方法不止一种。正如其他人提到的,您可以在注册表中修改应用程序的搜索路径。有时,您没有权限写入注册表,或者由于其他原因无法执行此操作,那么您可以显式设置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.听起来您正在寻找 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths 键。请参阅此处了解完整信息。简而言之,名为Path的字符串指向DLL搜索路径。例如,如果您的应用程序名为“MyApp”,则像这样的 .reg 文件就可以解决问题:
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:
我相信这就是您正在寻找的文章:
http://www .codeguru.com/Cpp/WP/dll/article.php/c99
I believe this is the article you are looking for:
http://www.codeguru.com/Cpp/W-P/dll/article.php/c99