Here is some code to help understand what I am asking:
% Allocate Input struct and assign values to it
function MatlabFunction = MatlabFunction(matlabstruct)
% Assume DLL loaded
t = calllib('DLL32', 'AllocateInput');
t.Value.waves = libpointer('doublePtr',matlabstruct.waves);
t.Value.range = libpointer('doublePtr',matlabstruct.range);
t.Value.timeStep = matlabstruct.timeStep;
% Allocate output struct
o = calllib('DLL32', 'AllocateOutput');
% Execute main function, passing t and returning o
errorCode = calllib('DLL32', 'MainFunction', t, o);
if (errorCode ~=0)
errordlg('Call failed', 'Return Code Status');
return;
end
% Set data type of returned struct members in libpointer
setdatatype(o.Value.s, 'doublePtr', o.Value.nS, 1);
setdatatype(o.Value.f, 'doublePtr', o.Value.nF, 1);
setdatatype(o.Value.map, 'doublePtr', o.Value.nS*o.Value.nF, 1);
% Clean up. Do not use DLL's Deallocate and subsequent clear in Matlab, as that causes crash
% calllib('DLL32', 'DeallocateInput', t);
% calllib('DLL32', 'DeallocateOutput', o);
clear t o; % This clears the libpointers, but does not release the memory allocated by DLL
unloadlibrary('DLL32');
return;