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.

393 lines
9.0 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // PreCreateServices.h
  7. //
  8. // Description:
  9. // PreCreateServices implementation.
  10. //
  11. // Maintained By:
  12. // David Potter (DavidP) 14-JUN-2001
  13. // Geoffrey Pease (GPease) 15-JUN-2000
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16. #include "Pch.h"
  17. #include "GroupHandle.h"
  18. #include "ResourceEntry.h"
  19. #include "IPrivatePostCfgResource.h"
  20. #include "PreCreateServices.h"
  21. DEFINE_THISCLASS("CPreCreateServices")
  22. #define DEPENDENCY_INCREMENT 5
  23. // ************************************************************************
  24. //
  25. // Constructor / Destructor
  26. //
  27. // ************************************************************************
  28. //////////////////////////////////////////////////////////////////////////////
  29. //
  30. // HRESULT
  31. // CPreCreateServices::S_HrCreateInstance(
  32. // IUnknown ** ppunkOut
  33. // )
  34. //
  35. //////////////////////////////////////////////////////////////////////////////
  36. HRESULT
  37. CPreCreateServices::S_HrCreateInstance(
  38. IUnknown ** ppunkOut
  39. )
  40. {
  41. TraceFunc( "" );
  42. HRESULT hr = S_OK;
  43. CPreCreateServices * ppcs = NULL;
  44. Assert( ppunkOut != NULL );
  45. if ( ppunkOut == NULL )
  46. {
  47. hr = THR( E_POINTER );
  48. goto Cleanup;
  49. }
  50. ppcs = new CPreCreateServices;
  51. if ( ppcs == NULL )
  52. {
  53. hr = THR( E_OUTOFMEMORY );
  54. goto Cleanup;
  55. }
  56. hr = THR( ppcs->HrInit() );
  57. if ( FAILED( hr ) )
  58. {
  59. goto Cleanup;
  60. }
  61. hr = THR( ppcs->TypeSafeQI( IUnknown, ppunkOut ) );
  62. if ( FAILED( hr ) )
  63. {
  64. goto Cleanup;
  65. }
  66. Cleanup:
  67. if ( ppcs != NULL )
  68. {
  69. ppcs->Release();
  70. }
  71. HRETURN( hr );
  72. } //*** CPreCreateServices::S_HrCreateInstance
  73. //////////////////////////////////////////////////////////////////////////////
  74. //
  75. // CPreCreateServices::CPreCreateServices
  76. //
  77. //////////////////////////////////////////////////////////////////////////////
  78. CPreCreateServices::CPreCreateServices( void )
  79. : m_cRef( 1 )
  80. {
  81. TraceFunc( "" );
  82. InterlockedIncrement( &g_cObjects );
  83. TraceFuncExit();
  84. } //*** CPreCreateServices::CPreCreateServices
  85. //////////////////////////////////////////////////////////////////////////////
  86. //
  87. // HRESULT
  88. // CPreCreateServices::HrInit
  89. //
  90. //////////////////////////////////////////////////////////////////////////////
  91. HRESULT
  92. CPreCreateServices::HrInit( void )
  93. {
  94. TraceFunc( "" );
  95. HRESULT hr = S_OK;
  96. // IUnknown stuff
  97. Assert( m_cRef == 1 );
  98. // Resource
  99. Assert( m_presentry == NULL );
  100. HRETURN( hr );
  101. } //*** CPreCreateServices::HrInit
  102. //////////////////////////////////////////////////////////////////////////////
  103. //
  104. // CPreCreateServices::~CPreCreateServices
  105. //
  106. //////////////////////////////////////////////////////////////////////////////
  107. CPreCreateServices::~CPreCreateServices( void )
  108. {
  109. TraceFunc( "" );
  110. InterlockedDecrement( &g_cObjects );
  111. TraceFuncExit();
  112. } //*** CPreCreateServices::~CPreCreateServices
  113. // ************************************************************************
  114. //
  115. // IUnknown
  116. //
  117. // ************************************************************************
  118. //////////////////////////////////////////////////////////////////////////////
  119. //++
  120. //
  121. // CPreCreateServices::QueryInterface
  122. //
  123. // Description:
  124. // Query this object for the passed in interface.
  125. //
  126. // Arguments:
  127. // riidIn
  128. // Id of interface requested.
  129. //
  130. // ppvOut
  131. // Pointer to the requested interface.
  132. //
  133. // Return Value:
  134. // S_OK
  135. // If the interface is available on this object.
  136. //
  137. // E_NOINTERFACE
  138. // If the interface is not available.
  139. //
  140. // E_POINTER
  141. // ppvOut was NULL.
  142. //
  143. // Remarks:
  144. // None.
  145. //
  146. //--
  147. //////////////////////////////////////////////////////////////////////////////
  148. STDMETHODIMP
  149. CPreCreateServices::QueryInterface(
  150. REFIID riidIn
  151. , LPVOID * ppvOut
  152. )
  153. {
  154. TraceQIFunc( riidIn, ppvOut );
  155. HRESULT hr = S_OK;
  156. //
  157. // Validate arguments.
  158. //
  159. Assert( ppvOut != NULL );
  160. if ( ppvOut == NULL )
  161. {
  162. hr = THR( E_POINTER );
  163. goto Cleanup;
  164. }
  165. //
  166. // Handle known interfaces.
  167. //
  168. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  169. {
  170. *ppvOut = static_cast< IClusCfgResourcePreCreate * >( this );
  171. } // if: IUnknown
  172. else if ( IsEqualIID( riidIn, IID_IClusCfgResourcePreCreate ) )
  173. {
  174. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgResourcePreCreate, this, 0 );
  175. } // else if: IClusCfgResourcePreCreate
  176. else if ( IsEqualIID( riidIn, IID_IPrivatePostCfgResource ) )
  177. {
  178. *ppvOut = TraceInterface( __THISCLASS__, IPrivatePostCfgResource, this, 0 );
  179. } // else if: IPrivatePostCfgResource
  180. else
  181. {
  182. *ppvOut = NULL;
  183. hr = E_NOINTERFACE;
  184. }
  185. //
  186. // Add a reference to the interface if successful.
  187. //
  188. if ( SUCCEEDED( hr ) )
  189. {
  190. ((IUnknown *) *ppvOut)->AddRef();
  191. } // if: success
  192. Cleanup:
  193. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  194. } //*** CPreCreateServices::QueryInterface
  195. //////////////////////////////////////////////////////////////////////////////
  196. //
  197. // STDMETHODIMP_(ULONG)
  198. // CPreCreateServices::AddRef
  199. //
  200. //////////////////////////////////////////////////////////////////////////////
  201. STDMETHODIMP_( ULONG )
  202. CPreCreateServices::AddRef( void )
  203. {
  204. TraceFunc( "[IUnknown]" );
  205. InterlockedIncrement( &m_cRef );
  206. CRETURN( m_cRef );
  207. } //*** CPreCreateServices::AddRef
  208. //////////////////////////////////////////////////////////////////////////////
  209. //
  210. // STDMETHODIMP_(ULONG)
  211. // CPreCreateServices::Release
  212. //
  213. //////////////////////////////////////////////////////////////////////////////
  214. STDMETHODIMP_( ULONG )
  215. CPreCreateServices::Release( void )
  216. {
  217. TraceFunc( "[IUnknown]" );
  218. LONG cRef;
  219. cRef = InterlockedDecrement( &m_cRef );
  220. if ( cRef == 0 )
  221. {
  222. TraceDo( delete this );
  223. }
  224. CRETURN( cRef );
  225. } //*** CPreCreateServices::Release
  226. //****************************************************************************
  227. //
  228. // IClusCfgResourcePreCreate
  229. //
  230. //****************************************************************************
  231. //////////////////////////////////////////////////////////////////////////////
  232. //
  233. // STDMETHODIMP
  234. // CPreCreateServices::SetType(
  235. // CLSID * pclsidIn
  236. // )
  237. //
  238. //////////////////////////////////////////////////////////////////////////////
  239. STDMETHODIMP
  240. CPreCreateServices::SetType(
  241. CLSID * pclsidIn
  242. )
  243. {
  244. TraceFunc( "[IClusCfgResourcePreCreate]" );
  245. HRESULT hr;
  246. Assert( m_presentry != NULL );
  247. hr = THR( m_presentry->SetType( pclsidIn ) );
  248. HRETURN( hr );
  249. } //*** CPreCreateServices::SetType
  250. //////////////////////////////////////////////////////////////////////////////
  251. //
  252. // STDMETHODIMP
  253. // CPreCreateServices::SetClassType(
  254. // CLSID * pclsidIn
  255. // )
  256. //
  257. //////////////////////////////////////////////////////////////////////////////
  258. STDMETHODIMP
  259. CPreCreateServices::SetClassType(
  260. CLSID * pclsidIn
  261. )
  262. {
  263. TraceFunc( "[IClusCfgResourcePreCreate]" );
  264. HRESULT hr;
  265. Assert( m_presentry != NULL );
  266. hr = THR( m_presentry->SetClassType( pclsidIn ) );
  267. HRETURN( hr );
  268. } //*** CPreCreateServices::SetClassType
  269. //////////////////////////////////////////////////////////////////////////////
  270. //
  271. // STDMETHODIMP
  272. // CPreCreateServices::SetDependency(
  273. // LPCLSID pclsidDepResTypeIn,
  274. // DWORD dfIn
  275. // )
  276. //
  277. //////////////////////////////////////////////////////////////////////////////
  278. STDMETHODIMP
  279. CPreCreateServices::SetDependency(
  280. LPCLSID pclsidDepResTypeIn,
  281. DWORD dfIn
  282. )
  283. {
  284. TraceFunc( "[IClusCfgResourcePreCreate]" );
  285. HRESULT hr;
  286. Assert( m_presentry != NULL );
  287. hr = THR( m_presentry->AddTypeDependency( pclsidDepResTypeIn, (EDependencyFlags) dfIn ) );
  288. HRETURN( hr );
  289. } //*** CPreCreateServices::SetDependency
  290. //****************************************************************************
  291. //
  292. // IPrivatePostCfgResource
  293. //
  294. //****************************************************************************
  295. //////////////////////////////////////////////////////////////////////////////
  296. //
  297. // STDMETHODIMP
  298. // CPreCreateServices::SetEntry(
  299. // CResourceEntry * presentryIn
  300. // )
  301. //
  302. //////////////////////////////////////////////////////////////////////////////
  303. STDMETHODIMP
  304. CPreCreateServices::SetEntry(
  305. CResourceEntry * presentryIn
  306. )
  307. {
  308. TraceFunc( "[IPrivatePostCfgResource]" );
  309. HRESULT hr = S_OK;
  310. m_presentry = presentryIn;
  311. HRETURN( hr );
  312. } //*** CPreCreateServices::SetEntry