An Origin C matrix class is not tied to an internal Origin matrix. You should use an Origin C Matrix class instead, which is tied to an internal Origin matrix, and you can use it to change Matrix Objects. You can change your beginning script as follows.
--------------------------------------------------------------
void matrix_matrix_ex5()
{
MatrixLayer ml;
ml = (MatrixLayer) Project.ActiveLayer();
Matrix m(ml, 0);
int nRows, nCols;
nRows = m.GetNumRows();
nCols = m.GetNumCols();
...
}
--------------------------------------------------------------
Sam
OriginLab Technical Services