LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Arrays and activex...again

I've seen the messages saying that when passing arrays to activex,
they get copied back and passed "down the line", but it's not working
for me.
I'm working on an activeX control(VC 6.0) that wants to copy some
numbers into a labview(or VB, or VC) array. This is that function:

void ACTIVEXCtrl::BufferedSafeArray(const VARIANT FAR& theBuffer)
{
SAFEARRAY* SABuffer; /* gets the hardware buffer */
SABuffer = theBuffer.parray;
/* if this isn't an array of longs, return */
if ( ! ( theBuffer.vt == (VT_ARRAY | VT_I4) ) )
return;
/* if this isn't a one-dimensional array, return */
if ( SafeArrayGetDim(theBuffer.parray) != 1 )
return;
USHORT* normBuffer; /* the sane representation of the array*/
/*lock array for use */
S
afeArrayAccessData(SABuffer, (void **) &normBuffer);
/*copy array */
for ( int i = 0; i < GetBufferSize(); i++)
normBuffer[i] = dBuffer[i];
/*give up control of safearray */
SafeArrayUnaccessData(SABuffer);
}

when running in debug mode in VC, i can see that the array is passed
into the function properly from the invoke node, and it copies the
data into the array properly within the C++ code. But once we're back
in labview, the data is the same as it originally was. I've got an
indicator wired to the output of the invoke node, and it still shows
the original value. This code works FINE when it's being called from
VC or VB. Is it the way I'm accessing the data in the activex
control?

Many Thanx

Sam Skuce
0 Kudos
Message 1 of 2
(2,790 Views)
Maybe you are not handling the safe array properly in LabVIEW. Safe arrays have special structures whichj need to be accounted for in LabVIEW. If LabVIEW does not recognize the data being fed to it, it won't update values correctly.
Here is the structure for a SAFEARRAY:

typedef struct tagSAFEARRAY
{
USHORT cDims;
USHORT fFeatures;
ULONG cbElements;
ULONG cLocks;
PVOID pvData;
SAFEARRAYBOUND rgsabound[ 1 ];
} SAFEARRAY;

So you could make a cluster with these same data types in it, in the same order. A USHORT is an unsigned short (U8), and ULONG is unsigned long (U32) and PVOID is a pointer to the data and SAFEARRAYBOUND is another cluster with this structure:

typedef struct tagSAFEARRAYBOUND
{
ULONG cElements;
LONG lLbo
und;
} SAFEARRAYBOUND;

Here's a web page that describes all the different paramters:

http://msdn.microsoft.com/library/wcedoc/wcemfc/struct_25.htm
0 Kudos
Message 2 of 2
(2,790 Views)