I'm having a question about when it is necessary to use SafeArrayAccessData to lock a SAFEARRAY, which is passed by managed code. Here is our code. The VARIANT is passed by managed code, with a string array. During code review, somebody suggest to use SafeArrayAccessData/SafeArrayUnAccessData. But he is not sure about why and what's the benefit. Can you share some of your experiences? Thanks!
STDMETHODIMP Base::Method1(VARIANT values, VARIANT_BOOL result)
{
CComSafeArray<BSTR> ids;
ids.Attach(values.parray);
unsigned int size = ids.GetCount();
for(unsigned int i = 0; i < size; ++i)
{
// use ids[i] here
}
// ...
}