Re: HELP NEEDED convert VARIANT to Double in SAFEARRAY
<ivaynsht@yahoo.com> wrote in message
news:1154994903.273965.289650@i42g2000cwa.googlegroups.com...
Egbert, thanks for response, but I guess you assume here that I send
array of doubles and want to convert it to array of Variant, the
situation is opposite I send array of variants and want to convert it
to double I did try the following:
short __stdcall Single_SafeArray(VARIANT *pv){
double* arr;
...
//Convert to safe_array of type double
VARIANT pv1={0};
pv1.vt=VT_ARRAY|VT_R8;
lResult=SafeArrayCopy(pv->parray,&pv1.parray);
//Assign to one-dimensional array of doubles
lResult=SafeArrayLock(pv1.parray);
arr=(double*)pv1.parray->pvData;
...
}
but it gives me the same result (each even index is junk)
i check that VARTYPE I get from Excel is 12 (Variant) and I have to
convert this to Double
thanks for the help
Ilya
That's rather simple.
Here the idea.
VARIANT v = {0};
v.vt = VT_ARRAY | VT_R8;
hr = SafeArrayCopy(sourceDoubleArray, &v.parray)
etc...
And if you have a non-double-safearray, you should loop throught its
elements and do what Brian suggests.
This is faulty
arr=(double*)pv1.parray->pvData;
As Brian suggests, you must loop! You cannot cast this array.
arr = new double[elements];
VARIANT** ppv = (VARIANT*)pv1.parray->pvData;
for (int cx =0; cx < elements; cx++
{
arr[cx] = ppv[cx].doubleVal;
}