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.

248 lines
5.6 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. if (ppvOut == NULL)
  51. {
  52. return E_INVALIDARG;
  53. }
  54. *ppvOut = NULL;
  55. if ( IID_IUnknown == riidIn || IID_IClassFactory == riidIn )
  56. {
  57. *ppvOut = this;
  58. }
  59. if ( NULL != *ppvOut )
  60. {
  61. ( (LPUNKNOWN) *ppvOut )->AddRef( );
  62. return NOERROR;
  63. }
  64. return E_NOINTERFACE;
  65. } //*** CProvFactory::QueryInterface()
  66. //////////////////////////////////////////////////////////////////////////////
  67. //++
  68. //
  69. // STDMETHODIMP_( ULONG )
  70. // CProvFactory::AddRef ( void )
  71. //
  72. // Description:
  73. // Increment the reference count on the COM object.
  74. //
  75. // Arguments:
  76. // None.
  77. //
  78. // Return Values:
  79. // New count of references.
  80. //
  81. //--
  82. //////////////////////////////////////////////////////////////////////////////
  83. STDMETHODIMP_( ULONG )
  84. CProvFactory::AddRef ( void )
  85. {
  86. //return ++m_cRef;
  87. return InterlockedIncrement( (long *) &m_cRef );
  88. } //*** CProvFactory::AddRef()
  89. //////////////////////////////////////////////////////////////////////////////
  90. //++
  91. //
  92. // STDMETHODIMP_( ULONG )
  93. // CProvFactory::Release( void )
  94. //
  95. // Description:
  96. // Decrement the reference count on the COM object.
  97. //
  98. // Arguments:
  99. // None.
  100. //
  101. // Return Values:
  102. // New count of references.
  103. //
  104. //--
  105. //////////////////////////////////////////////////////////////////////////////
  106. STDMETHODIMP_( ULONG )
  107. CProvFactory::Release( void )
  108. {
  109. ULONG nNewCount = InterlockedDecrement( (long *) & m_cRef );
  110. if ( 0L == nNewCount )
  111. {
  112. delete this;
  113. } // if: 0L == nNewCount
  114. return nNewCount;
  115. } //*** CProvFactory::Release()
  116. //////////////////////////////////////////////////////////////////////////////
  117. //++
  118. //
  119. // STDMETHODIMP
  120. // CProvFactory::CreateInstance(
  121. // LPUNKNOWN pUnkOuterIn,
  122. // REFIID riidIn,
  123. // PPVOID ppvObjOut
  124. // )
  125. //
  126. // Description:
  127. // Instantiates a Locator object returning an interface pointer.
  128. //
  129. // Arguments:
  130. // pUnkOuterIn
  131. // LPUNKNOWN to the controlling IUnknown if we are being used in
  132. // an aggregation.
  133. //
  134. // riidIn
  135. // REFIID identifying the interface the caller desires to have
  136. // for the new object.
  137. //
  138. // ppvObjOut
  139. // PPVOID in which to store the desired interface pointer for the
  140. // new object.
  141. //
  142. // Return Values:
  143. // NOERROR
  144. // E_OUTOFMEMORY
  145. // E_NOINTERFACE
  146. // CLASS_E_NOAGGREGATION
  147. //
  148. //--
  149. //////////////////////////////////////////////////////////////////////////////
  150. STDMETHODIMP
  151. CProvFactory::CreateInstance(
  152. LPUNKNOWN pUnkOuterIn,
  153. REFIID riidIn,
  154. PPVOID ppvObjOut
  155. )
  156. {
  157. IUnknown * pObj = NULL;
  158. HRESULT hr;
  159. _ASSERTE(ppvObjOut != NULL);
  160. _ASSERTE(m_pFactoryData != NULL);
  161. *ppvObjOut = NULL;
  162. // This object doesnt support aggregation.
  163. if ( NULL != pUnkOuterIn )
  164. {
  165. return CLASS_E_NOAGGREGATION;
  166. } /// if: not pUnkOuter
  167. hr = m_pFactoryData->pFnCreateInstance(
  168. NULL,
  169. reinterpret_cast< VOID ** >( &pObj )
  170. );
  171. if ( NULL == pObj )
  172. {
  173. return E_OUTOFMEMORY;
  174. } // if: pObj is NULL
  175. hr = pObj->QueryInterface( riidIn, ppvObjOut );
  176. //Kill the object if initial creation or Init failed.
  177. if ( FAILED( hr ) )
  178. {
  179. delete pObj;
  180. } // if: failed
  181. return hr;
  182. } //*** CProvFactory::CreateInstance()
  183. //////////////////////////////////////////////////////////////////////////////
  184. //++
  185. //
  186. // STDMETHODIMP
  187. // CProvFactory::LockServer(
  188. // BOOL fLockIn
  189. // )
  190. //
  191. // Description:
  192. // Increments or decrements the lock count of the DLL. If the lock
  193. // count goes to zero and there are no objects, the DLL is allowed to
  194. // unload. See DllCanUnloadNow.
  195. //
  196. // Arguments:
  197. // fLockIn
  198. // BOOL specifying whether to increment or decrement the lock count.
  199. //
  200. // Return Values:
  201. // NOERROR
  202. //
  203. //--
  204. //////////////////////////////////////////////////////////////////////////////
  205. STDMETHODIMP
  206. CProvFactory::LockServer(
  207. BOOL fLockIn
  208. )
  209. {
  210. if ( fLockIn )
  211. {
  212. InterlockedIncrement( & g_cLock );
  213. } /// if: lock
  214. else
  215. {
  216. InterlockedDecrement( & g_cLock );
  217. } /// else:
  218. return NOERROR;
  219. } //*** CProvFactory::LockServer()