Udostępnij za pośrednictwem


COleSafeArray::GetElement

Pobiera pojedynczego elementu tablicy bezpiecznej.

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

Parametry

  • rgIndices
    Wskaźnik do tablicy indeksów dla każdego wymiaru tablicy.

  • pvData
    Wskaźnik do lokalizacji, aby umieścić element tablicy.

Uwagi

Ta funkcja automatycznie wywołuje funkcje windows SafeArrayLock i SafeArrayUnlock przed i po pobraniu elementu.Jeśli element danych jest ciąg, obiektu lub wariant, funkcja kopiuje element w prawidłowy sposób.Parametr pvData powinien wskazywać na duży wystarczająco bufor zawiera element.

Na błąd, funkcja generuje CMemoryException lub COleException.

Przykład

//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;
      }
   }
}

Wymagania

Nagłówek: afxdisp.h

Zobacz też

Informacje

Klasa COleSafeArray

Wykres hierarchii

COleSafeArray::PutElement