Help with use of multilievel pointers

3 visualizaciones (últimos 30 días)
Amy
Amy el 7 de Jun. de 2017
Comentada: Hoanzn el 26 de En. de 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 comentario
Hoanzn
Hoanzn el 26 de En. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Call C from MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by