Home > Windows API > Useful macros for working with VARIANT!

Useful macros for working with VARIANT!

VARIANT is a COM data type desgined to hold different kinds types of values. VARIANT structure contains a member vt of type VARTYPE. This vt determines the type of data that a VARIANT object will hold!

For eg:

VARIANT vtVarUINT;
vtVarUINT.vt = VT_UI4;
vtVarUINT.ulVal = 123;

So every vt type has a corresponding value member, and sometimes it’s hard to correctly map between these types as there are more than 40 types from what I see!

So that’s why we have macros to help us maintain this mapping correctly, above code can be re-written as follows…

VARIANT vtVarUINT;
vtVarUINT.vt = VT_UI4;
// No need to worry here about <em>ulVal</em>, it will be done for use by this macro
V_UI4( &vtVarUINT ) = 123;

Well this was assigning, how about using this on the RHS side, it’s easy…

// No need to worry about which value type to pick from the big structure, correctly
// mapped for us by this macro.
const UINT uBlah = V_UI4( &vtVarUINT );

VT_UI4 is one among many macros provided in oleauto.h. I am pasting the rest here for your reference sake!

V_UI1(X)
V_UI1REF(X)
V_I2(X)
V_I2REF(X)
V_I4(X)
V_I4REF(X)
V_R4(X)
V_R4REF(X)
V_R8(X)
V_R8REF(X)
V_I1(X)
V_I1REF(X)
V_UI2(X)
V_UI2REF(X)
V_UI4(X)
V_UI4REF(X)
V_INT(X)
V_INTREF(X)
V_UINT(X)
V_UINTREF(X)
V_CY(X)
V_CYREF(X)
V_DATE(X)
V_DATEREF(X)
V_BSTR(X)
V_BSTRREF(X)
V_DISPATCH(X)
V_DISPATCHREF(X
V_ERROR(X)
V_ERRORREF(X)
V_BOOL(X)
V_BOOLREF(X)
V_UNKNOWN(X)
V_UNKNOWNREF(X)
V_VARIANTREF(X)
V_ARRAY(X)
V_ARRAYREF(X)
V_BYREF(X)
V_DECIMAL(X)
V_DECIMALREF(X)
Advertisements
Categories: Windows API Tags: , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: