0

I created GUI in C# as gui.dll and create C++/CLI interop interop.dll for C++ project. That means (*.exe call --> interop.dll and interop.dll call --> gui.dll) I test it with C++ console application which is working wintout any problem, because in the end consoleApp.exe and all dlls are in same folder.

What I did:

  • interop is c++/cli code with reference to C# dll. I created class and export it for use it inside plugin.vst3. C# dll is dynamicaly linked
  • inside plugin.vst3 project I includeLibrary for interop project to use class and add interop.lib to Linker. interop.dll is dynamicaly linked

What I want: Now I want use those dlls (gui.dll and interop.dll) inside c++ project as another "dll" myPlugin.vst3 (audio plugin). For those who don't know, audio plugins are located on different location as program which use it. That means, if audio program load plugin, it is different scenario as my consoleApp.exe call dll on same location.

The Problem: When I run host program which load my vst3, unfortunately vst3 start search for my dlls from AudioHost.exe view not from vst3 view where is my vst3 file located.

For example, if myPlugin.vst3 is inside D:\VstiPlugins\MyTest\, interop.dll is on D:\VstiPlugins\interop.dll and gui.dll next to C:\ProgramFiles\Reaper\Reaper.exe, my plugin is loaded. All files myPlugin.vst3, interop.dll and gui.dll must be on same location D:\VstiPlugins\MyTest.


The questions:

Simple question is "How to load those dlls from vst3" as I describe it in "What I want" and "The Problem"?

What come to mind as firstly was load plugin with code (like LoadLibrary(...)) instead use *.lib. But all examples and solutions, are for dlls which export only C functions and not as my scenario where I use class. Can be dll loaded from code and use class?

Another idea was DLL redirection with manifest file, but there is no documentation for that scenario or I can't find it. And I am not sure if it will be working.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Wanderer
  • 319
  • 1
  • 3
  • 12
  • What is stopping you from registering `gui.dll`'s folder in your `%PATH%` environment, or even registering the path to `gui.dll` itself in the [`KnownDlls` key](https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order) in the Registry? – Remy Lebeau Jan 14 '20 at 03:45
  • [https://stackoverflow.com/questions/2100973/dll-redirection-using-manifests](https://stackoverflow.com/questions/2100973/dll-redirection-using-manifests) – Suarez Zhou Jan 14 '20 at 09:06
  • @RemyLebeau I don't want mess with enviroment. all plugins I have, which use dlls don't have anything in enviroment path. – Wanderer Jan 14 '20 at 11:03
  • @Wanderer if you can load `interop.dll` and `gui.dll` dynamically, you can pass absolute paths to `LoadLibrary()`. If you use delay loading, you can use `AddDllDirectory()` before performing an action that invokes a load. – Remy Lebeau Jan 14 '20 at 15:17
  • @RemyLebeau I'll try AddDllDirectory, it looks interesting. To be sure, maybe it is not clear from my question, but does it work (AddDllDirecotry()) for dll which is linked only with *.lib? That means I don't use any loading functions in code. Also, from documentation, it is not clear to me, if I have to remove Directory if I add Directory once. – Wanderer Jan 14 '20 at 15:35
  • @RemyLebeau I tried AddDllDirectory without success, but SetDllDirectory is working and my first dll is loaded. But second dll is not loaded because it "lost" the DllDirectory or it try load from *.exe path. To remember, first dll (interop.dll) is loading second (gui.dll), that means plugin.vst3 loads only interop.dll. Problem is, it is c++/cli which call managed dll, which is different as call c++ vst3 to c++/cli dll – Wanderer Jan 14 '20 at 20:19
  • @Wanderer `SetDllDirectory()` only allows 1 extra folder to be set, but you have 2 extra folders that need to be set, so you will need `AddDllDirectory()` instead. But it will not work at all if you use *static* linking, since there is no opportunity to call it before the OS Loader tries to load dependent DLLs (the EXE would have to call it before loading your plugin). Either function will only work when you use dynamic loading or delay loading, since both allow your DLLs code to run before loading any additional DLLs. – Remy Lebeau Jan 14 '20 at 21:16
  • @RemyLebeau I am little confused now, what two extra folders? All my dlls with vst3 are under one folder. When I call `AddDllDirecotry("D:\path\To\My\DLLs")` calling this function is ok, but it not detect my C++/CLI DLL, I must use `'SetDllDericetory("D:\path\To\My\DLLs")` to find it, but then it don't find GUI DLL which is managed DLL (C#), even if I call `SetDllDericetory("D:\path\To\My\DLLs")` from C++/CLI DLL. – Wanderer Jan 14 '20 at 22:50
  • @Wanderer you stated in your question: "*myPlugin.vst3 is inside D:\VstiPlugins\MyTest\, interop.dll is on D:\VstiPlugins\interop.dll and gui.dll next to C:\ProgramFiles\Reaper\Reaper.exe*" - count them, that is 3 separate folders, which `SetDllDirectory()` can't handle, but `AddDllDirectory()` call. And there is very little difference between calling `SetDllDirectory()` vs calling `AddDllDirectory()` 1 time, they do the same thing. Though `AddDllDirectory()` is affected by `SetDefaultDllDirectories()`, not sure if `SetDllDirectory()` is, too. – Remy Lebeau Jan 15 '20 at 01:03
  • @RemyLebeau that was only example, when it is working. In next sentence I wrote, they must be in one folder, and I mean then it is not working, but I have to make it working. Btw. I found that is not working because managed dll is not working with win32 way `SetDllDirectory` and all similar functions. Now I am looking managed solution for that. – Wanderer Jan 15 '20 at 15:52

0 Answers0