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.

152 lines
3.9 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation.
  4. //
  5. // File : WLBSProvClassFac.cpp
  6. //
  7. // Module: WLBS Instance provider class factory
  8. //
  9. // Purpose: Contains the class factory. This creates objects when
  10. // connections are requested.
  11. //
  12. // History:
  13. //
  14. //***************************************************************************
  15. #include "WLBS_Provider.h"
  16. //***************************************************************************
  17. //
  18. // CWLBSClassFactory::CWLBSClassFactory
  19. // CWLBSClassFactory::~CWLBSClassFactory
  20. //
  21. // Constructor Parameters:
  22. // None
  23. //***************************************************************************
  24. CWLBSClassFactory::CWLBSClassFactory()
  25. : m_cRef(1)
  26. {
  27. return;
  28. }
  29. CWLBSClassFactory::~CWLBSClassFactory(void)
  30. {
  31. return;
  32. }
  33. //***************************************************************************
  34. //
  35. // CWLBSClassFactory::QueryInterface
  36. // CWLBSClassFactory::AddRef
  37. // CWLBSClassFactory::Release
  38. //
  39. // Purpose: Standard OLE routines needed for all interfaces
  40. //
  41. //***************************************************************************
  42. STDMETHODIMP CWLBSClassFactory::QueryInterface(REFIID a_riid, PPVOID a_ppv)
  43. {
  44. *a_ppv = NULL;
  45. if (IID_IUnknown==a_riid || IID_IClassFactory==a_riid)
  46. *a_ppv = static_cast<IClassFactory *>(this);
  47. if (*a_ppv != NULL) {
  48. reinterpret_cast<IUnknown *>(*a_ppv)->AddRef();
  49. return S_OK;
  50. }
  51. return E_NOINTERFACE;
  52. }
  53. STDMETHODIMP_(ULONG) CWLBSClassFactory::AddRef(void)
  54. {
  55. return InterlockedIncrement(&m_cRef);
  56. }
  57. STDMETHODIMP_(ULONG) CWLBSClassFactory::Release(void)
  58. {
  59. ULONG cRef = InterlockedDecrement(&m_cRef);
  60. if ( 0 == cRef )
  61. {
  62. delete this;
  63. }
  64. return cRef;
  65. }
  66. //***************************************************************************
  67. //
  68. // CWLBSClassFactory::CreateInstance
  69. //
  70. // Purpose: Instantiates a provider object returning an interface pointer.
  71. //
  72. // Parameters:
  73. // a_pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
  74. // being used in an aggregation.
  75. // a_riid REFIID identifying the interface the caller
  76. // desires to have for the new object.
  77. // a_ppvObj PPVOID in which to store the desired
  78. // interface pointer for the new object.
  79. //
  80. // Return Value:
  81. // HRESULT NOERROR if successful, otherwise E_NOINTERFACE
  82. // if we cannot support the requested interface.
  83. //***************************************************************************
  84. STDMETHODIMP CWLBSClassFactory::CreateInstance(
  85. LPUNKNOWN a_pUnkOuter,
  86. REFIID a_riid,
  87. PPVOID a_ppvObj
  88. )
  89. {
  90. CWLBSProvider * pObj = NULL;
  91. HRESULT hr;
  92. *a_ppvObj = NULL;
  93. // This object doesnt support aggregation.
  94. if (a_pUnkOuter != NULL)
  95. return CLASS_E_NOAGGREGATION;
  96. // Create the object.
  97. pObj = new CWLBSProvider();
  98. if (pObj == NULL)
  99. return E_OUTOFMEMORY;
  100. hr = pObj->QueryInterface(a_riid, a_ppvObj);
  101. if( FAILED(hr) ) {
  102. delete pObj;
  103. pObj = NULL;
  104. }
  105. return hr;
  106. }
  107. //***************************************************************************
  108. //
  109. // CWLBSClassFactory::LockServer
  110. //
  111. // Purpose:
  112. // Increments or decrements the lock count of the DLL. If the
  113. // lock count goes to zero and there are no objects, the DLL
  114. // is allowed to unload. See DllCanUnloadNow.
  115. //
  116. // Parameters:
  117. // fLock BOOL specifying whether to increment or
  118. // decrement the lock count.
  119. //
  120. // Return Value:
  121. // HRESULT NOERROR always.
  122. //***************************************************************************
  123. STDMETHODIMP CWLBSClassFactory::LockServer(BOOL a_bLock)
  124. {
  125. if (a_bLock)
  126. InterlockedIncrement(&g_cServerLocks);
  127. else
  128. InterlockedDecrement(&g_cServerLocks);
  129. return S_OK;
  130. }