nextcloud-desktop/shell_integration/windows/NCOverlays/NCOverlayFactory.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
2.2 KiB
C++
Raw Normal View History

2014-07-30 19:20:55 +04:00
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
#include <windows.h>
#include <new>
#include "NCOverlayFactory.h"
#include "NCOverlay.h"
2014-07-30 19:20:55 +04:00
extern long dllReferenceCount;
NCOverlayFactory::NCOverlayFactory(int state)
: _referenceCount(1), _state(state)
2014-07-30 19:20:55 +04:00
{
InterlockedIncrement(&dllReferenceCount);
}
NCOverlayFactory::~NCOverlayFactory()
2014-07-30 19:20:55 +04:00
{
InterlockedDecrement(&dllReferenceCount);
}
IFACEMETHODIMP NCOverlayFactory::QueryInterface(REFIID riid, void **ppv)
2014-07-30 19:20:55 +04:00
{
HRESULT hResult = S_OK;
2014-07-30 19:20:55 +04:00
if (IsEqualIID(IID_IUnknown, riid) ||
IsEqualIID(IID_IClassFactory, riid))
{
*ppv = static_cast<IUnknown *>(this);
AddRef();
}
else
{
hResult = E_NOINTERFACE;
*ppv = nullptr;
2014-07-30 19:20:55 +04:00
}
return hResult;
}
IFACEMETHODIMP_(ULONG) NCOverlayFactory::AddRef()
2014-07-30 19:20:55 +04:00
{
return InterlockedIncrement(&_referenceCount);
}
IFACEMETHODIMP_(ULONG) NCOverlayFactory::Release()
2014-07-30 19:20:55 +04:00
{
ULONG cRef = InterlockedDecrement(&_referenceCount);
if (0 == cRef)
{
delete this;
}
return cRef;
}
IFACEMETHODIMP NCOverlayFactory::CreateInstance(
IUnknown *pUnkOuter, REFIID riid, void **ppv)
2014-07-30 19:20:55 +04:00
{
HRESULT hResult = CLASS_E_NOAGGREGATION;
2014-07-30 19:20:55 +04:00
if (pUnkOuter) { return hResult; }
2014-07-30 19:20:55 +04:00
hResult = E_OUTOFMEMORY;
auto lrOverlay = new (std::nothrow) NCOverlay(_state);
if (!lrOverlay) { return hResult; }
2014-07-30 19:20:55 +04:00
hResult = lrOverlay->QueryInterface(riid, ppv);
lrOverlay->Release();
2014-07-30 19:20:55 +04:00
return hResult;
2014-07-30 19:20:55 +04:00
}
IFACEMETHODIMP NCOverlayFactory::LockServer(BOOL fLock)
2014-07-30 19:20:55 +04:00
{
2014-08-04 17:40:08 +04:00
if (fLock) {
2014-07-30 19:20:55 +04:00
InterlockedIncrement(&dllReferenceCount);
2014-08-04 17:40:08 +04:00
} else {
2014-07-30 19:20:55 +04:00
InterlockedDecrement(&dllReferenceCount);
}
return S_OK;
}