Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

how can i get two channels' sample data using CWAI

i use cwai control sample two channels' data.
when finished, use function get data as followed:
OnAcquiredDataCwai1(VARIANT FAR* ScaledData, VARIANT FAR* BinaryCodes)
now, i know the data that i want to get are in VARIANT FAR* ScaledData , i know it is a 2d array.
and i donn't know how can i save variant data to myself double array .
0 Kudos
Message 1 of 2
(2,809 Views)
Hello eyver,

You are correct that the VARIANT FAR* ScaledData parameter contains a 2D array. In Visual C++, this is a SAFEARRAY datatype, so you can deal with it as you would any other VARIANT containing a 2D-SAFEARRAY:

// Get the pointer to the 2D-SAFEARRAY which is stored in the VARIANT ScaledData.
SAFEARRAY* parray = ScaledData->parray;
double dbl;
HRESULT hresult;

// Get the value out of the SAFEARRAY stored at element 0,0 (0 = first channel, 0 = value index)
long indices[2] = { 0,0 };
hresult = SafeArrayGetElement(parray, indices, &dbl);
if FAILED(hresult) {
// handle error here
return;
}

// Now get the value out of the SAFEARRAY stored at element 1,10 (1 = second channel, 10 = value index)
long indices2[2] = { 1,10 };

hresult = SafeArrayGetElement(parray, indices2, &dbl);
if FAILED(hresult) {
// handle error here
return;
}

Microsoft Visual C++ provides other SAFEARRAY functions to you, including SafeArrayGetLBound, SafeArrayGetUBound, and SafeArrayCopy, which you can learn more about at http://msdn.microsoft.com.


David Mc.
NI Applications Engineering
0 Kudos
Message 2 of 2
(2,808 Views)