1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: classfactory.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_shell.hxx"
33 #include "internal/global.hxx"
34 #include "classfactory.hxx"
35 #include "internal/infotips.hxx"
36 #include "internal/propsheets.hxx"
37 #include "internal/columninfo.hxx"
43 #include "internal/thumbviewer.hxx"
44 #include "internal/shlxthdl.hxx"
46 //-----------------------------
48 //-----------------------------
50 long CClassFactory::s_ServerLocks
= 0;
52 //-----------------------------
54 //-----------------------------
56 CClassFactory::CClassFactory(const CLSID
& clsid
) :
60 InterlockedIncrement(&g_DllRefCnt
);
63 //-----------------------------
65 //-----------------------------
67 CClassFactory::~CClassFactory()
69 InterlockedDecrement(&g_DllRefCnt
);
72 //-----------------------------
74 //-----------------------------
76 HRESULT STDMETHODCALLTYPE
CClassFactory::QueryInterface(REFIID riid
, void __RPC_FAR
*__RPC_FAR
*ppvObject
)
80 if (IID_IUnknown
== riid
|| IID_IClassFactory
== riid
)
82 IUnknown
* pUnk
= this;
91 //-----------------------------
93 //-----------------------------
95 ULONG STDMETHODCALLTYPE
CClassFactory::AddRef(void)
97 return InterlockedIncrement(&m_RefCnt
);
100 //-----------------------------
102 //-----------------------------
104 ULONG STDMETHODCALLTYPE
CClassFactory::Release(void)
106 long refcnt
= InterlockedDecrement(&m_RefCnt
);
114 //-----------------------------
115 // IClassFactory methods
116 //-----------------------------
118 HRESULT STDMETHODCALLTYPE
CClassFactory::CreateInstance(
119 IUnknown __RPC_FAR
*pUnkOuter
,
121 void __RPC_FAR
*__RPC_FAR
*ppvObject
)
123 if ((pUnkOuter
!= NULL
))
124 return CLASS_E_NOAGGREGATION
;
128 if (CLSID_PROPERTYSHEET_HANDLER
== m_Clsid
)
129 pUnk
= static_cast<IShellExtInit
*>(new CPropertySheet());
131 else if (CLSID_INFOTIP_HANDLER
== m_Clsid
)
132 pUnk
= static_cast<IQueryInfo
*>(new CInfoTip());
134 else if (CLSID_COLUMN_HANDLER
== m_Clsid
)
135 pUnk
= static_cast<IColumnProvider
*>(new CColumnInfo());
137 else if (CLSID_THUMBVIEWER_HANDLER
== m_Clsid
)
138 pUnk
= static_cast<IExtractImage
*>(new CThumbviewer());
140 POST_CONDITION(pUnk
!= 0, "Could not create COM object");
143 return E_OUTOFMEMORY
;
145 HRESULT hr
= pUnk
->QueryInterface(riid
, ppvObject
);
147 // if QueryInterface failed the component will destroy itself
153 //-----------------------------
155 //-----------------------------
157 HRESULT STDMETHODCALLTYPE
CClassFactory::LockServer(BOOL fLock
)
160 InterlockedIncrement(&s_ServerLocks
);
162 InterlockedDecrement(&s_ServerLocks
);
167 //-----------------------------
169 //-----------------------------
171 bool CClassFactory::IsLocked()
173 return (s_ServerLocks
> 0);