-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.cpp
More file actions
90 lines (71 loc) · 1.48 KB
/
Factory.cpp
File metadata and controls
90 lines (71 loc) · 1.48 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
81
82
83
84
85
86
87
88
89
90
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <new>
#include "Globals.h"
#include "LangSound.h"
class Factory final : public IClassFactory
{
public:
STDMETHODIMP QueryInterface(REFIID riid, void** ppv) override
{
if (riid == IID_IUnknown ||
riid == IID_IClassFactory)
{
*ppv = this;
AddRef();
return S_OK;
}
*ppv = nullptr;
return E_NOINTERFACE;
}
STDMETHODIMP_(ULONG) AddRef() override
{
return 2;
}
STDMETHODIMP_(ULONG) Release() override
{
return 1;
}
STDMETHODIMP CreateInstance(IUnknown* outer, REFIID riid, void** ppv) override
{
if (outer)
return CLASS_E_NOAGGREGATION;
LangSound* obj = new(std::nothrow) LangSound();
if (!obj)
return E_OUTOFMEMORY;
const HRESULT hr =
obj->QueryInterface(
riid,
ppv);
obj->Release();
return hr;
}
STDMETHODIMP LockServer(BOOL) override
{
return S_OK;
}
Factory() = default;
Factory(const Factory&) = delete;
Factory& operator=(const Factory&) = delete;
Factory(Factory&&) = delete;
Factory& operator=(Factory&&) = delete;
~Factory() = default;
};
namespace
{
Factory g_factory;
}
extern "C" STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
if (!ppv)
return E_POINTER;
*ppv = nullptr;
if (rclsid != CLSID_LangSound)
return CLASS_E_CLASSNOTAVAILABLE;
return g_factory.QueryInterface(riid, ppv);
}
extern "C" STDAPI DllCanUnloadNow()
{
const long refs = g_cRefDll.load(std::memory_order_relaxed);
return (refs == 0) ? S_OK : S_FALSE;
}