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.

153 lines
3.9 KiB

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