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.

172 lines
4.1 KiB

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