Source code of Windows XP (NT5)
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.

149 lines
3.8 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. if (InterlockedDecrement(&m_cRef) == 0) {
  60. delete this;
  61. return 0;
  62. }
  63. return m_cRef;
  64. }
  65. //***************************************************************************
  66. //
  67. // CWLBSClassFactory::CreateInstance
  68. //
  69. // Purpose: Instantiates a provider object returning an interface pointer.
  70. //
  71. // Parameters:
  72. // a_pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
  73. // being used in an aggregation.
  74. // a_riid REFIID identifying the interface the caller
  75. // desires to have for the new object.
  76. // a_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 CWLBSClassFactory::CreateInstance(
  84. LPUNKNOWN a_pUnkOuter,
  85. REFIID a_riid,
  86. PPVOID a_ppvObj
  87. )
  88. {
  89. CWLBSProvider * pObj = NULL;
  90. HRESULT hr;
  91. *a_ppvObj = NULL;
  92. // This object doesnt support aggregation.
  93. if (a_pUnkOuter != NULL)
  94. return CLASS_E_NOAGGREGATION;
  95. // Create the object.
  96. pObj = new CWLBSProvider();
  97. if (pObj == NULL)
  98. return E_OUTOFMEMORY;
  99. hr = pObj->QueryInterface(a_riid, a_ppvObj);
  100. if( FAILED(hr) ) {
  101. delete pObj;
  102. pObj = NULL;
  103. }
  104. return hr;
  105. }
  106. //***************************************************************************
  107. //
  108. // CWLBSClassFactory::LockServer
  109. //
  110. // Purpose:
  111. // Increments or decrements the lock count of the DLL. If the
  112. // lock count goes to zero and there are no objects, the DLL
  113. // is allowed to unload. See DllCanUnloadNow.
  114. //
  115. // Parameters:
  116. // fLock BOOL specifying whether to increment or
  117. // decrement the lock count.
  118. //
  119. // Return Value:
  120. // HRESULT NOERROR always.
  121. //***************************************************************************
  122. STDMETHODIMP CWLBSClassFactory::LockServer(BOOL a_bLock)
  123. {
  124. if (a_bLock)
  125. InterlockedIncrement(&g_cServerLocks);
  126. else
  127. InterlockedDecrement(&g_cServerLocks);
  128. return S_OK;
  129. }