0

I have a C++ application on Windows, compiled with MSVC, that is linking to a number of dlls at runtime. The application has an Excel front end: an .xll file that the user can load into excel. The user should be able to load the xll from whichever location.

All the dlls are located on a shared drive and none of the users has this location added to his/her windows path variable (I wouldn’t want that, since these dlls could clash with other programs). I’ve made the application such that, when the application is launched, the Windows path variable is changed locally (only in the session in which the application is running) to include the path to these dlls.

This only works because, in my Visual Studio solution, I’m able to specify that these dlls should be delay loaded (run-time dynamic loading).

Here comes my problem: I want to use boost-python for a python front end. Boost python forces my application to load python27.dll when the application is started (load-time linking), i.e. without delay.

I actually tried linking with delay, and got the following error: 1>LINK : fatal error LNK1194: cannot delay-load 'python27.dll' due to import of data symbol '__imp___Py_NoneStruct'; link without /DELAYLOAD:python27.dll

My question is whether I can somehow modify the load-time search path, from within my application?

Note that all those users that use the Excel front-end, don't intend to use the python front end (which is meant for another group of users), so I cannot be sure that those Excel users have python installed, especially not version 2.7.

Many thanks in advance, Nele

Nele
  • 73
  • 7
  • As with Rob K's answer: this is exactly what a launcher can do for you. Either a batch file or another exe, that simply sets up the correct environment for execution, then starts a process running the actual executable. You might even pack your executable app into a delay loaded dll that you load in your launcher after you've modified the environment... – BeyelerStudios Dec 20 '18 at 15:25
  • why not compile a no-python version for those use excel? since it looks like not a problem for python users as your last paragraph said. – apple apple Dec 20 '18 at 15:28
  • Many thanks for your comments. There was some old code in there that caused python to be needed in the excel compilation. I removed that and now my excel plugin has no longer any dependency on python27.dll. – Nele Dec 21 '18 at 19:57

1 Answers1

1

You cannot modify the load-time search path from within your application since your application isn't loaded yet to do anything. The best you can do is some type of wrapper, like a batch file or other script that will set up the environment, or maybe link the DLLs with fully qualified paths to the network share.

Rob K
  • 8,757
  • 2
  • 32
  • 36
  • Hi Rob, I actually tried to set the dll path in Linker->General->Additional Library Directories of the application project, but that doesn't work (it works for .lib files). Is there another way? – Nele Dec 20 '18 at 15:29
  • I'm not sure it will work, but in your "Delay Loaded Dlls" setting, specify the fully qualified path to the Dll, not just the file name of the Dll. In my projects where I wanted to conditionally load a Dll, I wrote a base class which wrapped `LoadLibrary()` in the constructor, `FreeLibrary()` in the destructor, and had functions to look up function addresses by name or ordinal. I derived classes from that for each of the Dlls I wanted to dynamically load. – Rob K Dec 20 '18 at 16:08
  • Another thing you might consider is [writing your own delay-load helper function](https://learn.microsoft.com/en-us/cpp/build/reference/developing-your-own-helper-function?view=vs-2017) – Rob K Dec 20 '18 at 16:09
  • Hi Rob, the delay-load is working fine (by the time the delay-load needs to take place, the path is already including the location of the dlls. My problem was that I couldn't delay load python. At the end, I removed some old code that was creating a dependency on python for the excel plugin. Everything works fine now. – Nele Dec 21 '18 at 19:59