Question

I am working on a MATLAB Engine application. In order for it to work, MATLAB needs to be added to the PATH environment variable so that the Engine application can find certain DLLs (libeng and libmx).

When MATLAB is registered as a COM server, it writes its location into the registry and I can access it. Using this information, is there a simple way to allow the Engine application to work without having to add MATLAB to the PATH? The Engine application could theoretically read the location of these DLLs from the registry, but the problem is that it won't even start up without those DLLs (when compiled the standard way, according to MATLAB Engine compilation instructions).

I am not very familiar with winapi and not at all familiar with COM.

Is there an easy solution to let the problem find its DLLs based on the information from the registry?

Was it helpful?

Solution

I found the following solution:

If we use delayed DLL loading then we get a chance to set the DLL search path before the program attempts to load the DLLs.

To do this, the following needed to be added to the linker options: /DELAYLOAD:libmx.dll /DELAYLOAD:libeng.dll and it's necessary to link against delayimp.lib. After doing this, we can add a call to SetDllDirectory() with the path to the location of the libmx.dll and libeng.dll to the beginning of the main/WinMain function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top