Brian Dumas
asked on
Passing a VARIANT to a COM function and returning it.
I have a C++ class that needs to get information from an oscilloscope for analysis. I have the code that issues the command to the o'scope and can see the o'scope getting the info. Here is that code:
The calling function looks like this:
When I breakpoint in the top function, I can see valid data in the loop:
However, when I exit the called function and return to the calling function, I get an exception. Any ideas why?
Thanks, Brian
void CbeLecroy::GetScaledWF(LCHAN channel, int numpoints, VARIANT* rvals)
{
waveform.Attach(activeDSO->GetScaledWaveform(bCHANNEL[channel], numpoints, 0));
rvals->parray = waveform.parray;
float* pfloatVals;
HRESULT hr;
hr = SafeArrayAccessData(rvals->parray, (void**)&pfloatVals); // direct access to SA memory
if (SUCCEEDED(hr))
{
long lowerBound, upperBound; // get array bounds
SafeArrayGetLBound(rvals->parray, 1, &lowerBound);
SafeArrayGetUBound(rvals->parray, 1, &upperBound);
fvec.clear();
long cnt_elements = upperBound - lowerBound + 1;
for (int i = 0; i < cnt_elements; ++i) // iterate through returned values
fvec.push_back(pfloatVals[i]);
SafeArrayUnaccessData(rvals->parray);
}
// SafeArrayDestroy(psa);
}
The calling function looks like this:
VARIANT rvals;
comLecroy->GetScaledWF(channel, numpoints, &rvals);
When I breakpoint in the top function, I can see valid data in the loop:
for (int i = 0; i < cnt_elements; ++i) // iterate through returned values
fvec.push_back(pfloatVals[i]);
However, when I exit the called function and return to the calling function, I get an exception. Any ideas why?
Thanks, Brian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.