%% Pass Pointer to Structure
% This example shows how calling the addStructByRef function with a pointer modifies the fields in the input argument.

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

%
% Create a structure of type c_struct.

S.p1 = 20;
S.p2 = 99;
S.p3 = 3;

%
% Create a pointer sp to the structure.

sp = libpointer('c_struct',S);
sp.Value

%
% Pass the pointer to the function.

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

%
% When you pass a pointer, the function modifies the fields in the structure it points to.

sp.Value

%
% Copyright 2015 The MathWorks, Inc.