-
Notifications
You must be signed in to change notification settings - Fork 7
/
process.hpp
52 lines (39 loc) · 1.21 KB
/
process.hpp
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
#pragma once
#include "safe_handle.hpp"
#include <windows.h>
#include <unordered_map>
#include <string>
#include <locale>
#include <codecvt>
#pragma warning(disable:4996) // DEPRECATED LIBRARY :(
using wstring_converter_t = std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>;
namespace native
{
class process
{
public:
process() noexcept { }
explicit process(HANDLE handle) noexcept : m_handle(handle) {}
explicit process(std::uint32_t id, std::uint32_t desired_access) noexcept :
m_handle(safe_handle(OpenProcess(desired_access, false, id))) { }
explicit process(std::string_view process_name, std::uint32_t desired_access) noexcept
{
const auto process_id = native::process::id_from_name(process_name);
if (!process_id)
return;
this->m_handle = safe_handle(OpenProcess(desired_access, false, process_id));
}
explicit operator bool() const noexcept
{
return this->handle().unsafe_handle() != nullptr;
}
// STATICS
static std::uint32_t id_from_name(std::string_view process_name) noexcept;
// INFORMATION
std::uint32_t get_id() const noexcept;
std::string get_name() const noexcept;
const safe_handle& handle() const noexcept;
private:
safe_handle m_handle;
};
}