COleSafeArray::PutElement

void PutElement( long* rgIndices, LPVOID pvData );

Parameters

rgIndices

Pointer to an array of indexes for each dimension of the array.

pvData

Pointer to the data to assign to the array. VT_DISPATCH, VT_UNKNOWN, and VT_BSTR variant types are pointers and do not require another level of indirection.

Remarks

Call this function to assign a single element into the array. This function automatically calls the Windows functions SafeArrayLock and SafeArrayUnlock before and after assigning the element. If the data element is a string, object, or variant, the function copies it correctly, and if the existing element is a string, object, or variant, it is cleared correctly.

Note that you can have multiple locks on an array, so you can put elements into an array while the array is locked by other operations.

On error, the function throws a CMemoryException or COleException.

Example

VARIANT _stdcall retVariantArray(void) 
{
   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();
}

COleSafeArray OverviewClass MembersHierarchy Chart

See Also   COleSafeArray::GetElement, SafeArrayPutElement