//Create the SAFEARRAY from the VARIANT ret.
COleSafeArray sa(ret);
//Determine the array's dimensions.
long lNumRows;
long lNumCols;
sa.GetUBound(1, &lNumRows);
sa.GetUBound(2, &lNumCols);
//Display the elements in the SAFEARRAY.
long index[2];
VARIANT val;
int r, c;
TRACE("Contents of SafeArray\n");
TRACE("=====================\n\t");
for(c=1;c<=lNumCols;c++)
{
TRACE("\t\tCol %d", c);
}
TRACE("\n");
for(r=1;r<=lNumRows;r++)
{
TRACE("Row %d", r);
for(c=1;c<=lNumCols;c++)
{
index[0]=r;
index[1]=c;
sa.GetElement(index, &val);
switch(val.vt)
{
case VT_R8:
{
TRACE("\t\t%1.2f", val.dblVal);
break;
}
case VT_BSTR:
{
TRACE("\t\t%s",(CString)val.bstrVal);
break;
}
case VT_EMPTY:
{
TRACE("\t\t<empty>");
break;
}
}
}
TRACE("\n");
}