Search code examples
visual-studio-2008matlabdllmexloadlibrary

Explicit/implicit loading of a dll from a mex file


My question is a possible duplicate of this: matlab mex files and C++ dll (windows), however not exactly.

When I try to explicitly load a dll from a Matlab's mex file (Visual Studio 2008, Windows 7 64bit, Matlab 2010b), The loading fails at runtime (I get a NULL handle). The same code works ok when used not in the mex file.

When I try to implicitly load, by linking to the .lib file, I get a linker error of unresolved external symbol regarding the functions defined in the dll. Again, the same code works ok when used not in the mex file.

Is the reason the same as in the answer of the above SO question, or am I missing something? If the reason is the same, is there another solution except the one suggested in the above question?


Solution

  • I assume your code is using the Windows function LoadLibrary. You should check the return from GetLastError to see why the LoadLibrary call fails.