Partager via


SafeArrayAccessData

This function increments the lock count of an array, and retrieves a pointer to the array data.

HRESULT SafeArrayAccessData( 
  SAFEARRAY FAR* psa, 
  void HUGEP* FAR* ppvData 
); 

Parameters

  • psa
    [in] Pointer to an array descriptor created by SafeArrayCreate.
  • ppvData
    [in] On exit, pointer to a pointer to the array data.

Return Values

The following table shows the HRESULT values that can be returned by this function.

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

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

Example

The following code example sorts a safearray of one dimension that contains BSTRs by accessing the array elements directly. This approach is faster than using SafeArrayGetElement and SafeArrayPutElement.

long i, j, min; 
BSTR BSTRTemp;
BSTR HUGEP *pBSTR;
HRESULT hr;

// Get a pointer to the elements of the array.
hr = SafeArrayAccessData(psa, (void HUGEP* FAR*)&pBSTR);
if (FAILED(hr))
goto error;

// Bubble sort.
cElements = lUBound–lLBound+1; 
for (i = 0; i < cElements–1; i++)
{
  min = i;
  for (j = i+1; j < cElements; j++)
  {
    if (wcscmp(pBSTR[j], pBSTR[min]) < 0)
      min = j; 
  }

  // Swap array[min] and array[i].
  BSTRTemp = pBSTR[min];
  pBSTR[min] = pBSTR[i];
  pBSTR[i] = BSTRTemp;

}

SafeArrayUnaccessData(psa);

Requirements

OS Versions: Windows CE 2.0 and later.
Header: Oleauto.h.
Link Library: Oleaut32.lib.

See Also

SafeArrayCreate | SafeArrayGetElement | SafeArrayPutElement

Last updated on Wednesday, April 13, 2005

© 2005 Microsoft Corporation. All rights reserved.