Clear Filters
Clear Filters

Can't load library function from dll

4 views (last 30 days)
Andrés Aguilar
Andrés Aguilar on 1 Nov 2023
Commented: Andrés Aguilar on 7 Mar 2024
Hello!
Question first:
Does anyone have an idea on why the funciton I need is not loaded?
Explanation:
I am working with a sensor and I need to call a function called
GetOpticalProbe
This function is described in an API reference document the manufacturer provided me with.
I do have all the files, .dll and .hs. namely
CHRocodile.dll
CHRocodileLib.h
CHRocodileLibErrorDef.h
CHRocodileLibPluginDef.h
CHRocodileLibSpecialFunc.h
After examining the CHRocodileLib.h I found nothing named GetOpticalProbe. I did however found something in CHRocodileLibSpecialFunc:
inline Res_t GetOpticalProbe(arguments)
and includes to some of the other heathers near the beginning:
#include "CHRocodileLib.h"
#include "CHRocodileLibErrorDef.h"
From the matlab documentation of loadlibrary, I understood that when loading a library that has includes, the other heathers should be added to the command:
loadlibrary('mylib','mylib.h','addheader','header2')
So I tried loading it like this:
loadlibrary(fullPathToDll, fullPathToCHRocodileLibSpecialFunc.h, 'addheader', 'CHRocodileLib', 'addheader', 'CHRocodileLibErrorDef')
But after executing loadlibrary, there is no sign of the function I need:
libfunctions CHRocodile
Functions in library CHRocodile:
...
GetNext...
GetOutput...
GetResponse...
...
loadlibrary does give me some warnings like
Warning: The data type 'FcnPtr' used by function RegisterSomethingCallback does not exist.
I do not read C/C++ so I find it rather hard to read any of the .h files.
Thanks in advance!
P.S.: I edited some of the names as I am not sure they are public.

Answers (1)

Aiswarya
Aiswarya on 30 Nov 2023
Hi,
I understand that you are not able to load a particular function 'GetOpticalProbe' in your CHRocodile library.
One of the possible ways to resolve this issue is to specify the storage class information of the function by using "__declspec". This can be done as follows:
__declspec( dllimport ) inline Res_t GetOpticalProbe(arguments)
Then you can use the loadlibrary function to load the dllibrary and then call the function with arguments using the function "calllib" (https://www.mathworks.com/help/matlab/ref/calllib.html)
calllib('CHRocodile','GetOpticalProbe',arg1,arg2,,argn);
You may also refer to this MATLAB answer to know more about this issue:
Hope this helps!
  1 Comment
Andrés Aguilar
Andrés Aguilar on 7 Mar 2024
Aiswarya, thank you very much for your reply.
I ended up achieving the same result by sending direct commands using a proprietary protocol of the manufacturer.
I'll try to sets your method though once I unentangle myself from other stuff.

Sign in to comment.

Categories

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

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!