Windows apps
Collapse the table of content
Expand the table of content

SafeArrayCreate Function

Creates a new array descriptor, allocates and initializes the data for the array, and returns a pointer to the new array descriptor.

SAFEARRAY* SafeArrayCreate(  
  VARTYPE  vt,                     
  unsigned int  cDims,             
  SAFEARRAYBOUND * rgsabound  


The 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.


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


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

Points to the array descriptor, or null if the array could not be created.

The following example demonstrates calling the SafeArrayCreate function.

   SAFEARRAY * psa;
   SAFEARRAYBOUND rgsabound[1];

   rgsabound[0].lLbound = 0;
   rgsabound[0].cElements = 5;
   psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
   if(psa == NULL)
      return E_OUTOFMEMORY;
   // Use the array 
   return NOERROR;
© 2017 Microsoft