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.

100 lines
1.7 KiB

  1. #include "private.h"
  2. #include "factory.h"
  3. CClassFactory::CClassFactory(const CFactoryData *pFactoryData) :
  4. m_pFactoryData(pFactoryData)
  5. {
  6. m_cRef = 1;
  7. DllAddRef();
  8. }
  9. CClassFactory::~CClassFactory()
  10. {
  11. DllRelease();
  12. }
  13. // IUnknown members
  14. STDMETHODIMP CClassFactory::QueryInterface(
  15. REFIID riid, void **ppv)
  16. {
  17. if (NULL == ppv)
  18. {
  19. return E_INVALIDARG;
  20. }
  21. *ppv=NULL;
  22. // Validate requested interface
  23. if( IID_IUnknown == riid || IID_IClassFactory == riid )
  24. *ppv=this;
  25. // Addref through the interface
  26. if( NULL != *ppv ) {
  27. ((LPUNKNOWN)*ppv)->AddRef();
  28. return S_OK;
  29. }
  30. return E_NOINTERFACE;
  31. }
  32. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  33. {
  34. return ++m_cRef;
  35. }
  36. STDMETHODIMP_(ULONG) CClassFactory::Release()
  37. {
  38. if( 0L != --m_cRef )
  39. return m_cRef;
  40. delete this;
  41. return 0L;
  42. }
  43. // IClassFactory members
  44. STDMETHODIMP CClassFactory::CreateInstance(
  45. LPUNKNOWN punkOuter, REFIID riid, void **ppv)
  46. {
  47. HRESULT hr;
  48. if ((NULL == ppv) ||
  49. (punkOuter && (IID_IUnknown != riid)))
  50. {
  51. return E_INVALIDARG;
  52. }
  53. *ppv = NULL;
  54. if ((NULL != punkOuter) &&
  55. !(m_pFactoryData->m_dwFlags & FD_ALLOWAGGREGATION))
  56. {
  57. return CLASS_E_NOAGGREGATION;
  58. }
  59. IUnknown *punk;
  60. hr = m_pFactoryData->m_pCreateProc(punkOuter, &punk);
  61. if (SUCCEEDED(hr))
  62. {
  63. hr = punk->QueryInterface(riid, ppv);
  64. punk->Release();
  65. }
  66. return hr;
  67. }
  68. STDMETHODIMP CClassFactory::LockServer(BOOL fLock)
  69. {
  70. if (fLock)
  71. {
  72. DllLock();
  73. }
  74. else
  75. {
  76. DllUnlock();
  77. }
  78. return S_OK;
  79. }