Help with use of multilievel pointers

2 visualizzazioni (ultimi 30 giorni)
Amy
Amy il 7 Giu 2017
Commentato: Hoanzn il 26 Gen 2018
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 Commento
Hoanzn
Hoanzn il 26 Gen 2018
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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by