linking a dll with loadlibrary "specified module could not be found" error

44 views (last 30 days)
Hi, I'm trying to use loadlibrary to link a .dll to matlab (rather than using the mex compiler). I received from a vendor comes with the following header (it already had the extern "C" command, but I've modified it to include #ifdef __cplusplus as recommended). I'm currently using matlab 2014b, (32 bit). I have visual studio 2013 professional on my machine.
loadlibrary('IRIS_API'); returns the following...
In C:\Program Files (x86)\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 359
In loadAPI at 3
Error using loadlibrary (line 440)
There was an error loading the library "C:\Users\jmcmullen\Documents\Data\20160928 - IRIS
API\IRIS_API.dll"
The specified module could not be found.
The header file is below. Any help would be greatly appreciated.
Thanks Jesse
#ifndef IRIS_API_included
#define IRIS_API_included
#ifndef IRIS_EXPORT // Compiling a user of IRIS
#define IRIS_EXPORT __declspec(dllimport) // For Microsoft Visual Studio
#endif
#ifdef __cplusplus
extern "C" { // Prevent C++ name-mangling (for other compilers)
#endif
// Must be called very early
IRIS_EXPORT void IRIS_InitAll(HWND mainHWnd);
// Must be called very late
IRIS_EXPORT void IRIS_ExitAll();
IRIS_EXPORT int signInUser();
IRIS_EXPORT void onMenuSystem();
IRIS_EXPORT bool signOut(CString sUser);
IRIS_EXPORT bool changeSuperPswd();
IRIS_EXPORT bool changePswdCurrentUserPswd();
IRIS_EXPORT bool changePswdHomingPswd();
IRIS_EXPORT bool signInChangeUser();
IRIS_EXPORT bool deleteUser();
IRIS_EXPORT bool userManagementSetCurrentProjectsDir();
... %more functions
#ifdef __cplusplus
}
#endif
#endif // IRIS_API_included

Answers (2)

Pico Technology
Pico Technology on 7 Oct 2016
Edited: Pico Technology on 10 Oct 2016
Hi Jesse,
Assuming this is your header file name, try:
loadlibrary('IRIS_API.dll', 'IRIS_API.h');
Is the IRIS_API dll 32-bit or 64-bit?
You may also need to configure a C compiler using
mex -setup

Philip Borghesani
Philip Borghesani on 10 Oct 2016
That error is frequently the result of some other dll being missing from your system or otherwise failing to load. I recommend running MATLAB from the dependency walker program and looking at the results for dlls that failed to load.
  1. Dependency walker may already be on your machine it ships with many versions of Visual Studio and other Microsoft toolkits.
  2. Open file ...\matlab\bin\win32\matlab.exe
  3. Start profiling (default options should be ok, Full file paths might be helpfull)
  4. When matlab is up clear the log window (optional but helpfull)
  5. Load your library from MATLAB and look in the log for dlls that failed to load and reason why.

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!