You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
static int numElements(SAFEARRAY *psa)
{
int nDims = SafeArrayGetDim(psa);
int elems = 0;
for(int i=1;i<=nDims;i++) {
long lb, ub;
SafeArrayGetLBound(psa, i, &lb);
SafeArrayGetUBound(psa, i, &ub);
elems += ub - lb + 1;
}
return elems;
}
This calculation is incorrect, as the number of elements in an mxn array is mxn, not m+n. It happens to be correct in the 1D case only, but not beyond. The effect of this is that fromXXXArray() and toXXXArray() don't work for 2D and higher.
Solution:
static int numElements(SAFEARRAY *psa)
{
int nDims = SafeArrayGetDim(psa);
int elems = 0;
for(int i=1;i<=nDims;i++) {
long lb, ub;
SafeArrayGetLBound(psa, i, &lb);
SafeArrayGetUBound(psa, i, &ub);
if (elems == 0)
elems = 1;
elems *= ub - lb + 1;
}
return elems;
}