依赖于其他dll的插件dll。

时间:2022-10-05 14:12:34

I am writing a DLL to plug into another (3rd party) application. The DLL will need to depend on another set of DLLs (for license reasons I cannot link statically).

我正在编写一个DLL来插入另一个(第三方)应用程序。DLL需要依赖于另一组DLL(出于许可原因,我不能静态链接)。

I would like my DLL to be "xcopy-deployable" to any directory. I would also like not to require adding this directory to the path.

我希望我的DLL是“xcopy-deployable”到任何目录。我也不需要将这个目录添加到路径中。

If I just build the DLL the usual way, Windows will refuse to load the DLL, since it cannot find the DLLs next to the current process.

如果我只是按照通常的方式构建DLL, Windows将拒绝加载DLL,因为它无法在当前进程旁边找到DLL。

Are there any good options for helping Windows locate the DLL?

有什么好的选项可以帮助Windows定位DLL?


To answer some questions:

回答一些问题:

  • The DLL is written in C++.
  • DLL是用c++编写的。
  • The extra DLLs are QT-dlls.
  • 额外的dll是qt -dll。
  • I would like to place the extra DLLs in the same folder as my plugin DLL. I can get the name of that folder from GetModuleFileName.
  • 我想把额外的DLL放在与我的插件DLL相同的文件夹中。我可以从GetModuleFileName获得那个文件夹的名称。
  • The application is Firefox, the DLL is a PKCS#11 security module.
  • 应用程序是Firefox, DLL是PKCS#11安全模块。
  • The application loads the DLL using the full path to the DLL (the user supplies it when installing the plugin).
  • 应用程序使用DLL的完整路径加载DLL(用户在安装插件时提供DLL)。
  • Requiring that the DLLs be placed in System32 or next to the application would work, but it is a bit messy and could cause problems with uninstallers.
  • 要求将dll放在System32中或应用程序旁边可以工作,但是这样做有点麻烦,可能会导致卸载程序出现问题。
  • LoadLibrary and GetProcAddress would of course work, but is not really feasible in my case. I am using hundreds, if not thousands, of methods in the other DLLs. I really need to use the import-libraries.
  • LoadLibrary和GetProcAddress当然可以,但是在我的例子中并不可行。我在其他的DLLs中使用了成百上千的方法。我真的需要使用导入库。

I had thought about using delay-loaded dlls combined with SetDllDirectory in DllMain. Have anyone tried anything like this?

我想过在DllMain中使用延迟加载的dll和SetDllDirectory。有人试过这种方法吗?

3 个解决方案

#1


4  

I can think of 3 ways.

我可以想出三种方法。

  1. put the dlls in the same folder as your application (you cannot do this?)
  2. 将dll放在与应用程序相同的文件夹中(您不能这样做吗?)
  3. Use runtime linking. LoadLibrary() and GetProcAddress()
  4. 使用运行时链接。LoadLibrary()和GetProcAddress()
  5. Use a manifest http://msdn.microsoft.com/en-us/library/aa374182(VS.85).aspx
  6. 使用一个清单http://msdn.microsoft.com/en-us/library/aa374182(VS.85). aspx

But if the dll isn't in the same folder as the .exe, how are you going to know where it is? forget Windows not knowing, how do you know?

但是如果dll与.exe不在同一个文件夹中,你怎么知道它在哪里呢?忘记窗户不知道,你怎么知道?

#2


1  

you can specify the path of dll as the parameter of LoadLibrary().

可以将dll的路径指定为LoadLibrary()的参数。

#3


0  

Another option is to modify the PATH variable. Have a batch file for launching the main app, and set the PATH=%PATH%;%~dp0. This ensures a minimal footprint, with no additional traces left in the system after running.

另一个选项是修改PATH变量。为启动主应用程序设置一个批处理文件,并设置路径=%PATH%;%~dp0。这确保了最小的内存占用,在运行后系统中不会留下任何额外的痕迹。

#1


4  

I can think of 3 ways.

我可以想出三种方法。

  1. put the dlls in the same folder as your application (you cannot do this?)
  2. 将dll放在与应用程序相同的文件夹中(您不能这样做吗?)
  3. Use runtime linking. LoadLibrary() and GetProcAddress()
  4. 使用运行时链接。LoadLibrary()和GetProcAddress()
  5. Use a manifest http://msdn.microsoft.com/en-us/library/aa374182(VS.85).aspx
  6. 使用一个清单http://msdn.microsoft.com/en-us/library/aa374182(VS.85). aspx

But if the dll isn't in the same folder as the .exe, how are you going to know where it is? forget Windows not knowing, how do you know?

但是如果dll与.exe不在同一个文件夹中,你怎么知道它在哪里呢?忘记窗户不知道,你怎么知道?

#2


1  

you can specify the path of dll as the parameter of LoadLibrary().

可以将dll的路径指定为LoadLibrary()的参数。

#3


0  

Another option is to modify the PATH variable. Have a batch file for launching the main app, and set the PATH=%PATH%;%~dp0. This ensures a minimal footprint, with no additional traces left in the system after running.

另一个选项是修改PATH变量。为启动主应用程序设置一个批处理文件,并设置路径=%PATH%;%~dp0。这确保了最小的内存占用,在运行后系统中不会留下任何额外的痕迹。