Win32::OLE::Variant

All automation data has to be coerced into a special type called a Variant. Most of the time, you don’t need to worry about explicit type coercion. You just provide your scalar data, and the magic of automation takes care of the rest. However, there are times when you want to control the exact type of data you’re sending to the automation server. The Win32::OLE::Variant module provides access to the Variant data type and lets you control exactly how the data is represented.

A Variant is an OLE data structure that contains a type field and a data field. The flags are implemented in Perl (as are many constants) as subroutines that return an integer value. The following table lists the Variant type flags, along with a brief description of each:

Type

Description

VT_EMPTY

No value specified. Incidentally, automation does not use VT_EMPTY for empty optional parameters. Rather, it uses VT_ERROR with a value of DISP_E_PARAMNOTFOUND (which isn’t exported by Perl: the value in current Win32 SDK headers is 0x80020004).

VT_NULL

A propagating NULL value was specified (not to be confused with a null pointer). This is used for things like the NULL in SQL.

VT_I2

A two-byte integer value.

VT_I4

A four-byte integer value.

VT_R4

An IEEE four-byte real value.

VT_R8

An IEEE eight-byte real value.

VT_CY

An automation currency value.

VT_DATE

An automation date value.

VT_BSTR

A string value.

VT_DISPATCH

The value contains another automation object.

VT_ERROR

An error code was specified. ...

Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.