MATLAB: How to manipulate multilayer pointers in calllib calls, what is the proper syntax

calllibmultilayer pointers

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)

Best Answer

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.
  • 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:
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.