nextcloud-desktop/shell_integration/windows/OCOverlays/OCOverlayFactory.cpp

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

93 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 "stdafx.h"
2014-07-30 19:20:55 +04:00
#include "OCOverlayFactory.h"
#include "OCOverlay.h"
extern long dllReferenceCount;
2014-08-04 17:40:08 +04:00
OCOverlayFactory::OCOverlayFactory(int state)
: _referenceCount(1), _state(state)
2014-07-30 19:20:55 +04:00
{
InterlockedIncrement(&dllReferenceCount);
}
OCOverlayFactory::~OCOverlayFactory()
{
InterlockedDecrement(&dllReferenceCount);
}
IFACEMETHODIMP OCOverlayFactory::QueryInterface(REFIID riid, void **ppv)
{
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 = NULL;
}
return hResult;
}
IFACEMETHODIMP_(ULONG) OCOverlayFactory::AddRef()
{
return InterlockedIncrement(&_referenceCount);
}
IFACEMETHODIMP_(ULONG) OCOverlayFactory::Release()
{
ULONG cRef = InterlockedDecrement(&_referenceCount);
if (0 == cRef)
{
delete this;
}
return cRef;
}
IFACEMETHODIMP OCOverlayFactory::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
2014-08-04 17:40:08 +04:00
if (pUnkOuter != NULL) { return hResult; }
2014-07-30 19:20:55 +04:00
hResult = E_OUTOFMEMORY;
2014-08-04 17:40:08 +04:00
OCOverlay *lrOverlay = new (std::nothrow) OCOverlay(_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 OCOverlayFactory::LockServer(BOOL fLock)
{
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;
}