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.

557 lines
11 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // StandardInfo.cpp
  7. //
  8. // Description:
  9. // CStandardInfo implementation.
  10. //
  11. // Maintained By:
  12. // Galen Barbee (GalenB) 02-FEB-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "StandardInfo.h"
  17. DEFINE_THISCLASS("CStandardInfo")
  18. // ************************************************************************
  19. //
  20. // Constructor / Destructor
  21. //
  22. // ************************************************************************
  23. //////////////////////////////////////////////////////////////////////////////
  24. //++
  25. //
  26. // HRESULT
  27. // CStandardInfo::S_HrCreateInstance(
  28. // IUnknown ** ppunkOut
  29. // )
  30. //
  31. //--
  32. //////////////////////////////////////////////////////////////////////////////
  33. HRESULT
  34. CStandardInfo::S_HrCreateInstance(
  35. IUnknown ** ppunkOut
  36. )
  37. {
  38. TraceFunc( "" );
  39. HRESULT hr = S_OK;
  40. CStandardInfo * psi = NULL;
  41. Assert( ppunkOut != NULL );
  42. if ( ppunkOut == NULL )
  43. {
  44. hr = THR( E_POINTER );
  45. goto Cleanup;
  46. }
  47. psi = new CStandardInfo;
  48. if ( psi == NULL )
  49. {
  50. hr = THR( E_OUTOFMEMORY );
  51. goto Cleanup;
  52. }
  53. hr = THR( psi->HrInit() );
  54. if ( FAILED( hr ) )
  55. {
  56. goto Cleanup;
  57. }
  58. hr = THR( psi->TypeSafeQI( IUnknown, ppunkOut ) );
  59. if ( FAILED( hr ) )
  60. {
  61. goto Cleanup;
  62. }
  63. Cleanup:
  64. if ( psi != NULL )
  65. {
  66. psi->Release();
  67. }
  68. HRETURN( hr );
  69. } //*** CStandardInfo::S_HrCreateInstance
  70. //////////////////////////////////////////////////////////////////////////////
  71. //++
  72. //
  73. // CStandardInfo::CStandardInfo
  74. //
  75. //--
  76. //////////////////////////////////////////////////////////////////////////////
  77. CStandardInfo::CStandardInfo( void )
  78. : m_cRef( 1 )
  79. {
  80. TraceFunc( "" );
  81. InterlockedIncrement( &g_cObjects );
  82. TraceFuncExit();
  83. } //*** CStandardInfo::CStandardInfo
  84. //////////////////////////////////////////////////////////////////////////////
  85. //++
  86. //
  87. // CStandardInfo::CStandardInfo(
  88. // CLSID * pclsidTypeIn,
  89. // OBJECTCOOKIE cookieParentIn,
  90. // BSTR bstrNameIn
  91. // )
  92. //
  93. //--
  94. //////////////////////////////////////////////////////////////////////////////
  95. CStandardInfo::CStandardInfo(
  96. CLSID * pclsidTypeIn,
  97. OBJECTCOOKIE cookieParentIn,
  98. BSTR bstrNameIn
  99. )
  100. : m_cRef( 1 )
  101. {
  102. TraceFunc( "" );
  103. InterlockedIncrement( &g_cObjects );
  104. //THR( HrInit() );
  105. m_clsidType = *pclsidTypeIn;
  106. m_cookieParent = cookieParentIn;
  107. m_bstrName = bstrNameIn;
  108. TraceFuncExit();
  109. } //*** CStandardInfo::CStandardInfo( ... )
  110. //////////////////////////////////////////////////////////////////////////////
  111. //++
  112. //
  113. // STDMETHODIMP
  114. // CStandardInfo::HrInit( void )
  115. //
  116. //--
  117. //////////////////////////////////////////////////////////////////////////////
  118. STDMETHODIMP
  119. CStandardInfo::HrInit( void )
  120. {
  121. TraceFunc( "" );
  122. HRESULT hr = S_OK;
  123. // IUnknown stuff
  124. Assert( m_cRef == 1 );
  125. // IStandardInfo
  126. Assert( m_clsidType == IID_NULL );
  127. Assert( m_cookieParent == 0 );
  128. Assert( m_bstrName == NULL );
  129. Assert( m_hrStatus == 0 );
  130. Assert( m_pci == NULL );
  131. Assert( m_pExtObjList == NULL );
  132. HRETURN( hr );
  133. } //*** CStandardInfo::HrInit
  134. //////////////////////////////////////////////////////////////////////////////
  135. //++
  136. //
  137. // CStandardInfo::~CStandardInfo
  138. //
  139. //--
  140. //////////////////////////////////////////////////////////////////////////////
  141. CStandardInfo::~CStandardInfo( void )
  142. {
  143. TraceFunc( "" );
  144. if ( m_bstrName != NULL )
  145. {
  146. TraceSysFreeString( m_bstrName );
  147. }
  148. if ( m_pci != NULL )
  149. {
  150. m_pci->Release();
  151. }
  152. while ( m_pExtObjList != NULL )
  153. {
  154. ExtObjectEntry * pnext = m_pExtObjList->pNext;
  155. m_pExtObjList->punk->Release();
  156. TraceFree( m_pExtObjList );
  157. m_pExtObjList = pnext;
  158. }
  159. InterlockedDecrement( &g_cObjects );
  160. TraceFuncExit();
  161. } //*** CStandardInfo::~CStandardInfo
  162. // ************************************************************************
  163. //
  164. // IUnknown
  165. //
  166. // ************************************************************************
  167. //////////////////////////////////////////////////////////////////////////////
  168. //++
  169. //
  170. // CStandardInfo::QueryInterface
  171. //
  172. // Description:
  173. // Query this object for the passed in interface.
  174. //
  175. // Arguments:
  176. // riidIn
  177. // Id of interface requested.
  178. //
  179. // ppvOut
  180. // Pointer to the requested interface.
  181. //
  182. // Return Value:
  183. // S_OK
  184. // If the interface is available on this object.
  185. //
  186. // E_NOINTERFACE
  187. // If the interface is not available.
  188. //
  189. // E_POINTER
  190. // ppvOut was NULL.
  191. //
  192. // Remarks:
  193. // None.
  194. //
  195. //--
  196. //////////////////////////////////////////////////////////////////////////////
  197. STDMETHODIMP
  198. CStandardInfo::QueryInterface(
  199. REFIID riidIn
  200. , LPVOID * ppvOut
  201. )
  202. {
  203. TraceQIFunc( riidIn, ppvOut );
  204. HRESULT hr = S_OK;
  205. //
  206. // Validate arguments.
  207. //
  208. Assert( ppvOut != NULL );
  209. if ( ppvOut == NULL )
  210. {
  211. hr = THR( E_POINTER );
  212. goto Cleanup;
  213. }
  214. //
  215. // Handle known interfaces.
  216. //
  217. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  218. {
  219. *ppvOut = static_cast< IStandardInfo * >( this );
  220. } // if: IUnknown
  221. else if ( IsEqualIID( riidIn, IID_IStandardInfo ) )
  222. {
  223. *ppvOut = TraceInterface( __THISCLASS__, IStandardInfo, this, 0 );
  224. } // else if: IStandardInfo
  225. else
  226. {
  227. *ppvOut = NULL;
  228. hr = E_NOINTERFACE;
  229. }
  230. //
  231. // Add a reference to the interface if successful.
  232. //
  233. if ( SUCCEEDED( hr ) )
  234. {
  235. ((IUnknown *) *ppvOut)->AddRef();
  236. } // if: success
  237. Cleanup:
  238. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  239. } //*** CStandardInfo::QueryInterface
  240. //////////////////////////////////////////////////////////////////////////////
  241. //++
  242. //
  243. // STDMETHODIMP_( ULONG )
  244. // CStandardInfo::AddRef
  245. //
  246. //--
  247. //////////////////////////////////////////////////////////////////////////////
  248. STDMETHODIMP_( ULONG )
  249. CStandardInfo::AddRef( void )
  250. {
  251. TraceFunc( "[IUnknown]" );
  252. InterlockedIncrement( &m_cRef );
  253. CRETURN( m_cRef );
  254. } //*** CStandardInfo::AddRef
  255. //////////////////////////////////////////////////////////////////////////////
  256. //++
  257. //
  258. // STDMETHODIMP_( ULONG )
  259. // CStandardInfo::Release
  260. //
  261. //--
  262. //////////////////////////////////////////////////////////////////////////////
  263. STDMETHODIMP_( ULONG )
  264. CStandardInfo::Release( void )
  265. {
  266. TraceFunc( "[IUnknown]" );
  267. LONG cRef;
  268. cRef = InterlockedDecrement( &m_cRef );
  269. if ( cRef == 0 )
  270. {
  271. TraceDo( delete this );
  272. }
  273. CRETURN( cRef );
  274. } //*** CStandardInfo::Release
  275. //****************************************************************************
  276. //
  277. // IStandardInfo
  278. //
  279. //****************************************************************************
  280. //////////////////////////////////////////////////////////////////////////////
  281. //++
  282. //
  283. // STDMETHODIMP
  284. // CStandardInfo::GetType(
  285. // CLSID * pclsidTypeOut
  286. // )
  287. //
  288. //--
  289. //////////////////////////////////////////////////////////////////////////////
  290. STDMETHODIMP
  291. CStandardInfo::GetType(
  292. CLSID * pclsidTypeOut
  293. )
  294. {
  295. TraceFunc( "[IStandardInfo]" );
  296. HRESULT hr = S_OK;
  297. if ( pclsidTypeOut == NULL )
  298. {
  299. hr = THR( E_POINTER );
  300. goto Cleanup;
  301. }
  302. CopyMemory( pclsidTypeOut, &m_clsidType, sizeof( *pclsidTypeOut ) );
  303. Cleanup:
  304. HRETURN( hr );
  305. } //*** CStandardInfo::GetType
  306. //////////////////////////////////////////////////////////////////////////////
  307. //++
  308. //
  309. // STDMETHODIMP
  310. // CStandardInfo::GetName(
  311. // BSTR * pbstrNameOut
  312. // )
  313. //
  314. //--
  315. //////////////////////////////////////////////////////////////////////////////
  316. STDMETHODIMP
  317. CStandardInfo::GetName(
  318. BSTR * pbstrNameOut
  319. )
  320. {
  321. TraceFunc( "[IStandardInfo]" );
  322. HRESULT hr = S_OK;
  323. if ( pbstrNameOut == NULL )
  324. {
  325. hr = THR( E_POINTER );
  326. goto Cleanup;
  327. }
  328. *pbstrNameOut = SysAllocString( m_bstrName );
  329. if ( *pbstrNameOut == NULL )
  330. {
  331. hr = THR( E_OUTOFMEMORY );
  332. goto Cleanup;
  333. }
  334. Cleanup:
  335. HRETURN( hr );
  336. } //*** CStandardInfo::GetName
  337. //////////////////////////////////////////////////////////////////////////////
  338. //++
  339. //
  340. // STDMETHODIMP
  341. // CStandardInfo::SetName(
  342. // LPCWSTR pcszNameIn
  343. // )
  344. //
  345. //--
  346. //////////////////////////////////////////////////////////////////////////////
  347. STDMETHODIMP
  348. CStandardInfo::SetName(
  349. LPCWSTR pcszNameIn
  350. )
  351. {
  352. TraceFunc1( "[IStandardInfo] pcszNameIn = '%ws'", pcszNameIn == NULL ? L"<null>" : pcszNameIn );
  353. HRESULT hr = S_OK;
  354. BSTR bstrNew;
  355. if ( pcszNameIn == NULL )
  356. {
  357. hr = THR( E_INVALIDARG );
  358. goto Cleanup;
  359. }
  360. bstrNew = TraceSysAllocString( pcszNameIn );
  361. if ( bstrNew == NULL )
  362. {
  363. hr = THR( E_OUTOFMEMORY );
  364. goto Cleanup;
  365. }
  366. if ( m_bstrName != NULL )
  367. {
  368. TraceSysFreeString( m_bstrName );
  369. }
  370. m_bstrName = bstrNew;
  371. Cleanup:
  372. HRETURN( hr );
  373. } //*** CStandardInfo::SetName
  374. //////////////////////////////////////////////////////////////////////////////
  375. //++
  376. //
  377. // STDMETHODIMP
  378. // CStandardInfo::GetParent(
  379. // OBJECTCOOKIE * pcookieOut
  380. // )
  381. //
  382. //--
  383. //////////////////////////////////////////////////////////////////////////////
  384. STDMETHODIMP
  385. CStandardInfo::GetParent(
  386. OBJECTCOOKIE * pcookieOut
  387. )
  388. {
  389. TraceFunc( "[IStandardInfo]" );
  390. HRESULT hr = S_OK;
  391. if ( pcookieOut == NULL )
  392. {
  393. hr = THR( E_POINTER );
  394. goto Cleanup;
  395. }
  396. *pcookieOut = m_cookieParent;
  397. if ( m_cookieParent == NULL )
  398. {
  399. hr = S_FALSE;
  400. }
  401. Cleanup:
  402. HRETURN( hr );
  403. } //*** CStandardInfo::GetParent
  404. //////////////////////////////////////////////////////////////////////////////
  405. //++
  406. //
  407. // STDMETHODIMP
  408. // CStandardInfo::GetStatus(
  409. // HRESULT * phrOut
  410. // )
  411. //
  412. //--
  413. //////////////////////////////////////////////////////////////////////////////
  414. STDMETHODIMP
  415. CStandardInfo::GetStatus(
  416. HRESULT * phrStatusOut
  417. )
  418. {
  419. TraceFunc( "[IStandardInfo]" );
  420. HRESULT hr = S_OK;
  421. if ( phrStatusOut == NULL )
  422. {
  423. hr = THR( E_POINTER );
  424. goto Cleanup;
  425. }
  426. *phrStatusOut = m_hrStatus;
  427. Cleanup:
  428. HRETURN( hr );
  429. } //*** CStandardInfo::GetStatus
  430. //////////////////////////////////////////////////////////////////////////////
  431. //++
  432. //
  433. // STDMETHODIMP
  434. // CStandardInfo::SetStatus(
  435. // HRESULT hrIn
  436. // )
  437. //
  438. //--
  439. //////////////////////////////////////////////////////////////////////////////
  440. STDMETHODIMP
  441. CStandardInfo::SetStatus(
  442. HRESULT hrIn
  443. )
  444. {
  445. TraceFunc1( "[IStandardInfo] hrIn = %#08x", hrIn );
  446. HRESULT hr = S_OK;
  447. m_hrStatus = hrIn;
  448. HRETURN( hr );
  449. } //*** CStandardInfo::SetStatus