Compartilhar via


COleSafeArray::CreateOneDim

Creates a new one-dimensional COleSafeArray object.

void CreateOneDim( 
   VARTYPE vtSrc, 
   DWORD dwElements, 
   const void* pvSrcData = NULL, 
   long nLBound = 0  
);

Parameters

  • vtSrc
    The base type of the array (that is, the VARTYPE of each element of the array).

  • dwElements
    Number of elements in the array. This can be changed after the array is created with ResizeOneDim.

  • pvSrcData
    Pointer to the data to copy into the array.

  • nLBound
    The lower bound of the array.

Remarks

The function allocates and initializes the data for the array, copying the specified data if the pointer pvSrcData is not NULL.

On error, the function throws a CMemoryException.

Example

VARIANT varColInfo[3];

//initialize VARIANTs 
for (int i = 0; i < 3; i++)
   VariantInit(&varColInfo[i]);

// Column Name
varColInfo[0].vt = VT_BSTR;
varColInfo[0].bstrVal = ::SysAllocString(L"Name");

// Column Type
varColInfo[1].vt = VT_UI4;
varColInfo[1].lVal = 1;

COleSafeArray sa;
//create a 1 dimensional safearray of VARIANTs 
//& initialize it with varColInfo VARIANT array
sa.CreateOneDim(VT_VARIANT, 2, varColInfo);

//check that the dimension is 2
ASSERT(sa.GetOneDimSize() == 2);

//increase safearray size by 1
sa.ResizeOneDim(3);

// populate the last element of the safearray, (Column Size)
varColInfo[2].vt = VT_I4;
varColInfo[2].lVal = 30;
long el = 2;
sa.PutElement(&el, &varColInfo[2]);

Requirements

Header: afxdisp.h

See Also

Reference

COleSafeArray Class

Hierarchy Chart

COleSafeArray::GetOneDimSize

COleSafeArray::ResizeOneDim

COleSafeArray::Create