COleSafeArray::PutElement
指派唯一的元素至陣列。
void PutElement(
long* rgIndices,
void* pvData
);
參數
rgIndices
物件陣列的指標陣列每個維度的索引。pvData
指派給資料的指標陣列。 VT_DISPATCH、 VT_UNKNOWN和 VT_BSTR 不同類型是指標,而且不需要其他的間接取值。
備註
在指派項目之前或之後,這個函式自動呼叫 Windows 函式 SafeArrayLock 和 SafeArrayUnlock 。 如果資料項目是字串、物件或變數中,函式正確複製該值;如果為現有項目是字串、物件或變數,就會正確地清除。
請注意您可以在陣列中的多個鎖定,因此,您可以將項目陣列,此陣列是由其他作業期間鎖定。
在發生錯誤時,擲回例外狀況 CMemoryException 或 COleException。
範例
VARIANT retVariantArray()
{
COleSafeArray saRet;
DWORD numElements[] = {10, 10}; // 10x10
// Create the 2 dimensional safe-array of type VT_R8 with size 10x10
saRet.Create(VT_R8, 2, numElements);
// Initialize safearray with values...
long index[2];
for(index[0] = 0; index[0] < 10; index[0]++)
{
for(index[1] = 0; index[1] < 10; index[1]++)
{
double val = index[0] + index[1]*10;
//populate the safearray elements with double values
saRet.PutElement(index, &val);
}
}
// Return the safe-array encapsulated in a VARIANT...
return saRet.Detach();
}
需求
Header: afxdisp.h