Can't load library function from dll

조회 수: 14 (최근 30일)
Andrés Aguilar
Andrés Aguilar 2023년 11월 1일
댓글: Andrés Aguilar 2024년 3월 7일
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에서 Startup and Shutdown에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by