Libpointers and multilevel pointers

3 views (last 30 days)
Matthieu on 12 Oct 2011
Hi there,
I am stuck with shared library and multilevel pointers and was hoping that some of you may help. I need to use a DLL which notably provides two functions:
char ** functionOne();
[stringPtrPtr] = functionOne(); (matlab equivalent)
void functionTwo(char * Text);
functionTwo(cstring); (matlab equivalent)
The first one is recognized as returning stringPtrPtr data. Which seems allright so far. Matlab is indeed able to read the array of string returned.
Then, I need to provide functionTwo with one of the elements of the array of strings returned by functionOne.
I'm doing: TextArray = calllib(DLL_Alias , 'functionOne');
get(TextArray) shows:
  • DataType = stringPtrPtr
  • Value = {'Text1', 'Text2', ...}, hence a cell array of strings
Which synthax, if it is possible, do I have to use to provide Text1 or Text2's addresses to functionTwo ?
  • Writing:
TAval = TextArray.Value();
calllib(DLL_Alias, TAval{1}) % for text1
calllib(DLL_Alias, TAval{2}) % for text2
fails as TAval{1} is a string and not a pointer
  • Writing:
calllib(DLL_Alias, TextArray) % for text 1
calllib(DLL_Alias, TextArray+1) % for text 2
fails as TextArray or TextArray+1 are interpreted as stringPtrPtr and not cstring (nor stringPtr).
I've also tried to force the datatype to stringPtr or cstring, which Matlab seems to refuse.
Any hint?
Thanks, Matthieu

Answers (2)

Malcolm Lidierth
Malcolm Lidierth on 14 Oct 2011

Philip Borghesani
Philip Borghesani on 14 Oct 2011
calllib(DLL_Alias, 'functionTwo', TAval{1}) % for text1
Should work. Note that in your example you forgot 'functionTwo'. MATLAB strings are automatically converted into pointers (cstrings) in function calls.
Example code:
cd (fullfile(matlabroot,'extern','examples','shrlib'));
loadlibrary shrlibsample
If you still have problems please post your MATLAB version.

Community Treasure Hunt

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

Start Hunting!

Translated by