Plugin DLLs that depend on other DLLs

2019-02-16 18:24发布

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).

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.

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.

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


To answer some questions:

  • The DLL is written in C++.
  • The extra DLLs are QT-dlls.
  • 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.
  • The application is Firefox, the DLL is a PKCS#11 security module.
  • The application loads the DLL using the full path to the DLL (the user supplies it when installing the plugin).
  • 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.
  • 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.

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

3条回答
劫难
2楼-- · 2019-02-16 19:07

I can think of 3 ways.

  1. put the dlls in the same folder as your application (you cannot do this?)
  2. Use runtime linking. LoadLibrary() and GetProcAddress()
  3. Use a manifest 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?

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-02-16 19:10

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.

查看更多
戒情不戒烟
4楼-- · 2019-02-16 19:30

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

查看更多
登录 后发表回答