Clear Filters
Clear Filters

C Dll does not find all header paths

11 views (last 30 days)

Hello all,

I am currently trying to call functions from a dll from within MATLAB. Here are two things that I tried and have questions about:

1.:

calllib("C:\Windows\System32\mxsvcb.dll",'mxCardsReset',0)

This is the way I am used to calling Dlls (from LabVIEW): reference the dll, select a function and pass the parameters. However, when I call this, I get an error back: Error using calllib Library was not found

The file is definitely at that location. Is this sort of call possible?

2.: When I go to the documentation folder and call

loadlibrary('C:\Windows\System32\mxsvcb.dll','\apimx\apimx.h')

I get a different error, that tells me the file that is being referenced by an include does not exist "common/nowarn.h". Now, that file is in a parallel folder and not in a subfolder to the "apimx.h", so the path would be "../../common/nowarn.h" from where apimx is.

Because of this, I copied the folder into the "apimx" folder and got the same message for the next include in line. Since the header files reference each other, I can't rearrange everything, because it would take a long time. Is there a way to make MATLAB understand the structure better?

Edit: Sorry, somehow the post got submitted while adding tags.

  3 Comments
Dennis
Dennis on 2 Oct 2018
Which version of matlab are you using and are your .dll 32 or 64 bit?
Peter Foerster
Peter Foerster on 3 Oct 2018
It's a 32 Bit dll on MATLAB R2018b 64-Bit, but for now, I don't believe that to be the issue, since the error message clearly indicate some issues with referencing the header files. (I'd expect to be able to call 32 bit dlls from 64 bit MATLAB anyway)

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 2 Oct 2018
Edited: Guillaume on 2 Oct 2018
You cannot use calllib in matlab unless you have first loaded the library with loadlibrary.
If there is a bunch of include file that are not found because they're in a different folder then you need to tell loadlibrary where to find them, using the includepath option (Not that this is orthogonal to addpath which is for m files). From your description, it looks like includepath should point to whatever ../.. is, so
loadlibrary('C:\Windows\System32\mxsvcb.dll','\apimx\apimx.h', 'includepath', '\apimx\..\..\')
may work.
  1 Comment
Peter Foerster
Peter Foerster on 3 Oct 2018
Hi Guillaume,
thanks for your answer! Just to clarify a few things: when I write .. I mean out one folder. Also, if the option is inlcudepath and not addpath, why are they using addpath in the loadlibrary example?
I have tried your suggestion, but it still gives me the same error as without the 'includepath'. It is telling me no such file or directory #include common/nowarn.h, regardless of how I put in the path:
loadlibrary('C:\Windows\System32\mxsvcb.dll','\apimx\apimx.h','includepath', 'c:\Program Files\MAX Technologies\maxapi\common\')
loadlibrary('C:\Windows\System32\mxsvcb.dll','\apimx\apimx.h','includepath', '\common\')
loadlibrary('C:\Windows\System32\mxsvcb.dll','\apimx\apimx.h','includepath', '\..\common\')
It doesn't appear to be searching the includepath at all, because the actual call for common/nowarn.h comes from another header file that is referenced in apimx.h. Is there any way to do this without header file?

Sign in to comment.

More Answers (0)

Categories

Find more on Search Path in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!