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.

249 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. cpropbag.h
  5. Abstract:
  6. This module contains the definition of the
  7. generic property bag class
  8. Author:
  9. Keith Lau (keithlau@microsoft.com)
  10. Revision History:
  11. keithlau 06/30/98 created
  12. jstamerj 12/07/00 Copied source for use in dsnsink
  13. --*/
  14. #ifndef _CPROPBAG_H_
  15. #define _CPROPBAG_H_
  16. #include "filehc.h"
  17. #include "mailmsg.h"
  18. #include "cmmtypes.h"
  19. /***************************************************************************/
  20. // Definitions
  21. //
  22. #define GENERIC_PTABLE_INSTANCE_SIGNATURE_VALID ((DWORD)'PTGv')
  23. /***************************************************************************/
  24. // CMailMsgPropertyBag
  25. //
  26. class CMailMsgPropertyBag :
  27. public IMailMsgPropertyBag
  28. {
  29. public:
  30. CMailMsgPropertyBag() :
  31. m_bmBlockManager(NULL),
  32. m_ptProperties(
  33. PTT_PROPERTY_TABLE,
  34. GENERIC_PTABLE_INSTANCE_SIGNATURE_VALID,
  35. &m_bmBlockManager,
  36. &m_InstanceInfo,
  37. CompareProperty,
  38. NULL,
  39. NULL
  40. )
  41. {
  42. m_lRefCount = 1;
  43. // Copy the default instance into our instance
  44. MoveMemory(
  45. &m_InstanceInfo,
  46. &s_DefaultInstanceInfo,
  47. sizeof(PROPERTY_TABLE_INSTANCE));
  48. }
  49. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID *ppvObj)
  50. {
  51. if (riid == IID_IUnknown)
  52. *ppvObj = (IUnknown *)(IMailMsgPropertyBag *)this;
  53. else if (riid == IID_IMailMsgPropertyBag)
  54. *ppvObj = (IMailMsgPropertyBag *)this;
  55. else if (riid == IID_IMailMsgRegisterCleanupCallback)
  56. *ppvObj = (IMailMsgRegisterCleanupCallback *)this;
  57. else
  58. return(E_NOINTERFACE);
  59. AddRef();
  60. return(S_OK);
  61. }
  62. unsigned long STDMETHODCALLTYPE AddRef()
  63. {
  64. return(InterlockedIncrement(&m_lRefCount));
  65. }
  66. unsigned long STDMETHODCALLTYPE Release()
  67. {
  68. LONG lTemp = InterlockedDecrement(&m_lRefCount);
  69. if (!lTemp)
  70. {
  71. // Extra releases are bad!
  72. _ASSERT(lTemp);
  73. }
  74. return(lTemp);
  75. }
  76. HRESULT STDMETHODCALLTYPE PutProperty(
  77. DWORD dwPropID,
  78. DWORD cbLength,
  79. LPBYTE pbValue
  80. )
  81. {
  82. GLOBAL_PROPERTY_ITEM piItem;
  83. piItem.idProp = dwPropID;
  84. return(m_ptProperties.PutProperty(
  85. (LPVOID)&dwPropID,
  86. (LPPROPERTY_ITEM)&piItem,
  87. cbLength,
  88. pbValue));
  89. }
  90. HRESULT STDMETHODCALLTYPE GetProperty(
  91. DWORD dwPropID,
  92. DWORD cbLength,
  93. DWORD *pcbLength,
  94. LPBYTE pbValue
  95. )
  96. {
  97. GLOBAL_PROPERTY_ITEM piItem;
  98. return(m_ptProperties.GetPropertyItemAndValue(
  99. (LPVOID)&dwPropID,
  100. (LPPROPERTY_ITEM)&piItem,
  101. cbLength,
  102. pcbLength,
  103. pbValue));
  104. }
  105. HRESULT STDMETHODCALLTYPE PutStringA(
  106. DWORD dwPropID,
  107. LPCSTR pszValue
  108. )
  109. {
  110. return(PutProperty(dwPropID, pszValue?strlen(pszValue)+1:0, (LPBYTE)pszValue));
  111. }
  112. HRESULT STDMETHODCALLTYPE GetStringA(
  113. DWORD dwPropID,
  114. DWORD cchLength,
  115. LPSTR pszValue
  116. )
  117. {
  118. DWORD dwLength;
  119. return(GetProperty(dwPropID, cchLength, &dwLength, (LPBYTE)pszValue));
  120. }
  121. HRESULT STDMETHODCALLTYPE PutStringW(
  122. DWORD dwPropID,
  123. LPCWSTR pszValue
  124. )
  125. {
  126. return(PutProperty(dwPropID, pszValue?(wcslen(pszValue)+1)*sizeof(WCHAR):0, (LPBYTE)pszValue));
  127. }
  128. HRESULT STDMETHODCALLTYPE GetStringW(
  129. DWORD dwPropID,
  130. DWORD cchLength,
  131. LPWSTR pszValue
  132. )
  133. {
  134. DWORD dwLength;
  135. return(GetProperty(dwPropID, cchLength*sizeof(WCHAR), &dwLength, (LPBYTE)pszValue));
  136. }
  137. HRESULT STDMETHODCALLTYPE PutDWORD(
  138. DWORD dwPropID,
  139. DWORD dwValue
  140. )
  141. {
  142. return(PutProperty(dwPropID, sizeof(DWORD), (LPBYTE)&dwValue));
  143. }
  144. HRESULT STDMETHODCALLTYPE GetDWORD(
  145. DWORD dwPropID,
  146. DWORD *pdwValue
  147. )
  148. {
  149. DWORD dwLength;
  150. return(GetProperty(dwPropID, sizeof(DWORD), &dwLength, (LPBYTE)pdwValue));
  151. }
  152. HRESULT STDMETHODCALLTYPE PutBool(
  153. DWORD dwPropID,
  154. DWORD dwValue
  155. )
  156. {
  157. dwValue = dwValue ? 1 : 0;
  158. return(PutProperty(dwPropID, sizeof(DWORD), (LPBYTE)&dwValue));
  159. }
  160. HRESULT STDMETHODCALLTYPE GetBool(
  161. DWORD dwPropID,
  162. DWORD *pdwValue
  163. )
  164. {
  165. HRESULT hrRes;
  166. DWORD dwLength;
  167. hrRes = GetProperty(dwPropID, sizeof(DWORD), &dwLength, (LPBYTE)pdwValue);
  168. if (pdwValue)
  169. *pdwValue = *pdwValue ? 1 : 0;
  170. return (hrRes);
  171. }
  172. private:
  173. // The specific compare function for this type of property table
  174. static HRESULT CompareProperty(
  175. LPVOID pvPropKey,
  176. LPPROPERTY_ITEM pItem
  177. );
  178. private:
  179. // Usage count
  180. LONG m_lRefCount;
  181. // Property table instance
  182. PROPERTY_TABLE_INSTANCE m_InstanceInfo;
  183. static PROPERTY_TABLE_INSTANCE s_DefaultInstanceInfo;
  184. // IMailMsgProperties is an instance of CPropertyTable
  185. CPropertyTable m_ptProperties;
  186. // An instance of the block memory manager
  187. CBlockManager m_bmBlockManager;
  188. };
  189. // =================================================================
  190. // Compare function
  191. //
  192. inline HRESULT CMailMsgPropertyBag::CompareProperty(
  193. LPVOID pvPropKey,
  194. LPPROPERTY_ITEM pItem
  195. )
  196. {
  197. if (*(PROP_ID *)pvPropKey == ((LPGLOBAL_PROPERTY_ITEM)pItem)->idProp)
  198. return(S_OK);
  199. return(STG_E_UNKNOWN);
  200. }
  201. #endif