COleSafeArray::GetElement

void GetElement( long* rgIndices, void* pvData );

Parameters

rgIndices

Pointer to an array of indexes for each dimension of the array.

pvData

Pointer to the location to place the element of the array.

Remarks

Call this function to retrieve a single element of the safe array. This function automatically calls the windows functions SafeArrayLock and SafeArrayUnlock before and after retrieving the element. If the data element is a string, object, or variant, the function copies the element in the correct way. The parameter pvData should point to a large enough buffer to contain the element.

On error, the function throws a CMemoryException or COleException.

Example

//sa is of type COleSafeArray with 2 dimensions
COleSafeArray sa;

//Determine upper bounds for both dimensions
long lNumRows;
long lNumCols;
sa.GetUBound(1, &lNumRows);
sa.GetUBound(2, &lNumCols);

//Display the elements in the SAFEARRAY.
long index[2];
VARIANT val;

//Determine upper bounds for both dimensions
long r, c;
sa.GetLBound(1, &r);
sa.GetLBound(2, &c);

for(;r <= lNumRows; r++ )
{
   for(; c <= lNumCols; c++ )
   {
      index[0]=r;
      index[1]=c;

      //retrieve each element of the safearray
      sa.GetElement(index, &val);

      switch(val.vt)
      {
      case VT_R8:
         TRACE("%1.2f\n", val.dblVal);
         break;

      case VT_BSTR:
         TRACE("%s\n",(CString)val.bstrVal);
         break;

      ...
      ...

      case VT_EMPTY:
         TRACE("<empty>\n");
         break;
      }
   }
}

COleSafeArray OverviewClass MembersHierarchy Chart

See Also   COleSafeArray::PutElement, SafeArrayGetElement