HRESULT SafeArrayAccessData(
SAFEARRAY FAR* psa,
void HUGEP* FAR* ppvData
);
Increments the lock count of an array, and retrieves a pointer to the array data.
The return value obtained from the returned HRESULT is one of the following.
Return value | Meaning |
---|---|
S_OK | Success. |
E_INVALIDARG | The argument psa was not a valid safe array descriptor. |
E_UNEXPECTED | The array could not be locked. |
The following example sorts a safe array 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);
Windows NT: Use version 3.1 and later.
Windows: Use Windows 95 and later.
Header: Declared in oleauto.h.
Import Library: Link with oleaut32.lib.