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.

269 lines
7.7 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993-1998
  5. //
  6. // File: propvar.h
  7. //
  8. // Contents: PROPVARIANT manipulation code
  9. //
  10. // History: 15-Aug-95 vich created
  11. // 01-Jul-96 MikeHill Updated to allow Win32 SEH removal
  12. //
  13. //---------------------------------------------------------------------------
  14. #ifndef _PROPVAR_H_
  15. #define _PROPVAR_H_
  16. #include <debnot.h>
  17. #include <propset.h>
  18. SERIALIZEDPROPERTYVALUE *
  19. RtlConvertVariantToProperty(
  20. IN PROPVARIANT const *pvar,
  21. IN USHORT CodePage,
  22. OUT SERIALIZEDPROPERTYVALUE *pprop,
  23. IN OUT ULONG *pcb,
  24. IN PROPID pid,
  25. IN BOOLEAN fVariantVector,
  26. OPTIONAL OUT ULONG *pcIndirect);
  27. SERIALIZEDPROPERTYVALUE *
  28. RtlConvertVariantToPropertyNoEH( // No NT Exception Handling version
  29. IN PROPVARIANT const *pvar,
  30. IN USHORT CodePage,
  31. OUT SERIALIZEDPROPERTYVALUE *pprop,
  32. IN OUT ULONG *pcb,
  33. IN PROPID pid,
  34. IN BOOLEAN fVariantVector,
  35. OPTIONAL OUT ULONG *pcIndirect,
  36. OUT NTSTATUS *pstatus);
  37. BOOLEAN
  38. RtlConvertPropertyToVariant(
  39. IN SERIALIZEDPROPERTYVALUE const *pprop,
  40. IN USHORT CodePage,
  41. OUT PROPVARIANT *pvar,
  42. IN PMemoryAllocator *pma);
  43. BOOLEAN
  44. RtlConvertPropertyToVariantNoEH( // No NT Exception Handling version
  45. IN SERIALIZEDPROPERTYVALUE const *pprop,
  46. IN USHORT CodePage,
  47. OUT PROPVARIANT *pvar,
  48. IN PMemoryAllocator *pma,
  49. OUT NTSTATUS *pstatus);
  50. SERIALIZEDPROPERTYVALUE *
  51. PrConvertVariantToProperty(
  52. IN PROPVARIANT const *pvar,
  53. IN USHORT CodePage,
  54. OUT SERIALIZEDPROPERTYVALUE *pprop,
  55. IN OUT ULONG *pcb,
  56. IN PROPID pid,
  57. IN BOOLEAN fVariantVector,
  58. OPTIONAL OUT ULONG *pcIndirect);
  59. SERIALIZEDPROPERTYVALUE *
  60. PrConvertVariantToPropertyNoEH( // No NT Exception Handling version
  61. IN PROPVARIANT const *pvar,
  62. IN USHORT CodePage,
  63. OUT SERIALIZEDPROPERTYVALUE *pprop,
  64. IN OUT ULONG *pcb,
  65. IN PROPID pid,
  66. IN BOOLEAN fVariantVector,
  67. OPTIONAL OUT ULONG *pcIndirect,
  68. OUT NTSTATUS *pstatus);
  69. BOOLEAN
  70. PrConvertPropertyToVariant(
  71. IN SERIALIZEDPROPERTYVALUE const *pprop,
  72. IN USHORT CodePage,
  73. OUT PROPVARIANT *pvar,
  74. IN PMemoryAllocator *pma);
  75. BOOLEAN
  76. PrConvertPropertyToVariantNoEH( // No NT Exception Handling version
  77. IN SERIALIZEDPROPERTYVALUE const *pprop,
  78. IN USHORT CodePage,
  79. OUT PROPVARIANT *pvar,
  80. IN PMemoryAllocator *pma,
  81. OUT NTSTATUS *pstatus);
  82. #ifndef KERNEL
  83. VOID
  84. CleanupVariants(
  85. IN PROPVARIANT *pvar,
  86. IN ULONG cprop,
  87. IN PMemoryAllocator *pma);
  88. #endif
  89. #if DBGPROP
  90. BOOLEAN IsUnicodeString(WCHAR const *pwszname, ULONG cb);
  91. BOOLEAN IsAnsiString(CHAR const *pszname, ULONG cb);
  92. #endif
  93. //+--------------------------------------------------------------------------
  94. // Function: SignalOverflow, SignalInvalidParameter, SignalStatus
  95. //
  96. // Synopsis: ASSERT and raise data corrupt/overflow/specified error
  97. //
  98. // Arguments: [szReason] -- string explanation
  99. // [Status] -- Status to raise (SignalStatus only)
  100. //
  101. // Returns: None
  102. //+--------------------------------------------------------------------------
  103. #define StatusOverflow(pstatus, szReason) \
  104. *(pstatus) = STATUS_BUFFER_OVERFLOW; \
  105. TraceStatus(szReason)
  106. #define StatusAccessDenied(pstatus, szReason) \
  107. *(pstatus) = STATUS_ACCESS_DENIED; \
  108. TraceStatus(szReason);
  109. #define StatusInvalidParameter(pstatus, szReason) \
  110. *(pstatus) = STATUS_INVALID_PARAMETER; \
  111. TraceStatus(szReason);
  112. #define StatusNoMemory(pstatus, szReason) \
  113. *(pstatus) = STATUS_INSUFFICIENT_RESOURCES;\
  114. TraceStatus(szReason);
  115. #define StatusDiskFull(pstatus, szReason) \
  116. *(pstatus) = STATUS_DISK_FULL; \
  117. TraceStatus(szReason);
  118. #define StatusError(pstatus, szReason, Status) \
  119. *(pstatus) = Status; \
  120. TraceStatus(szReason);
  121. #ifdef KERNEL
  122. #define StatusKBufferOverflow(pstatus, szReason) StatusOverflow(pstatus, szReason)
  123. #else
  124. #define StatusKBufferOverflow(pstatus, szReason) StatusNoMemory(pstatus, szReason)
  125. #endif
  126. #ifdef KERNEL
  127. #define KERNELSELECT(k, u) k
  128. #else
  129. #define KERNELSELECT(k, u) u
  130. #endif
  131. #define DBGPROPASSERT KERNELSELECT(DBGPROP, DBG)
  132. #if DBGPROPASSERT
  133. #define TraceStatus(szReason) \
  134. { \
  135. DebugTrace(0, DEBTRACE_ERROR, (szReason "\n")); \
  136. PROPASSERTMSG(szReason, !(DebugLevel & DEBTRACE_WARN)); \
  137. }
  138. #else
  139. #define TraceStatus(szReason)
  140. #endif
  141. #define AssertVarField(field, cb) \
  142. PROPASSERT(FIELD_OFFSET(PROPVARIANT, iVal) == FIELD_OFFSET(PROPVARIANT, field) && \
  143. sizeof(((PROPVARIANT *) 0)->field) == (cb))
  144. #define AssertVarVector(field, cbElem) \
  145. PROPASSERT(FIELD_OFFSET(PROPVARIANT, cai.cElems) == \
  146. FIELD_OFFSET(PROPVARIANT, field.cElems) && \
  147. FIELD_OFFSET(PROPVARIANT, cai.pElems) == \
  148. FIELD_OFFSET(PROPVARIANT, field.pElems) && \
  149. sizeof(((PROPVARIANT *) 0)->field.pElems[0]) == (cbElem))
  150. #define AssertByteField(field) AssertVarField(field, sizeof(BYTE))
  151. #define AssertShortField(field) AssertVarField(field, sizeof(SHORT))
  152. #define AssertLongField(field) AssertVarField(field, sizeof(LONG))
  153. #define AssertLongLongField(field) AssertVarField(field, sizeof(LONGLONG))
  154. #define AssertStringField(field) AssertVarField(field, sizeof(VOID *))
  155. #define AssertByteVector(field) AssertVarVector(field, sizeof(BYTE))
  156. #define AssertShortVector(field) AssertVarVector(field, sizeof(SHORT))
  157. #define AssertLongVector(field) AssertVarVector(field, sizeof(LONG))
  158. #define AssertLongLongVector(field) AssertVarVector(field, sizeof(LONGLONG))
  159. #define AssertStringVector(field) AssertVarVector(field, sizeof(VOID *))
  160. #define AssertVariantVector(field) AssertVarVector(field, sizeof(PROPVARIANT))
  161. #define BSTRLEN(bstrVal) *((ULONG *) bstrVal - 1)
  162. //+-------------------------------------------------------------------
  163. // Class: CBufferAllocator, private
  164. //
  165. // Synopsis: allocation from a buffer
  166. //
  167. // Notes: The Summary catalog APIs use a single buffer to serialize row
  168. // values on input and deserialize them on output. This class
  169. // encapsulates the memory allocation routines for these APIs.
  170. //--------------------------------------------------------------------
  171. class CBufferAllocator : public PMemoryAllocator
  172. {
  173. public:
  174. inline CBufferAllocator(ULONG cbBuffer, VOID *pvBuffer)
  175. {
  176. _cbFree = cbBuffer;
  177. _pvCur = _pvBuffer = pvBuffer;
  178. #if defined(_X86_)
  179. PROPASSERT(((ULONG) _pvCur & (sizeof(LONG) - 1)) == 0);
  180. #else
  181. PROPASSERT(((ULONG_PTR) _pvCur & (sizeof(LONGLONG) - 1)) == 0);
  182. #endif // defined(_X86_)
  183. }
  184. VOID *Allocate(ULONG cbSize);
  185. VOID Free(VOID *pv) { }
  186. inline ULONG GetFreeSize(VOID) { return(_cbFree); }
  187. private:
  188. ULONG _cbFree;
  189. VOID *_pvCur;
  190. VOID *_pvBuffer;
  191. };
  192. //+-------------------------------------------------------------------
  193. // Member: CBufferAllocator::Allocate, private
  194. //
  195. // Synopsis: allocation from a buffer
  196. //
  197. // Arguments: [cb] -- Count of bytes to be allocated.
  198. //
  199. // Returns: pointer to 'allocated' memory -- NULL if no space left
  200. //--------------------------------------------------------------------
  201. #define DEFINE_CBufferAllocator__Allocate \
  202. VOID * \
  203. CBufferAllocator::Allocate(ULONG cb) \
  204. { \
  205. VOID *pv; \
  206. \
  207. cb = (cb + sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1); \
  208. if (cb > _cbFree) \
  209. { \
  210. return(NULL); \
  211. } \
  212. pv = _pvCur; \
  213. _pvCur = (BYTE *) _pvCur + cb; \
  214. _cbFree -= cb; \
  215. return(pv); \
  216. }
  217. #endif // !_PROPVAR_H_