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.

208 lines
4.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: Clsfact.cpp
  7. //
  8. // Contents: Class Factory
  9. //
  10. // Classes: CClassFactory
  11. //
  12. // Notes:
  13. //
  14. // History: 05-Nov-97 rogerg Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #include "precomp.h"
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Member: CClassFactory::CClassFactory, public
  21. //
  22. // Synopsis: Constructor
  23. //
  24. // Arguments:
  25. //
  26. // Returns:
  27. //
  28. // Modifies:
  29. //
  30. // History: 05-Nov-97 rogerg Created.
  31. //
  32. //----------------------------------------------------------------------------
  33. CClassFactory::CClassFactory()
  34. {
  35. m_cRef = 1;
  36. return;
  37. }
  38. //+---------------------------------------------------------------------------
  39. //
  40. // Member: CClassFactory::~CClassFactory, public
  41. //
  42. // Synopsis: Destructor
  43. //
  44. // Arguments:
  45. //
  46. // Returns:
  47. //
  48. // Modifies:
  49. //
  50. // History: 05-Nov-97 rogerg Created.
  51. //
  52. //----------------------------------------------------------------------------
  53. CClassFactory::~CClassFactory( void )
  54. {
  55. Assert(0 == m_cRef);
  56. return;
  57. }
  58. //+---------------------------------------------------------------------------
  59. //
  60. // Member: CClassFactory::QueryInterface, public
  61. //
  62. // Synopsis: Standard QueryInterface
  63. //
  64. // Arguments: [iid] - Interface ID
  65. // [ppvObj] - Object return
  66. //
  67. // Returns: Appropriate status code
  68. //
  69. // Modifies: [ppvObj]
  70. //
  71. // History: 05-Nov-97 rogerg Created.
  72. //
  73. //----------------------------------------------------------------------------
  74. STDMETHODIMP CClassFactory::QueryInterface( REFIID riid, LPVOID* ppv )
  75. {
  76. *ppv = NULL;
  77. if( IsEqualIID( riid, IID_IUnknown ) || IsEqualIID( riid, IID_IClassFactory ) )
  78. {
  79. *ppv = (LPVOID)this;
  80. AddRef();
  81. return S_OK;
  82. }
  83. return E_NOINTERFACE;
  84. }
  85. //+---------------------------------------------------------------------------
  86. //
  87. // Member: CClassFactory::AddRef, public
  88. //
  89. // Synopsis: Add reference
  90. //
  91. // History: 05-Nov-97 rogerg Created.
  92. //
  93. //----------------------------------------------------------------------------
  94. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  95. {
  96. ULONG cRefs;
  97. cRefs = InterlockedIncrement((LONG *)& m_cRef);
  98. return cRefs;
  99. }
  100. //+---------------------------------------------------------------------------
  101. //
  102. // Member: CClasFactory::Release, public
  103. //
  104. // Synopsis: Release reference
  105. //
  106. // History: 05-Nov-97 rogerg Created.
  107. //
  108. //----------------------------------------------------------------------------
  109. STDMETHODIMP_(ULONG) CClassFactory::Release()
  110. {
  111. ULONG cRefs;
  112. cRefs = InterlockedDecrement( (LONG *) &m_cRef);
  113. if (0 == cRefs)
  114. {
  115. delete this;
  116. }
  117. return cRefs;
  118. }
  119. //+---------------------------------------------------------------------------
  120. //
  121. // Member: CClassFactory::CreateInstance, public
  122. //
  123. // Synopsis: Creates and instance of the requested object
  124. //
  125. // Arguments: [pUnkOuter] - Controlling unknown
  126. // [riid] - Requested interface
  127. // [ppvObj] - object pointer
  128. //
  129. // Returns: Appropriate status code
  130. //
  131. // Modifies:
  132. //
  133. // History: 05-Nov-97 rogerg Created.
  134. //
  135. //----------------------------------------------------------------------------
  136. STDMETHODIMP CClassFactory::CreateInstance( LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR *ppvObj )
  137. {
  138. HRESULT hr = E_OUTOFMEMORY;
  139. CSynchronizeInvoke *pNewSynchronizeInstance;
  140. *ppvObj = NULL;
  141. // We don't support aggregation at all.
  142. if( pUnkOuter )
  143. {
  144. return CLASS_E_NOAGGREGATION;
  145. }
  146. //Create the object, passing function to notify on destruction
  147. pNewSynchronizeInstance = new CSynchronizeInvoke(); // initialized RefCount to 1.
  148. if( NULL == pNewSynchronizeInstance )
  149. {
  150. return hr;
  151. }
  152. hr = pNewSynchronizeInstance->QueryInterface( riid, ppvObj );
  153. pNewSynchronizeInstance->Release(); // release our copy of the object
  154. return hr;
  155. }
  156. //+---------------------------------------------------------------------------
  157. //
  158. // Member: CClassFactory::LockServer, public
  159. //
  160. // Synopsis: Locks the Server
  161. //
  162. // Arguments: [fLock] - To Lock or Unlock
  163. //
  164. // Returns: Appropriate status code
  165. //
  166. // Modifies:
  167. //
  168. // History: 05-Nov-97 rogerg Created.
  169. //
  170. //----------------------------------------------------------------------------
  171. STDMETHODIMP CClassFactory::LockServer( BOOL fLock )
  172. {
  173. if( fLock )
  174. {
  175. AddRefOneStopLifetime(TRUE /*External*/);
  176. }
  177. else
  178. {
  179. ReleaseOneStopLifetime(TRUE /*External*/);
  180. }
  181. return S_OK;
  182. }