User`s guide
A Producing a COM Object from MATLAB
A-8
Producing a COM Class
Producing a COM class requires the generation of a class definition file in
Interface Description Language (IDL) as well as the associated C++ class
definition/implementation files. (See the Microsoft COM documentation for a
complete discussion of IDL and C++ coding rules for building COM objects.)
The builder automatically produces the necessary IDL and C/C++ code to build
each COM class in the component. This process is generally transparent to the
user.
As a final step, the builder produces a Visual Basic function wrapper for each
method, used to implement an Excel formula function. Formula functions are
useful when calling a method that returns a single scalar value with one or
more inputs. Use a general Visual Basic subroutine when calling a method that
returns array data or multiple outputs.
IDL Mapping
The most generic MATLAB M-function is
function [Y1, Y2, , varargout] = foo(X1, X2, , varargin)
This function maps directly to the following IDL signature.
HRESULT foo([in] long nargout,
[in,out] VARIANT* Y1,
[in,out] VARIANT* Y2,
.
.
[in,out] VARIANT* varargout,
[in] VARIANT X1,
[in] VARIANT X2,
.
.
[in] VARIANT varargin);
This IDL function definition is generated by producing a function with the
same name as the original M-function and an argument list containing all
inputs and outputs of the original plus one additional parameter,
nargout.
(
nargout is not produced if you compile an M-function containing no outputs.)
When present, the
nargout parameter is an [in] parameter of type long. It is
always the first argument in the list. This parameter allows correct passage of
the MATLAB
nargout parameter to the compiled M-code. Following the