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.

171 lines
3.7 KiB

  1. #pragma once
  2. class CFps : public FULLPROPSPEC
  3. {
  4. public:
  5. CFps()
  6. {
  7. ZeroMemory( this, sizeof CFps );
  8. psProperty.ulKind = PRSPEC_PROPID;
  9. }
  10. void Copy( FULLPROPSPEC const & fps )
  11. {
  12. Free();
  13. guidPropSet = fps.guidPropSet;
  14. psProperty.ulKind = fps.psProperty.ulKind;
  15. if ( PRSPEC_LPWSTR == psProperty.ulKind )
  16. {
  17. if ( 0 != fps.psProperty.lpwstr )
  18. {
  19. unsigned cwc = 1 + wcslen( fps.psProperty.lpwstr );
  20. psProperty.lpwstr = (LPWSTR) CoTaskMemAlloc( cwc * sizeof WCHAR );
  21. wcscpy( psProperty.lpwstr, fps.psProperty.lpwstr );
  22. }
  23. }
  24. else
  25. {
  26. psProperty.propid = fps.psProperty.propid;
  27. }
  28. }
  29. ~CFps()
  30. {
  31. Free();
  32. }
  33. void Free()
  34. {
  35. if ( ( PRSPEC_LPWSTR == psProperty.ulKind ) &&
  36. ( 0 != psProperty.lpwstr ) )
  37. {
  38. CoTaskMemFree( psProperty.lpwstr );
  39. psProperty.lpwstr = 0;
  40. psProperty.ulKind = PRSPEC_PROPID;
  41. }
  42. }
  43. BOOL IsMatch( FULLPROPSPEC & fps )
  44. {
  45. if ( guidPropSet != fps.guidPropSet )
  46. return FALSE;
  47. if ( psProperty.ulKind != fps.psProperty.ulKind )
  48. return FALSE;
  49. if ( PRSPEC_PROPID == psProperty.ulKind )
  50. return ( psProperty.propid == fps.psProperty.propid );
  51. if ( PRSPEC_LPWSTR != psProperty.ulKind )
  52. return FALSE;
  53. return ( !wcscmp( psProperty.lpwstr,
  54. fps.psProperty.lpwstr ) );
  55. }
  56. };
  57. class CPropVar : public PROPVARIANT
  58. {
  59. public:
  60. CPropVar()
  61. {
  62. PropVariantInit( this );
  63. }
  64. ~CPropVar()
  65. {
  66. PropVariantClear( this );
  67. }
  68. void SetUI4( UINT x )
  69. {
  70. PropVariantClear( this );
  71. vt = VT_UI4;
  72. ulVal = x;
  73. }
  74. ULONG Count() const
  75. {
  76. if ( 0 != ( vt & VT_VECTOR ) )
  77. return cai.cElems;
  78. return 0;
  79. }
  80. #if 0 //works, but not needed
  81. BOOL SetLPWSTR( WCHAR const * pwc, UINT index )
  82. {
  83. if ( ( VT_VECTOR | VT_LPWSTR ) != vt )
  84. PropVariantClear( this );
  85. if ( index >= calpwstr.cElems )
  86. {
  87. WCHAR **ppOld = calpwstr.pElems;
  88. calpwstr.pElems = (WCHAR **) CoTaskMemAlloc( (index + 1) * sizeof (calpwstr.pElems[0]) );
  89. if ( 0 == calpwstr.pElems )
  90. {
  91. calpwstr.pElems = ppOld;
  92. return FALSE;
  93. }
  94. vt = ( VT_VECTOR | VT_LPWSTR );
  95. memcpy( calpwstr.pElems,
  96. ppOld,
  97. calpwstr.cElems * sizeof( calpwstr.pElems[0] ) );
  98. memset( &calpwstr.pElems[calpwstr.cElems],
  99. 0,
  100. ((index + 1) - calpwstr.cElems) * sizeof(calpwstr.pElems[0]) );
  101. calpwstr.cElems = index + 1;
  102. CoTaskMemFree( ppOld );
  103. }
  104. unsigned cwc = wcslen( pwc ) + 1;
  105. WCHAR * pwsz = (WCHAR *) CoTaskMemAlloc( cwc * sizeof WCHAR );
  106. if ( 0 == pwsz )
  107. return FALSE;
  108. wcscpy( pwsz, pwc );
  109. if ( 0 != calpwstr.pElems[index] )
  110. CoTaskMemFree( calpwstr.pElems[index] );
  111. calpwstr.pElems[index] = pwsz;
  112. return TRUE;
  113. }
  114. #endif
  115. void * operator new( size_t cb )
  116. {
  117. return CoTaskMemAlloc( cb );
  118. }
  119. void * operator new( size_t cb, void *p )
  120. {
  121. return p;
  122. }
  123. void operator delete( void *p )
  124. {
  125. if ( 0 != p )
  126. CoTaskMemFree( p );
  127. }
  128. #if _MSC_VER >= 1200
  129. void operator delete( void *p, void *pp )
  130. {
  131. return;
  132. }
  133. #endif
  134. };