0

I am asking this question after VERY extensive googling, but there seem to be no comprehensive answer. I have a DLL which implicitly loads another (third-party) DLL. How can I create a manifest/config file/whatever, to load this third-party DLL from another folder?

Why I want to do this: My C++ program (MSVC-compiled) needs to use a third-party DLL (I think it's a .NET assembly, but I am really not knowledgeable in all this). I use #using "third party DLL.dll" to get access to the classes and functions of this DLL. Since it's a .NET assembly, I can only do it from managed code. Since my main program is unmanaged C++, I create a managed DLL (compiled with /clr) that loads the third-party DLL, and then load this managed DLL dynamically. So it looks like this:

C++ program (unmanaged) -> [LoadLibrary()] -> My managed DLL -> [#using directive] -> third-party .DLL

Now, I want to distribute the whole thing to users, but I don't like the license of the third-party .DLL. So what I am doing is asking the users to install another software package, which contains the third-party DLL, and then ask them to copy-paste it into the folder of my program. Would be a lot better, if it were possible to somehow tell Windows where to look for the third-party DLL, when my managed DLL is being loaded with LoadLibrary().

Any ideas how to solve this? Sorry if it's a stupid question, I don't understand all this DLL stuff.

vdxdnn
  • 23
  • 4
  • If you are loading your managed DLL dynamically at runtime, you can use `SetDllDirectory()` or `AddDllDirectory()` beforehand. Otherwise, if you are static-linking everything, then a manifest is the only option (see [this blog article](https://devblogs.microsoft.com/oldnewthing/20171011-00/?p=97195) for an example), unless you change the user’s `%PATH%` environment before running your app. As for the licensing issue, if you don’t like how the 3rd party DLL is licensed, then don’t use it, period. – Remy Lebeau Dec 20 '20 at 18:39
  • Thank you! Unfortunately, not using the third-party DLL is not an option. I tried including SetDllDirectory() and AddDllDirectory() (each one or both) before doing LoadLibrary for my managed DLL, but it's not working. Embedding manifest into my DLL is not an option, as I don't know the path to the third-party library at compile time. Will look up how to add to PATH at runtime. – vdxdnn Dec 21 '20 at 13:49
  • OK, nothing is working, my DLL loaded with LoadLibrary apparently ignores PATH when looking for implicitly linked third-party DLL. Also, I tried the solution here https://stackoverflow.com/questions/36814862/search-path-for-a-dll-referenced-by-a-plug-in-dll - does not work for me. So I pre-load the third-party DLL with LoadLibrary before doing LoadLibrary on my DLL, it still fails. – vdxdnn Dec 21 '20 at 16:14
  • See [Dynamic-Link Library Search Order](https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order). If you don't know where the DLL is located, and Windows doesn't know where to look for it, then how do you plan on loading it? One of you has to know where to look so the other can be told. Does the 3rd party app save its install location anywhere (Registry, etc)? – Remy Lebeau Dec 21 '20 at 18:27
  • Well, I do know where the library is, at the installation time or runtime. The third-party app does not save its install location, but it's not difficult to find it. The question is, how to tell this to Windows? Of course, I can use SetDllDirectory() or add this to PATH, but Windows seems to ignore it when searching for the implicitly loaded DLL. – vdxdnn Dec 22 '20 at 18:52
  • it should not be ignoring it, per the documentation I linked to earlier. – Remy Lebeau Dec 23 '20 at 02:47

0 Answers0