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.

152 lines
3.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: utils.hxx
  7. //
  8. // Contents: Useful classes in implementing properties.
  9. //
  10. // Classes: CPropSetName - Buffer which converts fmtids->names
  11. // CSubPropertyName - Buffer which converts VT_STREAM etc -> name
  12. //
  13. // Functions: DfpStatusToHResult - map NTSTATUS to HRESULT
  14. // VerifyCommitFlags - check transaction flags
  15. // Probe - probe memory range to generate GP fault.
  16. //
  17. // History: 1-Mar-95 BillMo Created.
  18. //
  19. // Notes:
  20. //
  21. // Codework:
  22. //
  23. //--------------------------------------------------------------------------
  24. //+-------------------------------------------------------------------------
  25. //
  26. // Misc functions and defines
  27. //
  28. //--------------------------------------------------------------------------
  29. #if DBG
  30. #define STACKELEMS 3
  31. #else
  32. #define STACKELEMS 64
  33. #endif
  34. extern HRESULT NtStatusToScode(NTSTATUS);
  35. inline HRESULT DfpNtStatusToHResult(NTSTATUS nts)
  36. {
  37. if ((nts & 0xF0000000) == 0x80000000)
  38. return nts;
  39. else
  40. return(NtStatusToScode(nts));
  41. }
  42. #define VerifyCommitFlags(cf) \
  43. ((((cf) & ~(STGC_OVERWRITE | STGC_ONLYIFCURRENT | \
  44. STGC_DANGEROUSLYCOMMITMERELYTODISKCACHE)) == 0) ? S_OK : \
  45. STG_E_INVALIDFLAG)
  46. inline VOID Probe(VOID *pv, ULONG cb)
  47. {
  48. BYTE b = *(BYTE*)pv;
  49. b=((BYTE*)pv)[cb-1];
  50. }
  51. //+-------------------------------------------------------------------------
  52. //
  53. // Class: CPropSetName
  54. //
  55. // Purpose: Wrap buffer to convert
  56. //
  57. // Interface:
  58. //
  59. //
  60. //
  61. //
  62. //
  63. // Notes:
  64. //
  65. //--------------------------------------------------------------------------
  66. class CPropSetName
  67. {
  68. public:
  69. CPropSetName(REFFMTID rfmtid);
  70. inline const OLECHAR * GetPropSetName()
  71. {
  72. return(_oszName);
  73. }
  74. private:
  75. OLECHAR _oszName[CWCSTORAGENAME];
  76. };
  77. class CStackBuffer
  78. {
  79. public:
  80. CStackBuffer(BYTE *pbStackBuf,
  81. ULONG ulElementSize,
  82. ULONG cStackElements);
  83. ~CStackBuffer();
  84. HRESULT Init(ULONG cElements);
  85. protected:
  86. BYTE * _pbHeapBuf;
  87. private:
  88. BYTE * _pbStackBuf;
  89. ULONG _cbElementSize;
  90. ULONG _cStackElements;
  91. };
  92. inline CStackBuffer::CStackBuffer( BYTE *pbStackBuf,
  93. ULONG cbElementSize,
  94. ULONG cStackElements)
  95. : _pbStackBuf(pbStackBuf),
  96. _pbHeapBuf(pbStackBuf),
  97. _cbElementSize(cbElementSize),
  98. _cStackElements(cStackElements)
  99. {
  100. }
  101. inline CStackBuffer::~CStackBuffer()
  102. {
  103. if (_pbHeapBuf != _pbStackBuf)
  104. {
  105. delete [] _pbHeapBuf;
  106. }
  107. }
  108. class CStackPropIdArray : public CStackBuffer
  109. {
  110. public:
  111. inline CStackPropIdArray();
  112. inline PROPID * GetBuf();
  113. private:
  114. PROPID _apid[STACKELEMS];
  115. };
  116. inline CStackPropIdArray::CStackPropIdArray() :
  117. CStackBuffer((BYTE*)_apid, sizeof(_apid[0]), sizeof(_apid)/sizeof(_apid[0]))
  118. {
  119. }
  120. inline PROPID * CStackPropIdArray::GetBuf()
  121. {
  122. return((PROPID*)_pbHeapBuf);
  123. }
  124. inline void PropSysFreeString(BSTR bstr)
  125. {
  126. SysFreeString(bstr);
  127. }
  128. inline BSTR PropSysAllocString(LPOLECHAR pwsz)
  129. {
  130. return SysAllocString(pwsz);
  131. }