| MATLAB® | ![]() |
[x1, ..., xN] = calllib('libname',
'funcname', arg1, ..., argN)
[x1, ..., xN] = calllib('libname', 'funcname', arg1, ..., argN) calls the function funcname in library libname, passing input arguments arg1 through argN. calllib returns output values obtained from function funcname in x1 through XN.
If you used an alias when initially loading the library, then you must use that alias for the libname argument.
The following examples show ways calls to calllib. By using libfunctionsview, you determined that the addStructByRef function in the shared library shrlibsample requires a pointer to a c_struct data type as its argument.
Load the library:
addpath([matlabroot '\extern\examples\shrlib']) loadlibrary shrlibsample shrlibsample.h
Create a MATLAB structure:
struct.p1 = 4; struct.p2 = 7.3; struct.p3 = -290;
Use libstruct to create a C structure of the proper type (c_struct):
[res,st] = calllib('shrlibsample','addStructByRef',...
libstruct('c_struct',struct));Let MATLAB convert struct to the proper type of C structure:
[res,st] = calllib('shrlibsample','addStructByRef',struct);Pass an empty array to libstruct and assign the values from your C function:
[res,st] = calllib('shrlibsample','addStructByRef',...
libstruct('c_struct',[]));Let MATLAB create the proper type of structure and assign values from your C function:
[res,st] = calllib('shrlibsample','addStructByRef',[]);Remove the library from memory:
unloadlibrary shrlibsample
To call functions in the MATLAB libmx library, see Invoking Library Functions.
loadlibrary, libfunctions, libfunctionsview, unloadlibrary
See Passing Arguments for information on defining the correct data types for library function arguments.
![]() | calendar | callSoapService | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |