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.

240 lines
5.5 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // CopyRight (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ProvFactory.cpp
  7. //
  8. // Description:
  9. // Implementation of CProvFactory class.
  10. //
  11. // Author:
  12. // Henry Wang (HenryWa) 24-AUG-1999
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "ProvFactory.h"
  17. //****************************************************************************
  18. //
  19. // CProvFactory
  20. //
  21. //****************************************************************************
  22. //////////////////////////////////////////////////////////////////////////////
  23. //++
  24. //
  25. // STDMETHODIMP
  26. // CProvFactory::QueryInterface(
  27. // REFIID riidIn,
  28. // PPVOID ppvOut
  29. // )
  30. //
  31. // Description:
  32. // Query for an interface supported by this COM object.
  33. //
  34. // Arguments:
  35. // riidIn -- Interface ID.
  36. // ppvOut -- Receives the interface pointer.
  37. //
  38. // Return Values:
  39. // NOERROR
  40. // E_NOINTERFACE
  41. //
  42. //--
  43. //////////////////////////////////////////////////////////////////////////////
  44. STDMETHODIMP
  45. CProvFactory::QueryInterface(
  46. REFIID riidIn,
  47. PPVOID ppvOut
  48. )
  49. {
  50. *ppvOut = NULL;
  51. if ( IID_IUnknown == riidIn || IID_IClassFactory == riidIn )
  52. {
  53. *ppvOut = this;
  54. }
  55. if ( NULL != *ppvOut )
  56. {
  57. ( (LPUNKNOWN) *ppvOut )->AddRef( );
  58. return NOERROR;
  59. }
  60. return E_NOINTERFACE;
  61. } //*** CProvFactory::QueryInterface()
  62. //////////////////////////////////////////////////////////////////////////////
  63. //++
  64. //
  65. // STDMETHODIMP_( ULONG )
  66. // CProvFactory::AddRef ( void )
  67. //
  68. // Description:
  69. // Increment the reference count on the COM object.
  70. //
  71. // Arguments:
  72. // None.
  73. //
  74. // Return Values:
  75. // New count of references.
  76. //
  77. //--
  78. //////////////////////////////////////////////////////////////////////////////
  79. STDMETHODIMP_( ULONG )
  80. CProvFactory::AddRef ( void )
  81. {
  82. //return ++m_cRef;
  83. return InterlockedIncrement( (long *) &m_cRef );
  84. } //*** CProvFactory::AddRef()
  85. //////////////////////////////////////////////////////////////////////////////
  86. //++
  87. //
  88. // STDMETHODIMP_( ULONG )
  89. // CProvFactory::Release( void )
  90. //
  91. // Description:
  92. // Decrement the reference count on the COM object.
  93. //
  94. // Arguments:
  95. // None.
  96. //
  97. // Return Values:
  98. // New count of references.
  99. //
  100. //--
  101. //////////////////////////////////////////////////////////////////////////////
  102. STDMETHODIMP_( ULONG )
  103. CProvFactory::Release( void )
  104. {
  105. ULONG nNewCount = InterlockedDecrement( (long *) & m_cRef );
  106. if ( 0L == nNewCount )
  107. {
  108. delete this;
  109. } // if: 0L == nNewCount
  110. return nNewCount;
  111. } //*** CProvFactory::Release()
  112. //////////////////////////////////////////////////////////////////////////////
  113. //++
  114. //
  115. // STDMETHODIMP
  116. // CProvFactory::CreateInstance(
  117. // LPUNKNOWN pUnkOuterIn,
  118. // REFIID riidIn,
  119. // PPVOID ppvObjOut
  120. // )
  121. //
  122. // Description:
  123. // Instantiates a Locator object returning an interface pointer.
  124. //
  125. // Arguments:
  126. // pUnkOuterIn
  127. // LPUNKNOWN to the controlling IUnknown if we are being used in
  128. // an aggregation.
  129. //
  130. // riidIn
  131. // REFIID identifying the interface the caller desires to have
  132. // for the new object.
  133. //
  134. // ppvObjOut
  135. // PPVOID in which to store the desired interface pointer for the
  136. // new object.
  137. //
  138. // Return Values:
  139. // NOERROR
  140. // E_OUTOFMEMORY
  141. // E_NOINTERFACE
  142. // CLASS_E_NOAGGREGATION
  143. //
  144. //--
  145. //////////////////////////////////////////////////////////////////////////////
  146. STDMETHODIMP
  147. CProvFactory::CreateInstance(
  148. LPUNKNOWN pUnkOuterIn,
  149. REFIID riidIn,
  150. PPVOID ppvObjOut
  151. )
  152. {
  153. IUnknown * pObj = NULL;
  154. HRESULT hr;
  155. *ppvObjOut = NULL;
  156. // This object doesnt support aggregation.
  157. if ( NULL != pUnkOuterIn )
  158. {
  159. return CLASS_E_NOAGGREGATION;
  160. } /// if: not pUnkOuter
  161. hr = m_pFactoryData->pFnCreateInstance(
  162. NULL,
  163. reinterpret_cast< VOID ** >( &pObj )
  164. );
  165. if ( NULL == pObj )
  166. {
  167. return E_OUTOFMEMORY;
  168. } // if: pObj is NULL
  169. hr = pObj->QueryInterface( riidIn, ppvObjOut );
  170. //Kill the object if initial creation or Init failed.
  171. if ( FAILED( hr ) )
  172. {
  173. delete pObj;
  174. } // if: failed
  175. return hr;
  176. } //*** CProvFactory::CreateInstance()
  177. //////////////////////////////////////////////////////////////////////////////
  178. //++
  179. //
  180. // STDMETHODIMP
  181. // CProvFactory::LockServer(
  182. // BOOL fLockIn
  183. // )
  184. //
  185. // Description:
  186. // Increments or decrements the lock count of the DLL. If the lock
  187. // count goes to zero and there are no objects, the DLL is allowed to
  188. // unload. See DllCanUnloadNow.
  189. //
  190. // Arguments:
  191. // fLockIn
  192. // BOOL specifying whether to increment or decrement the lock count.
  193. //
  194. // Return Values:
  195. // NOERROR
  196. //
  197. //--
  198. //////////////////////////////////////////////////////////////////////////////
  199. STDMETHODIMP
  200. CProvFactory::LockServer(
  201. BOOL fLockIn
  202. )
  203. {
  204. if ( fLockIn )
  205. {
  206. InterlockedIncrement( & g_cLock );
  207. } /// if: lock
  208. else
  209. {
  210. InterlockedDecrement( & g_cLock );
  211. } /// else:
  212. return NOERROR;
  213. } //*** CProvFactory::LockServer()