-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathprocess.h
More file actions
48 lines (40 loc) · 1.36 KB
/
process.h
File metadata and controls
48 lines (40 loc) · 1.36 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
#pragma once
#ifndef PROCESS_H
#define PROCESS_H
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <TlHelp32.h>
#include <vector>
// Struct definition copy pasted from Microsoft's documentation.
// For some reason, TiHelp.h doesn't allow you to use the non-unicode version of this struct explicity
// You either explititly use the Unicode version by using PROCESSENTRY32W, or you use PROCESSENTRY32,
// which, if _UNICODE is defined, will resolve to PROCESSENTRY32W.
// Perhaps defining a completely new struct with just the stuff that's needed would be better
struct PROCESSENTRY32A
{
DWORD dwSize;
DWORD cntUsage;
DWORD th32ProcessID; // this process
ULONG_PTR th32DefaultHeapID;
DWORD th32ModuleID; // associated exe
DWORD cntThreads;
DWORD th32ParentProcessID; // this process's parent process
LONG pcPriClassBase; // Base priority of process's threads
DWORD dwFlags;
CHAR szExeFile[MAX_PATH]; // Path
} ;
class process {
public:
struct Pair {
HANDLE handle;
PROCESSENTRY32A process;
};
process();
~process();
Pair openProcess(const char* processName, char** errorMessage);
Pair openProcess(DWORD processId, char** errorMessage);
void closeProcess(HANDLE hProcess);
std::vector<PROCESSENTRY32A> getProcesses(char** errorMessage);
};
#endif
#pragma once