XLL+ Class Library (7.0)

Matrix arguments

Passing 2-dimensional arrays to C/C++ functions

This topic shows you how to read 2-dimensional arrays from Excel, and pass them on to C/C++ functions.

There is no standard way to pass 2-dimensional data to a C/C++ function. With 1-dimensional data (vectors) it is simple: pass a pointer to the array, and the size of the array. (Or, in STL conventions, pass iterators for the start and end of the array.)

To pass a matrix to a C/C++ function, there are several options. You may be expected to keep all the data in a single continuous block, or you may be expected to pass an array of pointers, each of which points to an array. In addition, the data may be arranged row-wise or column-wise.

The imtx<T> template class

Since there is no STL container for 2-dimensional data, the class library contains the imtx<T> interface and related template classes.

Note: Unlike the other classes in the library, it follows STL conventions, using lower case and underscores. The other classes in the library all follow Microsoft C++ conventions (mixed case, class names preceded by 'C', member variables prefixed by 'm_' and their type).

The imtx classes handle all the data storage issues referred to above, and cooperate with the STL vector class to help you pass data to C/C++ functions easily.

Other matrix classes

Any other matrix class can be handled by providing an adapter class. Examples are provided for the boost::multi_array class and for the deprecated xlp::matrix<T> class. For details of adapter classes, see Adapter classes for imtx<T>.

The matrix<T> template class

The matrix<T> class was provided as standard in early versions of XLL+. This class is now deprecated and has been replaced by the imtx<T> classes. Any code that uses the class will continue to work, because of the adapter class provided.

Next: Two-dimensional linear interpolation function >>