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.

276 lines
7.9 KiB

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