I coded up an xll function receiving a matrix from excel, modifying it a returning it :
__declspec(dllexport) LPXLOPER12 WINAPI ZZZZUpdateArray1(LPXLOPER12 arrayin)
{
if (arrayin->xltype == xltypeMulti | xlbitDLLFree)
{
double ScaleFactor = 2.0;
int rows = arrayin->val.array.rows;
int cols = arrayin->val.array.columns;
static XLOPER12 xlArray;
xlArray.val.array.lparray = reinterpret_cast<LPXLOPER12>(::new XLOPER12[rows * cols] /*::malloc(rows * cols * sizeof(XLOPER12))*/);
for (int r = 0; r<rows; r++)
{
for (int c = 0; c<cols; c++)
{
if ((arrayin->val.array.lparray + ((r* cols) + c))->xltype == xltypeNum)
{
XLOPER12* var = xlArray.val.array.lparray + ((r* cols) + c);
var->xltype = xltypeNum;
var->val.num = ScaleFactor*(arrayin->val.array.lparray + ((r* cols) + c))->val.num ;
}
}
}
return static_cast<LPXLOPER12>(&xlArray);
}
return arrayin;
}
but it crashes on
if ((arrayin->val.array.lparray + ((r* cols) + c))->xltype == xltypeNum)
If I am for instance taking a 5*5 matrix from excel, at debug I see it having 19 rows and 20 colums, what happened !?
Is it maybe because when I receive the LPXLOPER12 arrayin
, it represents an excel range, way more complicated than a 5*5 matrix. How to access the 5*5 matrix it contains, then ?
I took the ujsgeyrr1f0d0d0r0h1h0j0j_juj code´s to make one to test my application. I think it can be useful. I´ve used codes from another references also.
{
}
Q
to register the input argument.You need to declare properly the return variable :