Is it possible to access a pointer to a structure within another structure via libpointer?
Show older comments
Hello,
I am using an external c/c++ shared library from within MATLAB.
Please see the code below:
% c/c++ interface function
% bool oa_get_pattern_objects ( int instance_id , oa_object_array * pReturned_objects )
function [found object_xyrecords] = get_pattern_objects(instance_id)
oa_object_array.m_objects = {};
oa_object_array.m_size = 0;
pOA_pattern_objects = libpointer('oa_object_array',oa_object_array);
if calllib('OpenAccessCore','oa_get_pattern_objects',instance_id,pOA_pattern_objects) == true
found = true;
proxy_objects = get(pOA_pattern_objects,'Value');
size = proxy_objects.m_size;
%THIS IS ILLEGAL
setdatatype(proxy_objects.m_objects,'oa_xyrecordPtr',1,size)
object_xyrecords = proxy_objects.m_objects.Value;
else
found = false;
object_xyrecords = [];
end
I cannot use setdatatype to inform MATLAB that the field, m_objects, points to an array of structures of the same type.
Perhaps I could get a pointer to the first element in the array and manually convert them in MATLAB one-by-one. Is there a way to do this?
My real desire is to give MATLAB the information it needs and allow it to convert all the elements for me more efficiently and elegantly than I can. Is there a way I can do this?
For a simple c-structure like below is it possible to access the elements in the array pointed to by the pointer, sc_array, by any means in MATLAB?
struct simple_class
{
int my_id;
simple_class * sc_array;
};
Any thoughts are greatly appreciated :-)
Accepted Answer
More Answers (0)
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!