| External Interfaces |    | 
Reference Pointers
Arguments that have more than one level of referencing (e.g., uint16 **) are referred to here as reference pointers. In MATLAB, these argument types are named with the suffix PtrPtr (for example, uint16PtrPtr). See the output of libfunctionsview or methods -full for examples of this type.
When calling a function that takes a reference pointer argument, you can use a reference argument instead and MATLAB will convert it to the reference pointer. For example, the external allocateStruct function expects a c_structPtrPtr argument:
void allocateStruct(struct c_struct **val) { *val=(struct c_struct*) malloc(sizeof(struct c_struct)); (*val)->p1 = 12.4; (*val)->p2 = 222; (*val)->p3 = 333333; }
Although the prototype says that a c_structPtrPtr is required, you can use a c_structPtr and let MATLAB do the second level of conversion. Create a reference to an empty structure argument and pass it to allocateStruct:
sp = libpointer('c_structPtr'); calllib('shrlibsample', 'allocateStruct', sp) get(sp) ans = Value: [1x1 struct] DataType: 'c_structPtr' get(sp, 'Value') ans = p1: 12.4000 p2: 222 p3: 333333
When you are done, return the memory that you had allocated:
|   | Creating References | Calling C and Fortran Programs from MATLAB |  | 
© 1994-2005 The MathWorks, Inc.