-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathClassFactory.cpp
More file actions
64 lines (52 loc) · 1.4 KB
/
ClassFactory.cpp
File metadata and controls
64 lines (52 loc) · 1.4 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
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include "ClassFactory.h"
#include "CorProfiler.h"
ClassFactory::ClassFactory() : refCount(0)
{
}
ClassFactory::~ClassFactory()
{
}
HRESULT STDMETHODCALLTYPE ClassFactory::QueryInterface(REFIID riid, void **ppvObject)
{
if (riid == IID_IUnknown || riid == IID_IClassFactory)
{
*ppvObject = this;
this->AddRef();
return S_OK;
}
*ppvObject = nullptr;
return E_NOINTERFACE;
}
ULONG STDMETHODCALLTYPE ClassFactory::AddRef()
{
return std::atomic_fetch_add(&this->refCount, 1) + 1;
}
ULONG STDMETHODCALLTYPE ClassFactory::Release()
{
int count = std::atomic_fetch_sub(&this->refCount, 1) - 1;
if (count <= 0)
{
delete this;
}
return count;
}
HRESULT STDMETHODCALLTYPE ClassFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObject)
{
if (pUnkOuter != nullptr)
{
*ppvObject = nullptr;
return CLASS_E_NOAGGREGATION;
}
CorProfiler* profiler = new CorProfiler();
if (profiler == nullptr)
{
return E_FAIL;
}
return profiler->QueryInterface(riid, ppvObject);
}
HRESULT STDMETHODCALLTYPE ClassFactory::LockServer(BOOL fLock)
{
return S_OK;
}