-
Notifications
You must be signed in to change notification settings - Fork 5
/
ClassFactory.cpp
64 lines (49 loc) · 1.27 KB
/
ClassFactory.cpp
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
#include "ClassFactory.hpp"
STDMETHODIMP ClassFactory::CreateInstance(
_In_opt_ IUnknown* pUnknownOuter,
_In_ REFIID riid,
_COM_Outptr_ LPVOID* ppv)
{
COM_CLASS_NAME* pTaskHandler;
if (!ppv) { return E_INVALIDARG; }
if (pUnknownOuter) { return CLASS_E_NOAGGREGATION; }
pTaskHandler = new COM_CLASS_NAME();
if (!pTaskHandler) { return E_OUTOFMEMORY; }
return pTaskHandler->QueryInterface(riid, ppv);
}
STDMETHODIMP ClassFactory::LockServer(_In_ BOOL bLock)
{
UNREFERENCED_PARAMETER(bLock);
return S_OK;
}
STDMETHODIMP ClassFactory::QueryInterface(
_In_ REFIID riid,
_COM_Outptr_ LPVOID* ppv)
{
if (!ppv) { return E_INVALIDARG; }
if (IsEqualGUID(riid, IID_IUnknown))
{
*ppv = static_cast<IUnknown*>(this);
}
else if (IsEqualGUID(riid, IID_IClassFactory))
{
*ppv = static_cast<IClassFactory*>(this);
}
else {
*ppv = NULL;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
STDMETHODIMP_(ULONG) ClassFactory::AddRef()
{
return InterlockedIncrement(&m_nRefCount);
}
STDMETHODIMP_(ULONG) ClassFactory::Release()
{
LONG nRefCount = 0;
nRefCount = InterlockedDecrement(&m_nRefCount);
if (nRefCount == 0) delete this;
return nRefCount;
}