LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I extract data from an OLE variant?

I am trying to retrieve a string from a Dot Net function.  What I get out is a Labview variant.

From my research, I suspect that what Labview is giving me in this variant is a pointer to the string that I need to dereference.  Problem is that I can't even get the pointer value out of the variant.

If I view the variant as an indicator, I see that it has a value but no matter what type I wire to the Variant to Data function, I get a type mismatch error.

The value is there, why can't Labview give it to me?

 

Clipboard02.gif

 

0 Kudos
Message 1 of 9
(4,027 Views)

Have you tried the Variant to Data function (found on the Variant sub-Palette of the Cluster Palette)?  You need to know (and have as a constant) the type of the output you expect (which seems to be VT_Dispatch).  I'm not sure that will help you much, as I can't easily find what VT_Dispatch is ...

0 Kudos
Message 2 of 9
(4,009 Views)

VT_DISPATCH means that the variant in fact contains an object interface pointer of type IDispatch. You need to find out what object type this refers to and then convert this variant into an Automation refnum of the underlaying object atatype (or a compatible/derived one).

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 9
(4,001 Views)

Yes, I agree this is a pointer to the data I want.   Looking at the .net refnum in Labvew its type is VBA._Collection. The method I get has an index input and outputs the variant reference to a string.

Can you offer any suggestions as to how I could construct an automation refnum?  Or find a collection of refnums I could sift through and test?

 

So far I have been able to extract some data from the variant using the MoveBlock function from LABVIEW.dll but not sure where to go from there. 

I can get the number that appears in the variant indicator but this looks like a U32. I tried to then use this number as the source address with MoveBlock but I don't find anything that looks like a string at that address.  Now I am doubting this is a pointer.  It is only 32 bits but I think a pointer should be 64 bits??

0 Kudos
Message 4 of 9
(3,972 Views)

MoveBlock() won't help you here much. VT_DISPATCH indeed contains a pointer, but not a pointer to data but instead a pointer to an IDispatch COM object. This is basically a pointer to an object containing internally one (and typically more) so called COM virtual method dispatch tables. The only safe way to get at the information is by using the COM QueryInterface() method in that object to retrieve the IDispatch interface, then calling the IDispatch methods to inspect the data contents the object contains and then retrieving the actual data.

 

This is impossible to do on your own in a LabVIEW diagram but requires quite a bit of C(++) code. However if you know what the IDispatch is really holding internally (and your VBA.ICollection sounds like a plausible idea) then you can create a compatible Automation refnum by dropping one on your front panel and then browsing to the according ActiveX object type (here most like in the Visual Basic typelibrary) and then using Variant to Data, let LabVIEW comvert the contained IDispatch to the actual Automation refnum to the data object. Variant to Data will return an error if you selected the wrong ActiveX refnum type.

 

An VBA.ICollection is however not a string or numeric data already but more like an Array like container, so you would then have to use the VBA.ICollection methods to enumerate the elements in it as variants and convert them to the actual datatype using Variant to Data again.

 

Also note that pointers are 32 bit in LabVIEW 32 Bit and 64 bit in LabVIEW for 64 bit. This is independent if you run on 32 bit or 64 bit Windows, since a 32 Bit version of LabVIEW runs in a 32 bit environment even on 64 bit Windows.

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 9
(3,956 Views)

Getting pretty close to giving up on labview here but...

I can index the individual elements of the "VBA._Collection" but still unable to find something to allow access to the string.

Clipboard03.gif

 

I have sample C++ snippets from the SDK help where the "items" are converted to strings using the following code:

Convert.ToString(H_RecordSet.Fields["Value"].Value)

I have tried a few .tlb and .dll files but none so far containing useful type references.

Any thoughts as to where to look? 

 

0 Kudos
Message 6 of 9
(3,918 Views)

Getting pretty close to giving up on labview here but...

I can index the individual elements of the "VBA._Collection" but still unable to find something to allow access to the string.

Clipboard03.gif

 

I have sample C++ snippets from the SDK help where the "items" are converted to strings using the following code:

Convert.ToString(H_RecordSet.Fields["Value"].Value)

I have tried a few .tlb and .dll files but none so far containing useful type references.

Any thoughts as to where to look? 

 

0 Kudos
Message 7 of 9
(3,918 Views)
you succeeded?
 
0 Kudos
Message 8 of 9
(3,315 Views)

Are you still having issues with this?

0 Kudos
Message 9 of 9
(3,303 Views)