%% Autoconvert Structure Arguments
% This example shows how to pass a MATLAB structure to a C library function,  addStructByRef. When you pass the structure, MATLAB automatically converts the field types, but MATLAB also makes a copy of the fields.
% Load the library.

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

%
% Create a structure.

S.p1 = 476;
S.p2 = -299;
S.p3 = 1000;

%
% Call addStructByRef.

res = calllib('shrlibsample','addStructByRef',S)

%
% MATLAB does not modify the contents of structure S, since it is not a pointer.

S

%
% Copyright 2015 The MathWorks, Inc.