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.

110 lines
2.6 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  4. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  5. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  6. // PARTICULAR PURPOSE.
  7. //
  8. // Copyright 1998 Microsoft Corporation. All Rights Reserved.
  9. //
  10. // Author: Scott Roberts, Microsoft Developer Support - Internet Client SDK
  11. //
  12. // Portions of this code were taken from the bandobj sample that comes
  13. // with the Internet Client SDK for Internet Explorer 4.0x
  14. //
  15. //
  16. // ClsFact.cpp - CClassFactory Implementation
  17. /////////////////////////////////////////////////////////////////////////////
  18. #include "pch.hxx"
  19. #include "ClsFact.h"
  20. #include "Guid.h"
  21. ///////////////////////////////////////////////////////////////////////////
  22. //
  23. // IClassFactory Methods
  24. //
  25. CClassFactory::CClassFactory(CLSID clsid)
  26. : m_cRef(1),
  27. m_clsidObject(clsid)
  28. {
  29. InterlockedIncrement(&g_cDllRefCount);
  30. }
  31. CClassFactory::~CClassFactory()
  32. {
  33. InterlockedDecrement(&g_cDllRefCount);
  34. }
  35. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, LPVOID* ppvObject)
  36. {
  37. *ppvObject = NULL;
  38. if (IsEqualIID(riid, IID_IUnknown))
  39. *ppvObject = this;
  40. else if(IsEqualIID(riid, IID_IClassFactory))
  41. *ppvObject = static_cast<IClassFactory*>(this);
  42. if (*ppvObject)
  43. {
  44. static_cast<LPUNKNOWN>(*ppvObject)->AddRef();
  45. return S_OK;
  46. }
  47. return E_NOINTERFACE;
  48. }
  49. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  50. {
  51. return InterlockedIncrement(&m_cRef);
  52. }
  53. STDMETHODIMP_(ULONG) CClassFactory::Release()
  54. {
  55. if (0 == InterlockedDecrement(&m_cRef))
  56. {
  57. delete this;
  58. return 0;
  59. }
  60. return m_cRef;
  61. }
  62. STDMETHODIMP CClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppvObject)
  63. {
  64. HRESULT hr = E_FAIL;
  65. LPVOID pTemp = NULL;
  66. *ppvObject = NULL;
  67. if (pUnkOuter != NULL)
  68. return CLASS_E_NOAGGREGATION;
  69. // Create the proper object
  70. if (IsEqualCLSID(m_clsidObject, CLSID_BLHost))
  71. {
  72. CBLHost* pBLHost = new CBLHost();
  73. if (NULL == pBLHost)
  74. return E_OUTOFMEMORY;
  75. pTemp = pBLHost;
  76. }
  77. if (pTemp)
  78. {
  79. // QI for the requested interface
  80. hr = (static_cast<LPUNKNOWN>(pTemp))->QueryInterface(riid, ppvObject);
  81. // Call Release to decement the ref count
  82. (static_cast<LPUNKNOWN>(pTemp))->Release();
  83. }
  84. return hr;
  85. }
  86. STDMETHODIMP CClassFactory::LockServer(BOOL)
  87. {
  88. return E_NOTIMPL;
  89. }