COleSafeArray::GetElement
안전 배열의 단일 요소를 검색합니다.
void GetElement(
long* rgIndices,
void* pvData
);
매개 변수
rgIndices
배열 인덱스 배열의 각 차원에 대 한 포인터입니다.pvData
배열의 요소를 배치할 위치에 포인터입니다.
설명
이 함수는 자동으로 windows 함수 호출 SafeArrayLock 및 SafeArrayUnlock 전과 후의 요소를 검색 합니다. 데이터 요소가 string, object 또는 variant 이면 함수는 올바른 방법에 요소를 복사 합니다. 매개 변수는 pvData 충분 한 버퍼의 요소를 포함 하는 큰 가리켜야 합니다.
함수에서 오류를 throw 한 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