Source code of Windows XP (NT5)
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.

102 lines
2.2 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. if (InterlockedDecrement(&m_cRef) == 0)
  32. {
  33. delete this;
  34. return 0;
  35. }
  36. return m_cRef;
  37. }
  38. /************************************************************************************
  39. IClassFactory Implementation
  40. ************************************************************************************/
  41. HRESULT CSysTrayFactory::CreateInstance(IUnknown* pUnkOuter, REFIID iid, void** ppvObject)
  42. {
  43. HRESULT hr = S_OK;
  44. if (pUnkOuter != NULL)
  45. {
  46. hr = CLASS_E_NOAGGREGATION;
  47. }
  48. else
  49. {
  50. CSysTray* ptray = new CSysTray(m_fRunTrayOnConstruct);
  51. if (ptray != NULL)
  52. {
  53. hr = ptray->QueryInterface(iid, ppvObject);
  54. ptray->Release();
  55. }
  56. else
  57. {
  58. hr = E_OUTOFMEMORY;
  59. }
  60. }
  61. return hr;
  62. }
  63. HRESULT CSysTrayFactory::LockServer(BOOL fLock)
  64. {
  65. if (fLock)
  66. InterlockedIncrement(&g_cLocks);
  67. else
  68. InterlockedDecrement(&g_cLocks);
  69. return S_OK;
  70. }
  71. /************************************************************************************
  72. Constructor/Destructor Implementation
  73. ************************************************************************************/
  74. CSysTrayFactory::CSysTrayFactory(BOOL fRunTrayOnConstruct)
  75. {
  76. m_fRunTrayOnConstruct = fRunTrayOnConstruct;
  77. m_cRef = 1;
  78. InterlockedIncrement(&g_cLocks);
  79. }
  80. CSysTrayFactory::~CSysTrayFactory()
  81. {
  82. InterlockedDecrement(&g_cLocks);
  83. }