Mercurial > games > semicongine
comparison fuhtark_test/include/winapi/comutil.h @ 1500:91c8c3b7cbf0
add: futhark tests for generating vulkan api
| author | sam <sam@basx.dev> |
|---|---|
| date | Wed, 26 Nov 2025 21:36:48 +0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1499:1f58458b7ef7 | 1500:91c8c3b7cbf0 |
|---|---|
| 1 /** | |
| 2 * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 * This file is part of the w64 mingw-runtime package. | |
| 4 * No warranty is given; refer to the file DISCLAIMER within this package. | |
| 5 */ | |
| 6 #ifndef _INC_COMUTIL | |
| 7 #define _INC_COMUTIL | |
| 8 | |
| 9 #include <ole2.h> | |
| 10 | |
| 11 #ifndef _COM_ASSERT | |
| 12 #define _COM_ASSERT(x) ((void)0) | |
| 13 #endif | |
| 14 | |
| 15 #define _COM_MEMCPY_S(dest,destsize,src,count) memcpy(dest,src,count) | |
| 16 #define _COM_PRINTF_S_1(dest,destsize,format,arg1) wsprintf(dest,format,arg1) | |
| 17 | |
| 18 #ifdef __cplusplus | |
| 19 | |
| 20 #pragma push_macro("new") | |
| 21 #undef new | |
| 22 | |
| 23 #ifndef WINAPI | |
| 24 #define WINAPI __stdcall | |
| 25 #endif | |
| 26 | |
| 27 class _com_error; | |
| 28 | |
| 29 void WINAPI _com_issue_error(HRESULT); | |
| 30 | |
| 31 class _bstr_t; | |
| 32 class _variant_t; | |
| 33 | |
| 34 namespace _com_util { | |
| 35 inline void CheckError(HRESULT hr) throw(...) { | |
| 36 if(FAILED(hr)) { _com_issue_error(hr); } | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 namespace _com_util { | |
| 41 BSTR WINAPI ConvertStringToBSTR(const char *pSrc); | |
| 42 char *WINAPI ConvertBSTRToString(BSTR pSrc); | |
| 43 } | |
| 44 | |
| 45 class _bstr_t { | |
| 46 public: | |
| 47 _bstr_t() throw(); | |
| 48 _bstr_t(const _bstr_t &s) throw(); | |
| 49 _bstr_t(const char *s); | |
| 50 _bstr_t(const wchar_t *s); | |
| 51 _bstr_t(const _variant_t &var); | |
| 52 _bstr_t(BSTR bstr,bool fCopy); | |
| 53 ~_bstr_t() throw(); | |
| 54 _bstr_t &operator=(const _bstr_t &s) throw(); | |
| 55 _bstr_t &operator=(const char *s); | |
| 56 _bstr_t &operator=(const wchar_t *s); | |
| 57 _bstr_t &operator=(const _variant_t &var); | |
| 58 _bstr_t &operator+=(const _bstr_t &s); | |
| 59 _bstr_t operator+(const _bstr_t &s) const; | |
| 60 friend _bstr_t operator+(const char *s1,const _bstr_t &s2); | |
| 61 friend _bstr_t operator+(const wchar_t *s1,const _bstr_t &s2); | |
| 62 operator const wchar_t *() const throw(); | |
| 63 operator wchar_t *() const throw(); | |
| 64 operator const char *() const; | |
| 65 operator char *() const; | |
| 66 bool operator!() const throw(); | |
| 67 bool operator==(const _bstr_t &str) const throw(); | |
| 68 bool operator!=(const _bstr_t &str) const throw(); | |
| 69 bool operator<(const _bstr_t &str) const throw(); | |
| 70 bool operator>(const _bstr_t &str) const throw(); | |
| 71 bool operator<=(const _bstr_t &str) const throw(); | |
| 72 bool operator>=(const _bstr_t &str) const throw(); | |
| 73 BSTR copy(bool fCopy = true) const; | |
| 74 unsigned int length() const throw(); | |
| 75 void Assign(BSTR s); | |
| 76 BSTR &GetBSTR(); | |
| 77 BSTR *GetAddress(); | |
| 78 void Attach(BSTR s); | |
| 79 BSTR Detach() throw(); | |
| 80 private: | |
| 81 class Data_t { | |
| 82 public: | |
| 83 Data_t(const char *s); | |
| 84 Data_t(const wchar_t *s); | |
| 85 Data_t(BSTR bstr,bool fCopy); | |
| 86 Data_t(const _bstr_t &s1,const _bstr_t &s2); | |
| 87 unsigned long AddRef() throw(); | |
| 88 unsigned long Release() throw(); | |
| 89 unsigned long RefCount() const throw(); | |
| 90 operator const wchar_t *() const throw(); | |
| 91 operator const char *() const; | |
| 92 const wchar_t *GetWString() const throw(); | |
| 93 wchar_t *&GetWString() throw(); | |
| 94 const char *GetString() const; | |
| 95 BSTR Copy() const; | |
| 96 void Assign(BSTR s); | |
| 97 void Attach(BSTR s) throw(); | |
| 98 unsigned int Length() const throw(); | |
| 99 int Compare(const Data_t &str) const throw(); | |
| 100 void *operator new(size_t sz); | |
| 101 private: | |
| 102 BSTR m_wstr; | |
| 103 mutable char *m_str; | |
| 104 unsigned long m_RefCount; | |
| 105 Data_t() throw(); | |
| 106 Data_t(const Data_t &s) throw(); | |
| 107 ~Data_t() throw(); | |
| 108 void _Free() throw(); | |
| 109 }; | |
| 110 private: | |
| 111 Data_t *m_Data; | |
| 112 private: | |
| 113 void _AddRef() throw(); | |
| 114 void _Free() throw(); | |
| 115 int _Compare(const _bstr_t &str) const throw(); | |
| 116 }; | |
| 117 | |
| 118 inline _bstr_t::_bstr_t() throw() : m_Data(NULL) { } | |
| 119 | |
| 120 inline _bstr_t::_bstr_t(const _bstr_t &s) throw() : m_Data(s.m_Data) { _AddRef(); } | |
| 121 | |
| 122 inline _bstr_t::_bstr_t(const char *s) : m_Data(new Data_t(s)) { | |
| 123 if(!m_Data) { _com_issue_error(E_OUTOFMEMORY); } | |
| 124 } | |
| 125 | |
| 126 inline _bstr_t::_bstr_t(const wchar_t *s) : m_Data(new Data_t(s)) { | |
| 127 if(!m_Data) { _com_issue_error(E_OUTOFMEMORY); } | |
| 128 } | |
| 129 | |
| 130 inline _bstr_t::_bstr_t(BSTR bstr,bool fCopy) : m_Data(new Data_t(bstr,fCopy)) { | |
| 131 if(!m_Data) { _com_issue_error(E_OUTOFMEMORY); } | |
| 132 } | |
| 133 | |
| 134 inline _bstr_t::~_bstr_t() throw() { _Free(); } | |
| 135 | |
| 136 inline _bstr_t &_bstr_t::operator=(const _bstr_t &s) throw() { | |
| 137 if(this!=&s) { | |
| 138 _Free(); | |
| 139 m_Data = s.m_Data; | |
| 140 _AddRef(); | |
| 141 } | |
| 142 return *this; | |
| 143 } | |
| 144 | |
| 145 inline _bstr_t &_bstr_t::operator=(const char *s) { | |
| 146 _COM_ASSERT(!s || static_cast<const char *>(*this)!=s); | |
| 147 if(!s || static_cast<const char *>(*this)!=s) { | |
| 148 _Free(); | |
| 149 m_Data = new Data_t(s); | |
| 150 if(!m_Data) { _com_issue_error(E_OUTOFMEMORY); } | |
| 151 } | |
| 152 return *this; | |
| 153 } | |
| 154 | |
| 155 inline _bstr_t &_bstr_t::operator=(const wchar_t *s) { | |
| 156 _COM_ASSERT(!s || static_cast<const wchar_t *>(*this)!=s); | |
| 157 if(!s || static_cast<const wchar_t *>(*this)!=s) { | |
| 158 _Free(); | |
| 159 m_Data = new Data_t(s); | |
| 160 if(!m_Data) { _com_issue_error(E_OUTOFMEMORY); } | |
| 161 } | |
| 162 return *this; | |
| 163 } | |
| 164 | |
| 165 inline _bstr_t &_bstr_t::operator+=(const _bstr_t &s) { | |
| 166 Data_t *newData = new Data_t(*this,s); | |
| 167 if(!newData) { _com_issue_error(E_OUTOFMEMORY); } | |
| 168 else { | |
| 169 _Free(); | |
| 170 m_Data = newData; | |
| 171 } | |
| 172 return *this; | |
| 173 } | |
| 174 | |
| 175 inline _bstr_t _bstr_t::operator+(const _bstr_t &s) const { | |
| 176 _bstr_t b = *this; | |
| 177 b += s; | |
| 178 return b; | |
| 179 } | |
| 180 | |
| 181 inline _bstr_t operator+(const char *s1,const _bstr_t &s2) { | |
| 182 _bstr_t b = s1; | |
| 183 b += s2; | |
| 184 return b; | |
| 185 } | |
| 186 | |
| 187 inline _bstr_t operator+(const wchar_t *s1,const _bstr_t &s2) { | |
| 188 _bstr_t b = s1; | |
| 189 b += s2; | |
| 190 return b; | |
| 191 } | |
| 192 | |
| 193 inline _bstr_t::operator const wchar_t *() const throw() { return (m_Data!=NULL) ? m_Data->GetWString() : NULL; } | |
| 194 inline _bstr_t::operator wchar_t *() const throw() { return const_cast<wchar_t *>((m_Data!=NULL) ? m_Data->GetWString() : NULL); } | |
| 195 inline _bstr_t::operator const char *() const { return (m_Data!=NULL) ? m_Data->GetString() : NULL; } | |
| 196 inline _bstr_t::operator char *() const { return const_cast<char *>((m_Data!=NULL) ? m_Data->GetString() : NULL); } | |
| 197 inline bool _bstr_t::operator!() const throw() { return (m_Data!=NULL) ? !m_Data->GetWString() : true; } | |
| 198 inline bool _bstr_t::operator==(const _bstr_t &str) const throw() { return _Compare(str)==0; } | |
| 199 inline bool _bstr_t::operator!=(const _bstr_t &str) const throw() { return _Compare(str)!=0; } | |
| 200 inline bool _bstr_t::operator<(const _bstr_t &str) const throw() { return _Compare(str)<0; } | |
| 201 inline bool _bstr_t::operator>(const _bstr_t &str) const throw() { return _Compare(str)>0; } | |
| 202 inline bool _bstr_t::operator<=(const _bstr_t &str) const throw() { return _Compare(str)<=0; } | |
| 203 inline bool _bstr_t::operator>=(const _bstr_t &str) const throw() { return _Compare(str)>=0; } | |
| 204 inline BSTR _bstr_t::copy(bool fCopy) const { return (m_Data!=NULL) ? (fCopy ? m_Data->Copy() : m_Data->GetWString()) : NULL; } | |
| 205 inline unsigned int _bstr_t::length() const throw() { return (m_Data!=NULL) ? m_Data->Length() : 0; } | |
| 206 inline void _bstr_t::Assign(BSTR s) { | |
| 207 _COM_ASSERT(!s || !m_Data || m_Data->GetWString()!=s); | |
| 208 if(!s || !m_Data || m_Data->GetWString()!=s) { | |
| 209 _Free(); | |
| 210 m_Data = new Data_t(s,TRUE); | |
| 211 if(!m_Data) { _com_issue_error(E_OUTOFMEMORY); } | |
| 212 } | |
| 213 } | |
| 214 | |
| 215 inline BSTR &_bstr_t::GetBSTR() { | |
| 216 if(!m_Data) { | |
| 217 m_Data = new Data_t(0,FALSE); | |
| 218 if(!m_Data) { _com_issue_error(E_OUTOFMEMORY); } | |
| 219 } | |
| 220 return m_Data->GetWString(); | |
| 221 } | |
| 222 | |
| 223 inline BSTR *_bstr_t::GetAddress() { | |
| 224 Attach(0); | |
| 225 return &m_Data->GetWString(); | |
| 226 } | |
| 227 | |
| 228 inline void _bstr_t::Attach(BSTR s) { | |
| 229 _Free(); | |
| 230 m_Data = new Data_t(s,FALSE); | |
| 231 if(!m_Data) { _com_issue_error(E_OUTOFMEMORY); } | |
| 232 } | |
| 233 | |
| 234 inline BSTR _bstr_t::Detach() { | |
| 235 _COM_ASSERT(m_Data!=NULL && m_Data->RefCount()==1); | |
| 236 if(m_Data!=NULL && m_Data->RefCount()==1) { | |
| 237 BSTR b = m_Data->GetWString(); | |
| 238 m_Data->GetWString() = NULL; | |
| 239 _Free(); | |
| 240 return b; | |
| 241 } else { | |
| 242 _com_issue_error(E_POINTER); | |
| 243 return NULL; | |
| 244 } | |
| 245 } | |
| 246 | |
| 247 inline void _bstr_t::_AddRef() throw() { | |
| 248 if(m_Data!=NULL) m_Data->AddRef(); | |
| 249 } | |
| 250 | |
| 251 inline void _bstr_t::_Free() throw() { | |
| 252 if(m_Data!=NULL) { | |
| 253 m_Data->Release(); | |
| 254 m_Data = NULL; | |
| 255 } | |
| 256 } | |
| 257 | |
| 258 inline int _bstr_t::_Compare(const _bstr_t &str) const throw() { | |
| 259 if(m_Data==str.m_Data) return 0; | |
| 260 if(!m_Data) return -1; | |
| 261 if(!str.m_Data) return 1; | |
| 262 return m_Data->Compare(*str.m_Data); | |
| 263 } | |
| 264 | |
| 265 inline _bstr_t::Data_t::Data_t(const char *s) : m_str(NULL),m_RefCount(1) { | |
| 266 m_wstr = _com_util::ConvertStringToBSTR(s); | |
| 267 } | |
| 268 | |
| 269 inline _bstr_t::Data_t::Data_t(const wchar_t *s) : m_str(NULL),m_RefCount(1) { | |
| 270 m_wstr = ::SysAllocString(s); | |
| 271 if(!m_wstr && s!=NULL) { _com_issue_error(E_OUTOFMEMORY); } | |
| 272 } | |
| 273 | |
| 274 inline _bstr_t::Data_t::Data_t(BSTR bstr,bool fCopy) : m_str(NULL),m_RefCount(1) { | |
| 275 if(fCopy && bstr!=NULL) { | |
| 276 m_wstr = ::SysAllocStringByteLen(reinterpret_cast<char *>(bstr),::SysStringByteLen(bstr)); | |
| 277 if(!m_wstr) { _com_issue_error(E_OUTOFMEMORY); } | |
| 278 } else m_wstr = bstr; | |
| 279 } | |
| 280 | |
| 281 inline _bstr_t::Data_t::Data_t(const _bstr_t &s1,const _bstr_t &s2) : m_str(NULL),m_RefCount(1) { | |
| 282 const unsigned int l1 = s1.length(); | |
| 283 const unsigned int l2 = s2.length(); | |
| 284 m_wstr = ::SysAllocStringByteLen(NULL,(l1 + l2) *sizeof(wchar_t)); | |
| 285 if(!m_wstr) { | |
| 286 _com_issue_error(E_OUTOFMEMORY); | |
| 287 return; | |
| 288 } | |
| 289 const wchar_t *wstr1 = static_cast<const wchar_t *>(s1); | |
| 290 if(wstr1!=NULL) { | |
| 291 _COM_MEMCPY_S(m_wstr,(l1 + l2 + 1) *sizeof(wchar_t),wstr1,(l1 + 1) *sizeof(wchar_t)); | |
| 292 } | |
| 293 const wchar_t *wstr2 = static_cast<const wchar_t *>(s2); | |
| 294 if(wstr2!=NULL) { | |
| 295 _COM_MEMCPY_S(m_wstr + l1,(l2 + 1) *sizeof(wchar_t),wstr2,(l2 + 1) *sizeof(wchar_t)); | |
| 296 } | |
| 297 } | |
| 298 | |
| 299 inline unsigned long _bstr_t::Data_t::AddRef() throw() { | |
| 300 InterlockedIncrement(reinterpret_cast<long*>(&m_RefCount)); | |
| 301 return m_RefCount; | |
| 302 } | |
| 303 | |
| 304 inline unsigned long _bstr_t::Data_t::Release() throw() { | |
| 305 unsigned long cRef = InterlockedDecrement(reinterpret_cast<long*>(&m_RefCount)); | |
| 306 if(cRef==0) delete this; | |
| 307 return cRef; | |
| 308 } | |
| 309 | |
| 310 inline unsigned long _bstr_t::Data_t::RefCount() const throw() { return m_RefCount; } | |
| 311 inline _bstr_t::Data_t::operator const wchar_t *() const throw() { return m_wstr; } | |
| 312 inline _bstr_t::Data_t::operator const char *() const { return GetString(); } | |
| 313 inline const wchar_t *_bstr_t::Data_t::GetWString() const throw() { return m_wstr; } | |
| 314 inline wchar_t *&_bstr_t::Data_t::GetWString() throw() { return m_wstr; } | |
| 315 inline const char *_bstr_t::Data_t::GetString() const { | |
| 316 if(!m_str) m_str = _com_util::ConvertBSTRToString(m_wstr); | |
| 317 return m_str; | |
| 318 } | |
| 319 inline BSTR _bstr_t::Data_t::Copy() const { | |
| 320 if(m_wstr!=NULL) { | |
| 321 BSTR bstr = ::SysAllocStringByteLen(reinterpret_cast<char *>(m_wstr),::SysStringByteLen(m_wstr)); | |
| 322 if(!bstr) { _com_issue_error(E_OUTOFMEMORY); } | |
| 323 return bstr; | |
| 324 } | |
| 325 return NULL; | |
| 326 } | |
| 327 inline void _bstr_t::Data_t::Assign(BSTR s) { | |
| 328 _Free(); | |
| 329 if(s!=NULL) { | |
| 330 m_wstr = ::SysAllocStringByteLen(reinterpret_cast<char *>(s),::SysStringByteLen(s)); | |
| 331 m_str = 0; | |
| 332 } | |
| 333 } | |
| 334 inline void _bstr_t::Data_t::Attach(BSTR s) throw() { | |
| 335 _Free(); | |
| 336 m_wstr = s; | |
| 337 m_str = 0; | |
| 338 m_RefCount = 1; | |
| 339 } | |
| 340 inline unsigned int _bstr_t::Data_t::Length() const throw() { return m_wstr ? ::SysStringLen(m_wstr) : 0; } | |
| 341 inline int _bstr_t::Data_t::Compare(const _bstr_t::Data_t &str) const throw() { | |
| 342 if(!m_wstr) return str.m_wstr ? -1 : 0; | |
| 343 if(!str.m_wstr) return 1; | |
| 344 const unsigned int l1 = ::SysStringLen(m_wstr); | |
| 345 const unsigned int l2 = ::SysStringLen(str.m_wstr); | |
| 346 unsigned int len = l1; | |
| 347 if(len>l2) len = l2; | |
| 348 BSTR bstr1 = m_wstr; | |
| 349 BSTR bstr2 = str.m_wstr; | |
| 350 while (len-->0) { | |
| 351 if(*bstr1++!=*bstr2++) return bstr1[-1] - bstr2[-1]; | |
| 352 } | |
| 353 return (l1<l2) ? -1 : (l1==l2) ? 0 : 1; | |
| 354 } | |
| 355 | |
| 356 #ifdef _COM_OPERATOR_NEW_THROWS | |
| 357 inline void *_bstr_t::Data_t::operator new(size_t sz) { | |
| 358 try { | |
| 359 return ::operator new(sz); | |
| 360 } catch (...) { | |
| 361 return NULL; | |
| 362 } | |
| 363 } | |
| 364 #else | |
| 365 inline void *_bstr_t::Data_t::operator new(size_t sz) { | |
| 366 return ::operator new(sz); | |
| 367 } | |
| 368 #endif | |
| 369 | |
| 370 inline _bstr_t::Data_t::~Data_t() throw() { _Free(); } | |
| 371 inline void _bstr_t::Data_t::_Free() throw() { | |
| 372 if(m_wstr!=NULL) ::SysFreeString(m_wstr); | |
| 373 if(m_str!=NULL) delete [] m_str; | |
| 374 } | |
| 375 | |
| 376 class _variant_t : public ::tagVARIANT { | |
| 377 public: | |
| 378 _variant_t() throw(); | |
| 379 _variant_t(const VARIANT &varSrc); | |
| 380 _variant_t(const VARIANT *pSrc); | |
| 381 _variant_t(const _variant_t &varSrc); | |
| 382 _variant_t(VARIANT &varSrc,bool fCopy); | |
| 383 _variant_t(short sSrc,VARTYPE vtSrc = VT_I2); | |
| 384 _variant_t(long lSrc,VARTYPE vtSrc = VT_I4); | |
| 385 _variant_t(float fltSrc) throw(); | |
| 386 _variant_t(double dblSrc,VARTYPE vtSrc = VT_R8); | |
| 387 _variant_t(const CY &cySrc) throw(); | |
| 388 _variant_t(const _bstr_t &bstrSrc); | |
| 389 _variant_t(const wchar_t *pSrc); | |
| 390 _variant_t(const char *pSrc); | |
| 391 _variant_t(IDispatch *pSrc,bool fAddRef = true) throw(); | |
| 392 _variant_t(bool boolSrc) throw(); | |
| 393 _variant_t(IUnknown *pSrc,bool fAddRef = true) throw(); | |
| 394 _variant_t(const DECIMAL &decSrc) throw(); | |
| 395 _variant_t(BYTE bSrc) throw(); | |
| 396 _variant_t(char cSrc) throw(); | |
| 397 _variant_t(unsigned short usSrc) throw(); | |
| 398 _variant_t(unsigned long ulSrc) throw(); | |
| 399 _variant_t(int iSrc) throw(); | |
| 400 _variant_t(unsigned int uiSrc) throw(); | |
| 401 __MINGW_EXTENSION _variant_t(__int64 i8Src) throw(); | |
| 402 __MINGW_EXTENSION _variant_t(unsigned __int64 ui8Src) throw(); | |
| 403 ~_variant_t() throw(); | |
| 404 operator short() const; | |
| 405 operator long() const; | |
| 406 operator float() const; | |
| 407 operator double() const; | |
| 408 operator CY() const; | |
| 409 operator _bstr_t() const; | |
| 410 operator IDispatch*() const; | |
| 411 operator bool() const; | |
| 412 operator IUnknown*() const; | |
| 413 operator DECIMAL() const; | |
| 414 operator BYTE() const; | |
| 415 operator VARIANT() const throw(); | |
| 416 operator char() const; | |
| 417 operator unsigned short() const; | |
| 418 operator unsigned long() const; | |
| 419 operator int() const; | |
| 420 operator unsigned int() const; | |
| 421 __MINGW_EXTENSION operator __int64() const; | |
| 422 __MINGW_EXTENSION operator unsigned __int64() const; | |
| 423 _variant_t &operator=(const VARIANT &varSrc); | |
| 424 _variant_t &operator=(const VARIANT *pSrc); | |
| 425 _variant_t &operator=(const _variant_t &varSrc); | |
| 426 _variant_t &operator=(short sSrc); | |
| 427 _variant_t &operator=(long lSrc); | |
| 428 _variant_t &operator=(float fltSrc); | |
| 429 _variant_t &operator=(double dblSrc); | |
| 430 _variant_t &operator=(const CY &cySrc); | |
| 431 _variant_t &operator=(const _bstr_t &bstrSrc); | |
| 432 _variant_t &operator=(const wchar_t *pSrc); | |
| 433 _variant_t &operator=(const char *pSrc); | |
| 434 _variant_t &operator=(IDispatch *pSrc); | |
| 435 _variant_t &operator=(bool boolSrc); | |
| 436 _variant_t &operator=(IUnknown *pSrc); | |
| 437 _variant_t &operator=(const DECIMAL &decSrc); | |
| 438 _variant_t &operator=(BYTE bSrc); | |
| 439 _variant_t &operator=(char cSrc); | |
| 440 _variant_t &operator=(unsigned short usSrc); | |
| 441 _variant_t &operator=(unsigned long ulSrc); | |
| 442 _variant_t &operator=(int iSrc); | |
| 443 _variant_t &operator=(unsigned int uiSrc); | |
| 444 __MINGW_EXTENSION _variant_t &operator=(__int64 i8Src); | |
| 445 __MINGW_EXTENSION _variant_t &operator=(unsigned __int64 ui8Src); | |
| 446 bool operator==(const VARIANT &varSrc) const throw(); | |
| 447 bool operator==(const VARIANT *pSrc) const throw(); | |
| 448 bool operator!=(const VARIANT &varSrc) const throw(); | |
| 449 bool operator!=(const VARIANT *pSrc) const throw(); | |
| 450 void Clear(); | |
| 451 void Attach(VARIANT &varSrc); | |
| 452 VARIANT Detach(); | |
| 453 VARIANT &GetVARIANT() throw(); | |
| 454 VARIANT *GetAddress(); | |
| 455 void ChangeType(VARTYPE vartype,const _variant_t *pSrc = NULL); | |
| 456 void SetString(const char *pSrc); | |
| 457 }; | |
| 458 | |
| 459 inline _variant_t::_variant_t() throw() { ::VariantInit(this); } | |
| 460 inline _variant_t::_variant_t(const VARIANT &varSrc) { | |
| 461 ::VariantInit(this); | |
| 462 _com_util::CheckError(::VariantCopy(this,const_cast<VARIANT*>(&varSrc))); | |
| 463 } | |
| 464 inline _variant_t::_variant_t(const VARIANT *pSrc) { | |
| 465 if(!pSrc) { _com_issue_error(E_POINTER); } | |
| 466 else { | |
| 467 ::VariantInit(this); | |
| 468 _com_util::CheckError(::VariantCopy(this,const_cast<VARIANT*>(pSrc))); | |
| 469 } | |
| 470 } | |
| 471 inline _variant_t::_variant_t(const _variant_t &varSrc) { | |
| 472 ::VariantInit(this); | |
| 473 _com_util::CheckError(::VariantCopy(this,const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)))); | |
| 474 } | |
| 475 inline _variant_t::_variant_t(VARIANT &varSrc,bool fCopy) { | |
| 476 if(fCopy) { | |
| 477 ::VariantInit(this); | |
| 478 _com_util::CheckError(::VariantCopy(this,&varSrc)); | |
| 479 } else { | |
| 480 _COM_MEMCPY_S(this,sizeof(varSrc),&varSrc,sizeof(varSrc)); | |
| 481 V_VT(&varSrc) = VT_EMPTY; | |
| 482 } | |
| 483 } | |
| 484 inline _variant_t::_variant_t(short sSrc,VARTYPE vtSrc) { | |
| 485 if((vtSrc!=VT_I2) && (vtSrc!=VT_BOOL)) { | |
| 486 _com_issue_error(E_INVALIDARG); | |
| 487 return; | |
| 488 } | |
| 489 if(vtSrc==VT_BOOL) { | |
| 490 V_VT(this) = VT_BOOL; | |
| 491 V_BOOL(this) = (sSrc ? VARIANT_TRUE : VARIANT_FALSE); | |
| 492 } else { | |
| 493 V_VT(this) = VT_I2; | |
| 494 V_I2(this) = sSrc; | |
| 495 } | |
| 496 } | |
| 497 inline _variant_t::_variant_t(long lSrc,VARTYPE vtSrc) { | |
| 498 if((vtSrc!=VT_I4) && (vtSrc!=VT_ERROR) && (vtSrc!=VT_BOOL)) { | |
| 499 _com_issue_error(E_INVALIDARG); | |
| 500 return; | |
| 501 } | |
| 502 if(vtSrc==VT_ERROR) { | |
| 503 V_VT(this) = VT_ERROR; | |
| 504 V_ERROR(this) = lSrc; | |
| 505 } else if(vtSrc==VT_BOOL) { | |
| 506 V_VT(this) = VT_BOOL; | |
| 507 V_BOOL(this) = (lSrc ? VARIANT_TRUE : VARIANT_FALSE); | |
| 508 } else { | |
| 509 V_VT(this) = VT_I4; | |
| 510 V_I4(this) = lSrc; | |
| 511 } | |
| 512 } | |
| 513 inline _variant_t::_variant_t(float fltSrc) throw() { | |
| 514 V_VT(this) = VT_R4; | |
| 515 V_R4(this) = fltSrc; | |
| 516 } | |
| 517 | |
| 518 inline _variant_t::_variant_t(double dblSrc,VARTYPE vtSrc) { | |
| 519 if((vtSrc!=VT_R8) && (vtSrc!=VT_DATE)) { | |
| 520 _com_issue_error(E_INVALIDARG); | |
| 521 return; | |
| 522 } | |
| 523 if(vtSrc==VT_DATE) { | |
| 524 V_VT(this) = VT_DATE; | |
| 525 V_DATE(this) = dblSrc; | |
| 526 } else { | |
| 527 V_VT(this) = VT_R8; | |
| 528 V_R8(this) = dblSrc; | |
| 529 } | |
| 530 } | |
| 531 inline _variant_t::_variant_t(const CY &cySrc) throw() { | |
| 532 V_VT(this) = VT_CY; | |
| 533 V_CY(this) = cySrc; | |
| 534 } | |
| 535 inline _variant_t::_variant_t(const _bstr_t &bstrSrc) { | |
| 536 V_VT(this) = VT_BSTR; | |
| 537 BSTR bstr = static_cast<wchar_t *>(bstrSrc); | |
| 538 if(!bstr) V_BSTR(this) = NULL; | |
| 539 else { | |
| 540 V_BSTR(this) = ::SysAllocStringByteLen(reinterpret_cast<char *>(bstr),::SysStringByteLen(bstr)); | |
| 541 if(!(V_BSTR(this))) { _com_issue_error(E_OUTOFMEMORY); } | |
| 542 } | |
| 543 } | |
| 544 inline _variant_t::_variant_t(const wchar_t *pSrc) { | |
| 545 V_VT(this) = VT_BSTR; | |
| 546 V_BSTR(this) = ::SysAllocString(pSrc); | |
| 547 if(!(V_BSTR(this)) && pSrc!=NULL) { _com_issue_error(E_OUTOFMEMORY); } | |
| 548 } | |
| 549 inline _variant_t::_variant_t(const char *pSrc) { | |
| 550 V_VT(this) = VT_BSTR; | |
| 551 V_BSTR(this) = _com_util::ConvertStringToBSTR(pSrc); | |
| 552 } | |
| 553 inline _variant_t::_variant_t(IDispatch *pSrc,bool fAddRef) throw() { | |
| 554 V_VT(this) = VT_DISPATCH; | |
| 555 V_DISPATCH(this) = pSrc; | |
| 556 if(fAddRef && V_DISPATCH(this)!=NULL) V_DISPATCH(this)->AddRef(); | |
| 557 } | |
| 558 inline _variant_t::_variant_t(bool boolSrc) throw() { | |
| 559 V_VT(this) = VT_BOOL; | |
| 560 V_BOOL(this) = (boolSrc ? VARIANT_TRUE : VARIANT_FALSE); | |
| 561 } | |
| 562 inline _variant_t::_variant_t(IUnknown *pSrc,bool fAddRef) throw() { | |
| 563 V_VT(this) = VT_UNKNOWN; | |
| 564 V_UNKNOWN(this) = pSrc; | |
| 565 if(fAddRef && V_UNKNOWN(this)!=NULL) V_UNKNOWN(this)->AddRef(); | |
| 566 } | |
| 567 inline _variant_t::_variant_t(const DECIMAL &decSrc) throw() { | |
| 568 V_DECIMAL(this) = decSrc; | |
| 569 V_VT(this) = VT_DECIMAL; | |
| 570 } | |
| 571 inline _variant_t::_variant_t(BYTE bSrc) throw() { | |
| 572 V_VT(this) = VT_UI1; | |
| 573 V_UI1(this) = bSrc; | |
| 574 } | |
| 575 inline _variant_t::_variant_t(char cSrc) throw() { | |
| 576 V_VT(this) = VT_I1; | |
| 577 V_I1(this) = cSrc; | |
| 578 } | |
| 579 inline _variant_t::_variant_t(unsigned short usSrc) throw() { | |
| 580 V_VT(this) = VT_UI2; | |
| 581 V_UI2(this) = usSrc; | |
| 582 } | |
| 583 inline _variant_t::_variant_t(unsigned long ulSrc) throw() { | |
| 584 V_VT(this) = VT_UI4; | |
| 585 V_UI4(this) = ulSrc; | |
| 586 } | |
| 587 inline _variant_t::_variant_t(int iSrc) throw() { | |
| 588 V_VT(this) = VT_INT; | |
| 589 V_INT(this) = iSrc; | |
| 590 } | |
| 591 inline _variant_t::_variant_t(unsigned int uiSrc) throw() { | |
| 592 V_VT(this) = VT_UINT; | |
| 593 V_UINT(this) = uiSrc; | |
| 594 } | |
| 595 __MINGW_EXTENSION inline _variant_t::_variant_t(__int64 i8Src) throw() { | |
| 596 V_VT(this) = VT_I8; | |
| 597 V_I8(this) = i8Src; | |
| 598 } | |
| 599 __MINGW_EXTENSION inline _variant_t::_variant_t(unsigned __int64 ui8Src) throw() { | |
| 600 V_VT(this) = VT_UI8; | |
| 601 V_UI8(this) = ui8Src; | |
| 602 } | |
| 603 inline _variant_t::operator short() const { | |
| 604 if(V_VT(this)==VT_I2) return V_I2(this); | |
| 605 _variant_t varDest; | |
| 606 varDest.ChangeType(VT_I2,this); | |
| 607 return V_I2(&varDest); | |
| 608 } | |
| 609 inline _variant_t::operator long() const { | |
| 610 if(V_VT(this)==VT_I4) return V_I4(this); | |
| 611 _variant_t varDest; | |
| 612 varDest.ChangeType(VT_I4,this); | |
| 613 return V_I4(&varDest); | |
| 614 } | |
| 615 | |
| 616 inline _variant_t::operator float() const { | |
| 617 if(V_VT(this)==VT_R4) return V_R4(this); | |
| 618 _variant_t varDest; | |
| 619 varDest.ChangeType(VT_R4,this); | |
| 620 return V_R4(&varDest); | |
| 621 } | |
| 622 | |
| 623 inline _variant_t::operator double() const { | |
| 624 if(V_VT(this)==VT_R8) return V_R8(this); | |
| 625 _variant_t varDest; | |
| 626 varDest.ChangeType(VT_R8,this); | |
| 627 return V_R8(&varDest); | |
| 628 } | |
| 629 | |
| 630 inline _variant_t::operator CY() const { | |
| 631 if(V_VT(this)==VT_CY) return V_CY(this); | |
| 632 _variant_t varDest; | |
| 633 varDest.ChangeType(VT_CY,this); | |
| 634 return V_CY(&varDest); | |
| 635 } | |
| 636 | |
| 637 inline _variant_t::operator _bstr_t() const { | |
| 638 if(V_VT(this)==VT_BSTR) return V_BSTR(this); | |
| 639 _variant_t varDest; | |
| 640 varDest.ChangeType(VT_BSTR,this); | |
| 641 return V_BSTR(&varDest); | |
| 642 } | |
| 643 | |
| 644 inline _variant_t::operator IDispatch*() const { | |
| 645 if(V_VT(this)==VT_DISPATCH) { | |
| 646 if(V_DISPATCH(this)!=NULL) V_DISPATCH(this)->AddRef(); | |
| 647 return V_DISPATCH(this); | |
| 648 } | |
| 649 _variant_t varDest; | |
| 650 varDest.ChangeType(VT_DISPATCH,this); | |
| 651 if(V_DISPATCH(&varDest)!=NULL) V_DISPATCH(&varDest)->AddRef(); | |
| 652 return V_DISPATCH(&varDest); | |
| 653 } | |
| 654 inline _variant_t::operator bool() const { | |
| 655 if(V_VT(this)==VT_BOOL) return V_BOOL(this) ? true : false; | |
| 656 _variant_t varDest; | |
| 657 varDest.ChangeType(VT_BOOL,this); | |
| 658 return (V_BOOL(&varDest)==VARIANT_TRUE) ? true : false; | |
| 659 } | |
| 660 | |
| 661 inline _variant_t::operator IUnknown*() const { | |
| 662 if(V_VT(this)==VT_UNKNOWN) { | |
| 663 if(V_UNKNOWN(this)!=NULL) V_UNKNOWN(this)->AddRef(); | |
| 664 return V_UNKNOWN(this); | |
| 665 } | |
| 666 _variant_t varDest; | |
| 667 varDest.ChangeType(VT_UNKNOWN,this); | |
| 668 if(V_UNKNOWN(&varDest)!=NULL) V_UNKNOWN(&varDest)->AddRef(); | |
| 669 return V_UNKNOWN(&varDest); | |
| 670 } | |
| 671 inline _variant_t::operator DECIMAL() const { | |
| 672 if(V_VT(this)==VT_DECIMAL) return V_DECIMAL(this); | |
| 673 _variant_t varDest; | |
| 674 varDest.ChangeType(VT_DECIMAL,this); | |
| 675 return V_DECIMAL(&varDest); | |
| 676 } | |
| 677 inline _variant_t::operator BYTE() const { | |
| 678 if(V_VT(this)==VT_UI1) return V_UI1(this); | |
| 679 _variant_t varDest; | |
| 680 varDest.ChangeType(VT_UI1,this); | |
| 681 return V_UI1(&varDest); | |
| 682 } | |
| 683 inline _variant_t::operator VARIANT() const throw() { return *(VARIANT*) this; } | |
| 684 inline _variant_t::operator char() const { | |
| 685 if(V_VT(this)==VT_I1) return V_I1(this); | |
| 686 _variant_t varDest; | |
| 687 varDest.ChangeType(VT_I1,this); | |
| 688 return V_I1(&varDest); | |
| 689 } | |
| 690 | |
| 691 inline _variant_t::operator unsigned short() const { | |
| 692 if(V_VT(this)==VT_UI2) return V_UI2(this); | |
| 693 _variant_t varDest; | |
| 694 varDest.ChangeType(VT_UI2,this); | |
| 695 return V_UI2(&varDest); | |
| 696 } | |
| 697 | |
| 698 inline _variant_t::operator unsigned long() const { | |
| 699 if(V_VT(this)==VT_UI4) return V_UI4(this); | |
| 700 _variant_t varDest; | |
| 701 varDest.ChangeType(VT_UI4,this); | |
| 702 return V_UI4(&varDest); | |
| 703 } | |
| 704 inline _variant_t::operator int() const { | |
| 705 if(V_VT(this)==VT_INT) return V_INT(this); | |
| 706 _variant_t varDest; | |
| 707 varDest.ChangeType(VT_INT,this); | |
| 708 return V_INT(&varDest); | |
| 709 } | |
| 710 inline _variant_t::operator unsigned int() const { | |
| 711 if(V_VT(this)==VT_UINT) return V_UINT(this); | |
| 712 _variant_t varDest; | |
| 713 varDest.ChangeType(VT_UINT,this); | |
| 714 return V_UINT(&varDest); | |
| 715 } | |
| 716 __MINGW_EXTENSION inline _variant_t::operator __int64() const { | |
| 717 if(V_VT(this)==VT_I8) return V_I8(this); | |
| 718 _variant_t varDest; | |
| 719 varDest.ChangeType(VT_I8,this); | |
| 720 return V_I8(&varDest); | |
| 721 } | |
| 722 __MINGW_EXTENSION inline _variant_t::operator unsigned __int64() const { | |
| 723 if(V_VT(this)==VT_UI8) return V_UI8(this); | |
| 724 _variant_t varDest; | |
| 725 varDest.ChangeType(VT_UI8,this); | |
| 726 return V_UI8(&varDest); | |
| 727 } | |
| 728 inline _variant_t &_variant_t::operator=(const VARIANT &varSrc) { | |
| 729 _com_util::CheckError(::VariantCopy(this,const_cast<VARIANT*>(&varSrc))); | |
| 730 return *this; | |
| 731 } | |
| 732 inline _variant_t &_variant_t::operator=(const VARIANT *pSrc) { | |
| 733 if(!pSrc) { _com_issue_error(E_POINTER); } | |
| 734 else { _com_util::CheckError(::VariantCopy(this,const_cast<VARIANT*>(pSrc))); } | |
| 735 return *this; | |
| 736 } | |
| 737 inline _variant_t &_variant_t::operator=(const _variant_t &varSrc) { | |
| 738 _com_util::CheckError(::VariantCopy(this,const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)))); | |
| 739 return *this; | |
| 740 } | |
| 741 inline _variant_t &_variant_t::operator=(short sSrc) { | |
| 742 if(V_VT(this)==VT_I2) V_I2(this) = sSrc; | |
| 743 else if(V_VT(this)==VT_BOOL) V_BOOL(this) = (sSrc ? VARIANT_TRUE : VARIANT_FALSE); | |
| 744 else { | |
| 745 Clear(); | |
| 746 V_VT(this) = VT_I2; | |
| 747 V_I2(this) = sSrc; | |
| 748 } | |
| 749 return *this; | |
| 750 } | |
| 751 inline _variant_t &_variant_t::operator=(long lSrc) { | |
| 752 if(V_VT(this)==VT_I4) V_I4(this) = lSrc; | |
| 753 else if(V_VT(this)==VT_ERROR) V_ERROR(this) = lSrc; | |
| 754 else if(V_VT(this)==VT_BOOL) V_BOOL(this) = (lSrc ? VARIANT_TRUE : VARIANT_FALSE); | |
| 755 else { | |
| 756 Clear(); | |
| 757 V_VT(this) = VT_I4; | |
| 758 V_I4(this) = lSrc; | |
| 759 } | |
| 760 return *this; | |
| 761 } | |
| 762 inline _variant_t &_variant_t::operator=(float fltSrc) { | |
| 763 if(V_VT(this)!=VT_R4) { | |
| 764 Clear(); | |
| 765 V_VT(this) = VT_R4; | |
| 766 } | |
| 767 V_R4(this) = fltSrc; | |
| 768 return *this; | |
| 769 } | |
| 770 | |
| 771 inline _variant_t &_variant_t::operator=(double dblSrc) | |
| 772 { | |
| 773 if(V_VT(this)==VT_R8) { | |
| 774 V_R8(this) = dblSrc; | |
| 775 } | |
| 776 else if(V_VT(this)==VT_DATE) { | |
| 777 V_DATE(this) = dblSrc; | |
| 778 } | |
| 779 else { | |
| 780 | |
| 781 Clear(); | |
| 782 | |
| 783 V_VT(this) = VT_R8; | |
| 784 V_R8(this) = dblSrc; | |
| 785 } | |
| 786 | |
| 787 return *this; | |
| 788 } | |
| 789 | |
| 790 inline _variant_t &_variant_t::operator=(const CY &cySrc) | |
| 791 { | |
| 792 if(V_VT(this)!=VT_CY) { | |
| 793 | |
| 794 Clear(); | |
| 795 | |
| 796 V_VT(this) = VT_CY; | |
| 797 } | |
| 798 | |
| 799 V_CY(this) = cySrc; | |
| 800 | |
| 801 return *this; | |
| 802 } | |
| 803 | |
| 804 inline _variant_t &_variant_t::operator=(const _bstr_t &bstrSrc) | |
| 805 { | |
| 806 _COM_ASSERT(V_VT(this)!=VT_BSTR || !((BSTR) bstrSrc) || V_BSTR(this)!=(BSTR) bstrSrc); | |
| 807 | |
| 808 Clear(); | |
| 809 | |
| 810 V_VT(this) = VT_BSTR; | |
| 811 | |
| 812 if(!bstrSrc) { | |
| 813 V_BSTR(this) = NULL; | |
| 814 } | |
| 815 else { | |
| 816 BSTR bstr = static_cast<wchar_t *>(bstrSrc); | |
| 817 V_BSTR(this) = ::SysAllocStringByteLen(reinterpret_cast<char *>(bstr),::SysStringByteLen(bstr)); | |
| 818 | |
| 819 if(!(V_BSTR(this))) { | |
| 820 _com_issue_error(E_OUTOFMEMORY); | |
| 821 } | |
| 822 } | |
| 823 | |
| 824 return *this; | |
| 825 } | |
| 826 | |
| 827 inline _variant_t &_variant_t::operator=(const wchar_t *pSrc) | |
| 828 { | |
| 829 _COM_ASSERT(V_VT(this)!=VT_BSTR || !pSrc || V_BSTR(this)!=pSrc); | |
| 830 | |
| 831 Clear(); | |
| 832 | |
| 833 V_VT(this) = VT_BSTR; | |
| 834 | |
| 835 if(!pSrc) { | |
| 836 V_BSTR(this) = NULL; | |
| 837 } | |
| 838 else { | |
| 839 V_BSTR(this) = ::SysAllocString(pSrc); | |
| 840 | |
| 841 if(!(V_BSTR(this))) { | |
| 842 _com_issue_error(E_OUTOFMEMORY); | |
| 843 } | |
| 844 } | |
| 845 | |
| 846 return *this; | |
| 847 } | |
| 848 | |
| 849 inline _variant_t &_variant_t::operator=(const char *pSrc) | |
| 850 { | |
| 851 _COM_ASSERT(V_VT(this)!=(VT_I1 | VT_BYREF) || !pSrc || V_I1REF(this)!=pSrc); | |
| 852 | |
| 853 Clear(); | |
| 854 | |
| 855 V_VT(this) = VT_BSTR; | |
| 856 V_BSTR(this) = _com_util::ConvertStringToBSTR(pSrc); | |
| 857 | |
| 858 return *this; | |
| 859 } | |
| 860 | |
| 861 inline _variant_t &_variant_t::operator=(IDispatch *pSrc) | |
| 862 { | |
| 863 _COM_ASSERT(V_VT(this)!=VT_DISPATCH || pSrc==0 || V_DISPATCH(this)!=pSrc); | |
| 864 | |
| 865 Clear(); | |
| 866 | |
| 867 V_VT(this) = VT_DISPATCH; | |
| 868 V_DISPATCH(this) = pSrc; | |
| 869 | |
| 870 if(V_DISPATCH(this)!=NULL) { | |
| 871 | |
| 872 V_DISPATCH(this)->AddRef(); | |
| 873 } | |
| 874 | |
| 875 return *this; | |
| 876 } | |
| 877 | |
| 878 inline _variant_t &_variant_t::operator=(bool boolSrc) | |
| 879 { | |
| 880 if(V_VT(this)!=VT_BOOL) { | |
| 881 | |
| 882 Clear(); | |
| 883 | |
| 884 V_VT(this) = VT_BOOL; | |
| 885 } | |
| 886 | |
| 887 V_BOOL(this) = (boolSrc ? VARIANT_TRUE : VARIANT_FALSE); | |
| 888 | |
| 889 return *this; | |
| 890 } | |
| 891 | |
| 892 inline _variant_t &_variant_t::operator=(IUnknown *pSrc) | |
| 893 { | |
| 894 _COM_ASSERT(V_VT(this)!=VT_UNKNOWN || !pSrc || V_UNKNOWN(this)!=pSrc); | |
| 895 | |
| 896 Clear(); | |
| 897 | |
| 898 V_VT(this) = VT_UNKNOWN; | |
| 899 V_UNKNOWN(this) = pSrc; | |
| 900 | |
| 901 if(V_UNKNOWN(this)!=NULL) { | |
| 902 | |
| 903 V_UNKNOWN(this)->AddRef(); | |
| 904 } | |
| 905 | |
| 906 return *this; | |
| 907 } | |
| 908 | |
| 909 inline _variant_t &_variant_t::operator=(const DECIMAL &decSrc) | |
| 910 { | |
| 911 if(V_VT(this)!=VT_DECIMAL) { | |
| 912 | |
| 913 Clear(); | |
| 914 } | |
| 915 | |
| 916 V_DECIMAL(this) = decSrc; | |
| 917 V_VT(this) = VT_DECIMAL; | |
| 918 | |
| 919 return *this; | |
| 920 } | |
| 921 | |
| 922 inline _variant_t &_variant_t::operator=(BYTE bSrc) | |
| 923 { | |
| 924 if(V_VT(this)!=VT_UI1) { | |
| 925 | |
| 926 Clear(); | |
| 927 | |
| 928 V_VT(this) = VT_UI1; | |
| 929 } | |
| 930 | |
| 931 V_UI1(this) = bSrc; | |
| 932 | |
| 933 return *this; | |
| 934 } | |
| 935 | |
| 936 inline _variant_t &_variant_t::operator=(char cSrc) | |
| 937 { | |
| 938 if(V_VT(this)!=VT_I1) { | |
| 939 | |
| 940 Clear(); | |
| 941 | |
| 942 V_VT(this) = VT_I1; | |
| 943 } | |
| 944 | |
| 945 V_I1(this) = cSrc; | |
| 946 | |
| 947 return *this; | |
| 948 } | |
| 949 | |
| 950 inline _variant_t &_variant_t::operator=(unsigned short usSrc) | |
| 951 { | |
| 952 if(V_VT(this)!=VT_UI2) { | |
| 953 | |
| 954 Clear(); | |
| 955 | |
| 956 V_VT(this) = VT_UI2; | |
| 957 } | |
| 958 | |
| 959 V_UI2(this) = usSrc; | |
| 960 | |
| 961 return *this; | |
| 962 } | |
| 963 | |
| 964 inline _variant_t &_variant_t::operator=(unsigned long ulSrc) | |
| 965 { | |
| 966 if(V_VT(this)!=VT_UI4) { | |
| 967 | |
| 968 Clear(); | |
| 969 | |
| 970 V_VT(this) = VT_UI4; | |
| 971 } | |
| 972 | |
| 973 V_UI4(this) = ulSrc; | |
| 974 | |
| 975 return *this; | |
| 976 } | |
| 977 | |
| 978 inline _variant_t &_variant_t::operator=(int iSrc) | |
| 979 { | |
| 980 if(V_VT(this)!=VT_INT) { | |
| 981 | |
| 982 Clear(); | |
| 983 | |
| 984 V_VT(this) = VT_INT; | |
| 985 } | |
| 986 | |
| 987 V_INT(this) = iSrc; | |
| 988 | |
| 989 return *this; | |
| 990 } | |
| 991 | |
| 992 inline _variant_t &_variant_t::operator=(unsigned int uiSrc) | |
| 993 { | |
| 994 if(V_VT(this)!=VT_UINT) { | |
| 995 | |
| 996 Clear(); | |
| 997 | |
| 998 V_VT(this) = VT_UINT; | |
| 999 } | |
| 1000 | |
| 1001 V_UINT(this) = uiSrc; | |
| 1002 | |
| 1003 return *this; | |
| 1004 } | |
| 1005 | |
| 1006 __MINGW_EXTENSION inline _variant_t &_variant_t::operator=(__int64 i8Src) { | |
| 1007 if(V_VT(this)!=VT_I8) { | |
| 1008 | |
| 1009 Clear(); | |
| 1010 | |
| 1011 V_VT(this) = VT_I8; | |
| 1012 } | |
| 1013 | |
| 1014 V_I8(this) = i8Src; | |
| 1015 | |
| 1016 return *this; | |
| 1017 } | |
| 1018 | |
| 1019 __MINGW_EXTENSION inline _variant_t &_variant_t::operator=(unsigned __int64 ui8Src) { | |
| 1020 if(V_VT(this)!=VT_UI8) { | |
| 1021 | |
| 1022 Clear(); | |
| 1023 | |
| 1024 V_VT(this) = VT_UI8; | |
| 1025 } | |
| 1026 | |
| 1027 V_UI8(this) = ui8Src; | |
| 1028 | |
| 1029 return *this; | |
| 1030 } | |
| 1031 | |
| 1032 inline bool _variant_t::operator==(const VARIANT &varSrc) const throw() { | |
| 1033 return *this==&varSrc; | |
| 1034 } | |
| 1035 | |
| 1036 inline bool _variant_t::operator==(const VARIANT *pSrc) const throw() | |
| 1037 { | |
| 1038 if(!pSrc) { | |
| 1039 return false; | |
| 1040 } | |
| 1041 | |
| 1042 if(this==pSrc) { | |
| 1043 return true; | |
| 1044 } | |
| 1045 | |
| 1046 if(V_VT(this)!=V_VT(pSrc)) { | |
| 1047 return false; | |
| 1048 } | |
| 1049 | |
| 1050 switch (V_VT(this)) { | |
| 1051 case VT_EMPTY: | |
| 1052 case VT_NULL: | |
| 1053 return true; | |
| 1054 | |
| 1055 case VT_I2: | |
| 1056 return V_I2(this)==V_I2(pSrc); | |
| 1057 | |
| 1058 case VT_I4: | |
| 1059 return V_I4(this)==V_I4(pSrc); | |
| 1060 | |
| 1061 case VT_R4: | |
| 1062 return V_R4(this)==V_R4(pSrc); | |
| 1063 | |
| 1064 case VT_R8: | |
| 1065 return V_R8(this)==V_R8(pSrc); | |
| 1066 | |
| 1067 case VT_CY: | |
| 1068 return memcmp(&(V_CY(this)),&(V_CY(pSrc)),sizeof(CY))==0; | |
| 1069 | |
| 1070 case VT_DATE: | |
| 1071 return V_DATE(this)==V_DATE(pSrc); | |
| 1072 | |
| 1073 case VT_BSTR: | |
| 1074 return (::SysStringByteLen(V_BSTR(this))==::SysStringByteLen(V_BSTR(pSrc))) && | |
| 1075 (memcmp(V_BSTR(this),V_BSTR(pSrc),::SysStringByteLen(V_BSTR(this)))==0); | |
| 1076 | |
| 1077 case VT_DISPATCH: | |
| 1078 return V_DISPATCH(this)==V_DISPATCH(pSrc); | |
| 1079 | |
| 1080 case VT_ERROR: | |
| 1081 return V_ERROR(this)==V_ERROR(pSrc); | |
| 1082 | |
| 1083 case VT_BOOL: | |
| 1084 return V_BOOL(this)==V_BOOL(pSrc); | |
| 1085 | |
| 1086 case VT_UNKNOWN: | |
| 1087 return V_UNKNOWN(this)==V_UNKNOWN(pSrc); | |
| 1088 | |
| 1089 case VT_DECIMAL: | |
| 1090 return memcmp(&(V_DECIMAL(this)),&(V_DECIMAL(pSrc)),sizeof(DECIMAL))==0; | |
| 1091 | |
| 1092 case VT_UI1: | |
| 1093 return V_UI1(this)==V_UI1(pSrc); | |
| 1094 | |
| 1095 case VT_I1: | |
| 1096 return V_I1(this)==V_I1(pSrc); | |
| 1097 | |
| 1098 case VT_UI2: | |
| 1099 return V_UI2(this)==V_UI2(pSrc); | |
| 1100 | |
| 1101 case VT_UI4: | |
| 1102 return V_UI4(this)==V_UI4(pSrc); | |
| 1103 | |
| 1104 case VT_INT: | |
| 1105 return V_INT(this)==V_INT(pSrc); | |
| 1106 | |
| 1107 case VT_UINT: | |
| 1108 return V_UINT(this)==V_UINT(pSrc); | |
| 1109 | |
| 1110 case VT_I8: | |
| 1111 return V_I8(this)==V_I8(pSrc); | |
| 1112 | |
| 1113 case VT_UI8: | |
| 1114 return V_UI8(this)==V_UI8(pSrc); | |
| 1115 | |
| 1116 default: | |
| 1117 _com_issue_error(E_INVALIDARG); | |
| 1118 | |
| 1119 } | |
| 1120 | |
| 1121 return false; | |
| 1122 } | |
| 1123 | |
| 1124 inline bool _variant_t::operator!=(const VARIANT &varSrc) const throw() | |
| 1125 { | |
| 1126 return !(*this==&varSrc); | |
| 1127 } | |
| 1128 | |
| 1129 inline bool _variant_t::operator!=(const VARIANT *pSrc) const throw() | |
| 1130 { | |
| 1131 return !(*this==pSrc); | |
| 1132 } | |
| 1133 | |
| 1134 inline void _variant_t::Clear() | |
| 1135 { | |
| 1136 _com_util::CheckError(::VariantClear(this)); | |
| 1137 } | |
| 1138 | |
| 1139 inline void _variant_t::Attach(VARIANT &varSrc) | |
| 1140 { | |
| 1141 | |
| 1142 Clear(); | |
| 1143 | |
| 1144 _COM_MEMCPY_S(this,sizeof(varSrc),&varSrc,sizeof(varSrc)); | |
| 1145 V_VT(&varSrc) = VT_EMPTY; | |
| 1146 } | |
| 1147 | |
| 1148 inline VARIANT _variant_t::Detach() | |
| 1149 { | |
| 1150 VARIANT varResult = *this; | |
| 1151 V_VT(this) = VT_EMPTY; | |
| 1152 | |
| 1153 return varResult; | |
| 1154 } | |
| 1155 | |
| 1156 inline VARIANT &_variant_t::GetVARIANT() throw() | |
| 1157 { | |
| 1158 return *(VARIANT*) this; | |
| 1159 } | |
| 1160 | |
| 1161 inline VARIANT *_variant_t::GetAddress() { | |
| 1162 Clear(); | |
| 1163 return (VARIANT*) this; | |
| 1164 } | |
| 1165 inline void _variant_t::ChangeType(VARTYPE vartype,const _variant_t *pSrc) { | |
| 1166 if(!pSrc) pSrc = this; | |
| 1167 if((this!=pSrc) || (vartype!=V_VT(this))) { | |
| 1168 _com_util::CheckError(::VariantChangeType(static_cast<VARIANT*>(this),const_cast<VARIANT*>(static_cast<const VARIANT*>(pSrc)),0,vartype)); | |
| 1169 } | |
| 1170 } | |
| 1171 inline void _variant_t::SetString(const char *pSrc) { operator=(pSrc); } | |
| 1172 inline _variant_t::~_variant_t() throw() { ::VariantClear(this); } | |
| 1173 inline _bstr_t::_bstr_t(const _variant_t &var) : m_Data(NULL) { | |
| 1174 if(V_VT(&var)==VT_BSTR) { | |
| 1175 *this = V_BSTR(&var); | |
| 1176 return; | |
| 1177 } | |
| 1178 _variant_t varDest; | |
| 1179 varDest.ChangeType(VT_BSTR,&var); | |
| 1180 *this = V_BSTR(&varDest); | |
| 1181 } | |
| 1182 inline _bstr_t &_bstr_t::operator=(const _variant_t &var) { | |
| 1183 if(V_VT(&var)==VT_BSTR) { | |
| 1184 *this = V_BSTR(&var); | |
| 1185 return *this; | |
| 1186 } | |
| 1187 _variant_t varDest; | |
| 1188 varDest.ChangeType(VT_BSTR,&var); | |
| 1189 *this = V_BSTR(&varDest); | |
| 1190 return *this; | |
| 1191 } | |
| 1192 | |
| 1193 extern _variant_t vtMissing; | |
| 1194 | |
| 1195 #ifndef _USE_RAW | |
| 1196 #define bstr_t _bstr_t | |
| 1197 #define variant_t _variant_t | |
| 1198 #endif | |
| 1199 | |
| 1200 #pragma pop_macro("new") | |
| 1201 | |
| 1202 #endif /* __cplusplus */ | |
| 1203 | |
| 1204 #endif |
