MATLAB Answers

Help with use of multilievel pointers

1 ビュー (過去 30 日間)
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 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 件)

Community Treasure Hunt

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

Start Hunting!

Translated by