calllib - Call function in C shared library - MATLAB (original) (raw)

Call function in C shared library

Syntax

Description

[[x1,...,xN](#btdfvoz-1-x1xN)] = calllib([libname](#btdfvoz-1%5Fsep%5Fshared-libname),[funcname](#btdfvoz-1-funcname),[arg1,...,argN](#btdfvoz-1-arg1argN)) calls function funcname in C library libname, passing input arguments arg1,...,argN. Thecalllib function returns output values obtained fromfuncname in x1,...,xN.

example

Examples

collapse all

Call addStructByRef Function

Load the library.

if ~libisloaded('shrlibsample') addpath(fullfile(matlabroot,'extern','examples','shrlib')) loadlibrary('shrlibsample') end

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.

Cleanup.

unloadlibrary shrlibsample

Input Arguments

collapse all

Name of shared library, specified as a character vector. Do not include the path or file extension in libname.

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 library

character vector

Name of function in library, specified as a character vector.

Data Types: char

arg1,...,argN — Input arguments

any type

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

Output Arguments

collapse all

x1,...,xN — Output arguments

any type

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

Limitations

Tips

Version History

Introduced before R2006a