private static Array CrackSingleDimSafeArray(IntPtr psa)
{
uint cDims = PropVariantNativeMethods.SafeArrayGetDim(psa);
if (cDims != 1)
{
throw new ArgumentException("", "psa");
}
int lBound = PropVariantNativeMethods.SafeArrayGetLBound(psa, 1U);
int uBound = PropVariantNativeMethods.SafeArrayGetUBound(psa, 1U);
int n = uBound - lBound + 1; // uBound is inclusive
object[] array = new object[n];
for (int i = lBound; i <= uBound; ++i)
{
array[i] = PropVariantNativeMethods.SafeArrayGetElement(psa, ref i);
}
return(array);
}