Libpointers and multilevel pointers

조회 수: 3 (최근 30일)
Matthieu
Matthieu 2011년 10월 12일
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

답변 (2개)

Malcolm Lidierth
Malcolm Lidierth 2011년 10월 14일

Philip Borghesani
Philip Borghesani 2011년 10월 14일
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
strings={'str1','str2'};
[s1,s2]=calllib('shrlibsample','stringToUpper',strings{2})
If you still have problems please post your MATLAB version.

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by