How can I pass arguments by reference to an ActiveX server from MATLAB 7.0 (R14)?
8 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 28 Nov 2016
I have created an ActiveX server that I instantiate in MATLAB with ACTXSERVER. It appears that MATLAB passes a copy of all data to server methods that I invoke. Instead, I would like to pass data by reference.
Accepted Answer
MathWorks Support Team
on 28 Nov 2016
The default data conversion rules for MATLAB's COM interface specifies that arrays are passed by value.
Beginning with MATLAB 7.0.4 (R14SP2) it is possible to work around the default data conversion rule and have MATLAB pass the array by reference. You can pass SAFEARRAYs to ActiveX servers by reference by executing the following command at the MATLAB prompt:
feature('COM_PassSafeArrayByRef', 1)
Note that setting this feature may break COM interaction with Excel, including Excel Link. If you wish to reset the default behavior of MATLAB of passing all data by value, execute:
feature('COM_PassSafeArrayByRef', 0)
You can also query the current state of this property with the command
feature('COM_PassSafeArrayByRef')
Note on passing Numeric arrays by reference: MATLAB supports passing a VARIANT type by reference to COM object. Since cell arrays are converted as SAFEARRAY of VARIANT's, COM_PassSafeArrayByRef works only with cell arrays. Numeric arrays are passed by reference only if they are marked as [in,out] or [out] in the COM object's IDL file.
More information about the default behavior of the MATLAB COM Interface data conversion is available here:
MATLAB COM Client Support :: COM and DDE Support (Windows Only) (External Interfaces)
<http://www.mathworks.com/help/releases/R14/techdoc/matlab_external/ch07cli5.html?s_tid=srchtitle>
0 Comments
More Answers (0)
See Also
See Also
Categories
Find more on Use COM Objects in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!