LibreOffice Module shell (master) 1
classfactory.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <global.hxx>
21#include "classfactory.hxx"
22#include <infotips.hxx>
23#include <propsheets.hxx>
24#include <columninfo.hxx>
25#include <thumbviewer.hxx>
26#include <shlxthdl.hxx>
27
28
30
31
32CClassFactory::CClassFactory(const CLSID& clsid) :
33 m_RefCnt(1),
34 m_Clsid(clsid)
35{
36 InterlockedIncrement(&g_DllRefCnt);
37}
38
39
41{
42 InterlockedDecrement(&g_DllRefCnt);
43}
44
45
46// IUnknown methods
47
48
49HRESULT STDMETHODCALLTYPE CClassFactory::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
50{
51 *ppvObject = nullptr;
52
53 if (IID_IUnknown == riid || IID_IClassFactory == riid)
54 {
55 IUnknown* pUnk = this;
56 pUnk->AddRef();
57 *ppvObject = pUnk;
58 return S_OK;
59 }
60
61 return E_NOINTERFACE;
62}
63
64
65ULONG STDMETHODCALLTYPE CClassFactory::AddRef()
66{
67 return InterlockedIncrement(&m_RefCnt);
68}
69
70
71ULONG STDMETHODCALLTYPE CClassFactory::Release()
72{
73 LONG refcnt = InterlockedDecrement(&m_RefCnt);
74
75 if (0 == refcnt)
76 delete this;
77
78 return refcnt;
79}
80
81
82// IClassFactory methods
83
84
85HRESULT STDMETHODCALLTYPE CClassFactory::CreateInstance(
86 IUnknown __RPC_FAR *pUnkOuter,
87 REFIID riid,
88 void __RPC_FAR *__RPC_FAR *ppvObject)
89{
90 if (pUnkOuter != nullptr)
91 return CLASS_E_NOAGGREGATION;
92
93 IUnknown* pUnk = nullptr;
94
96 pUnk = static_cast<IShellExtInit*>(new CPropertySheet());
97
99 pUnk = static_cast<IQueryInfo*>(new CInfoTip());
100
101 else if (CLSID_COLUMN_HANDLER == m_Clsid)
102 pUnk = new CColumnInfo();
103
105 pUnk = static_cast<IExtractImage*>(new CThumbviewer());
106
107 if (nullptr == pUnk)
108 {
109 return E_OUTOFMEMORY;
110 }
111
112 HRESULT hr = pUnk->QueryInterface(riid, ppvObject);
113
114 // if QueryInterface failed the component will destroy itself
115 pUnk->Release();
116
117 return hr;
118}
119
120
121HRESULT STDMETHODCALLTYPE CClassFactory::LockServer(BOOL fLock)
122{
123 if (fLock)
124 InterlockedIncrement(&s_ServerLocks);
125 else
126 InterlockedDecrement(&s_ServerLocks);
127
128 return S_OK;
129}
130
131
133{
134 return (s_ServerLocks > 0);
135}
136
137/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock) override
virtual HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown __RPC_FAR *pUnkOuter, REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject) override
virtual ULONG STDMETHODCALLTYPE Release() override
virtual ULONG STDMETHODCALLTYPE AddRef() override
CClassFactory(const CLSID &clsid)
virtual ~CClassFactory()
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject) override
static LONG s_ServerLocks
static bool IsLocked()
LONG g_DllRefCnt
Definition: propertyhdl.cxx:39
const wchar_t *typedef BOOL
LONG
const CLSID CLSID_PROPERTYSHEET_HANDLER
Definition: shlxthdl.hxx:35
const CLSID CLSID_THUMBVIEWER_HANDLER
Definition: shlxthdl.hxx:39
const CLSID CLSID_INFOTIP_HANDLER
Definition: shlxthdl.hxx:27
const CLSID CLSID_COLUMN_HANDLER
Definition: shlxthdl.hxx:31
return hr