| External Interfaces Reference | ![]() |
Construct structure as defined in external library
Syntax
Description
s = libstruct('type')
returns a libstruct object s that is a MATLAB object designed to resemble a C structure of type structtype. The structure type, structtype, is defined in an external library that must be loaded into MATLAB using the loadlibrary function. All fields of s are set to zero.
s = libstruct('structtype', mlstruct)
returns a libstruct object s with its fields initialized from MATLAB structure, mlstruct.
The libstruct function essentially creates a C-like structure that you can pass to functions in an external library. You can handle this structure in MATLAB as you would a true MATLAB structure.
Examples
This example performs a simple addition of the fields of a structure. The function addStructFields is defined in the MATLAB sample shared library, shrlibsample.
Start by loading the shrlibsample library and creating MATLAB structure, sm:
addpath([matlabroot '\extern\examples\shrlib']) loadlibrary shrlibsample.dll shrlibsample.h sm.p1 = 476; sm.p2 = -299; sm.p3 = 1000;
Construct a libstruct object sc that uses the c_struct template:
Now call the function, passing the libstruct object, sc:
| Note In most cases, you can pass a MATLAB structure and MATLAB will automatically convert the argument to a C structure. See Structures, in the MATLAB documentation for more information. |
See Also
loadlibrary, libfunctions, libfunctionsview, libpointer, calllib, libisloaded, unloadlibrary
| libpointer | loadlibrary | ![]() |
© 1994-2005 The MathWorks, Inc.