1

I am learning Microsoft OLE Automation and COM and it use VARIANT to pass data. I have read that it is union data structure but did not find enough information regarding this.

It would be helpful to me understand more about VARIANT as I am new to Automation and COM ?

Mehul Donga
  • 105
  • 3
  • 14
  • Just a universal variable type, it can store any kind of value. Could be an int or a string or an array, etcetera. Compare to Boost.Variant, exact same idea. – Hans Passant Mar 10 '16 at 10:34

2 Answers2

4

COM Automation defines a set of types that it knows how to marshal through thread or process boundaries.

It means there is no need for custom proxy/stubs if you restrict your interfaces to use only those types, and you describe your interface with a type library (most development tools, such as Visual Studio, do that automatically).

Those types are described here: VARENUM Enumeration.

The VARIANT type is itself an automation type, it's a struct that can contain any one of the other automation types.

COM Automation appeared with the Visual Basic development environment (up to version 6, before VB.NET). VB/VBA defines the same types (including Variant).

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
2

A VARIANT is 16 bytes long. The first two bytes define the data type that the variant holds:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms221170(v=vs.85).aspx

The second half of the VARIANT holds the variable’s content. For more informations:

https://msdn.microsoft.com/en-gb/library/windows/desktop/ms221627(v=vs.85).aspx

Florent B.
  • 41,537
  • 7
  • 86
  • 101