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.

108 lines
2.4 KiB

  1. #include "stdafx.h"
  2. #include "cfact.h"
  3. #include "stobject.h"
  4. /************************************************************************************
  5. IUnknown Implementation
  6. ************************************************************************************/
  7. HRESULT CSysTrayFactory::QueryInterface(REFIID iid, void** ppvObject)
  8. {
  9. HRESULT hr = S_OK;
  10. if ((iid == IID_IClassFactory) || (iid == IID_IUnknown))
  11. {
  12. *ppvObject = (IClassFactory*) this;
  13. }
  14. else
  15. {
  16. *ppvObject = NULL;
  17. hr = E_NOINTERFACE;
  18. }
  19. if (hr == S_OK)
  20. {
  21. ((IUnknown*) (*ppvObject))->AddRef();
  22. }
  23. return hr;
  24. }
  25. ULONG CSysTrayFactory::AddRef()
  26. {
  27. return InterlockedIncrement(&m_cRef);
  28. }
  29. ULONG CSysTrayFactory::Release()
  30. {
  31. ASSERT( 0 != m_cRef );
  32. ULONG cRef = InterlockedDecrement(&m_cRef);
  33. if ( 0 == cRef )
  34. {
  35. delete this;
  36. }
  37. return cRef;
  38. }
  39. /************************************************************************************
  40. IClassFactory Implementation
  41. ************************************************************************************/
  42. HRESULT CSysTrayFactory::CreateInstance(IUnknown* pUnkOuter, REFIID iid, void** ppvObject)
  43. {
  44. HRESULT hr = S_OK;
  45. if (pUnkOuter != NULL)
  46. {
  47. hr = CLASS_E_NOAGGREGATION;
  48. }
  49. else
  50. {
  51. CSysTray* ptray = new CSysTray(m_fRunTrayOnConstruct);
  52. if (ptray != NULL)
  53. {
  54. hr = ptray->QueryInterface(iid, ppvObject);
  55. ptray->Release();
  56. }
  57. else
  58. {
  59. hr = E_OUTOFMEMORY;
  60. }
  61. }
  62. return hr;
  63. }
  64. HRESULT CSysTrayFactory::LockServer(BOOL fLock)
  65. {
  66. if (fLock)
  67. {
  68. InterlockedIncrement(&g_cLocks);
  69. }
  70. else
  71. {
  72. ASSERT( 0 != g_cLocks );
  73. InterlockedDecrement(&g_cLocks);
  74. }
  75. return S_OK;
  76. }
  77. /************************************************************************************
  78. Constructor/Destructor Implementation
  79. ************************************************************************************/
  80. CSysTrayFactory::CSysTrayFactory(BOOL fRunTrayOnConstruct)
  81. {
  82. m_fRunTrayOnConstruct = fRunTrayOnConstruct;
  83. m_cRef = 1;
  84. InterlockedIncrement(&g_cLocks);
  85. }
  86. CSysTrayFactory::~CSysTrayFactory()
  87. {
  88. ASSERT( 0 != g_cLocks );
  89. InterlockedDecrement(&g_cLocks);
  90. }