Share via


COleSafeArray::GetElement

Recupera un único elemento de la matriz segura.

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

Parámetros

  • rgIndices
    Puntero a una matriz de índices para cada dimensión de la matriz.

  • pvData
    Puntero a la ubicación para colocar el elemento de matriz.

Comentarios

Esta función llama automáticamente a las funciones de ventanas SafeArrayLock y SafeArrayUnlock antes y después de recuperar el elemento.Si el elemento de datos es una cadena, un objeto, o un tipo Variant, la función copia el elemento de la manera correcta.El parámetro pvData debe señalar suficientemente grande a un búfer para contener el elemento.

Por error, la función produce CMemoryException o COleException.

Ejemplo

//sa is of type COleSafeArray with 2 dimensions

//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 lower bounds for both dimensions
long lowRow, lowCol;
sa.GetLBound(1, &lowRow);
sa.GetLBound(2, &lowCol);

for(long r = lowRow; r <= lNumRows; r++ )
{
   for(long c = lowCol; 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(_T("%1.2f\n"), val.dblVal);
         break;

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

      // other cases ommitted

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

Requisitos

encabezado: afxdisp.h

Vea también

Referencia

Clase de COleSafeArray

Gráfico de jerarquía

COleSafeArray::PutElement