0

I'm trying to write an ActiveX plugin, and I'm finding myself in a dead end when trying to load DLLs from subfolders. I am developing in Visual Studio 2013 for Windows 10.

The structure of the libraries is as follows:

myocx.ocx --> this is the compiled result
mylibs/
  mainlib.lib
  maindll.dll
  rest-of-dlls.dll

I do not load the DLLs directly in my code, instead they are used by the "mainlib.lib" library. I have tried to set in "Additional dependencies" of the VS Linker the path to the mainlib.lib file, and it fails to register my plugin. If I specify "maindll.dll" as a delayed load DLL, then it compiles, but the plugin does not work (it fails at some point in delayhlp.cpp).

I have read the following posts:

And the following docs from Microsoft:

I tried to add the path to the libraries to my system's PATH environment variable, but for some reason it does not work on some PCs.

I also have tried the manifest way (as described in the first linked question), but looks like VS is completely ignoring it since I can write whatever there and it will fail no matter what.

If I put the DLLs in the same folder as the plugin, it will work, but I really need to put them in a subfolder because of compatibility issues, so that option is discarded.

I do not mind using dynamic loading, but I do not know if this is possible since the DLLs are not loaded inside my code, but in a .lib file instead. I do not mind modifying PATH variable either, but as I said, in some Windows installations it is failing.

Anyone can shed some light on this, in addition to what the linked posts say?

1 Answers1

0

After pulling my hair A LOT, I managed to solve it using a combination of the above links.

In Visual Studio, I added in the "Linker" section the path to the libraries, and added mainlib.lib to the dependencies. Then, I added maindll.dll to the delayed load DLLs, and in the code (main class, right after imports) I added the following:

#pragma comment(lib, "mainlib.lib")

And then in the class initializer, I added the following:

SetDllDirectory("absolute_path_to_my_DLLs_folder")

Then the .ocx plugin was able to compile and register using regsvr32, and it did not fail at execution time.