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.

184 lines
6.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1997.
  5. //
  6. // File: stdcf.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. #pragma once
  22. //---------------------------------------------------------------
  23. // IUnknown
  24. //---------------------------------------------------------------
  25. #define IXIncrement(__ul) InterlockedIncrement((long *) &__ul)
  26. #define IXDecrement(__ul) InterlockedDecrement((long *) &__ul)
  27. #define DECLARE_IR_IUNKNOWN_METHODS \
  28. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv); \
  29. STDMETHOD_(ULONG, AddRef) (void); \
  30. STDMETHOD_(ULONG, Release) (void);
  31. #define DECLARE_IR_APTTHREAD_IUNKNOWN \
  32. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv); \
  33. ULONG _ulRefs; \
  34. STDMETHOD_(ULONG, AddRef) (void) \
  35. { \
  36. return ++_ulRefs; \
  37. } \
  38. STDMETHOD_(ULONG, Release) (void) \
  39. { \
  40. if (!--_ulRefs) \
  41. { \
  42. delete this; \
  43. return 0; \
  44. } \
  45. return _ulRefs; \
  46. }
  47. #define DECLARE_IR_STANDARD_IUNKNOWN(cls) \
  48. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv); \
  49. ULONG _ulRefs; \
  50. STDMETHOD_(ULONG, AddRef) (void) \
  51. { \
  52. IXIncrement(_ulRefs); \
  53. return _ulRefs; \
  54. } \
  55. STDMETHOD_(ULONG, Release) (void) \
  56. { \
  57. if (!IXDecrement(_ulRefs)) \
  58. { \
  59. IXIncrement(_ulRefs); \
  60. delete this; \
  61. return 0; \
  62. } \
  63. return _ulRefs; \
  64. }
  65. //+---------------------------------------------------------------------
  66. //
  67. // Miscellaneous useful OLE helper and debugging functions
  68. //
  69. //----------------------------------------------------------------------
  70. //+---------------------------------------------------------------------
  71. //
  72. // Standard IClassFactory implementation
  73. //
  74. //----------------------------------------------------------------------
  75. //
  76. // Functions to manipulate object count variable g_ulObjCount. This variable
  77. // is used in the implementation of DllCanUnloadNow.
  78. inline void
  79. INC_OBJECT_COUNT(void)
  80. {
  81. extern ULONG g_ulObjCount;
  82. IXIncrement(g_ulObjCount);
  83. }
  84. inline void
  85. DEC_OBJECT_COUNT(void)
  86. {
  87. extern ULONG g_ulObjCount;
  88. Win4Assert(g_ulObjCount > 0);
  89. IXDecrement(g_ulObjCount);
  90. }
  91. inline ULONG
  92. GET_OBJECT_COUNT(void)
  93. {
  94. extern ULONG g_ulObjCount;
  95. return g_ulObjCount;
  96. }
  97. //+---------------------------------------------------------------
  98. //
  99. // Class: CStaticClassFactory
  100. //
  101. // Purpose: Standard implementation of a class factory object
  102. //
  103. // Notes: **************!!!!!!!!!!!!!!!!!*************
  104. // TAKE NOTE --- The implementation of Release on this
  105. // class does not perform a delete. This is so you can
  106. // make the class factory a global static variable.
  107. // Use the CDynamicClassFactory class below for an object
  108. // which is not global static data.
  109. //
  110. //---------------------------------------------------------------
  111. class CStaticClassFactory: public IClassFactory
  112. {
  113. public:
  114. CStaticClassFactory(void) : _ulRefs(1) {};
  115. // IUnknown methods
  116. DECLARE_IR_IUNKNOWN_METHODS;
  117. // IClassFactory methods
  118. STDMETHOD(LockServer) (BOOL fLock);
  119. // CreateInstance is left pure virtual.
  120. protected:
  121. ULONG _ulRefs;
  122. };
  123. //+---------------------------------------------------------------------------
  124. //
  125. // Class: CDynamicClassFactory (DYNCF)
  126. //
  127. // Purpose: Class factory which exists on the heap, and whose Release
  128. // method does the normal thing.
  129. //
  130. // Interface: DECLARE_IR_STANDARD_IUNKNOWN -- IUnknown methods
  131. //
  132. // LockServer -- Per IClassFactory.
  133. // CDynamicClassFactory -- ctor.
  134. // ~CDynamicClassFactory -- dtor.
  135. //
  136. //----------------------------------------------------------------------------
  137. class CDynamicClassFactory: public IClassFactory
  138. {
  139. public:
  140. // IUnknown methods
  141. DECLARE_IR_STANDARD_IUNKNOWN(CDynamicClassFactory)
  142. // IClassFactory methods
  143. STDMETHOD(LockServer) (BOOL fLock);
  144. // CreateInstance is left pure virtual.
  145. protected:
  146. CDynamicClassFactory(void);
  147. virtual ~CDynamicClassFactory(void);
  148. };