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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/* Benjamin DELPY `gentilkiwi`
http://blog.gentilkiwi.com
benjamin@gentilkiwi.com
Licence : http://creativecommons.org/licenses/by/3.0/fr/
*/
#include "mod_thread.h"
bool mod_thread::getList(vector<THREADENTRY32> * monVecteurThreads, DWORD * processId)
{
bool reussite = false;
HANDLE hThreadsSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if(hThreadsSnapshot != INVALID_HANDLE_VALUE)
{
THREADENTRY32 monThread;
monThread.dwSize = sizeof(THREADENTRY32);
if(reussite = (Thread32First(hThreadsSnapshot, &monThread) != 0))
{
do
{
if(!processId || (*processId == monThread.th32OwnerProcessID))
monVecteurThreads->push_back(monThread);
} while(Thread32Next(hThreadsSnapshot, &monThread));
}
CloseHandle(hThreadsSnapshot);
}
return reussite;
}
bool mod_thread::suspend(DWORD & threadId)
{
bool reussite = false;
HANDLE monHandle = OpenThread(THREAD_SUSPEND_RESUME, false, threadId);
if(reussite = (monHandle && monHandle != INVALID_HANDLE_VALUE))
{
SuspendThread(monHandle);
CloseHandle(monHandle);
}
return reussite;
}
bool mod_thread::resume(DWORD & threadId)
{
bool reussite = false;
HANDLE monHandle = OpenThread(THREAD_SUSPEND_RESUME, false, threadId);
if(reussite = (monHandle && monHandle != INVALID_HANDLE_VALUE))
{
ResumeThread(monHandle);
CloseHandle(monHandle);
}
return reussite;
}
bool mod_thread::stop(DWORD & threadId, DWORD exitCode)
{
bool reussite = false;
HANDLE monHandle = OpenThread(THREAD_TERMINATE, false, threadId);
if(reussite = (monHandle && monHandle != INVALID_HANDLE_VALUE))
{
TerminateThread(monHandle, exitCode);
CloseHandle(monHandle);
}
return reussite;
}
bool mod_thread::quit(DWORD & threadId)
{
return PostThreadMessage(threadId, WM_QUIT, NULL, NULL) != 0;
}
|