Kennt sich hier jemand mit SafeArray aus? Oder hat jemand zufällig einen Codeschnipsel für PB, oder kann jemand die Beispiele in PB "übersetzen"?
Code: Alles auswählen
Example
The following 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**)&pbstr);
if (FAILED(hr))
goto error;
// Selection sort.
for (i = 0; i < psa->rgsabound.cElements-1; i++)
{
min = i;
for (j = i+1; j < psa->rgsabound.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);
Code: Alles auswählen
Example
The following example is taken from the COM Fundamentals SPoly sample (Cenumpt.cpp) shipped with the Platform SDK.
STDMETHODIMP CEnumPoint::Next(
ULONG celt,
VARIANT FAR rgvar[],
ULONG * pceltFetched)
{
unsigned int i;
long ix;
HRESULT hresult;
for(i = 0; i < celt; ++i)
VariantInit(&rgvar[i]);
for(i = 0; i < celt; ++i){
// Are we at the last element?
if(m_iCurrent == m_celts){
hresult = S_FALSE;
goto LDone;
}
ix = m_iCurrent++;
// m_psa is a global variable that holds the safe array.
hresult = SafeArrayGetElement(m_psa, &ix, &rgvar[i]);
if(FAILED(hresult))
goto LError0;
}
hresult = NOERROR;
LDone:;
if (pceltFetched != NULL)
*pceltFetched = i;
return hresult;
LError0:;
for(i = 0; i < celt; ++i)
VariantClear(&rgvar[i]);
return hresult;
}
Requirements
