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.

156 lines
3.7 KiB

  1. //***************************************************************************
  2. //
  3. // CLASSFAC.CPP
  4. //
  5. // Module: WMI IIS Instance provider
  6. //
  7. // Purpose: Contains the class factory. This creates objects when
  8. // connections are requested.
  9. //
  10. // Copyright (c)1999 Microsoft Corporation, All Rights Reserved
  11. //
  12. //***************************************************************************
  13. #include "iisprov.h"
  14. //***************************************************************************
  15. //
  16. // CProvFactory::CProvFactory
  17. // CProvFactory::~CProvFactory
  18. //
  19. // Constructor Parameters:
  20. // None
  21. //***************************************************************************
  22. CProvFactory::CProvFactory()
  23. {
  24. m_cRef=0L;
  25. }
  26. CProvFactory::~CProvFactory(void)
  27. {
  28. }
  29. //***************************************************************************
  30. //
  31. // CProvFactory::QueryInterface
  32. // CProvFactory::AddRef
  33. // CProvFactory::Release
  34. //
  35. // Purpose: Standard Ole routines needed for all interfaces
  36. //
  37. //***************************************************************************
  38. STDMETHODIMP CProvFactory::QueryInterface(
  39. REFIID riid,
  40. PPVOID ppv
  41. )
  42. {
  43. *ppv=NULL;
  44. if (IID_IUnknown == riid || IID_IClassFactory == riid)
  45. *ppv=this;
  46. if (NULL != *ppv)
  47. {
  48. ((LPUNKNOWN)*ppv)->AddRef();
  49. return S_OK;
  50. }
  51. return E_NOINTERFACE;
  52. }
  53. STDMETHODIMP_(ULONG) CProvFactory::AddRef(void)
  54. {
  55. return InterlockedIncrement((long *)&m_cRef);
  56. }
  57. STDMETHODIMP_(ULONG) CProvFactory::Release(void)
  58. {
  59. long lNewCount = InterlockedDecrement((long *)&m_cRef);
  60. if (0L == lNewCount)
  61. delete this;
  62. return lNewCount>0 ? lNewCount : 0;
  63. }
  64. //***************************************************************************
  65. //
  66. // CProvFactory::CreateInstance
  67. //
  68. // Purpose: Instantiates a Locator object returning an interface pointer.
  69. //
  70. // Parameters:
  71. // pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
  72. // being used in an aggregation.
  73. // riid REFIID identifying the interface the caller
  74. // desires to have for the new object.
  75. // ppvObj PPVOID in which to store the desired
  76. // interface pointer for the new object.
  77. //
  78. // Return Value:
  79. // HRESULT NOERROR if successful, otherwise E_NOINTERFACE
  80. // if we cannot support the requested interface.
  81. //***************************************************************************
  82. STDMETHODIMP CProvFactory::CreateInstance(
  83. LPUNKNOWN pUnkOuter,
  84. REFIID riid, PPVOID ppvObj
  85. )
  86. {
  87. CIISInstProvider *pObj;
  88. HRESULT hr;
  89. *ppvObj=NULL;
  90. // This object doesnt support aggregation.
  91. if (NULL!=pUnkOuter)
  92. return CLASS_E_NOAGGREGATION;
  93. // Create the locator object.
  94. pObj = new CIISInstProvider();
  95. if (NULL==pObj)
  96. return E_OUTOFMEMORY;
  97. hr = pObj->QueryInterface(riid, ppvObj);
  98. //Kill the object if initial creation or Init failed.
  99. if (FAILED(hr))
  100. delete pObj;
  101. return hr;
  102. }
  103. //***************************************************************************
  104. //
  105. // CProvFactory::LockServer
  106. //
  107. // Purpose:
  108. // Increments or decrements the lock count of the DLL. If the
  109. // lock count goes to zero and there are no objects, the DLL
  110. // is allowed to unload. See DllCanUnloadNow.
  111. //
  112. // Parameters:
  113. // fLock BOOL specifying whether to increment or
  114. // decrement the lock count.
  115. //
  116. // Return Value:
  117. // HRESULT NOERROR always.
  118. //***************************************************************************
  119. STDMETHODIMP CProvFactory::LockServer(BOOL fLock)
  120. {
  121. if (fLock)
  122. InterlockedIncrement(&g_cLock);
  123. else
  124. InterlockedDecrement(&g_cLock);
  125. return S_OK;
  126. }