Libpointers and multilevel pointers
显示 更早的评论
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
2011-10-14
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Call C from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!