How to pass a three-level pointer (void***) to a function in a shared library?

2 views (last 30 days)
Hello dear Mathworks community,
I'm trying to load a shared C-library into MATLAB with loadlibrary . Unfortunately the library contains a function which alters its first input argument of the type three-level void pointer . The complete signature of the function in the C-header is the following:
typedef void* EnsembleHandle;
BOOL EnsembleConnect(EnsembleHandle** handles, DWORD* handleCount);
My problem consists of the issue that Matlab does not recognize this three-level pointer (void***) correctly. When I try to load the library MATLAB gives me the following error:
Warning: The data type 'voidPtrPtrPtr' used by function EnsembleConnect does not exist.
> In loadlibrary at 402
In MotionController03 at 18
There is a help resource with the title Passing Arguments to Shared Library Functions which only talks about two-level pointers (void**).
Does this mean, that it is impossible to use pointers with more than two levels when dealing with functions from shared C-libraries?
If yes, what other possibilities do i have to be able to use this library within MATLAB?
Thanks for your help in advance,
hr
APPENDIX: code of the m-file loading the library
root = <myPathToTheLibraryRootFolder>
header = [root,'\Ensemble\Include\test.h'];
library = [root,'\Ensemble\Bin64\EnsembleC64.dll'];
[notfound, warnings] = loadlibrary(library, header);
libfunctionsview('EnsembleC64')
unloadlibrary('EnsembleC64');

Answers (1)

Philip Borghesani
Philip Borghesani on 17 Feb 2014
Edited: Philip Borghesani on 17 Feb 2014
Three level pointers are not supported if you do not need to manipulate the handles from matlab or need only minor access you may be able to modify the header file or create a modified prototype file to make this work. Your other option is to use a mex file for some or all library operations.
Header change:
typedef void* EnsembleHandle;
BOOL EnsembleConnect(EnsembleHandle* handles, DWORD* handleCount); // all references to EnsembleHandle in header must have one * removed
It may work if you just change the typedef to be:
typedef void EnsembleHandle;
But i am not sure it is legal.
To modify the prototype file remove one Ptr from each place an EnsembleHandle is passed.

Categories

Find more on Troubleshooting in MATLAB Compiler SDK in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!