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.

122 lines
2.9 KiB

  1. ////////////////////////////////////////////////////////////////////////
  2. //
  3. // Factory.cpp
  4. //
  5. // Module: WMI high performance provider sample code
  6. //
  7. // This is a standard class factory implementation for the CHiPerfProvider
  8. // object.
  9. //
  10. // History:
  11. // a-dcrews 12-Jan-99 Created
  12. //
  13. //
  14. // Copyright (c) 1999-2001 Microsoft Corporation
  15. //
  16. ////////////////////////////////////////////////////////////////////////
  17. #include "precomp.h"
  18. #include "Provider.h"
  19. #include "Factory.h"
  20. extern long g_lObjects;
  21. extern long g_lLocks;
  22. //////////////////////////////////////////////////////////////
  23. //
  24. //
  25. // CClassFactory
  26. //
  27. //
  28. //////////////////////////////////////////////////////////////
  29. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, void** ppv)
  30. //////////////////////////////////////////////////////////////
  31. //
  32. // Standard QueryInterface
  33. //
  34. // Parameters:
  35. // riid - the ID of the requested interface
  36. // ppv - a pointer to the interface pointer
  37. //
  38. //////////////////////////////////////////////////////////////
  39. {
  40. if (NULL == ppv) return E_POINTER;
  41. if(riid == IID_IUnknown)
  42. *ppv = (LPVOID)(IUnknown*)this;
  43. else if(riid == IID_IClassFactory)
  44. *ppv = (LPVOID)(IClassFactory*)this;
  45. else
  46. {
  47. *ppv = NULL;
  48. return E_NOINTERFACE;
  49. }
  50. ((IUnknown*)*ppv)->AddRef();
  51. return S_OK;
  52. }
  53. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  54. {
  55. return InterlockedIncrement(&m_lRef);
  56. }
  57. STDMETHODIMP_(ULONG) CClassFactory::Release()
  58. {
  59. long lRef = InterlockedDecrement(&m_lRef);
  60. if(lRef == 0) delete this;
  61. return lRef;
  62. }
  63. STDMETHODIMP CClassFactory::CreateInstance(
  64. /* [in] */ IUnknown* pUnknownOuter,
  65. /* [in] */ REFIID iid,
  66. /* [out] */ LPVOID *ppv)
  67. //////////////////////////////////////////////////////////////
  68. //
  69. // Standard COM CreateInstance
  70. //
  71. //////////////////////////////////////////////////////////////
  72. {
  73. HRESULT hRes;
  74. CHiPerfProvider *pProvider = NULL;
  75. *ppv = NULL;
  76. // We do not support aggregation
  77. if (pUnknownOuter) return CLASS_E_NOAGGREGATION;
  78. // Create the provider object
  79. pProvider = new CHiPerfProvider;
  80. if (NULL == pProvider) return E_OUTOFMEMORY;
  81. // Retrieve the requested interface
  82. // ================================
  83. hRes = pProvider->QueryInterface(iid, ppv);
  84. if (FAILED(hRes))
  85. {
  86. delete pProvider;
  87. return hRes;
  88. }
  89. return S_OK;
  90. }
  91. STDMETHODIMP CClassFactory::LockServer(
  92. /* [in] */ BOOL bLock)
  93. //////////////////////////////////////////////////////////////
  94. //
  95. // Standard COM LockServer
  96. //
  97. //////////////////////////////////////////////////////////////
  98. {
  99. if (bLock)
  100. InterlockedIncrement(&g_lLocks);
  101. else
  102. InterlockedDecrement(&g_lLocks);
  103. return S_OK;
  104. }