1f8e2c85aSAndrew Rist /**************************************************************
2*0ba0bc4aSmseidel  *
3f8e2c85aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f8e2c85aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f8e2c85aSAndrew Rist  * distributed with this work for additional information
6f8e2c85aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f8e2c85aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f8e2c85aSAndrew Rist  * "License"); you may not use this file except in compliance
9f8e2c85aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*0ba0bc4aSmseidel  *
11f8e2c85aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*0ba0bc4aSmseidel  *
13f8e2c85aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f8e2c85aSAndrew Rist  * software distributed under the License is distributed on an
15f8e2c85aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f8e2c85aSAndrew Rist  * KIND, either express or implied.  See the License for the
17f8e2c85aSAndrew Rist  * specific language governing permissions and limitations
18f8e2c85aSAndrew Rist  * under the License.
19*0ba0bc4aSmseidel  *
20f8e2c85aSAndrew Rist  *************************************************************/
21f8e2c85aSAndrew Rist 
22f8e2c85aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_shell.hxx"
26cdf0e10cSrcweir #include "internal/global.hxx"
27cdf0e10cSrcweir #include "classfactory.hxx"
28cdf0e10cSrcweir #include "internal/infotips.hxx"
29cdf0e10cSrcweir #include "internal/propsheets.hxx"
30cdf0e10cSrcweir #include "internal/columninfo.hxx"
31cdf0e10cSrcweir #ifdef __MINGW32__
32cdf0e10cSrcweir #include <algorithm>
33cdf0e10cSrcweir using ::std::max;
34cdf0e10cSrcweir using ::std::min;
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #include "internal/thumbviewer.hxx"
37cdf0e10cSrcweir #include "internal/shlxthdl.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //-----------------------------
40cdf0e10cSrcweir //
41cdf0e10cSrcweir //-----------------------------
42cdf0e10cSrcweir 
43cdf0e10cSrcweir long CClassFactory::s_ServerLocks = 0;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //-----------------------------
46cdf0e10cSrcweir //
47cdf0e10cSrcweir //-----------------------------
48cdf0e10cSrcweir 
CClassFactory(const CLSID & clsid)49*0ba0bc4aSmseidel CClassFactory::CClassFactory(const CLSID& clsid) :
50*0ba0bc4aSmseidel 	m_RefCnt(1),
51cdf0e10cSrcweir 	m_Clsid(clsid)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	InterlockedIncrement(&g_DllRefCnt);
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir //-----------------------------
57cdf0e10cSrcweir //
58cdf0e10cSrcweir //-----------------------------
59cdf0e10cSrcweir 
~CClassFactory()60cdf0e10cSrcweir CClassFactory::~CClassFactory()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	InterlockedDecrement(&g_DllRefCnt);
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //-----------------------------
66cdf0e10cSrcweir // IUnknown methods
67cdf0e10cSrcweir //-----------------------------
68cdf0e10cSrcweir 
QueryInterface(REFIID riid,void __RPC_FAR * __RPC_FAR * ppvObject)69cdf0e10cSrcweir HRESULT STDMETHODCALLTYPE CClassFactory::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	*ppvObject = 0;
72cdf0e10cSrcweir 
73*0ba0bc4aSmseidel 	if (IID_IUnknown == riid || IID_IClassFactory == riid)
74cdf0e10cSrcweir 	{
75cdf0e10cSrcweir 		IUnknown* pUnk = this;
76cdf0e10cSrcweir 		pUnk->AddRef();
77cdf0e10cSrcweir 		*ppvObject = pUnk;
78cdf0e10cSrcweir 		return S_OK;
79cdf0e10cSrcweir 	}
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	return E_NOINTERFACE;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir //-----------------------------
85cdf0e10cSrcweir //
86cdf0e10cSrcweir //-----------------------------
87*0ba0bc4aSmseidel 
AddRef(void)88cdf0e10cSrcweir ULONG STDMETHODCALLTYPE CClassFactory::AddRef(void)
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	return InterlockedIncrement(&m_RefCnt);
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir //-----------------------------
94cdf0e10cSrcweir //
95cdf0e10cSrcweir //-----------------------------
96*0ba0bc4aSmseidel 
Release(void)97cdf0e10cSrcweir ULONG STDMETHODCALLTYPE CClassFactory::Release(void)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	long refcnt = InterlockedDecrement(&m_RefCnt);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	if (0 == refcnt)
102cdf0e10cSrcweir 		delete this;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	return refcnt;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir //-----------------------------
108cdf0e10cSrcweir // IClassFactory methods
109cdf0e10cSrcweir //-----------------------------
110cdf0e10cSrcweir 
CreateInstance(IUnknown __RPC_FAR * pUnkOuter,REFIID riid,void __RPC_FAR * __RPC_FAR * ppvObject)111*0ba0bc4aSmseidel HRESULT STDMETHODCALLTYPE CClassFactory::CreateInstance(
112*0ba0bc4aSmseidel 			IUnknown __RPC_FAR *pUnkOuter,
113*0ba0bc4aSmseidel 			REFIID riid,
114*0ba0bc4aSmseidel 			void __RPC_FAR *__RPC_FAR *ppvObject)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	if ((pUnkOuter != NULL))
117cdf0e10cSrcweir 		return CLASS_E_NOAGGREGATION;
118*0ba0bc4aSmseidel 
119cdf0e10cSrcweir 	IUnknown* pUnk = 0;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	if (CLSID_PROPERTYSHEET_HANDLER == m_Clsid)
122cdf0e10cSrcweir 		pUnk = static_cast<IShellExtInit*>(new CPropertySheet());
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	else if (CLSID_INFOTIP_HANDLER == m_Clsid)
125*0ba0bc4aSmseidel 		pUnk = static_cast<IQueryInfo*>(new CInfoTip());
126*0ba0bc4aSmseidel 
127cdf0e10cSrcweir 	else if (CLSID_COLUMN_HANDLER == m_Clsid)
128cdf0e10cSrcweir 		pUnk = static_cast<IColumnProvider*>(new CColumnInfo());
129cdf0e10cSrcweir 
130*0ba0bc4aSmseidel 	else if (CLSID_THUMBVIEWER_HANDLER == m_Clsid)
131*0ba0bc4aSmseidel 		pUnk = static_cast<IExtractImage*>(new CThumbviewer());
132*0ba0bc4aSmseidel 
133cdf0e10cSrcweir 	POST_CONDITION(pUnk != 0, "Could not create COM object");
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	if (0 == pUnk)
136cdf0e10cSrcweir 		return E_OUTOFMEMORY;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	HRESULT hr = pUnk->QueryInterface(riid, ppvObject);
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	// if QueryInterface failed the component will destroy itself
141cdf0e10cSrcweir 	pUnk->Release();
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	return hr;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir //-----------------------------
147cdf0e10cSrcweir //
148cdf0e10cSrcweir //-----------------------------
149*0ba0bc4aSmseidel 
LockServer(BOOL fLock)150cdf0e10cSrcweir HRESULT STDMETHODCALLTYPE CClassFactory::LockServer(BOOL fLock)
151cdf0e10cSrcweir {
152*0ba0bc4aSmseidel 	if (fLock)
153*0ba0bc4aSmseidel 		InterlockedIncrement(&s_ServerLocks);
154cdf0e10cSrcweir 	else
155cdf0e10cSrcweir 		InterlockedDecrement(&s_ServerLocks);
156*0ba0bc4aSmseidel 
157cdf0e10cSrcweir 	return S_OK;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir //-----------------------------
161cdf0e10cSrcweir //
162cdf0e10cSrcweir //-----------------------------
163cdf0e10cSrcweir 
IsLocked()164cdf0e10cSrcweir bool CClassFactory::IsLocked()
165cdf0e10cSrcweir {
166cdf0e10cSrcweir 	return (s_ServerLocks > 0);
167cdf0e10cSrcweir }
168*0ba0bc4aSmseidel 
169*0ba0bc4aSmseidel /* vim: set noet sw=4 ts=4: */
170