forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdllmain.cpp
More file actions
62 lines (52 loc) · 1.21 KB
/
dllmain.cpp
File metadata and controls
62 lines (52 loc) · 1.21 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
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
// Additional libraries to link
#pragma comment(lib, "shlwapi")
#include "ClassFactory.h"
#include "FileLocksmithLib/Trace.h"
namespace globals
{
HMODULE instance;
std::atomic<ULONG> ref_count;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
globals::instance = hModule;
Trace::RegisterProvider();
break;
case DLL_PROCESS_DETACH:
Trace::UnregisterProvider();
break;
}
return TRUE;
}
STDAPI DllRegisterServer()
{
return S_OK;
}
STDAPI DllUnregisterServer()
{
return S_OK;
}
STDAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void** ppv)
{
HRESULT result = E_FAIL;
*ppv = NULL;
ClassFactory* class_factory = new (std::nothrow) ClassFactory(clsid);
if (class_factory)
{
result = class_factory->QueryInterface(riid, ppv);
class_factory->Release();
}
return result;
}
STDAPI DllCanUnloadNow(void)
{
return globals::ref_count == 0 ? S_OK : S_FALSE;
}