-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMain_WIN32.cpp
More file actions
33 lines (28 loc) · 834 Bytes
/
Copy pathMain_WIN32.cpp
File metadata and controls
33 lines (28 loc) · 834 Bytes
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
#include "hacklib/Main.h"
#include <Windows.h>
#include <stdexcept>
static DWORD WINAPI ThreadFunc(LPVOID param)
{
auto self = (hl::StaticInitImpl*)param;
self->mainThread();
return 0;
}
void hl::StaticInitImpl::runMainThread()
{
// Must use WinAPI threads instead of std threads, because current std
// implementation blocks within the loader lock.
HANDLE hThread = CreateThread(NULL, 0, ThreadFunc, (LPVOID)this, 0, NULL);
if (hThread == NULL)
{
throw std::runtime_error(std::string("CreateThread failed with code ") + std::to_string(GetLastError()));
}
else
{
// Thread will be exited by suiciding with FreeLibraryAndExitThread.
CloseHandle(hThread);
}
}
void hl::StaticInitImpl::unloadSelf()
{
FreeLibraryAndExitThread(hl::GetCurrentModule(), 0);
}