I have COM object, which I initialize it at once:
ISTIPositionPtr _position;
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
_position.CreateInstance(__uuidof(STIPosition));
Next I have function, that invoke method of this COM object:
LPSAFEARRAY saValues;
structSTIPositionUpdate* pVals;
long count;
float sum = 0;
if (SUCCEEDED(_position->GetPositionList(&saValues, &count))) {
if (SUCCEEDED(SafeArrayAccessData(saValues, (void**)&pVals))) {
for (int i = 0; i < count; ++i) {
sum += pVals[i].fDollarsBot;
}
SafeArrayUnaccessData(saValues);
}
SafeArrayDestroy(saValues);
}
return sum;
Problem is that the method:
_position->GetPositionList(&saValues, &count)
Return correct value or zero. but if I invoke function with pause intervals, then all works fine. I don't know, probably this is asynchronous method and I must use some mechanisms, that wait until method will be finished?
For example:
long count = 0;
while (count == 0) {
_position->GetPositionList(&saValues, &count)
}
I found that is need to initialize saValues:
LPSAFEARRAY saValues = NULL;
and then all works as expected.