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

SafeArrayAllocDescriptor Function

Allocates memory for a safe array descriptor.

HRESULT SafeArrayAllocDescriptor(  
  unsigned int  cDims,          
  SAFEARRAY **  ppsaOut  


The number of dimensions of the array.


Pointer to a location in which to store the created array descriptor.

The return value obtained from the returned HRESULT is one of the following.

Return value





The argument ppsaOut was not a valid pointer to a safe array descriptor.


The array could not be locked.

This function allows the creation of safe arrays that contain elements with data types other than those provided by SafeArrayCreate. After creating an array descriptor using SafeArrayAllocDescriptor, set the element size in the array descriptor, an call SafeArrayAllocData to allocate memory for the array elements.

The following example creates a safe array using the SafeArrayAllocDescriptor and SafeArrayAllocData Function functions.

unsigned int ndim =  2;
HRESULT hresult = SafeArrayAllocDescriptor( ndim, &psa );
if( FAILED( hresult ) )
   return ERR_OutOfMemory;
(psa)->rgsabound[ 0 ].lLbound = 0;
(psa)->rgsabound[ 0 ].cElements = 5;
(psa)->rgsabound[ 1 ].lLbound = 1;
(psa)->rgsabound[ 1 ].cElements = 4;
hresult = SafeArrayAllocData( psa );
if( FAILED( hresult ) ) {
   SafeArrayDestroyDescriptor( psa )
   return ERR_OutOfMemory;
© 2016 Microsoft