Documentation Center

  • Trial Software
  • Product Updates


Call function in shared library


  • [x1,...,xN] = calllib(libname,funcname,arg1,...,argN) example



[x1,...,xN] = calllib(libname,funcname,arg1,...,argN) calls function, funcname, in library, libname, passing input arguments, arg1,...,argN, and returns output values obtained from funcname in x1,...,xN.


expand all

Call addStructByRef Function

Load the library.

if ~libisloaded('shrlibsample')

Display function signature.

libfunctionsview shrlibsample
[double, c_structPtr] addStructByRef(c_structPtr)

The input argument is a pointer to a c_struct data type.

Create a MATLAB® structure, struct:

struct.p1 = 4; struct.p2 = 7.3; struct.p3 = -290; 

Call the function.

[res,st] = calllib('shrlibsample','addStructByRef',struct);

Display the results.

res =


unloadlibrary shrlibsample

Input Arguments

expand all

libname — Name of shared librarystring

Name of shared library, specified as a string. If you call loadlibrary using the alias option, then you must use the alias name for the libname argument.

Data Types: char

funcname — Name of function in librarystring

Name of function in library, specified as a string.

Data Types: char

arg1,...,argN — Input argumentsany type

Input arguments, 1 through N, required by funcname (if any), specified by any type. The argument type is specified by the funcname argument list.

Output Arguments

expand all

x1,...,xN — Output argumentsany type

Output arguments, 1 through N, from funcname (if any), returned as any type. The argument type is specified by the funcname argument list.


  • Use with libraries that are loaded using the loadlibrary function.

See Also


Was this topic helpful?