Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / shell / source / win32 / shlxthandler / classfactory.cxx
blob1f4200521778adaf8a7fe11d15d5c05c1e31b139
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <global.hxx>
21 #include "classfactory.hxx"
22 #include <infotips.hxx>
23 #include <propsheets.hxx>
24 #include <columninfo.hxx>
25 #include <thumbviewer.hxx>
26 #include <shlxthdl.hxx>
29 long CClassFactory::s_ServerLocks = 0;
32 CClassFactory::CClassFactory(const CLSID& clsid) :
33 m_RefCnt(1),
34 m_Clsid(clsid)
36 InterlockedIncrement(&g_DllRefCnt);
40 CClassFactory::~CClassFactory()
42 InterlockedDecrement(&g_DllRefCnt);
46 // IUnknown methods
49 HRESULT STDMETHODCALLTYPE CClassFactory::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
51 *ppvObject = nullptr;
53 if (IID_IUnknown == riid || IID_IClassFactory == riid)
55 IUnknown* pUnk = this;
56 pUnk->AddRef();
57 *ppvObject = pUnk;
58 return S_OK;
61 return E_NOINTERFACE;
65 ULONG STDMETHODCALLTYPE CClassFactory::AddRef()
67 return InterlockedIncrement(&m_RefCnt);
71 ULONG STDMETHODCALLTYPE CClassFactory::Release()
73 long refcnt = InterlockedDecrement(&m_RefCnt);
75 if (0 == refcnt)
76 delete this;
78 return refcnt;
82 // IClassFactory methods
85 HRESULT STDMETHODCALLTYPE CClassFactory::CreateInstance(
86 IUnknown __RPC_FAR *pUnkOuter,
87 REFIID riid,
88 void __RPC_FAR *__RPC_FAR *ppvObject)
90 if (pUnkOuter != nullptr)
91 return CLASS_E_NOAGGREGATION;
93 IUnknown* pUnk = nullptr;
95 if (CLSID_PROPERTYSHEET_HANDLER == m_Clsid)
96 pUnk = static_cast<IShellExtInit*>(new CPropertySheet());
98 else if (CLSID_INFOTIP_HANDLER == m_Clsid)
99 pUnk = static_cast<IQueryInfo*>(new CInfoTip());
101 else if (CLSID_COLUMN_HANDLER == m_Clsid)
102 pUnk = static_cast<IColumnProvider*>(new CColumnInfo());
104 else if (CLSID_THUMBVIEWER_HANDLER == m_Clsid)
105 pUnk = static_cast<IExtractImage*>(new CThumbviewer());
107 if (nullptr == pUnk)
109 return E_OUTOFMEMORY;
112 HRESULT hr = pUnk->QueryInterface(riid, ppvObject);
114 // if QueryInterface failed the component will destroy itself
115 pUnk->Release();
117 return hr;
121 HRESULT STDMETHODCALLTYPE CClassFactory::LockServer(BOOL fLock)
123 if (fLock)
124 InterlockedIncrement(&s_ServerLocks);
125 else
126 InterlockedDecrement(&s_ServerLocks);
128 return S_OK;
132 bool CClassFactory::IsLocked()
134 return (s_ServerLocks > 0);
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */