STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | List of all members
_variant_t Class Reference

#include <comutil.h>

Inheritance diagram for _variant_t:

Public Member Functions

 _variant_t () throw ()
 
 _variant_t (const VARIANT &varSrc)
 
 _variant_t (const VARIANT *pSrc)
 
 _variant_t (const _variant_t &varSrc)
 
 _variant_t (VARIANT &varSrc, bool fCopy)
 
 _variant_t (short sSrc, VARTYPE vtSrc=VT_I2)
 
 _variant_t (long lSrc, VARTYPE vtSrc=VT_I4)
 
 _variant_t (float fltSrc) throw ()
 
 _variant_t (double dblSrc, VARTYPE vtSrc=VT_R8)
 
 _variant_t (const CY &cySrc) throw ()
 
 _variant_t (const _bstr_t &bstrSrc)
 
 _variant_t (const wchar_t *pSrc)
 
 _variant_t (const char *pSrc)
 
 _variant_t (IDispatch *pSrc, bool fAddRef=true) throw ()
 
 _variant_t (bool boolSrc) throw ()
 
 _variant_t (IUnknown *pSrc, bool fAddRef=true) throw ()
 
 _variant_t (const DECIMAL &decSrc) throw ()
 
 _variant_t (BYTE bSrc) throw ()
 
 _variant_t (char cSrc) throw ()
 
 _variant_t (unsigned short usSrc) throw ()
 
 _variant_t (unsigned long ulSrc) throw ()
 
 _variant_t (int iSrc) throw ()
 
 _variant_t (unsigned int uiSrc) throw ()
 
 ~_variant_t () throw ()
 
 operator short () const
 
 operator long () const
 
 operator float () const
 
 operator double () const
 
 operator CY () const
 
 operator _bstr_t () const
 
 operator IDispatch * () const
 
 operator bool () const
 
 operator IUnknown * () const
 
 operator DECIMAL () const
 
 operator BYTE () const
 
 operator VARIANT () const throw ()
 
 operator char () const
 
 operator unsigned short () const
 
 operator unsigned long () const
 
 operator int () const
 
 operator unsigned int () const
 
_variant_toperator= (const VARIANT &varSrc)
 
_variant_toperator= (const VARIANT *pSrc)
 
_variant_toperator= (const _variant_t &varSrc)
 
_variant_toperator= (short sSrc)
 
_variant_toperator= (long lSrc)
 
_variant_toperator= (float fltSrc)
 
_variant_toperator= (double dblSrc)
 
_variant_toperator= (const CY &cySrc)
 
_variant_toperator= (const _bstr_t &bstrSrc)
 
_variant_toperator= (const wchar_t *pSrc)
 
_variant_toperator= (const char *pSrc)
 
_variant_toperator= (IDispatch *pSrc)
 
_variant_toperator= (bool boolSrc)
 
_variant_toperator= (IUnknown *pSrc)
 
_variant_toperator= (const DECIMAL &decSrc)
 
_variant_toperator= (BYTE bSrc)
 
_variant_toperator= (char cSrc)
 
_variant_toperator= (unsigned short usSrc)
 
_variant_toperator= (unsigned long ulSrc)
 
_variant_toperator= (int iSrc)
 
_variant_toperator= (unsigned int uiSrc)
 
bool operator== (const VARIANT &varSrc) const throw ()
 
bool operator== (const VARIANT *pSrc) const throw ()
 
bool operator!= (const VARIANT &varSrc) const throw ()
 
bool operator!= (const VARIANT *pSrc) const throw ()
 
void Clear ()
 
void Attach (VARIANT &varSrc)
 
VARIANT Detach () throw ()
 
VARIANT & GetVARIANT () throw ()
 
VARIANT * GetAddress ()
 
void ChangeType (VARTYPE vartype, const _variant_t *pSrc=NULL)
 
void SetString (const char *pSrc)
 

Constructor & Destructor Documentation

_variant_t::_variant_t ( )
throw (
)
inline
1129 {
1130  ::VariantInit(this);
1131 }
_variant_t::_variant_t ( const VARIANT &  varSrc)
inline
1136 {
1137  ::VariantInit(this);
1138  _com_util::CheckError(::VariantCopy(this, const_cast<VARIANT*>(&varSrc)));
1139 }
void CheckError(HRESULT hr)
Definition: comutil.h:94
_variant_t::_variant_t ( const VARIANT *  pSrc)
inline
1144 {
1145  if (pSrc == NULL) {
1146  _com_issue_error(E_POINTER);
1147  }
1148  else {
1149  ::VariantInit(this);
1150  _com_util::CheckError(::VariantCopy(this, const_cast<VARIANT*>(pSrc)));
1151  }
1152 }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
void CheckError(HRESULT hr)
Definition: comutil.h:94
_variant_t::_variant_t ( const _variant_t varSrc)
inline
1157 {
1158  ::VariantInit(this);
1159  _com_util::CheckError(::VariantCopy(this, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc))));
1160 }
void CheckError(HRESULT hr)
Definition: comutil.h:94
_variant_t::_variant_t ( VARIANT &  varSrc,
bool  fCopy 
)
inline
1166 {
1167  if (fCopy) {
1168  ::VariantInit(this);
1169  _com_util::CheckError(::VariantCopy(this, &varSrc));
1170  }
1171  else {
1172  _COM_MEMCPY_S(this, sizeof(varSrc), &varSrc, sizeof(varSrc));
1173  V_VT(&varSrc) = VT_EMPTY;
1174  }
1175 }
#define _COM_MEMCPY_S(dest, destsize, src, count)
Definition: comutil.h:48
void CheckError(HRESULT hr)
Definition: comutil.h:94
_variant_t::_variant_t ( short  sSrc,
VARTYPE  vtSrc = VT_I2 
)
inline
1181 {
1182  if ((vtSrc != VT_I2) && (vtSrc != VT_BOOL)) {
1183  _com_issue_error(E_INVALIDARG);
1184  return;
1185  }
1186 
1187  if (vtSrc == VT_BOOL) {
1188  V_VT(this) = VT_BOOL;
1189  V_BOOL(this) = (sSrc ? VARIANT_TRUE : VARIANT_FALSE);
1190  }
1191  else {
1192  V_VT(this) = VT_I2;
1193  V_I2(this) = sSrc;
1194  }
1195 }
void __stdcall _com_issue_error(HRESULT)
_variant_t::_variant_t ( long  lSrc,
VARTYPE  vtSrc = VT_I4 
)
inline
1201 {
1202  if ((vtSrc != VT_I4) && (vtSrc != VT_ERROR) && (vtSrc != VT_BOOL)) {
1203  _com_issue_error(E_INVALIDARG);
1204  return;
1205  }
1206 
1207  if (vtSrc == VT_ERROR) {
1208  V_VT(this) = VT_ERROR;
1209  V_ERROR(this) = lSrc;
1210  }
1211  else if (vtSrc == VT_BOOL) {
1212  V_VT(this) = VT_BOOL;
1213  V_BOOL(this) = (lSrc ? VARIANT_TRUE : VARIANT_FALSE);
1214  }
1215  else {
1216  V_VT(this) = VT_I4;
1217  V_I4(this) = lSrc;
1218  }
1219 }
void __stdcall _com_issue_error(HRESULT)
_variant_t::_variant_t ( float  fltSrc)
throw (
)
inline
1224 {
1225  V_VT(this) = VT_R4;
1226  V_R4(this) = fltSrc;
1227 }
_variant_t::_variant_t ( double  dblSrc,
VARTYPE  vtSrc = VT_R8 
)
inline
1233 {
1234  if ((vtSrc != VT_R8) && (vtSrc != VT_DATE)) {
1235  _com_issue_error(E_INVALIDARG);
1236  return;
1237  }
1238 
1239  if (vtSrc == VT_DATE) {
1240  V_VT(this) = VT_DATE;
1241  V_DATE(this) = dblSrc;
1242  }
1243  else {
1244  V_VT(this) = VT_R8;
1245  V_R8(this) = dblSrc;
1246  }
1247 }
void __stdcall _com_issue_error(HRESULT)
_variant_t::_variant_t ( const CY &  cySrc)
throw (
)
inline
1252 {
1253  V_VT(this) = VT_CY;
1254  V_CY(this) = cySrc;
1255 }
_variant_t::_variant_t ( const _bstr_t bstrSrc)
inline
1260 {
1261  V_VT(this) = VT_BSTR;
1262 
1263  BSTR bstr = static_cast<wchar_t*>(bstrSrc);
1264  if (bstr == NULL) {
1265  V_BSTR(this) = NULL;
1266  }
1267  else {
1268  V_BSTR(this) = ::SysAllocStringByteLen(reinterpret_cast<char*>(bstr),
1269  ::SysStringByteLen(bstr));
1270  if (V_BSTR(this) == NULL) {
1271  _com_issue_error(E_OUTOFMEMORY);
1272  }
1273  }
1274 }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
_variant_t::_variant_t ( const wchar_t pSrc)
inline
1279 {
1280  V_VT(this) = VT_BSTR;
1281 
1282  V_BSTR(this) = ::SysAllocString(pSrc);
1283 
1284  if (V_BSTR(this) == NULL && pSrc != NULL) {
1285  _com_issue_error(E_OUTOFMEMORY);
1286  }
1287 }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
_variant_t::_variant_t ( const char *  pSrc)
inline
1292 {
1293  V_VT(this) = VT_BSTR;
1294  V_BSTR(this) = _com_util::ConvertStringToBSTR(pSrc);
1295 }
BSTR __stdcall ConvertStringToBSTR(const char *pSrc)
_variant_t::_variant_t ( IDispatch *  pSrc,
bool  fAddRef = true 
)
throw (
)
inline
1300 {
1301  V_VT(this) = VT_DISPATCH;
1302  V_DISPATCH(this) = pSrc;
1303 
1304  // Need the AddRef() as VariantClear() calls Release(), unless fAddRef
1305  // false indicates we're taking ownership
1306  //
1307  if (fAddRef) {
1308  if (V_DISPATCH(this) != NULL) {
1309  V_DISPATCH(this)->AddRef();
1310  }
1311  }
1312 }
#define NULL
Definition: vcruntime.h:236
_variant_t::_variant_t ( bool  boolSrc)
throw (
)
inline
1317 {
1318  V_VT(this) = VT_BOOL;
1319  V_BOOL(this) = (boolSrc ? VARIANT_TRUE : VARIANT_FALSE);
1320 }
_variant_t::_variant_t ( IUnknown *  pSrc,
bool  fAddRef = true 
)
throw (
)
inline
1325 {
1326  V_VT(this) = VT_UNKNOWN;
1327  V_UNKNOWN(this) = pSrc;
1328 
1329  // Need the AddRef() as VariantClear() calls Release(), unless fAddRef
1330  // false indicates we're taking ownership
1331  //
1332  if (fAddRef) {
1333  if (V_UNKNOWN(this) != NULL) {
1334  V_UNKNOWN(this)->AddRef();
1335  }
1336  }
1337 }
#define NULL
Definition: vcruntime.h:236
_variant_t::_variant_t ( const DECIMAL &  decSrc)
throw (
)
inline
1342 {
1343  // Order is important here! Setting V_DECIMAL wipes out the entire VARIANT
1344  //
1345  V_DECIMAL(this) = decSrc;
1346  V_VT(this) = VT_DECIMAL;
1347 }
_variant_t::_variant_t ( BYTE  bSrc)
throw (
)
inline
1352 {
1353  V_VT(this) = VT_UI1;
1354  V_UI1(this) = bSrc;
1355 }
_variant_t::_variant_t ( char  cSrc)
throw (
)
inline
1360 {
1361  V_VT(this) = VT_I1;
1362  V_I1(this) = cSrc;
1363 }
_variant_t::_variant_t ( unsigned short  usSrc)
throw (
)
inline
1368 {
1369  V_VT(this) = VT_UI2;
1370  V_UI2(this) = usSrc;
1371 }
_variant_t::_variant_t ( unsigned long  ulSrc)
throw (
)
inline
1376 {
1377  V_VT(this) = VT_UI4;
1378  V_UI4(this) = ulSrc;
1379 }
_variant_t::_variant_t ( int  iSrc)
throw (
)
inline
1384 {
1385  V_VT(this) = VT_INT;
1386  V_INT(this) = iSrc;
1387 }
_variant_t::_variant_t ( unsigned int  uiSrc)
throw (
)
inline
1392 {
1393  V_VT(this) = VT_UINT;
1394  V_UINT(this) = uiSrc;
1395 }
_variant_t::~_variant_t ( )
throw (
)
inline
2333 {
2334  ::VariantClear(this);
2335 }

Member Function Documentation

void _variant_t::Attach ( VARIANT &  varSrc)
inline
2270 {
2271  //
2272  // Free up previous VARIANT
2273  //
2274  Clear();
2275 
2276  //
2277  // Give control of data to _variant_t
2278  //
2279  _COM_MEMCPY_S(this, sizeof(varSrc), &varSrc, sizeof(varSrc));
2280  V_VT(&varSrc) = VT_EMPTY;
2281 }
void Clear()
Definition: comutil.h:2264
#define _COM_MEMCPY_S(dest, destsize, src, count)
Definition: comutil.h:48
void _variant_t::ChangeType ( VARTYPE  vartype,
const _variant_t pSrc = NULL 
)
inline
2306 {
2307  //
2308  // If pDest is NULL, convert type in place
2309  //
2310  if (pSrc == NULL) {
2311  pSrc = this;
2312  }
2313 
2314  if ((this != pSrc) || (vartype != V_VT(this))) {
2315  _com_util::CheckError(::VariantChangeType(static_cast<VARIANT*>(this),
2316  const_cast<VARIANT*>(static_cast<const VARIANT*>(pSrc)),
2317  0, vartype));
2318  }
2319 }
#define NULL
Definition: vcruntime.h:236
void CheckError(HRESULT hr)
Definition: comutil.h:94
void _variant_t::Clear ( )
inline
2265 {
2266  _com_util::CheckError(::VariantClear(this));
2267 }
void CheckError(HRESULT hr)
Definition: comutil.h:94
VARIANT _variant_t::Detach ( )
throw (
)
inline
2284 {
2285  VARIANT varResult = *this;
2286  V_VT(this) = VT_EMPTY;
2287 
2288  return varResult;
2289 }
VARIANT * _variant_t::GetAddress ( )
inline
2297 {
2298  Clear();
2299  return (VARIANT*) this;
2300 }
void Clear()
Definition: comutil.h:2264
VARIANT & _variant_t::GetVARIANT ( )
throw (
)
inline
2292 {
2293  return *(VARIANT*) this;
2294 }
_variant_t::operator _bstr_t ( ) const
inline
1494 {
1495  if (V_VT(this) == VT_BSTR) {
1496  return V_BSTR(this);
1497  }
1498 
1499  _variant_t varDest;
1500  varDest.ChangeType(VT_BSTR, this);
1501 
1502  return V_BSTR(&varDest);
1503 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator bool ( ) const
inline
1529 {
1530  if (V_VT(this) == VT_BOOL) {
1531  return V_BOOL(this) ? true : false;
1532  }
1533 
1534  _variant_t varDest;
1535  varDest.ChangeType(VT_BOOL, this);
1536 
1537  return (V_BOOL(&varDest) == VARIANT_TRUE) ? true : false;
1538 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator BYTE ( ) const
inline
1578 {
1579  if (V_VT(this) == VT_UI1) {
1580  return V_UI1(this);
1581  }
1582 
1583  _variant_t varDest;
1584  varDest.ChangeType(VT_UI1, this);
1585 
1586  return V_UI1(&varDest);
1587 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator char ( ) const
inline
1599 {
1600  if (V_VT(this) == VT_I1) {
1601  return V_I1(this);
1602  }
1603 
1604  _variant_t varDest;
1605  varDest.ChangeType(VT_I1, this);
1606 
1607  return V_I1(&varDest);
1608 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator CY ( ) const
inline
1480 {
1481  if (V_VT(this) == VT_CY) {
1482  return V_CY(this);
1483  }
1484 
1485  _variant_t varDest;
1486  varDest.ChangeType(VT_CY, this);
1487 
1488  return V_CY(&varDest);
1489 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator DECIMAL ( ) const
inline
1564 {
1565  if (V_VT(this) == VT_DECIMAL) {
1566  return V_DECIMAL(this);
1567  }
1568 
1569  _variant_t varDest;
1570  varDest.ChangeType(VT_DECIMAL, this);
1571 
1572  return V_DECIMAL(&varDest);
1573 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator double ( ) const
inline
1466 {
1467  if (V_VT(this) == VT_R8) {
1468  return V_R8(this);
1469  }
1470 
1471  _variant_t varDest;
1472  varDest.ChangeType(VT_R8, this);
1473 
1474  return V_R8(&varDest);
1475 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator float ( ) const
inline
1452 {
1453  if (V_VT(this) == VT_R4) {
1454  return V_R4(this);
1455  }
1456 
1457  _variant_t varDest;
1458  varDest.ChangeType(VT_R4, this);
1459 
1460  return V_R4(&varDest);
1461 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator IDispatch * ( ) const
inline
1508 {
1509  if (V_VT(this) == VT_DISPATCH) {
1510  if (V_DISPATCH(this) != NULL) {
1511  V_DISPATCH(this)->AddRef();
1512  }
1513  return V_DISPATCH(this);
1514  }
1515 
1516  _variant_t varDest;
1517  varDest.ChangeType(VT_DISPATCH, this);
1518 
1519  if (V_DISPATCH(&varDest) != NULL) {
1520  V_DISPATCH(&varDest)->AddRef();
1521  }
1522 
1523  return V_DISPATCH(&varDest);
1524 }
#define NULL
Definition: vcruntime.h:236
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator int ( ) const
inline
1641 {
1642  if (V_VT(this) == VT_INT) {
1643  return V_INT(this);
1644  }
1645 
1646  _variant_t varDest;
1647  varDest.ChangeType(VT_INT, this);
1648 
1649  return V_INT(&varDest);
1650 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator IUnknown * ( ) const
inline
1543 {
1544  if (V_VT(this) == VT_UNKNOWN) {
1545  if (V_UNKNOWN(this) != NULL) {
1546  V_UNKNOWN(this)->AddRef();
1547  }
1548  return V_UNKNOWN(this);
1549  }
1550 
1551  _variant_t varDest;
1552  varDest.ChangeType(VT_UNKNOWN, this);
1553 
1554  if (V_UNKNOWN(&varDest) != NULL) {
1555  V_UNKNOWN(&varDest)->AddRef();
1556  }
1557 
1558  return V_UNKNOWN(&varDest);
1559 }
#define NULL
Definition: vcruntime.h:236
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator long ( ) const
inline
1438 {
1439  if (V_VT(this) == VT_I4) {
1440  return V_I4(this);
1441  }
1442 
1443  _variant_t varDest;
1444  varDest.ChangeType(VT_I4, this);
1445 
1446  return V_I4(&varDest);
1447 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator short ( ) const
inline
1424 {
1425  if (V_VT(this) == VT_I2) {
1426  return V_I2(this);
1427  }
1428 
1429  _variant_t varDest;
1430  varDest.ChangeType(VT_I2, this);
1431 
1432  return V_I2(&varDest);
1433 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator unsigned int ( ) const
inline
1655 {
1656  if (V_VT(this) == VT_UINT) {
1657  return V_UINT(this);
1658  }
1659 
1660  _variant_t varDest;
1661  varDest.ChangeType(VT_UINT, this);
1662 
1663  return V_UINT(&varDest);
1664 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator unsigned long ( ) const
inline
1627 {
1628  if (V_VT(this) == VT_UI4) {
1629  return V_UI4(this);
1630  }
1631 
1632  _variant_t varDest;
1633  varDest.ChangeType(VT_UI4, this);
1634 
1635  return V_UI4(&varDest);
1636 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator unsigned short ( ) const
inline
1613 {
1614  if (V_VT(this) == VT_UI2) {
1615  return V_UI2(this);
1616  }
1617 
1618  _variant_t varDest;
1619  varDest.ChangeType(VT_UI2, this);
1620 
1621  return V_UI2(&varDest);
1622 }
void ChangeType(VARTYPE vartype, const _variant_t *pSrc=NULL)
Definition: comutil.h:2305
Definition: comutil.h:1002
_variant_t::operator VARIANT ( ) const
throw (
)
inline
1592 {
1593  return *(VARIANT*) this;
1594 }
bool _variant_t::operator!= ( const VARIANT &  varSrc) const
throw (
)
inline
2245 {
2246  return !(*this == &varSrc);
2247 }
bool _variant_t::operator!= ( const VARIANT *  pSrc) const
throw (
)
inline
2252 {
2253  return !(*this == pSrc);
2254 }
_variant_t & _variant_t::operator= ( const VARIANT &  varSrc)
inline
1705 {
1706  _com_util::CheckError(::VariantCopy(this, const_cast<VARIANT*>(&varSrc)));
1707 
1708  return *this;
1709 }
void CheckError(HRESULT hr)
Definition: comutil.h:94
_variant_t & _variant_t::operator= ( const VARIANT *  pSrc)
inline
1714 {
1715  if (pSrc == NULL) {
1716  _com_issue_error(E_POINTER);
1717  }
1718  else {
1719  _com_util::CheckError(::VariantCopy(this, const_cast<VARIANT*>(pSrc)));
1720  }
1721 
1722  return *this;
1723 }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
void CheckError(HRESULT hr)
Definition: comutil.h:94
_variant_t & _variant_t::operator= ( const _variant_t varSrc)
inline
1728 {
1729  _com_util::CheckError(::VariantCopy(this, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc))));
1730 
1731  return *this;
1732 }
void CheckError(HRESULT hr)
Definition: comutil.h:94
_variant_t & _variant_t::operator= ( short  sSrc)
inline
1738 {
1739  if (V_VT(this) == VT_I2) {
1740  V_I2(this) = sSrc;
1741  }
1742  else if (V_VT(this) == VT_BOOL) {
1743  V_BOOL(this) = (sSrc ? VARIANT_TRUE : VARIANT_FALSE);
1744  }
1745  else {
1746  // Clear the VARIANT and create a VT_I2
1747  //
1748  Clear();
1749 
1750  V_VT(this) = VT_I2;
1751  V_I2(this) = sSrc;
1752  }
1753 
1754  return *this;
1755 }
void Clear()
Definition: comutil.h:2264
_variant_t & _variant_t::operator= ( long  lSrc)
inline
1761 {
1762  if (V_VT(this) == VT_I4) {
1763  V_I4(this) = lSrc;
1764  }
1765  else if (V_VT(this) == VT_ERROR) {
1766  V_ERROR(this) = lSrc;
1767  }
1768  else if (V_VT(this) == VT_BOOL) {
1769  V_BOOL(this) = (lSrc ? VARIANT_TRUE : VARIANT_FALSE);
1770  }
1771  else {
1772  // Clear the VARIANT and create a VT_I4
1773  //
1774  Clear();
1775 
1776  V_VT(this) = VT_I4;
1777  V_I4(this) = lSrc;
1778  }
1779 
1780  return *this;
1781 }
void Clear()
Definition: comutil.h:2264
_variant_t & _variant_t::operator= ( float  fltSrc)
inline
1786 {
1787  if (V_VT(this) != VT_R4) {
1788  // Clear the VARIANT and create a VT_R4
1789  //
1790  Clear();
1791 
1792  V_VT(this) = VT_R4;
1793  }
1794 
1795  V_R4(this) = fltSrc;
1796 
1797  return *this;
1798 }
void Clear()
Definition: comutil.h:2264
_variant_t & _variant_t::operator= ( double  dblSrc)
inline
1804 {
1805  if (V_VT(this) == VT_R8) {
1806  V_R8(this) = dblSrc;
1807  }
1808  else if(V_VT(this) == VT_DATE) {
1809  V_DATE(this) = dblSrc;
1810  }
1811  else {
1812  // Clear the VARIANT and create a VT_R8
1813  //
1814  Clear();
1815 
1816  V_VT(this) = VT_R8;
1817  V_R8(this) = dblSrc;
1818  }
1819 
1820  return *this;
1821 }
void Clear()
Definition: comutil.h:2264
_variant_t & _variant_t::operator= ( const CY &  cySrc)
inline
1826 {
1827  if (V_VT(this) != VT_CY) {
1828  // Clear the VARIANT and create a VT_CY
1829  //
1830  Clear();
1831 
1832  V_VT(this) = VT_CY;
1833  }
1834 
1835  V_CY(this) = cySrc;
1836 
1837  return *this;
1838 }
void Clear()
Definition: comutil.h:2264
_variant_t & _variant_t::operator= ( const _bstr_t bstrSrc)
inline
1843 {
1844  _COM_ASSERT(V_VT(this) != VT_BSTR || (BSTR) bstrSrc == NULL || V_BSTR(this) != (BSTR) bstrSrc);
1845 
1846  // Clear the VARIANT (This will SysFreeString() any previous occupant)
1847  //
1848  Clear();
1849 
1850  V_VT(this) = VT_BSTR;
1851 
1852  if (!bstrSrc) {
1853  V_BSTR(this) = NULL;
1854  }
1855  else {
1856  BSTR bstr = static_cast<wchar_t*>(bstrSrc);
1857  V_BSTR(this) = ::SysAllocStringByteLen(reinterpret_cast<char*>(bstr),
1858  ::SysStringByteLen(bstr));
1859 
1860  if (V_BSTR(this) == NULL) {
1861  _com_issue_error(E_OUTOFMEMORY);
1862  }
1863  }
1864 
1865  return *this;
1866 }
void Clear()
Definition: comutil.h:2264
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
#define _COM_ASSERT(x)
Definition: comutil.h:26
_variant_t & _variant_t::operator= ( const wchar_t pSrc)
inline
1871 {
1872  _COM_ASSERT(V_VT(this) != VT_BSTR || pSrc == NULL || V_BSTR(this) != pSrc);
1873 
1874  // Clear the VARIANT (This will SysFreeString() any previous occupant)
1875  //
1876  Clear();
1877 
1878  V_VT(this) = VT_BSTR;
1879 
1880  if (pSrc == NULL) {
1881  V_BSTR(this) = NULL;
1882  }
1883  else {
1884  V_BSTR(this) = ::SysAllocString(pSrc);
1885 
1886  if (V_BSTR(this) == NULL) {
1887  _com_issue_error(E_OUTOFMEMORY);
1888  }
1889  }
1890 
1891  return *this;
1892 }
void Clear()
Definition: comutil.h:2264
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
#define _COM_ASSERT(x)
Definition: comutil.h:26
_variant_t & _variant_t::operator= ( const char *  pSrc)
inline
1897 {
1898  _COM_ASSERT(V_VT(this) != (VT_I1 | VT_BYREF) || pSrc == NULL || V_I1REF(this) != pSrc);
1899 
1900  // Clear the VARIANT (This will SysFreeString() any previous occupant)
1901  //
1902  Clear();
1903 
1904  V_VT(this) = VT_BSTR;
1905  V_BSTR(this) = _com_util::ConvertStringToBSTR(pSrc);
1906 
1907  return *this;
1908 }
BSTR __stdcall ConvertStringToBSTR(const char *pSrc)
void Clear()
Definition: comutil.h:2264
#define NULL
Definition: vcruntime.h:236
#define _COM_ASSERT(x)
Definition: comutil.h:26
_variant_t & _variant_t::operator= ( IDispatch *  pSrc)
inline
1913 {
1914  _COM_ASSERT(V_VT(this) != VT_DISPATCH || pSrc == 0 || V_DISPATCH(this) != pSrc);
1915 
1916  // Clear the VARIANT (This will Release() any previous occupant)
1917  //
1918  Clear();
1919 
1920  V_VT(this) = VT_DISPATCH;
1921  V_DISPATCH(this) = pSrc;
1922 
1923  if (V_DISPATCH(this) != NULL) {
1924  // Need the AddRef() as VariantClear() calls Release()
1925  //
1926  V_DISPATCH(this)->AddRef();
1927  }
1928 
1929  return *this;
1930 }
void Clear()
Definition: comutil.h:2264
#define NULL
Definition: vcruntime.h:236
#define _COM_ASSERT(x)
Definition: comutil.h:26
_variant_t & _variant_t::operator= ( bool  boolSrc)
inline
1935 {
1936  if (V_VT(this) != VT_BOOL) {
1937  // Clear the VARIANT and create a VT_BOOL
1938  //
1939  Clear();
1940 
1941  V_VT(this) = VT_BOOL;
1942  }
1943 
1944  V_BOOL(this) = (boolSrc ? VARIANT_TRUE : VARIANT_FALSE);
1945 
1946  return *this;
1947 }
void Clear()
Definition: comutil.h:2264
_variant_t & _variant_t::operator= ( IUnknown *  pSrc)
inline
1952 {
1953  _COM_ASSERT(V_VT(this) != VT_UNKNOWN || pSrc == NULL || V_UNKNOWN(this) != pSrc);
1954 
1955  // Clear VARIANT (This will Release() any previous occupant)
1956  //
1957  Clear();
1958 
1959  V_VT(this) = VT_UNKNOWN;
1960  V_UNKNOWN(this) = pSrc;
1961 
1962  if (V_UNKNOWN(this) != NULL) {
1963  // Need the AddRef() as VariantClear() calls Release()
1964  //
1965  V_UNKNOWN(this)->AddRef();
1966  }
1967 
1968  return *this;
1969 }
void Clear()
Definition: comutil.h:2264
#define NULL
Definition: vcruntime.h:236
#define _COM_ASSERT(x)
Definition: comutil.h:26
_variant_t & _variant_t::operator= ( const DECIMAL &  decSrc)
inline
1974 {
1975  if (V_VT(this) != VT_DECIMAL) {
1976  // Clear the VARIANT
1977  //
1978  Clear();
1979  }
1980 
1981  // Order is important here! Setting V_DECIMAL wipes out the entire VARIANT
1982  V_DECIMAL(this) = decSrc;
1983  V_VT(this) = VT_DECIMAL;
1984 
1985  return *this;
1986 }
void Clear()
Definition: comutil.h:2264
_variant_t & _variant_t::operator= ( BYTE  bSrc)
inline
1991 {
1992  if (V_VT(this) != VT_UI1) {
1993  // Clear the VARIANT and create a VT_UI1
1994  //
1995  Clear();
1996 
1997  V_VT(this) = VT_UI1;
1998  }
1999 
2000  V_UI1(this) = bSrc;
2001 
2002  return *this;
2003 }
void Clear()
Definition: comutil.h:2264
_variant_t & _variant_t::operator= ( char  cSrc)
inline
2008 {
2009  if (V_VT(this) != VT_I1) {
2010  // Clear the VARIANT and create a VT_I1
2011  //
2012  Clear();
2013 
2014  V_VT(this) = VT_I1;
2015  }
2016 
2017  V_I1(this) = cSrc;
2018 
2019  return *this;
2020 }
void Clear()
Definition: comutil.h:2264
_variant_t & _variant_t::operator= ( unsigned short  usSrc)
inline
2025 {
2026  if (V_VT(this) != VT_UI2) {
2027  // Clear the VARIANT and create a VT_UI2
2028  //
2029  Clear();
2030 
2031  V_VT(this) = VT_UI2;
2032  }
2033 
2034  V_UI2(this) = usSrc;
2035 
2036  return *this;
2037 }
void Clear()
Definition: comutil.h:2264
_variant_t & _variant_t::operator= ( unsigned long  ulSrc)
inline
2042 {
2043  if (V_VT(this) != VT_UI4) {
2044  // Clear the VARIANT and create a VT_UI4
2045  //
2046  Clear();
2047 
2048  V_VT(this) = VT_UI4;
2049  }
2050 
2051  V_UI4(this) = ulSrc;
2052 
2053  return *this;
2054 }
void Clear()
Definition: comutil.h:2264
_variant_t & _variant_t::operator= ( int  iSrc)
inline
2059 {
2060  if (V_VT(this) != VT_INT) {
2061  // Clear the VARIANT and create a VT_INT
2062  //
2063  Clear();
2064 
2065  V_VT(this) = VT_INT;
2066  }
2067 
2068  V_INT(this) = iSrc;
2069 
2070  return *this;
2071 }
void Clear()
Definition: comutil.h:2264
_variant_t & _variant_t::operator= ( unsigned int  uiSrc)
inline
2076 {
2077  if (V_VT(this) != VT_UINT) {
2078  // Clear the VARIANT and create a VT_UINT
2079  //
2080  Clear();
2081 
2082  V_VT(this) = VT_UINT;
2083  }
2084 
2085  V_UINT(this) = uiSrc;
2086 
2087  return *this;
2088 }
void Clear()
Definition: comutil.h:2264
bool _variant_t::operator== ( const VARIANT &  varSrc) const
throw (
)
inline
2135 {
2136  return *this == &varSrc;
2137 }
bool _variant_t::operator== ( const VARIANT *  pSrc) const
throw (
)
inline
2145 {
2146  if (pSrc == NULL) {
2147  return false;
2148  }
2149 
2150  if (this == pSrc) {
2151  return true;
2152  }
2153 
2154  //
2155  // Variants not equal if types don't match
2156  //
2157  if (V_VT(this) != V_VT(pSrc)) {
2158  return false;
2159  }
2160 
2161  //
2162  // Check type specific values
2163  //
2164  switch (V_VT(this)) {
2165  case VT_EMPTY:
2166  case VT_NULL:
2167  return true;
2168 
2169  case VT_I2:
2170  return V_I2(this) == V_I2(pSrc);
2171 
2172  case VT_I4:
2173  return V_I4(this) == V_I4(pSrc);
2174 
2175  case VT_R4:
2176  return V_R4(this) == V_R4(pSrc);
2177 
2178  case VT_R8:
2179  return V_R8(this) == V_R8(pSrc);
2180 
2181  case VT_CY:
2182  return memcmp(&(V_CY(this)), &(V_CY(pSrc)), sizeof(CY)) == 0;
2183 
2184  case VT_DATE:
2185  return V_DATE(this) == V_DATE(pSrc);
2186 
2187  case VT_BSTR:
2188  return (::SysStringByteLen(V_BSTR(this)) == ::SysStringByteLen(V_BSTR(pSrc))) &&
2189  (memcmp(V_BSTR(this), V_BSTR(pSrc), ::SysStringByteLen(V_BSTR(this))) == 0);
2190 
2191  case VT_DISPATCH:
2192  return V_DISPATCH(this) == V_DISPATCH(pSrc);
2193 
2194  case VT_ERROR:
2195  return V_ERROR(this) == V_ERROR(pSrc);
2196 
2197  case VT_BOOL:
2198  return V_BOOL(this) == V_BOOL(pSrc);
2199 
2200  case VT_UNKNOWN:
2201  return V_UNKNOWN(this) == V_UNKNOWN(pSrc);
2202 
2203  case VT_DECIMAL:
2204  return memcmp(&(V_DECIMAL(this)), &(V_DECIMAL(pSrc)), sizeof(DECIMAL)) == 0;
2205 
2206  case VT_UI1:
2207  return V_UI1(this) == V_UI1(pSrc);
2208 
2209  case VT_I1:
2210  return V_I1(this) == V_I1(pSrc);
2211 
2212  case VT_UI2:
2213  return V_UI2(this) == V_UI2(pSrc);
2214 
2215  case VT_UI4:
2216  return V_UI4(this) == V_UI4(pSrc);
2217 
2218  case VT_INT:
2219  return V_INT(this) == V_INT(pSrc);
2220 
2221  case VT_UINT:
2222  return V_UINT(this) == V_UINT(pSrc);
2223 
2224 #if (_WIN32_WINNT >= 0x0501)
2225  case VT_I8:
2226  return V_I8(this) == V_I8(pSrc);
2227 
2228  case VT_UI8:
2229  return V_UI8(this) == V_UI8(pSrc);
2230 #endif
2231 
2232  default:
2233  _com_issue_error(E_INVALIDARG);
2234  // fall through
2235  }
2236 
2237  return false;
2238 }
#define NULL
Definition: vcruntime.h:236
_Check_return_ int __cdecl memcmp(_In_reads_bytes_(_Size) void const *_Buf1, _In_reads_bytes_(_Size) void const *_Buf2, _In_ size_t _Size)
void __stdcall _com_issue_error(HRESULT)
void _variant_t::SetString ( const char *  pSrc)
inline
2322 {
2323  operator=(pSrc);
2324 }
_variant_t & operator=(const VARIANT &varSrc)
Definition: comutil.h:1704

The documentation for this class was generated from the following file: