Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

626 lines
13 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: StgVar.hxx
  7. //
  8. // Contents: C++ wrapper for PROPVARIANT.
  9. //
  10. // History: 01-Aug-94 KyleP Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #if !defined(__STGVAR_HXX__)
  14. #define __STGVAR_HXX__
  15. #include <objbase.h>
  16. #include <stgvara.hxx>
  17. //+-------------------------------------------------------------------------
  18. //
  19. // Class: CStorageVariant
  20. //
  21. // Purpose: C++ wrapper for PROPVARIANT
  22. //
  23. // History: 01-Aug-94 KyleP Created
  24. //
  25. // Notes: A couple of variant arms are not implemented below.
  26. // VT_BSTR because its type signature is identical to that of
  27. // VT_LPSTR. VT_SAFEARRAY because I don't fully understand the
  28. // structure.
  29. //
  30. // Some types are duplicate base types with a different variant
  31. // tag. These include:
  32. // VARIANT_BOOL (short)
  33. // SCODE (long)
  34. // DATE (double)
  35. // We cannot create trivial constructors for the above because
  36. // of the type collision. You must use the Set methods.
  37. //
  38. // Some types will automatically coerce and cause confusion,
  39. // so they don't have constructors. You must use the Set
  40. // method. These include:
  41. // VT_UI2
  42. // VT_UI4
  43. // VT_UI8
  44. //
  45. //--------------------------------------------------------------------------
  46. class CCoTaskAllocator : public PMemoryAllocator
  47. {
  48. public:
  49. virtual void *Allocate(ULONG cbSize);
  50. virtual void Free(void *pv);
  51. };
  52. #ifndef COTASKDECLSPEC
  53. #define COTASKDECLSPEC __declspec(dllimport)
  54. #endif
  55. COTASKDECLSPEC CCoTaskAllocator CoTaskAllocator;
  56. class CStorageVariant : public CAllocStorageVariant
  57. {
  58. public:
  59. //
  60. // Simple types
  61. //
  62. CStorageVariant() { vt = VT_EMPTY; }
  63. CStorageVariant(short i) { vt = VT_I2; iVal = i; }
  64. CStorageVariant(long l) { vt = VT_I4; lVal = l; }
  65. CStorageVariant(LARGE_INTEGER h) { vt = VT_I8; hVal = h; }
  66. CStorageVariant(float flt) { vt = VT_R4; fltVal = flt; }
  67. CStorageVariant(double dbl) { vt = VT_R8; dblVal = dbl; }
  68. CStorageVariant(CY cy) { vt = VT_CY; cyVal = cy; }
  69. CStorageVariant(FILETIME ft) { vt = VT_FILETIME; filetime = ft; }
  70. inline CStorageVariant & operator =(CStorageVariant const &var);
  71. inline CStorageVariant & operator =(short i);
  72. inline CStorageVariant & operator =(USHORT ui);
  73. inline CStorageVariant & operator =(long l);
  74. inline CStorageVariant & operator =(ULONG ul);
  75. inline CStorageVariant & operator =(LARGE_INTEGER h);
  76. inline CStorageVariant & operator =(ULARGE_INTEGER uh);
  77. inline CStorageVariant & operator =(float flt);
  78. inline CStorageVariant & operator =(double dbl);
  79. inline CStorageVariant & operator =(CY cy);
  80. inline CStorageVariant & operator =(FILETIME ft);
  81. //
  82. // Types with indirection
  83. //
  84. CStorageVariant(BLOB b);
  85. CStorageVariant(BYTE *pb, ULONG cb);
  86. CStorageVariant(char const *psz);
  87. CStorageVariant(WCHAR const *pwsz);
  88. CStorageVariant(CLSID const *pcid);
  89. inline CStorageVariant & operator =(BLOB b);
  90. inline CStorageVariant & operator =(char const *psz);
  91. inline CStorageVariant & operator =(WCHAR const *pwsz);
  92. inline CStorageVariant & operator =(CLSID const *pcid);
  93. //
  94. // Interface types
  95. //
  96. CStorageVariant(IStream *pstr);
  97. CStorageVariant(IStorage *pstor);
  98. //
  99. // Counted array types. Elements initially zeroed. Use Set/Get/Size
  100. // for access.
  101. //
  102. CStorageVariant(VARENUM vt, ULONG cElements);
  103. //
  104. // To/From C style PROPVARIANT and copy constructor
  105. //
  106. inline CStorageVariant(CStorageVariant const &var);
  107. CStorageVariant(PROPVARIANT &var);
  108. //
  109. // Destructor
  110. //
  111. ~CStorageVariant();
  112. //
  113. // Memory allocation. Uses CoTaskAllocator
  114. //
  115. inline void *operator new(size_t size);
  116. inline void operator delete(void *p);
  117. inline void *operator new(size_t size, void *p);
  118. #if _MSC_VER >= 1200
  119. inline void operator delete(void *p, void *pp);
  120. #endif
  121. //
  122. // Serialization
  123. //
  124. CStorageVariant(PDeSerStream &stm);
  125. //
  126. // Set/Get, all types including arrays.
  127. //
  128. inline void SetEMPTY();
  129. inline void SetNULL();
  130. inline void SetI1(CHAR i);
  131. inline void SetUI1(BYTE i);
  132. inline void SetI2(short i);
  133. inline void SetUI2(USHORT ui);
  134. inline void SetI4(long l);
  135. inline void SetUI4(ULONG ul);
  136. inline void SetR4(float f);
  137. inline void SetR8(double d);
  138. inline void SetI8(LARGE_INTEGER li);
  139. inline void SetUI8(ULARGE_INTEGER uli);
  140. inline void SetBOOL(VARIANT_BOOL b);
  141. inline void SetERROR(SCODE sc);
  142. inline void SetCY(CY cy);
  143. inline void SetDATE(DATE d);
  144. inline void SetFILETIME(FILETIME ft);
  145. inline void SetBSTR(BSTR b);
  146. // void SetSAFEARRAY(SAFEARRAY &sa);
  147. // SAFEARRAY GetSAFEARRAY();
  148. inline void SetLPSTR(char const *psz);
  149. inline void SetLPWSTR(WCHAR const *pwsz);
  150. inline void SetBLOB(BLOB b);
  151. inline void SetSTREAM(IStream *ps);
  152. inline void SetSTREAMED_OBJECT(IStream *ps);
  153. inline void SetSTORAGE(IStorage *ps);
  154. inline void SetSTORED_OBJECT(IStorage *ps);
  155. inline void SetCLSID(CLSID const *pc);
  156. //
  157. // Array access
  158. //
  159. void SetI1(CHAR i, unsigned pos);
  160. void SetUI1(BYTE i, unsigned pos);
  161. void SetI2(short i, unsigned pos);
  162. void SetUI2(USHORT ui, unsigned pos);
  163. void SetI4(long l, unsigned pos);
  164. void SetUI4(ULONG ul, unsigned pos);
  165. void SetI8(LARGE_INTEGER li, unsigned pos);
  166. void SetUI8(ULARGE_INTEGER uli, unsigned pos);
  167. void SetR4(float f, unsigned pos);
  168. void SetR8(double d, unsigned pos);
  169. void SetBOOL(VARIANT_BOOL b, unsigned pos);
  170. void SetERROR(SCODE sc, unsigned pos);
  171. void SetCY(CY c, unsigned pos);
  172. void SetDATE(DATE d, unsigned pos);
  173. void SetBSTR(BSTR b, unsigned pos);
  174. // void SetVARIANT(CStorageVariant var, unsigned pos);
  175. // CStorageVariant GetVARIANT(unsigned pos) const;
  176. void SetLPSTR(char const *psz, unsigned pos);
  177. void SetLPWSTR(WCHAR const *pwsz, unsigned pos);
  178. void SetFILETIME(FILETIME f, unsigned pos);
  179. void SetCLSID(CLSID c, unsigned pos);
  180. };
  181. inline
  182. CStorageVariant::CStorageVariant(BYTE *pb, ULONG cb) :
  183. CAllocStorageVariant(pb, cb, CoTaskAllocator)
  184. {
  185. }
  186. inline
  187. CStorageVariant::CStorageVariant(char const *psz) :
  188. CAllocStorageVariant(psz, CoTaskAllocator)
  189. {
  190. }
  191. inline
  192. CStorageVariant::CStorageVariant(WCHAR const *pwsz) :
  193. CAllocStorageVariant(pwsz, CoTaskAllocator)
  194. {
  195. }
  196. inline
  197. CStorageVariant::CStorageVariant(CLSID const *pcid) :
  198. CAllocStorageVariant(pcid, CoTaskAllocator)
  199. {
  200. }
  201. inline
  202. CStorageVariant::CStorageVariant(VARENUM v, ULONG cElements) :
  203. CAllocStorageVariant(v, cElements, CoTaskAllocator)
  204. {
  205. }
  206. inline
  207. CStorageVariant::CStorageVariant(PROPVARIANT &var) :
  208. CAllocStorageVariant(var, CoTaskAllocator)
  209. {
  210. }
  211. inline
  212. CStorageVariant::CStorageVariant(PDeSerStream &MemDeSerStream) :
  213. CAllocStorageVariant(MemDeSerStream, CoTaskAllocator)
  214. {
  215. }
  216. inline
  217. CStorageVariant::~CStorageVariant()
  218. {
  219. ResetType(CoTaskAllocator);
  220. }
  221. inline void
  222. CStorageVariant::SetEMPTY()
  223. {
  224. CAllocStorageVariant::SetEMPTY(CoTaskAllocator);
  225. }
  226. inline void
  227. CStorageVariant::SetNULL()
  228. {
  229. CAllocStorageVariant::SetNULL(CoTaskAllocator);
  230. }
  231. inline void
  232. CStorageVariant::SetI1(CHAR c)
  233. {
  234. CAllocStorageVariant::SetI1(c, CoTaskAllocator);
  235. }
  236. inline void
  237. CStorageVariant::SetUI1(BYTE b)
  238. {
  239. CAllocStorageVariant::SetUI1(b, CoTaskAllocator);
  240. }
  241. inline void
  242. CStorageVariant::SetI2(short i)
  243. {
  244. CAllocStorageVariant::SetI2(i, CoTaskAllocator);
  245. }
  246. inline void
  247. CStorageVariant::SetUI2(USHORT ui)
  248. {
  249. CAllocStorageVariant::SetUI2(ui, CoTaskAllocator);
  250. }
  251. inline void
  252. CStorageVariant::SetI4(long l)
  253. {
  254. CAllocStorageVariant::SetI4(l, CoTaskAllocator);
  255. }
  256. inline void
  257. CStorageVariant::SetUI4(ULONG ul)
  258. {
  259. CAllocStorageVariant::SetUI4(ul, CoTaskAllocator);
  260. }
  261. inline void
  262. CStorageVariant::SetR4(float f)
  263. {
  264. CAllocStorageVariant::SetR4(f, CoTaskAllocator);
  265. }
  266. inline void
  267. CStorageVariant::SetR8(double d)
  268. {
  269. CAllocStorageVariant::SetR8(d, CoTaskAllocator);
  270. }
  271. inline void
  272. CStorageVariant::SetI8(LARGE_INTEGER li)
  273. {
  274. CAllocStorageVariant::SetI8(li, CoTaskAllocator);
  275. }
  276. inline void
  277. CStorageVariant::SetUI8(ULARGE_INTEGER uli)
  278. {
  279. CAllocStorageVariant::SetUI8(uli, CoTaskAllocator);
  280. }
  281. inline void
  282. CStorageVariant::SetBOOL(VARIANT_BOOL b)
  283. {
  284. CAllocStorageVariant::SetBOOL(b, CoTaskAllocator);
  285. }
  286. inline void
  287. CStorageVariant::SetERROR(SCODE sc)
  288. {
  289. CAllocStorageVariant::SetERROR(sc, CoTaskAllocator);
  290. }
  291. inline void
  292. CStorageVariant::SetCY(CY cy)
  293. {
  294. CAllocStorageVariant::SetCY(cy, CoTaskAllocator);
  295. }
  296. inline void
  297. CStorageVariant::SetDATE(DATE d)
  298. {
  299. CAllocStorageVariant::SetDATE(d, CoTaskAllocator);
  300. }
  301. inline void
  302. CStorageVariant::SetFILETIME(FILETIME ft)
  303. {
  304. CAllocStorageVariant::SetFILETIME(ft, CoTaskAllocator);
  305. }
  306. inline void
  307. CStorageVariant::SetSTREAM(IStream *ps)
  308. {
  309. CAllocStorageVariant::SetSTREAM(ps, CoTaskAllocator);
  310. }
  311. inline void
  312. CStorageVariant::SetSTREAMED_OBJECT(IStream *ps)
  313. {
  314. CAllocStorageVariant::SetSTREAMED_OBJECT(ps, CoTaskAllocator);
  315. }
  316. inline void
  317. CStorageVariant::SetSTORAGE(IStorage *ps)
  318. {
  319. CAllocStorageVariant::SetSTORAGE(ps, CoTaskAllocator);
  320. }
  321. inline void
  322. CStorageVariant::SetSTORED_OBJECT(IStorage *ps)
  323. {
  324. CAllocStorageVariant::SetSTORED_OBJECT(ps, CoTaskAllocator);
  325. }
  326. inline void
  327. CStorageVariant::SetCLSID(CLSID const *pc)
  328. {
  329. CAllocStorageVariant::SetCLSID(pc, CoTaskAllocator);
  330. }
  331. inline CStorageVariant &
  332. CStorageVariant::operator =(CStorageVariant const &var)
  333. {
  334. ResetType(CoTaskAllocator);
  335. new (this) CStorageVariant((PROPVARIANT &) var);
  336. return(*this);
  337. }
  338. inline CStorageVariant &
  339. CStorageVariant::operator =(short i)
  340. {
  341. CAllocStorageVariant::SetI2(i, CoTaskAllocator);
  342. return(*this);
  343. }
  344. inline CStorageVariant &
  345. CStorageVariant::operator =(USHORT ui)
  346. {
  347. CAllocStorageVariant::SetUI2(ui, CoTaskAllocator);
  348. return(*this);
  349. }
  350. inline void
  351. CStorageVariant::SetBSTR(BSTR b)
  352. {
  353. CAllocStorageVariant::SetBSTR( b, CoTaskAllocator );
  354. }
  355. inline void
  356. CStorageVariant::SetLPSTR(char const *psz)
  357. {
  358. CAllocStorageVariant::SetLPSTR(psz, CoTaskAllocator);
  359. }
  360. inline void
  361. CStorageVariant::SetLPWSTR(WCHAR const *pwsz)
  362. {
  363. CAllocStorageVariant::SetLPWSTR(pwsz, CoTaskAllocator);
  364. }
  365. inline void
  366. CStorageVariant::SetBLOB(BLOB b)
  367. {
  368. CAllocStorageVariant::SetBLOB(b, CoTaskAllocator);
  369. }
  370. inline CStorageVariant &
  371. CStorageVariant::operator =(long l)
  372. {
  373. CAllocStorageVariant::SetI4(l, CoTaskAllocator);
  374. return(*this);
  375. }
  376. inline CStorageVariant &
  377. CStorageVariant::operator =(ULONG ul)
  378. {
  379. CAllocStorageVariant::SetUI4(ul, CoTaskAllocator);
  380. return(*this);
  381. }
  382. inline CStorageVariant &
  383. CStorageVariant::operator =(LARGE_INTEGER h)
  384. {
  385. CAllocStorageVariant::SetI8(h, CoTaskAllocator);
  386. return(*this);
  387. }
  388. inline CStorageVariant &
  389. CStorageVariant::operator =(ULARGE_INTEGER uh)
  390. {
  391. CAllocStorageVariant::SetUI8(uh, CoTaskAllocator);
  392. return(*this);
  393. }
  394. inline CStorageVariant &
  395. CStorageVariant::operator =(float flt)
  396. {
  397. CAllocStorageVariant::SetR4(flt, CoTaskAllocator);
  398. return(*this);
  399. }
  400. inline CStorageVariant &
  401. CStorageVariant::operator =(double dbl)
  402. {
  403. CAllocStorageVariant::SetR8(dbl, CoTaskAllocator);
  404. return(*this);
  405. }
  406. inline CStorageVariant &
  407. CStorageVariant::operator =(CY cy)
  408. {
  409. CAllocStorageVariant::SetCY(cy, CoTaskAllocator);
  410. return(*this);
  411. }
  412. inline CStorageVariant &
  413. CStorageVariant::operator =(FILETIME ft)
  414. {
  415. CAllocStorageVariant::SetFILETIME(ft, CoTaskAllocator);
  416. return(*this);
  417. }
  418. inline CStorageVariant &
  419. CStorageVariant::operator =(BLOB b)
  420. {
  421. CAllocStorageVariant::SetBLOB(b, CoTaskAllocator);
  422. return(*this);
  423. }
  424. inline CStorageVariant &
  425. CStorageVariant::operator =(char const *psz)
  426. {
  427. CAllocStorageVariant::SetLPSTR(psz, CoTaskAllocator);
  428. return(*this);
  429. }
  430. inline CStorageVariant &
  431. CStorageVariant::operator =(WCHAR const *pwsz)
  432. {
  433. CAllocStorageVariant::SetLPWSTR(pwsz, CoTaskAllocator);
  434. return(*this);
  435. }
  436. inline CStorageVariant &
  437. CStorageVariant::operator =(CLSID const *pcid)
  438. {
  439. CAllocStorageVariant::SetCLSID(pcid, CoTaskAllocator);
  440. return(*this);
  441. }
  442. inline void *
  443. CStorageVariant::operator new(size_t size)
  444. {
  445. void *p = CoTaskMemAlloc(size);
  446. return(p);
  447. }
  448. inline void *
  449. CStorageVariant::operator new(size_t size, void *p)
  450. {
  451. return(p);
  452. }
  453. inline void
  454. CStorageVariant::operator delete(void *p)
  455. {
  456. if (p != NULL)
  457. {
  458. CoTaskMemFree(p);
  459. }
  460. }
  461. #if _MSC_VER >= 1200
  462. inline void
  463. CStorageVariant::operator delete(void *p, void *pp)
  464. {
  465. return;
  466. }
  467. #endif
  468. inline
  469. CStorageVariant::CStorageVariant(CStorageVariant const &var)
  470. {
  471. new (this) CStorageVariant((PROPVARIANT &) var);
  472. }
  473. #endif // __STGVAR_HXX__