フィルターのクリア

Problem using external shared library with pointers

8 ビュー (過去 30 日間)
Wolfgang
Wolfgang 2014 年 8 月 1 日
コメント済み: Wolfgang 2014 年 8 月 13 日
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
Philip Borghesani 2014 年 8 月 8 日
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 Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by