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.

239 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. seodefs.h
  5. Abstract:
  6. This module contains the definitions for all of the internal
  7. pieces of SEO.DLL.
  8. Author:
  9. Don Dumitru (dondu@microsoft.com)
  10. Revision History:
  11. dondu 10/24/96 created
  12. --*/
  13. #ifndef _SEODEFS_INC
  14. #define _SEODEFS_INC
  15. #include <limits.h>
  16. #include "resource.h"
  17. #include "seo.h"
  18. #if 1
  19. #include "dbgtrace.h"
  20. #else
  21. #define TraceFunctEnter(x)
  22. inline void _DummyFunctTrace(int a, ...) {}
  23. #define FunctTrace _DummyFunctTrace
  24. inline void _DummyTraceFunctLeave() {}
  25. #define TraceFunctLeave _DummyTraceFunctLeave
  26. #endif
  27. #ifdef DEBUG
  28. class CDebugModule {
  29. public:
  30. void Init() {
  31. InitializeCriticalSection(&m_csLock);
  32. m_dwData = 0;
  33. m_pData = NULL;
  34. };
  35. void Term() {
  36. if (m_pData) {
  37. for (DWORD dwIdx=0;dwIdx<m_dwData;dwIdx++) {
  38. //_ASSERTE(!m_pData[dwIdx].pszObject);
  39. }
  40. delete[] m_pData;
  41. m_pData = NULL;
  42. m_dwData = 0;
  43. }
  44. DeleteCriticalSection(&m_csLock);
  45. };
  46. void AddObject(LPVOID pvObject, LPCSTR pszObject) {
  47. EnterCriticalSection(&m_csLock);
  48. for (DWORD dwIdx=0;dwIdx<m_dwData;dwIdx++) {
  49. if (!m_pData[dwIdx].pvObject) {
  50. m_pData[dwIdx].pvObject = pvObject;
  51. m_pData[dwIdx].pszObject = pszObject;
  52. LeaveCriticalSection(&m_csLock);
  53. return;
  54. }
  55. }
  56. Data *pData = new Data[m_dwData+8];
  57. if (!pData) {
  58. LeaveCriticalSection(&m_csLock);
  59. return;
  60. }
  61. memcpy(pData,m_pData,sizeof(*pData)*m_dwData);
  62. memset(&pData[m_dwData],0,sizeof(*pData)*8);
  63. delete[] m_pData;
  64. m_pData = pData;
  65. pData[m_dwData].pvObject = pvObject;
  66. pData[m_dwData].pszObject = pszObject;
  67. m_dwData += 8;
  68. LeaveCriticalSection(&m_csLock);
  69. };
  70. void RemoveObject(LPVOID pvObject) {
  71. EnterCriticalSection(&m_csLock);
  72. for (DWORD dwIdx=0;dwIdx<m_dwData;dwIdx++) {
  73. if (m_pData[dwIdx].pvObject == pvObject) {
  74. m_pData[dwIdx].pvObject = NULL;
  75. m_pData[dwIdx].pszObject = NULL;
  76. break;
  77. }
  78. }
  79. LeaveCriticalSection(&m_csLock);
  80. _ASSERTE(dwIdx!=m_dwData);
  81. }
  82. private:
  83. typedef struct tagData {
  84. LPVOID pvObject;
  85. LPCSTR pszObject;
  86. } Data;
  87. CRITICAL_SECTION m_csLock;
  88. DWORD m_dwData;
  89. Data *m_pData;
  90. };
  91. #ifndef MODULE_DEBUG
  92. #define MODULE_DEBUG _ModuleDebug
  93. #endif
  94. #define DEFINE_DEBUG_MODULE extern CDebugModule MODULE_DEBUG;
  95. #define ALLOC_DEBUG_MODULE CDebugModule MODULE_DEBUG;
  96. #define INIT_DEBUG_MODULE MODULE_DEBUG.Init();
  97. #define TERM_DEBUG_MODULE MODULE_DEBUG.Term();
  98. #define ADD_DEBUG_OBJECT(x) MODULE_DEBUG.AddObject(this,x);
  99. #define REMOVE_DEBUG_OBJECT MODULE_DEBUG.RemoveObject(this);
  100. #else
  101. #define DEFINE_DEBUG_MODULE
  102. #define ALLOC_DEBUG_MODULE
  103. #define INIT_DEBUG_MODULE
  104. #define TERM_DEBUG_MODULE
  105. #define ADD_DEBUG_OBJECT(x)
  106. #define REMOVE_DEBUG_OBJECT
  107. #endif
  108. #ifdef DEBUG
  109. template<class T>
  110. class CDebugObject {
  111. public:
  112. CDebugObject() { m_pszName = T::DebugObjectGetInitName(); };
  113. ~CDebugObject() { m_pszName = T::DebugObjectGetTermName(); };
  114. BOOL Check() { return (((m_pszName==T::DebugObjectGetInitName())||(strcmp(m_pszName,T::DebugObjectGetInitName())==0))?TRUE:FALSE); };
  115. private:
  116. LPCSTR m_pszName;
  117. };
  118. #define DEBUG_OBJECT_DEF2(_class,_string,_suffix) \
  119. public: \
  120. static inline LPCSTR DebugObjectGetInitName() { return (_string); }; \
  121. static inline LPCSTR DebugObjectGetTermName() { return (_string " *** DELETED ***" ); }; \
  122. CDebugObject<_class> m_DebugObject##_suffix; \
  123. inline BOOL DebugObjectCheck() { return (m_DebugObject##_suffix.Check()); };
  124. #define DEBUG_OBJECT_DEF(x) DEBUG_OBJECT_DEF2(x,#x,x)
  125. #define DEBUG_OBJECT_CHECK _ASSERTE(DebugObjectCheck());
  126. #else
  127. #define DEBUG_OBJECT_DEF2(_class,_string,_suffix)
  128. #define DEBUG_OBJECT_DEF(x)
  129. #define DEBUG_OBJECT_CHECK
  130. #endif
  131. DEFINE_DEBUG_MODULE
  132. void MyMallocTerm();
  133. BOOL MyMallocInit();
  134. LPVOID MyMalloc(size_t cbBytes);
  135. LPVOID MyRealloc(LPVOID pvBlock, size_t cbBytes);
  136. BOOL MyReallocInPlace(LPVOID pvPtrToPtrToBlock, size_t cbBytes);
  137. void MyFree(LPVOID pvBlock);
  138. void MyFreeInPlace(LPVOID pvPtrToPtrToBlock);
  139. void MySysFreeStringInPlace(BSTR *pstrBlock);
  140. // SHREAD_POINTER destroys a pointer so it can't be used again.
  141. // Not really necissary, so only included in DEBUG builds
  142. #ifdef DEBUG
  143. #define SHREAD_POINTER(ptr) ptr = 0
  144. #else // DEBUG
  145. #define SHREAD_POINTER(ptr)
  146. #endif // DEBUG
  147. #define RELEASE_AND_SHREAD_POINTER(ptr) if(ptr) ptr->Release(); SHREAD_POINTER(ptr)
  148. // Compare two BSTR's. Return true if they're equal
  149. inline BOOL EqualBSTR(BSTR a, BSTR b) {
  150. return (CompareStringW(LOCALE_SYSTEM_DEFAULT, 0, a, -1, b, -1) == 2);
  151. }
  152. // Coerce a Variant into the desired type in-place
  153. void VariantCoerce(VARIANTARG &var, VARTYPE varType);
  154. // Turn the IUnknown parameter into an ISEODictionary
  155. ISEODictionary *GetDictionary(IUnknown *piUnk);
  156. // Read a subkey from an ISEODictionary and return it as another ISEODictionary
  157. ISEODictionary *ReadSubBag(ISEODictionary *bag, LPCSTR str);
  158. // Read a string from the Dictionary.
  159. HRESULT ReadString(ISEODictionary *bag, LPCOLESTR property,
  160. LPSTR psBuf, LPDWORD dwCount);
  161. // Given a CLSID as a string, create an object of that CLSID
  162. void *CreateFromString(LPCOLESTR str, REFIID iface);
  163. template<class T, const IID *piid, class CDV = CComDynamicUnkArray>
  164. class ATL_NO_VTABLE CSEOConnectionPointImpl : public IConnectionPointImpl<T,piid,CDV> {
  165. public:
  166. CSEOConnectionPointImpl() {
  167. m_dwCount = 0; };
  168. virtual void AdviseCalled(IUnknown *pUnk, DWORD *pdwCookie, REFIID riid, DWORD dwCount) {
  169. /* nothing */ };
  170. virtual void UnadviseCalled(DWORD dwCookie, REFIID riid, DWORD dwCount) {
  171. /* nothing */ };
  172. DWORD GetCount() {
  173. return (m_dwCount); };
  174. public:
  175. HRESULT STDMETHODCALLTYPE Advise(IUnknown *pUnk, DWORD *pdwCookie) {
  176. HRESULT hrRes;
  177. T *pT = (T *) this;
  178. pT->Lock();
  179. hrRes = IConnectionPointImpl<T,piid,CDV>::Advise(pUnk,pdwCookie);
  180. if (SUCCEEDED(hrRes)) {
  181. m_dwCount++;
  182. AdviseCalled(pUnk,pdwCookie,*piid,m_dwCount);
  183. }
  184. pT->Unlock();
  185. return (hrRes);
  186. }
  187. HRESULT STDMETHODCALLTYPE Unadvise(DWORD dwCookie) {
  188. HRESULT hrRes;
  189. T *pT = (T *) this;
  190. pT->Lock();
  191. hrRes = IConnectionPointImpl<T,piid,CDV>::Unadvise(dwCookie);
  192. if (SUCCEEDED(hrRes)) {
  193. m_dwCount--;
  194. UnadviseCalled(dwCookie,*piid,m_dwCount);
  195. }
  196. pT->Unlock();
  197. return (hrRes);
  198. }
  199. private:
  200. DWORD m_dwCount;
  201. };
  202. #endif