Share via


SafeArrayAllocDescriptor (Compact 2013)

3/26/2014

This function allocates memory for a safearray descriptor, allowing the creation of safearrays that contain elements with data types other than those provided by SafeArrayCreate.

Syntax

HRESULT SafeArrayAllocDescriptor( 
  unsigned int cDims, 
  SAFEARRAY FAR* FAR* ppsaOut 
); 

Parameters

  • cDims
    [in] Number of dimensions of the array.
  • ppsaOut
    [out] Pointer to a location in which to store the created array descriptor.

Return Value

Returns the HRESULT values shown in the following table.

Value

Description

S_OK

Success.

E_INVALIDARG

The psa parameter was not a valid safearray descriptor.

E_UNEXPECTED

The array could not be locked.

Remarks

This function allows the creation of safearrays 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 and call SafeArrayAllocData to allocate memory for the array elements.

Passing invalid (and under some circumstances NULL) pointers to this function causes an unexpected termination of the application.

Example

The following code example creates a safearray using the SafeArrayAllocDescriptor and SafeArrayAllocData functions.

Important

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

SAFEARRAY FAR* FAR*ppsa;
unsigned int ndim = 2;
HRESULT HRESULT = SafeArrayAllocDescriptor( ndim, ppsa );
if( FAILED( HRESULT ) )
  return ERR_OutOfMemory;
(*ppsa)->rgsabound[ 0 ].lLbound = 0;
(*ppsa)->rgsabound[ 0 ].cElements = 5;
(*ppsa)->rgsabound[ 1 ].lLbound = 1;
(*ppsa)->rgsabound[ 1 ].cElements = 4;
HRESULT = SafeArrayAllocData( *ppsa );
if( FAILED( HRESULT ) ) {
  SafeArrayDestroyDescriptor( *ppsa )
  return ERR_OutOfMemory;
}

Requirements

Header

oleauto.h

Library

oleaut32.lib

See Also

Reference

Automation Functions
SafeArrayAllocData
SafeArrayDestroyData
SafeArrayDestroyDescriptor