Inline cstring vtocstr (variant * V)
{
If (V-> VT = vt_bstr)
{
Cstring STR (lpcwstr) V-> bstrval );
Return STR;
}
Else
{
Return cstring ("");
}
}
# Define vtolong (V). Vt = vt_i4? (Long) (v). lval: 0l)
# Define vtodate (V). Vt = vt_date? (Ctime) (v). ival: 0l)
Class CVaR: public variant
{
Public:
CVaR ()
{
Variantinit (this );
}
CVaR (vartype VT, scode = 0)
{
Variantinit (this );
This-> VT = Vt;
This-> scode = scode;
}
CVaR (variant var)
{
* This = var;
}
~ CVaR ()
{
Variantclear (this );
}
// Assignment ops.
CVaR & operator = (pcwstr)
{
Variantclear (this );
If (null = (this-> bstrval = sysallocstringlen (pcwstr, wcslen (pcwstr ))))
Throw e_outofmemory;
This-> VT = vt_bstr;
Return * this;
}
CVaR & operator = (variant var)
{
Hresult hr;
Variantclear (this );
If (failed (hR = variantcopy (this, & var )))
Throw hr;
Return * this;
}
.
Operator STR () const
{
If (vt_bstr = This-> VT)
Return this-> bstrval;
Else
Return NULL;
}
Operator long () const
{
If (vt_i4 = This-> VT)
Return this-> lval;
Else
Return NULL;
}
Operator date () const
{
If (vt_date = This-> VT)
Return this-> date;
Else
Return NULL;
}
Operator cy () const
{
Colecurrency cynull;
Cynull. setcurrency (0, 0 );
If (vt_cy = This-> VT)
Return this-> cyval;
Else
Return cynull;
}
Hresult clear ()
{
Return variantclear (this );
}
};
This is a class that I have organized and enhanced in msdn. I hope it will be helpful to the guys who operate the database through ado!