Filter löschen
Filter löschen

Problem using external shared library with pointers

8 Ansichten (letzte 30 Tage)
Wolfgang
Wolfgang am 1 Aug. 2014
Kommentiert: Wolfgang am 13 Aug. 2014
Hey there!
I'm trying to control a camera via MatLab. Loading the library and using some of its functions works fine. However I have problems using the functions working with pointers.
In order to save a picture I first have to allocate an image memory by using:
INT is_AllocImageMem (HIDS hCam, INT width, INT height, INT bitspixel, char** ppcImgMem, INT* pid)
The second function which makes the specified image memory the active memory is:
INT is_SetImageMem (HIDS hCam, char* pcImgMem, INT id)
In MatLab my code looks like this:
width=1280;
height=1024;
bitspixel=24;
pcImgMem=libpointer('stringPtrPtr',{char()});
pid=libpointer('int32Ptr',0);
[m,pcImgMem,pid]=calllib('uc480','is_AllocImageMem',hcam,width,height,bitspixel,pcImgMem,pid);
[m,pcImgMem]=calllib('uc480','is_SetImageMem',hcam,pcImgMem,pid);
When I execute it I always either get an "Parameter can not be converted to a string" error for the variable pcImgMem. If I convert pcImgMem with char(...) I get an error message from the function itself.
Can anybody help me with this problem? Or does anybody have a good tutorial for the use of pointers in libraries? I have read the "Working with Pointer Arguments" in the Mathworks Documentation Center from top to bottom and tried to apply it correctly.
But something still seems to be wrong... Thank you for your help!

Akzeptierte Antwort

Philip Borghesani
Philip Borghesani am 8 Aug. 2014
Because ppcImgMem is an image not a string the best solution here is to create a prototype file using the mfilename option to loadlibrary and edit the function prototypes to change stringPtrPtr to int8PtrPtr and cstring reference to the image to int8Ptr. If you do this it will be much easier to work with the library calls. Be careful doing this globally because some of the parameters may want to stay strings if that is the actual use.
The confusion here is that c does not have a standard way to differentiate an array of bytes from a string and loadlibrary defaults to a string unless they are unsigned.
  1 Kommentar
Wolfgang
Wolfgang am 13 Aug. 2014
Thank you for your answer, Philip!
I managed to solve the problem by writing a MEX file which worked fine for me because I have some experience with C/C++. But still: I hate pointers! :-)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by