Main Content

Convert MATLAB Types to COM Types

Data types for the arguments and return values of the server functions are expressed as Automation data types, which are language-independent types defined by the Automation protocol. For example, BSTR is a wide-character string type defined as an Automation type, and is the same data format used by the Visual Basic® language to store strings. Any COM-compliant client should support these data types, although the details of how you declare and manipulate these types are client specific.

This table shows how MATLAB® converts data from MATLAB to COM types.

MATLAB TypeClosest COM TypeAllowed Types
handleVT_DISPATCH
VT_UNKNOWN
VT_DISPATCH
VT_UNKNOWN
character vector VT_BSTRVT_LPWSTR
VT_LPSTR
VT_BSTR
VT_FILETIME
VT_ERROR
VT_DECIMAL
VT_CLSID
VT_DATE
int16 VT_I2VT_I2
uint16VT_UI2VT_UI2
int32VT_I4VT_I4
VT_INT
uint32VT_UI4VT_UI4
VT_UINT
int64VT_I8VT_I8
uint64VT_UI8VT_UI8
singleVT_R4VT_R4
double VT_R8VT_R8
VT_CY
logicalVT_BOOL VT_BOOL
char VT_I1VT_I1
VT_UI1

Variant Data

variant is any data type except a structure or a sparse array. (For more information, see Fundamental MATLAB Classes.)

When used as an input argument, MATLAB treats variant and variant(pointer) the same way.

If you pass an empty array ([]) of type double, MATLAB creates a variant(pointer) set to VT_EMPTY. Passing an empty array of any other numeric type is not supported.

MATLAB ArgumentClosest COM TypeAllowed Types
variant VT_VARIANTVT_VARIANT
VT_USERDEFINED
VT_ARRAY
variant(pointer)VT_VARIANTVT_VARIANT | VT_BYREF

SAFEARRAY Data

When a COM method identifies a SAFEARRAY or SAFEARRAY(pointer), the MATLAB equivalent is a matrix.

MATLAB ArgumentClosest COM TypeAllowed Types
SAFEARRAYVT_SAFEARRAYVT_SAFEARRAY
SAFEARRAY(pointer) VT_SAFEARRAYVT_SAFEARRAY | VT_BYREF

VT_DATE Data Type

To pass a VT_DATE type input to a Visual Basic program, use the MATLAB class COM.date. For example:

d = COM.date(2005,12,21,15,30,05);
get(d)
     Value: 7.3267e+005
    String: '12/21/2005 3:30:05 PM'

Use the now function to set the Value property to a date number:

d.Value = now;

COM.date accepts the same input arguments as datenum.

Unsupported Types

MATLAB does not support these COM types.

  • String array

  • Structure

  • Sparse array

  • Multidimensional SAFEARRAYs (greater than two dimensions)

  • Write-only properties

See Also

Related Topics