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.

1472 lines
45 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: utils.cxx
  7. //
  8. // Contents: Utility classes/functions for property implementation.
  9. //
  10. // Classes: CPropSetName -- wraps buffer and conversion of fmtids
  11. // CStackBuffer -- utility class that allows a small number
  12. // of items be on stack, but more be on heap.
  13. //
  14. // Functions: PropVariantClear
  15. // FreePropVariantArray
  16. // AllocAndCopy
  17. // PropVariantCopy
  18. //
  19. // History: 1-Mar-95 BillMo Created.
  20. // 22-Feb-96 MikeHill Removed an over-active assert.
  21. // 22-May-96 MikeHill Handle "unmappable character" in
  22. // NtStatusToScode.
  23. // 12-Jun-96 MikeHill - Added PropSysAllocString and PropSysFreeString.
  24. // - Added VT_I1 support (under ifdef)
  25. // - Fix PropVarCopy where the input VT_CF
  26. // has a zero size but a non-NULL pClipData.
  27. // 29-Jul-96 MikeHill - PropSet names: WCHAR => OLECHAR
  28. // - Bug in PropVarCopy of 0-length VT_BLOB
  29. // - Support VT_BSTR_BLOB types (used in IProp.dll)
  30. // 10-Mar-98 MikeHIll Support Variant types in PropVariantCopy/Clear
  31. // 06-May-98 MikeHill - Use CoTaskMem rather than new/delete.
  32. // - Removed unused PropSysAlloc/FreeString.
  33. // - Support VT_VECTOR|VT_I1.
  34. // - Removed UnicodeCallouts support.
  35. // - Use oleaut32.dll wrappers, don't call directly.
  36. // 5/18/98 MikeHill
  37. // - Moved IsOriginalPropVariantType from utils.hxx.
  38. // - Added IsVariantType.
  39. //
  40. // Notes:
  41. //
  42. // Codework:
  43. //
  44. //--------------------------------------------------------------------------
  45. #include <pch.cxx>
  46. #include <privoa.h> // Private OleAut32 wrappers
  47. #ifdef _MAC_NODOC
  48. ASSERTDATA // File-specific data for FnAssert
  49. #endif
  50. //+-------------------------------------------------------------------
  51. //
  52. // Member: CPropSetName::CPropSetName
  53. //
  54. // Synopsis: Initialize internal buffer with converted FMTID
  55. //
  56. // Arguments: [rfmtid] -- FMTID to convert
  57. //
  58. //--------------------------------------------------------------------
  59. CPropSetName::CPropSetName(REFFMTID rfmtid)
  60. {
  61. PrGuidToPropertySetName(&rfmtid, _oszName);
  62. }
  63. //+-------------------------------------------------------------------
  64. //
  65. // Member: CStackBuffer::Init
  66. //
  67. // Synopsis: Determine whether the class derived from this one
  68. // needs to have additional buffer allocated on the
  69. // heap and allocate it if neccessary. Otherwise, if
  70. // there is space, use the internal buffer in the
  71. // derived class.
  72. //
  73. // Arguments: [cElements] -- the number of elements required.
  74. //
  75. // Returns: S_OK if buffer available
  76. // STG_E_INSUFFICIENTMEMORY if stack buffer was not
  77. // big enough AND heap allocation failed.
  78. //
  79. // Notes: To be called directly by client after the derived
  80. // classes constructor initialized CStackBuffer.
  81. //
  82. //--------------------------------------------------------------------
  83. HRESULT CStackBuffer::Init(ULONG cElements)
  84. {
  85. if (cElements > _cElements)
  86. {
  87. _pbHeapBuf = reinterpret_cast<BYTE*>( CoTaskMemAlloc( cElements * _cbElement ));
  88. if (_pbHeapBuf == NULL)
  89. {
  90. return(STG_E_INSUFFICIENTMEMORY);
  91. }
  92. _cElements = cElements;
  93. }
  94. memset( _pbHeapBuf, 0, _cElements * _cbElement );
  95. return(S_OK);
  96. }
  97. //+-------------------------------------------------------------------------
  98. //
  99. // Function: PropVariantClear
  100. //
  101. // Synopsis: Deallocates the members of the PROPVARIANT that require
  102. // deallocation.
  103. //
  104. // Arguments: [pvarg] - variant to clear
  105. //
  106. // Returns: S_OK if successful,
  107. // STG_E_INVALIDPARAMETER if any part of the variant has
  108. // an unknown vt type. (In this case, ALL the elements
  109. // that can be freed, will be freed.)
  110. //
  111. // Modifies: [pvarg] - the variant is left with vt = VT_EMPTY
  112. //
  113. //--------------------------------------------------------------------------
  114. STDAPI PropVariantClear(PROPVARIANT *pvarg)
  115. {
  116. ULONG l;
  117. HRESULT hr = S_OK;
  118. // Is there really anything to clear?
  119. if (pvarg == NULL)
  120. return(hr);
  121. // Validate the input
  122. VDATEPTROUT( pvarg, PROPVARIANT );
  123. switch (pvarg->vt)
  124. {
  125. case VT_EMPTY:
  126. case VT_NULL:
  127. case VT_ILLEGAL:
  128. case VT_I1:
  129. case VT_UI1:
  130. case VT_I2:
  131. case VT_UI2:
  132. case VT_I4:
  133. case VT_UI4:
  134. case VT_I8:
  135. case VT_UI8:
  136. case VT_R4:
  137. case VT_R8:
  138. case VT_CY:
  139. case VT_DATE:
  140. break;
  141. case VT_BSTR:
  142. if (pvarg->bstrVal != NULL)
  143. PrivSysFreeString( pvarg->bstrVal );
  144. break;
  145. case VT_BSTR_BLOB:
  146. if (pvarg->bstrblobVal.pData != NULL)
  147. CoTaskMemFree( pvarg->bstrblobVal.pData );
  148. break;
  149. case VT_BOOL:
  150. case VT_ERROR:
  151. case VT_FILETIME:
  152. break;
  153. case VT_LPSTR:
  154. case VT_LPWSTR:
  155. case VT_CLSID:
  156. DfpAssert((void**)&pvarg->pszVal == (void**)&pvarg->pwszVal);
  157. DfpAssert((void**)&pvarg->pszVal == (void**)&pvarg->puuid);
  158. CoTaskMemFree( pvarg->pszVal ); // ptr at 0
  159. break;
  160. case VT_CF:
  161. if (pvarg->pclipdata != NULL)
  162. {
  163. CoTaskMemFree( pvarg->pclipdata->pClipData ); // ptr at 8
  164. CoTaskMemFree( pvarg->pclipdata );
  165. }
  166. break;
  167. case VT_BLOB:
  168. case VT_BLOB_OBJECT:
  169. CoTaskMemFree( pvarg->blob.pBlobData ); //ptr at 4
  170. break;
  171. case VT_STREAM:
  172. case VT_STREAMED_OBJECT:
  173. if (pvarg->pStream != NULL)
  174. pvarg->pStream->Release();
  175. break;
  176. case VT_VERSIONED_STREAM:
  177. if( NULL != pvarg->pVersionedStream )
  178. {
  179. if( NULL != pvarg->pVersionedStream->pStream )
  180. pvarg->pVersionedStream->pStream->Release();
  181. CoTaskMemFree( pvarg->pVersionedStream );
  182. }
  183. break;
  184. case VT_STORAGE:
  185. case VT_STORED_OBJECT:
  186. if (pvarg->pStorage != NULL)
  187. pvarg->pStorage->Release();
  188. break;
  189. case (VT_VECTOR | VT_I1):
  190. case (VT_VECTOR | VT_UI1):
  191. case (VT_VECTOR | VT_I2):
  192. case (VT_VECTOR | VT_UI2):
  193. case (VT_VECTOR | VT_I4):
  194. case (VT_VECTOR | VT_UI4):
  195. case (VT_VECTOR | VT_I8):
  196. case (VT_VECTOR | VT_UI8):
  197. case (VT_VECTOR | VT_R4):
  198. case (VT_VECTOR | VT_R8):
  199. case (VT_VECTOR | VT_CY):
  200. case (VT_VECTOR | VT_DATE):
  201. FreeArray:
  202. DfpAssert((void**)&pvarg->caub.pElems == (void**)&pvarg->cai.pElems);
  203. CoTaskMemFree( pvarg->caub.pElems );
  204. break;
  205. case (VT_VECTOR | VT_BSTR):
  206. if (pvarg->cabstr.pElems != NULL)
  207. {
  208. for (l=0; l< pvarg->cabstr.cElems; l++)
  209. {
  210. if (pvarg->cabstr.pElems[l] != NULL)
  211. {
  212. PrivSysFreeString( pvarg->cabstr.pElems[l] );
  213. }
  214. }
  215. }
  216. goto FreeArray;
  217. case (VT_VECTOR | VT_BSTR_BLOB):
  218. if (pvarg->cabstrblob.pElems != NULL)
  219. {
  220. for (l=0; l< pvarg->cabstrblob.cElems; l++)
  221. {
  222. if (pvarg->cabstrblob.pElems[l].pData != NULL)
  223. {
  224. CoTaskMemFree( pvarg->cabstrblob.pElems[l].pData );
  225. }
  226. }
  227. }
  228. goto FreeArray;
  229. case (VT_VECTOR | VT_BOOL):
  230. case (VT_VECTOR | VT_ERROR):
  231. goto FreeArray;
  232. case (VT_VECTOR | VT_LPSTR):
  233. case (VT_VECTOR | VT_LPWSTR):
  234. if (pvarg->calpstr.pElems != NULL)
  235. for (l=0; l< pvarg->calpstr.cElems; l++)
  236. {
  237. CoTaskMemFree( pvarg->calpstr.pElems[l] );
  238. }
  239. goto FreeArray;
  240. case (VT_VECTOR | VT_FILETIME):
  241. case (VT_VECTOR | VT_CLSID):
  242. goto FreeArray;
  243. case (VT_VECTOR | VT_CF):
  244. if (pvarg->caclipdata.pElems != NULL)
  245. for (l=0; l< pvarg->caclipdata.cElems; l++)
  246. {
  247. CoTaskMemFree( pvarg->caclipdata.pElems[l].pClipData );
  248. }
  249. goto FreeArray;
  250. case (VT_VECTOR | VT_VARIANT):
  251. if (pvarg->capropvar.pElems != NULL)
  252. hr = FreePropVariantArray(pvarg->capropvar.cElems, pvarg->capropvar.pElems);
  253. goto FreeArray;
  254. default:
  255. hr = PrivVariantClear( reinterpret_cast<VARIANT*>(pvarg) );
  256. if( DISP_E_BADVARTYPE == hr )
  257. hr = STG_E_INVALIDPARAMETER;
  258. break;
  259. }
  260. // We have all of the important information about the variant, so
  261. // let's clear it out.
  262. //
  263. PropVariantInit(pvarg);
  264. return (hr);
  265. }
  266. //+---------------------------------------------------------------------------
  267. //
  268. // Function: FreePropVariantArray, public
  269. //
  270. // Synopsis: Frees a value array returned from ReadMultiple
  271. //
  272. // Arguments: [cval] - Number of elements
  273. // [rgvar] - Array
  274. //
  275. // Returns: S_OK if all types recognised and all freeable items were freed.
  276. // STG_E_INVALID_PARAMETER if one or more types were not
  277. // recognised but all items are freed too.
  278. //
  279. // Notes: Even if a vt-type is not understood, all the ones that are
  280. // understood are freed. The error code will indicate
  281. // if *any* of the members were illegal types.
  282. //
  283. //----------------------------------------------------------------------------
  284. STDAPI FreePropVariantArray (
  285. ULONG cVariants,
  286. PROPVARIANT *rgvars)
  287. {
  288. HRESULT hr = S_OK;
  289. VDATESIZEPTROUT_LABEL(rgvars, cVariants * sizeof(PROPVARIANT),
  290. Exit, hr );
  291. if (rgvars != NULL)
  292. for ( ULONG I=0; I < cVariants; I++ )
  293. if (STG_E_INVALIDPARAMETER == PropVariantClear ( rgvars + I ))
  294. hr = STG_E_INVALIDPARAMETER;
  295. Exit:
  296. return hr;
  297. }
  298. //+-------------------------------------------------------------------
  299. //
  300. // Function: AllocAndCopy
  301. //
  302. // Synopsis: Allocates enough memory to copy the passed data into and
  303. // then copies the data into the new buffer.
  304. //
  305. // Arguments: [cb] -- number of bytes of data to allocate and copy
  306. // [pvData] -- the source of the data to copy
  307. // [phr] -- optional pointer to an HRESULT set to
  308. // STG_E_INSUFFICIENTMEMORY if memory could
  309. // not be allocated.
  310. //
  311. //
  312. // Returns: NULL if no memory could be allocated,
  313. // Otherwise, pointer to allocated and copied data.
  314. //
  315. //--------------------------------------------------------------------
  316. void * AllocAndCopy(ULONG cb, void * pvData, HRESULT *phr /* = NULL */)
  317. {
  318. void * pvNew = CoTaskMemAlloc( cb );
  319. if (pvNew != NULL)
  320. {
  321. memcpy(pvNew, pvData, cb);
  322. }
  323. else
  324. {
  325. if (phr != NULL)
  326. {
  327. *phr = STG_E_INSUFFICIENTMEMORY;
  328. }
  329. }
  330. return(pvNew);
  331. }
  332. //+-------------------------------------------------------------------
  333. //
  334. // Function: PropSysAllocString
  335. // PropSysFreeString
  336. //
  337. // Synopsis: Wrappers for OleAut32 routines.
  338. //
  339. // Notes: These PropSys* functions simply forward the call to
  340. // the PrivSys* routines in OLE32. Those functions
  341. // will load OleAut32 if necessary, and forward the call.
  342. //
  343. // The PrivSys* wrapper functions are provided in order to
  344. // delay the OleAut32 load. The PropSys* functions below
  345. // are provided as a mechanism to allow the NTDLL PropSet
  346. // functions to call the PrivSys* function pointers.
  347. //
  348. // The PropSys* functions below are part of the
  349. // UNICODECALLOUTS structure used by NTDLL.
  350. // These functions should go away when the property set
  351. // code is moved from NTDLL to OLE32.
  352. //
  353. //--------------------------------------------------------------------
  354. STDAPI_(BSTR)
  355. PropSysAllocString(OLECHAR FAR* pwsz)
  356. {
  357. return( PrivSysAllocString( pwsz ));
  358. }
  359. STDAPI_(VOID)
  360. PropSysFreeString(BSTR bstr)
  361. {
  362. PrivSysFreeString( bstr );
  363. return;
  364. }
  365. //+---------------------------------------------------------------------------
  366. //
  367. // Class: CRGTypeSizes (instantiated in g_TypeSizes)
  368. //
  369. // Synopsis: This class maintains a table with an entry for
  370. // each of the VT types. Each entry contains
  371. // flags and a byte-size for the type (each entry is
  372. // only a byte).
  373. //
  374. // This was implemented as a class so that we could use
  375. // it like an array (using an overloaded subscript operator),
  376. // indexed by the VT. An actual array would require
  377. // 4K entries
  378. //
  379. // Internally, this class keeps two tables, each containing
  380. // a range of VTs (the VTs range from 0 to 31, and 64 to 72).
  381. // Other values are treated as a special-case.
  382. //
  383. //----------------------------------------------------------------------------
  384. // -----------------------
  385. // Flags for table entries
  386. // -----------------------
  387. #define BIT_VECTNOALLOC 0x80 // the VT_VECTOR with this type does not
  388. // use heap allocation
  389. #define BIT_SIMPNOALLOC 0x40 // the non VT_VECTOR with this type does not
  390. // use heap allocation
  391. #define BIT_INVALID 0x20 // marks an invalid type
  392. #define BIT_SIZEMASK 0x1F // mask for size of underlying type
  393. // Dimensions of the internal tables
  394. #define MIN_TYPE_SIZES_A VT_EMPTY // First contiguous range of VTs
  395. #define MAX_TYPE_SIZES_A VT_LPWSTR
  396. #define MIN_TYPE_SIZES_B VT_FILETIME // Second continuous range of VTs
  397. #define MAX_TYPE_SIZES_B VT_VERSIONED_STREAM
  398. // ----------------
  399. // class CRTTypeSizes
  400. // ----------------
  401. class CRGTypeSizes
  402. {
  403. public:
  404. // Subscript Operator
  405. //
  406. // This is the only method on this class. It is used to
  407. // read an entry in the table.
  408. unsigned char operator[]( int nSubscript )
  409. {
  410. // Is this in the first table?
  411. if( MIN_TYPE_SIZES_A <= nSubscript && nSubscript <= MAX_TYPE_SIZES_A )
  412. {
  413. return( m_ucTypeSizesA[ nSubscript ] );
  414. }
  415. // Or, is it in the second table?
  416. else if( MIN_TYPE_SIZES_B<= nSubscript && nSubscript <= MAX_TYPE_SIZES_B )
  417. {
  418. return( m_ucTypeSizesB[ nSubscript - MIN_TYPE_SIZES_B ] );
  419. }
  420. // Or, is it a special-case value (not in either table)?
  421. else
  422. if( VT_BSTR_BLOB == nSubscript )
  423. {
  424. return( sizeof(BSTRBLOB) );
  425. }
  426. // Otherwise, the VT is invalid.
  427. return( BIT_INVALID );
  428. }
  429. private:
  430. // There are two ranges of supported VTs, so we have
  431. // one table for each.
  432. static const unsigned char m_ucTypeSizesA[];
  433. static const unsigned char m_ucTypeSizesB[];
  434. };
  435. // --------------------------
  436. // Instantiate the CRGTypeSizes
  437. // --------------------------
  438. CRGTypeSizes g_TypeSizes;
  439. // ----------------------------
  440. // Define the CTypeSizes tables
  441. // ----------------------------
  442. const unsigned char CRGTypeSizes::m_ucTypeSizesA[] =
  443. { BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 0, //VT_EMPTY= 0,
  444. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 0, //VT_NULL = 1,
  445. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 2, //VT_I2 = 2,
  446. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 4, //VT_I4 = 3,
  447. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 4, //VT_R4 = 4,
  448. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 8, //VT_R8 = 5,
  449. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | sizeof(CY), //VT_CY = 6,
  450. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | sizeof(DATE), //VT_DATE = 7,
  451. sizeof(BSTR), //VT_BSTR = 8,
  452. BIT_INVALID | 0, //VT_DISPATCH = 9,
  453. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | sizeof(SCODE), //VT_ERROR = 10,
  454. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | sizeof(VARIANT_BOOL), //VT_BOOL = 11,
  455. sizeof(PROPVARIANT), //VT_VARIANT = 12,
  456. BIT_INVALID | BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 0, //VT_UNKNOWN = 13,
  457. BIT_INVALID | BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 0, // 14
  458. BIT_INVALID | BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 0, // 15
  459. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 1, //VT_I1 = 16,
  460. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 1, //VT_UI1 = 17,
  461. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 2, //VT_UI2 = 18,
  462. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 4, //VT_UI4 = 19,
  463. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 8, //VT_I8 = 20,
  464. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 8, //VT_UI8 = 21,
  465. BIT_INVALID | BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 0, //VT_INT = 22,
  466. BIT_INVALID | BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 0, //VT_UINT = 23,
  467. BIT_INVALID | BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 0, //VT_VOID = 24,
  468. BIT_INVALID | BIT_SIMPNOALLOC | BIT_VECTNOALLOC | 0, //VT_HRESULT = 25,
  469. BIT_INVALID | 0, //VT_PTR = 26,
  470. BIT_INVALID | 0, //VT_SAFEARRAY = 27,
  471. BIT_INVALID | 0, //VT_CARRAY = 28,
  472. BIT_INVALID | 0, //VT_USERDEFINED = 29,
  473. sizeof(LPSTR), //VT_LPSTR = 30,
  474. sizeof(LPWSTR) //VT_LPWSTR = 31,
  475. };
  476. const unsigned char CRGTypeSizes::m_ucTypeSizesB[] =
  477. {
  478. // sizes for vectors of types marked ** are determined dynamically
  479. BIT_SIMPNOALLOC | BIT_VECTNOALLOC | sizeof(FILETIME), //VT_FILETIME = 64,
  480. 0, //**VT_BLOB = 65,
  481. 0, //**VT_STREAM = 66,
  482. 0, //**VT_STORAGE = 67,
  483. 0, //**VT_STREAMED_OBJECT = 68,
  484. 0, //**VT_STORED_OBJECT = 69,
  485. 0, //**VT_BLOB_OBJECT = 70,
  486. sizeof(CLIPDATA), //VT_CF = 71,
  487. BIT_VECTNOALLOC | sizeof(CLSID), //VT_CLSID = 72,
  488. 0 //**VT_VERSIONED_STREAM = 73
  489. };
  490. //+---------------------------------------------------------------------------
  491. //
  492. // Function: PropVariantCopy, public
  493. //
  494. // Synopsis: Copies a PROPVARIANT
  495. //
  496. // Arguments: [pDest] -- the destination PROPVARIANT
  497. // [pvarg] - the source PROPVARIANT
  498. //
  499. // Returns: Appropriate status code
  500. //
  501. //----------------------------------------------------------------------------
  502. STDAPI PropVariantCopy ( PROPVARIANT * pvOut, const PROPVARIANT * pvarg )
  503. {
  504. HRESULT hr = S_OK;
  505. register unsigned char TypeInfo;
  506. register int iBaseType;
  507. BOOL fInputValidated = FALSE;
  508. PROPVARIANT Temp, *pDest = &Temp;
  509. // ----------
  510. // Initialize
  511. // ----------
  512. // Validate the inputs
  513. VDATEREADPTRIN_LABEL( pvarg, PROPVARIANT, Exit, hr );
  514. VDATEPTROUT_LABEL( pvOut, PROPVARIANT, Exit, hr );
  515. fInputValidated = TRUE;
  516. // Duplicate the source propvar to the temp destination. For types with
  517. // no external buffer (e.g. an I4), this will be sufficient. For
  518. // types with an external buffer, we'll now have both propvars
  519. // pointing to the same buffer. So we'll have to re-allocate
  520. // for the destination propvar and copy the data into it.
  521. //
  522. *pDest = *pvarg;
  523. // Handle the simple types quickly.
  524. iBaseType = pvarg->vt & ~VT_VECTOR;
  525. TypeInfo = g_TypeSizes[ iBaseType ]; // Not to be confused with an ITypeInfo
  526. if( (TypeInfo & BIT_INVALID) != 0 )
  527. {
  528. // Try copying it as a regular Variant
  529. PropVariantInit( pDest );
  530. hr = PrivVariantCopy( reinterpret_cast<VARIANT*>(pDest),
  531. reinterpret_cast<VARIANT*>(const_cast<PROPVARIANT*>( pvarg )) );
  532. goto Exit;
  533. }
  534. // -----------------------
  535. // Handle non-vector types
  536. // -----------------------
  537. if ((pvarg->vt & VT_VECTOR) == 0)
  538. {
  539. // Is this a type which requires an allocation (otherwise there's
  540. // nothing to do)?
  541. if ((TypeInfo & BIT_SIMPNOALLOC) == 0)
  542. {
  543. // Yes - an allocation is required.
  544. // Keep a copy of the allocated buffer, so that at the end of
  545. // this switch, we can distiguish the out-of-memory condition from
  546. // the no-alloc-required condition.
  547. void * pvAllocated = (void*)-1;
  548. switch (pvarg->vt)
  549. {
  550. case VT_BSTR:
  551. if( NULL != pvarg->bstrVal )
  552. pvAllocated = pDest->bstrVal = PrivSysAllocString( pvarg->bstrVal );
  553. break;
  554. case VT_BSTR_BLOB:
  555. if( NULL != pvarg->bstrblobVal.pData )
  556. pvAllocated = pDest->bstrblobVal.pData = (BYTE*)
  557. AllocAndCopy(pDest->bstrblobVal.cbSize, pvarg->bstrblobVal.pData);
  558. break;
  559. case VT_LPSTR:
  560. if (pvarg->pszVal != NULL)
  561. pvAllocated = pDest->pszVal = (CHAR *)
  562. AllocAndCopy(strlen(pvarg->pszVal)+1, pvarg->pszVal);
  563. break;
  564. case VT_LPWSTR:
  565. if (pvarg->pwszVal != NULL)
  566. {
  567. ULONG cbString = (Prop_wcslen(pvarg->pwszVal)+1) * sizeof(WCHAR);
  568. pvAllocated = pDest->pwszVal = (WCHAR *)
  569. AllocAndCopy(cbString, pvarg->pwszVal);
  570. }
  571. break;
  572. case VT_CLSID:
  573. if (pvarg->puuid != NULL)
  574. pvAllocated = pDest->puuid = (GUID *)
  575. AllocAndCopy(sizeof(*(pvarg->puuid)), pvarg->puuid);
  576. break;
  577. case VT_CF:
  578. // first check if CLIPDATA is present
  579. if (pvarg->pclipdata != NULL)
  580. {
  581. // yes ... copy the clip data structure
  582. pvAllocated = pDest->pclipdata = (CLIPDATA*)AllocAndCopy(
  583. sizeof(*(pvarg->pclipdata)), pvarg->pclipdata);
  584. // did we allocate the CLIPDATA ?
  585. if (pvAllocated != NULL)
  586. {
  587. // yes ... initialize the destination.
  588. pDest->pclipdata->pClipData = NULL;
  589. // Is the input valid?
  590. if (NULL == pvarg->pclipdata->pClipData
  591. &&
  592. 0 != CBPCLIPDATA(*pvarg->pclipdata))
  593. {
  594. // no ... the input is not valid
  595. hr = STG_E_INVALIDPARAMETER;
  596. CoTaskMemFree( pDest->pclipdata );
  597. pvAllocated = pDest->pclipdata = NULL;
  598. break;
  599. }
  600. // Copy the actual clip data. Note that if the source
  601. // is non-NULL, we copy it, even if the length is 0.
  602. if( NULL != pvarg->pclipdata->pClipData )
  603. {
  604. pvAllocated = pDest->pclipdata->pClipData =
  605. (BYTE*)AllocAndCopy(CBPCLIPDATA(*pvarg->pclipdata),
  606. pvarg->pclipdata->pClipData);
  607. }
  608. } // if (pvAllocated != NULL)
  609. } // if (pvarg->pclipdata != NULL)
  610. break;
  611. case VT_BLOB:
  612. case VT_BLOB_OBJECT:
  613. // Is the input valid?
  614. if (NULL == pvarg->blob.pBlobData
  615. &&
  616. 0 != pvarg->blob.cbSize)
  617. {
  618. // no ... the input is not valid
  619. hr = STG_E_INVALIDPARAMETER;
  620. goto Exit;
  621. }
  622. // Copy the actual blob. Note that if the source
  623. // is non-NULL, we copy it, even if the length is 0.
  624. if( NULL != pvarg->blob.pBlobData )
  625. {
  626. pvAllocated = pDest->blob.pBlobData =
  627. (BYTE*)AllocAndCopy(pvarg->blob.cbSize,
  628. pvarg->blob.pBlobData);
  629. }
  630. break;
  631. case VT_STREAM:
  632. case VT_STREAMED_OBJECT:
  633. if (pDest->pStream != NULL)
  634. pDest->pStream->AddRef();
  635. break;
  636. case VT_VERSIONED_STREAM:
  637. if( NULL != pvarg->pVersionedStream )
  638. {
  639. LPVERSIONEDSTREAM pVersionedStream
  640. = reinterpret_cast<LPVERSIONEDSTREAM>(CoTaskMemAlloc( sizeof(VERSIONEDSTREAM) ));
  641. if( NULL == pVersionedStream )
  642. {
  643. hr = E_OUTOFMEMORY;
  644. goto Exit;
  645. }
  646. *pVersionedStream = *pvarg->pVersionedStream;
  647. if( NULL != pVersionedStream->pStream )
  648. pVersionedStream->pStream->AddRef();
  649. pDest->pVersionedStream = pVersionedStream;
  650. }
  651. break;
  652. case VT_STORAGE:
  653. case VT_STORED_OBJECT:
  654. if (pDest->pStorage != NULL)
  655. pDest->pStorage->AddRef();
  656. break;
  657. case VT_VARIANT:
  658. // drop through - this merely documents that VT_VARIANT has been thought of.
  659. // VT_VARIANT is only supported as part of a vector.
  660. default:
  661. hr = STG_E_INVALIDPARAMETER;
  662. goto Exit;
  663. } // switch (pvarg->vt)
  664. // If there was an error, we're done.
  665. if( FAILED(hr) )
  666. goto Exit;
  667. // pvAllocated was initialized to -1, so if it's NULL now,
  668. // there was an alloc failure.
  669. if (pvAllocated == NULL)
  670. {
  671. hr = STG_E_INSUFFICIENTMEMORY;
  672. goto Exit;
  673. }
  674. } // if ((TypeInfo & BIT_SIMPNOALLOC) == 0)
  675. } // if ((pvarg->vt & VT_VECTOR) == 0)
  676. // -------------------
  677. // Handle vector types
  678. // -------------------
  679. else
  680. {
  681. // What's the byte-size of this type.
  682. ULONG cbType = TypeInfo & BIT_SIZEMASK;
  683. if (cbType == 0)
  684. {
  685. hr = STG_E_INVALIDPARAMETER;
  686. goto Exit;
  687. }
  688. // handle the vector types
  689. // this depends on the pointer and count being in the same place in
  690. // each of CAUI1 CAI2 etc
  691. // allocate the array for pElems
  692. if (pvarg->caub.pElems == NULL || pvarg->caub.cElems == 0)
  693. {
  694. DfpAssert( hr == S_OK );
  695. goto Exit; // not really an error
  696. }
  697. // Allocate the pElems array (the size of which is
  698. // type-dependent), and copy the source into it.
  699. void *pvAllocated = pDest->caub.pElems = (BYTE *)
  700. AllocAndCopy(cbType * pvarg->caub.cElems, pvarg->caub.pElems);
  701. if (pvAllocated == NULL)
  702. {
  703. hr = STG_E_INSUFFICIENTMEMORY;
  704. goto Exit;
  705. }
  706. // If this type doesn't require secondary allocation (e.g.
  707. // a VT_VECTOR | VT_I4), then we're done.
  708. if ((TypeInfo & BIT_VECTNOALLOC) != 0)
  709. {
  710. // the vector needs no further allocation
  711. DfpAssert( hr == S_OK );
  712. goto Exit;
  713. }
  714. ULONG l;
  715. // vector types that require allocation ...
  716. // we first zero out the pointers so that we can use PropVariantClear
  717. // to clean up in the error case
  718. switch (pvarg->vt)
  719. {
  720. case (VT_VECTOR | VT_BSTR):
  721. // initialize for error case
  722. for (l=0; l< pvarg->cabstr.cElems; l++)
  723. {
  724. pDest->cabstr.pElems[l] = NULL;
  725. }
  726. break;
  727. case (VT_VECTOR | VT_BSTR_BLOB):
  728. // initialize for error case
  729. for (l=0; l< pvarg->cabstrblob.cElems; l++)
  730. {
  731. memset( &pDest->cabstrblob.pElems[l], 0, sizeof(BSTRBLOB) );
  732. }
  733. break;
  734. case (VT_VECTOR | VT_LPSTR):
  735. case (VT_VECTOR | VT_LPWSTR):
  736. // initialize for error case
  737. for (l=0; l< pvarg->calpstr.cElems; l++)
  738. {
  739. pDest->calpstr.pElems[l] = NULL;
  740. }
  741. break;
  742. case (VT_VECTOR | VT_CF):
  743. // initialize for error case
  744. for (l=0; l< pvarg->caclipdata.cElems; l++)
  745. {
  746. pDest->caclipdata.pElems[l].pClipData = NULL;
  747. }
  748. break;
  749. case (VT_VECTOR | VT_VARIANT):
  750. // initialize for error case
  751. for (l=0; l< pvarg->capropvar.cElems; l++)
  752. {
  753. pDest->capropvar.pElems[l].vt = VT_ILLEGAL;
  754. }
  755. break;
  756. default:
  757. DfpAssert(!"Internal error: Unexpected type in PropVariantCopy");
  758. CoTaskMemFree( pvAllocated );
  759. hr = STG_E_INVALIDPARAMETER;
  760. goto Exit;
  761. }
  762. // This is a vector type which requires a secondary alloc.
  763. switch (pvarg->vt)
  764. {
  765. case (VT_VECTOR | VT_BSTR):
  766. for (l=0; l< pvarg->cabstr.cElems; l++)
  767. {
  768. if (pvarg->cabstr.pElems[l] != NULL)
  769. {
  770. pDest->cabstr.pElems[l] = PrivSysAllocString( pvarg->cabstr.pElems[l]);
  771. if (pDest->cabstr.pElems[l] == NULL)
  772. {
  773. hr = STG_E_INSUFFICIENTMEMORY;
  774. break;
  775. }
  776. }
  777. }
  778. break;
  779. case (VT_VECTOR | VT_BSTR_BLOB):
  780. for (l=0; l< pvarg->cabstrblob.cElems; l++)
  781. {
  782. if (pvarg->cabstrblob.pElems[l].pData != NULL)
  783. {
  784. pDest->cabstrblob.pElems[l].cbSize
  785. = pvarg->cabstrblob.pElems[l].cbSize;
  786. pDest->cabstrblob.pElems[l].pData = (BYTE*)AllocAndCopy(
  787. pvarg->cabstrblob.pElems[l].cbSize,
  788. pvarg->cabstrblob.pElems[l].pData,
  789. &hr );
  790. if (hr != S_OK)
  791. break;
  792. }
  793. }
  794. break;
  795. case (VT_VECTOR | VT_LPWSTR):
  796. for (l=0; l< pvarg->calpwstr.cElems; l++)
  797. {
  798. if (pvarg->calpwstr.pElems[l] != NULL)
  799. {
  800. pDest->calpwstr.pElems[l] = (LPWSTR)AllocAndCopy(
  801. sizeof(WCHAR)*(Prop_wcslen(pvarg->calpwstr.pElems[l])+1),
  802. pvarg->calpwstr.pElems[l],
  803. &hr);
  804. if (hr != S_OK)
  805. break;
  806. }
  807. }
  808. break;
  809. case (VT_VECTOR | VT_LPSTR):
  810. for (l=0; l< pvarg->calpstr.cElems; l++)
  811. {
  812. if (pvarg->calpstr.pElems[l] != NULL)
  813. {
  814. pDest->calpstr.pElems[l] = (LPSTR)AllocAndCopy(
  815. strlen(pvarg->calpstr.pElems[l])+1,
  816. pvarg->calpstr.pElems[l],
  817. &hr);
  818. if (hr != S_OK)
  819. break;
  820. }
  821. }
  822. break;
  823. case (VT_VECTOR | VT_CF):
  824. for (l=0; l< pvarg->caclipdata.cElems; l++)
  825. {
  826. // Is the input valid?
  827. if (NULL == pvarg->caclipdata.pElems[l].pClipData
  828. &&
  829. 0 != CBPCLIPDATA(pvarg->caclipdata.pElems[l] ))
  830. {
  831. hr = STG_E_INVALIDPARAMETER;
  832. break;
  833. }
  834. // Is there data to copy?
  835. if (NULL != pvarg->caclipdata.pElems[l].pClipData)
  836. {
  837. pDest->caclipdata.pElems[l].pClipData = (BYTE*)AllocAndCopy(
  838. CBPCLIPDATA(pvarg->caclipdata.pElems[l]),
  839. pvarg->caclipdata.pElems[l].pClipData,
  840. &hr);
  841. if (hr != S_OK)
  842. break;
  843. }
  844. }
  845. break;
  846. case (VT_VECTOR | VT_VARIANT):
  847. for (l=0; l< pvarg->capropvar.cElems; l++)
  848. {
  849. hr = PropVariantCopy(pDest->capropvar.pElems + l,
  850. pvarg->capropvar.pElems + l);
  851. if (hr != S_OK)
  852. {
  853. break;
  854. }
  855. }
  856. break;
  857. default:
  858. DfpAssert(!"Internal error: Unexpected type in PropVariantCopy");
  859. CoTaskMemFree( pvAllocated );
  860. hr = STG_E_INVALIDPARAMETER;
  861. goto Exit;
  862. } // switch (pvarg->vt)
  863. } // if ((pvarg->vt & VT_VECTOR) == 0) ... else
  864. // ----
  865. // Exit
  866. // ----
  867. Exit:
  868. // If there was an error, and it wasn't a caller error
  869. // (in which case *pDest may not be writable), clear the
  870. // destination propvar.
  871. if (fInputValidated && hr != S_OK && E_INVALIDARG != hr)
  872. {
  873. // if *pDest == *pvarg, then we didn't alloc anything, and
  874. // nothing need be cleared, so we'll just init *pDest.
  875. // We can't free it because it may point to pvarg's buffers.
  876. if( !memcmp( pDest, pvarg, sizeof(PROPVARIANT) ))
  877. PropVariantInit( pDest );
  878. // Otherwise, we must have done some allocations for *pDest,
  879. // and must free them.
  880. else
  881. PropVariantClear( pDest );
  882. }
  883. if (SUCCEEDED(hr))
  884. *pvOut = Temp;
  885. return(hr);
  886. }
  887. //+---------------------------------------------------------------------------
  888. //
  889. // Function: NtStatusToScode, public
  890. //
  891. // Synopsis: Attempts to map an NTSTATUS code to an SCODE
  892. //
  893. // Arguments: [nts] - NTSTATUS
  894. //
  895. // Returns: Appropriate status code
  896. //
  897. // History: 29-Jun-93 DrewB Created
  898. //
  899. // Notes: Assumes [nts] is an error code
  900. // This function is by no means exhaustively complete
  901. //
  902. //----------------------------------------------------------------------------
  903. SCODE NtStatusToScode(NTSTATUS nts)
  904. {
  905. SCODE sc;
  906. propDbg((DEB_ITRACE, "In NtStatusToScode(%lX)\n", nts));
  907. switch(nts)
  908. {
  909. case STATUS_INVALID_PARAMETER:
  910. case STATUS_INVALID_PARAMETER_MIX:
  911. case STATUS_INVALID_PARAMETER_1:
  912. case STATUS_INVALID_PARAMETER_2:
  913. case STATUS_INVALID_PARAMETER_3:
  914. case STATUS_INVALID_PARAMETER_4:
  915. case STATUS_INVALID_PARAMETER_5:
  916. case STATUS_INVALID_PARAMETER_6:
  917. case STATUS_INVALID_PARAMETER_7:
  918. case STATUS_INVALID_PARAMETER_8:
  919. case STATUS_INVALID_PARAMETER_9:
  920. case STATUS_INVALID_PARAMETER_10:
  921. case STATUS_INVALID_PARAMETER_11:
  922. case STATUS_INVALID_PARAMETER_12:
  923. sc = STG_E_INVALIDPARAMETER;
  924. break;
  925. case STATUS_DUPLICATE_NAME:
  926. case STATUS_DUPLICATE_OBJECTID:
  927. case STATUS_OBJECTID_EXISTS:
  928. case STATUS_OBJECT_NAME_COLLISION:
  929. sc = STG_E_FILEALREADYEXISTS;
  930. break;
  931. case STATUS_NO_SUCH_DEVICE:
  932. case STATUS_NO_SUCH_FILE:
  933. case STATUS_OBJECT_NAME_NOT_FOUND:
  934. case STATUS_NOT_A_DIRECTORY:
  935. case STATUS_FILE_IS_A_DIRECTORY:
  936. case STATUS_PROPSET_NOT_FOUND:
  937. case STATUS_NOT_FOUND:
  938. case STATUS_OBJECT_TYPE_MISMATCH:
  939. sc = STG_E_FILENOTFOUND;
  940. break;
  941. case STATUS_OBJECT_NAME_INVALID:
  942. case STATUS_OBJECT_PATH_SYNTAX_BAD:
  943. case STATUS_OBJECT_PATH_INVALID:
  944. case STATUS_NAME_TOO_LONG:
  945. sc = STG_E_INVALIDNAME;
  946. break;
  947. case STATUS_ACCESS_DENIED:
  948. sc = STG_E_ACCESSDENIED;
  949. break;
  950. case STATUS_NO_MEMORY:
  951. case STATUS_INSUFFICIENT_RESOURCES:
  952. sc = STG_E_INSUFFICIENTMEMORY;
  953. break;
  954. case STATUS_INVALID_HANDLE:
  955. case STATUS_FILE_INVALID:
  956. case STATUS_FILE_FORCED_CLOSED:
  957. sc = STG_E_INVALIDHANDLE;
  958. break;
  959. case STATUS_INVALID_DEVICE_REQUEST:
  960. case STATUS_INVALID_SYSTEM_SERVICE:
  961. case STATUS_NOT_IMPLEMENTED:
  962. sc = STG_E_INVALIDFUNCTION;
  963. break;
  964. case STATUS_NO_MEDIA_IN_DEVICE:
  965. case STATUS_UNRECOGNIZED_MEDIA:
  966. case STATUS_DISK_CORRUPT_ERROR:
  967. case STATUS_DATA_ERROR:
  968. sc = STG_E_WRITEFAULT;
  969. break;
  970. case STATUS_OBJECT_PATH_NOT_FOUND:
  971. sc = STG_E_PATHNOTFOUND;
  972. break;
  973. case STATUS_SHARING_VIOLATION:
  974. sc = STG_E_SHAREVIOLATION;
  975. break;
  976. case STATUS_FILE_LOCK_CONFLICT:
  977. case STATUS_LOCK_NOT_GRANTED:
  978. sc = STG_E_LOCKVIOLATION;
  979. break;
  980. case STATUS_DISK_FULL:
  981. sc = STG_E_MEDIUMFULL;
  982. break;
  983. case STATUS_ACCESS_VIOLATION:
  984. case STATUS_INVALID_USER_BUFFER:
  985. sc = STG_E_INVALIDPOINTER;
  986. break;
  987. case STATUS_TOO_MANY_OPENED_FILES:
  988. sc = STG_E_TOOMANYOPENFILES;
  989. break;
  990. case STATUS_DIRECTORY_NOT_EMPTY:
  991. sc = HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY);
  992. break;
  993. case STATUS_DELETE_PENDING:
  994. sc = STG_E_REVERTED;
  995. break;
  996. case STATUS_INTERNAL_DB_CORRUPTION:
  997. sc = STG_E_INVALIDHEADER;
  998. break;
  999. case STATUS_UNSUCCESSFUL:
  1000. sc = E_FAIL;
  1001. break;
  1002. case STATUS_UNMAPPABLE_CHARACTER:
  1003. sc = HRESULT_FROM_WIN32( ERROR_NO_UNICODE_TRANSLATION );
  1004. break;
  1005. default:
  1006. propDbg((DEB_TRACE, "NtStatusToScode: Unknown status %lX\n", nts));
  1007. sc = HRESULT_FROM_WIN32(RtlNtStatusToDosError(nts));
  1008. break;
  1009. }
  1010. propDbg((DEB_ITRACE, "Out NtStatusToScode => %lX\n", sc));
  1011. return sc;
  1012. }
  1013. #if DBG!=0 && !defined(WINNT)
  1014. ULONG
  1015. DbgPrint(
  1016. PCHAR Format,
  1017. ...
  1018. )
  1019. {
  1020. va_list arglist;
  1021. CHAR Buffer[512];
  1022. int cb;
  1023. //
  1024. // Format the output into a buffer and then print it.
  1025. //
  1026. va_start(arglist, Format);
  1027. cb = PropVsprintfA(Buffer, Format, arglist);
  1028. if (cb == -1) { // detect buffer overflow
  1029. cb = sizeof(Buffer);
  1030. Buffer[sizeof(Buffer) - 2] = '\n';
  1031. Buffer[sizeof(Buffer) - 1] = '\0';
  1032. }
  1033. OutputDebugString(Buffer);
  1034. return 0;
  1035. }
  1036. #endif
  1037. //+-------------------------------------------------------------------
  1038. //
  1039. // Member: ValidateInRGPROPVARIANT
  1040. //
  1041. // Synopsis: S_OK if PROPVARIANT[] is valid for Read.
  1042. // E_INVALIDARG otherwise.
  1043. //
  1044. //--------------------------------------------------------------------
  1045. HRESULT
  1046. ValidateInRGPROPVARIANT( ULONG cpspec, const PROPVARIANT rgpropvar[] )
  1047. {
  1048. // We verify that we can read the whole PropVariant[], but
  1049. // we don't validate the content of those elements.
  1050. HRESULT hr;
  1051. VDATESIZEREADPTRIN_LABEL(rgpropvar, cpspec * sizeof(PROPVARIANT), Exit, hr);
  1052. hr = S_OK;
  1053. Exit:
  1054. return( hr );
  1055. }
  1056. //+-------------------------------------------------------------------
  1057. //
  1058. // Member: ValidateOutRGPROPVARIANT
  1059. //
  1060. // Synopsis: S_OK if PROPVARIANT[] is valid for Write.
  1061. // E_INVALIDARG otherwise.
  1062. //
  1063. //--------------------------------------------------------------------
  1064. HRESULT
  1065. ValidateOutRGPROPVARIANT( ULONG cpspec, PROPVARIANT rgpropvar[] )
  1066. {
  1067. // We verify that we can write the whole PropVariant[], but
  1068. // we don't validate the content of those elements.
  1069. HRESULT hr;
  1070. VDATESIZEPTROUT_LABEL(rgpropvar, cpspec * sizeof(PROPVARIANT), Exit, hr);
  1071. hr = S_OK;
  1072. Exit:
  1073. return( hr );
  1074. }
  1075. //+-------------------------------------------------------------------
  1076. //
  1077. // Member: ValidateOutRGLPOLESTR.
  1078. //
  1079. // Synopsis: S_OK if LPOLESTR[] is valid for Write.
  1080. // E_INVALIDARG otherwise.
  1081. //
  1082. //--------------------------------------------------------------------
  1083. HRESULT
  1084. ValidateOutRGLPOLESTR( ULONG cpropid, LPOLESTR rglpwstrName[] )
  1085. {
  1086. HRESULT hr;
  1087. VDATESIZEPTROUT_LABEL( rglpwstrName, cpropid * sizeof(LPOLESTR), Exit, hr );
  1088. hr = S_OK;
  1089. Exit:
  1090. return( hr );
  1091. }
  1092. //+-------------------------------------------------------------------
  1093. //
  1094. // Member: ValidateInRGLPOLESTR
  1095. //
  1096. // Synopsis: S_OK if LPOLESTR[] is valid for Read.
  1097. // E_INVALIDARG otherwise.
  1098. //
  1099. //--------------------------------------------------------------------
  1100. HRESULT
  1101. ValidateInRGLPOLESTR( ULONG cpropid, const OLECHAR* const rglpwstrName[] )
  1102. {
  1103. // Validate that we can read the entire vector.
  1104. HRESULT hr;
  1105. VDATESIZEREADPTRIN_LABEL( rglpwstrName, cpropid * sizeof(LPOLESTR), Exit, hr );
  1106. // Validate that we can at least read the first character of
  1107. // each of the strings.
  1108. for( ; cpropid > 0; cpropid-- )
  1109. {
  1110. VDATEREADPTRIN_LABEL( rglpwstrName[cpropid-1], WCHAR, Exit, hr );
  1111. }
  1112. hr = S_OK;
  1113. Exit:
  1114. return( hr );
  1115. }
  1116. //+----------------------------------------------------------------------------
  1117. //
  1118. // Function: IsOriginalPropVariantType
  1119. //
  1120. // Determines if a VARTYPE was one of the ones in the original PropVariant
  1121. // definition (as defined in the OLE2 spec and shipped with NT4/DCOM95).
  1122. //
  1123. //+----------------------------------------------------------------------------
  1124. BOOL
  1125. IsOriginalPropVariantType( VARTYPE vt )
  1126. {
  1127. if( vt & ~VT_TYPEMASK & ~VT_VECTOR )
  1128. return( FALSE );
  1129. switch( vt )
  1130. {
  1131. case VT_EMPTY:
  1132. case VT_NULL:
  1133. case VT_UI1:
  1134. case VT_I2:
  1135. case VT_UI2:
  1136. case VT_BOOL:
  1137. case VT_I4:
  1138. case VT_UI4:
  1139. case VT_R4:
  1140. case VT_ERROR:
  1141. case VT_I8:
  1142. case VT_UI8:
  1143. case VT_R8:
  1144. case VT_CY:
  1145. case VT_DATE:
  1146. case VT_FILETIME:
  1147. case VT_CLSID:
  1148. case VT_BLOB:
  1149. case VT_BLOB_OBJECT:
  1150. case VT_CF:
  1151. case VT_STREAM:
  1152. case VT_STREAMED_OBJECT:
  1153. case VT_STORAGE:
  1154. case VT_STORED_OBJECT:
  1155. case VT_BSTR:
  1156. case VT_LPSTR:
  1157. case VT_LPWSTR:
  1158. case VT_UI1|VT_VECTOR:
  1159. case VT_I2|VT_VECTOR:
  1160. case VT_UI2|VT_VECTOR:
  1161. case VT_BOOL|VT_VECTOR:
  1162. case VT_I4|VT_VECTOR:
  1163. case VT_UI4|VT_VECTOR:
  1164. case VT_R4|VT_VECTOR:
  1165. case VT_ERROR|VT_VECTOR:
  1166. case VT_I8|VT_VECTOR:
  1167. case VT_UI8|VT_VECTOR:
  1168. case VT_R8|VT_VECTOR:
  1169. case VT_CY|VT_VECTOR:
  1170. case VT_DATE|VT_VECTOR:
  1171. case VT_FILETIME|VT_VECTOR:
  1172. case VT_CLSID|VT_VECTOR:
  1173. case VT_CF|VT_VECTOR:
  1174. case VT_BSTR|VT_VECTOR:
  1175. case VT_BSTR_BLOB|VT_VECTOR:
  1176. case VT_LPSTR|VT_VECTOR:
  1177. case VT_LPWSTR|VT_VECTOR:
  1178. case VT_VARIANT|VT_VECTOR:
  1179. return( TRUE );
  1180. }
  1181. return( FALSE );
  1182. }
  1183. //+----------------------------------------------------------------------------
  1184. //
  1185. // Function: IsVariantType
  1186. //
  1187. // Determines if a VARTYPE is one in the set of Variant types which are
  1188. // supported in the property set implementation.
  1189. //
  1190. //+----------------------------------------------------------------------------
  1191. BOOL
  1192. IsVariantType( VARTYPE vt )
  1193. {
  1194. // Vectors are unsupported
  1195. if( (VT_VECTOR | VT_RESERVED) & vt )
  1196. return( FALSE );
  1197. switch( VT_TYPEMASK & vt )
  1198. {
  1199. case VT_EMPTY:
  1200. case VT_NULL:
  1201. case VT_I1:
  1202. case VT_UI1:
  1203. case VT_I2:
  1204. case VT_UI2:
  1205. case VT_I4:
  1206. case VT_UI4:
  1207. case VT_INT:
  1208. case VT_UINT:
  1209. case VT_R4:
  1210. case VT_R8:
  1211. case VT_CY:
  1212. case VT_DATE:
  1213. case VT_BSTR:
  1214. case VT_UNKNOWN:
  1215. case VT_DISPATCH:
  1216. case VT_BOOL:
  1217. case VT_ERROR:
  1218. case VT_DECIMAL:
  1219. case VT_VARIANT:
  1220. return( TRUE );
  1221. default:
  1222. return( FALSE );
  1223. }
  1224. }