Can't load library function from dll

6 次查看(过去 30 天)
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.

回答(1 个)

Aiswarya
Aiswarya 2023-11-30
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 个评论
Andrés Aguilar
Andrés Aguilar 2024-3-7
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by