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.

198 lines
3.0 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. cfacchng.cxx
  5. Abstract:
  6. Implements the Class Factory for the SENS IEventObjectChange Subscriber.
  7. Author:
  8. Gopal Parupudi <GopalP>
  9. [Notes:]
  10. optional-notes
  11. Revision History:
  12. GopalP 11/17/1997 Start.
  13. --*/
  14. #include <precomp.hxx>
  15. //
  16. // Global counts for the number of objects in the server and the number of
  17. // locks.
  18. //
  19. ULONG g_cCFObj = 0L;
  20. ULONG g_cCFLock = 0L;
  21. //
  22. // Constructor and Destructor
  23. //
  24. CIEventObjectChangeCF::CIEventObjectChangeCF(
  25. void
  26. ) : m_cRef(1L)
  27. {
  28. }
  29. CIEventObjectChangeCF::~CIEventObjectChangeCF(
  30. void
  31. )
  32. {
  33. // Empty Destructor.
  34. }
  35. //
  36. // QI
  37. //
  38. STDMETHODIMP
  39. CIEventObjectChangeCF::QueryInterface(
  40. REFIID riid,
  41. LPVOID *ppv
  42. )
  43. {
  44. HRESULT hr = S_OK;
  45. *ppv = NULL; // To handle failure cases
  46. // IUnknown or IClassFactory
  47. if (IsEqualIID(riid, IID_IUnknown) ||
  48. IsEqualIID(riid, IID_IClassFactory))
  49. {
  50. *ppv = (LPUNKNOWN) this;
  51. }
  52. else
  53. {
  54. hr = E_NOINTERFACE;
  55. }
  56. if (NULL != *ppv)
  57. {
  58. ((LPUNKNOWN)*ppv)->AddRef();
  59. }
  60. return hr;
  61. }
  62. //
  63. // AddRef
  64. //
  65. STDMETHODIMP_(ULONG)
  66. CIEventObjectChangeCF::AddRef(
  67. void
  68. )
  69. {
  70. return InterlockedIncrement((PLONG) &m_cRef);
  71. }
  72. //
  73. // Release
  74. //
  75. STDMETHODIMP_(ULONG)
  76. CIEventObjectChangeCF::Release(
  77. void
  78. )
  79. {
  80. ULONG cRefT;
  81. cRefT = InterlockedDecrement((PLONG) &m_cRef);
  82. if (0 == m_cRef)
  83. {
  84. // Invoke the callback function.
  85. delete this;
  86. }
  87. return cRefT;
  88. }
  89. //
  90. // CreateInstance
  91. //
  92. STDMETHODIMP
  93. CIEventObjectChangeCF::CreateInstance(
  94. LPUNKNOWN pUnkOuter,
  95. REFIID riid,
  96. LPVOID *ppvObj
  97. )
  98. {
  99. LPCIMPIEVENTOBJECTCHANGE pObjChange;
  100. HRESULT hr;
  101. DebugTraceGuid("CIEventObjectChangeCF:CreateInstance()", riid);
  102. hr = E_OUTOFMEMORY;
  103. *ppvObj = NULL;
  104. pObjChange = NULL;
  105. //
  106. // Return the appropriate interface pointer.
  107. //
  108. if (IsEqualIID(riid, IID_IEventObjectChange) ||
  109. IsEqualIID(riid, IID_IUnknown))
  110. {
  111. SensPrintA(SENS_INFO, ("\t| ClassFactory::CreateInstance(IEventObjectChange)\n"));
  112. pObjChange = new CImpIEventObjectChange();
  113. if (NULL != pObjChange)
  114. {
  115. hr = pObjChange->QueryInterface(riid, ppvObj);
  116. SensPrintA(SENS_INFO, ("\t| QI on CImpIEventObjectChange returned 0x%x\n", hr));
  117. }
  118. }
  119. else
  120. {
  121. hr = E_NOINTERFACE;
  122. }
  123. if (NULL != *ppvObj)
  124. {
  125. InterlockedIncrement((PLONG) &g_cCFObj);
  126. }
  127. SensPrintA(SENS_INFO, ("\t| Returning 0x%x from CF:CreateInstance\n", hr));
  128. return hr;
  129. }
  130. //
  131. // LockServer
  132. //
  133. STDMETHODIMP
  134. CIEventObjectChangeCF::LockServer(
  135. BOOL fLock
  136. )
  137. {
  138. if (fLock)
  139. {
  140. InterlockedIncrement((PLONG) &g_cCFLock);
  141. }
  142. else
  143. {
  144. InterlockedDecrement((PLONG) &g_cCFLock);
  145. InterlockedIncrement((PLONG) &g_cCFObj);
  146. }
  147. return NOERROR;
  148. }