Help with use of multilievel pointers

3 次查看(过去 30 天)
Amy
Amy 2017-6-7
评论: Hoanzn 2018-1-26
I would like to be able to do something like the following:
data = { zeros(5,3), zeros(10,3)};
dataPtr = libpointer('doublePtrPtr');
% need to set up the pointer appropriately - this is the part I'm not sure about
[success, ~, data] = calllib('myalias', 'myfunction', 2, [5 10], 3, dataPtr);
% would like data to come back as a cell array or something that can easily be converted to a cell array
As I indicate above, I'm not sure how to properly initialize the pointer. The syntax for the library function looks something like:
int myfunction(int n0, int* n1, int n2, double** data)
{
// do something with data
}
I cannot use mxArrays because the library function that I'm calling needs to be independent of Matlab. I'm just trying to find a way to call it from Matlab. Can this even be done and how would I do it?
  1 个评论
Hoanzn
Hoanzn 2018-1-26
As Matlab R2017a, you have to flatten your pointer-to-pointer structure such that the data blocks are aligned in subsequent order without gaps.
My workaround: Add a new function "<function_name>Matlab" in your DLL which receives the flattened data, restore the required ptr-to-ptr array therein and call the original "<function_name>" function with the restored array from "<function_name>Matlab". Seems that Ptr-Ptr implementation of the Matlab C interface is incomplete (only stringPtrPtr implemented). If you can not touch your DLL, you may write a DLL wrapper.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call C from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by