Filter löschen
Filter löschen

Can't load library function from dll

4 Ansichten (letzte 30 Tage)
Andrés Aguilar
Andrés Aguilar am 1 Nov. 2023
Kommentiert: Andrés Aguilar am 7 Mär. 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.

Antworten (1)

Aiswarya
Aiswarya am 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 Kommentar
Andrés Aguilar
Andrés Aguilar am 7 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu C Shared Library Integration finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by