forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassFactory.cpp
More file actions
80 lines (68 loc) · 1.43 KB
/
ClassFactory.cpp
File metadata and controls
80 lines (68 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "pch.h"
#include "ClassFactory.h"
#include "ExplorerCommand.h"
#include "dllmain.h"
// Class ctor/dtors
ClassFactory::ClassFactory(_In_ REFCLSID clsid) :
m_ref_count(1),
m_clsid(clsid)
{
++globals::ref_count;
}
ClassFactory::~ClassFactory()
{
--globals::ref_count;
}
// Implementations of inherited IUnknown methods
IFACEMETHODIMP ClassFactory::QueryInterface(REFIID riid, void** ppv)
{
static const QITAB qit[] = {
QITABENT(ClassFactory, IClassFactory),
{ 0, 0 },
};
return QISearch(this, qit, riid, ppv);
}
IFACEMETHODIMP_(ULONG) ClassFactory::AddRef()
{
return ++m_ref_count;
}
IFACEMETHODIMP_(ULONG) ClassFactory::Release()
{
auto result = --m_ref_count;
if (result == 0)
{
delete this;
}
return result;
}
// Implementations of inherited IClassFactory methods
IFACEMETHODIMP ClassFactory::CreateInstance(IUnknown* pUnkOuter, REFIID riid, void** ppvObject)
{
*ppvObject = NULL;
HRESULT hr;
if (pUnkOuter)
{
hr = CLASS_E_NOAGGREGATION;
}
else if (m_clsid == __uuidof(ExplorerCommand))
{
hr = ExplorerCommand::s_CreateInstance(pUnkOuter, riid, ppvObject);
}
else
{
hr = CLASS_E_CLASSNOTAVAILABLE;
}
return hr;
}
IFACEMETHODIMP ClassFactory::LockServer(BOOL fLock)
{
if (fLock)
{
++globals::ref_count;
}
else
{
--globals::ref_count;
}
return S_OK;
}