1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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
) :
36 InterlockedIncrement(&g_DllRefCnt
);
40 CClassFactory::~CClassFactory()
42 InterlockedDecrement(&g_DllRefCnt
);
49 HRESULT STDMETHODCALLTYPE
CClassFactory::QueryInterface(REFIID riid
, void __RPC_FAR
*__RPC_FAR
*ppvObject
)
53 if (IID_IUnknown
== riid
|| IID_IClassFactory
== riid
)
55 IUnknown
* pUnk
= this;
65 ULONG STDMETHODCALLTYPE
CClassFactory::AddRef()
67 return InterlockedIncrement(&m_RefCnt
);
71 ULONG STDMETHODCALLTYPE
CClassFactory::Release()
73 long refcnt
= InterlockedDecrement(&m_RefCnt
);
82 // IClassFactory methods
85 HRESULT STDMETHODCALLTYPE
CClassFactory::CreateInstance(
86 IUnknown __RPC_FAR
*pUnkOuter
,
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());
109 return E_OUTOFMEMORY
;
112 HRESULT hr
= pUnk
->QueryInterface(riid
, ppvObject
);
114 // if QueryInterface failed the component will destroy itself
121 HRESULT STDMETHODCALLTYPE
CClassFactory::LockServer(BOOL fLock
)
124 InterlockedIncrement(&s_ServerLocks
);
126 InterlockedDecrement(&s_ServerLocks
);
132 bool CClassFactory::IsLocked()
134 return (s_ServerLocks
> 0);
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */