NCOverlayFactory.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. #include <windows.h>
  15. #include <new>
  16. #include "NCOverlayFactory.h"
  17. #include "NCOverlay.h"
  18. extern long dllReferenceCount;
  19. NCOverlayFactory::NCOverlayFactory(int state)
  20. : _referenceCount(1), _state(state)
  21. {
  22. InterlockedIncrement(&dllReferenceCount);
  23. }
  24. NCOverlayFactory::~NCOverlayFactory()
  25. {
  26. InterlockedDecrement(&dllReferenceCount);
  27. }
  28. IFACEMETHODIMP NCOverlayFactory::QueryInterface(REFIID riid, void **ppv)
  29. {
  30. HRESULT hResult = S_OK;
  31. if (IsEqualIID(IID_IUnknown, riid) ||
  32. IsEqualIID(IID_IClassFactory, riid))
  33. {
  34. *ppv = static_cast<IUnknown *>(this);
  35. AddRef();
  36. }
  37. else
  38. {
  39. hResult = E_NOINTERFACE;
  40. *ppv = nullptr;
  41. }
  42. return hResult;
  43. }
  44. IFACEMETHODIMP_(ULONG) NCOverlayFactory::AddRef()
  45. {
  46. return InterlockedIncrement(&_referenceCount);
  47. }
  48. IFACEMETHODIMP_(ULONG) NCOverlayFactory::Release()
  49. {
  50. ULONG cRef = InterlockedDecrement(&_referenceCount);
  51. if (0 == cRef)
  52. {
  53. delete this;
  54. }
  55. return cRef;
  56. }
  57. IFACEMETHODIMP NCOverlayFactory::CreateInstance(
  58. IUnknown *pUnkOuter, REFIID riid, void **ppv)
  59. {
  60. HRESULT hResult = CLASS_E_NOAGGREGATION;
  61. if (pUnkOuter) { return hResult; }
  62. hResult = E_OUTOFMEMORY;
  63. auto lrOverlay = new (std::nothrow) NCOverlay(_state);
  64. if (!lrOverlay) { return hResult; }
  65. hResult = lrOverlay->QueryInterface(riid, ppv);
  66. lrOverlay->Release();
  67. return hResult;
  68. }
  69. IFACEMETHODIMP NCOverlayFactory::LockServer(BOOL fLock)
  70. {
  71. if (fLock) {
  72. InterlockedIncrement(&dllReferenceCount);
  73. } else {
  74. InterlockedDecrement(&dllReferenceCount);
  75. }
  76. return S_OK;
  77. }