LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I extract data from an OLE variant?

I'm receiving data from a COM server who is supposed to send to me a SAFEARRAY. I could see in a variant indicator that the data is an OLE variant, and its value is :
variant type -> VT_ARRAY|VT_UI1
value -> Array ( Non displayable)
I have tried to extract the safearray with the 'variant to data' function.I have built the Safearray struct in a cluster but this function returns a 'incorrect type' error (code =80020005h). I think there is something bad the way I have built the cluster, possible in the pointer to data or in the rgsabound array because the way Labview stores arrays in memory when they are in a cluster. I enclosed a Vi with two ways I made the cluster.
Message 1 of 8
(5,355 Views)
AOrtin,

Using "Variant to Data", you do not need to convert the variant to a Safearray structure but to the array subtype, which seems to be an array of U8. Input a wire with type array of U8 to the type input of the "Variant to Data" node.


LabVIEW, C'est LabVIEW

Message 2 of 8
(5,349 Views)
See the example below.

The VI uses AvtiveX VI Server to read an array of U8 on its own front panel. The read variant indicator displays

Variant Type -> VT_ARRAY|VT_UI1
Value -> Array(Non Displayable)

This variant is converted using "Variant to Data" with an array of U8 on its type input.


LabVIEW, C'est LabVIEW

Message 4 of 8
(5,349 Views)
Thanks Jean-Pierre,Now with your example VI I Know clearly the way to read the variant but still have a problem. I couldn't read anything because the 'variant to data' function returns an error.I'm very annoyed with this because I don't understand what is wrong.This error only cames when I put an indicator on the 'variant to data', it seems like it couldn't cast to a U8 array, but the variant indicator says clearly it is a U8 array.The error is "Tipo incorrecto" (wrong type) code =80020005h and there is not listed in the internal database. what could be the problem?
Message 5 of 8
(5,349 Views)
AOrtin,

There are two ways you could go about this.

The first would be to create a cluster with the same data types as a SAFEARRAY and use the to G DATA vi.

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 lLbound;
} SAFEARRAYBOUND;

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

http
://msdn.microsoft.com/library/wcedoc/wcemfc/struct_25.htm

The second is possibly the better/easier way to do this. You could write a wrapper DLL in C code that just passes out the array, which is all you really care about. That way you wouldn't need to worry about creating the cluster just right.

Regards,

Cyril Bouton
Applications Engineer
National Instruments
Cyril Bouton
Active LabVIEW Developper
Message 3 of 8
(5,349 Views)

Hi

I'm also having problems extracting data from a safearray.  I've made the cluster according to the struct defined above but am getting a type mismatch error. 

I'm trying to display an image from an Apogee Alta ccd camera and the output of Image Array as stated by the camera documentation is "safearray of Long of size NumX * NumY containing the pixel values from the last exposure - CCDCamera.ImageArray(read only, Long)".

Any help or suggestions would be appreciated!

Thanks,

S

I'll try to attach my vi to this message...

Message 6 of 8
(5,213 Views)

HI,

 

I am having similar problem. I am trying top extract variant data that are described as Safearray of VT_I4 data but no success. I am setting the type of the "Variant to Data" to Cluster containing an array of long (I32). And many other combinations.

 

Any idea?

 

Thanks,

0 Kudos
Message 7 of 8
(4,442 Views)

I was also getting a similar problem. I was getting ': OLE Variant

Variant Type -> VT_ARRAY|VT_VARIANT
Value -> Array(Non Displayable)

in the variant indicator.

I was expecting a 1D array of integers.  When I used Variant to Data VI, I was getting type mismatch error.

Some how, out of the blue, I got an idea of increasing the dimension of the "type" input to the Variant to Data VI (making it a 2D array).  After that, everything worked fine.

0 Kudos
Message 8 of 8
(3,962 Views)