Problem using external shared library with pointers
6 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Philip Borghesani
on 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.
More Answers (0)
See Also
Categories
Find more on Call C from MATLAB 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!