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.

221 lines
6.4 KiB

  1. /*****************************************************************************\
  2. FILE: classfactory.cpp
  3. DESCRIPTION:
  4. This file will be the Class Factory.
  5. BryanSt 4/4/2000 (Bryan Starbuck)
  6. Copyright (C) Microsoft Corp 2000-2000. All rights reserved.
  7. \*****************************************************************************/
  8. #include "priv.h"
  9. #include "classfactory.h"
  10. #include "EffectsBasePg.h"
  11. #include "ScreenSaverPg.h"
  12. #include "store.h"
  13. /*****************************************************************************
  14. *
  15. * CClassFactory
  16. *
  17. *
  18. *****************************************************************************/
  19. HRESULT CSettingsPage_CreateInstance(IN IUnknown * punkOuter, IN REFIID riid, OUT LPVOID * ppvObj);
  20. HRESULT CDisplaySettings_CreateInstance(IN IUnknown * punkOuter, IN REFIID riid, OUT LPVOID * ppvObj);
  21. HRESULT CScreenResFixer_CreateInstance(IN IUnknown * punkOuter, IN REFIID riid, OUT LPVOID * ppvObj);
  22. class CClassFactory : public IClassFactory
  23. {
  24. public:
  25. //////////////////////////////////////////////////////
  26. // Public Interfaces
  27. //////////////////////////////////////////////////////
  28. // *** IUnknown ***
  29. virtual STDMETHODIMP_(ULONG) AddRef(void);
  30. virtual STDMETHODIMP_(ULONG) Release(void);
  31. virtual STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  32. // *** IClassFactory ***
  33. virtual STDMETHODIMP CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObject);
  34. virtual STDMETHODIMP LockServer(BOOL fLock);
  35. public:
  36. CClassFactory(REFCLSID rclsid);
  37. ~CClassFactory(void);
  38. // Friend Functions
  39. friend HRESULT CClassFactory_Create(REFCLSID rclsid, REFIID riid, LPVOID * ppvObj);
  40. protected:
  41. long m_cRef;
  42. CLSID m_rclsid;
  43. };
  44. /*****************************************************************************
  45. * IClassFactory::CreateInstance
  46. *****************************************************************************/
  47. HRESULT CClassFactory::CreateInstance(IUnknown * punkOuter, REFIID riid, LPVOID * ppvObj)
  48. {
  49. HRESULT hr = E_INVALIDARG;
  50. if (NULL != ppvObj)
  51. {
  52. if (!punkOuter)
  53. {
  54. if (IsEqualCLSID(m_rclsid, CLSID_ThemeManager))
  55. {
  56. hr = CThemeManager_CreateInstance(punkOuter, riid, ppvObj);
  57. }
  58. else if (IsEqualCLSID(m_rclsid, CLSID_ThemeUIPages))
  59. {
  60. hr = CThemeUIPages_CreateInstance(punkOuter, riid, ppvObj);
  61. }
  62. else if (IsEqualCLSID(m_rclsid, CLSID_ThemePreview))
  63. {
  64. hr = CThemePreview_CreateInstance(punkOuter, riid, ppvObj);
  65. }
  66. else if (IsEqualCLSID(m_rclsid, CLSID_EffectsPage))
  67. {
  68. hr = CEffectsBasePage_CreateInstance(punkOuter, riid, ppvObj);
  69. }
  70. else if (IsEqualCLSID(m_rclsid, CLSID_SettingsPage))
  71. {
  72. hr = CSettingsPage_CreateInstance(punkOuter, riid, ppvObj);
  73. }
  74. else if (IsEqualCLSID(m_rclsid, CLSID_DisplaySettings))
  75. {
  76. hr = CDisplaySettings_CreateInstance(punkOuter, riid, ppvObj);
  77. }
  78. else if (IsEqualCLSID(m_rclsid, CLSID_ScreenResFixer))
  79. {
  80. hr = CScreenResFixer_CreateInstance(punkOuter, riid, ppvObj);
  81. }
  82. else if (IsEqualCLSID(m_rclsid, CLSID_ScreenSaverPage))
  83. {
  84. hr = CScreenSaverPage_CreateInstance(punkOuter, riid, ppvObj);
  85. }
  86. else
  87. {
  88. TCHAR szGuid[GUIDSTR_MAX];
  89. SHStringFromGUID(m_rclsid, szGuid, ARRAYSIZE(szGuid));
  90. AssertMsg(0, TEXT("CClassFactory::CreateInstance(%s) failed because we don't support that CLSID. This is because someone made a registration bug."), szGuid); // What are you looking for?
  91. hr = E_NOINTERFACE;
  92. }
  93. }
  94. else
  95. { // Does anybody support aggregation any more?
  96. hr = ResultFromScode(CLASS_E_NOAGGREGATION);
  97. }
  98. }
  99. return hr;
  100. }
  101. /*****************************************************************************
  102. *
  103. * IClassFactory::LockServer
  104. *
  105. * What a poor function. Locking the server is identical to
  106. * creating an object and not releasing it until you want to unlock
  107. * the server.
  108. *
  109. *****************************************************************************/
  110. HRESULT CClassFactory::LockServer(BOOL fLock)
  111. {
  112. if (fLock)
  113. DllAddRef();
  114. else
  115. DllRelease();
  116. return S_OK;
  117. }
  118. /*****************************************************************************
  119. *
  120. * CClassFactory_Create
  121. *
  122. *****************************************************************************/
  123. /****************************************************\
  124. Constructor
  125. \****************************************************/
  126. CClassFactory::CClassFactory(REFCLSID rclsid) : m_cRef(1)
  127. {
  128. m_rclsid = rclsid;
  129. DllAddRef();
  130. }
  131. /****************************************************\
  132. Destructor
  133. \****************************************************/
  134. CClassFactory::~CClassFactory()
  135. {
  136. DllRelease();
  137. }
  138. //===========================
  139. // *** IUnknown Interface ***
  140. //===========================
  141. ULONG CClassFactory::AddRef()
  142. {
  143. return InterlockedIncrement(&m_cRef);
  144. }
  145. ULONG CClassFactory::Release()
  146. {
  147. ASSERT( 0 != m_cRef );
  148. ULONG cRef = InterlockedDecrement(&m_cRef);
  149. if ( 0 == cRef )
  150. {
  151. delete this;
  152. }
  153. return cRef;
  154. }
  155. HRESULT CClassFactory::QueryInterface(REFIID riid, void **ppvObj)
  156. {
  157. if (IsEqualCLSID(riid, IID_IUnknown) || IsEqualCLSID(riid, IID_IClassFactory))
  158. {
  159. *ppvObj = SAFECAST(this, IClassFactory *);
  160. }
  161. else
  162. {
  163. TraceMsg(TF_WMTHEME, "CClassFactory::QueryInterface() failed.");
  164. *ppvObj = NULL;
  165. return E_NOINTERFACE;
  166. }
  167. AddRef();
  168. return S_OK;
  169. }
  170. HRESULT CClassFactory_Create(REFCLSID rclsid, REFIID riid, LPVOID * ppvObj)
  171. {
  172. HRESULT hres;
  173. if (IsEqualCLSID(riid, IID_IClassFactory))
  174. {
  175. *ppvObj = (LPVOID) new CClassFactory(rclsid);
  176. hres = (*ppvObj) ? S_OK : E_OUTOFMEMORY;
  177. }
  178. else
  179. hres = ResultFromScode(E_NOINTERFACE);
  180. return hres;
  181. }