XLL+ Class Library

Matrix arguments

Passing 2-dimensional arrays to 'C' functions

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

There is no standard way to pass 2-dimensional data to a '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 pointers to the start and end of the array.)

To pass a matrix to a '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' functions easily.

The matrix<T> template class

The matrix<T> class was provided as standard in earlier 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.

Next: Two-dimensional linear interpolation function >>