Problems with CComSafeArrays
Hey guys, I am trying to make use of a 3rd party API which makes use
of variants to pass arguments in. Unfortunately, I have not had much
experience with variants.
What I have implemented seems to be resulting in some exceptions,
which may be a problem with what I am passing on the 3rd party API
side, or it may be a problem with how I created my variants. I wanted
to get confirmation that how I created my safe arrays looks correct.
I continually get the same error (which is currently caught in the
exception handling below..see comment below).
My code looks as follows:
---------------------
_variant_t vt;
CComSafeArrayBound bounds[1]; // 1 column
bounds[0].SetCount(2); // 2 rows
DWORD numElements[] = {1, 2}; // 1x2 array (single position)
CComSafeArray<double> saR(bounds, 1);
long index[2]; // used to identify the position in an array
double dValue;
// at (0,0)
index[0] = 0; index[1] = 0; dValue = 11.0;
saR.MultiDimSetAt(index, dValue);
// at (0,1)
index[1] = 1; dValue = -22.6789;
saR.MultiDimSetAt(index, dValue);
VariantInit(&vt);
vt.vt = VT_ARRAY | VT_R8;
vt.parray = saR;
try {
//makes a call with vt as attribute in 3rd party API
} catch ( _com_error e) {
// catches a first-chance exception with an Access violation
}
-------------------
Any help is greately appreciated.