1 /**
2  * Windows API header module
3  *
4  * Translated from MinGW Windows headers
5  *
6  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7  * Source: $(DRUNTIMESRC core/sys/windows/_tlhelp32.d)
8  */
9 module core.sys.windows.tlhelp32;
10 version (Windows):
11 pragma(lib, "kernel32");
12 
13 version (ANSI) {} else version = Unicode;
14 
15 import core.sys.windows.windef;
16 
17 enum : uint {
18     HF32_DEFAULT = 1,
19     HF32_SHARED
20 }
21 
22 enum : uint {
23     LF32_FIXED    = 0x1,
24     LF32_FREE     = 0x2,
25     LF32_MOVEABLE = 0x4
26 }
27 
28 enum MAX_MODULE_NAME32 = 255;
29 
30 enum : uint {
31     TH32CS_SNAPHEAPLIST = 0x1,
32     TH32CS_SNAPPROCESS  = 0x2,
33     TH32CS_SNAPTHREAD   = 0x4,
34     TH32CS_SNAPMODULE   = 0x8,
35     TH32CS_SNAPALL      = (TH32CS_SNAPHEAPLIST|TH32CS_SNAPPROCESS|TH32CS_SNAPTHREAD|TH32CS_SNAPMODULE),
36     TH32CS_INHERIT      = 0x80000000
37 }
38 
39 struct HEAPLIST32 {
40     SIZE_T dwSize;
41     DWORD th32ProcessID;
42     ULONG_PTR th32HeapID;
43     DWORD dwFlags;
44 }
45 alias HEAPLIST32* PHEAPLIST32;
46 alias HEAPLIST32* LPHEAPLIST32;
47 
48 struct HEAPENTRY32 {
49     SIZE_T dwSize;
50     HANDLE hHandle;
51     ULONG_PTR dwAddress;
52     SIZE_T dwBlockSize;
53     DWORD dwFlags;
54     DWORD dwLockCount;
55     DWORD dwResvd;
56     DWORD th32ProcessID;
57     ULONG_PTR th32HeapID;
58 }
59 alias HEAPENTRY32* PHEAPENTRY32;
60 alias HEAPENTRY32* LPHEAPENTRY32;
61 
62 struct PROCESSENTRY32W {
63     DWORD dwSize;
64     DWORD cntUsage;
65     DWORD th32ProcessID;
66     ULONG_PTR th32DefaultHeapID;
67     DWORD th32ModuleID;
68     DWORD cntThreads;
69     DWORD th32ParentProcessID;
70     LONG pcPriClassBase;
71     DWORD dwFlags;
72     WCHAR[MAX_PATH] szExeFile = 0;
73 }
74 alias PROCESSENTRY32W* PPROCESSENTRY32W;
75 alias PROCESSENTRY32W* LPPROCESSENTRY32W;
76 
77 struct THREADENTRY32 {
78     DWORD dwSize;
79     DWORD cntUsage;
80     DWORD th32ThreadID;
81     DWORD th32OwnerProcessID;
82     LONG tpBasePri;
83     LONG tpDeltaPri;
84     DWORD dwFlags;
85 }
86 alias THREADENTRY32* PTHREADENTRY32;
87 alias THREADENTRY32* LPTHREADENTRY32;
88 
89 struct MODULEENTRY32W {
90     DWORD dwSize;
91     DWORD th32ModuleID;
92     DWORD th32ProcessID;
93     DWORD GlblcntUsage;
94     DWORD ProccntUsage;
95     BYTE *modBaseAddr;
96     DWORD modBaseSize;
97     HMODULE hModule;
98     WCHAR[MAX_MODULE_NAME32 + 1] szModule = 0;
99     WCHAR[MAX_PATH] szExePath = 0;
100 }
101 alias MODULEENTRY32W* PMODULEENTRY32W;
102 alias MODULEENTRY32W* LPMODULEENTRY32W;
103 
104 version (Unicode) {
105     alias PROCESSENTRY32W PROCESSENTRY32;
106     alias PPROCESSENTRY32W PPROCESSENTRY32;
107     alias LPPROCESSENTRY32W LPPROCESSENTRY32;
108 
109     alias MODULEENTRY32W MODULEENTRY32;
110     alias PMODULEENTRY32W PMODULEENTRY32;
111     alias LPMODULEENTRY32W LPMODULEENTRY32;
112 } else {
113     struct PROCESSENTRY32 {
114         DWORD dwSize;
115         DWORD cntUsage;
116         DWORD th32ProcessID;
117         ULONG_PTR th32DefaultHeapID;
118         DWORD th32ModuleID;
119         DWORD cntThreads;
120         DWORD th32ParentProcessID;
121         LONG pcPriClassBase;
122         DWORD dwFlags;
123         CHAR[MAX_PATH] szExeFile = 0;
124     }
125     alias PROCESSENTRY32* PPROCESSENTRY32;
126     alias PROCESSENTRY32* LPPROCESSENTRY32;
127 
128     struct MODULEENTRY32 {
129         DWORD dwSize;
130         DWORD th32ModuleID;
131         DWORD th32ProcessID;
132         DWORD GlblcntUsage;
133         DWORD ProccntUsage;
134         BYTE *modBaseAddr;
135         DWORD modBaseSize;
136         HMODULE hModule;
137         char[MAX_MODULE_NAME32 + 1] szModule = 0;
138         char[MAX_PATH] szExePath = 0;
139     }
140     alias MODULEENTRY32* PMODULEENTRY32;
141     alias MODULEENTRY32* LPMODULEENTRY32;
142 }
143 
144 
145 extern(Windows) nothrow @nogc {
146     BOOL Heap32First(LPHEAPENTRY32,DWORD,ULONG_PTR);
147     BOOL Heap32ListFirst(HANDLE,LPHEAPLIST32);
148     BOOL Heap32ListNext(HANDLE,LPHEAPLIST32);
149     BOOL Heap32Next(LPHEAPENTRY32);
150     BOOL Thread32First(HANDLE,LPTHREADENTRY32);
151     BOOL Thread32Next(HANDLE,LPTHREADENTRY32);
152     BOOL Toolhelp32ReadProcessMemory(DWORD,LPCVOID,LPVOID,SIZE_T,SIZE_T*);
153     HANDLE CreateToolhelp32Snapshot(DWORD,DWORD);
154     BOOL Module32FirstW(HANDLE,LPMODULEENTRY32W);
155     BOOL Module32NextW(HANDLE,LPMODULEENTRY32W);
156     BOOL Process32FirstW(HANDLE,LPPROCESSENTRY32W);
157     BOOL Process32NextW(HANDLE,LPPROCESSENTRY32W);
158 }
159 
160 version (Unicode) {
161     alias Module32FirstW Module32First;
162     alias Module32NextW Module32Next;
163     alias Process32FirstW Process32First;
164     alias Process32NextW Process32Next;
165 } else {
166     extern(Windows) nothrow @nogc {
167         BOOL Module32First(HANDLE,LPMODULEENTRY32);
168         BOOL Module32Next(HANDLE,LPMODULEENTRY32);
169         BOOL Process32First(HANDLE,LPPROCESSENTRY32);
170         BOOL Process32Next(HANDLE,LPPROCESSENTRY32);
171     }
172 }