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.

125 lines
4.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. //
  14. // Functions:
  15. //
  16. // Macros:
  17. //
  18. // History: 26-Feb-96 SSanu adapted from Forms stuff
  19. //----------------------------------------------------------------------------
  20. #pragma once
  21. //---------------------------------------------------------------
  22. // IUnknown
  23. //---------------------------------------------------------------
  24. #define IXIncrement(__ul) InterlockedIncrement((long *) &__ul)
  25. #define IXDecrement(__ul) InterlockedDecrement((long *) &__ul)
  26. #define DECLARE_IR_IUNKNOWN_METHODS \
  27. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv); \
  28. STDMETHOD_(ULONG, AddRef) (void); \
  29. STDMETHOD_(ULONG, Release) (void);
  30. #define DECLARE_IR_APTTHREAD_IUNKNOWN \
  31. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv); \
  32. ULONG _ulRefs; \
  33. STDMETHOD_(ULONG, AddRef) (void) \
  34. { \
  35. return ++_ulRefs; \
  36. } \
  37. STDMETHOD_(ULONG, Release) (void) \
  38. { \
  39. if (!--_ulRefs) \
  40. { \
  41. delete this; \
  42. return 0; \
  43. } \
  44. return _ulRefs; \
  45. }
  46. //+---------------------------------------------------------------------
  47. //
  48. // Miscellaneous useful OLE helper and debugging functions
  49. //
  50. //----------------------------------------------------------------------
  51. //+---------------------------------------------------------------------
  52. //
  53. // Standard IClassFactory implementation
  54. //
  55. //----------------------------------------------------------------------
  56. //
  57. // Functions to manipulate object count variable g_ulObjCount. This variable
  58. // is used in the implementation of DllCanUnloadNow.
  59. inline void
  60. INC_OBJECT_COUNT(void)
  61. {
  62. extern ULONG g_ulObjCount;
  63. IXIncrement(g_ulObjCount);
  64. }
  65. inline void
  66. DEC_OBJECT_COUNT(void)
  67. {
  68. extern ULONG g_ulObjCount;
  69. Win4Assert(g_ulObjCount > 0);
  70. IXDecrement(g_ulObjCount);
  71. }
  72. inline ULONG
  73. GET_OBJECT_COUNT(void)
  74. {
  75. extern ULONG g_ulObjCount;
  76. return g_ulObjCount;
  77. }
  78. //+---------------------------------------------------------------
  79. //
  80. // Class: CStaticClassFactory
  81. //
  82. // Purpose: Standard implementation of a class factory object
  83. //
  84. // Notes: **************!!!!!!!!!!!!!!!!!*************
  85. // TAKE NOTE --- The implementation of Release on this
  86. // class does not perform a delete. This is so you can
  87. // make the class factory a global static variable.
  88. // Use the CDynamicClassFactory class below for an object
  89. // which is not global static data.
  90. //
  91. //---------------------------------------------------------------
  92. class CStaticClassFactory: public IClassFactory
  93. {
  94. public:
  95. CStaticClassFactory(void) : _ulRefs(1) {};
  96. // IUnknown methods
  97. DECLARE_IR_IUNKNOWN_METHODS;
  98. // IClassFactory methods
  99. STDMETHOD(LockServer) (BOOL fLock);
  100. // CreateInstance is left pure virtual.
  101. protected:
  102. ULONG _ulRefs;
  103. };