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.

151 lines
3.9 KiB

  1. //***************************************************************************
  2. //
  3. // CLASSFAC.CPP
  4. //
  5. // Module: WMI Instance provider sample code
  6. //
  7. // Purpose: Contains the class factory. This creates objects when
  8. // connections are requested.
  9. //
  10. // Copyright (c) 1997-1999 Microsoft Corporation
  11. //
  12. //***************************************************************************
  13. #include <objbase.h>
  14. #include "bootini.h"
  15. //***************************************************************************
  16. //
  17. // CBootProvFactory::CBootProvFactory
  18. // CBootProvFactory::~CBootProvFactory
  19. //
  20. // Constructor Parameters:
  21. // None
  22. //***************************************************************************
  23. CBootProvFactory::CBootProvFactory()
  24. {
  25. m_cRef=0L;
  26. return;
  27. }
  28. CBootProvFactory::~CBootProvFactory(void)
  29. {
  30. return;
  31. }
  32. //***************************************************************************
  33. //
  34. // CBootProvFactory::QueryInterface
  35. // CBootProvFactory::AddRef
  36. // CBootProvFactory::Release
  37. //
  38. // Purpose: Standard Ole routines needed for all interfaces
  39. //
  40. //***************************************************************************
  41. STDMETHODIMP CBootProvFactory::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) CBootProvFactory::AddRef(void)
  55. {
  56. return ++m_cRef;
  57. }
  58. STDMETHODIMP_(ULONG) CBootProvFactory::Release(void)
  59. {
  60. ULONG nNewCount = InterlockedDecrement((long *)&m_cRef);
  61. if (0L == nNewCount)
  62. delete this;
  63. return nNewCount;
  64. }
  65. //***************************************************************************
  66. //
  67. // CBootProvFactory::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 CBootProvFactory::CreateInstance(LPUNKNOWN pUnkOuter
  84. , REFIID riid, PPVOID ppvObj)
  85. {
  86. CBootInstPro * pObj;
  87. HRESULT hr;
  88. *ppvObj=NULL;
  89. // This object doesnt support aggregation.
  90. if (NULL!=pUnkOuter)
  91. return CLASS_E_NOAGGREGATION;
  92. // Create the locator object.
  93. pObj=new CBootInstPro();
  94. if (NULL==pObj)
  95. return E_OUTOFMEMORY;
  96. hr=pObj->QueryInterface(riid, ppvObj);
  97. //Kill the object if initial creation or Init failed.
  98. if (FAILED(hr))
  99. delete pObj;
  100. return hr;
  101. }
  102. //***************************************************************************
  103. //
  104. // CBootProvFactory::LockServer
  105. //
  106. // Purpose:
  107. // Increments or decrements the lock count of the DLL. If the
  108. // lock count goes to zero and there are no objects, the DLL
  109. // is allowed to unload. See DllCanUnloadNow.
  110. //
  111. // Parameters:
  112. // fLock BOOL specifying whether to increment or
  113. // decrement the lock count.
  114. //
  115. // Return Value:
  116. // HRESULT NOERROR always.
  117. //***************************************************************************
  118. STDMETHODIMP CBootProvFactory::LockServer(BOOL fLock)
  119. {
  120. if (fLock)
  121. InterlockedIncrement(&g_cLock);
  122. else
  123. InterlockedDecrement(&g_cLock);
  124. return NOERROR;
  125. }