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.

181 lines
3.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 1999.
  5. //
  6. // File: ClassFactory.cpp
  7. //
  8. // Contents: com class factory routines
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "priv.h"
  12. #include "UserOM.h" // needed for class factory prototypes
  13. class CSHGinaFactory : public IClassFactory
  14. {
  15. public:
  16. // *** IUnknown ***
  17. virtual STDMETHODIMP_(ULONG) AddRef(void);
  18. virtual STDMETHODIMP_(ULONG) Release(void);
  19. virtual STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  20. // *** IClassFactory ***
  21. virtual STDMETHODIMP CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObject);
  22. virtual STDMETHODIMP LockServer(BOOL fLock);
  23. public:
  24. CSHGinaFactory(REFCLSID rclsid);
  25. ~CSHGinaFactory(void);
  26. // friend Functions
  27. friend HRESULT CSHGinaFactory_Create(REFCLSID rclsid, REFIID riid, LPVOID * ppvObj);
  28. protected:
  29. int _cRef;
  30. CLSID _rclsid;
  31. };
  32. //
  33. // IUnknown Interface
  34. //
  35. ULONG CSHGinaFactory::AddRef()
  36. {
  37. _cRef++;
  38. return _cRef;
  39. }
  40. ULONG CSHGinaFactory::Release()
  41. {
  42. ASSERT(_cRef > 0);
  43. _cRef--;
  44. if (_cRef > 0)
  45. {
  46. return _cRef;
  47. }
  48. delete this;
  49. return 0;
  50. }
  51. HRESULT CSHGinaFactory::QueryInterface(REFIID riid, void **ppvObj)
  52. {
  53. HRESULT hr = E_NOINTERFACE;
  54. *ppvObj = NULL;
  55. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  56. {
  57. *ppvObj = SAFECAST(this, IClassFactory*);
  58. AddRef();
  59. hr = S_OK;
  60. }
  61. return hr;
  62. }
  63. //
  64. // IClassFactory methods
  65. //
  66. HRESULT CSHGinaFactory::CreateInstance(IUnknown* punkOuter, REFIID riid, LPVOID* ppvObj)
  67. {
  68. HRESULT hr = ResultFromScode(REGDB_E_CLASSNOTREG);
  69. *ppvObj = NULL;
  70. if (!punkOuter)
  71. {
  72. if (IsEqualIID(_rclsid, CLSID_ShellLogonEnumUsers))
  73. {
  74. hr = CLogonEnumUsers_Create(riid, ppvObj);
  75. }
  76. else if (IsEqualIID(_rclsid, CLSID_ShellLogonUser))
  77. {
  78. hr = CLogonUser_Create(riid, ppvObj);
  79. }
  80. else if (IsEqualIID(_rclsid, CLSID_ShellLocalMachine))
  81. {
  82. hr = CLocalMachine_Create(riid, ppvObj);
  83. }
  84. else if (IsEqualIID(_rclsid, CLSID_ShellLogonStatusHost))
  85. {
  86. hr = CLogonStatusHost_Create(riid, ppvObj);
  87. }
  88. else
  89. {
  90. // What are you looking for?
  91. ASSERTMSG(FALSE, "CSHGinaFactory::CreateInstance unable to create object.");
  92. hr = E_FAIL;
  93. }
  94. }
  95. else
  96. {
  97. // Does anybody support aggregation any more?
  98. hr = ResultFromScode(CLASS_E_NOAGGREGATION);
  99. }
  100. return hr;
  101. }
  102. HRESULT CSHGinaFactory::LockServer(BOOL fLock)
  103. {
  104. if (fLock)
  105. {
  106. DllAddRef();
  107. }
  108. else
  109. {
  110. DllRelease();
  111. }
  112. return S_OK;
  113. }
  114. HRESULT CSHGinaFactory_Create(REFCLSID rclsid, REFIID riid, LPVOID* ppvObj)
  115. {
  116. HRESULT hr;
  117. *ppvObj = NULL;
  118. if (IsEqualIID(riid, IID_IClassFactory) ||
  119. IsEqualIID(riid, IID_IUnknown))
  120. {
  121. *ppvObj = (LPVOID) new CSHGinaFactory(rclsid);
  122. if (*ppvObj)
  123. {
  124. hr = S_OK;
  125. }
  126. else
  127. {
  128. hr = E_OUTOFMEMORY;
  129. }
  130. }
  131. else
  132. {
  133. hr = ResultFromScode(E_NOINTERFACE);
  134. }
  135. return hr;
  136. }
  137. CSHGinaFactory::CSHGinaFactory(REFCLSID rclsid) : _cRef(1)
  138. {
  139. _rclsid = rclsid;
  140. DllAddRef();
  141. }
  142. CSHGinaFactory::~CSHGinaFactory()
  143. {
  144. DllRelease();
  145. }