SafeArrayAllocDescriptor function (oleauto.h)

Allocates memory for a safe array descriptor.

Syntax

HRESULT SafeArrayAllocDescriptor(
  [in]  UINT      cDims,
  [out] SAFEARRAY **ppsaOut
);

Parameters

[in] cDims

The number of dimensions of the array.

[out] ppsaOut

The safe array descriptor.

Return value

This function can return one of these values.

Return code Description
S_OK
Success.
E_INVALIDARG
The argument psa was not valid.
E_UNEXPECTED
The array could not be locked.

Remarks

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, a call SafeArrayAllocData to allocate memory for the array elements.

Examples

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

SAFEARRAY *psa;
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;
}

Requirements

Requirement Value
Target Platform Windows
Header oleauto.h
Library OleAut32.lib
DLL OleAut32.dll

See also

SafeArrayAllocData

SafeArrayDestroyData

SafeArrayDestroyDescriptor