www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ShrlibPassPointerOfTypeDoubleExample.m

    %% Pass Pointer of Type double
% This example shows how to construct and pass a pointer to C function |multDoubleRef|. 
% 
% Load the library containing the function.

% Copyright 2015 The MathWorks, Inc.


if not(libisloaded('shrlibsample'))
    addpath(fullfile(matlabroot,'extern','examples','shrlib'))
    loadlibrary('shrlibsample')
end
%% 
% Construct a pointer, |Xptr|, to the input argument, |X|.

X = 13.3;
Xptr = libpointer('doublePtr',X);
%% 
% Verify the contents of |Xptr|.

get(Xptr)
%% 
% Call the function and check the results.

calllib('shrlibsample','multDoubleRef',Xptr);
Xptr.Value
%% 
% |Xptr| is a handle object. Copies of this handle refer to the same 
% underlying object and any operations you perform on a handle object affect all 
% copies of that object. However, |Xptr| is not a C language pointer. Although 
% it points to |X|, it does not contain the address of |X|. The function modifies 
% the Value property of |Xptr| but does not modify the value in the underlying object 
% |X|. The original value of |X| is unchanged.

X