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.

105 lines
1.8 KiB

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