-
Notifications
You must be signed in to change notification settings - Fork 208
/
Copy pathRuntime_Win.cpp
58 lines (45 loc) · 1.39 KB
/
Runtime_Win.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
#ifdef _WIN32
#include "Utils/Runtime.h"
#include "Utils/Platform.h"
#include "Utils/SafeWindows.hpp"
MAA_NS_BEGIN
static std::filesystem::path s_library_dir_cache;
const std::filesystem::path& library_dir()
{
return s_library_dir_cache;
}
void init_library_dir(HINSTANCE hinstDLL)
{
char buffer[MAX_PATH + 1] = { 0 };
GetModuleFileName(hinstDLL, buffer, MAX_PATH);
s_library_dir_cache = MAA_NS::path(buffer).parent_path();
}
MAA_NS_END
// https://learn.microsoft.com/zh-cn/windows/win32/dlls/dllmain
BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpvReserved) // reserved
{
// Perform actions based on the reason for calling.
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
// Initialize once for each new process.
// Return FALSE to fail DLL load.
MAA_NS::init_library_dir(hinstDLL);
break;
case DLL_THREAD_ATTACH:
// Do thread-specific initialization.
break;
case DLL_THREAD_DETACH:
// Do thread-specific cleanup.
break;
case DLL_PROCESS_DETACH:
if (lpvReserved != nullptr) {
break; // do not do cleanup if process termination scenario
}
// Perform any necessary cleanup.
break;
}
return TRUE; // Successful DLL_PROCESS_ATTACH.
}
#endif