public static object[] GetVARIANTs(ref IntPtr pArray, int size, bool deallocate)
{
// this method unmarshals VARIANTs one at a time because a single bad value throws
// an exception with GetObjectsForNativeVariants(). This approach simply sets the
// offending value to null.
if (pArray == IntPtr.Zero || size <= 0)
{
return null;
}
object[] values = new object[size];
IntPtr pos = pArray;
for (int ii = 0; ii < size; ii++)
{
try
{
values[ii] = Marshal.GetObjectForNativeVariant(pos);
values[ii] = ProcessComValue(values[ii]);
if (deallocate) VariantClear(pos);
}
catch (Exception)
{
values[ii] = null;
}
pos = (IntPtr)(pos.ToInt64() + VARIANT_SIZE);
}
if (deallocate)
{
Marshal.FreeCoTaskMem(pArray);
pArray = IntPtr.Zero;
}
return values;
}