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.

269 lines
8.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: iroleutl.h
  7. //
  8. // Contents: Definitions of utility stuff for use with Compound Document
  9. // objects.
  10. //
  11. // Classes:
  12. // CStaticClassFactory
  13. // CDynamicClassFactory
  14. //
  15. // Functions:
  16. //
  17. // Macros:
  18. //
  19. // History: 26-Feb-96 SSanu adapted from Forms stuff
  20. //----------------------------------------------------------------------------
  21. #ifndef _IROLEUTL_HXX_
  22. #define _IROLEUTL_HXX_
  23. //---------------------------------------------------------------
  24. // SCODE and HRESULT macros
  25. //---------------------------------------------------------------
  26. #define OK(r) (SUCCEEDED(r))
  27. #define NOTOK(r) (FAILED(r))
  28. // {9AAB0270-7181-11cf-BE7A-00AA00577DD6}
  29. DEFINE_GUID(CLSID_IndexNotify, 0x9aab0270, 0x7181, 0x11cf, 0xbe, 0x7a, 0x0, 0xaa, 0x0, 0x57, 0x7d, 0xd6);
  30. //
  31. // {991adb50-b7f1-11cf-86e3-00aa00b4e1b8}
  32. DEFINE_GUID(CLSID_DSSNotify, 0x991adb50, 0xb7f1, 0x11cf, 0x86, 0xe3, 0x0, 0xaa, 0x0, 0xb4, 0xe1, 0xb8);
  33. //
  34. STDAPI _DllRegisterServer(HINSTANCE hInst, LPSTR lpszProgId, REFCLSID clsid);
  35. STDAPI _DllUnregisterServer(LPSTR lpszProgID, REFCLSID clsid);
  36. //---------------------------------------------------------------
  37. // IUnknown
  38. //---------------------------------------------------------------
  39. #define IRIncrement(__ul) InterlockedIncrement((long *) &__ul)
  40. #define IRDecrement(__ul) InterlockedDecrement((long *) &__ul)
  41. #define DECLARE_IR_IUNKNOWN_METHODS \
  42. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv); \
  43. STDMETHOD_(ULONG, AddRef) (void); \
  44. STDMETHOD_(ULONG, Release) (void);
  45. #define DECLARE_IR_APTTHREAD_IUNKNOWN \
  46. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv); \
  47. ULONG _ulRefs; \
  48. STDMETHOD_(ULONG, AddRef) (void) \
  49. { \
  50. return ++_ulRefs; \
  51. } \
  52. STDMETHOD_(ULONG, Release) (void) \
  53. { \
  54. if (!--_ulRefs) \
  55. { \
  56. delete this; \
  57. return 0; \
  58. } \
  59. return _ulRefs; \
  60. }
  61. #define DECLARE_IR_STANDARD_IUNKNOWN(cls) \
  62. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv); \
  63. ULONG _ulRefs; \
  64. STDMETHOD_(ULONG, AddRef) (void) \
  65. { \
  66. IRIncrement(_ulRefs); \
  67. return _ulRefs; \
  68. } \
  69. STDMETHOD_(ULONG, Release) (void) \
  70. { \
  71. if (!IRDecrement(_ulRefs)) \
  72. { \
  73. IRIncrement(_ulRefs); \
  74. delete this; \
  75. return 0; \
  76. } \
  77. return _ulRefs; \
  78. }
  79. //+---------------------------------------------------------------------
  80. //
  81. // Miscellaneous useful OLE helper and debugging functions
  82. //
  83. //----------------------------------------------------------------------
  84. #if DBG == 1
  85. STDAPI CheckAndReturnResult(
  86. HRESULT hr,
  87. LPSTR lpstrFile,
  88. UINT line,
  89. int cSuccess,
  90. ...);
  91. STDAPI_(void) CheckResult(HRESULT hr, LPSTR lpstrFile, UINT line);
  92. STDAPI_(void) PrintIID(DWORD dwFlags, REFIID riid);
  93. STDAPI PrintHRESULT(DWORD dwFlags, HRESULT hr);
  94. #define SRETURN(hr) \
  95. return CheckAndReturnResult((hr), __FILE__, __LINE__, -1)
  96. #define RRETURN(hr) \
  97. return CheckAndReturnResult((hr), __FILE__, __LINE__, 0)
  98. #define RRETURN1(hr, s1) \
  99. return CheckAndReturnResult((hr), __FILE__, __LINE__, 1, (s1))
  100. #define RRETURN2(hr, s1, s2) \
  101. return CheckAndReturnResult((hr), __FILE__, __LINE__, 2, (s1), (s2))
  102. #define RRETURN3(hr, s1, s2, s3) \
  103. return CheckAndReturnResult((hr), __FILE__, __LINE__, 3, (s1), (s2), (s3))
  104. #define WARN_ERROR(hr) CheckResult((hr), __FILE__, __LINE__)
  105. #define TRETURN(hr) return PrintHRESULT(DEB_TRACE, (hr))
  106. #define TRACEIID(iid) PrintIID(DEB_TRACE, iid)
  107. #define TRACEHRESULT(hr) PrintHRESULT(DEB_TRACE, (hr))
  108. #else // DBG == 0
  109. #define SRETURN(hr) return (hr)
  110. #define RRETURN(hr) return (hr)
  111. #define RRETURN1(hr, s1) return (hr)
  112. #define RRETURN2(hr, s1, s2) return (hr)
  113. #define RRETURN3(hr, s1, s2, s3) return (hr)
  114. #define WARN_ERROR(hr)
  115. #define TRETURN(hr) return (hr)
  116. #define TRACEIID(iid)
  117. #define TRACEHRESULT(hr)
  118. #endif // DBG
  119. //+---------------------------------------------------------------------
  120. //
  121. // Interface wrapper for tracing method invocations
  122. //
  123. //----------------------------------------------------------------------
  124. #if DBG == 1
  125. LPVOID WatchInterface(REFIID riid, LPVOID pv, LPWSTR lpstr);
  126. #define WATCHINTERFACE(iid, p, lpstr) WatchInterface(iid, p, lpstr)
  127. #else // DBG == 0
  128. #define WATCHINTERFACE(iid, p, lpstr) (p)
  129. #endif // DBG
  130. //+---------------------------------------------------------------------
  131. //
  132. // Standard IClassFactory implementation
  133. //
  134. //----------------------------------------------------------------------
  135. //
  136. // Functions to manipulate object count variable g_ulObjCount. This variable
  137. // is used in the implementation of DllCanUnloadNow.
  138. inline void
  139. INC_OBJECT_COUNT(void)
  140. {
  141. extern ULONG g_ulObjCount;
  142. IRIncrement(g_ulObjCount);
  143. }
  144. inline void
  145. DEC_OBJECT_COUNT(void)
  146. {
  147. extern ULONG g_ulObjCount;
  148. // ASSERT(g_ulObjCount > 0);
  149. IRDecrement(g_ulObjCount);
  150. }
  151. inline ULONG
  152. GET_OBJECT_COUNT(void)
  153. {
  154. extern ULONG g_ulObjCount;
  155. return g_ulObjCount;
  156. }
  157. //+---------------------------------------------------------------
  158. //
  159. // Class: CStaticClassFactory
  160. //
  161. // Purpose: Standard implementation of a class factory object
  162. //
  163. // Notes: **************!!!!!!!!!!!!!!!!!*************
  164. // TAKE NOTE --- The implementation of Release on this
  165. // class does not perform a delete. This is so you can
  166. // make the class factory a global static variable.
  167. // Use the CDynamicClassFactory class below for an object
  168. // which is not global static data.
  169. //
  170. //---------------------------------------------------------------
  171. class CStaticClassFactory: public IClassFactory
  172. {
  173. public:
  174. CStaticClassFactory(void) : _ulRefs(1) {};
  175. // IUnknown methods
  176. DECLARE_IR_IUNKNOWN_METHODS;
  177. // IClassFactory methods
  178. STDMETHOD(LockServer) (BOOL fLock);
  179. // CreateInstance is left pure virtual.
  180. protected:
  181. ULONG _ulRefs;
  182. };
  183. //+---------------------------------------------------------------------------
  184. //
  185. // Class: CDynamicClassFactory (DYNCF)
  186. //
  187. // Purpose: Class factory which exists on the heap, and whose Release
  188. // method does the normal thing.
  189. //
  190. // Interface: DECLARE_IR_STANDARD_IUNKNOWN -- IUnknown methods
  191. //
  192. // LockServer -- Per IClassFactory.
  193. // CDynamicClassFactory -- ctor.
  194. // ~CDynamicClassFactory -- dtor.
  195. //
  196. //----------------------------------------------------------------------------
  197. class CDynamicClassFactory: public IClassFactory
  198. {
  199. public:
  200. // IUnknown methods
  201. DECLARE_IR_STANDARD_IUNKNOWN(CDynamicClassFactory)
  202. // IClassFactory methods
  203. STDMETHOD(LockServer) (BOOL fLock);
  204. // CreateInstance is left pure virtual.
  205. protected:
  206. CDynamicClassFactory(void);
  207. virtual ~CDynamicClassFactory(void);
  208. };
  209. #endif //__IROLEUTL_HXX_