Leaked source code of windows server 2003
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.

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