Update git submodules
[LibreOffice.git] / shell / source / win32 / spsupp / spsuppClassFactory.cxx
blob2a95cf0506fe9fd0dc81cda55f73ca18673eddf8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <spsuppClassFactory.hpp>
11 #include <COMOpenDocuments.hpp>
13 LONG ClassFactory::m_nObjCount = 0;
14 LONG ClassFactory::m_nLockCount = 0;
16 ClassFactory::ClassFactory()
18 ::InterlockedIncrement(&m_nObjCount);
21 ClassFactory::~ClassFactory()
23 ::InterlockedDecrement(&m_nObjCount);
26 // IUnknown methods
28 STDMETHODIMP ClassFactory::QueryInterface(
29 REFIID riid,
30 void **ppvObject)
32 *ppvObject = nullptr;
33 if (IsEqualIID(riid, __uuidof(IUnknown)) ||
34 IsEqualIID(riid, __uuidof(IClassFactory)))
36 *ppvObject = static_cast<IClassFactory*>(this);
37 AddRef();
38 return S_OK;
40 return E_NOINTERFACE;
43 // IClassFactory methods
45 STDMETHODIMP ClassFactory::CreateInstance(
46 IUnknown *pUnkOuter,
47 REFIID riid,
48 void **ppvObject)
50 *ppvObject = nullptr;
51 if (pUnkOuter)
53 return CLASS_E_NOAGGREGATION;
56 COMOpenDocuments* pObj;
57 try {
58 pObj = new COMOpenDocuments;
60 catch (const COMOpenDocuments::Error& e) {
61 return e.val();
63 catch (...) {
64 return E_OUTOFMEMORY;
67 HRESULT hr = pObj->QueryInterface(riid, ppvObject);
68 pObj->Release();
69 return hr;
72 STDMETHODIMP ClassFactory::LockServer(BOOL fLock)
74 if (fLock)
75 ::InterlockedIncrement(&m_nLockCount);
76 else
77 ::InterlockedDecrement(&m_nLockCount);
78 return S_OK;
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */