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.

156 lines
3.6 KiB

  1. /*++
  2. Copyright (C) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. //***************************************************************************
  8. //
  9. // CLocatorFactory::CLocatorFactory
  10. // CLocatorFactory::~CLocatorFactory
  11. //
  12. // Constructor Parameters:
  13. // None
  14. //***************************************************************************
  15. template<class TProvider>
  16. CLocatorFactory<TProvider>::CLocatorFactory()
  17. {
  18. m_cRef=0L;
  19. return;
  20. }
  21. template<class TProvider>
  22. CLocatorFactory<TProvider>::~CLocatorFactory(void)
  23. {
  24. return;
  25. }
  26. //***************************************************************************
  27. //
  28. // CLocatorFactory::QueryInterface
  29. // CLocatorFactory::AddRef
  30. // CLocatorFactory::Release
  31. //
  32. // Purpose: Standard Ole routines needed for all interfaces
  33. //
  34. //***************************************************************************
  35. template<class TProvider>
  36. STDMETHODIMP CLocatorFactory<TProvider>::QueryInterface(REFIID riid, PPVOID ppv)
  37. {
  38. *ppv=NULL;
  39. if (IID_IUnknown==riid || IID_IClassFactory==riid)
  40. *ppv=this;
  41. if (NULL!=*ppv)
  42. {
  43. ((LPUNKNOWN)*ppv)->AddRef();
  44. return NOERROR;
  45. }
  46. return E_NOINTERFACE;
  47. }
  48. template<class TProvider>
  49. STDMETHODIMP_(ULONG) CLocatorFactory<TProvider>::AddRef(void)
  50. {
  51. return InterlockedIncrement(&m_cRef);;
  52. }
  53. template<class TProvider>
  54. STDMETHODIMP_(ULONG) CLocatorFactory<TProvider>::Release(void)
  55. {
  56. ULONG cRef = InterlockedDecrement(&m_cRef);
  57. if(cRef == 0)
  58. {
  59. delete this;
  60. }
  61. return cRef;
  62. }
  63. //***************************************************************************
  64. //
  65. // CLocatorFactory::CreateInstance
  66. //
  67. // Purpose: Instantiates a Locator object returning an interface pointer.
  68. //
  69. // Parameters:
  70. // pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
  71. // being used in an aggregation.
  72. // riid REFIID identifying the interface the caller
  73. // desires to have for the new object.
  74. // ppvObj PPVOID in which to store the desired
  75. // interface pointer for the new object.
  76. //
  77. // Return Value:
  78. // HRESULT NOERROR if successful, otherwise E_NOINTERFACE
  79. // if we cannot support the requested interface.
  80. //***************************************************************************
  81. template<class TProvider>
  82. STDMETHODIMP CLocatorFactory<TProvider>::CreateInstance(LPUNKNOWN pUnkOuter
  83. , REFIID riid, PPVOID ppvObj)
  84. {
  85. IHmmLocator * pObj;
  86. HRESULT hr;
  87. *ppvObj=NULL;
  88. hr=E_OUTOFMEMORY;
  89. // This object doesnt support aggregation.
  90. if (NULL!=pUnkOuter)
  91. return CLASS_E_NOAGGREGATION;
  92. //Create the object passing function to notify on destruction.
  93. pObj=(IHmmLocator*)new CProviderLocator<TProvider>;
  94. if (NULL==pObj)
  95. return hr;
  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. // CLocatorFactory::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. template<class TProvider>
  119. STDMETHODIMP CLocatorFactory<TProvider>::LockServer(BOOL fLock)
  120. {
  121. LockServer(fLock);
  122. return NOERROR;
  123. }