Bump version to 5.0-14
[LibreOffice.git] / shell / source / win32 / shlxthandler / classfactory.cxx
blob977b3ce8168e89904cb26ca95e7cce687b1b71c8
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 "internal/global.hxx"
21 #include "classfactory.hxx"
22 #include "internal/infotips.hxx"
23 #include "internal/propsheets.hxx"
24 #include "internal/columninfo.hxx"
25 #ifdef __MINGW32__
26 #include <algorithm>
27 using ::std::max;
28 using ::std::min;
29 #endif
30 #include "internal/thumbviewer.hxx"
31 #include "internal/shlxthdl.hxx"
35 long CClassFactory::s_ServerLocks = 0;
39 CClassFactory::CClassFactory(const CLSID& clsid) :
40 m_RefCnt(1),
41 m_Clsid(clsid)
43 InterlockedIncrement(&g_DllRefCnt);
48 CClassFactory::~CClassFactory()
50 InterlockedDecrement(&g_DllRefCnt);
54 // IUnknown methods
57 HRESULT STDMETHODCALLTYPE CClassFactory::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
59 *ppvObject = 0;
61 if (IID_IUnknown == riid || IID_IClassFactory == riid)
63 IUnknown* pUnk = this;
64 pUnk->AddRef();
65 *ppvObject = pUnk;
66 return S_OK;
69 return E_NOINTERFACE;
74 ULONG STDMETHODCALLTYPE CClassFactory::AddRef()
76 return InterlockedIncrement(&m_RefCnt);
81 ULONG STDMETHODCALLTYPE CClassFactory::Release()
83 long refcnt = InterlockedDecrement(&m_RefCnt);
85 if (0 == refcnt)
86 delete this;
88 return refcnt;
92 // IClassFactory methods
95 HRESULT STDMETHODCALLTYPE CClassFactory::CreateInstance(
96 IUnknown __RPC_FAR *pUnkOuter,
97 REFIID riid,
98 void __RPC_FAR *__RPC_FAR *ppvObject)
100 if ((pUnkOuter != NULL))
101 return CLASS_E_NOAGGREGATION;
103 IUnknown* pUnk = 0;
105 if (CLSID_PROPERTYSHEET_HANDLER == m_Clsid)
106 pUnk = static_cast<IShellExtInit*>(new CPropertySheet());
108 else if (CLSID_INFOTIP_HANDLER == m_Clsid)
109 pUnk = static_cast<IQueryInfo*>(new CInfoTip());
111 else if (CLSID_COLUMN_HANDLER == m_Clsid)
112 pUnk = static_cast<IColumnProvider*>(new CColumnInfo());
114 else if (CLSID_THUMBVIEWER_HANDLER == m_Clsid)
115 pUnk = static_cast<IExtractImage*>(new CThumbviewer());
117 if (0 == pUnk)
119 return E_OUTOFMEMORY;
122 HRESULT hr = pUnk->QueryInterface(riid, ppvObject);
124 // if QueryInterface failed the component will destroy itself
125 pUnk->Release();
127 return hr;
132 HRESULT STDMETHODCALLTYPE CClassFactory::LockServer(BOOL fLock)
134 if (fLock)
135 InterlockedIncrement(&s_ServerLocks);
136 else
137 InterlockedDecrement(&s_ServerLocks);
139 return S_OK;
144 bool CClassFactory::IsLocked()
146 return (s_ServerLocks > 0);
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */