SafeArrayPutElement
I' m using VC6, i'm writing a dll, that is used by a vb6 application.
i try to create a 2 dimention table that will be sent to vb.
when i use this code it work's fine:
void CreateTableOfVariant(VARIANT* TabAllCombinaison, double**
newRefArray,long NBLigne, long NBColonne)
{
SAFEARRAYBOUND sabound[2]; // 2-D array
SAFEARRAY * psa = NULL; // SAFEARRAY structure pointer
sabound[0].lLbound = 0;
sabound[0].cElements = NBLigne;
sabound[1].lLbound = 0;
sabound[1].cElements = NBColonne;
psa = SafeArrayCreate(VT_R8, 2, sabound );
double* ResData;
SafeArrayAccessData(psa, (void **)&ResData);
long index = 0;
for (long j = 0; j< NBColonne; j++)
for (long i = 0; i < NBLigne; i++ )
{
ResData[index] = newRefArray[i][j];
index++;
}
V_VT(TabAllCombinaison ) = VT_ARRAY | VT_R8;
V_ARRAY(TabAllCombinaison) = psa;
SafeArrayUnaccessData(psa);
}
i try to use SafeArrayPutElement with the table newRefArray.
when i use this code the table in vb does not contain the needed
data(all values are 0)
void CreateTableOfVariant(VARIANT* TabAllCombinaison, double**
newRefArray,long NBLigne, long NBColonne)
{
SAFEARRAYBOUND sabound[2]; // 2-D array
SAFEARRAY * psa = NULL; // SAFEARRAY structure pointer
sabound[0].lLbound = 0;
sabound[0].cElements = NBLigne;
sabound[1].lLbound = 0;
sabound[1].cElements = NBColonne;
psa = SafeArrayCreate(VT_R8, 2, sabound );
long* ix = new long[2];
ix[0] = NBLigne;
ix[1] = NBColonne;
SafeArrayPutElement(psa, ix, &newRefArray);
V_VT(TabAllCombinaison ) = VT_ARRAY | VT_R8;
V_ARRAY(TabAllCombinaison) = psa;
SafeArrayUnaccessData(psa);
}