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.

305 lines
11 KiB

  1. class COleVariant; // OLE VARIANT wrapper
  2. class COleDateTime; // Based on OLE DATE
  3. class CLongBinary; // forward reference (see afxdb_.h)
  4. /*
  5. class COleCurrency; // Based on OLE CY
  6. class COleDateTimeSpan; // Based on a double
  7. class COleSafeArray; // Based on OLE VARIANT
  8. */
  9. /////////////////////////////////////////////////////////////////////////////
  10. // AFXDLL support
  11. #undef AFX_DATA
  12. #define AFX_DATA AFX_OLE_DATA
  13. #include <delaydll.h>
  14. // parameter types: by value VTs
  15. #define VTS_I2 "\x02" // a 'short'
  16. #define VTS_I4 "\x03" // a 'long'
  17. #define VTS_R4 "\x04" // a 'float'
  18. #define VTS_R8 "\x05" // a 'double'
  19. #define VTS_CY "\x06" // a 'CY' or 'CY*'
  20. #define VTS_DATE "\x07" // a 'DATE'
  21. #define VTS_WBSTR "\x08" // an 'LPCOLESTR'
  22. #define VTS_DISPATCH "\x09" // an 'IDispatch*'
  23. #define VTS_SCODE "\x0A" // an 'SCODE'
  24. #define VTS_BOOL "\x0B" // a 'BOOL'
  25. #define VTS_VARIANT "\x0C" // a 'const VARIANT&' or 'VARIANT*'
  26. #define VTS_UNKNOWN "\x0D" // an 'IUnknown*'
  27. #if defined(_UNICODE) || defined(OLE2ANSI)
  28. #define VTS_BSTR VTS_WBSTR// an 'LPCOLESTR'
  29. #define VT_BSTRT VT_BSTR
  30. #else
  31. #define VTS_BSTR "\x0E" // an 'LPCSTR'
  32. #define VT_BSTRA 14
  33. #define VT_BSTRT VT_BSTRA
  34. #endif
  35. // parameter types: by reference VTs
  36. #define VTS_PI2 "\x42" // a 'short*'
  37. #define VTS_PI4 "\x43" // a 'long*'
  38. #define VTS_PR4 "\x44" // a 'float*'
  39. #define VTS_PR8 "\x45" // a 'double*'
  40. #define VTS_PCY "\x46" // a 'CY*'
  41. #define VTS_PDATE "\x47" // a 'DATE*'
  42. #define VTS_PBSTR "\x48" // a 'BSTR*'
  43. #define VTS_PDISPATCH "\x49" // an 'IDispatch**'
  44. #define VTS_PSCODE "\x4A" // an 'SCODE*'
  45. #define VTS_PBOOL "\x4B" // a 'VARIANT_BOOL*'
  46. #define VTS_PVARIANT "\x4C" // a 'VARIANT*'
  47. #define VTS_PUNKNOWN "\x4D" // an 'IUnknown**'
  48. // special VT_ and VTS_ values
  49. #define VTS_NONE NULL // used for members with 0 params
  50. #define VT_MFCVALUE 0xFFF // special value for DISPID_VALUE
  51. #define VT_MFCBYREF 0x40 // indicates VT_BYREF type
  52. #define VT_MFCMARKER 0xFF // delimits named parameters (INTERNAL USE)
  53. // variant handling (use V_BSTRT when you have ANSI BSTRs, as in DAO)
  54. #ifndef _UNICODE
  55. #define V_BSTRT(b) (LPSTR)V_BSTR(b)
  56. #else
  57. #define V_BSTRT(b) V_BSTR(b)
  58. #endif
  59. /////////////////////////////////////////////////////////////////////////////
  60. // COleVariant class - wraps VARIANT types
  61. typedef const VARIANT* LPCVARIANT;
  62. class COleVariant : public tagVARIANT
  63. {
  64. // Constructors
  65. public:
  66. COleVariant();
  67. COleVariant(const VARIANT& varSrc);
  68. COleVariant(LPCVARIANT pSrc);
  69. COleVariant(const COleVariant& varSrc);
  70. COleVariant(LPCTSTR lpszSrc);
  71. COleVariant(LPCTSTR lpszSrc, VARTYPE vtSrc); // used to set to ANSI string
  72. COleVariant(CString& strSrc);
  73. COleVariant(BYTE nSrc);
  74. COleVariant(short nSrc, VARTYPE vtSrc = VT_I2);
  75. COleVariant(long lSrc, VARTYPE vtSrc = VT_I4);
  76. //COleVariant(const COleCurrency& curSrc);
  77. COleVariant(float fltSrc);
  78. COleVariant(double dblSrc);
  79. COleVariant(const COleDateTime& timeSrc);
  80. //COleVariant(const CByteArray& arrSrc);
  81. COleVariant(const CLongBinary& lbSrc);
  82. // Operations
  83. public:
  84. void Clear();
  85. void ChangeType(VARTYPE vartype, LPVARIANT pSrc = NULL);
  86. void Attach(VARIANT& varSrc);
  87. VARIANT Detach();
  88. BOOL operator==(const VARIANT& varSrc) const;
  89. BOOL operator==(LPCVARIANT pSrc) const;
  90. const COleVariant& operator=(const VARIANT& varSrc);
  91. const COleVariant& operator=(LPCVARIANT pSrc);
  92. const COleVariant& operator=(const COleVariant& varSrc);
  93. const COleVariant& operator=(const LPCTSTR lpszSrc);
  94. const COleVariant& operator=(const CString& strSrc);
  95. const COleVariant& operator=(BYTE nSrc);
  96. const COleVariant& operator=(short nSrc);
  97. const COleVariant& operator=(long lSrc);
  98. //const COleVariant& operator=(const COleCurrency& curSrc);
  99. const COleVariant& operator=(float fltSrc);
  100. const COleVariant& operator=(double dblSrc);
  101. const COleVariant& operator=(const COleDateTime& dateSrc);
  102. //const COleVariant& operator=(const CByteArray& arrSrc);
  103. const COleVariant& operator=(const CLongBinary& lbSrc);
  104. void SetString(LPCTSTR lpszSrc, VARTYPE vtSrc); // used to set ANSI string
  105. HRESULT Save(IStream *pStm, BOOL fClearDirty = FALSE);
  106. HRESULT Load(IStream *pStm);
  107. //HRESULT GetSizeMax(ULARGE_INTEGER *pcbSize);
  108. HRESULT GetSizeMax(ULONG *pcbSize);
  109. operator LPVARIANT();
  110. operator LPCVARIANT() const;
  111. // Implementation
  112. public:
  113. ~COleVariant();
  114. };
  115. // COleVariant diagnostics and serialization
  116. #ifdef _DEBUG
  117. CDumpContext& AFXAPI operator<<(CDumpContext& dc, COleVariant varSrc);
  118. #endif
  119. //CArchive& AFXAPI operator<<(CArchive& ar, COleVariant varSrc);
  120. //CArchive& AFXAPI operator>>(CArchive& ar, COleVariant& varSrc);
  121. // Helper for initializing VARIANT structures
  122. void AFXAPI AfxVariantInit(LPVARIANT pVar);
  123. class COleSafeArray;
  124. /////////////////////////////////////////////////////////////////////////////
  125. // Helper for initializing COleSafeArray
  126. void AFXAPI AfxSafeArrayInit(COleSafeArray* psa);
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CSafeArray class
  129. typedef const SAFEARRAY* LPCSAFEARRAY;
  130. class COleSafeArray : public tagVARIANT
  131. {
  132. //Constructors
  133. public:
  134. COleSafeArray();
  135. COleSafeArray(const SAFEARRAY& saSrc, VARTYPE vtSrc);
  136. COleSafeArray(LPCSAFEARRAY pSrc, VARTYPE vtSrc);
  137. COleSafeArray(const COleSafeArray& saSrc);
  138. COleSafeArray(const VARIANT& varSrc);
  139. COleSafeArray(LPCVARIANT pSrc);
  140. COleSafeArray(const COleVariant& varSrc);
  141. // Operations
  142. public:
  143. void Clear();
  144. void Attach(VARIANT& varSrc);
  145. VARIANT Detach();
  146. COleSafeArray& operator=(const COleSafeArray& saSrc);
  147. COleSafeArray& operator=(const VARIANT& varSrc);
  148. COleSafeArray& operator=(LPCVARIANT pSrc);
  149. COleSafeArray& operator=(const COleVariant& varSrc);
  150. BOOL operator==(const SAFEARRAY& saSrc) const;
  151. BOOL operator==(LPCSAFEARRAY pSrc) const;
  152. BOOL operator==(const COleSafeArray& saSrc) const;
  153. BOOL operator==(const VARIANT& varSrc) const;
  154. BOOL operator==(LPCVARIANT pSrc) const;
  155. BOOL operator==(const COleVariant& varSrc) const;
  156. operator LPVARIANT();
  157. operator LPCVARIANT() const;
  158. // One dim array helpers
  159. void CreateOneDim(VARTYPE vtSrc, DWORD dwElements,
  160. void* pvSrcData = NULL, long nLBound = 0);
  161. DWORD GetOneDimSize();
  162. void ResizeOneDim(DWORD dwElements);
  163. // Multi dim array helpers
  164. void Create(VARTYPE vtSrc, DWORD dwDims, DWORD* rgElements);
  165. // SafeArray wrapper classes
  166. void Create(VARTYPE vtSrc, DWORD dwDims, SAFEARRAYBOUND* rgsabounds);
  167. void AccessData(void** ppvData);
  168. void UnaccessData();
  169. void AllocData();
  170. void AllocDescriptor(DWORD dwDims);
  171. void Copy(LPSAFEARRAY* ppsa);
  172. void GetLBound(DWORD dwDim, long* pLBound);
  173. void GetUBound(DWORD dwDim, long* pUBound);
  174. void GetElement(long* rgIndices, void* pvData);
  175. void PtrOfIndex(long* rgIndices, void** ppvData);
  176. void PutElement(long* rgIndices, void* pvData);
  177. void Redim(SAFEARRAYBOUND* psaboundNew);
  178. void Lock();
  179. void Unlock();
  180. DWORD GetDim();
  181. DWORD GetElemSize();
  182. void Destroy();
  183. void DestroyData();
  184. void DestroyDescriptor();
  185. //Implementation
  186. public:
  187. ~COleSafeArray();
  188. // Cache info to make element access (operator []) faster
  189. DWORD m_dwElementSize;
  190. DWORD m_dwDims;
  191. };
  192. // COleSafeArray diagnostics and serialization
  193. #ifdef _DEBUG
  194. CDumpContext& AFXAPI operator<<(CDumpContext& dc, COleSafeArray saSrc);
  195. #endif
  196. //CArchive& AFXAPI operator<<(CArchive& ar, COleSafeArray saSrc);
  197. //CArchive& AFXAPI operator>>(CArchive& ar, COleSafeArray& saSrc);
  198. #define _AFXDISP_INLINE inline
  199. #ifdef _AFX_INLINE
  200. // COleVariant
  201. _AFXDISP_INLINE COleVariant::COleVariant()
  202. { AfxVariantInit(this); }
  203. _AFXDISP_INLINE COleVariant::~COleVariant()
  204. { ::VariantClear(this); }
  205. _AFXDISP_INLINE COleVariant::COleVariant(LPCTSTR lpszSrc)
  206. { vt = VT_EMPTY; *this = lpszSrc; }
  207. _AFXDISP_INLINE COleVariant::COleVariant(CString& strSrc)
  208. { vt = VT_EMPTY; *this = strSrc; }
  209. _AFXDISP_INLINE COleVariant::COleVariant(BYTE nSrc)
  210. { vt = VT_UI1; bVal = nSrc; }
  211. //_AFXDISP_INLINE COleVariant::COleVariant(const COleCurrency& curSrc)
  212. // { vt = VT_CY; cyVal = curSrc.m_cur; }
  213. _AFXDISP_INLINE COleVariant::COleVariant(float fltSrc)
  214. { vt = VT_R4; fltVal = fltSrc; }
  215. _AFXDISP_INLINE COleVariant::COleVariant(double dblSrc)
  216. { vt = VT_R8; dblVal = dblSrc; }
  217. //_AFXDISP_INLINE COleVariant::COleVariant(const COleDateTime& dateSrc)
  218. // { vt = VT_DATE; date = dateSrc.m_dt; }
  219. //_AFXDISP_INLINE COleVariant::COleVariant(const CByteArray& arrSrc)
  220. // { vt = VT_EMPTY; *this = arrSrc; }
  221. _AFXDISP_INLINE COleVariant::COleVariant(const CLongBinary& lbSrc)
  222. { vt = VT_EMPTY; *this = lbSrc; }
  223. _AFXDISP_INLINE BOOL COleVariant::operator==(LPCVARIANT pSrc) const
  224. { return *this == *pSrc; }
  225. _AFXDISP_INLINE COleVariant::operator LPVARIANT()
  226. { return this; }
  227. _AFXDISP_INLINE COleVariant::operator LPCVARIANT() const
  228. { return this; }
  229. #endif //_AFX_INLINE
  230. /*
  231. /////////////////////////////////////////////////////////////////////////////
  232. // Inline function declarations
  233. #ifdef _AFX_PACKING
  234. #pragma pack(pop)
  235. #endif
  236. #ifdef _AFX_ENABLE_INLINES
  237. #define _AFXDISP_INLINE inline
  238. //#include <afxole.inl>
  239. #undef _AFXDISP_INLINE
  240. #endif
  241. #undef AFX_DATA
  242. #define AFX_DATA
  243. #ifdef _AFX_MINREBUILD
  244. #pragma component(minrebuild, on)
  245. #endif
  246. #ifndef _AFX_FULLTYPEINFO
  247. #pragma component(mintypeinfo, off)
  248. #endif
  249. */
  250. /////////////////////////////////////////////////////////////////////////////