How to use a dll outside of the system path

僤鯓⒐⒋嵵緔 提交于 2019-12-28 05:33:07

问题


I made an application that uses the openssl dlls (libeay32.dll and ssleay32.dll). It is indy using them, I don't call the dlls directly.

The simplest workaround i found to avoid an installer (i just delpoy an exe and i am ok with this approach) is to:

  1. put the dlls as resources of the exe
  2. on program start I extract them in the exe folder
  3. the exe uses them

This is perfect but I would like to improve the approach by extracting the dlls in a temp folder and not on the exe folder (that in many cases is the desktop).

The problem is that I don't know how to force the application to use the dlls in the temp folder, because now the behaviour is: if dlls are not in current directory try to search in the directories defined in the system path.

Who knows a solution to force indy to use the dlls in my temp path? (like "temporarly registering the dlls")


回答1:


Load the DLLs yourself with LoadLibrary as soon as you have written them to the temp folder.
This will make Indy's LoadLibrary use your DLLs when they need them:

If lpFileName does not include a path and there is more than one loaded module with the same base name and extension, the function returns a handle to the module that was loaded first.




回答2:


If you are using an up-to-date version of Indy 10, the IdSSLOpenSSLHeaders unit has a public IdOpenSSLSetLibPath() function to tell Indy which custom folder to look in for the OpenSSL DLLs:

procedure IdOpenSSLSetLibPath(const APath: String);



回答3:


You can use SetDllDirectory to manipulate the DLL search order.



来源:https://stackoverflow.com/questions/13269169/how-to-use-a-dll-outside-of-the-system-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!