MFC应用程序中dll的Saparate文件夹 [英] Saparate folder for dll in mfc application

查看:75
本文介绍了MFC应用程序中dll的Saparate文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绞尽脑汁,想出一个优雅的解决DLL加载问题的方法.我有一个静态链接到其他加载DLL的lib文件的应用程序.我没有直接加载DLL.我确实想在可执行文件所在的文件夹之外的其他文件夹中有一些DLL.类似%working_folder%\ dlls的东西-我宁可在我的%working_folder%中也没有很多(是……很多)DLL. br/>
我正在尝试开发一些主要应用程序,该应用程序将在启动时调整搜索路径.我遇到的问题是系统搜索路径中没有这个新的自定义DLL路径.当我启动应用程序时,它崩溃了(STATUS_DLL_NOT_FOUND),因为所需的DLL不在适当的位置.我想做的就是检查@start,如果这个新的自定义DLL文件夹在进程环境变量搜索路径中,如果没有,请添加它.问题是,应用程序在执行一行代码之前尝试加载所有这些DLL.

我该如何解决?我已经考虑过编写一个帮助应用程序,该应用程序首先启动,适当地调整环境变量,然后通过CreateProcess启动主应用程序.我确信这将起作用,但是这会使开发人员感到困难.当他们调试主应用程序时,他们不会首先启动助手应用程序-并不是说他们可以做到这一点.

有关更多信息,请参阅我尚未解决的普遍问题
Dll实现

:doh::doh:

I am racking my brain trying to come up with an elegant solution to a DLL load problem. I have an application that statically links to other lib files which load DLLs. I am not loading the DLLs directly. I did like to have some DLLs in another folder other than the folder that the executable is in. Something like %working_folder%\dlls - I did rather not have dozens (yes ... dozens) of DLLs in my %working_folder%.

I am trying to develop something that is part of the main app that will adjust the search path @ startup. The problem i am running into is that this new custom DLL path isnt in the system search path. When I start the app it crashes (STATUS_DLL_NOT_FOUND) because the necessary DLLs are not in the appropriate places. What I did like to do is to check @ startup if this new custom DLL folder is in the process environment variable search path and if not add it. Problem is, the application attempts to load all these DLLs before the app executes one line of code.

How do I fix this? I have considered writing a help app that starts first, adjusts the environment variables appropriately and the launches the main app via CreateProcess. This will work I am sure of it but it makes things difficult on the developers. When they debug the main app they are not going to launch a helper app first - not that they could even do that.

for more information please refer my unsolved prevous question
Dll implementation

:doh: :doh:

推荐答案

santoshmaruti写道:
santoshmaruti wrote:

我考虑过写作一个先启动的帮助应用程序,适当调整环境变量,然后通过CreateProcess启动主应用程序.

I have considered writing a help app that starts first, adjusts the environment variables appropriately and the launches the main app via CreateProcess.


我认为您可以利用链接器对延迟加载的DLL的支持,在应用程序本身中嵌入类似的机制 [ ^ ].
请注意,这只是一个假设,我尚未对其进行检验.
:)


I think you may embed a similar mechanism inside the application itself, exploiting the Linker Support for Delay-Loaded DLLs[^].
Please note it''s just an hypothesis, I haven''t tested it.
:)


我在您以前的帖子中添加了新答案:
从子项目中分离输出DLL的文件夹 [ ^ ]
I added a new answer to your previous post:
Separate folder for output DLLs from subprojects[^]


我只想在应用程序启动之前停止加载dll.
CPallini
提供的链接 帮助我完成这项任务.链接器输入的延迟加载选项提供了在应用程序启动之前停止dll加载的功能.
因此,当它调用Loadlibrary(DLLNAME)函数时,便会加载dll.

现在,在加载dll之前更改applcation文件夹非常容易

所谓的

SetCurrentDirectory(DLLFILE PATH)函数更改应用路径.

现在,dll从用户定义路径调用了load.

就像下面的外套:
如果myApplication文件夹为C:\\ DLLTRIAL \\

I just want to stop loading of dll before application start.
a link given by CPallini
help me to get this task. A Delay load option of linker input provide facility to stop dll loading before application start.
so now dlls are load when it called Loadlibrary(DLLNAME) function.

its now so easy to change applcation folder before dlls are load

so called of

SetCurrentDirectory(DLLFILE PATH) function change applcation path.

now dll called load from user define path.

like following coad:
if myApplication folder is C:\\DLLTRIAL\\

<pre>void CMainFrame::OnOk()<br />
{<br />
   SetCurrentDirecory("C:\\DLLTRIAL\\MYDLL\\"");<br />
   HINSANCE TempHandle;<br />
   TempHandle=AfxLoadLibrary("Test.dll");<br />
   if(TempHandle!=NULL)<br />
   {<br />
      ShowDialog();         ////Dll function called<br />
   }<br />
   else<br />
   { <br />
      AfxMessageBox("failed to load dll");<br />
   }<br />
}</pre>


动态应用Dll加载

请点击以下链接
延迟加载


感谢所有评论我的问题的读者提供了如此好的答案
:-D :-D:rolleyes::rolleyes::-\:cool:


to applied Dll loading dynamically

please click following link
DELAY LOAD


Thank all readers that review my question provide such good answers
:-D :-D :rolleyes: :rolleyes: :-\ :cool:


这篇关于MFC应用程序中dll的Saparate文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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