Dear Users;
Sorry if this is a repeat question - I could not find relevant code in the faq.
I have an activeX control which contains a method (PassArray) which accepts an array, and modifies its contents... The array *seems* to be correctly passed in, and I can make the modifications to the data. The data is then passed back out... In labview I use the Variant -> Data object to return the underlying dataset. However all my modifications are lost. (Sample code below).
Ie: it seems Labview is passing me a copy of the original data, and does not accept that changes have occured. When I create a method which returns a variant containing a new array (ReturnArray), everything works properly. Does this occur because methods use 'const' keywords for parameters? Is there a solution where labview accepts that the data has changed?
Any hints would be useful...
thanks,
Marc
VARIANT CAcxLVArrayCtrl::ReturnArray(short Lendth)
{
VARIANT vaResult;
VariantInit(&vaResult);
// TODO: Add your dispatch handler code here
// Ok use this code to generate an array based upon size of Lendth.
double* lpusBuffer;
//Assigns the Variant to hold an array of doubles (real 8-byte numbers)
vaResult.vt = VT_ARRAY | VT_R8;
SAFEARRAYBOUND rgsabound[1];
//Set bounds of array
rgsabound[0].lLbound = 0; //Lower bound
rgsabound[0].cElements = Lendth; //Number of elements
//Create the safe array of doubles, with the specified bounds, and only 1 dimension
vaResult.parray = SafeArrayCreate( VT_R8, 1, rgsabound );
SafeArrayAllocData( vaResult.parray );
SafeArrayAccessData( vaResult.parray, (void**)&lpusBuffer );
//Fill in the buffer
for( int i=0; i
{
*(lpusBuffer + i ) = i + 1;
}
SafeArrayUnaccessData( vaResult.parray );
return vaResult;
}
short CAcxLVArrayCtrl::PassArray(const VARIANT FAR& ArrayInOut)
{
// TODO: Add your dispatch handler code here
long LowerBound, UpperBound, cbElements;
if(ArrayInOut.vt != (VT_ARRAY | VT_I4))
{
MessageBox("Data is not an array of Longs");
return -1;
}
if(SafeArrayGetDim(ArrayInOut.parray) != 1)
{
MessageBox("Data must be a 1D array");
return -1;
}
SafeArrayGetLBound(ArrayInOut.parray, 1, &LowerBound);
SafeArrayGetUBound(ArrayInOut.parray, 1, &UpperBound);
if( (UpperBound - LowerBound) = 0)
{
MessageBox("Data array is not initialised");
return -1;
}
long* lpusBuffer;
SafeArrayAccessData( ArrayInOut.parray, (void**)&lpusBuffer );
//Fill in the buffer
for( int i=LowerBound; i
{
*(lpusBuffer + i ) = i + 1;
}
SafeArrayUnaccessData( ArrayInOut.parray );
return 0;
}