Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

calllib

Call function in shared library

Syntax

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

Description

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.

Examples

collapse all

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.

res
res =
         -279

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

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

Data Types: char

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

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

Limitations

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

More About

collapse all

Tips

  • MATLAB validates input argument types before calling funcname. If MATLAB displays error messages about data types, check the MATLAB function signature. For example, if funcname is in library mylib type:

    libfunctions('mylib','-full')

    Scroll through the output to find funcname. For more information, refer to your library documentation.

    When you call funcname, that function might display errors. For information about error messages, refer to your library documentation.

Introduced before R2006a

Was this topic helpful?