byte[] toVariant() throws BSFException {
investigate(arrayObject, 0);
int totalDimSize= maxDimArray[0];
for(int i=1; i < maxDepth; ++i) totalDimSize *= maxDimArray[i];
int mallocSize=16 + // Size of variant.
16 + // The size of a safeArray that follows.
8*maxDepth+ //The size of SAFEARRAYBOUND by the no of dim.
totalDimSize* 16;
byte[] v= new byte[mallocSize ]; //Size of each data item as a Variant.
v[0]= 12; //VT_ARRAY | VT_VARIANT
v[1]= 0x20; //VT_ARRAY
//SAFEARRAY IS PACKED AFTER THE VARIANT
v[16]= (byte)maxDepth; //cDims;
v[17]= (byte)((maxDepth > > >8) & 0xff);
v[18]= (byte) 0X92; //fFeatures = FADF_VARIANT
v[19]= 0X8;
//cbElements= 16 the size of a variant
v[20]= 16;
v[21]=v[22]=v[23]= 0;
//cLocks ??
v[24]=v[25]=v[26]=v[27]= 0;
int i=0, j=32;
//rgsabound[] one for each dimension. Has max no of elements for dim followed by staring base of index.
for(i=maxDepth-1; i >= 0 ; --i) //Kinda stored backward from what I expected.
{
v[j++]= (byte)( maxDimArray[i]);
v[j++]= (byte)((maxDimArray[i] > > >8) & 0xff);
v[j++]= (byte)((maxDimArray[i] > > >16) & 0xff);
v[j++]= (byte)((maxDimArray[i] > > >24) & 0xff);
v[j++]= 0; //Only support starting address of zero
v[j++]= 0;
v[j++]= 0;
v[j++]= 0;
}
//pvData addjusted on C++ side.
v[28]=v[29]=v[30]=v[31]= 0;
v[28]= (byte)(j);
v[29]= (byte)((j > > >8) & 0xff);
v[30]= (byte)((j > > >16) & 0xff);
v[31]= (byte)((j > > >24) & 0xff);
//THE DATA FOR THE SAFEARRAY IS PACKED AFTER IT
//Now for the data which will be a variant for each element. Note strings and true objects will need to be called back.
setVariantData( arrayObject, v, j, 0, new int[ maxDepth]);
return v;
}
|