SafeArrayCreate

This function creates a new array descriptor, allocates and initializes the data for the array, and returns a pointer to the new array descriptor.

At a Glance

Header file: Oleauto.h
Windows CE versions: 2.0 and later

Syntax

HRESULT SafeArrayCreate( VARTYPE vt, unsigned int cDims, SAFEARRRAYBOUND FAR* rgsabound);

Parameters

vt

Base type of the array (the VARTYPE of each element of the array). The VARTYPE is restricted to a subset of the variant types. Neither the VT_ARRAY nor the VT_BYREF flag can be set. VT_EMPTY and VT_NULL are not valid base types for the array. All other types are legal.

cDims

Number of dimensions in the array. The number cannot be changed after the array is created.

rgsabound

Pointer to a vector of bounds (one for each dimension) to allocate for the array.

Return Values

A pointer to the array descriptor indicates success. NULL indicates that the array could not be created.

Remarks

Passing into this function any invalid and, under some circumstances, NULL pointers will result in unexpected termination of the application.

Example

HRESULT PASCAL __export CPoly::EnumPoints(IEnumVARIANT FAR* FAR* ppenum)
{
   unsigned int i;
   HRESULT hresult;
   VARIANT var;
   SAFEARRAY FAR* psa;
   CEnumPoint FAR* penum;
   POINTLINK FAR* ppointlink;
   SAFEARRAYBOUND rgsabound[1];
   rgsabound[0].lLbound = 0;
   rgsabound[0].cElements = m_cPoints;
   psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
   if(psa == NULL){HRESULT = ReportResult(0, E_OUTOFMEMORY, 0, 0);
      goto LError0}

   // Code omitted here for brevity.

LError0:;
   return hresult;
}