See the question and my original answer on StackOverflow

When using SafeArrayPtrOfIndex there's an extra level of indirection, so you should change your code like this:

void* data;
SafeArrayPtrOfIndex(sa, &idx, &data);

auto disp = *(IDispatch**)data;
disp->AddRef();

Or just use SafeArrayGetElement (and you're supposed to lock the array when using SafeArrayPtrOfIndex):

IDispatch* disp;
SafeArrayGetElement(sa, &idx, &disp);
disp->AddRef();