Problem using external shared library with pointers

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

采纳的回答

Philip Borghesani
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 个评论
Wolfgang
Wolfgang 2014-8-13
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! :-)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by