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.

155 lines
3.7 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. //
  3. // CopyRight (c) 1999 Microsoft Corporation
  4. //
  5. // Module Name: provfactory.cpp
  6. //
  7. // Description:
  8. // Implementation of CProvFactory class
  9. //
  10. // Author:
  11. // Henry Wang ( henrywa ) March 8, 2000
  12. //
  13. //////////////////////////////////////////////////////////////////////
  14. #include "DnsWmi.h"
  15. //////////////////////////////////////////////////////////////////////
  16. // Construction/Destruction
  17. //////////////////////////////////////////////////////////////////////
  18. CProvFactory::CProvFactory()
  19. {
  20. m_cRef=0L;
  21. return;
  22. }
  23. CProvFactory::~CProvFactory(void)
  24. {
  25. return;
  26. }
  27. //***************************************************************************
  28. //
  29. // CProvFactory::QueryInterface
  30. // CProvFactory::AddRef
  31. // CProvFactory::Release
  32. //
  33. // Purpose: Standard Ole routines needed for all interfaces
  34. //
  35. //***************************************************************************
  36. STDMETHODIMP CProvFactory::QueryInterface(REFIID riid
  37. , PPVOID ppv)
  38. {
  39. *ppv=NULL;
  40. if (IID_IUnknown==riid || IID_IClassFactory==riid)
  41. *ppv=this;
  42. if (NULL!=*ppv)
  43. {
  44. ((LPUNKNOWN)*ppv)->AddRef();
  45. return NOERROR;
  46. }
  47. return E_NOINTERFACE;
  48. }
  49. STDMETHODIMP_(ULONG) CProvFactory::AddRef(void)
  50. {
  51. return ++m_cRef;
  52. }
  53. STDMETHODIMP_(ULONG) CProvFactory::Release(void)
  54. {
  55. ULONG nNewCount = InterlockedDecrement((long *)&m_cRef);
  56. if (0L == nNewCount)
  57. {
  58. delete this;
  59. }
  60. return nNewCount;
  61. }
  62. //***************************************************************************
  63. //
  64. // CProvFactory::CreateInstance
  65. //
  66. // Purpose: Instantiates a Locator object returning an interface pointer.
  67. //
  68. // Parameters:
  69. // pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
  70. // being used in an aggregation.
  71. // riid REFIID identifying the interface the caller
  72. // desires to have for the new object.
  73. // ppvObj PPVOID in which to store the desired
  74. // interface pointer for the new object.
  75. //
  76. // Return Value:
  77. // HRESULT NOERROR if successful, otherwise E_NOINTERFACE
  78. // if we cannot support the requested interface.
  79. //***************************************************************************
  80. STDMETHODIMP CProvFactory::CreateInstance(LPUNKNOWN pUnkOuter
  81. , REFIID riid, PPVOID ppvObj)
  82. {
  83. CInstanceProv * pObj;
  84. HRESULT hr;
  85. *ppvObj=NULL;
  86. // This object doesnt support aggregation.
  87. if (NULL!=pUnkOuter)
  88. return CLASS_E_NOAGGREGATION;
  89. // Create the locator object.
  90. pObj=new CInstanceProv();
  91. if (NULL==pObj)
  92. {
  93. return E_OUTOFMEMORY;
  94. }
  95. hr=pObj->QueryInterface(riid, ppvObj);
  96. //Kill the object if initial creation or Init failed.
  97. if (FAILED(hr))
  98. {
  99. delete pObj;
  100. }
  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 NOERROR;
  126. }