This repository was archived by the owner on Feb 18, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include " Process.hpp"
2+
3+ Process::Process (const wchar_t *processName) {
4+ HANDLE hSnapshot;
5+ PROCESSENTRY32 processEntry = {};
6+ BOOL hResult;
7+
8+ hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS , 0 );
9+ if (hSnapshot == INVALID_HANDLE_VALUE ) {
10+ std::cerr << " Failed to create snapshot of processes" << std::endl;
11+ return ;
12+ }
13+
14+ processEntry.dwSize = sizeof (PROCESSENTRY32 );
15+ hResult = Process32First (hSnapshot, &processEntry);
16+
17+ while (hResult) {
18+ if (wcscmp (processName, processEntry.szExeFile ) == 0 ) {
19+ processId = processEntry.th32ProcessID ;
20+ break ;
21+ }
22+ hResult = Process32Next (hSnapshot, &processEntry);
23+ }
24+
25+ if (processId == 0 ) {
26+ std::wcerr << " Failed to find " << processName << std::endl;
27+ }
28+
29+ CloseHandle (hSnapshot);
30+ }
31+
32+ Process::~Process () {
33+ CloseHandle (hProcess);
34+ }
35+
36+ DWORD Process::GetProcessId () const {
37+ return processId;
38+ }
39+
40+ HANDLE Process::GetProcessHandle () const {
41+ return hProcess;
42+ }
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include < Windows.h>
4+ #include < iostream>
5+ #include < TlHelp32.h>
6+
7+ class Process {
8+ private:
9+ DWORD processId = 0 ;
10+ HANDLE hProcess = NULL ;
11+ public:
12+ Process () = delete ;
13+ Process (const wchar_t *processName);
14+ ~Process ();
15+
16+ DWORD GetProcessId () const ;
17+ HANDLE GetProcessHandle () const ;
18+ };
You can’t perform that action at this time.
0 commit comments