cstring datatypes in library function calls dll files

13 次查看(过去 30 天)
Hi! I'm trying to read data returned by my function: the mprototype is:
% extern " C " int getName( unsigned deviceIndex , char * nameBuffer , unsigned size );
fcns.name{fcnNum}='getName'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'uint32', 'cstring', 'uint32'};fcnNum=fcnNum+1;
I run the function as:
buf = libpointer('cstring', blanks(200));
nam = calllib('pxc','pxcGetDeviceName',uint32(0),buf,uint32(200));
buf.Value
but all I get is blank string. So my question is: is the libpointer correct fot this usage of function? I'll be thanful for the help. KS

回答(1 个)

Philip Borghesani
Philip Borghesani 2014-12-2
Try :
[retval,name]=calllib('pxc','pxcGetDeviceName',0,blanks(200),200);
It is best to start by letting calllib do the data type conversion for you.

类别

Help CenterFile Exchange 中查找有关 Call C from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by