COleSafeArray::GetElement

更新 : 2007 年 11 月

セーフ配列の 1 つの要素を取得します。

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

パラメータ

  • rgIndices
    配列の各次元のインデックスが格納された配列へのポインタ。

  • pvData
    配列の要素が置かれるバッファへのポインタ。

解説

この関数は、要素取得の前後で、Windows の関数 SafeArrayLockSafeArrayUnlock を自動的に呼び出します。データ要素が文字列、オブジェクト、またはバリアントの場合、関数は要素をその型に従ってコピーします。pvData パラメータには、要素を入れるのに十分な大きさのバッファを指定する必要があります。

エラーの場合、関数は CMemoryException または COleException をスローします。

使用例

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

必要条件

ヘッダー : afxdisp.h

参照

参照

COleSafeArray クラス

階層図

COleSafeArray::PutElement

SafeArrayGetElement

その他の技術情報

COleSafeArray のメンバ