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.

144 lines
3.4 KiB

  1. // --------------------------------------------------------------------------------
  2. // Factory.cpp
  3. // --------------------------------------------------------------------------------
  4. #include <windows.h>
  5. #include <ole2.h>
  6. #include "dllmain.h"
  7. #include "acctreg.h"
  8. #include "guids.h"
  9. ////////////////////////////////////////////////////////////////////////
  10. //
  11. // IClassFactory implementation
  12. //
  13. ////////////////////////////////////////////////////////////////////////
  14. class CClassFactory : public IClassFactory
  15. {
  16. public:
  17. CClassFactory(REFCLSID clsid) : m_cRef(1), m_clsid(clsid) { DllAddRef(); }
  18. ~CClassFactory() { DllRelease(); }
  19. // IUnknown
  20. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
  21. ULONG STDMETHODCALLTYPE AddRef(void);
  22. ULONG STDMETHODCALLTYPE Release(void);
  23. // IClassFactory
  24. HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown *punkOuter, REFIID riid, LPVOID *ppv);
  25. HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
  26. private:
  27. UINT m_cRef;
  28. CLSID m_clsid;
  29. };
  30. HRESULT STDMETHODCALLTYPE CClassFactory::QueryInterface(REFIID riid, void **ppvObject)
  31. {
  32. if (!ppvObject)
  33. return E_INVALIDARG;
  34. *ppvObject = NULL;
  35. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  36. {
  37. *ppvObject = (IClassFactory *)this;
  38. }
  39. else
  40. return E_NOINTERFACE;
  41. AddRef();
  42. return S_OK;
  43. }
  44. ULONG STDMETHODCALLTYPE CClassFactory::AddRef(void)
  45. {
  46. return ++m_cRef;
  47. }
  48. ULONG STDMETHODCALLTYPE CClassFactory::Release(void)
  49. {
  50. if (--m_cRef > 0)
  51. return m_cRef;
  52. delete this;
  53. return 0;
  54. }
  55. HRESULT STDMETHODCALLTYPE CClassFactory::CreateInstance(IUnknown *punkOuter, REFIID riid, LPVOID *ppv)
  56. {
  57. HRESULT hr;
  58. if (!ppv)
  59. return E_INVALIDARG;
  60. *ppv = NULL; // assume error
  61. if (punkOuter)
  62. return CLASS_E_NOAGGREGATION; // don't support aggregation
  63. if (IsEqualCLSID(m_clsid, CLSID_AcctReg))
  64. {
  65. // make sure we're the IMsgBox class factory
  66. CAcctReg *pAcctReg;
  67. if (pAcctReg = new CAcctReg())
  68. {
  69. hr = pAcctReg->QueryInterface(riid, ppv);
  70. // Note that the Release member will free the object, if QueryInterface
  71. // failed.
  72. pAcctReg->Release();
  73. }
  74. else
  75. {
  76. hr = E_OUTOFMEMORY;
  77. }
  78. }
  79. else
  80. {
  81. hr = E_NOINTERFACE;
  82. }
  83. return hr;
  84. }
  85. HRESULT STDMETHODCALLTYPE CClassFactory::LockServer(BOOL fLock)
  86. {
  87. return E_NOTIMPL;
  88. }
  89. // --------------------------------------------------------------------------------
  90. // DllGetClassObject
  91. // --------------------------------------------------------------------------------
  92. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
  93. {
  94. HRESULT hr;
  95. if (ppv == NULL)
  96. return E_INVALIDARG;
  97. if (IsEqualCLSID(rclsid, CLSID_AcctReg))
  98. {
  99. // caller want the class factory that can handout msgbox
  100. // objects...
  101. CClassFactory *pcf = new CClassFactory(rclsid);
  102. if (pcf)
  103. {
  104. hr = pcf->QueryInterface(riid, ppv);
  105. pcf->Release();
  106. }
  107. else
  108. hr = E_OUTOFMEMORY;
  109. }
  110. else
  111. hr = CLASS_E_CLASSNOTAVAILABLE;
  112. return hr;
  113. }