LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

OLE VARIANT from COM ActiveX to LabView Variant

Solved!
Go to solution

Hi there!

 

I have an ActiveX COM method (written in C++) which consists of the following definition:

 

HRESULT GrabToArray( [out] VARIANT* output_array );

The method allocates a two-dimensional array of type VT_UI8, ie. 64-bit elements. I can confirm the OLE VARIANT is passed out correctly, containing the 2D array, using a C++ test program. However I'm struggling to do the same in LabView.

 

I am using the Variant to Data function in LabView. The type parameter is an array constant of two dimensions of type U64, and the output parameter is an array object of two dimensions of type U64. It looks like this:

 

labview_grabtoarray_layout.png

The Variant Indicator reports VT_EMPTY, which I don't understand:

 

labview_variant_indicator.png

 

And then the Variant to Data function obviously fails and reports a type mismatch.

 

I'm confident the VARIANT should contain the array, as I can debug the method in Visual Studio and see it successfully passed out in C++:

 

labview_variant_array.png

 

This makes me think I'm doing something wrong in LabView - where am I going wrong?

 

Many thanks,

Paul

0 Kudos
Message 1 of 4
(2,784 Views)
Solution
Accepted by topic author pmulvey

Just in case anybody else has this problem, I've managed to figure out what was going wrong. The issue was the way in which the OLE VARIANT VARTYPE vt parameter was set. This was originally set to VT_ARRAY, the fix was to OR this with VT_UI8:

 

output_array->vt = VT_ARRAY | VT_UI8;

LabView then successfully interops the 64-bit two-dimensional array:

 

labview_variant_indicator_correct.png

0 Kudos
Message 2 of 4
(2,717 Views)

VT_ARRAY alone is not a valid OLE variant datatype. It is only a flag that indicates to the variant observer that there is really a SAFEARRAY of a specific datatype inside the variant. Without any of the other VT_xxx datatypes it's basically simply an array of nothing.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 4
(2,710 Views)

Thanks Rolf, I understand. Microsoft are probably a bit looser about this, presumably that's why it was still successful in the Visual Studio compiler, whilst LabView seems to be stricter. Whether that strictness is correct or not I cannot confirm, documentation on this specific scenario is a bit sparse from both MS and National Instruments. The underlying SAFEARRAY has its own vt datatype parameter which was set to VT_UI8, and I expect that's how the MS environment is able to pull it all together.

 

Just one of those things - now I know the answer!

0 Kudos
Message 4 of 4
(2,701 Views)