Can't load library function from dll
6 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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!
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!