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 #undef OSL_DEBUG_LEVEL
23 #include <osl/diagnose.h>
25 #include "internal/global.hxx"
26 #include "classfactory.hxx"
27 #include "internal/infotips.hxx"
28 #include "internal/propsheets.hxx"
29 #include "internal/columninfo.hxx"
35 #include "internal/thumbviewer.hxx"
36 #include "internal/shlxthdl.hxx"
38 //-----------------------------
40 long CClassFactory::s_ServerLocks
= 0;
42 //-----------------------------
44 CClassFactory::CClassFactory(const CLSID
& clsid
) :
48 InterlockedIncrement(&g_DllRefCnt
);
51 //-----------------------------
53 CClassFactory::~CClassFactory()
55 InterlockedDecrement(&g_DllRefCnt
);
58 //-----------------------------
60 //-----------------------------
62 HRESULT STDMETHODCALLTYPE
CClassFactory::QueryInterface(REFIID riid
, void __RPC_FAR
*__RPC_FAR
*ppvObject
)
66 if (IID_IUnknown
== riid
|| IID_IClassFactory
== riid
)
68 IUnknown
* pUnk
= this;
77 //-----------------------------
79 ULONG STDMETHODCALLTYPE
CClassFactory::AddRef(void)
81 return InterlockedIncrement(&m_RefCnt
);
84 //-----------------------------
86 ULONG STDMETHODCALLTYPE
CClassFactory::Release(void)
88 long refcnt
= InterlockedDecrement(&m_RefCnt
);
96 //-----------------------------
97 // IClassFactory methods
98 //-----------------------------
100 HRESULT STDMETHODCALLTYPE
CClassFactory::CreateInstance(
101 IUnknown __RPC_FAR
*pUnkOuter
,
103 void __RPC_FAR
*__RPC_FAR
*ppvObject
)
105 if ((pUnkOuter
!= NULL
))
106 return CLASS_E_NOAGGREGATION
;
110 if (CLSID_PROPERTYSHEET_HANDLER
== m_Clsid
)
111 pUnk
= static_cast<IShellExtInit
*>(new CPropertySheet());
113 else if (CLSID_INFOTIP_HANDLER
== m_Clsid
)
114 pUnk
= static_cast<IQueryInfo
*>(new CInfoTip());
116 else if (CLSID_COLUMN_HANDLER
== m_Clsid
)
117 pUnk
= static_cast<IColumnProvider
*>(new CColumnInfo());
119 else if (CLSID_THUMBVIEWER_HANDLER
== m_Clsid
)
120 pUnk
= static_cast<IExtractImage
*>(new CThumbviewer());
122 OSL_POSTCOND(pUnk
!= 0, "Could not create COM object");
125 return E_OUTOFMEMORY
;
127 HRESULT hr
= pUnk
->QueryInterface(riid
, ppvObject
);
129 // if QueryInterface failed the component will destroy itself
135 //-----------------------------
137 HRESULT STDMETHODCALLTYPE
CClassFactory::LockServer(BOOL fLock
)
140 InterlockedIncrement(&s_ServerLocks
);
142 InterlockedDecrement(&s_ServerLocks
);
147 //-----------------------------
149 bool CClassFactory::IsLocked()
151 return (s_ServerLocks
> 0);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */