- libpointer objects work like handle objects. They can and will be modified when passed into a function on the right hand side of a calllib call there is no need to assign back into them on the left hand side of the calllib command. Create a new variable if needed to accept the output. Placing the same variable on both sides should work but places extra stress on the system because temporaries are needed to hold the input before the variable can be destroyed and the new copy (the input) can be copied into it.
- Passing an empty libpointer object will pass a NULL pointer to the function being called. A null may be correct for head in getHead but is most likely wrong for the sonar value. Your code should probably look something like this:
How do I manipulate multilayer pointers in calllib calls, what is the proper syntax?
2 views (last 30 days)
Show older comments
I have access to a library with the following calls:
[int32, BVTOpaqueSonarPtr, BVTOpaqueHeadPtrPtr] = BVTSonar_GetHead (BVTOpaqueSonarPtr, int32, BVTOpaqueHeadPtrPtr)
and
[int32, BVTOpaqueHeadPtr, BVTOpaquePingPtrPtr] = BVTHead_GetPing (BVTOpaqueHeadPtr, int32, BVTOpaquePingPtrPtr)
In my MATLAB function I have the following:
sonarPtr = libpointer;
headPtrPtr = libpointer;
[retval, sonarPtr, headPtrPtr] = BVTSonar_GetHead(sonarPtr, headIndex, headPtrPtr);
Now it is not clear to me how to dereference headPtrPtr to make the call to get the ping. It will look something like:
pingPtrPtr = libpointer;
[retval, *headPtr, pingPtrPtr] = BVTHead_GetPing(*headPtr, pingNumber, pingPtrPtr);
Except the '*' obviously does not work and I cannot find the proper syntax. I will have a similar problem using the BVTPing commands to get information from the ping, since they all call for pingPtr.
eg. [int32, BVTOpaquePingPtr, BVTOpaqueMagImagePtrPtr] BVTPing_GetImageRTheta (BVTOpaquePingPtr, BVTOpaqueMagImagePtrPtr)
0 Comments
Accepted Answer
Philip Borghesani
on 29 Jul 2013
Edited: Philip Borghesani
on 29 Jul 2013
MATLAB automatically does the pointer conversions for you there is no need to add a star.
You did not post the symptoms or specifics of your problem so you get some general comments.
sonarStruct=libstruct('BVTOpaqueSonar',matlabStructWithInputValues);
headPtr=libPointer('BVTOpaqueHead') % null typed pointer to hold head might need BVTOpaqueHeadPtr instead
retval=calllib('libname','BVTSonar_GetHead',sonarStruct, headPtr);
After the call sonarStruct and headPtr will contain modified values if modified by the function call.
2 Comments
Philip Borghesani
on 30 Jul 2013
Edited: Philip Borghesani
on 30 Jul 2013
MATLAB checks the number of levels of indirection needed on input parameters to a calllib command and adds any that are needed. There is no difference in MATLAB between a libpointer('myPtr') and libpointer('myPtrPtr') (except when using strings or cstrings).
For headPtr you probably want to use:
headPtr=libpointer('BVTOpaqueHeadPtr') % or libpointer('voidPtr')
What version of MATLAB are you using? There are bugs in version prior to R2010a that could cause issues.
When I Googled for 'BVTSonar_GetHead' I found and example.m file that does the initial setup and some use of this dll it may be a good starting point for you.
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!