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 .
20 #include "internal/global.hxx"
21 #include "classfactory.hxx"
22 #include "internal/infotips.hxx"
23 #include "internal/propsheets.hxx"
24 #include "internal/columninfo.hxx"
30 #include "internal/thumbviewer.hxx"
31 #include "internal/shlxthdl.hxx"
35 long CClassFactory::s_ServerLocks
= 0;
39 CClassFactory::CClassFactory(const CLSID
& clsid
) :
43 InterlockedIncrement(&g_DllRefCnt
);
48 CClassFactory::~CClassFactory()
50 InterlockedDecrement(&g_DllRefCnt
);
57 HRESULT STDMETHODCALLTYPE
CClassFactory::QueryInterface(REFIID riid
, void __RPC_FAR
*__RPC_FAR
*ppvObject
)
61 if (IID_IUnknown
== riid
|| IID_IClassFactory
== riid
)
63 IUnknown
* pUnk
= this;
74 ULONG STDMETHODCALLTYPE
CClassFactory::AddRef()
76 return InterlockedIncrement(&m_RefCnt
);
81 ULONG STDMETHODCALLTYPE
CClassFactory::Release()
83 long refcnt
= InterlockedDecrement(&m_RefCnt
);
92 // IClassFactory methods
95 HRESULT STDMETHODCALLTYPE
CClassFactory::CreateInstance(
96 IUnknown __RPC_FAR
*pUnkOuter
,
98 void __RPC_FAR
*__RPC_FAR
*ppvObject
)
100 if ((pUnkOuter
!= NULL
))
101 return CLASS_E_NOAGGREGATION
;
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());
119 return E_OUTOFMEMORY
;
122 HRESULT hr
= pUnk
->QueryInterface(riid
, ppvObject
);
124 // if QueryInterface failed the component will destroy itself
132 HRESULT STDMETHODCALLTYPE
CClassFactory::LockServer(BOOL fLock
)
135 InterlockedIncrement(&s_ServerLocks
);
137 InterlockedDecrement(&s_ServerLocks
);
144 bool CClassFactory::IsLocked()
146 return (s_ServerLocks
> 0);
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */