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