test: propvar.h Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# propvar.h

Go to the documentation of this file.

    00001 //+--------------------------------------------------------------------------
    00002 //
    00003 // Microsoft Windows
    00004 // Copyright (C) Microsoft Corporation, 1993-1998
    00005 //
    00006 // File:        propvar.h
    00007 //
    00008 // Contents:    PROPVARIANT manipulation code
    00009 //
    00010 // History:     15-Aug-95   vich        created
    00011 //              01-Jul-96   MikeHill    Updated to allow Win32 SEH removal
    00012 //
    00013 //---------------------------------------------------------------------------
    00014
    00015 #ifndef _PROPVAR_H_
    00016 #define _PROPVAR_H_
    00017
    00018 #include <debnot.h>
    00019 #include <propset.h>
    00020
    00021 SERIALIZEDPROPERTYVALUE *
    00022 RtlConvertVariantToProperty(
    00023     IN PROPVARIANT const *pvar,
    00024     IN USHORT CodePage,
    00025     OUT SERIALIZEDPROPERTYVALUE *pprop,
    00026     IN OUT ULONG *pcb,
    00027     IN PROPID pid,
    00028     IN BOOLEAN fVariantVector,
    00029     OPTIONAL OUT ULONG *pcIndirect);
    00030
    00031 SERIALIZEDPROPERTYVALUE *
    00032 RtlConvertVariantToPropertyNoEH(     // No NT Exception Handling version
    00033     IN PROPVARIANT const *pvar,
    00034     IN USHORT CodePage,
    00035     OUT SERIALIZEDPROPERTYVALUE *pprop,
    00036     IN OUT ULONG *pcb,
    00037     IN PROPID pid,
    00038     IN BOOLEAN fVariantVector,
    00039     OPTIONAL OUT ULONG *pcIndirect,
    00040     OUT NTSTATUS *pstatus);
    00041
    00042 BOOLEAN
    00043 RtlConvertPropertyToVariant(
    00044     IN SERIALIZEDPROPERTYVALUE const *pprop,
    00045     IN USHORT CodePage,
    00046     OUT PROPVARIANT *pvar,
    00047     IN PMemoryAllocator *pma);
    00048
    00049 BOOLEAN
    00050 RtlConvertPropertyToVariantNoEH(     // No NT Exception Handling version
    00051     IN SERIALIZEDPROPERTYVALUE const *pprop,
    00052     IN USHORT CodePage,
    00053     OUT PROPVARIANT *pvar,
    00054     IN PMemoryAllocator *pma,
    00055     OUT NTSTATUS *pstatus);
    00056
    00057
    00058
    00059
    00060 SERIALIZEDPROPERTYVALUE *
    00061 PrConvertVariantToProperty(
    00062     IN PROPVARIANT const *pvar,
    00063     IN USHORT CodePage,
    00064     OUT SERIALIZEDPROPERTYVALUE *pprop,
    00065     IN OUT ULONG *pcb,
    00066     IN PROPID pid,
    00067     IN BOOLEAN fVariantVector,
    00068     OPTIONAL OUT ULONG *pcIndirect);
    00069
    00070 SERIALIZEDPROPERTYVALUE *
    00071 PrConvertVariantToPropertyNoEH(     // No NT Exception Handling version
    00072     IN PROPVARIANT const *pvar,
    00073     IN USHORT CodePage,
    00074     OUT SERIALIZEDPROPERTYVALUE *pprop,
    00075     IN OUT ULONG *pcb,
    00076     IN PROPID pid,
    00077     IN BOOLEAN fVariantVector,
    00078     OPTIONAL OUT ULONG *pcIndirect,
    00079     OUT NTSTATUS *pstatus);
    00080
    00081 BOOLEAN
    00082 PrConvertPropertyToVariant(
    00083     IN SERIALIZEDPROPERTYVALUE const *pprop,
    00084     IN USHORT CodePage,
    00085     OUT PROPVARIANT *pvar,
    00086     IN PMemoryAllocator *pma);
    00087
    00088 BOOLEAN
    00089 PrConvertPropertyToVariantNoEH(     // No NT Exception Handling version
    00090     IN SERIALIZEDPROPERTYVALUE const *pprop,
    00091     IN USHORT CodePage,
    00092     OUT PROPVARIANT *pvar,
    00093     IN PMemoryAllocator *pma,
    00094     OUT NTSTATUS *pstatus);
    00095
    00096
    00097
    00098
    00099
    00100 #ifndef KERNEL
    00101 VOID
    00102 CleanupVariants(
    00103     IN PROPVARIANT *pvar,
    00104     IN ULONG cprop,
    00105     IN PMemoryAllocator *pma);
    00106 #endif
    00107
    00108 #if DBGPROP
    00109 BOOLEAN IsUnicodeString(WCHAR const *pwszname, ULONG cb);
    00110 BOOLEAN IsAnsiString(CHAR const *pszname, ULONG cb);
    00111 #endif
    00112
    00113
    00114 //+--------------------------------------------------------------------------
    00115 // Function:    SignalOverflow, SignalInvalidParameter, SignalStatus
    00116 //
    00117 // Synopsis:    ASSERT and raise data corrupt/overflow/specified error
    00118 //
    00119 // Arguments:   [szReason]              -- string explanation
    00120 //              [Status]                -- Status to raise (SignalStatus only)
    00121 //
    00122 // Returns:     None
    00123 //+--------------------------------------------------------------------------
    00124
    00125
    00126 #define StatusOverflow(pstatus, szReason)           \
    00127           *(pstatus) = STATUS_BUFFER_OVERFLOW;      \
    00128           TraceStatus(szReason)
    00129
    00130 #define StatusAccessDenied(pstatus, szReason)   \
    00131           *(pstatus) = STATUS_ACCESS_DENIED;        \
    00132           TraceStatus(szReason);
    00133
    00134 #define StatusInvalidParameter(pstatus, szReason)   \
    00135           *(pstatus) = STATUS_INVALID_PARAMETER;    \
    00136           TraceStatus(szReason);
    00137
    00138 #define StatusNoMemory(pstatus, szReason)           \
    00139           *(pstatus) = STATUS_INSUFFICIENT_RESOURCES;\
    00140           TraceStatus(szReason);
    00141
    00142 #define StatusDiskFull(pstatus, szReason)           \
    00143           *(pstatus) = STATUS_DISK_FULL;            \
    00144           TraceStatus(szReason);
    00145
    00146 #define StatusError(pstatus, szReason, Status)      \
    00147           *(pstatus) = Status;                      \
    00148           TraceStatus(szReason);
    00149
    00150 #ifdef KERNEL
    00151 #define StatusKBufferOverflow(pstatus, szReason) StatusOverflow(pstatus, szReason)
    00152 #else
    00153 #define StatusKBufferOverflow(pstatus, szReason) StatusNoMemory(pstatus, szReason)
    00154 #endif
    00155
    00156
    00157 #ifdef KERNEL
    00158 #define KERNELSELECT(k, u)      k
    00159 #else
    00160 #define KERNELSELECT(k, u)      u
    00161 #endif
    00162
    00163 #define DBGPROPASSERT   KERNELSELECT(DBGPROP, DBG)
    00164
    00165 #if DBGPROPASSERT
    00166 #define TraceStatus(szReason)                                   \
    00167         {                                                       \
    00168             DebugTrace(0, DEBTRACE_ERROR, (szReason "\n"));     \
    00169             PROPASSERTMSG(szReason, !(DebugLevel & DEBTRACE_WARN)); \
    00170         }
    00171
    00172
    00173 #else
    00174 #define TraceStatus(szReason)
    00175 #endif
    00176
    00177
    00178
    00179 #define AssertVarField(field, cb) \
    00180   PROPASSERT(FIELD_OFFSET(PROPVARIANT, iVal) == FIELD_OFFSET(PROPVARIANT, field) && \
    00181          sizeof(((PROPVARIANT *) 0)->field) == (cb))
    00182
    00183 #define AssertVarVector(field, cbElem) \
    00184   PROPASSERT(FIELD_OFFSET(PROPVARIANT, cai.cElems) == \
    00185              FIELD_OFFSET(PROPVARIANT, field.cElems) && \
    00186          FIELD_OFFSET(PROPVARIANT, cai.pElems) == \
    00187              FIELD_OFFSET(PROPVARIANT, field.pElems) && \
    00188          sizeof(((PROPVARIANT *) 0)->field.pElems[0]) == (cbElem))
    00189
    00190 #define AssertByteField(field)      AssertVarField(field, sizeof(BYTE))
    00191 #define AssertShortField(field)     AssertVarField(field, sizeof(SHORT))
    00192 #define AssertLongField(field)      AssertVarField(field, sizeof(LONG))
    00193 #define AssertLongLongField(field)  AssertVarField(field, sizeof(LONGLONG))
    00194 #define AssertStringField(field)    AssertVarField(field, sizeof(VOID *))
    00195
    00196 #define AssertByteVector(field)     AssertVarVector(field, sizeof(BYTE))
    00197 #define AssertShortVector(field)    AssertVarVector(field, sizeof(SHORT))
    00198 #define AssertLongVector(field)     AssertVarVector(field, sizeof(LONG))
    00199 #define AssertLongLongVector(field) AssertVarVector(field, sizeof(LONGLONG))
    00200 #define AssertStringVector(field)   AssertVarVector(field, sizeof(VOID *))
    00201 #define AssertVariantVector(field)  AssertVarVector(field, sizeof(PROPVARIANT))
    00202
    00203
    00204 #define BSTRLEN(bstrVal)        *((ULONG *) bstrVal - 1)
    00205
    00206
    00207 //+-------------------------------------------------------------------
    00208 // Class:       CBufferAllocator, private
    00209 //
    00210 // Synopsis:    allocation from a buffer
    00211 //
    00212 // Notes:       The Summary catalog APIs use a single buffer to serialize row
    00213 //              values on input and deserialize them on output.  This class
    00214 //              encapsulates the memory allocation routines for these APIs.
    00215 //--------------------------------------------------------------------
    00216
    00217 class CBufferAllocator : public PMemoryAllocator
    00218 {
    00219 public:
    00220     inline CBufferAllocator(ULONG cbBuffer, VOID *pvBuffer)
    00221     {
    00222         _cbFree = cbBuffer;
    00223         _pvCur = _pvBuffer = pvBuffer;
    00224 #if _X86_       // stack variables on x86 are not aligned
    00225         PROPASSERT(((ULONG) _pvCur & (sizeof(LONG) - 1)) == 0);
    00226 #else // RISC
    00227         PROPASSERT(((ULONG_PTR) _pvCur & (sizeof(LONGLONG) - 1)) == 0);
    00228 #endif // X86/RISC
    00229     }
    00230
    00231     VOID *Allocate(ULONG cbSize);
    00232     VOID Free(VOID *pv) { }
    00233
    00234     inline ULONG GetFreeSize(VOID) { return(_cbFree); }
    00235
    00236 private:
    00237     ULONG  _cbFree;
    00238     VOID  *_pvCur;
    00239     VOID  *_pvBuffer;
    00240 };
    00241
    00242 //+-------------------------------------------------------------------
    00243 // Member:      CBufferAllocator::Allocate, private
    00244 //
    00245 // Synopsis:    allocation from a buffer
    00246 //
    00247 // Arguments:   [cb]    -- Count of bytes to be allocated.
    00248 //
    00249 // Returns:     pointer to 'allocated' memory -- NULL if no space left
    00250 //--------------------------------------------------------------------
    00251
    00252 #define DEFINE_CBufferAllocator__Allocate                       \
    00253 VOID *                                                          \
    00254 CBufferAllocator::Allocate(ULONG cb)                            \
    00255 {                                                               \
    00256     VOID *pv;                                                   \
    00257                                                                 \
    00258     cb = (cb + sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1); \
    00259     if (cb > _cbFree)                                           \
    00260     {                                                           \
    00261         return(NULL);                                           \
    00262     }                                                           \
    00263     pv = _pvCur;                                                \
    00264     _pvCur = (BYTE *) _pvCur + cb;                              \
    00265     _cbFree -= cb;                                              \
    00266     return(pv);                                                 \
    00267 }
    00268
    00269 #endif // !_PROPVAR_H_