1 /**
2  * Windows API header module
3  *
4  * Translated from MinGW API for MS-Windows 3.12
5  *
6  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7  * Source: $(DRUNTIMESRC core/sys/windows/_winnt.d)
8  */
9 module core.sys.windows.winnt;
10 version (Windows):
11 
12 version (ANSI) {} else version = Unicode;
13 
14 public import core.sys.windows.basetsd, core.sys.windows.windef, core.sys.windows.winerror;
15 import core.sys.windows.w32api;
16 
17 /* Translation Notes:
18 The following macros are unneeded for D:
19 FIELD_OFFSET(t,f), CONTAINING_RECORD(address, type, field)
20 */
21 
22 alias void   VOID;
23 alias char   CHAR, CCHAR;
24 alias wchar  WCHAR;
25 alias bool   BOOLEAN;
26 alias byte   FCHAR;
27 alias ubyte  UCHAR;
28 alias short  SHORT;
29 alias ushort LANGID, FSHORT;
30 alias uint   LCID, FLONG, ACCESS_MASK;
31 alias long   LONGLONG, USN;
32 alias ulong  DWORDLONG, ULONGLONG;
33 
34 alias void*  PVOID, LPVOID;
35 alias char*  PSZ, PCHAR, PCCHAR, LPCH, PCH, LPSTR, PSTR;
36 alias wchar* PWCHAR, LPWCH, PWCH, LPWSTR, PWSTR;
37 alias bool*  PBOOLEAN;
38 alias ubyte* PUCHAR;
39 alias short* PSHORT;
40 alias int*   PLONG;
41 alias uint*  PLCID, PACCESS_MASK;
42 alias long*  PLONGLONG;
43 alias ulong* PDWORDLONG, PULONGLONG;
44 
45 // FIXME(MinGW) for __WIN64
46 alias void*  PVOID64;
47 
48 // const versions
49 alias const(char)*  PCCH, LPCCH, PCSTR, LPCSTR;
50 alias const(wchar)* LPCWCH, PCWCH, LPCWSTR, PCWSTR;
51 
52 alias PSTR* PZPSTR;
53 alias PWSTR* PZPWSTR;
54 
55 version (Unicode) {
56     alias WCHAR TCHAR, _TCHAR;
57 } else {
58     alias CHAR TCHAR, _TCHAR;
59 }
60 
61 alias TCHAR         TBYTE;
62 alias TCHAR*        PTCH , PTBYTE, LPTCH , PTSTR , LPTSTR , LP, PTCHAR;
63 alias const(TCHAR)* PCTCH,         LPCTCH, PCTSTR, LPCTSTR            ;
64 
65 enum char ANSI_NULL = '\0';
66 enum wchar UNICODE_NULL = '\0';
67 
68 enum APPLICATION_ERROR_MASK       = 0x20000000;
69 enum ERROR_SEVERITY_SUCCESS       = 0x00000000;
70 enum ERROR_SEVERITY_INFORMATIONAL = 0x40000000;
71 enum ERROR_SEVERITY_WARNING       = 0x80000000;
72 enum ERROR_SEVERITY_ERROR         = 0xC0000000;
73 
74 // MinGW: also in ddk/ntifs.h
75 enum : USHORT {
76     COMPRESSION_FORMAT_NONE     = 0x0000,
77     COMPRESSION_FORMAT_DEFAULT  = 0x0001,
78     COMPRESSION_FORMAT_LZNT1    = 0x0002,
79     COMPRESSION_ENGINE_STANDARD = 0x0000,
80     COMPRESSION_ENGINE_MAXIMUM  = 0x0100,
81     COMPRESSION_ENGINE_HIBER    = 0x0200
82 }
83 
84 // ACCESS_DENIED_OBJECT_ACE, etc
85 enum DWORD
86     ACE_OBJECT_TYPE_PRESENT           = 0x00000001,
87     ACE_INHERITED_OBJECT_TYPE_PRESENT = 0x00000002;
88 
89 // ACE_HEADER.AceType
90 // also in ddk/ntifs.h
91 enum : BYTE {
92     ACCESS_ALLOWED_ACE_TYPE,
93     ACCESS_DENIED_ACE_TYPE,
94     SYSTEM_AUDIT_ACE_TYPE,
95     SYSTEM_ALARM_ACE_TYPE
96 }
97 
98 // ACE_HEADER.AceFlags
99 enum BYTE
100     OBJECT_INHERIT_ACE         = 0x01,
101     CONTAINER_INHERIT_ACE      = 0x02,
102     NO_PROPAGATE_INHERIT_ACE   = 0x04,
103     INHERIT_ONLY_ACE           = 0x08,
104     INHERITED_ACE              = 0x10,
105     VALID_INHERIT_FLAGS        = 0x1F,
106     SUCCESSFUL_ACCESS_ACE_FLAG = 0x40,
107     FAILED_ACCESS_ACE_FLAG     = 0x80;
108 
109 // Access Mask Format
110 enum ACCESS_MASK
111     DELETE                   = 0x00010000,
112     READ_CONTROL             = 0x00020000,
113     WRITE_DAC                = 0x00040000,
114     WRITE_OWNER              = 0x00080000,
115     SYNCHRONIZE              = 0x00100000,
116     ACCESS_SYSTEM_SECURITY   = 0x01000000,
117     MAXIMUM_ALLOWED          = 0x02000000,
118     GENERIC_READ             = 0x80000000,
119     GENERIC_WRITE            = 0x40000000,
120     GENERIC_EXECUTE          = 0x20000000,
121     GENERIC_ALL              = 0x10000000,
122     STANDARD_RIGHTS_REQUIRED = 0x000F0000,
123     STANDARD_RIGHTS_READ     = 0x00020000,
124     STANDARD_RIGHTS_WRITE    = 0x00020000,
125     STANDARD_RIGHTS_EXECUTE  = 0x00020000,
126     STANDARD_RIGHTS_ALL      = 0x001F0000,
127     SPECIFIC_RIGHTS_ALL      = 0x0000FFFF;
128 
129 
130 enum DWORD INVALID_FILE_ATTRIBUTES = -1;
131 
132 // MinGW: Also in ddk/winddk.h
133 enum DWORD
134     FILE_LIST_DIRECTORY       = 0x00000001,
135     FILE_READ_DATA            = 0x00000001,
136     FILE_ADD_FILE             = 0x00000002,
137     FILE_WRITE_DATA           = 0x00000002,
138     FILE_ADD_SUBDIRECTORY     = 0x00000004,
139     FILE_APPEND_DATA          = 0x00000004,
140     FILE_CREATE_PIPE_INSTANCE = 0x00000004,
141     FILE_READ_EA              = 0x00000008,
142     FILE_READ_PROPERTIES      = 0x00000008,
143     FILE_WRITE_EA             = 0x00000010,
144     FILE_WRITE_PROPERTIES     = 0x00000010,
145     FILE_EXECUTE              = 0x00000020,
146     FILE_TRAVERSE             = 0x00000020,
147     FILE_DELETE_CHILD         = 0x00000040,
148     FILE_READ_ATTRIBUTES      = 0x00000080,
149     FILE_WRITE_ATTRIBUTES     = 0x00000100;
150 
151 enum DWORD
152     FILE_SHARE_READ        = 0x00000001,
153     FILE_SHARE_WRITE       = 0x00000002,
154     FILE_SHARE_DELETE      = 0x00000004,
155     FILE_SHARE_VALID_FLAGS = 0x00000007;
156 
157 enum DWORD
158     FILE_ATTRIBUTE_READONLY            = 0x00000001,
159     FILE_ATTRIBUTE_HIDDEN              = 0x00000002,
160     FILE_ATTRIBUTE_SYSTEM              = 0x00000004,
161     FILE_ATTRIBUTE_DIRECTORY           = 0x00000010,
162     FILE_ATTRIBUTE_ARCHIVE             = 0x00000020,
163     FILE_ATTRIBUTE_DEVICE              = 0x00000040,
164     FILE_ATTRIBUTE_NORMAL              = 0x00000080,
165     FILE_ATTRIBUTE_TEMPORARY           = 0x00000100,
166     FILE_ATTRIBUTE_SPARSE_FILE         = 0x00000200,
167     FILE_ATTRIBUTE_REPARSE_POINT       = 0x00000400,
168     FILE_ATTRIBUTE_COMPRESSED          = 0x00000800,
169     FILE_ATTRIBUTE_OFFLINE             = 0x00001000,
170     FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000,
171     FILE_ATTRIBUTE_ENCRYPTED           = 0x00004000,
172     FILE_ATTRIBUTE_VALID_FLAGS         = 0x00007fb7,
173     FILE_ATTRIBUTE_VALID_SET_FLAGS     = 0x000031a7;
174 
175 // These are not documented on MSDN
176 enum FILE_COPY_STRUCTURED_STORAGE = 0x00000041;
177 enum FILE_STRUCTURED_STORAGE      = 0x00000441;
178 
179 // Nor are these
180 enum FILE_VALID_OPTION_FLAGS          = 0x00ffffff;
181 enum FILE_VALID_PIPE_OPTION_FLAGS     = 0x00000032;
182 enum FILE_VALID_MAILSLOT_OPTION_FLAGS = 0x00000032;
183 enum FILE_VALID_SET_FLAGS             = 0x00000036;
184 
185 enum ULONG
186     FILE_SUPERSEDE           = 0x00000000,
187     FILE_OPEN                = 0x00000001,
188     FILE_CREATE              = 0x00000002,
189     FILE_OPEN_IF             = 0x00000003,
190     FILE_OVERWRITE           = 0x00000004,
191     FILE_OVERWRITE_IF        = 0x00000005,
192     FILE_MAXIMUM_DISPOSITION = 0x00000005;
193 
194 enum ULONG
195     FILE_DIRECTORY_FILE            = 0x00000001,
196     FILE_WRITE_THROUGH             = 0x00000002,
197     FILE_SEQUENTIAL_ONLY           = 0x00000004,
198     FILE_NO_INTERMEDIATE_BUFFERING = 0x00000008,
199     FILE_SYNCHRONOUS_IO_ALERT      = 0x00000010,
200     FILE_SYNCHRONOUS_IO_NONALERT   = 0x00000020,
201     FILE_NON_DIRECTORY_FILE        = 0x00000040,
202     FILE_CREATE_TREE_CONNECTION    = 0x00000080,
203     FILE_COMPLETE_IF_OPLOCKED      = 0x00000100,
204     FILE_NO_EA_KNOWLEDGE           = 0x00000200,
205     FILE_OPEN_FOR_RECOVERY         = 0x00000400,
206     FILE_RANDOM_ACCESS             = 0x00000800,
207     FILE_DELETE_ON_CLOSE           = 0x00001000,
208     FILE_OPEN_BY_FILE_ID           = 0x00002000,
209     FILE_OPEN_FOR_BACKUP_INTENT    = 0x00004000,
210     FILE_NO_COMPRESSION            = 0x00008000,
211     FILE_RESERVE_OPFILTER          = 0x00100000,
212     FILE_OPEN_REPARSE_POINT        = 0x00200000,
213     FILE_OPEN_NO_RECALL            = 0x00400000,
214     FILE_OPEN_FOR_FREE_SPACE_QUERY = 0x00800000;
215 
216 
217 enum ACCESS_MASK
218     FILE_ALL_ACCESS      = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x01FF,
219     FILE_GENERIC_EXECUTE = STANDARD_RIGHTS_EXECUTE | FILE_READ_ATTRIBUTES
220                            | FILE_EXECUTE | SYNCHRONIZE,
221     FILE_GENERIC_READ    = STANDARD_RIGHTS_READ | FILE_READ_DATA
222                            | FILE_READ_ATTRIBUTES | FILE_READ_EA | SYNCHRONIZE,
223     FILE_GENERIC_WRITE   = STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA
224                            | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | FILE_APPEND_DATA
225                            | SYNCHRONIZE;
226 
227 // MinGW: end winddk.h
228 // MinGW: also in ddk/ntifs.h
229 enum DWORD
230     FILE_NOTIFY_CHANGE_FILE_NAME    = 0x00000001,
231     FILE_NOTIFY_CHANGE_DIR_NAME     = 0x00000002,
232     FILE_NOTIFY_CHANGE_NAME         = 0x00000003,
233     FILE_NOTIFY_CHANGE_ATTRIBUTES   = 0x00000004,
234     FILE_NOTIFY_CHANGE_SIZE         = 0x00000008,
235     FILE_NOTIFY_CHANGE_LAST_WRITE   = 0x00000010,
236     FILE_NOTIFY_CHANGE_LAST_ACCESS  = 0x00000020,
237     FILE_NOTIFY_CHANGE_CREATION     = 0x00000040,
238     FILE_NOTIFY_CHANGE_EA           = 0x00000080,
239     FILE_NOTIFY_CHANGE_SECURITY     = 0x00000100,
240     FILE_NOTIFY_CHANGE_STREAM_NAME  = 0x00000200,
241     FILE_NOTIFY_CHANGE_STREAM_SIZE  = 0x00000400,
242     FILE_NOTIFY_CHANGE_STREAM_WRITE = 0x00000800,
243     FILE_NOTIFY_VALID_MASK          = 0x00000fff;
244 
245 enum DWORD
246     FILE_CASE_SENSITIVE_SEARCH      = 0x00000001,
247     FILE_CASE_PRESERVED_NAMES       = 0x00000002,
248     FILE_UNICODE_ON_DISK            = 0x00000004,
249     FILE_PERSISTENT_ACLS            = 0x00000008,
250     FILE_FILE_COMPRESSION           = 0x00000010,
251     FILE_VOLUME_QUOTAS              = 0x00000020,
252     FILE_SUPPORTS_SPARSE_FILES      = 0x00000040,
253     FILE_SUPPORTS_REPARSE_POINTS    = 0x00000080,
254     FILE_SUPPORTS_REMOTE_STORAGE    = 0x00000100,
255     FS_LFN_APIS                     = 0x00004000,
256     FILE_VOLUME_IS_COMPRESSED       = 0x00008000,
257     FILE_SUPPORTS_OBJECT_IDS        = 0x00010000,
258     FILE_SUPPORTS_ENCRYPTION        = 0x00020000,
259     FILE_NAMED_STREAMS              = 0x00040000,
260     FILE_READ_ONLY_VOLUME           = 0x00080000,
261     FILE_SEQUENTIAL_WRITE_ONCE      = 0x00100000,
262     FILE_SUPPORTS_TRANSACTIONS      = 0x00200000;
263 
264 // These are not documented on MSDN
265 enum ACCESS_MASK
266     IO_COMPLETION_QUERY_STATE  = 1,
267     IO_COMPLETION_MODIFY_STATE = 2,
268     IO_COMPLETION_ALL_ACCESS   = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 3;
269 // MinGW: end ntifs.h
270 
271 // MinGW: also in ddk/winddk.h
272 enum DWORD
273     DUPLICATE_CLOSE_SOURCE    = 1,
274     DUPLICATE_SAME_ACCESS     = 2,
275     DUPLICATE_SAME_ATTRIBUTES = 4;
276 // MinGW: end winddk.k
277 
278 enum DWORD
279     MAILSLOT_NO_MESSAGE   = -1,
280     MAILSLOT_WAIT_FOREVER = -1;
281 
282 enum ACCESS_MASK
283     PROCESS_TERMINATE         = 0x0001,
284     PROCESS_CREATE_THREAD     = 0x0002,
285     PROCESS_SET_SESSIONID     = 0x0004,
286     PROCESS_VM_OPERATION      = 0x0008,
287     PROCESS_VM_READ           = 0x0010,
288     PROCESS_VM_WRITE          = 0x0020,
289     PROCESS_DUP_HANDLE        = 0x0040,
290     PROCESS_CREATE_PROCESS    = 0x0080,
291     PROCESS_SET_QUOTA         = 0x0100,
292     PROCESS_SET_INFORMATION   = 0x0200,
293     PROCESS_QUERY_INFORMATION = 0x0400,
294     PROCESS_ALL_ACCESS        = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x0FFF;
295 
296 enum ACCESS_MASK
297     THREAD_TERMINATE            = 0x0001,
298     THREAD_SUSPEND_RESUME       = 0x0002,
299     THREAD_GET_CONTEXT          = 0x0008,
300     THREAD_SET_CONTEXT          = 0x0010,
301     THREAD_SET_INFORMATION      = 0x0020,
302     THREAD_QUERY_INFORMATION    = 0x0040,
303     THREAD_SET_THREAD_TOKEN     = 0x0080,
304     THREAD_IMPERSONATE          = 0x0100,
305     THREAD_DIRECT_IMPERSONATION = 0x0200,
306     THREAD_ALL_ACCESS           = STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3FF;
307 
308 // These are not documented on MSDN
309 enum THREAD_BASE_PRIORITY_LOWRT =  15;
310 enum THREAD_BASE_PRIORITY_MAX   =   2;
311 enum THREAD_BASE_PRIORITY_MIN   =  -2;
312 enum THREAD_BASE_PRIORITY_IDLE  = -15;
313 
314 enum DWORD EXCEPTION_NONCONTINUABLE      =  1;
315 enum size_t EXCEPTION_MAXIMUM_PARAMETERS = 15;
316 
317 // These are not documented on MSDN
318 enum ACCESS_MASK
319     MUTANT_QUERY_STATE = 1,
320     MUTANT_ALL_ACCESS =  STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | MUTANT_QUERY_STATE;
321 
322 enum ACCESS_MASK
323     TIMER_QUERY_STATE  = 1,
324     TIMER_MODIFY_STATE = 2,
325     TIMER_ALL_ACCESS   = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | TIMER_QUERY_STATE
326                          | TIMER_MODIFY_STATE;
327 
328 enum SID_IDENTIFIER_AUTHORITY
329     SECURITY_NULL_SID_AUTHORITY        = {[5: 0]},
330     SECURITY_WORLD_SID_AUTHORITY       = {[5: 1]},
331     SECURITY_LOCAL_SID_AUTHORITY       = {[5: 2]},
332     SECURITY_CREATOR_SID_AUTHORITY     = {[5: 3]},
333     SECURITY_NON_UNIQUE_AUTHORITY      = {[5: 4]},
334     SECURITY_NT_AUTHORITY              = {[5: 5]},
335     SECURITY_MANDATORY_LABEL_AUTHORITY = {[5: 6]};
336 
337 enum DWORD
338     SECURITY_NULL_RID                   =  0,
339     SECURITY_WORLD_RID                  =  0,
340     SECURITY_LOCAL_RID                  =  0,
341     SECURITY_CREATOR_OWNER_RID          =  0,
342     SECURITY_CREATOR_GROUP_RID          =  1,
343     SECURITY_DIALUP_RID                 =  1,
344     SECURITY_NETWORK_RID                =  2,
345     SECURITY_BATCH_RID                  =  3,
346     SECURITY_INTERACTIVE_RID            =  4,
347     SECURITY_LOGON_IDS_RID              =  5,
348     SECURITY_SERVICE_RID                =  6,
349     SECURITY_LOCAL_SYSTEM_RID           = 18,
350     SECURITY_BUILTIN_DOMAIN_RID         = 32,
351     SECURITY_PRINCIPAL_SELF_RID         = 10,
352     SECURITY_CREATOR_OWNER_SERVER_RID   =  2,
353     SECURITY_CREATOR_GROUP_SERVER_RID   =  3,
354     SECURITY_LOGON_IDS_RID_COUNT        =  3,
355     SECURITY_ANONYMOUS_LOGON_RID        =  7,
356     SECURITY_PROXY_RID                  =  8,
357     SECURITY_ENTERPRISE_CONTROLLERS_RID =  9,
358     SECURITY_SERVER_LOGON_RID           = SECURITY_ENTERPRISE_CONTROLLERS_RID,
359     SECURITY_AUTHENTICATED_USER_RID     = 11,
360     SECURITY_RESTRICTED_CODE_RID        = 12,
361     SECURITY_NT_NON_UNIQUE_RID          = 21,
362     SID_REVISION                        =  1;
363 
364 enum : DWORD {
365     DOMAIN_USER_RID_ADMIN        = 0x01F4,
366     DOMAIN_USER_RID_GUEST        = 0x01F5,
367     DOMAIN_GROUP_RID_ADMINS      = 0x0200,
368     DOMAIN_GROUP_RID_USERS       = 0x0201,
369     DOMAIN_ALIAS_RID_ADMINS      = 0x0220,
370     DOMAIN_ALIAS_RID_USERS       = 0x0221,
371     DOMAIN_ALIAS_RID_GUESTS      = 0x0222,
372     DOMAIN_ALIAS_RID_POWER_USERS = 0x0223,
373     DOMAIN_ALIAS_RID_ACCOUNT_OPS = 0x0224,
374     DOMAIN_ALIAS_RID_SYSTEM_OPS  = 0x0225,
375     DOMAIN_ALIAS_RID_PRINT_OPS   = 0x0226,
376     DOMAIN_ALIAS_RID_BACKUP_OPS  = 0x0227,
377     DOMAIN_ALIAS_RID_REPLICATOR  = 0x0228
378 }
379 
380 enum : WORD {
381     SECURITY_MANDATORY_UNTRUSTED_RID         = 0,
382     SECURITY_MANDATORY_LOW_RID               = 0x1000,
383     SECURITY_MANDATORY_MEDIUM_RID            = 0x2000,
384     SECURITY_MANDATORY_HIGH_RID              = 0x3000,
385     SECURITY_MANDATORY_SYSTEM_RID            = 0x4000,
386     SECURITY_MANDATORY_PROTECTED_PROCESS_RID = 0x5000,
387     SECURITY_MANDATORY_MAXIMUM_USER_RID      = SECURITY_MANDATORY_SYSTEM_RID
388 }
389 
390 const TCHAR[]
391     SE_CREATE_TOKEN_NAME           = "SeCreateTokenPrivilege",
392     SE_ASSIGNPRIMARYTOKEN_NAME     = "SeAssignPrimaryTokenPrivilege",
393     SE_LOCK_MEMORY_NAME            = "SeLockMemoryPrivilege",
394     SE_INCREASE_QUOTA_NAME         = "SeIncreaseQuotaPrivilege",
395     SE_UNSOLICITED_INPUT_NAME      = "SeUnsolicitedInputPrivilege",
396     SE_MACHINE_ACCOUNT_NAME        = "SeMachineAccountPrivilege",
397     SE_TCB_NAME                    = "SeTcbPrivilege",
398     SE_SECURITY_NAME               = "SeSecurityPrivilege",
399     SE_TAKE_OWNERSHIP_NAME         = "SeTakeOwnershipPrivilege",
400     SE_LOAD_DRIVER_NAME            = "SeLoadDriverPrivilege",
401     SE_SYSTEM_PROFILE_NAME         = "SeSystemProfilePrivilege",
402     SE_SYSTEMTIME_NAME             = "SeSystemtimePrivilege",
403     SE_PROF_SINGLE_PROCESS_NAME    = "SeProfileSingleProcessPrivilege",
404     SE_INC_BASE_PRIORITY_NAME      = "SeIncreaseBasePriorityPrivilege",
405     SE_CREATE_PAGEFILE_NAME        = "SeCreatePagefilePrivilege",
406     SE_CREATE_PERMANENT_NAME       = "SeCreatePermanentPrivilege",
407     SE_BACKUP_NAME                 = "SeBackupPrivilege",
408     SE_RESTORE_NAME                = "SeRestorePrivilege",
409     SE_SHUTDOWN_NAME               = "SeShutdownPrivilege",
410     SE_DEBUG_NAME                  = "SeDebugPrivilege",
411     SE_AUDIT_NAME                  = "SeAuditPrivilege",
412     SE_SYSTEM_ENVIRONMENT_NAME     = "SeSystemEnvironmentPrivilege",
413     SE_CHANGE_NOTIFY_NAME          = "SeChangeNotifyPrivilege",
414     SE_REMOTE_SHUTDOWN_NAME        = "SeRemoteShutdownPrivilege",
415     SE_CREATE_GLOBAL_NAME          = "SeCreateGlobalPrivilege",
416     SE_UNDOCK_NAME                 = "SeUndockPrivilege",
417     SE_MANAGE_VOLUME_NAME          = "SeManageVolumePrivilege",
418     SE_IMPERSONATE_NAME            = "SeImpersonatePrivilege",
419     SE_ENABLE_DELEGATION_NAME      = "SeEnableDelegationPrivilege",
420     SE_SYNC_AGENT_NAME             = "SeSyncAgentPrivilege",
421     SE_TRUSTED_CREDMAN_ACCESS_NAME = "SeTrustedCredManAccessPrivilege",
422     SE_RELABEL_NAME                = "SeRelabelPrivilege",
423     SE_INCREASE_WORKING_SET_NAME   = "SeIncreaseWorkingSetPrivilege",
424     SE_TIME_ZONE_NAME              = "SeTimeZonePrivilege",
425     SE_CREATE_SYMBOLIC_LINK_NAME   = "SeCreateSymbolicLinkPrivilege";
426 
427 enum DWORD
428     SE_GROUP_MANDATORY          = 0x00000001,
429     SE_GROUP_ENABLED_BY_DEFAULT = 0x00000002,
430     SE_GROUP_ENABLED            = 0x00000004,
431     SE_GROUP_OWNER              = 0x00000008,
432     SE_GROUP_USE_FOR_DENY_ONLY  = 0x00000010,
433     SE_GROUP_INTEGRITY          = 0x00000020,
434     SE_GROUP_INTEGRITY_ENABLED  = 0x00000040,
435     SE_GROUP_RESOURCE           = 0x20000000,
436     SE_GROUP_LOGON_ID           = 0xC0000000;
437 
438 // Primary language identifiers
439 enum : USHORT {
440     LANG_NEUTRAL,
441     LANG_ARABIC,
442     LANG_BULGARIAN,
443     LANG_CATALAN,
444     LANG_CHINESE,
445     LANG_CZECH,
446     LANG_DANISH,
447     LANG_GERMAN,
448     LANG_GREEK,
449     LANG_ENGLISH,
450     LANG_SPANISH,
451     LANG_FINNISH,
452     LANG_FRENCH,
453     LANG_HEBREW,
454     LANG_HUNGARIAN,
455     LANG_ICELANDIC,
456     LANG_ITALIAN,
457     LANG_JAPANESE,
458     LANG_KOREAN,
459     LANG_DUTCH,
460     LANG_NORWEGIAN,
461     LANG_POLISH,
462     LANG_PORTUGUESE,    // = 0x16
463     LANG_ROMANIAN          = 0x18,
464     LANG_RUSSIAN,
465     LANG_CROATIAN,      // = 0x1A
466     LANG_SERBIAN           = 0x1A,
467     LANG_BOSNIAN           = 0x1A,
468     LANG_SLOVAK,
469     LANG_ALBANIAN,
470     LANG_SWEDISH,
471     LANG_THAI,
472     LANG_TURKISH,
473     LANG_URDU,
474     LANG_INDONESIAN,
475     LANG_UKRAINIAN,
476     LANG_BELARUSIAN,
477     LANG_SLOVENIAN,
478     LANG_ESTONIAN,
479     LANG_LATVIAN,
480     LANG_LITHUANIAN,    // = 0x27
481     LANG_FARSI             = 0x29,
482     LANG_PERSIAN           = 0x29,
483     LANG_VIETNAMESE,
484     LANG_ARMENIAN,
485     LANG_AZERI,
486     LANG_BASQUE,
487     LANG_LOWER_SORBIAN, // = 0x2E
488     LANG_UPPER_SORBIAN     = 0x2E,
489     LANG_MACEDONIAN,    // = 0x2F
490     LANG_TSWANA            = 0x32,
491     LANG_XHOSA             = 0x34,
492     LANG_ZULU,
493     LANG_AFRIKAANS,
494     LANG_GEORGIAN,
495     LANG_FAEROESE,
496     LANG_HINDI,
497     LANG_MALTESE,
498     LANG_SAMI,
499     LANG_IRISH,         // = 0x3C
500     LANG_MALAY             = 0x3E,
501     LANG_KAZAK,
502     LANG_KYRGYZ,
503     LANG_SWAHILI,       // = 0x41
504     LANG_UZBEK             = 0x43,
505     LANG_TATAR,
506     LANG_BENGALI,
507     LANG_PUNJABI,
508     LANG_GUJARATI,
509     LANG_ORIYA,
510     LANG_TAMIL,
511     LANG_TELUGU,
512     LANG_KANNADA,
513     LANG_MALAYALAM,
514     LANG_ASSAMESE,
515     LANG_MARATHI,
516     LANG_SANSKRIT,
517     LANG_MONGOLIAN,
518     LANG_TIBETAN,
519     LANG_WELSH,
520     LANG_KHMER,
521     LANG_LAO,           // = 0x54
522     LANG_GALICIAN          = 0x56,
523     LANG_KONKANI,
524     LANG_MANIPURI,
525     LANG_SINDHI,
526     LANG_SYRIAC,
527     LANG_SINHALESE,     // = 0x5B
528     LANG_INUKTITUT         = 0x5D,
529     LANG_AMHARIC,
530     LANG_TAMAZIGHT,
531     LANG_KASHMIRI,
532     LANG_NEPALI,
533     LANG_FRISIAN,
534     LANG_PASHTO,
535     LANG_FILIPINO,
536     LANG_DIVEHI,        // = 0x65
537     LANG_HAUSA             = 0x68,
538     LANG_YORUBA            = 0x6A,
539     LANG_QUECHUA,
540     LANG_SOTHO,
541     LANG_BASHKIR,
542     LANG_LUXEMBOURGISH,
543     LANG_GREENLANDIC,
544     LANG_IGBO,          // = 0x70
545     LANG_TIGRIGNA          = 0x73,
546     LANG_YI                = 0x78,
547     LANG_MAPUDUNGUN        = 0x7A,
548     LANG_MOHAWK            = 0x7C,
549     LANG_BRETON            = 0x7E,
550     LANG_UIGHUR            = 0x80,
551     LANG_MAORI,
552     LANG_OCCITAN,
553     LANG_CORSICAN,
554     LANG_ALSATIAN,
555     LANG_YAKUT,
556     LANG_KICHE,
557     LANG_KINYARWANDA,
558     LANG_WOLOF,         // = 0x88
559     LANG_DARI              = 0x8C,
560     LANG_MALAGASY,      // = 0x8D
561 
562     LANG_SERBIAN_NEUTRAL   = 0x7C1A,
563     LANG_BOSNIAN_NEUTRAL   = 0x781A,
564 
565     LANG_INVARIANT         = 0x7F
566 }
567 
568 
569 // Sublanguage identifiers
570 enum : USHORT {
571     SUBLANG_NEUTRAL,
572     SUBLANG_DEFAULT,
573     SUBLANG_SYS_DEFAULT,
574     SUBLANG_CUSTOM_DEFAULT,                  // =  3
575     SUBLANG_UI_CUSTOM_DEFAULT                   =  3,
576     SUBLANG_CUSTOM_UNSPECIFIED,              // =  4
577 
578     SUBLANG_AFRIKAANS_SOUTH_AFRICA              =  1,
579     SUBLANG_ALBANIAN_ALBANIA                    =  1,
580     SUBLANG_ALSATIAN_FRANCE                     =  1,
581     SUBLANG_AMHARIC_ETHIOPIA                    =  1,
582 
583     SUBLANG_ARABIC_SAUDI_ARABIA                 =  1,
584     SUBLANG_ARABIC_IRAQ,
585     SUBLANG_ARABIC_EGYPT,
586     SUBLANG_ARABIC_LIBYA,
587     SUBLANG_ARABIC_ALGERIA,
588     SUBLANG_ARABIC_MOROCCO,
589     SUBLANG_ARABIC_TUNISIA,
590     SUBLANG_ARABIC_OMAN,
591     SUBLANG_ARABIC_YEMEN,
592     SUBLANG_ARABIC_SYRIA,
593     SUBLANG_ARABIC_JORDAN,
594     SUBLANG_ARABIC_LEBANON,
595     SUBLANG_ARABIC_KUWAIT,
596     SUBLANG_ARABIC_UAE,
597     SUBLANG_ARABIC_BAHRAIN,
598     SUBLANG_ARABIC_QATAR,                    // = 16
599 
600     SUBLANG_ARMENIAN_ARMENIA                    =  1,
601     SUBLANG_ASSAMESE_INDIA                      =  1,
602 
603     SUBLANG_AZERI_LATIN                         =  1,
604     SUBLANG_AZERI_CYRILLIC,                  // =  2
605 
606     SUBLANG_BASHKIR_RUSSIA                      =  1,
607     SUBLANG_BASQUE_BASQUE                       =  1,
608     SUBLANG_BELARUSIAN_BELARUS                  =  1,
609     SUBLANG_BENGALI_INDIA                       =  1,
610 
611     SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN    =  5,
612     SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC =  8,
613 
614     SUBLANG_BRETON_FRANCE                       =  1,
615     SUBLANG_BULGARIAN_BULGARIA                  =  1,
616     SUBLANG_CATALAN_CATALAN                     =  1,
617 
618     SUBLANG_CHINESE_TRADITIONAL                 =  1,
619     SUBLANG_CHINESE_SIMPLIFIED,
620     SUBLANG_CHINESE_HONGKONG,
621     SUBLANG_CHINESE_SINGAPORE,
622     SUBLANG_CHINESE_MACAU,                   // =  5
623 
624     SUBLANG_CORSICAN_FRANCE                     =  1,
625 
626     SUBLANG_CROATIAN_CROATIA                    =  1,
627     SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN   =  4,
628 
629     SUBLANG_CZECH_CZECH_REPUBLIC                =  1,
630     SUBLANG_DANISH_DENMARK                      =  1,
631     SUBLANG_DIVEHI_MALDIVES                     =  1,
632 
633     SUBLANG_DUTCH                               =  1,
634     SUBLANG_DUTCH_BELGIAN,                   // =  2
635 
636     SUBLANG_ENGLISH_US                          =  1,
637     SUBLANG_ENGLISH_UK,
638     SUBLANG_ENGLISH_AUS,
639     SUBLANG_ENGLISH_CAN,
640     SUBLANG_ENGLISH_NZ,
641     SUBLANG_ENGLISH_EIRE,                    // =  6
642     SUBLANG_ENGLISH_IRELAND                     =  6,
643     SUBLANG_ENGLISH_SOUTH_AFRICA,
644     SUBLANG_ENGLISH_JAMAICA,
645     SUBLANG_ENGLISH_CARIBBEAN,
646     SUBLANG_ENGLISH_BELIZE,
647     SUBLANG_ENGLISH_TRINIDAD,
648     SUBLANG_ENGLISH_ZIMBABWE,
649     SUBLANG_ENGLISH_PHILIPPINES,             // = 13
650     SUBLANG_ENGLISH_INDIA                       = 16,
651     SUBLANG_ENGLISH_MALAYSIA,
652     SUBLANG_ENGLISH_SINGAPORE,               // = 18
653 
654     SUBLANG_ESTONIAN_ESTONIA                    =  1,
655     SUBLANG_FAEROESE_FAROE_ISLANDS              =  1,
656     SUBLANG_FILIPINO_PHILIPPINES                =  1,
657     SUBLANG_FINNISH_FINLAND                     =  1,
658 
659     SUBLANG_FRENCH                              =  1,
660     SUBLANG_FRENCH_BELGIAN,
661     SUBLANG_FRENCH_CANADIAN,
662     SUBLANG_FRENCH_SWISS,
663     SUBLANG_FRENCH_LUXEMBOURG,
664     SUBLANG_FRENCH_MONACO,                   // =  6
665 
666     SUBLANG_FRISIAN_NETHERLANDS                 =  1,
667     SUBLANG_GALICIAN_GALICIAN                   =  1,
668     SUBLANG_GEORGIAN_GEORGIA                    =  1,
669 
670     SUBLANG_GERMAN                              =  1,
671     SUBLANG_GERMAN_SWISS,
672     SUBLANG_GERMAN_AUSTRIAN,
673     SUBLANG_GERMAN_LUXEMBOURG,
674     SUBLANG_GERMAN_LIECHTENSTEIN,            // =  5
675 
676     SUBLANG_GREEK_GREECE                        =  1,
677     SUBLANG_GREENLANDIC_GREENLAND               =  1,
678     SUBLANG_GUJARATI_INDIA                      =  1,
679     SUBLANG_HAUSA_NIGERIA                       =  1,
680     SUBLANG_HEBREW_ISRAEL                       =  1,
681     SUBLANG_HINDI_INDIA                         =  1,
682     SUBLANG_HUNGARIAN_HUNGARY                   =  1,
683     SUBLANG_ICELANDIC_ICELAND                   =  1,
684     SUBLANG_IGBO_NIGERIA                        =  1,
685     SUBLANG_INDONESIAN_INDONESIA                =  1,
686 
687     SUBLANG_INUKTITUT_CANADA                    =  1,
688     SUBLANG_INUKTITUT_CANADA_LATIN              =  1,
689 
690     SUBLANG_IRISH_IRELAND                       =  1,
691 
692     SUBLANG_ITALIAN                             =  1,
693     SUBLANG_ITALIAN_SWISS,                   // =  2
694 
695     SUBLANG_JAPANESE_JAPAN                      =  1,
696 
697     SUBLANG_KASHMIRI_INDIA                      =  2,
698     SUBLANG_KASHMIRI_SASIA                      =  2,
699 
700     SUBLANG_KAZAK_KAZAKHSTAN                    =  1,
701     SUBLANG_KHMER_CAMBODIA                      =  1,
702     SUBLANG_KICHE_GUATEMALA                     =  1,
703     SUBLANG_KINYARWANDA_RWANDA                  =  1,
704     SUBLANG_KONKANI_INDIA                       =  1,
705     SUBLANG_KOREAN                              =  1,
706     SUBLANG_KOREAN_JOHAB                        =  2,
707     SUBLANG_KYRGYZ_KYRGYZSTAN                   =  1,
708     SUBLANG_LAO_LAO_PDR                         =  1,
709     SUBLANG_LATVIAN_LATVIA                      =  1,
710 
711     SUBLANG_LITHUANIAN                          =  1,
712     SUBLANG_LITHUANIAN_LITHUANIA                =  1,
713 
714     SUBLANG_LOWER_SORBIAN_GERMANY               =  1,
715     SUBLANG_LUXEMBOURGISH_LUXEMBOURG            =  1,
716     SUBLANG_MACEDONIAN_MACEDONIA                =  1,
717     SUBLANG_MALAYALAM_INDIA                     =  1,
718     SUBLANG_MALTESE_MALTA                       =  1,
719     SUBLANG_MAORI_NEW_ZEALAND                   =  1,
720     SUBLANG_MAPUDUNGUN_CHILE                    =  1,
721     SUBLANG_MARATHI_INDIA                       =  1,
722     SUBLANG_MOHAWK_MOHAWK                       =  1,
723 
724     SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA         =  1,
725     SUBLANG_MONGOLIAN_PRC,                   // =  2
726 
727     SUBLANG_MALAY_MALAYSIA                      =  1,
728     SUBLANG_MALAY_BRUNEI_DARUSSALAM,         // =  2
729 
730     SUBLANG_NEPALI_NEPAL                        =  1,
731     SUBLANG_NEPALI_INDIA,                    // =  2
732 
733     SUBLANG_NORWEGIAN_BOKMAL                    =  1,
734     SUBLANG_NORWEGIAN_NYNORSK,               // =  2
735 
736     SUBLANG_OCCITAN_FRANCE                      =  1,
737     SUBLANG_ORIYA_INDIA                         =  1,
738     SUBLANG_PASHTO_AFGHANISTAN                  =  1,
739     SUBLANG_PERSIAN_IRAN                        =  1,
740     SUBLANG_POLISH_POLAND                       =  1,
741 
742     SUBLANG_PORTUGUESE_BRAZILIAN                =  1,
743     SUBLANG_PORTUGUESE                          =  2,
744     SUBLANG_PORTUGUESE_PORTUGAL,             // =  2
745 
746     SUBLANG_PUNJABI_INDIA                       =  1,
747 
748     SUBLANG_QUECHUA_BOLIVIA                     =  1,
749     SUBLANG_QUECHUA_ECUADOR,
750     SUBLANG_QUECHUA_PERU,                    // =  3
751 
752     SUBLANG_ROMANIAN_ROMANIA                    =  1,
753     SUBLANG_ROMANSH_SWITZERLAND                 =  1,
754     SUBLANG_RUSSIAN_RUSSIA                      =  1,
755 
756     SUBLANG_SAMI_NORTHERN_NORWAY                =  1,
757     SUBLANG_SAMI_NORTHERN_SWEDEN,
758     SUBLANG_SAMI_NORTHERN_FINLAND,           // =  3
759     SUBLANG_SAMI_SKOLT_FINLAND                  =  3,
760     SUBLANG_SAMI_INARI_FINLAND                  =  3,
761     SUBLANG_SAMI_LULE_NORWAY,
762     SUBLANG_SAMI_LULE_SWEDEN,
763     SUBLANG_SAMI_SOUTHERN_NORWAY,
764     SUBLANG_SAMI_SOUTHERN_SWEDEN,            // =  7
765 
766     SUBLANG_SANSKRIT_INDIA                      =  1,
767 
768     SUBLANG_SERBIAN_LATIN                       =  2,
769     SUBLANG_SERBIAN_CYRILLIC,                // =  3
770     SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_LATIN    =  6,
771     SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_CYRILLIC =  7,
772 
773     SUBLANG_SINDHI_AFGHANISTAN                  =  2,
774     SUBLANG_SINHALESE_SRI_LANKA                 =  1,
775     SUBLANG_SOTHO_NORTHERN_SOUTH_AFRICA         =  1,
776     SUBLANG_SLOVAK_SLOVAKIA                     =  1,
777     SUBLANG_SLOVENIAN_SLOVENIA                  =  1,
778 
779     SUBLANG_SPANISH                             =  1,
780     SUBLANG_SPANISH_MEXICAN,
781     SUBLANG_SPANISH_MODERN,
782     SUBLANG_SPANISH_GUATEMALA,
783     SUBLANG_SPANISH_COSTA_RICA,
784     SUBLANG_SPANISH_PANAMA,
785     SUBLANG_SPANISH_DOMINICAN_REPUBLIC,
786     SUBLANG_SPANISH_VENEZUELA,
787     SUBLANG_SPANISH_COLOMBIA,
788     SUBLANG_SPANISH_PERU,
789     SUBLANG_SPANISH_ARGENTINA,
790     SUBLANG_SPANISH_ECUADOR,
791     SUBLANG_SPANISH_CHILE,
792     SUBLANG_SPANISH_URUGUAY,
793     SUBLANG_SPANISH_PARAGUAY,
794     SUBLANG_SPANISH_BOLIVIA,
795     SUBLANG_SPANISH_EL_SALVADOR,
796     SUBLANG_SPANISH_HONDURAS,
797     SUBLANG_SPANISH_NICARAGUA,
798     SUBLANG_SPANISH_PUERTO_RICO,
799     SUBLANG_SPANISH_US,                      // = 21
800 
801     SUBLANG_SWEDISH                             =  1,
802     SUBLANG_SWEDISH_SWEDEN                      =  1,
803     SUBLANG_SWEDISH_FINLAND,                 // =  2
804 
805     SUBLANG_SYRIAC                              =  1,
806     SUBLANG_TAJIK_TAJIKISTAN                    =  1,
807     SUBLANG_TAMAZIGHT_ALGERIA_LATIN             =  2,
808     SUBLANG_TAMIL_INDIA                         =  1,
809     SUBLANG_TATAR_RUSSIA                        =  1,
810     SUBLANG_TELUGU_INDIA                        =  1,
811     SUBLANG_THAI_THAILAND                       =  1,
812     SUBLANG_TIBETAN_PRC                         =  1,
813     SUBLANG_TIBETAN_BHUTAN                      =  2,
814     SUBLANG_TIGRIGNA_ERITREA                    =  1,
815     SUBLANG_TSWANA_SOUTH_AFRICA                 =  1,
816     SUBLANG_TURKISH_TURKEY                      =  1,
817     SUBLANG_TURKMEN_TURKMENISTAN                =  1,
818     SUBLANG_UIGHUR_PRC                          =  1,
819     SUBLANG_UKRAINIAN_UKRAINE                   =  1,
820     SUBLANG_UPPER_SORBIAN_GERMANY               =  1,
821 
822     SUBLANG_URDU_PAKISTAN                       =  1,
823     SUBLANG_URDU_INDIA,                      // =  2
824 
825     SUBLANG_UZBEK_LATIN                         =  1,
826     SUBLANG_UZBEK_CYRILLIC,                  // =  2
827 
828     SUBLANG_VIETNAMESE_VIETNAM                  =  1,
829     SUBLANG_WELSH_UNITED_KINGDOM                =  1,
830     SUBLANG_WOLOF_SENEGAL                       =  1,
831     SUBLANG_YORUBA_NIGERIA                      =  1,
832     SUBLANG_XHOSA_SOUTH_AFRICA                  =  1,
833     SUBLANG_YAKUT_RUSSIA                        =  1,
834     SUBLANG_YI_PRC                              =  1,
835     SUBLANG_ZULU_SOUTH_AFRICA                   =  1
836 }
837 
838 // This is not documented on MSDN
839 enum NLS_VALID_LOCALE_MASK = 1048575;
840 
841 // Sorting identifiers
842 enum : WORD {
843     SORT_DEFAULT              = 0,
844     SORT_JAPANESE_XJIS        = 0,
845     SORT_JAPANESE_UNICODE     = 1,
846     SORT_CHINESE_BIG5         = 0,
847     SORT_CHINESE_PRCP         = 0,
848     SORT_CHINESE_UNICODE      = 1,
849     SORT_CHINESE_PRC          = 2,
850     SORT_CHINESE_BOPOMOFO     = 3,
851     SORT_KOREAN_KSC           = 0,
852     SORT_KOREAN_UNICODE       = 1,
853     SORT_GERMAN_PHONE_BOOK    = 1,
854     SORT_HUNGARIAN_DEFAULT    = 0,
855     SORT_HUNGARIAN_TECHNICAL  = 1,
856     SORT_GEORGIAN_TRADITIONAL = 0,
857     SORT_GEORGIAN_MODERN      = 1
858 }
859 
860 pure nothrow @nogc {
861     WORD MAKELANGID(/*USHORT*/uint p, /*USHORT*/ uint s) { return cast(WORD)((s << 10) | p); }
862     WORD PRIMARYLANGID(/*WORD*/uint lgid) { return cast(WORD)(lgid & 0x3FF); }
863     WORD SUBLANGID(/*WORD*/uint lgid) { return cast(WORD)(lgid >>> 10); }
864 
865     DWORD MAKELCID(/*WORD*/uint lgid, /*WORD*/uint srtid) { return (cast(DWORD) srtid << 16) | cast(DWORD) lgid; }
866     // ???
867     //DWORD MAKESORTLCID(WORD lgid, WORD srtid, WORD ver) { return (MAKELCID(lgid, srtid)) | ((cast(DWORD)ver) << 20); }
868     WORD LANGIDFROMLCID(LCID lcid) { return cast(WORD) lcid; }
869     WORD SORTIDFROMLCID(LCID lcid) { return cast(WORD) ((lcid >>> 16) & 0x0F); }
870     WORD SORTVERSIONFROMLCID(LCID lcid) { return cast(WORD) ((lcid >>> 20) & 0x0F); }
871 }
872 
873 enum WORD LANG_SYSTEM_DEFAULT = (SUBLANG_SYS_DEFAULT << 10) | LANG_NEUTRAL;
874 enum WORD LANG_USER_DEFAULT   = (SUBLANG_DEFAULT << 10) | LANG_NEUTRAL;
875 enum DWORD LOCALE_NEUTRAL     = (SORT_DEFAULT << 16)
876                                  | (SUBLANG_NEUTRAL << 10) | LANG_NEUTRAL;
877 
878 // ---
879 enum : BYTE {
880     ACL_REVISION    = 2,
881     ACL_REVISION_DS = 4
882 }
883 
884 // These are not documented on MSDN
885 enum : BYTE {
886     ACL_REVISION1    = 1,
887     ACL_REVISION2,
888     ACL_REVISION3,
889     ACL_REVISION4 // = 4
890 }
891 
892 enum BYTE
893     MIN_ACL_REVISION = 2,
894     MAX_ACL_REVISION = 4;
895 
896 /+
897 // These aren't necessary for D.
898 enum MINCHAR=0x80;
899 enum MAXCHAR=0x7f;
900 enum MINSHORT=0x8000;
901 enum MAXSHORT=0x7fff;
902 enum MINLONG=0x80000000;
903 enum MAXLONG=0x7fffffff;
904 enum MAXBYTE=0xff;
905 enum MAXWORD=0xffff;
906 enum MAXDWORD=0xffffffff;
907 +/
908 
909 // SYSTEM_INFO.dwProcessorType
910 enum : DWORD {
911     PROCESSOR_INTEL_386     =   386,
912     PROCESSOR_INTEL_486     =   486,
913     PROCESSOR_INTEL_PENTIUM =   586,
914     PROCESSOR_MIPS_R4000    =  4000,
915     PROCESSOR_ALPHA_21064   = 21064,
916     PROCESSOR_INTEL_IA64    =  2200
917 }
918 
919 // SYSTEM_INFO.wProcessorArchitecture
920 enum : WORD {
921     PROCESSOR_ARCHITECTURE_INTEL,
922     PROCESSOR_ARCHITECTURE_MIPS,
923     PROCESSOR_ARCHITECTURE_ALPHA,
924     PROCESSOR_ARCHITECTURE_PPC,
925     PROCESSOR_ARCHITECTURE_SHX,
926     PROCESSOR_ARCHITECTURE_ARM,
927     PROCESSOR_ARCHITECTURE_IA64,
928     PROCESSOR_ARCHITECTURE_ALPHA64,
929     PROCESSOR_ARCHITECTURE_MSIL,
930     PROCESSOR_ARCHITECTURE_AMD64,
931     PROCESSOR_ARCHITECTURE_IA32_ON_WIN64, // = 10
932     PROCESSOR_ARCHITECTURE_UNKNOWN = 0xFFFF
933 }
934 
935 // IsProcessorFeaturePresent()
936 enum : DWORD {
937     PF_FLOATING_POINT_PRECISION_ERRATA,
938     PF_FLOATING_POINT_EMULATED,
939     PF_COMPARE_EXCHANGE_DOUBLE,
940     PF_MMX_INSTRUCTIONS_AVAILABLE,
941     PF_PPC_MOVEMEM_64BIT_OK,
942     PF_ALPHA_BYTE_INSTRUCTIONS,
943     PF_XMMI_INSTRUCTIONS_AVAILABLE,
944     PF_3DNOW_INSTRUCTIONS_AVAILABLE,
945     PF_RDTSC_INSTRUCTION_AVAILABLE,
946     PF_PAE_ENABLED,
947     PF_XMMI64_INSTRUCTIONS_AVAILABLE
948 }
949 
950 // MinGW: also in ddk/ntifs.h
951 enum : DWORD {
952     FILE_ACTION_ADDED = 1,
953     FILE_ACTION_REMOVED,
954     FILE_ACTION_MODIFIED,
955     FILE_ACTION_RENAMED_OLD_NAME,
956     FILE_ACTION_RENAMED_NEW_NAME,
957     FILE_ACTION_ADDED_STREAM,
958     FILE_ACTION_REMOVED_STREAM,
959     FILE_ACTION_MODIFIED_STREAM,
960     FILE_ACTION_REMOVED_BY_DELETE,
961     FILE_ACTION_ID_NOT_TUNNELLED,
962     FILE_ACTION_TUNNELLED_ID_COLLISION // = 11
963 }
964 // MinGW: end ntifs.h
965 
966 enum DWORD
967     HEAP_NO_SERIALIZE             = 0x01,
968     HEAP_GROWABLE                 = 0x02,
969     HEAP_GENERATE_EXCEPTIONS      = 0x04,
970     HEAP_ZERO_MEMORY              = 0x08,
971     HEAP_REALLOC_IN_PLACE_ONLY    = 0x10,
972     HEAP_TAIL_CHECKING_ENABLED    = 0x20,
973     HEAP_FREE_CHECKING_ENABLED    = 0x40,
974     HEAP_DISABLE_COALESCE_ON_FREE = 0x80;
975 
976 // These are not documented on MSDN
977 enum HEAP_CREATE_ALIGN_16       = 0;
978 enum HEAP_CREATE_ENABLE_TRACING = 0x020000;
979 enum HEAP_MAXIMUM_TAG           = 0x000FFF;
980 enum HEAP_PSEUDO_TAG_FLAG       = 0x008000;
981 enum HEAP_TAG_SHIFT             = 16;
982 // ???
983 //MACRO #define HEAP_MAKE_TAG_FLAGS(b,o) ((DWORD)((b)+(o)<<16)))
984 
985 enum ACCESS_MASK
986     KEY_QUERY_VALUE        = 0x000001,
987     KEY_SET_VALUE          = 0x000002,
988     KEY_CREATE_SUB_KEY     = 0x000004,
989     KEY_ENUMERATE_SUB_KEYS = 0x000008,
990     KEY_NOTIFY             = 0x000010,
991     KEY_CREATE_LINK        = 0x000020,
992     KEY_WRITE              = 0x020006,
993     KEY_EXECUTE            = 0x020019,
994     KEY_READ               = 0x020019,
995     KEY_ALL_ACCESS         = 0x0F003F;
996 
997 static if (_WIN32_WINNT >= 0x502) {
998 enum ACCESS_MASK
999         KEY_WOW64_64KEY    = 0x000100,
1000         KEY_WOW64_32KEY    = 0x000200;
1001 }
1002 
1003 enum DWORD
1004     REG_WHOLE_HIVE_VOLATILE = 1,
1005     REG_REFRESH_HIVE        = 2,
1006     REG_NO_LAZY_FLUSH       = 4;
1007 
1008 enum DWORD
1009     REG_OPTION_RESERVED       =  0,
1010     REG_OPTION_NON_VOLATILE   =  0,
1011     REG_OPTION_VOLATILE       =  1,
1012     REG_OPTION_CREATE_LINK    =  2,
1013     REG_OPTION_BACKUP_RESTORE =  4,
1014     REG_OPTION_OPEN_LINK      =  8,
1015     REG_LEGAL_OPTION          = 15;
1016 
1017 enum SECURITY_INFORMATION
1018     OWNER_SECURITY_INFORMATION            = 0x00000001,
1019     GROUP_SECURITY_INFORMATION            = 0x00000002,
1020     DACL_SECURITY_INFORMATION             = 0x00000004,
1021     SACL_SECURITY_INFORMATION             = 0x00000008,
1022     LABEL_SECURITY_INFORMATION            = 0x00000010,
1023     UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000,
1024     UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000,
1025     PROTECTED_SACL_SECURITY_INFORMATION   = 0x40000000,
1026     PROTECTED_DACL_SECURITY_INFORMATION   = 0x80000000;
1027 
1028 enum DWORD MAXIMUM_PROCESSORS = 32;
1029 
1030 // VirtualAlloc(), etc
1031 // -------------------
1032 
1033 enum : DWORD {
1034     PAGE_NOACCESS          = 0x0001,
1035     PAGE_READONLY          = 0x0002,
1036     PAGE_READWRITE         = 0x0004,
1037     PAGE_WRITECOPY         = 0x0008,
1038     PAGE_EXECUTE           = 0x0010,
1039     PAGE_EXECUTE_READ      = 0x0020,
1040     PAGE_EXECUTE_READWRITE = 0x0040,
1041     PAGE_EXECUTE_WRITECOPY = 0x0080,
1042     PAGE_GUARD             = 0x0100,
1043     PAGE_NOCACHE           = 0x0200
1044 }
1045 
1046 enum : DWORD {
1047     MEM_COMMIT      = 0x00001000,
1048     MEM_RESERVE     = 0x00002000,
1049     MEM_DECOMMIT    = 0x00004000,
1050     MEM_RELEASE     = 0x00008000,
1051     MEM_FREE        = 0x00010000,
1052     MEM_PRIVATE     = 0x00020000,
1053     MEM_MAPPED      = 0x00040000,
1054     MEM_RESET       = 0x00080000,
1055     MEM_TOP_DOWN    = 0x00100000,
1056     MEM_WRITE_WATCH = 0x00200000, // MinGW (???): 98/Me
1057     MEM_PHYSICAL    = 0x00400000,
1058     MEM_4MB_PAGES   = 0x80000000
1059 }
1060 
1061 // MinGW: also in ddk/ntifs.h
1062 // CreateFileMapping()
1063 enum DWORD
1064     SEC_BASED     = 0x00200000,
1065     SEC_NO_CHANGE = 0x00400000,
1066     SEC_FILE      = 0x00800000,
1067     SEC_IMAGE     = 0x01000000,
1068     SEC_VLM       = 0x02000000,
1069     SEC_RESERVE   = 0x04000000,
1070     SEC_COMMIT    = 0x08000000,
1071     SEC_NOCACHE   = 0x10000000,
1072     MEM_IMAGE     = SEC_IMAGE;
1073 // MinGW: end ntifs.h
1074 
1075 // ???
1076 enum ACCESS_MASK
1077     SECTION_QUERY       = 0x000001,
1078     SECTION_MAP_WRITE   = 0x000002,
1079     SECTION_MAP_READ    = 0x000004,
1080     SECTION_MAP_EXECUTE = 0x000008,
1081     SECTION_EXTEND_SIZE = 0x000010,
1082     SECTION_ALL_ACCESS  = 0x0F001F;
1083 
1084 // These are not documented on MSDN
1085 enum MESSAGE_RESOURCE_UNICODE = 1;
1086 enum RTL_CRITSECT_TYPE        = 0;
1087 enum RTL_RESOURCE_TYPE        = 1;
1088 
1089 // COFF file format
1090 // ----------------
1091 
1092 // IMAGE_FILE_HEADER.Characteristics
1093 enum WORD
1094     IMAGE_FILE_RELOCS_STRIPPED         = 0x0001,
1095     IMAGE_FILE_EXECUTABLE_IMAGE        = 0x0002,
1096     IMAGE_FILE_LINE_NUMS_STRIPPED      = 0x0004,
1097     IMAGE_FILE_LOCAL_SYMS_STRIPPED     = 0x0008,
1098     IMAGE_FILE_AGGRESIVE_WS_TRIM       = 0x0010,
1099     IMAGE_FILE_LARGE_ADDRESS_AWARE     = 0x0020,
1100     IMAGE_FILE_BYTES_REVERSED_LO       = 0x0080,
1101     IMAGE_FILE_32BIT_MACHINE           = 0x0100,
1102     IMAGE_FILE_DEBUG_STRIPPED          = 0x0200,
1103     IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 0x0400,
1104     IMAGE_FILE_NET_RUN_FROM_SWAP       = 0x0800,
1105     IMAGE_FILE_SYSTEM                  = 0x1000,
1106     IMAGE_FILE_DLL                     = 0x2000,
1107     IMAGE_FILE_UP_SYSTEM_ONLY          = 0x4000,
1108     IMAGE_FILE_BYTES_REVERSED_HI       = 0x8000;
1109 
1110 // IMAGE_FILE_HEADER.Machine
1111 enum : WORD {
1112     IMAGE_FILE_MACHINE_UNKNOWN   = 0x0000,
1113     IMAGE_FILE_MACHINE_I386      = 0x014C,
1114     IMAGE_FILE_MACHINE_R3000     = 0x0162,
1115     IMAGE_FILE_MACHINE_R4000     = 0x0166,
1116     IMAGE_FILE_MACHINE_R10000    = 0x0168,
1117     IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x0169,
1118     IMAGE_FILE_MACHINE_ALPHA     = 0x0184,
1119     IMAGE_FILE_MACHINE_SH3       = 0x01A2,
1120     IMAGE_FILE_MACHINE_SH3DSP    = 0x01A3,
1121     IMAGE_FILE_MACHINE_SH4       = 0x01A6,
1122     IMAGE_FILE_MACHINE_SH5       = 0x01A8,
1123     IMAGE_FILE_MACHINE_ARM       = 0x01C0,
1124     IMAGE_FILE_MACHINE_THUMB     = 0x01C2,
1125     IMAGE_FILE_MACHINE_AM33      = 0x01D3,
1126     IMAGE_FILE_MACHINE_POWERPC   = 0x01F0,
1127     IMAGE_FILE_MACHINE_POWERPCFP = 0x01F1,
1128     IMAGE_FILE_MACHINE_IA64      = 0x0200,
1129     IMAGE_FILE_MACHINE_MIPS16    = 0x0266,
1130     IMAGE_FILE_MACHINE_MIPSFPU   = 0x0366,
1131     IMAGE_FILE_MACHINE_MIPSFPU16 = 0x0466,
1132     IMAGE_FILE_MACHINE_EBC       = 0x0EBC,
1133     IMAGE_FILE_MACHINE_AMD64     = 0x8664,
1134     IMAGE_FILE_MACHINE_M32R      = 0x9041
1135 }
1136 
1137 // ???
1138 enum  {
1139     IMAGE_DOS_SIGNATURE    = 0x5A4D,
1140     IMAGE_OS2_SIGNATURE    = 0x454E,
1141     IMAGE_OS2_SIGNATURE_LE = 0x454C,
1142     IMAGE_VXD_SIGNATURE    = 0x454C,
1143     IMAGE_NT_SIGNATURE     = 0x4550
1144 }
1145 
1146 // IMAGE_OPTIONAL_HEADER.Magic
1147 enum : WORD {
1148     IMAGE_NT_OPTIONAL_HDR32_MAGIC = 0x010B,
1149     IMAGE_ROM_OPTIONAL_HDR_MAGIC  = 0x0107,
1150     IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x020B
1151 }
1152 
1153 // IMAGE_OPTIONAL_HEADER.Subsystem
1154 enum : WORD {
1155     IMAGE_SUBSYSTEM_UNKNOWN                  =  0,
1156     IMAGE_SUBSYSTEM_NATIVE,
1157     IMAGE_SUBSYSTEM_WINDOWS_GUI,
1158     IMAGE_SUBSYSTEM_WINDOWS_CUI,          // =  3
1159     IMAGE_SUBSYSTEM_OS2_CUI                  =  5,
1160     IMAGE_SUBSYSTEM_POSIX_CUI                =  7,
1161     IMAGE_SUBSYSTEM_NATIVE_WINDOWS,
1162     IMAGE_SUBSYSTEM_WINDOWS_CE_GUI,
1163     IMAGE_SUBSYSTEM_EFI_APPLICATION,
1164     IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER,
1165     IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER,
1166     IMAGE_SUBSYSTEM_EFI_ROM,
1167     IMAGE_SUBSYSTEM_XBOX,                 // = 14
1168     IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION = 16
1169 }
1170 
1171 // IMAGE_OPTIONAL_HEADER.DllCharacteristics
1172 enum WORD
1173     IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE         = 0x0040,
1174     IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY      = 0x0080,
1175     IMAGE_DLL_CHARACTERISTICS_NX_COMPAT            = 0x0100,
1176     IMAGE_DLLCHARACTERISTICS_NO_ISOLATION          = 0x0200,
1177     IMAGE_DLLCHARACTERISTICS_NO_SEH                = 0x0400,
1178     IMAGE_DLLCHARACTERISTICS_NO_BIND               = 0x0800,
1179     IMAGE_DLLCHARACTERISTICS_WDM_DRIVER            = 0x2000,
1180     IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = 0x8000;
1181 
1182 // ???
1183 enum IMAGE_SEPARATE_DEBUG_SIGNATURE = 0x4944;
1184 
1185 enum size_t
1186     IMAGE_NUMBEROF_DIRECTORY_ENTRIES =  16,
1187     IMAGE_SIZEOF_ROM_OPTIONAL_HEADER =  56,
1188     IMAGE_SIZEOF_STD_OPTIONAL_HEADER =  28,
1189     IMAGE_SIZEOF_NT_OPTIONAL_HEADER  = 224,
1190     IMAGE_SIZEOF_SHORT_NAME          =   8,
1191     IMAGE_SIZEOF_SECTION_HEADER      =  40,
1192     IMAGE_SIZEOF_SYMBOL              =  18,
1193     IMAGE_SIZEOF_AUX_SYMBOL          =  18,
1194     IMAGE_SIZEOF_RELOCATION          =  10,
1195     IMAGE_SIZEOF_BASE_RELOCATION     =   8,
1196     IMAGE_SIZEOF_LINENUMBER          =   6,
1197     IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR  =  60,
1198     SIZEOF_RFPO_DATA                 =  16;
1199 
1200 PIMAGE_SECTION_HEADER IMAGE_FIRST_SECTION(PIMAGE_NT_HEADERS h) {
1201     return cast(PIMAGE_SECTION_HEADER)
1202         (&h.OptionalHeader + h.FileHeader.SizeOfOptionalHeader);
1203 }
1204 
1205 // ImageDirectoryEntryToDataEx()
1206 enum : USHORT {
1207     IMAGE_DIRECTORY_ENTRY_EXPORT             =  0,
1208     IMAGE_DIRECTORY_ENTRY_IMPORT,
1209     IMAGE_DIRECTORY_ENTRY_RESOURCE,
1210     IMAGE_DIRECTORY_ENTRY_EXCEPTION,
1211     IMAGE_DIRECTORY_ENTRY_SECURITY,
1212     IMAGE_DIRECTORY_ENTRY_BASERELOC,
1213     IMAGE_DIRECTORY_ENTRY_DEBUG,
1214     IMAGE_DIRECTORY_ENTRY_COPYRIGHT,      // =  7
1215     IMAGE_DIRECTORY_ENTRY_ARCHITECTURE       =  7,
1216     IMAGE_DIRECTORY_ENTRY_GLOBALPTR,
1217     IMAGE_DIRECTORY_ENTRY_TLS,
1218     IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG,
1219     IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT,
1220     IMAGE_DIRECTORY_ENTRY_IAT,
1221     IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT,
1222     IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR, // = 14
1223 }
1224 
1225 // IMAGE_SECTION_HEADER.Characteristics
1226 enum DWORD
1227     IMAGE_SCN_TYPE_REG               = 0x00000000,
1228     IMAGE_SCN_TYPE_DSECT             = 0x00000001,
1229     IMAGE_SCN_TYPE_NOLOAD            = 0x00000002,
1230     IMAGE_SCN_TYPE_GROUP             = 0x00000004,
1231     IMAGE_SCN_TYPE_NO_PAD            = 0x00000008,
1232     IMAGE_SCN_TYPE_COPY              = 0x00000010,
1233     IMAGE_SCN_CNT_CODE               = 0x00000020,
1234     IMAGE_SCN_CNT_INITIALIZED_DATA   = 0x00000040,
1235     IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080,
1236     IMAGE_SCN_LNK_OTHER              = 0x00000100,
1237     IMAGE_SCN_LNK_INFO               = 0x00000200,
1238     IMAGE_SCN_TYPE_OVER              = 0x00000400,
1239     IMAGE_SCN_LNK_REMOVE             = 0x00000800,
1240     IMAGE_SCN_LNK_COMDAT             = 0x00001000,
1241     IMAGE_SCN_MEM_FARDATA            = 0x00008000,
1242     IMAGE_SCN_GPREL                  = 0x00008000,
1243     IMAGE_SCN_MEM_PURGEABLE          = 0x00020000,
1244     IMAGE_SCN_MEM_16BIT              = 0x00020000,
1245     IMAGE_SCN_MEM_LOCKED             = 0x00040000,
1246     IMAGE_SCN_MEM_PRELOAD            = 0x00080000,
1247     IMAGE_SCN_ALIGN_1BYTES           = 0x00100000,
1248     IMAGE_SCN_ALIGN_2BYTES           = 0x00200000,
1249     IMAGE_SCN_ALIGN_4BYTES           = 0x00300000,
1250     IMAGE_SCN_ALIGN_8BYTES           = 0x00400000,
1251     IMAGE_SCN_ALIGN_16BYTES          = 0x00500000,
1252     IMAGE_SCN_ALIGN_32BYTES          = 0x00600000,
1253     IMAGE_SCN_ALIGN_64BYTES          = 0x00700000,
1254     IMAGE_SCN_ALIGN_128BYTES         = 0x00800000,
1255     IMAGE_SCN_ALIGN_256BYTES         = 0x00900000,
1256     IMAGE_SCN_ALIGN_512BYTES         = 0x00A00000,
1257     IMAGE_SCN_ALIGN_1024BYTES        = 0x00B00000,
1258     IMAGE_SCN_ALIGN_2048BYTES        = 0x00C00000,
1259     IMAGE_SCN_ALIGN_4096BYTES        = 0x00D00000,
1260     IMAGE_SCN_ALIGN_8192BYTES        = 0x00E00000,
1261     IMAGE_SCN_LNK_NRELOC_OVFL        = 0x01000000,
1262     IMAGE_SCN_MEM_DISCARDABLE        = 0x02000000,
1263     IMAGE_SCN_MEM_NOT_CACHED         = 0x04000000,
1264     IMAGE_SCN_MEM_NOT_PAGED          = 0x08000000,
1265     IMAGE_SCN_MEM_SHARED             = 0x10000000,
1266     IMAGE_SCN_MEM_EXECUTE            = 0x20000000,
1267     IMAGE_SCN_MEM_READ               = 0x40000000,
1268     IMAGE_SCN_MEM_WRITE              = 0x80000000;
1269 
1270 /*  The following constants are mostlydocumented at
1271  *  http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/pecoff.doc
1272  *  but don't seem to be defined in the HTML docs.
1273  */
1274 enum : SHORT {
1275     IMAGE_SYM_UNDEFINED =  0,
1276     IMAGE_SYM_ABSOLUTE  = -1,
1277     IMAGE_SYM_DEBUG     = -2
1278 }
1279 
1280 enum : ubyte {
1281     IMAGE_SYM_TYPE_NULL,
1282     IMAGE_SYM_TYPE_VOID,
1283     IMAGE_SYM_TYPE_CHAR,
1284     IMAGE_SYM_TYPE_SHORT,
1285     IMAGE_SYM_TYPE_INT,
1286     IMAGE_SYM_TYPE_LONG,
1287     IMAGE_SYM_TYPE_FLOAT,
1288     IMAGE_SYM_TYPE_DOUBLE,
1289     IMAGE_SYM_TYPE_STRUCT,
1290     IMAGE_SYM_TYPE_UNION,
1291     IMAGE_SYM_TYPE_ENUM,
1292     IMAGE_SYM_TYPE_MOE,
1293     IMAGE_SYM_TYPE_BYTE,
1294     IMAGE_SYM_TYPE_WORD,
1295     IMAGE_SYM_TYPE_UINT,
1296     IMAGE_SYM_TYPE_DWORD // = 15
1297 }
1298 enum IMAGE_SYM_TYPE_PCODE = 32768; // ???
1299 
1300 enum : ubyte {
1301     IMAGE_SYM_DTYPE_NULL,
1302     IMAGE_SYM_DTYPE_POINTER,
1303     IMAGE_SYM_DTYPE_FUNCTION,
1304     IMAGE_SYM_DTYPE_ARRAY
1305 }
1306 
1307 enum : BYTE {
1308     IMAGE_SYM_CLASS_END_OF_FUNCTION  = 0xFF,
1309     IMAGE_SYM_CLASS_NULL             =   0,
1310     IMAGE_SYM_CLASS_AUTOMATIC,
1311     IMAGE_SYM_CLASS_EXTERNAL,
1312     IMAGE_SYM_CLASS_STATIC,
1313     IMAGE_SYM_CLASS_REGISTER,
1314     IMAGE_SYM_CLASS_EXTERNAL_DEF,
1315     IMAGE_SYM_CLASS_LABEL,
1316     IMAGE_SYM_CLASS_UNDEFINED_LABEL,
1317     IMAGE_SYM_CLASS_MEMBER_OF_STRUCT,
1318     IMAGE_SYM_CLASS_ARGUMENT,
1319     IMAGE_SYM_CLASS_STRUCT_TAG,
1320     IMAGE_SYM_CLASS_MEMBER_OF_UNION,
1321     IMAGE_SYM_CLASS_UNION_TAG,
1322     IMAGE_SYM_CLASS_TYPE_DEFINITION,
1323     IMAGE_SYM_CLASS_UNDEFINED_STATIC,
1324     IMAGE_SYM_CLASS_ENUM_TAG,
1325     IMAGE_SYM_CLASS_MEMBER_OF_ENUM,
1326     IMAGE_SYM_CLASS_REGISTER_PARAM,
1327     IMAGE_SYM_CLASS_BIT_FIELD,    // =  18
1328     IMAGE_SYM_CLASS_FAR_EXTERNAL     =  68,
1329     IMAGE_SYM_CLASS_BLOCK            = 100,
1330     IMAGE_SYM_CLASS_FUNCTION,
1331     IMAGE_SYM_CLASS_END_OF_STRUCT,
1332     IMAGE_SYM_CLASS_FILE,
1333     IMAGE_SYM_CLASS_SECTION,
1334     IMAGE_SYM_CLASS_WEAK_EXTERNAL,// = 105
1335     IMAGE_SYM_CLASS_CLR_TOKEN        = 107
1336 }
1337 
1338 enum : BYTE {
1339     IMAGE_COMDAT_SELECT_NODUPLICATES = 1,
1340     IMAGE_COMDAT_SELECT_ANY,
1341     IMAGE_COMDAT_SELECT_SAME_SIZE,
1342     IMAGE_COMDAT_SELECT_EXACT_MATCH,
1343     IMAGE_COMDAT_SELECT_ASSOCIATIVE,
1344     IMAGE_COMDAT_SELECT_LARGEST,
1345     IMAGE_COMDAT_SELECT_NEWEST    // = 7
1346 }
1347 
1348 enum : DWORD {
1349     IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY = 1,
1350     IMAGE_WEAK_EXTERN_SEARCH_LIBRARY,
1351     IMAGE_WEAK_EXTERN_SEARCH_ALIAS
1352 }
1353 
1354 enum : WORD {
1355     IMAGE_REL_I386_ABSOLUTE       = 0x0000,
1356     IMAGE_REL_I386_DIR16          = 0x0001,
1357     IMAGE_REL_I386_REL16          = 0x0002,
1358     IMAGE_REL_I386_DIR32          = 0x0006,
1359     IMAGE_REL_I386_DIR32NB        = 0x0007,
1360     IMAGE_REL_I386_SEG12          = 0x0009,
1361     IMAGE_REL_I386_SECTION        = 0x000A,
1362     IMAGE_REL_I386_SECREL         = 0x000B,
1363     IMAGE_REL_I386_TOKEN          = 0x000C,
1364     IMAGE_REL_I386_SECREL7        = 0x000D,
1365     IMAGE_REL_I386_REL32          = 0x0014
1366 }
1367 
1368 enum : WORD {
1369     IMAGE_REL_AMD64_ABSOLUTE      = 0x0000,
1370     IMAGE_REL_AMD64_ADDR64        = 0x0001,
1371     IMAGE_REL_AMD64_ADDR32        = 0x0002,
1372     IMAGE_REL_AMD64_ADDR32NB      = 0x0003,
1373     IMAGE_REL_AMD64_REL32         = 0x0004,
1374     IMAGE_REL_AMD64_REL32_1       = 0x0005,
1375     IMAGE_REL_AMD64_REL32_2       = 0x0006,
1376     IMAGE_REL_AMD64_REL32_3       = 0x0007,
1377     IMAGE_REL_AMD64_REL32_4       = 0x0008,
1378     IMAGE_REL_AMD64_REL32_5       = 0x0009,
1379     IMAGE_REL_AMD64_SECTION       = 0x000A,
1380     IMAGE_REL_AMD64_SECREL        = 0x000B,
1381     IMAGE_REL_AMD64_SECREL7       = 0x000C,
1382     IMAGE_REL_AMD64_TOKEN         = 0x000D,
1383     IMAGE_REL_AMD64_SREL32        = 0x000E,
1384     IMAGE_REL_AMD64_PAIR          = 0x000F,
1385     IMAGE_REL_AMD64_SSPAN32       = 0x0010
1386 }
1387 
1388 enum : WORD {
1389     IMAGE_REL_IA64_ABSOLUTE       = 0x0000,
1390     IMAGE_REL_IA64_IMM14          = 0x0001,
1391     IMAGE_REL_IA64_IMM22          = 0x0002,
1392     IMAGE_REL_IA64_IMM64          = 0x0003,
1393     IMAGE_REL_IA64_DIR32          = 0x0004,
1394     IMAGE_REL_IA64_DIR64          = 0x0005,
1395     IMAGE_REL_IA64_PCREL21B       = 0x0006,
1396     IMAGE_REL_IA64_PCREL21M       = 0x0007,
1397     IMAGE_REL_IA64_PCREL21F       = 0x0008,
1398     IMAGE_REL_IA64_GPREL22        = 0x0009,
1399     IMAGE_REL_IA64_LTOFF22        = 0x000A,
1400     IMAGE_REL_IA64_SECTION        = 0x000B,
1401     IMAGE_REL_IA64_SECREL22       = 0x000C,
1402     IMAGE_REL_IA64_SECREL64I      = 0x000D,
1403     IMAGE_REL_IA64_SECREL32       = 0x000E,
1404     IMAGE_REL_IA64_DIR32NB        = 0x0010,
1405     IMAGE_REL_IA64_SREL14         = 0x0011,
1406     IMAGE_REL_IA64_SREL22         = 0x0012,
1407     IMAGE_REL_IA64_SREL32         = 0x0013,
1408     IMAGE_REL_IA64_UREL32         = 0x0014,
1409     IMAGE_REL_IA64_PCREL60X       = 0x0015,
1410     IMAGE_REL_IA64_PCREL60B       = 0x0016,
1411     IMAGE_REL_IA64_PCREL60F       = 0x0017,
1412     IMAGE_REL_IA64_PCREL60I       = 0x0018,
1413     IMAGE_REL_IA64_PCREL60M       = 0x0019,
1414     IMAGE_REL_IA64_IMMGPREL64     = 0x001A,
1415     IMAGE_REL_IA64_TOKEN          = 0x001B,
1416     IMAGE_REL_IA64_GPREL32        = 0x001C,
1417     IMAGE_REL_IA64_ADDEND         = 0x001F
1418 }
1419 
1420 enum : WORD {
1421     IMAGE_REL_SH3_ABSOLUTE        = 0x0000,
1422     IMAGE_REL_SH3_DIRECT16        = 0x0001,
1423     IMAGE_REL_SH3_DIRECT32        = 0x0002,
1424     IMAGE_REL_SH3_DIRECT8         = 0x0003,
1425     IMAGE_REL_SH3_DIRECT8_WORD    = 0x0004,
1426     IMAGE_REL_SH3_DIRECT8_LONG    = 0x0005,
1427     IMAGE_REL_SH3_DIRECT4         = 0x0006,
1428     IMAGE_REL_SH3_DIRECT4_WORD    = 0x0007,
1429     IMAGE_REL_SH3_DIRECT4_LONG    = 0x0008,
1430     IMAGE_REL_SH3_PCREL8_WORD     = 0x0009,
1431     IMAGE_REL_SH3_PCREL8_LONG     = 0x000A,
1432     IMAGE_REL_SH3_PCREL12_WORD    = 0x000B,
1433     IMAGE_REL_SH3_STARTOF_SECTION = 0x000C,
1434     IMAGE_REL_SH3_SIZEOF_SECTION  = 0x000D,
1435     IMAGE_REL_SH3_SECTION         = 0x000E,
1436     IMAGE_REL_SH3_SECREL          = 0x000F,
1437     IMAGE_REL_SH3_DIRECT32_NB     = 0x0010,
1438     IMAGE_REL_SH3_GPREL4_LONG     = 0x0011,
1439     IMAGE_REL_SH3_TOKEN           = 0x0012,
1440     IMAGE_REL_SHM_PCRELPT         = 0x0013,
1441     IMAGE_REL_SHM_REFLO           = 0x0014,
1442     IMAGE_REL_SHM_REFHALF         = 0x0015,
1443     IMAGE_REL_SHM_RELLO           = 0x0016,
1444     IMAGE_REL_SHM_RELHALF         = 0x0017,
1445     IMAGE_REL_SHM_PAIR            = 0x0018,
1446     IMAGE_REL_SHM_NOMODE          = 0x8000
1447 }
1448 
1449 enum : WORD {
1450     IMAGE_REL_M32R_ABSOLUTE       = 0x0000,
1451     IMAGE_REL_M32R_ADDR32         = 0x0001,
1452     IMAGE_REL_M32R_ADDR32NB       = 0x0002,
1453     IMAGE_REL_M32R_ADDR24         = 0x0003,
1454     IMAGE_REL_M32R_GPREL16        = 0x0004,
1455     IMAGE_REL_M32R_PCREL24        = 0x0005,
1456     IMAGE_REL_M32R_PCREL16        = 0x0006,
1457     IMAGE_REL_M32R_PCREL8         = 0x0007,
1458     IMAGE_REL_M32R_REFHALF        = 0x0008,
1459     IMAGE_REL_M32R_REFHI          = 0x0009,
1460     IMAGE_REL_M32R_REFLO          = 0x000A,
1461     IMAGE_REL_M32R_PAIR           = 0x000B,
1462     IMAGE_REL_M32R_SECTION        = 0x000C,
1463     IMAGE_REL_M32R_SECREL         = 0x000D,
1464     IMAGE_REL_M32R_TOKEN          = 0x000E
1465 }
1466 
1467 enum : WORD {
1468     IMAGE_REL_MIPS_ABSOLUTE       = 0x0000,
1469     IMAGE_REL_MIPS_REFHALF        = 0x0001,
1470     IMAGE_REL_MIPS_REFWORD        = 0x0002,
1471     IMAGE_REL_MIPS_JMPADDR        = 0x0003,
1472     IMAGE_REL_MIPS_REFHI          = 0x0004,
1473     IMAGE_REL_MIPS_REFLO          = 0x0005,
1474     IMAGE_REL_MIPS_GPREL          = 0x0006,
1475     IMAGE_REL_MIPS_LITERAL        = 0x0007,
1476     IMAGE_REL_MIPS_SECTION        = 0x000A,
1477     IMAGE_REL_MIPS_SECREL         = 0x000B,
1478     IMAGE_REL_MIPS_SECRELLO       = 0x000C,
1479     IMAGE_REL_MIPS_SECRELHI       = 0x000D,
1480     IMAGE_REL_MIPS_JMPADDR16      = 0x0010,
1481     IMAGE_REL_MIPS_REFWORDNB      = 0x0022,
1482     IMAGE_REL_MIPS_PAIR           = 0x0025
1483 }
1484 
1485 
1486 enum : WORD {
1487     IMAGE_REL_ALPHA_ABSOLUTE,
1488     IMAGE_REL_ALPHA_REFLONG,
1489     IMAGE_REL_ALPHA_REFQUAD,
1490     IMAGE_REL_ALPHA_GPREL32,
1491     IMAGE_REL_ALPHA_LITERAL,
1492     IMAGE_REL_ALPHA_LITUSE,
1493     IMAGE_REL_ALPHA_GPDISP,
1494     IMAGE_REL_ALPHA_BRADDR,
1495     IMAGE_REL_ALPHA_HINT,
1496     IMAGE_REL_ALPHA_INLINE_REFLONG,
1497     IMAGE_REL_ALPHA_REFHI,
1498     IMAGE_REL_ALPHA_REFLO,
1499     IMAGE_REL_ALPHA_PAIR,
1500     IMAGE_REL_ALPHA_MATCH,
1501     IMAGE_REL_ALPHA_SECTION,
1502     IMAGE_REL_ALPHA_SECREL,
1503     IMAGE_REL_ALPHA_REFLONGNB,
1504     IMAGE_REL_ALPHA_SECRELLO,
1505     IMAGE_REL_ALPHA_SECRELHI // = 18
1506 }
1507 
1508 enum : WORD {
1509     IMAGE_REL_PPC_ABSOLUTE,
1510     IMAGE_REL_PPC_ADDR64,
1511     IMAGE_REL_PPC_ADDR32,
1512     IMAGE_REL_PPC_ADDR24,
1513     IMAGE_REL_PPC_ADDR16,
1514     IMAGE_REL_PPC_ADDR14,
1515     IMAGE_REL_PPC_REL24,
1516     IMAGE_REL_PPC_REL14,
1517     IMAGE_REL_PPC_TOCREL16,
1518     IMAGE_REL_PPC_TOCREL14,
1519     IMAGE_REL_PPC_ADDR32NB,
1520     IMAGE_REL_PPC_SECREL,
1521     IMAGE_REL_PPC_SECTION,
1522     IMAGE_REL_PPC_IFGLUE,
1523     IMAGE_REL_PPC_IMGLUE,
1524     IMAGE_REL_PPC_SECREL16,
1525     IMAGE_REL_PPC_REFHI,
1526     IMAGE_REL_PPC_REFLO,
1527     IMAGE_REL_PPC_PAIR // = 18
1528 }
1529 
1530 // ???
1531 enum IMAGE_REL_PPC_TYPEMASK = 0x00FF;
1532 enum IMAGE_REL_PPC_NEG      = 0x0100;
1533 enum IMAGE_REL_PPC_BRTAKEN  = 0x0200;
1534 enum IMAGE_REL_PPC_BRNTAKEN = 0x0400;
1535 enum IMAGE_REL_PPC_TOCDEFN  = 0x0800;
1536 
1537 enum {
1538     IMAGE_REL_BASED_ABSOLUTE,
1539     IMAGE_REL_BASED_HIGH,
1540     IMAGE_REL_BASED_LOW,
1541     IMAGE_REL_BASED_HIGHLOW,
1542     IMAGE_REL_BASED_HIGHADJ,
1543     IMAGE_REL_BASED_MIPS_JMPADDR
1544 }
1545 // End of constants documented in pecoff.doc
1546 
1547 enum size_t IMAGE_ARCHIVE_START_SIZE = 8;
1548 
1549 const TCHAR[]
1550     IMAGE_ARCHIVE_START            = "!<arch>\n",
1551     IMAGE_ARCHIVE_END              = "`\n",
1552     IMAGE_ARCHIVE_PAD              = "\n",
1553     IMAGE_ARCHIVE_LINKER_MEMBER    = "/               ",
1554     IMAGE_ARCHIVE_LONGNAMES_MEMBER = "//              ";
1555 
1556 enum IMAGE_ORDINAL_FLAG32 = 0x80000000;
1557 
1558 ulong IMAGE_ORDINAL64(ulong Ordinal) { return Ordinal & 0xFFFF; }
1559 uint IMAGE_ORDINAL32(uint Ordinal)   { return Ordinal & 0xFFFF; }
1560 
1561 bool IMAGE_SNAP_BY_ORDINAL32(uint Ordinal) {
1562     return (Ordinal & IMAGE_ORDINAL_FLAG32) != 0;
1563 }
1564 
1565 enum ulong IMAGE_ORDINAL_FLAG64 = 0x8000000000000000;
1566 
1567 bool IMAGE_SNAP_BY_ORDINAL64(ulong Ordinal) {
1568     return (Ordinal & IMAGE_ORDINAL_FLAG64) != 0;
1569 }
1570 
1571 // ???
1572 enum IMAGE_RESOURCE_NAME_IS_STRING    = 0x80000000;
1573 enum IMAGE_RESOURCE_DATA_IS_DIRECTORY = 0x80000000;
1574 
1575 enum : DWORD {
1576     IMAGE_DEBUG_TYPE_UNKNOWN,
1577     IMAGE_DEBUG_TYPE_COFF,
1578     IMAGE_DEBUG_TYPE_CODEVIEW,
1579     IMAGE_DEBUG_TYPE_FPO,
1580     IMAGE_DEBUG_TYPE_MISC,
1581     IMAGE_DEBUG_TYPE_EXCEPTION,
1582     IMAGE_DEBUG_TYPE_FIXUP,
1583     IMAGE_DEBUG_TYPE_OMAP_TO_SRC,
1584     IMAGE_DEBUG_TYPE_OMAP_FROM_SRC,
1585     IMAGE_DEBUG_TYPE_BORLAND // = 9
1586 }
1587 
1588 enum : ubyte {
1589     FRAME_FPO,
1590     FRAME_TRAP,
1591     FRAME_TSS,
1592     FRAME_NONFPO
1593 }
1594 
1595 // ???
1596 enum IMAGE_DEBUG_MISC_EXENAME = 1;
1597 
1598 // ???
1599 enum N_BTMASK = 0x000F;
1600 enum N_TMASK  = 0x0030;
1601 enum N_TMASK1 = 0x00C0;
1602 enum N_TMASK2 = 0x00F0;
1603 enum N_BTSHFT = 4;
1604 enum N_TSHIFT = 2;
1605 
1606 enum int
1607     IS_TEXT_UNICODE_ASCII16            = 0x0001,
1608     IS_TEXT_UNICODE_STATISTICS         = 0x0002,
1609     IS_TEXT_UNICODE_CONTROLS           = 0x0004,
1610     IS_TEXT_UNICODE_SIGNATURE          = 0x0008,
1611     IS_TEXT_UNICODE_REVERSE_ASCII16    = 0x0010,
1612     IS_TEXT_UNICODE_REVERSE_STATISTICS = 0x0020,
1613     IS_TEXT_UNICODE_REVERSE_CONTROLS   = 0x0040,
1614     IS_TEXT_UNICODE_REVERSE_SIGNATURE  = 0x0080,
1615     IS_TEXT_UNICODE_ILLEGAL_CHARS      = 0x0100,
1616     IS_TEXT_UNICODE_ODD_LENGTH         = 0x0200,
1617     IS_TEXT_UNICODE_NULL_BYTES         = 0x1000,
1618     IS_TEXT_UNICODE_UNICODE_MASK       = 0x000F,
1619     IS_TEXT_UNICODE_REVERSE_MASK       = 0x00F0,
1620     IS_TEXT_UNICODE_NOT_UNICODE_MASK   = 0x0F00,
1621     IS_TEXT_UNICODE_NOT_ASCII_MASK     = 0xF000;
1622 
1623 enum DWORD
1624     SERVICE_KERNEL_DRIVER       = 0x0001,
1625     SERVICE_FILE_SYSTEM_DRIVER  = 0x0002,
1626     SERVICE_ADAPTER             = 0x0004,
1627     SERVICE_RECOGNIZER_DRIVER   = 0x0008,
1628     SERVICE_WIN32_OWN_PROCESS   = 0x0010,
1629     SERVICE_WIN32_SHARE_PROCESS = 0x0020,
1630     SERVICE_INTERACTIVE_PROCESS = 0x0100,
1631     SERVICE_DRIVER              = 0x000B,
1632     SERVICE_WIN32               = 0x0030,
1633     SERVICE_TYPE_ALL            = 0x013F;
1634 
1635 enum : DWORD {
1636     SERVICE_BOOT_START   = 0,
1637     SERVICE_SYSTEM_START = 1,
1638     SERVICE_AUTO_START   = 2,
1639     SERVICE_DEMAND_START = 3,
1640     SERVICE_DISABLED     = 4
1641 }
1642 
1643 enum : DWORD {
1644     SERVICE_ERROR_IGNORE   = 0,
1645     SERVICE_ERROR_NORMAL   = 1,
1646     SERVICE_ERROR_SEVERE   = 2,
1647     SERVICE_ERROR_CRITICAL = 3
1648 }
1649 
1650 
1651 enum uint
1652     SE_OWNER_DEFAULTED          = 0x0001,
1653     SE_GROUP_DEFAULTED          = 0x0002,
1654     SE_DACL_PRESENT             = 0x0004,
1655     SE_DACL_DEFAULTED           = 0x0008,
1656     SE_SACL_PRESENT             = 0x0010,
1657     SE_SACL_DEFAULTED           = 0x0020,
1658     SE_DACL_AUTO_INHERIT_REQ    = 0x0100,
1659     SE_SACL_AUTO_INHERIT_REQ    = 0x0200,
1660     SE_DACL_AUTO_INHERITED      = 0x0400,
1661     SE_SACL_AUTO_INHERITED      = 0x0800,
1662     SE_DACL_PROTECTED           = 0x1000,
1663     SE_SACL_PROTECTED           = 0x2000,
1664     SE_SELF_RELATIVE            = 0x8000;
1665 
1666 enum SECURITY_IMPERSONATION_LEVEL {
1667     SecurityAnonymous,
1668     SecurityIdentification,
1669     SecurityImpersonation,
1670     SecurityDelegation
1671 }
1672 alias SECURITY_IMPERSONATION_LEVEL* PSECURITY_IMPERSONATION_LEVEL;
1673 
1674 alias BOOLEAN SECURITY_CONTEXT_TRACKING_MODE;
1675 alias BOOLEAN* PSECURITY_CONTEXT_TRACKING_MODE;
1676 
1677 enum size_t SECURITY_DESCRIPTOR_MIN_LENGTH = 20;
1678 
1679 enum DWORD
1680     SECURITY_DESCRIPTOR_REVISION  = 1,
1681     SECURITY_DESCRIPTOR_REVISION1 = 1;
1682 
1683 enum DWORD
1684     SE_PRIVILEGE_ENABLED_BY_DEFAULT = 0x00000001,
1685     SE_PRIVILEGE_ENABLED            = 0x00000002,
1686     SE_PRIVILEGE_USED_FOR_ACCESS    = 0x80000000;
1687 
1688 enum DWORD PRIVILEGE_SET_ALL_NECESSARY = 1;
1689 
1690 enum SECURITY_IMPERSONATION_LEVEL
1691     SECURITY_MAX_IMPERSONATION_LEVEL = SECURITY_IMPERSONATION_LEVEL.SecurityDelegation,
1692     DEFAULT_IMPERSONATION_LEVEL      = SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation;
1693 
1694 enum BOOLEAN
1695     SECURITY_DYNAMIC_TRACKING = true,
1696     SECURITY_STATIC_TRACKING  = false;
1697 
1698 // also in ddk/ntifs.h
1699 enum DWORD
1700     TOKEN_ASSIGN_PRIMARY    = 0x0001,
1701     TOKEN_DUPLICATE         = 0x0002,
1702     TOKEN_IMPERSONATE       = 0x0004,
1703     TOKEN_QUERY             = 0x0008,
1704     TOKEN_QUERY_SOURCE      = 0x0010,
1705     TOKEN_ADJUST_PRIVILEGES = 0x0020,
1706     TOKEN_ADJUST_GROUPS     = 0x0040,
1707     TOKEN_ADJUST_DEFAULT    = 0x0080,
1708 
1709     TOKEN_ALL_ACCESS        = STANDARD_RIGHTS_REQUIRED
1710                               | TOKEN_ASSIGN_PRIMARY
1711                               | TOKEN_DUPLICATE
1712                               | TOKEN_IMPERSONATE
1713                               | TOKEN_QUERY
1714                               | TOKEN_QUERY_SOURCE
1715                               | TOKEN_ADJUST_PRIVILEGES
1716                               | TOKEN_ADJUST_GROUPS
1717                               | TOKEN_ADJUST_DEFAULT,
1718     TOKEN_READ              = STANDARD_RIGHTS_READ | TOKEN_QUERY,
1719     TOKEN_WRITE             = STANDARD_RIGHTS_WRITE
1720                               | TOKEN_ADJUST_PRIVILEGES
1721                               | TOKEN_ADJUST_GROUPS
1722                               | TOKEN_ADJUST_DEFAULT,
1723     TOKEN_EXECUTE           = STANDARD_RIGHTS_EXECUTE;
1724 
1725 enum size_t TOKEN_SOURCE_LENGTH = 8;
1726 // end ddk/ntifs.h
1727 
1728 enum : DWORD {
1729     DLL_PROCESS_DETACH,
1730     DLL_PROCESS_ATTACH,
1731     DLL_THREAD_ATTACH,
1732     DLL_THREAD_DETACH
1733 }
1734 
1735 enum : DWORD {
1736     DBG_CONTINUE              = 0x00010002,
1737     DBG_TERMINATE_THREAD      = 0x40010003,
1738     DBG_TERMINATE_PROCESS     = 0x40010004,
1739     DBG_CONTROL_C             = 0x40010005,
1740     DBG_CONTROL_BREAK         = 0x40010008,
1741     DBG_EXCEPTION_NOT_HANDLED = 0x80010001
1742 }
1743 
1744 enum : DWORD {
1745     TAPE_ABSOLUTE_POSITION,
1746     TAPE_LOGICAL_POSITION,
1747     TAPE_PSEUDO_LOGICAL_POSITION
1748 }
1749 
1750 enum : DWORD {
1751     TAPE_REWIND,
1752     TAPE_ABSOLUTE_BLOCK,
1753     TAPE_LOGICAL_BLOCK,
1754     TAPE_PSEUDO_LOGICAL_BLOCK,
1755     TAPE_SPACE_END_OF_DATA,
1756     TAPE_SPACE_RELATIVE_BLOCKS,
1757     TAPE_SPACE_FILEMARKS,
1758     TAPE_SPACE_SEQUENTIAL_FMKS,
1759     TAPE_SPACE_SETMARKS,
1760     TAPE_SPACE_SEQUENTIAL_SMKS
1761 }
1762 
1763 enum DWORD
1764     TAPE_DRIVE_FIXED            = 0x00000001,
1765     TAPE_DRIVE_SELECT           = 0x00000002,
1766     TAPE_DRIVE_INITIATOR        = 0x00000004,
1767     TAPE_DRIVE_ERASE_SHORT      = 0x00000010,
1768     TAPE_DRIVE_ERASE_LONG       = 0x00000020,
1769     TAPE_DRIVE_ERASE_BOP_ONLY   = 0x00000040,
1770     TAPE_DRIVE_ERASE_IMMEDIATE  = 0x00000080,
1771     TAPE_DRIVE_TAPE_CAPACITY    = 0x00000100,
1772     TAPE_DRIVE_TAPE_REMAINING   = 0x00000200,
1773     TAPE_DRIVE_FIXED_BLOCK      = 0x00000400,
1774     TAPE_DRIVE_VARIABLE_BLOCK   = 0x00000800,
1775     TAPE_DRIVE_WRITE_PROTECT    = 0x00001000,
1776     TAPE_DRIVE_EOT_WZ_SIZE      = 0x00002000,
1777     TAPE_DRIVE_ECC              = 0x00010000,
1778     TAPE_DRIVE_COMPRESSION      = 0x00020000,
1779     TAPE_DRIVE_PADDING          = 0x00040000,
1780     TAPE_DRIVE_REPORT_SMKS      = 0x00080000,
1781     TAPE_DRIVE_GET_ABSOLUTE_BLK = 0x00100000,
1782     TAPE_DRIVE_GET_LOGICAL_BLK  = 0x00200000,
1783     TAPE_DRIVE_SET_EOT_WZ_SIZE  = 0x00400000,
1784     TAPE_DRIVE_EJECT_MEDIA      = 0x01000000,
1785     TAPE_DRIVE_CLEAN_REQUESTS   = 0x02000000,
1786     TAPE_DRIVE_SET_CMP_BOP_ONLY = 0x04000000,
1787     TAPE_DRIVE_RESERVED_BIT     = 0x80000000;
1788 
1789 enum DWORD
1790     TAPE_DRIVE_LOAD_UNLOAD      = 0x80000001,
1791     TAPE_DRIVE_TENSION          = 0x80000002,
1792     TAPE_DRIVE_LOCK_UNLOCK      = 0x80000004,
1793     TAPE_DRIVE_REWIND_IMMEDIATE = 0x80000008,
1794     TAPE_DRIVE_SET_BLOCK_SIZE   = 0x80000010,
1795     TAPE_DRIVE_LOAD_UNLD_IMMED  = 0x80000020,
1796     TAPE_DRIVE_TENSION_IMMED    = 0x80000040,
1797     TAPE_DRIVE_LOCK_UNLK_IMMED  = 0x80000080,
1798     TAPE_DRIVE_SET_ECC          = 0x80000100,
1799     TAPE_DRIVE_SET_COMPRESSION  = 0x80000200,
1800     TAPE_DRIVE_SET_PADDING      = 0x80000400,
1801     TAPE_DRIVE_SET_REPORT_SMKS  = 0x80000800,
1802     TAPE_DRIVE_ABSOLUTE_BLK     = 0x80001000,
1803     TAPE_DRIVE_ABS_BLK_IMMED    = 0x80002000,
1804     TAPE_DRIVE_LOGICAL_BLK      = 0x80004000,
1805     TAPE_DRIVE_LOG_BLK_IMMED    = 0x80008000,
1806     TAPE_DRIVE_END_OF_DATA      = 0x80010000,
1807     TAPE_DRIVE_RELATIVE_BLKS    = 0x80020000,
1808     TAPE_DRIVE_FILEMARKS        = 0x80040000,
1809     TAPE_DRIVE_SEQUENTIAL_FMKS  = 0x80080000,
1810     TAPE_DRIVE_SETMARKS         = 0x80100000,
1811     TAPE_DRIVE_SEQUENTIAL_SMKS  = 0x80200000,
1812     TAPE_DRIVE_REVERSE_POSITION = 0x80400000,
1813     TAPE_DRIVE_SPACE_IMMEDIATE  = 0x80800000,
1814     TAPE_DRIVE_WRITE_SETMARKS   = 0x81000000,
1815     TAPE_DRIVE_WRITE_FILEMARKS  = 0x82000000,
1816     TAPE_DRIVE_WRITE_SHORT_FMKS = 0x84000000,
1817     TAPE_DRIVE_WRITE_LONG_FMKS  = 0x88000000,
1818     TAPE_DRIVE_WRITE_MARK_IMMED = 0x90000000,
1819     TAPE_DRIVE_FORMAT           = 0xA0000000,
1820     TAPE_DRIVE_FORMAT_IMMEDIATE = 0xC0000000,
1821     TAPE_DRIVE_HIGH_FEATURES    = 0x80000000;
1822 
1823 enum : DWORD {
1824     TAPE_FIXED_PARTITIONS     = 0,
1825     TAPE_SELECT_PARTITIONS    = 1,
1826     TAPE_INITIATOR_PARTITIONS = 2
1827 }
1828 
1829 enum : DWORD {
1830     TAPE_SETMARKS,
1831     TAPE_FILEMARKS,
1832     TAPE_SHORT_FILEMARKS,
1833     TAPE_LONG_FILEMARKS
1834 }
1835 
1836 enum : DWORD {
1837     TAPE_ERASE_SHORT,
1838     TAPE_ERASE_LONG
1839 }
1840 
1841 enum : DWORD {
1842     TAPE_LOAD,
1843     TAPE_UNLOAD,
1844     TAPE_TENSION,
1845     TAPE_LOCK,
1846     TAPE_UNLOCK,
1847     TAPE_FORMAT
1848 }
1849 
1850 enum : ULONG32 {
1851     VER_PLATFORM_WIN32s,
1852     VER_PLATFORM_WIN32_WINDOWS,
1853     VER_PLATFORM_WIN32_NT
1854 }
1855 
1856 enum : UCHAR {
1857     VER_NT_WORKSTATION = 1,
1858     VER_NT_DOMAIN_CONTROLLER,
1859     VER_NT_SERVER
1860 }
1861 
1862 enum USHORT
1863     VER_SUITE_SMALLBUSINESS            = 0x0001,
1864     VER_SUITE_ENTERPRISE               = 0x0002,
1865     VER_SUITE_BACKOFFICE               = 0x0004,
1866     VER_SUITE_TERMINAL                 = 0x0010,
1867     VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x0020,
1868     VER_SUITE_EMBEDDEDNT               = 0x0040,
1869     VER_SUITE_DATACENTER               = 0x0080,
1870     VER_SUITE_SINGLEUSERTS             = 0x0100,
1871     VER_SUITE_PERSONAL                 = 0x0200,
1872     VER_SUITE_BLADE                    = 0x0400,
1873     VER_SUITE_STORAGE_SERVER           = 0x2000,
1874     VER_SUITE_COMPUTE_SERVER           = 0x4000;
1875 
1876 enum ULONG
1877     WT_EXECUTEDEFAULT            = 0x00000000,
1878     WT_EXECUTEINIOTHREAD         = 0x00000001,
1879     WT_EXECUTEINWAITTHREAD       = 0x00000004,
1880     WT_EXECUTEONLYONCE           = 0x00000008,
1881     WT_EXECUTELONGFUNCTION       = 0x00000010,
1882     WT_EXECUTEINTIMERTHREAD      = 0x00000020,
1883     WT_EXECUTEINPERSISTENTTHREAD = 0x00000080,
1884     WT_TRANSFER_IMPERSONATION    = 0x00000100;
1885 
1886 static if (_WIN32_WINNT >= 0x500) {
1887 enum DWORD
1888         VER_MINORVERSION     = 0x01,
1889         VER_MAJORVERSION     = 0x02,
1890         VER_BUILDNUMBER      = 0x04,
1891         VER_PLATFORMID       = 0x08,
1892         VER_SERVICEPACKMINOR = 0x10,
1893         VER_SERVICEPACKMAJOR = 0x20,
1894         VER_SUITENAME        = 0x40,
1895         VER_PRODUCT_TYPE     = 0x80;
1896 
1897     enum : DWORD {
1898         VER_EQUAL = 1,
1899         VER_GREATER,
1900         VER_GREATER_EQUAL,
1901         VER_LESS,
1902         VER_LESS_EQUAL,
1903         VER_AND,
1904         VER_OR // = 7
1905     }
1906 }
1907 
1908 static if (_WIN32_WINNT >= 0x501) {
1909     enum : ULONG {
1910         ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION       = 1,
1911         ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1912         ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
1913         ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION,
1914         ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION,
1915         ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION,
1916         ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION, // = 7
1917         ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES             = 9
1918     }
1919 }
1920 
1921 // Macros
1922 BYTE BTYPE(BYTE x) { return cast(BYTE) (x & N_BTMASK); }
1923 bool ISPTR(uint x) { return (x & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT); }
1924 bool ISFCN(uint x) { return (x & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT); }
1925 bool ISARY(uint x) { return (x & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT); }
1926 bool ISTAG(uint x) {
1927     return x == IMAGE_SYM_CLASS_STRUCT_TAG
1928         || x == IMAGE_SYM_CLASS_UNION_TAG
1929         || x == IMAGE_SYM_CLASS_ENUM_TAG;
1930 }
1931 uint INCREF(uint x) {
1932     return ((x & ~N_BTMASK) << N_TSHIFT) | (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT)
1933       | (x & N_BTMASK);
1934 }
1935 uint DECREF(uint x) { return ((x >>> N_TSHIFT) & ~N_BTMASK) | (x & N_BTMASK); }
1936 
1937 enum DWORD TLS_MINIMUM_AVAILABLE = 64;
1938 
1939 enum ULONG
1940     IO_REPARSE_TAG_RESERVED_ZERO  = 0,
1941     IO_REPARSE_TAG_RESERVED_ONE   = 1,
1942     IO_REPARSE_TAG_RESERVED_RANGE = IO_REPARSE_TAG_RESERVED_ONE,
1943     IO_REPARSE_TAG_SYMBOLIC_LINK  = IO_REPARSE_TAG_RESERVED_ZERO,
1944     IO_REPARSE_TAG_MOUNT_POINT    = 0xA0000003,
1945     IO_REPARSE_TAG_SYMLINK        = 0xA000000C,
1946     IO_REPARSE_TAG_VALID_VALUES   = 0xE000FFFF;
1947 
1948 /*  Although these are semantically boolean, they are documented and
1949  *  implemented to return ULONG; this behaviour is preserved for compatibility
1950  */
1951 ULONG IsReparseTagMicrosoft(ULONG x)     { return x & 0x80000000; }
1952 ULONG IsReparseTagHighLatency(ULONG x)   { return x & 0x40000000; }
1953 ULONG IsReparseTagNameSurrogate(ULONG x) { return x & 0x20000000; }
1954 
1955 bool IsReparseTagValid(ULONG x) {
1956     return !(x & ~IO_REPARSE_TAG_VALID_VALUES) && (x > IO_REPARSE_TAG_RESERVED_RANGE);
1957 }
1958 
1959 // Doesn't seem to make sense, but anyway....
1960 ULONG WT_SET_MAX_THREADPOOL_THREADS(ref ULONG Flags, ushort Limit) {
1961     return Flags |= Limit << 16;
1962 }
1963 
1964 import core.sys.windows.basetyps;
1965 /* also in core.sys.windows.basetyps
1966 struct GUID {
1967     uint  Data1;
1968     ushort Data2;
1969     ushort Data3;
1970     ubyte  Data4[8];
1971 }
1972 alias GUID* REFGUID, LPGUID;
1973 */
1974 
1975 struct GENERIC_MAPPING {
1976     ACCESS_MASK GenericRead;
1977     ACCESS_MASK GenericWrite;
1978     ACCESS_MASK GenericExecute;
1979     ACCESS_MASK GenericAll;
1980 }
1981 alias GENERIC_MAPPING* PGENERIC_MAPPING;
1982 
1983 struct ACE_HEADER {
1984     BYTE AceType;
1985     BYTE AceFlags;
1986     WORD AceSize;
1987 }
1988 alias ACE_HEADER* PACE_HEADER;
1989 
1990 struct ACCESS_ALLOWED_ACE {
1991     ACE_HEADER  Header;
1992     ACCESS_MASK Mask;
1993     DWORD       SidStart;
1994 }
1995 alias ACCESS_ALLOWED_ACE* PACCESS_ALLOWED_ACE;
1996 
1997 struct ACCESS_DENIED_ACE {
1998     ACE_HEADER  Header;
1999     ACCESS_MASK Mask;
2000     DWORD       SidStart;
2001 }
2002 alias ACCESS_DENIED_ACE* PACCESS_DENIED_ACE;
2003 
2004 struct SYSTEM_AUDIT_ACE {
2005     ACE_HEADER  Header;
2006     ACCESS_MASK Mask;
2007     DWORD       SidStart;
2008 }
2009 alias SYSTEM_AUDIT_ACE *PSYSTEM_AUDIT_ACE;
2010 
2011 struct SYSTEM_ALARM_ACE {
2012     ACE_HEADER  Header;
2013     ACCESS_MASK Mask;
2014     DWORD       SidStart;
2015 }
2016 alias SYSTEM_ALARM_ACE* PSYSTEM_ALARM_ACE;
2017 
2018 struct ACCESS_ALLOWED_OBJECT_ACE {
2019     ACE_HEADER  Header;
2020     ACCESS_MASK Mask;
2021     DWORD       Flags;
2022     GUID        ObjectType;
2023     GUID        InheritedObjectType;
2024     DWORD       SidStart;
2025 }
2026 alias ACCESS_ALLOWED_OBJECT_ACE* PACCESS_ALLOWED_OBJECT_ACE;
2027 
2028 struct ACCESS_DENIED_OBJECT_ACE {
2029     ACE_HEADER  Header;
2030     ACCESS_MASK Mask;
2031     DWORD       Flags;
2032     GUID        ObjectType;
2033     GUID        InheritedObjectType;
2034     DWORD       SidStart;
2035 }
2036 alias ACCESS_DENIED_OBJECT_ACE* PACCESS_DENIED_OBJECT_ACE;
2037 
2038 struct SYSTEM_AUDIT_OBJECT_ACE {
2039     ACE_HEADER  Header;
2040     ACCESS_MASK Mask;
2041     DWORD       Flags;
2042     GUID        ObjectType;
2043     GUID        InheritedObjectType;
2044     DWORD       SidStart;
2045 }
2046 alias SYSTEM_AUDIT_OBJECT_ACE* PSYSTEM_AUDIT_OBJECT_ACE;
2047 
2048 struct SYSTEM_ALARM_OBJECT_ACE {
2049     ACE_HEADER  Header;
2050     ACCESS_MASK Mask;
2051     DWORD       Flags;
2052     GUID        ObjectType;
2053     GUID        InheritedObjectType;
2054     DWORD       SidStart;
2055 }
2056 alias SYSTEM_ALARM_OBJECT_ACE* PSYSTEM_ALARM_OBJECT_ACE;
2057 
2058 struct ACL {
2059     BYTE AclRevision;
2060     BYTE Sbz1;
2061     WORD AclSize;
2062     WORD AceCount;
2063     WORD Sbz2;
2064 }
2065 alias ACL* PACL;
2066 
2067 struct ACL_REVISION_INFORMATION {
2068     DWORD AclRevision;
2069 }
2070 
2071 struct ACL_SIZE_INFORMATION {
2072     DWORD AceCount;
2073     DWORD AclBytesInUse;
2074     DWORD AclBytesFree;
2075 }
2076 
2077 version (X86) {
2078     // ???
2079 enum SIZE_OF_80387_REGISTERS     = 80;
2080 enum CONTEXT_i386                = 0x010000;
2081 enum CONTEXT_i486                = 0x010000;
2082 enum CONTEXT_CONTROL             = CONTEXT_i386 | 0x01;
2083 enum CONTEXT_INTEGER             = CONTEXT_i386 | 0x02;
2084 enum CONTEXT_SEGMENTS            = CONTEXT_i386 | 0x04;
2085 enum CONTEXT_FLOATING_POINT      = CONTEXT_i386 | 0x08;
2086 enum CONTEXT_DEBUG_REGISTERS     = CONTEXT_i386 | 0x10;
2087 enum CONTEXT_EXTENDED_REGISTERS  = CONTEXT_i386 | 0x20;
2088 enum CONTEXT_FULL                = CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS;
2089 enum CONTEXT_ALL                 = CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS |
2090                                         CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS |
2091                                         CONTEXT_EXTENDED_REGISTERS;
2092 
2093 enum MAXIMUM_SUPPORTED_EXTENSION = 512;
2094 
2095     struct FLOATING_SAVE_AREA {
2096         DWORD    ControlWord;
2097         DWORD    StatusWord;
2098         DWORD    TagWord;
2099         DWORD    ErrorOffset;
2100         DWORD    ErrorSelector;
2101         DWORD    DataOffset;
2102         DWORD    DataSelector;
2103         BYTE[80] RegisterArea;
2104         DWORD    Cr0NpxState;
2105     }
2106 
2107     struct CONTEXT {
2108         DWORD ContextFlags;
2109         DWORD Dr0;
2110         DWORD Dr1;
2111         DWORD Dr2;
2112         DWORD Dr3;
2113         DWORD Dr6;
2114         DWORD Dr7;
2115         FLOATING_SAVE_AREA FloatSave;
2116         DWORD SegGs;
2117         DWORD SegFs;
2118         DWORD SegEs;
2119         DWORD SegDs;
2120         DWORD Edi;
2121         DWORD Esi;
2122         DWORD Ebx;
2123         DWORD Edx;
2124         DWORD Ecx;
2125         DWORD Eax;
2126         DWORD Ebp;
2127         DWORD Eip;
2128         DWORD SegCs;
2129         DWORD EFlags;
2130         DWORD Esp;
2131         DWORD SegSs;
2132         BYTE[MAXIMUM_SUPPORTED_EXTENSION] ExtendedRegisters;
2133     }
2134 
2135 } else version (X86_64)
2136 {
2137 enum CONTEXT_AMD64 = 0x100000;
2138 
2139 enum CONTEXT_CONTROL         = (CONTEXT_AMD64 | 0x1L);
2140 enum CONTEXT_INTEGER         = (CONTEXT_AMD64 | 0x2L);
2141 enum CONTEXT_SEGMENTS        = (CONTEXT_AMD64 | 0x4L);
2142 enum CONTEXT_FLOATING_POINT  = (CONTEXT_AMD64 | 0x8L);
2143 enum CONTEXT_DEBUG_REGISTERS = (CONTEXT_AMD64 | 0x10L);
2144 
2145 enum CONTEXT_FULL = (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT);
2146 enum CONTEXT_ALL  = (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS);
2147 
2148 enum CONTEXT_EXCEPTION_ACTIVE    = 0x8000000;
2149 enum CONTEXT_SERVICE_ACTIVE      = 0x10000000;
2150 enum CONTEXT_EXCEPTION_REQUEST   = 0x40000000;
2151 enum CONTEXT_EXCEPTION_REPORTING = 0x80000000;
2152 
2153 enum INITIAL_MXCSR = 0x1f80;
2154 enum INITIAL_FPCSR = 0x027f;
2155 
2156     align(16) struct M128A
2157     {
2158         ULONGLONG Low;
2159         LONGLONG High;
2160     }
2161     alias M128A* PM128A;
2162 
2163     struct XMM_SAVE_AREA32
2164     {
2165         WORD ControlWord;
2166         WORD StatusWord;
2167         BYTE TagWord;
2168         BYTE Reserved1;
2169         WORD ErrorOpcode;
2170         DWORD ErrorOffset;
2171         WORD ErrorSelector;
2172         WORD Reserved2;
2173         DWORD DataOffset;
2174         WORD DataSelector;
2175         WORD Reserved3;
2176         DWORD MxCsr;
2177         DWORD MxCsr_Mask;
2178         M128A[8] FloatRegisters;
2179         M128A[16] XmmRegisters;
2180         BYTE[96] Reserved4;
2181     }
2182     alias XMM_SAVE_AREA32 PXMM_SAVE_AREA32;
2183 enum LEGACY_SAVE_AREA_LENGTH = XMM_SAVE_AREA32.sizeof;
2184 
2185     align(16) struct CONTEXT
2186     {
2187         DWORD64 P1Home;
2188         DWORD64 P2Home;
2189         DWORD64 P3Home;
2190         DWORD64 P4Home;
2191         DWORD64 P5Home;
2192         DWORD64 P6Home;
2193         DWORD ContextFlags;
2194         DWORD MxCsr;
2195         WORD SegCs;
2196         WORD SegDs;
2197         WORD SegEs;
2198         WORD SegFs;
2199         WORD SegGs;
2200         WORD SegSs;
2201         DWORD EFlags;
2202         DWORD64 Dr0;
2203         DWORD64 Dr1;
2204         DWORD64 Dr2;
2205         DWORD64 Dr3;
2206         DWORD64 Dr6;
2207         DWORD64 Dr7;
2208         DWORD64 Rax;
2209         DWORD64 Rcx;
2210         DWORD64 Rdx;
2211         DWORD64 Rbx;
2212         DWORD64 Rsp;
2213         DWORD64 Rbp;
2214         DWORD64 Rsi;
2215         DWORD64 Rdi;
2216         DWORD64 R8;
2217         DWORD64 R9;
2218         DWORD64 R10;
2219         DWORD64 R11;
2220         DWORD64 R12;
2221         DWORD64 R13;
2222         DWORD64 R14;
2223         DWORD64 R15;
2224         DWORD64 Rip;
2225         union
2226         {
2227             XMM_SAVE_AREA32 FltSave;
2228             XMM_SAVE_AREA32 FloatSave;
2229             struct
2230             {
2231                 M128A[2] Header;
2232                 M128A[8] Legacy;
2233                 M128A Xmm0;
2234                 M128A Xmm1;
2235                 M128A Xmm2;
2236                 M128A Xmm3;
2237                 M128A Xmm4;
2238                 M128A Xmm5;
2239                 M128A Xmm6;
2240                 M128A Xmm7;
2241                 M128A Xmm8;
2242                 M128A Xmm9;
2243                 M128A Xmm10;
2244                 M128A Xmm11;
2245                 M128A Xmm12;
2246                 M128A Xmm13;
2247                 M128A Xmm14;
2248                 M128A Xmm15;
2249             }
2250         }
2251         M128A[26] VectorRegister;
2252         DWORD64 VectorControl;
2253         DWORD64 DebugControl;
2254         DWORD64 LastBranchToRip;
2255         DWORD64 LastBranchFromRip;
2256         DWORD64 LastExceptionToRip;
2257         DWORD64 LastExceptionFromRip;
2258     }
2259 
2260 } else {
2261     static assert(false, "Unsupported CPU");
2262     // Versions for PowerPC, Alpha, SHX, and MIPS removed.
2263 }
2264 
2265 alias CONTEXT* PCONTEXT, LPCONTEXT;
2266 
2267 struct EXCEPTION_RECORD {
2268     DWORD ExceptionCode;
2269     DWORD ExceptionFlags;
2270     EXCEPTION_RECORD* ExceptionRecord;
2271     PVOID ExceptionAddress;
2272     DWORD NumberParameters;
2273     ULONG_PTR[EXCEPTION_MAXIMUM_PARAMETERS] ExceptionInformation;
2274 }
2275 alias EXCEPTION_RECORD* PEXCEPTION_RECORD, LPEXCEPTION_RECORD;
2276 
2277 struct EXCEPTION_POINTERS {
2278     PEXCEPTION_RECORD ExceptionRecord;
2279     PCONTEXT          ContextRecord;
2280 }
2281 alias EXCEPTION_POINTERS* PEXCEPTION_POINTERS, LPEXCEPTION_POINTERS;
2282 
2283 union LARGE_INTEGER {
2284     struct {
2285         uint LowPart;
2286         int  HighPart;
2287     }
2288     long QuadPart;
2289 }
2290 alias LARGE_INTEGER* PLARGE_INTEGER;
2291 
2292 union ULARGE_INTEGER {
2293     struct {
2294         uint LowPart;
2295         uint HighPart;
2296     }
2297     ulong QuadPart;
2298 }
2299 alias ULARGE_INTEGER* PULARGE_INTEGER;
2300 
2301 alias LARGE_INTEGER LUID;
2302 alias LUID* PLUID;
2303 
2304 enum LUID SYSTEM_LUID = { QuadPart:999 };
2305 
2306 align(4) struct LUID_AND_ATTRIBUTES {
2307     LUID  Luid;
2308     DWORD Attributes;
2309 }
2310 alias LUID_AND_ATTRIBUTES* PLUID_AND_ATTRIBUTES;
2311 
2312 align(4) struct PRIVILEGE_SET {
2313     DWORD PrivilegeCount;
2314     DWORD Control;
2315     LUID_AND_ATTRIBUTES _Privilege;
2316 
2317     LUID_AND_ATTRIBUTES* Privilege() return { return &_Privilege; }
2318 }
2319 alias PRIVILEGE_SET* PPRIVILEGE_SET;
2320 
2321 struct SECURITY_ATTRIBUTES {
2322     DWORD  nLength;
2323     LPVOID lpSecurityDescriptor;
2324     BOOL   bInheritHandle;
2325 }
2326 alias SECURITY_ATTRIBUTES* PSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES;
2327 
2328 struct SECURITY_QUALITY_OF_SERVICE {
2329     DWORD   Length;
2330     SECURITY_IMPERSONATION_LEVEL   ImpersonationLevel;
2331     SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
2332     BOOLEAN EffectiveOnly;
2333 }
2334 alias SECURITY_QUALITY_OF_SERVICE* PSECURITY_QUALITY_OF_SERVICE;
2335 
2336 alias PVOID PACCESS_TOKEN;
2337 
2338 struct SE_IMPERSONATION_STATE {
2339     PACCESS_TOKEN Token;
2340     BOOLEAN       CopyOnOpen;
2341     BOOLEAN       EffectiveOnly;
2342     SECURITY_IMPERSONATION_LEVEL Level;
2343 }
2344 alias SE_IMPERSONATION_STATE* PSE_IMPERSONATION_STATE;
2345 
2346 struct SID_IDENTIFIER_AUTHORITY {
2347     BYTE[6] Value;
2348 }
2349 alias SID_IDENTIFIER_AUTHORITY* PSID_IDENTIFIER_AUTHORITY, LPSID_IDENTIFIER_AUTHORITY;
2350 
2351 alias PVOID PSID;
2352 
2353 struct SID {
2354     BYTE  Revision;
2355     BYTE  SubAuthorityCount;
2356     SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
2357     DWORD _SubAuthority;
2358 
2359     DWORD* SubAuthority() return { return &_SubAuthority; }
2360 }
2361 alias SID* PISID;
2362 
2363 struct SID_AND_ATTRIBUTES {
2364     PSID  Sid;
2365     DWORD Attributes;
2366 }
2367 alias SID_AND_ATTRIBUTES* PSID_AND_ATTRIBUTES;
2368 
2369 struct TOKEN_SOURCE {
2370     CHAR[TOKEN_SOURCE_LENGTH] SourceName = 0;
2371     LUID SourceIdentifier;
2372 }
2373 alias TOKEN_SOURCE* PTOKEN_SOURCE;
2374 
2375 struct TOKEN_CONTROL {
2376     LUID         TokenId;
2377     LUID         AuthenticationId;
2378     LUID         ModifiedId;
2379     TOKEN_SOURCE TokenSource;
2380 }
2381 alias TOKEN_CONTROL* PTOKEN_CONTROL;
2382 
2383 struct TOKEN_DEFAULT_DACL {
2384     PACL DefaultDacl;
2385 }
2386 alias TOKEN_DEFAULT_DACL* PTOKEN_DEFAULT_DACL;
2387 
2388 struct TOKEN_GROUPS {
2389     DWORD GroupCount;
2390     SID_AND_ATTRIBUTES _Groups;
2391 
2392     SID_AND_ATTRIBUTES* Groups() return { return &_Groups; }
2393 }
2394 alias TOKEN_GROUPS* PTOKEN_GROUPS, LPTOKEN_GROUPS;
2395 
2396 struct TOKEN_OWNER {
2397     PSID Owner;
2398 }
2399 alias TOKEN_OWNER* PTOKEN_OWNER;
2400 enum SECURITY_MAX_SID_SIZE = 68;
2401 
2402 struct TOKEN_PRIMARY_GROUP {
2403     PSID PrimaryGroup;
2404 }
2405 alias TOKEN_PRIMARY_GROUP* PTOKEN_PRIMARY_GROUP;
2406 
2407 struct TOKEN_PRIVILEGES {
2408     DWORD PrivilegeCount;
2409     LUID_AND_ATTRIBUTES _Privileges;
2410 
2411     LUID_AND_ATTRIBUTES* Privileges() return { return &_Privileges; }
2412 }
2413 alias TOKEN_PRIVILEGES* PTOKEN_PRIVILEGES, LPTOKEN_PRIVILEGES;
2414 
2415 enum TOKEN_TYPE {
2416     TokenPrimary = 1,
2417     TokenImpersonation
2418 }
2419 alias TOKEN_TYPE* PTOKEN_TYPE;
2420 
2421 struct TOKEN_STATISTICS {
2422     LUID          TokenId;
2423     LUID          AuthenticationId;
2424     LARGE_INTEGER ExpirationTime;
2425     TOKEN_TYPE    TokenType;
2426     SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
2427     DWORD         DynamicCharged;
2428     DWORD         DynamicAvailable;
2429     DWORD         GroupCount;
2430     DWORD         PrivilegeCount;
2431     LUID          ModifiedId;
2432 }
2433 alias TOKEN_STATISTICS* PTOKEN_STATISTICS;
2434 
2435 struct TOKEN_USER {
2436     SID_AND_ATTRIBUTES User;
2437 }
2438 alias TOKEN_USER* PTOKEN_USER;
2439 
2440 struct TOKEN_MANDATORY_LABEL {
2441     SID_AND_ATTRIBUTES Label;
2442 }
2443 alias PTOKEN_MANDATORY_LABEL = TOKEN_MANDATORY_LABEL*;
2444 alias DWORD SECURITY_INFORMATION;
2445 alias SECURITY_INFORMATION* PSECURITY_INFORMATION;
2446 alias WORD SECURITY_DESCRIPTOR_CONTROL;
2447 alias SECURITY_DESCRIPTOR_CONTROL* PSECURITY_DESCRIPTOR_CONTROL;
2448 
2449 struct SECURITY_DESCRIPTOR {
2450     BYTE Revision;
2451     BYTE Sbz1;
2452     SECURITY_DESCRIPTOR_CONTROL Control;
2453     PSID Owner;
2454     PSID Group;
2455     PACL Sacl;
2456     PACL Dacl;
2457 }
2458 alias SECURITY_DESCRIPTOR* PSECURITY_DESCRIPTOR, PISECURITY_DESCRIPTOR;
2459 enum TOKEN_ELEVATION_TYPE {
2460     TokenElevationTypeDefault = 1,
2461     TokenElevationTypeFull,
2462     TokenElevationTypeLimited
2463 }
2464 
2465 alias PTOKEN_ELEVATION_TYPE = TOKEN_ELEVATION_TYPE*;
2466 
2467 struct TOKEN_ELEVATION {
2468     DWORD TokenIsElevated;
2469 }
2470 alias PTOKEN_ELEVATION = TOKEN_ELEVATION*;
2471 
2472 enum TOKEN_INFORMATION_CLASS {
2473     TokenUser = 1,
2474     TokenGroups,
2475     TokenPrivileges,
2476     TokenOwner,
2477     TokenPrimaryGroup,
2478     TokenDefaultDacl,
2479     TokenSource,
2480     TokenType,
2481     TokenImpersonationLevel,
2482     TokenStatistics,
2483     TokenRestrictedSids,
2484     TokenSessionId,
2485     TokenGroupsAndPrivileges,
2486     TokenSessionReference,
2487     TokenSandBoxInert,
2488     TokenAuditPolicy,
2489     TokenOrigin,
2490     TokenElevationType,
2491     TokenLinkedToken,
2492     TokenElevation,
2493     TokenHasRestrictions,
2494     TokenAccessInformation,
2495     TokenVirtualizationAllowed,
2496     TokenVirtualizationEnabled,
2497     TokenIntegrityLevel,
2498     TokenUIAccess,
2499     TokenMandatoryPolicy,
2500     TokenLogonSid,
2501     TokenIsAppContainer,
2502     TokenCapabilities,
2503     TokenAppContainerSid,
2504     TokenAppContainerNumber,
2505     TokenUserClaimAttributes,
2506     TokenDeviceClaimAttributes,
2507     TokenRestrictedUserClaimAttributes,
2508     TokenRestrictedDeviceClaimAttributes,
2509     TokenDeviceGroups,
2510     TokenRestrictedDeviceGroups,
2511     TokenSecurityAttributes,
2512     TokenIsRestricted,
2513     TokenProcessTrustLevel,
2514     MaxTokenInfoClass  // MaxTokenInfoClass should always be the last enum
2515 }
2516 
2517 enum SID_NAME_USE {
2518     SidTypeUser = 1,
2519     SidTypeGroup,
2520     SidTypeDomain,
2521     SidTypeAlias,
2522     SidTypeWellKnownGroup,
2523     SidTypeDeletedAccount,
2524     SidTypeInvalid,
2525     SidTypeUnknown,
2526     SidTypeComputer
2527 }
2528 alias SID_NAME_USE* PSID_NAME_USE;
2529 
2530 enum WELL_KNOWN_SID_TYPE {
2531     WinNullSid                                   = 0,
2532     WinWorldSid                                  = 1,
2533     WinLocalSid                                  = 2,
2534     WinCreatorOwnerSid                           = 3,
2535     WinCreatorGroupSid                           = 4,
2536     WinCreatorOwnerServerSid                     = 5,
2537     WinCreatorGroupServerSid                     = 6,
2538     WinNtAuthoritySid                            = 7,
2539     WinDialupSid                                 = 8,
2540     WinNetworkSid                                = 9,
2541     WinBatchSid                                  = 10,
2542     WinInteractiveSid                            = 11,
2543     WinServiceSid                                = 12,
2544     WinAnonymousSid                              = 13,
2545     WinProxySid                                  = 14,
2546     WinEnterpriseControllersSid                  = 15,
2547     WinSelfSid                                   = 16,
2548     WinAuthenticatedUserSid                      = 17,
2549     WinRestrictedCodeSid                         = 18,
2550     WinTerminalServerSid                         = 19,
2551     WinRemoteLogonIdSid                          = 20,
2552     WinLogonIdsSid                               = 21,
2553     WinLocalSystemSid                            = 22,
2554     WinLocalServiceSid                           = 23,
2555     WinNetworkServiceSid                         = 24,
2556     WinBuiltinDomainSid                          = 25,
2557     WinBuiltinAdministratorsSid                  = 26,
2558     WinBuiltinUsersSid                           = 27,
2559     WinBuiltinGuestsSid                          = 28,
2560     WinBuiltinPowerUsersSid                      = 29,
2561     WinBuiltinAccountOperatorsSid                = 30,
2562     WinBuiltinSystemOperatorsSid                 = 31,
2563     WinBuiltinPrintOperatorsSid                  = 32,
2564     WinBuiltinBackupOperatorsSid                 = 33,
2565     WinBuiltinReplicatorSid                      = 34,
2566     WinBuiltinPreWindows2000CompatibleAccessSid  = 35,
2567     WinBuiltinRemoteDesktopUsersSid              = 36,
2568     WinBuiltinNetworkConfigurationOperatorsSid   = 37,
2569     WinAccountAdministratorSid                   = 38,
2570     WinAccountGuestSid                           = 39,
2571     WinAccountKrbtgtSid                          = 40,
2572     WinAccountDomainAdminsSid                    = 41,
2573     WinAccountDomainUsersSid                     = 42,
2574     WinAccountDomainGuestsSid                    = 43,
2575     WinAccountComputersSid                       = 44,
2576     WinAccountControllersSid                     = 45,
2577     WinAccountCertAdminsSid                      = 46,
2578     WinAccountSchemaAdminsSid                    = 47,
2579     WinAccountEnterpriseAdminsSid                = 48,
2580     WinAccountPolicyAdminsSid                    = 49,
2581     WinAccountRasAndIasServersSid                = 50,
2582     WinNTLMAuthenticationSid                     = 51,
2583     WinDigestAuthenticationSid                   = 52,
2584     WinSChannelAuthenticationSid                 = 53,
2585     WinThisOrganizationSid                       = 54,
2586     WinOtherOrganizationSid                      = 55,
2587     WinBuiltinIncomingForestTrustBuildersSid     = 56,
2588     WinBuiltinPerfMonitoringUsersSid             = 57,
2589     WinBuiltinPerfLoggingUsersSid                = 58,
2590     WinBuiltinAuthorizationAccessSid             = 59,
2591     WinBuiltinTerminalServerLicenseServersSid    = 60,
2592     WinBuiltinDCOMUsersSid                       = 61,
2593     WinBuiltinIUsersSid                          = 62,
2594     WinIUserSid                                  = 63,
2595     WinBuiltinCryptoOperatorsSid                 = 64,
2596     WinUntrustedLabelSid                         = 65,
2597     WinLowLabelSid                               = 66,
2598     WinMediumLabelSid                            = 67,
2599     WinHighLabelSid                              = 68,
2600     WinSystemLabelSid                            = 69,
2601     WinWriteRestrictedCodeSid                    = 70,
2602     WinCreatorOwnerRightsSid                     = 71,
2603     WinCacheablePrincipalsGroupSid               = 72,
2604     WinNonCacheablePrincipalsGroupSid            = 73,
2605     WinEnterpriseReadonlyControllersSid          = 74,
2606     WinAccountReadonlyControllersSid             = 75,
2607     WinBuiltinEventLogReadersGroup               = 76,
2608     WinNewEnterpriseReadonlyControllersSid       = 77,
2609     WinBuiltinCertSvcDComAccessGroup             = 78,
2610     WinMediumPlusLabelSid                        = 79,
2611     WinLocalLogonSid                             = 80,
2612     WinConsoleLogonSid                           = 81,
2613     WinThisOrganizationCertificateSid            = 82,
2614     WinApplicationPackageAuthoritySid            = 83,
2615     WinBuiltinAnyPackageSid                      = 84,
2616     WinCapabilityInternetClientSid               = 85,
2617     WinCapabilityInternetClientServerSid         = 86,
2618     WinCapabilityPrivateNetworkClientServerSid   = 87,
2619     WinCapabilityPicturesLibrarySid              = 88,
2620     WinCapabilityVideosLibrarySid                = 89,
2621     WinCapabilityMusicLibrarySid                 = 90,
2622     WinCapabilityDocumentsLibrarySid             = 91,
2623     WinCapabilitySharedUserCertificatesSid       = 92,
2624     WinCapabilityEnterpriseAuthenticationSid     = 93,
2625     WinCapabilityRemovableStorageSid             = 94
2626 }
2627 struct QUOTA_LIMITS {
2628     SIZE_T PagedPoolLimit;
2629     SIZE_T NonPagedPoolLimit;
2630     SIZE_T MinimumWorkingSetSize;
2631     SIZE_T MaximumWorkingSetSize;
2632     SIZE_T PagefileLimit;
2633     LARGE_INTEGER TimeLimit;
2634 }
2635 alias QUOTA_LIMITS* PQUOTA_LIMITS;
2636 
2637 struct IO_COUNTERS {
2638     ULONGLONG ReadOperationCount;
2639     ULONGLONG WriteOperationCount;
2640     ULONGLONG OtherOperationCount;
2641     ULONGLONG ReadTransferCount;
2642     ULONGLONG WriteTransferCount;
2643     ULONGLONG OtherTransferCount;
2644 }
2645 alias IO_COUNTERS* PIO_COUNTERS;
2646 
2647 struct FILE_NOTIFY_INFORMATION {
2648     DWORD NextEntryOffset;
2649     DWORD Action;
2650     DWORD FileNameLength = 0;
2651     WCHAR _FileName = 0;
2652 
2653     WCHAR* FileName() return { return &_FileName; }
2654 }
2655 alias FILE_NOTIFY_INFORMATION* PFILE_NOTIFY_INFORMATION;
2656 
2657 struct TAPE_ERASE {
2658     DWORD   Type;
2659     BOOLEAN Immediate;
2660 }
2661 alias TAPE_ERASE* PTAPE_ERASE;
2662 
2663 struct TAPE_GET_DRIVE_PARAMETERS {
2664     BOOLEAN ECC;
2665     BOOLEAN Compression;
2666     BOOLEAN DataPadding;
2667     BOOLEAN ReportSetmarks;
2668     DWORD   DefaultBlockSize;
2669     DWORD   MaximumBlockSize;
2670     DWORD   MinimumBlockSize;
2671     DWORD   MaximumPartitionCount;
2672     DWORD   FeaturesLow;
2673     DWORD   FeaturesHigh;
2674     DWORD   EOTWarningZoneSize;
2675 }
2676 alias TAPE_GET_DRIVE_PARAMETERS* PTAPE_GET_DRIVE_PARAMETERS;
2677 
2678 struct TAPE_GET_MEDIA_PARAMETERS {
2679     LARGE_INTEGER Capacity;
2680     LARGE_INTEGER Remaining;
2681     DWORD         BlockSize;
2682     DWORD         PartitionCount;
2683     BOOLEAN       WriteProtected;
2684 }
2685 alias TAPE_GET_MEDIA_PARAMETERS* PTAPE_GET_MEDIA_PARAMETERS;
2686 
2687 struct TAPE_GET_POSITION {
2688     ULONG Type;
2689     ULONG Partition;
2690     ULONG OffsetLow;
2691     ULONG OffsetHigh;
2692 }
2693 alias TAPE_GET_POSITION* PTAPE_GET_POSITION;
2694 
2695 struct TAPE_PREPARE {
2696     DWORD   Operation;
2697     BOOLEAN Immediate;
2698 }
2699 alias TAPE_PREPARE* PTAPE_PREPARE;
2700 
2701 struct TAPE_SET_DRIVE_PARAMETERS {
2702     BOOLEAN ECC;
2703     BOOLEAN Compression;
2704     BOOLEAN DataPadding;
2705     BOOLEAN ReportSetmarks;
2706     ULONG   EOTWarningZoneSize;
2707 }
2708 alias TAPE_SET_DRIVE_PARAMETERS* PTAPE_SET_DRIVE_PARAMETERS;
2709 
2710 struct TAPE_SET_MEDIA_PARAMETERS {
2711     ULONG BlockSize;
2712 }
2713 alias TAPE_SET_MEDIA_PARAMETERS* PTAPE_SET_MEDIA_PARAMETERS;
2714 
2715 struct TAPE_SET_POSITION {
2716     DWORD         Method;
2717     DWORD         Partition;
2718     LARGE_INTEGER Offset;
2719     BOOLEAN       Immediate;
2720 }
2721 alias TAPE_SET_POSITION* PTAPE_SET_POSITION;
2722 
2723 struct TAPE_WRITE_MARKS {
2724     DWORD   Type;
2725     DWORD   Count;
2726     BOOLEAN Immediate;
2727 }
2728 alias TAPE_WRITE_MARKS* PTAPE_WRITE_MARKS;
2729 
2730 struct TAPE_CREATE_PARTITION {
2731     DWORD Method;
2732     DWORD Count;
2733     DWORD Size;
2734 }
2735 alias TAPE_CREATE_PARTITION* PTAPE_CREATE_PARTITION;
2736 
2737 struct MEMORY_BASIC_INFORMATION {
2738     PVOID BaseAddress;
2739     PVOID AllocationBase;
2740     DWORD AllocationProtect;
2741     SIZE_T RegionSize;
2742     DWORD State;
2743     DWORD Protect;
2744     DWORD Type;
2745 }
2746 alias MEMORY_BASIC_INFORMATION* PMEMORY_BASIC_INFORMATION;
2747 
2748 struct MESSAGE_RESOURCE_ENTRY {
2749     WORD Length;
2750     WORD Flags;
2751     BYTE _Text;
2752 
2753     BYTE* Text() return { return &_Text; }
2754 }
2755 alias MESSAGE_RESOURCE_ENTRY* PMESSAGE_RESOURCE_ENTRY;
2756 
2757 struct MESSAGE_RESOURCE_BLOCK {
2758     DWORD LowId;
2759     DWORD HighId;
2760     DWORD OffsetToEntries;
2761 }
2762 alias MESSAGE_RESOURCE_BLOCK* PMESSAGE_RESOURCE_BLOCK;
2763 
2764 struct MESSAGE_RESOURCE_DATA {
2765     DWORD NumberOfBlocks;
2766     MESSAGE_RESOURCE_BLOCK _Blocks;
2767 
2768     MESSAGE_RESOURCE_BLOCK* Blocks() return { return &_Blocks; }
2769 }
2770 alias MESSAGE_RESOURCE_DATA* PMESSAGE_RESOURCE_DATA;
2771 
2772 struct LIST_ENTRY {
2773     LIST_ENTRY* Flink;
2774     LIST_ENTRY* Blink;
2775 }
2776 alias LIST_ENTRY* PLIST_ENTRY;
2777 alias LIST_ENTRY _LIST_ENTRY;
2778 
2779 struct SINGLE_LIST_ENTRY {
2780     SINGLE_LIST_ENTRY* Next;
2781 }
2782 
2783 version (Win64) {
2784     align (16)
2785     struct SLIST_ENTRY {
2786         SLIST_ENTRY* Next;
2787     }
2788 } else {
2789     alias SINGLE_LIST_ENTRY SLIST_ENTRY;
2790 }
2791 alias SINGLE_LIST_ENTRY* PSINGLE_LIST_ENTRY, PSLIST_ENTRY;
2792 
2793 union SLIST_HEADER {
2794     ULONGLONG       Alignment;
2795     struct {
2796         SLIST_ENTRY Next;
2797         WORD        Depth;
2798         WORD        Sequence;
2799     }
2800 }
2801 alias SLIST_HEADER* PSLIST_HEADER;
2802 
2803 struct RTL_CRITICAL_SECTION_DEBUG {
2804     WORD       Type;
2805     WORD       CreatorBackTraceIndex;
2806     RTL_CRITICAL_SECTION* CriticalSection;
2807     LIST_ENTRY ProcessLocksList;
2808     DWORD      EntryCount;
2809     DWORD      ContentionCount;
2810     DWORD[2]   Spare;
2811 }
2812 alias RTL_CRITICAL_SECTION_DEBUG* PRTL_CRITICAL_SECTION_DEBUG;
2813 alias RTL_CRITICAL_SECTION_DEBUG _RTL_CRITICAL_SECTION_DEBUG;
2814 
2815 struct RTL_CRITICAL_SECTION {
2816     PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
2817     LONG   LockCount;
2818     LONG   RecursionCount;
2819     HANDLE OwningThread;
2820     HANDLE LockSemaphore;
2821     ULONG_PTR SpinCount;
2822     alias Reserved = SpinCount;
2823 }
2824 alias RTL_CRITICAL_SECTION* PRTL_CRITICAL_SECTION;
2825 alias RTL_CRITICAL_SECTION _RTL_CRITICAL_SECTION;
2826 
2827 struct EVENTLOGRECORD {
2828     DWORD Length;
2829     DWORD Reserved;
2830     DWORD RecordNumber;
2831     DWORD TimeGenerated;
2832     DWORD TimeWritten;
2833     DWORD EventID;
2834     WORD  EventType;
2835     WORD  NumStrings;
2836     WORD  EventCategory;
2837     WORD  ReservedFlags;
2838     DWORD ClosingRecordNumber;
2839     DWORD StringOffset;
2840     DWORD UserSidLength;
2841     DWORD UserSidOffset;
2842     DWORD DataLength;
2843     DWORD DataOffset;
2844 }
2845 alias EVENTLOGRECORD* PEVENTLOGRECORD;
2846 
2847 struct OSVERSIONINFOA {
2848     DWORD     dwOSVersionInfoSize = OSVERSIONINFOA.sizeof;
2849     DWORD     dwMajorVersion;
2850     DWORD     dwMinorVersion;
2851     DWORD     dwBuildNumber;
2852     DWORD     dwPlatformId;
2853     CHAR[128] szCSDVersion = 0;
2854 }
2855 alias OSVERSIONINFOA* POSVERSIONINFOA, LPOSVERSIONINFOA;
2856 
2857 struct OSVERSIONINFOW {
2858     DWORD      dwOSVersionInfoSize = OSVERSIONINFOW.sizeof;
2859     DWORD      dwMajorVersion;
2860     DWORD      dwMinorVersion;
2861     DWORD      dwBuildNumber;
2862     DWORD      dwPlatformId;
2863     WCHAR[128] szCSDVersion = 0;
2864 }
2865 alias OSVERSIONINFOW* POSVERSIONINFOW, LPOSVERSIONINFOW;
2866 
2867 struct OSVERSIONINFOEXA {
2868     DWORD     dwOSVersionInfoSize;
2869     DWORD     dwMajorVersion;
2870     DWORD     dwMinorVersion;
2871     DWORD     dwBuildNumber;
2872     DWORD     dwPlatformId;
2873     CHAR[128] szCSDVersion = 0;
2874     WORD      wServicePackMajor;
2875     WORD      wServicePackMinor;
2876     WORD      wSuiteMask;
2877     BYTE      wProductType;
2878     BYTE      wReserved;
2879 }
2880 alias OSVERSIONINFOEXA* POSVERSIONINFOEXA, LPOSVERSIONINFOEXA;
2881 
2882 struct OSVERSIONINFOEXW {
2883     DWORD      dwOSVersionInfoSize;
2884     DWORD      dwMajorVersion;
2885     DWORD      dwMinorVersion;
2886     DWORD      dwBuildNumber;
2887     DWORD      dwPlatformId;
2888     WCHAR[128] szCSDVersion = 0;
2889     WORD       wServicePackMajor;
2890     WORD       wServicePackMinor;
2891     WORD       wSuiteMask;
2892     BYTE       wProductType;
2893     BYTE       wReserved;
2894 }
2895 alias OSVERSIONINFOEXW* POSVERSIONINFOEXW, LPOSVERSIONINFOEXW;
2896 
2897 align(2) struct IMAGE_VXD_HEADER {
2898     WORD     e32_magic;
2899     BYTE     e32_border;
2900     BYTE     e32_worder;
2901     DWORD    e32_level;
2902     WORD     e32_cpu;
2903     WORD     e32_os;
2904     DWORD    e32_ver;
2905     DWORD    e32_mflags;
2906     DWORD    e32_mpages;
2907     DWORD    e32_startobj;
2908     DWORD    e32_eip;
2909     DWORD    e32_stackobj;
2910     DWORD    e32_esp;
2911     DWORD    e32_pagesize;
2912     DWORD    e32_lastpagesize;
2913     DWORD    e32_fixupsize;
2914     DWORD    e32_fixupsum;
2915     DWORD    e32_ldrsize;
2916     DWORD    e32_ldrsum;
2917     DWORD    e32_objtab;
2918     DWORD    e32_objcnt;
2919     DWORD    e32_objmap;
2920     DWORD    e32_itermap;
2921     DWORD    e32_rsrctab;
2922     DWORD    e32_rsrccnt;
2923     DWORD    e32_restab;
2924     DWORD    e32_enttab;
2925     DWORD    e32_dirtab;
2926     DWORD    e32_dircnt;
2927     DWORD    e32_fpagetab;
2928     DWORD    e32_frectab;
2929     DWORD    e32_impmod;
2930     DWORD    e32_impmodcnt;
2931     DWORD    e32_impproc;
2932     DWORD    e32_pagesum;
2933     DWORD    e32_datapage;
2934     DWORD    e32_preload;
2935     DWORD    e32_nrestab;
2936     DWORD    e32_cbnrestab;
2937     DWORD    e32_nressum;
2938     DWORD    e32_autodata;
2939     DWORD    e32_debuginfo;
2940     DWORD    e32_debuglen;
2941     DWORD    e32_instpreload;
2942     DWORD    e32_instdemand;
2943     DWORD    e32_heapsize;
2944     BYTE[12] e32_res3;
2945     DWORD    e32_winresoff;
2946     DWORD    e32_winreslen;
2947     WORD     e32_devid;
2948     WORD     e32_ddkver;
2949 }
2950 alias IMAGE_VXD_HEADER* PIMAGE_VXD_HEADER;
2951 
2952 align(4):
2953 struct IMAGE_FILE_HEADER {
2954     WORD  Machine;
2955     WORD  NumberOfSections;
2956     DWORD TimeDateStamp;
2957     DWORD PointerToSymbolTable;
2958     DWORD NumberOfSymbols;
2959     WORD  SizeOfOptionalHeader;
2960     WORD  Characteristics;
2961 }
2962 alias IMAGE_FILE_HEADER* PIMAGE_FILE_HEADER;
2963 // const IMAGE_SIZEOF_FILE_HEADER = IMAGE_FILE_HEADER.sizeof;
2964 
2965 struct IMAGE_DATA_DIRECTORY {
2966     DWORD VirtualAddress;
2967     DWORD Size;
2968 }
2969 alias IMAGE_DATA_DIRECTORY* PIMAGE_DATA_DIRECTORY;
2970 
2971 struct IMAGE_OPTIONAL_HEADER32 {
2972     WORD  Magic;
2973     BYTE  MajorLinkerVersion;
2974     BYTE  MinorLinkerVersion;
2975     DWORD SizeOfCode;
2976     DWORD SizeOfInitializedData;
2977     DWORD SizeOfUninitializedData;
2978     DWORD AddressOfEntryPoint;
2979     DWORD BaseOfCode;
2980     DWORD BaseOfData;
2981     DWORD ImageBase;
2982     DWORD SectionAlignment;
2983     DWORD FileAlignment;
2984     WORD  MajorOperatingSystemVersion;
2985     WORD  MinorOperatingSystemVersion;
2986     WORD  MajorImageVersion;
2987     WORD  MinorImageVersion;
2988     WORD  MajorSubsystemVersion;
2989     WORD  MinorSubsystemVersion;
2990     DWORD Win32VersionValue;
2991     DWORD SizeOfImage;
2992     DWORD SizeOfHeaders;
2993     DWORD CheckSum;
2994     WORD  Subsystem;
2995     WORD  DllCharacteristics;
2996     DWORD SizeOfStackReserve;
2997     DWORD SizeOfStackCommit;
2998     DWORD SizeOfHeapReserve;
2999     DWORD SizeOfHeapCommit;
3000     DWORD LoaderFlags;
3001     DWORD NumberOfRvaAndSizes;
3002     IMAGE_DATA_DIRECTORY[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] DataDirectory;
3003 }
3004 alias IMAGE_OPTIONAL_HEADER32* PIMAGE_OPTIONAL_HEADER32;
3005 
3006 struct IMAGE_OPTIONAL_HEADER64 {
3007     WORD      Magic;
3008     BYTE      MajorLinkerVersion;
3009     BYTE      MinorLinkerVersion;
3010     DWORD     SizeOfCode;
3011     DWORD     SizeOfInitializedData;
3012     DWORD     SizeOfUninitializedData;
3013     DWORD     AddressOfEntryPoint;
3014     DWORD     BaseOfCode;
3015     ULONGLONG ImageBase;
3016     DWORD     SectionAlignment;
3017     DWORD     FileAlignment;
3018     WORD      MajorOperatingSystemVersion;
3019     WORD      MinorOperatingSystemVersion;
3020     WORD      MajorImageVersion;
3021     WORD      MinorImageVersion;
3022     WORD      MajorSubsystemVersion;
3023     WORD      MinorSubsystemVersion;
3024     DWORD     Win32VersionValue;
3025     DWORD     SizeOfImage;
3026     DWORD     SizeOfHeaders;
3027     DWORD     CheckSum;
3028     WORD      Subsystem;
3029     WORD      DllCharacteristics;
3030     ULONGLONG SizeOfStackReserve;
3031     ULONGLONG SizeOfStackCommit;
3032     ULONGLONG SizeOfHeapReserve;
3033     ULONGLONG SizeOfHeapCommit;
3034     DWORD     LoaderFlags;
3035     DWORD     NumberOfRvaAndSizes;
3036     IMAGE_DATA_DIRECTORY[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] DataDirectory;
3037 }
3038 alias IMAGE_OPTIONAL_HEADER64* PIMAGE_OPTIONAL_HEADER64;
3039 
3040 struct IMAGE_ROM_OPTIONAL_HEADER {
3041     WORD     Magic;
3042     BYTE     MajorLinkerVersion;
3043     BYTE     MinorLinkerVersion;
3044     DWORD    SizeOfCode;
3045     DWORD    SizeOfInitializedData;
3046     DWORD    SizeOfUninitializedData;
3047     DWORD    AddressOfEntryPoint;
3048     DWORD    BaseOfCode;
3049     DWORD    BaseOfData;
3050     DWORD    BaseOfBss;
3051     DWORD    GprMask;
3052     DWORD[4] CprMask;
3053     DWORD    GpValue;
3054 }
3055 alias IMAGE_ROM_OPTIONAL_HEADER* PIMAGE_ROM_OPTIONAL_HEADER;
3056 
3057 align(2):
3058 struct IMAGE_DOS_HEADER {
3059     WORD     e_magic;
3060     WORD     e_cblp;
3061     WORD     e_cp;
3062     WORD     e_crlc;
3063     WORD     e_cparhdr;
3064     WORD     e_minalloc;
3065     WORD     e_maxalloc;
3066     WORD     e_ss;
3067     WORD     e_sp;
3068     WORD     e_csum;
3069     WORD     e_ip;
3070     WORD     e_cs;
3071     WORD     e_lfarlc;
3072     WORD     e_ovno;
3073     WORD[4] e_res;
3074     WORD     e_oemid;
3075     WORD     e_oeminfo;
3076     WORD[10] e_res2;
3077     LONG     e_lfanew;
3078 }
3079 alias IMAGE_DOS_HEADER* PIMAGE_DOS_HEADER;
3080 
3081 struct IMAGE_OS2_HEADER {
3082     WORD ne_magic;
3083     CHAR ne_ver = 0;
3084     CHAR ne_rev = 0;
3085     WORD ne_enttab;
3086     WORD ne_cbenttab;
3087     LONG ne_crc;
3088     WORD ne_flags;
3089     WORD ne_autodata;
3090     WORD ne_heap;
3091     WORD ne_stack;
3092     LONG ne_csip;
3093     LONG ne_sssp;
3094     WORD ne_cseg;
3095     WORD ne_cmod;
3096     WORD ne_cbnrestab;
3097     WORD ne_segtab;
3098     WORD ne_rsrctab;
3099     WORD ne_restab;
3100     WORD ne_modtab;
3101     WORD ne_imptab;
3102     LONG ne_nrestab;
3103     WORD ne_cmovent;
3104     WORD ne_align;
3105     WORD ne_cres;
3106     BYTE ne_exetyp;
3107     BYTE ne_flagsothers;
3108     WORD ne_pretthunks;
3109     WORD ne_psegrefbytes;
3110     WORD ne_swaparea;
3111     WORD ne_expver;
3112 }
3113 alias IMAGE_OS2_HEADER* PIMAGE_OS2_HEADER;
3114 
3115 align(4) struct IMAGE_NT_HEADERS32 {
3116     DWORD                 Signature;
3117     IMAGE_FILE_HEADER     FileHeader;
3118     IMAGE_OPTIONAL_HEADER32 OptionalHeader;
3119 }
3120 alias IMAGE_NT_HEADERS32* PIMAGE_NT_HEADERS32;
3121 
3122 align(4) struct IMAGE_NT_HEADERS64 {
3123     DWORD                 Signature;
3124     IMAGE_FILE_HEADER     FileHeader;
3125     IMAGE_OPTIONAL_HEADER64 OptionalHeader;
3126 }
3127 alias IMAGE_NT_HEADERS64* PIMAGE_NT_HEADERS64;
3128 
3129 struct IMAGE_ROM_HEADERS {
3130     IMAGE_FILE_HEADER         FileHeader;
3131     IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
3132 }
3133 alias IMAGE_ROM_HEADERS* PIMAGE_ROM_HEADERS;
3134 
3135 struct IMAGE_SECTION_HEADER {
3136     BYTE[IMAGE_SIZEOF_SHORT_NAME] Name;
3137     union _Misc {
3138         DWORD PhysicalAddress;
3139         DWORD VirtualSize;
3140     }
3141     _Misc Misc;
3142     DWORD VirtualAddress;
3143     DWORD SizeOfRawData;
3144     DWORD PointerToRawData;
3145     DWORD PointerToRelocations;
3146     DWORD PointerToLinenumbers;
3147     WORD  NumberOfRelocations;
3148     WORD  NumberOfLinenumbers;
3149     DWORD Characteristics;
3150 }
3151 alias IMAGE_SECTION_HEADER* PIMAGE_SECTION_HEADER;
3152 
3153 struct IMAGE_SYMBOL {
3154     union _N {
3155         BYTE[8]   ShortName;
3156         struct _Name {
3157             DWORD Short;
3158             DWORD Long;
3159         }
3160         _Name Name;
3161         DWORD[2]  LongName; // PBYTE[2]
3162     }
3163     _N    N;
3164     DWORD Value;
3165     SHORT SectionNumber;
3166     WORD  Type;
3167     BYTE  StorageClass;
3168     BYTE  NumberOfAuxSymbols;
3169 }
3170 alias IMAGE_SYMBOL* PIMAGE_SYMBOL;
3171 
3172 union IMAGE_AUX_SYMBOL {
3173     struct _Sym {
3174         DWORD           TagIndex;
3175         union _Misc {
3176             struct _LnSz {
3177                 WORD    Linenumber;
3178                 WORD    Size;
3179             }
3180             _LnSz       LnSz;
3181             DWORD       TotalSize;
3182         }
3183         _Misc Misc;
3184         union _FcnAry {
3185             struct _Function {
3186                 DWORD   PointerToLinenumber;
3187                 DWORD   PointerToNextFunction;
3188             }
3189             _Function   Function;
3190             struct _Array {
3191                 WORD[4] Dimension;
3192             }
3193             _Array      Array;
3194         }
3195         _FcnAry         FcnAry;
3196         WORD            TvIndex;
3197     }
3198     _Sym                Sym;
3199     struct _File {
3200         BYTE[IMAGE_SIZEOF_SYMBOL] Name;
3201     }
3202     _File               File;
3203     struct _Section {
3204         DWORD           Length;
3205         WORD            NumberOfRelocations;
3206         WORD            NumberOfLinenumbers;
3207         DWORD           CheckSum;
3208         SHORT           Number;
3209         BYTE            Selection;
3210     }
3211     _Section            Section;
3212 }
3213 alias IMAGE_AUX_SYMBOL* PIMAGE_AUX_SYMBOL;
3214 
3215 struct IMAGE_COFF_SYMBOLS_HEADER {
3216     DWORD NumberOfSymbols;
3217     DWORD LvaToFirstSymbol;
3218     DWORD NumberOfLinenumbers;
3219     DWORD LvaToFirstLinenumber;
3220     DWORD RvaToFirstByteOfCode;
3221     DWORD RvaToLastByteOfCode;
3222     DWORD RvaToFirstByteOfData;
3223     DWORD RvaToLastByteOfData;
3224 }
3225 alias IMAGE_COFF_SYMBOLS_HEADER* PIMAGE_COFF_SYMBOLS_HEADER;
3226 
3227 struct IMAGE_RELOCATION {
3228     union {
3229         DWORD VirtualAddress;
3230         DWORD RelocCount;
3231     }
3232     DWORD     SymbolTableIndex;
3233     WORD      Type;
3234 }
3235 alias IMAGE_RELOCATION* PIMAGE_RELOCATION;
3236 
3237 align(4) struct IMAGE_BASE_RELOCATION {
3238     DWORD VirtualAddress;
3239     DWORD SizeOfBlock;
3240 }
3241 alias IMAGE_BASE_RELOCATION* PIMAGE_BASE_RELOCATION;
3242 
3243 align(2) struct IMAGE_LINENUMBER {
3244     union _Type {
3245         DWORD SymbolTableIndex;
3246         DWORD VirtualAddress;
3247     }
3248     _Type Type;
3249     WORD  Linenumber;
3250 }
3251 alias IMAGE_LINENUMBER* PIMAGE_LINENUMBER;
3252 
3253 align(4):
3254 struct IMAGE_ARCHIVE_MEMBER_HEADER {
3255     BYTE[16] Name;
3256     BYTE[12] Date;
3257     BYTE[6]  UserID;
3258     BYTE[6]  GroupID;
3259     BYTE[8]  Mode;
3260     BYTE[10] Size;
3261     BYTE[2]  EndHeader;
3262 }
3263 alias IMAGE_ARCHIVE_MEMBER_HEADER* PIMAGE_ARCHIVE_MEMBER_HEADER;
3264 
3265 struct IMAGE_EXPORT_DIRECTORY {
3266     DWORD Characteristics;
3267     DWORD TimeDateStamp;
3268     WORD  MajorVersion;
3269     WORD  MinorVersion;
3270     DWORD Name;
3271     DWORD Base;
3272     DWORD NumberOfFunctions;
3273     DWORD NumberOfNames;
3274     DWORD AddressOfFunctions;
3275     DWORD AddressOfNames;
3276     DWORD AddressOfNameOrdinals;
3277 }
3278 alias IMAGE_EXPORT_DIRECTORY* PIMAGE_EXPORT_DIRECTORY;
3279 
3280 struct IMAGE_IMPORT_BY_NAME {
3281     WORD Hint;
3282     BYTE _Name;
3283 
3284     BYTE* Name() return { return &_Name; }
3285 }
3286 alias IMAGE_IMPORT_BY_NAME* PIMAGE_IMPORT_BY_NAME;
3287 
3288 struct IMAGE_THUNK_DATA32 {
3289     union _u1 {
3290         DWORD ForwarderString;
3291         DWORD Function;
3292         DWORD Ordinal;
3293         DWORD AddressOfData;
3294     }
3295     _u1 u1;
3296 }
3297 alias IMAGE_THUNK_DATA32* PIMAGE_THUNK_DATA32;
3298 
3299 struct IMAGE_THUNK_DATA64 {
3300     union _u1 {
3301         ULONGLONG ForwarderString;
3302         ULONGLONG Function;
3303         ULONGLONG Ordinal;
3304         ULONGLONG AddressOfData;
3305     }
3306     _u1 u1;
3307 }
3308 alias IMAGE_THUNK_DATA64* PIMAGE_THUNK_DATA64;
3309 
3310 struct IMAGE_IMPORT_DESCRIPTOR {
3311     union {
3312         DWORD Characteristics;
3313         DWORD OriginalFirstThunk;
3314     }
3315     DWORD TimeDateStamp;
3316     DWORD ForwarderChain;
3317     DWORD Name;
3318     DWORD FirstThunk;
3319 }
3320 alias IMAGE_IMPORT_DESCRIPTOR* PIMAGE_IMPORT_DESCRIPTOR;
3321 
3322 struct IMAGE_BOUND_IMPORT_DESCRIPTOR {
3323     DWORD TimeDateStamp;
3324     WORD  OffsetModuleName;
3325     WORD  NumberOfModuleForwarderRefs;
3326 }
3327 alias IMAGE_BOUND_IMPORT_DESCRIPTOR* PIMAGE_BOUND_IMPORT_DESCRIPTOR;
3328 
3329 struct IMAGE_BOUND_FORWARDER_REF {
3330     DWORD TimeDateStamp;
3331     WORD  OffsetModuleName;
3332     WORD  Reserved;
3333 }
3334 alias IMAGE_BOUND_FORWARDER_REF* PIMAGE_BOUND_FORWARDER_REF;
3335 
3336 struct IMAGE_TLS_DIRECTORY32 {
3337     DWORD StartAddressOfRawData;
3338     DWORD EndAddressOfRawData;
3339     DWORD AddressOfIndex;
3340     DWORD AddressOfCallBacks;
3341     DWORD SizeOfZeroFill;
3342     DWORD Characteristics;
3343 }
3344 alias IMAGE_TLS_DIRECTORY32* PIMAGE_TLS_DIRECTORY32;
3345 
3346 struct IMAGE_TLS_DIRECTORY64 {
3347     ULONGLONG StartAddressOfRawData;
3348     ULONGLONG EndAddressOfRawData;
3349     ULONGLONG AddressOfIndex;
3350     ULONGLONG AddressOfCallBacks;
3351     DWORD     SizeOfZeroFill;
3352     DWORD     Characteristics;
3353 }
3354 alias IMAGE_TLS_DIRECTORY64* PIMAGE_TLS_DIRECTORY64;
3355 
3356 struct IMAGE_RESOURCE_DIRECTORY {
3357     DWORD Characteristics;
3358     DWORD TimeDateStamp;
3359     WORD  MajorVersion;
3360     WORD  MinorVersion;
3361     WORD  NumberOfNamedEntries;
3362     WORD  NumberOfIdEntries;
3363 }
3364 alias IMAGE_RESOURCE_DIRECTORY* PIMAGE_RESOURCE_DIRECTORY;
3365 
3366 struct IMAGE_RESOURCE_DIRECTORY_ENTRY {
3367     union {
3368         /+struct {
3369             DWORD NameOffset:31;
3370             DWORD NameIsString:1;
3371         }+/
3372         DWORD Name;
3373         WORD Id;
3374     }
3375     DWORD OffsetToData;
3376         /+struct {
3377             DWORD OffsetToDirectory:31;
3378             DWORD DataIsDirectory:1;
3379         }+/
3380 
3381     uint NameOffset()        { return Name & 0x7FFFFFFF; }
3382     bool NameIsString()      { return cast(bool)(Name & 0x80000000); }
3383     uint OffsetToDirectory() { return OffsetToData & 0x7FFFFFFF; }
3384     bool DataIsDirectory()   { return cast(bool)(OffsetToData & 0x80000000); }
3385 
3386     uint NameOffset(uint n) {
3387         Name = (Name & 0x80000000) | (n & 0x7FFFFFFF);
3388         return n & 0x7FFFFFFF;
3389     }
3390 
3391     bool NameIsString(bool n) {
3392         Name = (Name & 0x7FFFFFFF) | (n << 31); return n;
3393     }
3394 
3395     uint OffsetToDirectory(uint o) {
3396         OffsetToData = (OffsetToData & 0x80000000) | (o & 0x7FFFFFFF);
3397         return o & 0x7FFFFFFF;
3398     }
3399 
3400     bool DataIsDirectory(bool d) {
3401         OffsetToData = (OffsetToData & 0x7FFFFFFF) | (d << 31); return d;
3402     }
3403 }
3404 alias IMAGE_RESOURCE_DIRECTORY_ENTRY* PIMAGE_RESOURCE_DIRECTORY_ENTRY;
3405 
3406 struct IMAGE_RESOURCE_DIRECTORY_STRING {
3407     WORD Length;
3408     CHAR _NameString = 0;
3409 
3410     CHAR* NameString() return { return &_NameString; }
3411 }
3412 alias IMAGE_RESOURCE_DIRECTORY_STRING* PIMAGE_RESOURCE_DIRECTORY_STRING;
3413 
3414 struct IMAGE_RESOURCE_DIR_STRING_U {
3415     WORD  Length;
3416     WCHAR _NameString = 0;
3417 
3418     WCHAR* NameString() return { return &_NameString; }
3419 }
3420 alias IMAGE_RESOURCE_DIR_STRING_U* PIMAGE_RESOURCE_DIR_STRING_U;
3421 
3422 struct IMAGE_RESOURCE_DATA_ENTRY {
3423     DWORD OffsetToData;
3424     DWORD Size;
3425     DWORD CodePage;
3426     DWORD Reserved;
3427 }
3428 alias IMAGE_RESOURCE_DATA_ENTRY* PIMAGE_RESOURCE_DATA_ENTRY;
3429 
3430 struct IMAGE_LOAD_CONFIG_DIRECTORY32 {
3431     DWORD    Characteristics;
3432     DWORD    TimeDateStamp;
3433     WORD     MajorVersion;
3434     WORD     MinorVersion;
3435     DWORD    GlobalFlagsClear;
3436     DWORD    GlobalFlagsSet;
3437     DWORD    CriticalSectionDefaultTimeout;
3438     DWORD    DeCommitFreeBlockThreshold;
3439     DWORD    DeCommitTotalFreeThreshold;
3440     PVOID    LockPrefixTable;
3441     DWORD    MaximumAllocationSize;
3442     DWORD    VirtualMemoryThreshold;
3443     DWORD    ProcessHeapFlags;
3444     DWORD[4] Reserved;
3445 }
3446 alias IMAGE_LOAD_CONFIG_DIRECTORY32* PIMAGE_LOAD_CONFIG_DIRECTORY32;
3447 
3448 struct IMAGE_LOAD_CONFIG_DIRECTORY64 {
3449     DWORD     Characteristics;
3450     DWORD     TimeDateStamp;
3451     WORD      MajorVersion;
3452     WORD      MinorVersion;
3453     DWORD     GlobalFlagsClear;
3454     DWORD     GlobalFlagsSet;
3455     DWORD     CriticalSectionDefaultTimeout;
3456     ULONGLONG DeCommitFreeBlockThreshold;
3457     ULONGLONG DeCommitTotalFreeThreshold;
3458     ULONGLONG LockPrefixTable;
3459     ULONGLONG MaximumAllocationSize;
3460     ULONGLONG VirtualMemoryThreshold;
3461     ULONGLONG ProcessAffinityMask;
3462     DWORD     ProcessHeapFlags;
3463     WORD      CSDFlags;
3464     WORD      Reserved1;
3465     ULONGLONG EditList;
3466     DWORD[2]  Reserved;
3467 }
3468 alias IMAGE_LOAD_CONFIG_DIRECTORY64* PIMAGE_LOAD_CONFIG_DIRECTORY64;
3469 
3470 version (Win64) {
3471     alias IMAGE_LOAD_CONFIG_DIRECTORY64 IMAGE_LOAD_CONFIG_DIRECTORY;
3472 } else {
3473     alias IMAGE_LOAD_CONFIG_DIRECTORY32 IMAGE_LOAD_CONFIG_DIRECTORY;
3474 }
3475 alias IMAGE_LOAD_CONFIG_DIRECTORY* PIMAGE_LOAD_CONFIG_DIRECTORY;
3476 
3477 // Note versions for Alpha, Alpha64, ARM removed.
3478 struct IMAGE_RUNTIME_FUNCTION_ENTRY {
3479     DWORD BeginAddress;
3480     DWORD EndAddress;
3481     union {
3482         DWORD UnwindInfoAddress;
3483         DWORD UnwindData;
3484     }
3485 }
3486 alias IMAGE_RUNTIME_FUNCTION_ENTRY* PIMAGE_RUNTIME_FUNCTION_ENTRY;
3487 
3488 struct IMAGE_CE_RUNTIME_FUNCTION_ENTRY {
3489     uint      FuncStart;
3490     union {
3491         ubyte PrologLen;
3492         uint  _bf;
3493     }
3494 /+
3495     unsigned int FuncLen:22;
3496     unsigned int ThirtyTwoBit:1;
3497     unsigned int ExceptionFlag:1;
3498 +/
3499     uint FuncLen()       { return (_bf >> 8) & 0x3FFFFF; }
3500     bool ThirtyTwoBit()  { return cast(bool)(_bf & 0x40000000); }
3501     bool ExceptionFlag() { return cast(bool)(_bf & 0x80000000); }
3502 
3503     uint FuncLen(uint f) {
3504         _bf = (_bf & ~0x3FFFFF00) | ((f & 0x3FFFFF) << 8); return f & 0x3FFFFF;
3505     }
3506 
3507     bool ThirtyTwoBit(bool t) {
3508         _bf = (_bf & ~0x40000000) | (t << 30); return t;
3509     }
3510 
3511     bool ExceptionFlag(bool e) {
3512         _bf = (_bf & ~0x80000000) | (e << 31); return e;
3513     }
3514 }
3515 alias IMAGE_CE_RUNTIME_FUNCTION_ENTRY* PIMAGE_CE_RUNTIME_FUNCTION_ENTRY;
3516 
3517 struct IMAGE_DEBUG_DIRECTORY {
3518     DWORD Characteristics;
3519     DWORD TimeDateStamp;
3520     WORD  MajorVersion;
3521     WORD  MinorVersion;
3522     DWORD Type;
3523     DWORD SizeOfData;
3524     DWORD AddressOfRawData;
3525     DWORD PointerToRawData;
3526 }
3527 alias IMAGE_DEBUG_DIRECTORY* PIMAGE_DEBUG_DIRECTORY;
3528 
3529 struct FPO_DATA {
3530     DWORD  ulOffStart;
3531     DWORD  cbProcSize;
3532     DWORD  cdwLocals;
3533     WORD   cdwParams;
3534     ubyte  cbProlog;
3535     ubyte  _bf;
3536 /+
3537     WORD cbRegs:3;
3538     WORD fHasSEH:1;
3539     WORD fUseBP:1;
3540     WORD reserved:1;
3541     WORD cbFrame:2;
3542 +/
3543     ubyte cbRegs()  { return cast(ubyte)(_bf & 0x07); }
3544     bool fHasSEH()  { return cast(bool)(_bf & 0x08); }
3545     bool fUseBP()   { return cast(bool)(_bf & 0x10); }
3546     bool reserved() { return cast(bool)(_bf & 0x20); }
3547     ubyte cbFrame() { return cast(ubyte)(_bf >> 6); }
3548 
3549     ubyte cbRegs(ubyte c) {
3550         _bf = cast(ubyte) ((_bf & ~0x07) | (c & 0x07));
3551         return cast(ubyte)(c & 0x07);
3552     }
3553 
3554     bool fHasSEH(bool f)  { _bf = cast(ubyte)((_bf & ~0x08) | (f << 3)); return f; }
3555     bool fUseBP(bool f)   { _bf = cast(ubyte)((_bf & ~0x10) | (f << 4)); return f; }
3556     bool reserved(bool r) { _bf = cast(ubyte)((_bf & ~0x20) | (r << 5)); return r; }
3557 
3558     ubyte cbFrame(ubyte c) {
3559         _bf = cast(ubyte) ((_bf & ~0xC0) | ((c & 0x03) << 6));
3560         return cast(ubyte)(c & 0x03);
3561     }
3562 }
3563 alias FPO_DATA* PFPO_DATA;
3564 
3565 struct IMAGE_DEBUG_MISC {
3566     DWORD   DataType;
3567     DWORD   Length;
3568     BOOLEAN Unicode;
3569     BYTE[3] Reserved;
3570     BYTE    _Data;
3571 
3572     BYTE*   Data() return { return &_Data; }
3573 }
3574 alias IMAGE_DEBUG_MISC* PIMAGE_DEBUG_MISC;
3575 
3576 struct IMAGE_FUNCTION_ENTRY {
3577     DWORD StartingAddress;
3578     DWORD EndingAddress;
3579     DWORD EndOfPrologue;
3580 }
3581 alias IMAGE_FUNCTION_ENTRY* PIMAGE_FUNCTION_ENTRY;
3582 
3583 struct IMAGE_FUNCTION_ENTRY64 {
3584     ULONGLONG     StartingAddress;
3585     ULONGLONG     EndingAddress;
3586     union {
3587         ULONGLONG EndOfPrologue;
3588         ULONGLONG UnwindInfoAddress;
3589     }
3590 }
3591 alias IMAGE_FUNCTION_ENTRY64* PIMAGE_FUNCTION_ENTRY64;
3592 
3593 struct IMAGE_SEPARATE_DEBUG_HEADER {
3594     WORD     Signature;
3595     WORD     Flags;
3596     WORD     Machine;
3597     WORD     Characteristics;
3598     DWORD    TimeDateStamp;
3599     DWORD    CheckSum;
3600     DWORD    ImageBase;
3601     DWORD    SizeOfImage;
3602     DWORD    NumberOfSections;
3603     DWORD    ExportedNamesSize;
3604     DWORD    DebugDirectorySize;
3605     DWORD    SectionAlignment;
3606     DWORD[2] Reserved;
3607 }
3608 alias IMAGE_SEPARATE_DEBUG_HEADER* PIMAGE_SEPARATE_DEBUG_HEADER;
3609 
3610 enum SERVICE_NODE_TYPE {
3611     DriverType               = SERVICE_KERNEL_DRIVER,
3612     FileSystemType           = SERVICE_FILE_SYSTEM_DRIVER,
3613     Win32ServiceOwnProcess   = SERVICE_WIN32_OWN_PROCESS,
3614     Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
3615     AdapterType              = SERVICE_ADAPTER,
3616     RecognizerType           = SERVICE_RECOGNIZER_DRIVER
3617 }
3618 
3619 enum SERVICE_LOAD_TYPE {
3620     BootLoad    = SERVICE_BOOT_START,
3621     SystemLoad  = SERVICE_SYSTEM_START,
3622     AutoLoad    = SERVICE_AUTO_START,
3623     DemandLoad  = SERVICE_DEMAND_START,
3624     DisableLoad = SERVICE_DISABLED
3625 }
3626 
3627 enum SERVICE_ERROR_TYPE {
3628     IgnoreError   = SERVICE_ERROR_IGNORE,
3629     NormalError   = SERVICE_ERROR_NORMAL,
3630     SevereError   = SERVICE_ERROR_SEVERE,
3631     CriticalError = SERVICE_ERROR_CRITICAL
3632 }
3633 alias SERVICE_ERROR_TYPE _CM_ERROR_CONTROL_TYPE;
3634 
3635 //DAC: According to MSJ, 'UnderTheHood', May 1996, this
3636 // structure is not documented in any official Microsoft header file.
3637 alias void EXCEPTION_REGISTRATION_RECORD;
3638 
3639 align:
3640 struct NT_TIB {
3641     EXCEPTION_REGISTRATION_RECORD *ExceptionList;
3642     PVOID StackBase;
3643     PVOID StackLimit;
3644     PVOID SubSystemTib;
3645     union {
3646         PVOID FiberData;
3647         DWORD Version;
3648     }
3649     PVOID ArbitraryUserPointer;
3650     NT_TIB *Self;
3651 }
3652 alias NT_TIB* PNT_TIB;
3653 
3654 struct REPARSE_DATA_BUFFER {
3655     DWORD  ReparseTag;
3656     WORD   ReparseDataLength;
3657     WORD   Reserved;
3658     union {
3659         struct _GenericReparseBuffer {
3660             BYTE  _DataBuffer;
3661 
3662             BYTE* DataBuffer() return { return &_DataBuffer; }
3663         }
3664         _GenericReparseBuffer GenericReparseBuffer;
3665         struct _SymbolicLinkReparseBuffer {
3666             WORD  SubstituteNameOffset;
3667             WORD  SubstituteNameLength;
3668             WORD  PrintNameOffset;
3669             WORD  PrintNameLength;
3670             // ??? This is in MinGW, but absent in MSDN docs
3671             ULONG Flags;
3672             WCHAR _PathBuffer = 0;
3673 
3674             WCHAR* PathBuffer() return { return &_PathBuffer; }
3675         }
3676         _SymbolicLinkReparseBuffer SymbolicLinkReparseBuffer;
3677         struct _MountPointReparseBuffer {
3678             WORD  SubstituteNameOffset;
3679             WORD  SubstituteNameLength;
3680             WORD  PrintNameOffset;
3681             WORD  PrintNameLength;
3682             WCHAR _PathBuffer = 0;
3683 
3684             WCHAR* PathBuffer() return { return &_PathBuffer; }
3685         }
3686         _MountPointReparseBuffer MountPointReparseBuffer;
3687     }
3688 }
3689 alias REPARSE_DATA_BUFFER *PREPARSE_DATA_BUFFER;
3690 
3691 struct REPARSE_GUID_DATA_BUFFER {
3692     DWORD    ReparseTag;
3693     WORD     ReparseDataLength;
3694     WORD     Reserved;
3695     GUID     ReparseGuid;
3696     struct _GenericReparseBuffer {
3697         BYTE _DataBuffer;
3698 
3699         BYTE* DataBuffer() return { return &_DataBuffer; }
3700     }
3701     _GenericReparseBuffer GenericReparseBuffer;
3702 }
3703 alias REPARSE_GUID_DATA_BUFFER* PREPARSE_GUID_DATA_BUFFER;
3704 
3705 enum size_t
3706     REPARSE_DATA_BUFFER_HEADER_SIZE = REPARSE_DATA_BUFFER.GenericReparseBuffer.offsetof,
3707     REPARSE_GUID_DATA_BUFFER_HEADER_SIZE = REPARSE_GUID_DATA_BUFFER.GenericReparseBuffer.offsetof,
3708     MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16384;
3709 
3710 
3711 struct REPARSE_POINT_INFORMATION {
3712     WORD ReparseDataLength;
3713     WORD UnparsedNameLength;
3714 }
3715 alias REPARSE_POINT_INFORMATION* PREPARSE_POINT_INFORMATION;
3716 
3717 union FILE_SEGMENT_ELEMENT {
3718     PVOID64   Buffer;
3719     ULONGLONG Alignment;
3720 }
3721 alias FILE_SEGMENT_ELEMENT* PFILE_SEGMENT_ELEMENT;
3722 
3723 // JOBOBJECT_BASIC_LIMIT_INFORMATION.LimitFlags constants
3724 enum DWORD
3725     JOB_OBJECT_LIMIT_WORKINGSET                 = 0x0001,
3726     JOB_OBJECT_LIMIT_PROCESS_TIME               = 0x0002,
3727     JOB_OBJECT_LIMIT_JOB_TIME                   = 0x0004,
3728     JOB_OBJECT_LIMIT_ACTIVE_PROCESS             = 0x0008,
3729     JOB_OBJECT_LIMIT_AFFINITY                   = 0x0010,
3730     JOB_OBJECT_LIMIT_PRIORITY_CLASS             = 0x0020,
3731     JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME          = 0x0040,
3732     JOB_OBJECT_LIMIT_SCHEDULING_CLASS           = 0x0080,
3733     JOB_OBJECT_LIMIT_PROCESS_MEMORY             = 0x0100,
3734     JOB_OBJECT_LIMIT_JOB_MEMORY                 = 0x0200,
3735     JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION = 0x0400,
3736     JOB_OBJECT_BREAKAWAY_OK                     = 0x0800,
3737     JOB_OBJECT_SILENT_BREAKAWAY                 = 0x1000;
3738 
3739 // JOBOBJECT_BASIC_UI_RESTRICTIONS.UIRestrictionsClass constants
3740 enum DWORD
3741     JOB_OBJECT_UILIMIT_HANDLES          = 0x0001,
3742     JOB_OBJECT_UILIMIT_READCLIPBOARD    = 0x0002,
3743     JOB_OBJECT_UILIMIT_WRITECLIPBOARD   = 0x0004,
3744     JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS = 0x0008,
3745     JOB_OBJECT_UILIMIT_DISPLAYSETTINGS  = 0x0010,
3746     JOB_OBJECT_UILIMIT_GLOBALATOMS      = 0x0020,
3747     JOB_OBJECT_UILIMIT_DESKTOP          = 0x0040,
3748     JOB_OBJECT_UILIMIT_EXITWINDOWS      = 0x0080;
3749 
3750 // JOBOBJECT_SECURITY_LIMIT_INFORMATION.SecurityLimitFlags constants
3751 enum DWORD
3752     JOB_OBJECT_SECURITY_NO_ADMIN         = 0x0001,
3753     JOB_OBJECT_SECURITY_RESTRICTED_TOKEN = 0x0002,
3754     JOB_OBJECT_SECURITY_ONLY_TOKEN       = 0x0004,
3755     JOB_OBJECT_SECURITY_FILTER_TOKENS    = 0x0008;
3756 
3757 // JOBOBJECT_END_OF_JOB_TIME_INFORMATION.EndOfJobTimeAction constants
3758 enum : DWORD {
3759     JOB_OBJECT_TERMINATE_AT_END_OF_JOB,
3760     JOB_OBJECT_POST_AT_END_OF_JOB
3761 }
3762 
3763 enum : DWORD {
3764     JOB_OBJECT_MSG_END_OF_JOB_TIME = 1,
3765     JOB_OBJECT_MSG_END_OF_PROCESS_TIME,
3766     JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT,
3767     JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO,
3768     JOB_OBJECT_MSG_NEW_PROCESS,
3769     JOB_OBJECT_MSG_EXIT_PROCESS,
3770     JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS,
3771     JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT,
3772     JOB_OBJECT_MSG_JOB_MEMORY_LIMIT
3773 }
3774 
3775 enum JOBOBJECTINFOCLASS {
3776     JobObjectBasicAccountingInformation = 1,
3777     JobObjectBasicLimitInformation,
3778     JobObjectBasicProcessIdList,
3779     JobObjectBasicUIRestrictions,
3780     JobObjectSecurityLimitInformation,
3781     JobObjectEndOfJobTimeInformation,
3782     JobObjectAssociateCompletionPortInformation,
3783     JobObjectBasicAndIoAccountingInformation,
3784     JobObjectExtendedLimitInformation,
3785     JobObjectJobSetInformation,
3786     MaxJobObjectInfoClass
3787 }
3788 
3789 struct JOBOBJECT_BASIC_ACCOUNTING_INFORMATION {
3790     LARGE_INTEGER TotalUserTime;
3791     LARGE_INTEGER TotalKernelTime;
3792     LARGE_INTEGER ThisPeriodTotalUserTime;
3793     LARGE_INTEGER ThisPeriodTotalKernelTime;
3794     DWORD         TotalPageFaultCount;
3795     DWORD         TotalProcesses;
3796     DWORD         ActiveProcesses;
3797     DWORD         TotalTerminatedProcesses;
3798 }
3799 alias JOBOBJECT_BASIC_ACCOUNTING_INFORMATION* PJOBOBJECT_BASIC_ACCOUNTING_INFORMATION;
3800 
3801 struct JOBOBJECT_BASIC_LIMIT_INFORMATION {
3802     LARGE_INTEGER PerProcessUserTimeLimit;
3803     LARGE_INTEGER PerJobUserTimeLimit;
3804     DWORD         LimitFlags;
3805     SIZE_T        MinimumWorkingSetSize;
3806     SIZE_T        MaximumWorkingSetSize;
3807     DWORD         ActiveProcessLimit;
3808     ULONG_PTR     Affinity;
3809     DWORD         PriorityClass;
3810     DWORD         SchedulingClass;
3811 }
3812 alias JOBOBJECT_BASIC_LIMIT_INFORMATION* PJOBOBJECT_BASIC_LIMIT_INFORMATION;
3813 
3814 struct JOBOBJECT_BASIC_PROCESS_ID_LIST {
3815     DWORD     NumberOfAssignedProcesses;
3816     DWORD     NumberOfProcessIdsInList;
3817     ULONG_PTR _ProcessIdList;
3818 
3819     ULONG_PTR* ProcessIdList() return { return &_ProcessIdList; }
3820 }
3821 alias JOBOBJECT_BASIC_PROCESS_ID_LIST* PJOBOBJECT_BASIC_PROCESS_ID_LIST;
3822 
3823 struct JOBOBJECT_BASIC_UI_RESTRICTIONS {
3824     DWORD UIRestrictionsClass;
3825 }
3826 alias JOBOBJECT_BASIC_UI_RESTRICTIONS* PJOBOBJECT_BASIC_UI_RESTRICTIONS;
3827 
3828 struct JOBOBJECT_SECURITY_LIMIT_INFORMATION {
3829     DWORD             SecurityLimitFlags;
3830     HANDLE            JobToken;
3831     PTOKEN_GROUPS     SidsToDisable;
3832     PTOKEN_PRIVILEGES PrivilegesToDelete;
3833     PTOKEN_GROUPS     RestrictedSids;
3834 }
3835 alias JOBOBJECT_SECURITY_LIMIT_INFORMATION* PJOBOBJECT_SECURITY_LIMIT_INFORMATION;
3836 
3837 struct JOBOBJECT_END_OF_JOB_TIME_INFORMATION {
3838     DWORD EndOfJobTimeAction;
3839 }
3840 alias JOBOBJECT_END_OF_JOB_TIME_INFORMATION* PJOBOBJECT_END_OF_JOB_TIME_INFORMATION;
3841 
3842 struct JOBOBJECT_ASSOCIATE_COMPLETION_PORT {
3843     PVOID  CompletionKey;
3844     HANDLE CompletionPort;
3845 }
3846 alias JOBOBJECT_ASSOCIATE_COMPLETION_PORT* PJOBOBJECT_ASSOCIATE_COMPLETION_PORT;
3847 
3848 struct JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION {
3849     JOBOBJECT_BASIC_ACCOUNTING_INFORMATION BasicInfo;
3850     IO_COUNTERS IoInfo;
3851 }
3852 alias JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION *PJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION;
3853 
3854 struct JOBOBJECT_EXTENDED_LIMIT_INFORMATION {
3855     JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation;
3856     IO_COUNTERS IoInfo;
3857     SIZE_T      ProcessMemoryLimit;
3858     SIZE_T      JobMemoryLimit;
3859     SIZE_T      PeakProcessMemoryUsed;
3860     SIZE_T      PeakJobMemoryUsed;
3861 }
3862 alias JOBOBJECT_EXTENDED_LIMIT_INFORMATION* PJOBOBJECT_EXTENDED_LIMIT_INFORMATION;
3863 
3864 struct JOBOBJECT_JOBSET_INFORMATION {
3865     DWORD MemberLevel;
3866 }
3867 alias JOBOBJECT_JOBSET_INFORMATION* PJOBOBJECT_JOBSET_INFORMATION;
3868 
3869 // MinGW: Making these defines conditional on _WIN32_WINNT will break ddk includes
3870 //static if (_WIN32_WINNT >= 0x500) {
3871 
3872 enum DWORD
3873     ES_SYSTEM_REQUIRED  = 0x00000001,
3874     ES_DISPLAY_REQUIRED = 0x00000002,
3875     ES_USER_PRESENT     = 0x00000004,
3876     ES_AWAYMODE_REQUIRED = 0x00000040,
3877     ES_CONTINUOUS       = 0x80000000;
3878 
3879 enum LATENCY_TIME {
3880     LT_DONT_CARE,
3881     LT_LOWEST_LATENCY
3882 }
3883 alias LATENCY_TIME* PLATENCY_TIME;
3884 
3885 enum SYSTEM_POWER_STATE {
3886     PowerSystemUnspecified,
3887     PowerSystemWorking,
3888     PowerSystemSleeping1,
3889     PowerSystemSleeping2,
3890     PowerSystemSleeping3,
3891     PowerSystemHibernate,
3892     PowerSystemShutdown,
3893     PowerSystemMaximum
3894 }
3895 alias SYSTEM_POWER_STATE* PSYSTEM_POWER_STATE;
3896 
3897 enum POWER_SYSTEM_MAXIMUM = SYSTEM_POWER_STATE.PowerSystemMaximum;
3898 
3899 enum POWER_ACTION {
3900     PowerActionNone,
3901     PowerActionReserved,
3902     PowerActionSleep,
3903     PowerActionHibernate,
3904     PowerActionShutdown,
3905     PowerActionShutdownReset,
3906     PowerActionShutdownOff,
3907     PowerActionWarmEject
3908 }
3909 alias POWER_ACTION* PPOWER_ACTION;
3910 
3911 static if (_WIN32_WINNT >= 0x600) {
3912     enum SYSTEM_POWER_CONDITION {
3913         PoAc,
3914         PoDc,
3915         PoHot,
3916         PoConditionMaximum
3917     }
3918     alias SYSTEM_POWER_CONDITION* PSYSTEM_POWER_CONDITION;
3919 }
3920 
3921 enum DEVICE_POWER_STATE {
3922     PowerDeviceUnspecified,
3923     PowerDeviceD0,
3924     PowerDeviceD1,
3925     PowerDeviceD2,
3926     PowerDeviceD3,
3927     PowerDeviceMaximum
3928 }
3929 alias DEVICE_POWER_STATE* PDEVICE_POWER_STATE;
3930 
3931 align(4):
3932 struct BATTERY_REPORTING_SCALE {
3933     DWORD Granularity;
3934     DWORD Capacity;
3935 }
3936 alias BATTERY_REPORTING_SCALE* PBATTERY_REPORTING_SCALE;
3937 
3938 struct POWER_ACTION_POLICY {
3939     POWER_ACTION Action;
3940     ULONG        Flags;
3941     ULONG        EventCode;
3942 }
3943 alias POWER_ACTION_POLICY* PPOWER_ACTION_POLICY;
3944 
3945 // POWER_ACTION_POLICY.Flags constants
3946 enum ULONG
3947     POWER_ACTION_QUERY_ALLOWED  = 0x00000001,
3948     POWER_ACTION_UI_ALLOWED     = 0x00000002,
3949     POWER_ACTION_OVERRIDE_APPS  = 0x00000004,
3950     POWER_ACTION_LIGHTEST_FIRST = 0x10000000,
3951     POWER_ACTION_LOCK_CONSOLE   = 0x20000000,
3952     POWER_ACTION_DISABLE_WAKES  = 0x40000000,
3953     POWER_ACTION_CRITICAL       = 0x80000000;
3954 
3955 // POWER_ACTION_POLICY.EventCode constants
3956 enum ULONG
3957     POWER_LEVEL_USER_NOTIFY_TEXT  = 0x00000001,
3958     POWER_LEVEL_USER_NOTIFY_SOUND = 0x00000002,
3959     POWER_LEVEL_USER_NOTIFY_EXEC  = 0x00000004,
3960     POWER_USER_NOTIFY_BUTTON      = 0x00000008,
3961     POWER_USER_NOTIFY_SHUTDOWN    = 0x00000010,
3962     POWER_FORCE_TRIGGER_RESET     = 0x80000000;
3963 
3964 enum size_t
3965     DISCHARGE_POLICY_CRITICAL = 0,
3966     DISCHARGE_POLICY_LOW      = 1,
3967     NUM_DISCHARGE_POLICIES    = 4;
3968 
3969 enum : BYTE {
3970     PO_THROTTLE_NONE,
3971     PO_THROTTLE_CONSTANT,
3972     PO_THROTTLE_DEGRADE,
3973     PO_THROTTLE_ADAPTIVE,
3974     PO_THROTTLE_MAXIMUM
3975 }
3976 
3977 struct SYSTEM_POWER_LEVEL {
3978     BOOLEAN             Enable;
3979     UCHAR[3]            Spare;
3980     ULONG               BatteryLevel;
3981     POWER_ACTION_POLICY PowerPolicy;
3982     SYSTEM_POWER_STATE  MinSystemState;
3983 }
3984 alias SYSTEM_POWER_LEVEL* PSYSTEM_POWER_LEVEL;
3985 
3986 struct SYSTEM_POWER_POLICY {
3987     ULONG               Revision;
3988     POWER_ACTION_POLICY PowerButton;
3989     POWER_ACTION_POLICY SleepButton;
3990     POWER_ACTION_POLICY LidClose;
3991     SYSTEM_POWER_STATE  LidOpenWake;
3992     ULONG               Reserved;
3993     POWER_ACTION_POLICY Idle;
3994     ULONG               IdleTimeout;
3995     UCHAR               IdleSensitivity;
3996     UCHAR               DynamicThrottle;
3997     UCHAR[2]            Spare2;
3998     SYSTEM_POWER_STATE  MinSleep;
3999     SYSTEM_POWER_STATE  MaxSleep;
4000     SYSTEM_POWER_STATE  ReducedLatencySleep;
4001     ULONG               WinLogonFlags;
4002     ULONG               Spare3;
4003     ULONG               DozeS4Timeout;
4004     ULONG               BroadcastCapacityResolution;
4005     SYSTEM_POWER_LEVEL[NUM_DISCHARGE_POLICIES] DischargePolicy;
4006     ULONG               VideoTimeout;
4007     BOOLEAN             VideoDimDisplay;
4008     ULONG[3]            VideoReserved;
4009     ULONG               SpindownTimeout;
4010     BOOLEAN             OptimizeForPower;
4011     UCHAR               FanThrottleTolerance;
4012     UCHAR               ForcedThrottle;
4013     UCHAR               MinThrottle;
4014     POWER_ACTION_POLICY OverThrottled;
4015 }
4016 alias SYSTEM_POWER_POLICY* PSYSTEM_POWER_POLICY;
4017 
4018 struct SYSTEM_POWER_CAPABILITIES {
4019     BOOLEAN                    PowerButtonPresent;
4020     BOOLEAN                    SleepButtonPresent;
4021     BOOLEAN                    LidPresent;
4022     BOOLEAN                    SystemS1;
4023     BOOLEAN                    SystemS2;
4024     BOOLEAN                    SystemS3;
4025     BOOLEAN                    SystemS4;
4026     BOOLEAN                    SystemS5;
4027     BOOLEAN                    HiberFilePresent;
4028     BOOLEAN                    FullWake;
4029     BOOLEAN                    VideoDimPresent;
4030     BOOLEAN                    ApmPresent;
4031     BOOLEAN                    UpsPresent;
4032     BOOLEAN                    ThermalControl;
4033     BOOLEAN                    ProcessorThrottle;
4034     UCHAR                      ProcessorMinThrottle;
4035     UCHAR                      ProcessorMaxThrottle;
4036     UCHAR[4]                   spare2;
4037     BOOLEAN                    DiskSpinDown;
4038     UCHAR[8]                   spare3;
4039     BOOLEAN                    SystemBatteriesPresent;
4040     BOOLEAN                    BatteriesAreShortTerm;
4041     BATTERY_REPORTING_SCALE[3] BatteryScale;
4042     SYSTEM_POWER_STATE         AcOnLineWake;
4043     SYSTEM_POWER_STATE         SoftLidWake;
4044     SYSTEM_POWER_STATE         RtcWake;
4045     SYSTEM_POWER_STATE         MinDeviceWakeState;
4046     SYSTEM_POWER_STATE         DefaultLowLatencyWake;
4047 }
4048 alias SYSTEM_POWER_CAPABILITIES* PSYSTEM_POWER_CAPABILITIES;
4049 
4050 struct SYSTEM_BATTERY_STATE {
4051     BOOLEAN    AcOnLine;
4052     BOOLEAN    BatteryPresent;
4053     BOOLEAN    Charging;
4054     BOOLEAN    Discharging;
4055     BOOLEAN[4] Spare1;
4056     ULONG      MaxCapacity;
4057     ULONG      RemainingCapacity;
4058     ULONG      Rate;
4059     ULONG      EstimatedTime;
4060     ULONG      DefaultAlert1;
4061     ULONG      DefaultAlert2;
4062 }
4063 alias SYSTEM_BATTERY_STATE* PSYSTEM_BATTERY_STATE;
4064 
4065 enum POWER_INFORMATION_LEVEL {
4066     SystemPowerPolicyAc,
4067     SystemPowerPolicyDc,
4068     VerifySystemPolicyAc,
4069     VerifySystemPolicyDc,
4070     SystemPowerCapabilities,
4071     SystemBatteryState,
4072     SystemPowerStateHandler,
4073     ProcessorStateHandler,
4074     SystemPowerPolicyCurrent,
4075     AdministratorPowerPolicy,
4076     SystemReserveHiberFile,
4077     ProcessorInformation,
4078     SystemPowerInformation,
4079     ProcessorStateHandler2,
4080     LastWakeTime,
4081     LastSleepTime,
4082     SystemExecutionState,
4083     SystemPowerStateNotifyHandler,
4084     ProcessorPowerPolicyAc,
4085     ProcessorPowerPolicyDc,
4086     VerifyProcessorPowerPolicyAc,
4087     VerifyProcessorPowerPolicyDc,
4088     ProcessorPowerPolicyCurrent
4089 }
4090 
4091 //#if 1 /* (WIN32_WINNT >= 0x0500) */
4092 struct SYSTEM_POWER_INFORMATION {
4093     ULONG MaxIdlenessAllowed;
4094     ULONG Idleness;
4095     ULONG TimeRemaining;
4096     UCHAR CoolingMode;
4097 }
4098 alias SYSTEM_POWER_INFORMATION* PSYSTEM_POWER_INFORMATION;
4099 //#endif
4100 
4101 struct PROCESSOR_POWER_POLICY_INFO {
4102     ULONG    TimeCheck;
4103     ULONG    DemoteLimit;
4104     ULONG    PromoteLimit;
4105     UCHAR    DemotePercent;
4106     UCHAR    PromotePercent;
4107     UCHAR[2] Spare;
4108     uint     _bf;
4109 
4110     bool AllowDemotion()  { return cast(bool)(_bf & 1); }
4111     bool AllowPromotion() { return cast(bool)(_bf & 2); }
4112 
4113     bool AllowDemotion(bool a)  { _bf = (_bf & ~1) | a; return a; }
4114     bool AllowPromotion(bool a) { _bf = (_bf & ~2) | (a << 1); return a; }
4115 /+
4116     ULONG  AllowDemotion : 1;
4117     ULONG  AllowPromotion : 1;
4118     ULONG  Reserved : 30;
4119 +/
4120 }
4121 alias PROCESSOR_POWER_POLICY_INFO* PPROCESSOR_POWER_POLICY_INFO;
4122 
4123 struct PROCESSOR_POWER_POLICY {
4124     ULONG    Revision;
4125     UCHAR    DynamicThrottle;
4126     UCHAR[3] Spare;
4127     ULONG    Reserved;
4128     ULONG    PolicyCount;
4129     PROCESSOR_POWER_POLICY_INFO[3] Policy;
4130 }
4131 alias PROCESSOR_POWER_POLICY* PPROCESSOR_POWER_POLICY;
4132 
4133 struct ADMINISTRATOR_POWER_POLICY {
4134     SYSTEM_POWER_STATE MinSleep;
4135     SYSTEM_POWER_STATE MaxSleep;
4136     ULONG              MinVideoTimeout;
4137     ULONG              MaxVideoTimeout;
4138     ULONG              MinSpindownTimeout;
4139     ULONG              MaxSpindownTimeout;
4140 }
4141 alias ADMINISTRATOR_POWER_POLICY* PADMINISTRATOR_POWER_POLICY;
4142 
4143 //}//#endif /* _WIN32_WINNT >= 0x500 */
4144 
4145 extern (Windows) {
4146     alias void function(PVOID, DWORD, PVOID) PIMAGE_TLS_CALLBACK;
4147 
4148     static if (_WIN32_WINNT >= 0x500) {
4149         alias LONG function(PEXCEPTION_POINTERS) PVECTORED_EXCEPTION_HANDLER;
4150         alias void function(PVOID, BOOLEAN) WAITORTIMERCALLBACKFUNC;
4151     }
4152 }
4153 
4154 static if (_WIN32_WINNT >= 0x501) {
4155     enum HEAP_INFORMATION_CLASS {
4156         HeapCompatibilityInformation
4157     }
4158 
4159     enum ACTIVATION_CONTEXT_INFO_CLASS {
4160         ActivationContextBasicInformation = 1,
4161         ActivationContextDetailedInformation,
4162         AssemblyDetailedInformationInActivationContext,
4163         FileInformationInAssemblyOfAssemblyInActivationContext
4164     }
4165 
4166     align struct ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION {
4167         DWORD         ulFlags;
4168         DWORD         ulEncodedAssemblyIdentityLength;
4169         DWORD         ulManifestPathType;
4170         DWORD         ulManifestPathLength;
4171         LARGE_INTEGER liManifestLastWriteTime;
4172         DWORD         ulPolicyPathType;
4173         DWORD         ulPolicyPathLength;
4174         LARGE_INTEGER liPolicyLastWriteTime;
4175         DWORD         ulMetadataSatelliteRosterIndex;
4176         DWORD         ulManifestVersionMajor;
4177         DWORD         ulManifestVersionMinor;
4178         DWORD         ulPolicyVersionMajor;
4179         DWORD         ulPolicyVersionMinor;
4180         DWORD         ulAssemblyDirectoryNameLength;
4181         PCWSTR        lpAssemblyEncodedAssemblyIdentity;
4182         PCWSTR        lpAssemblyManifestPath;
4183         PCWSTR        lpAssemblyPolicyPath;
4184         PCWSTR        lpAssemblyDirectoryName;
4185     }
4186     alias ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION*
4187       PACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION;
4188     alias const(ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION)*
4189       PCACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION;
4190 
4191     struct ACTIVATION_CONTEXT_DETAILED_INFORMATION {
4192         DWORD  dwFlags;
4193         DWORD  ulFormatVersion;
4194         DWORD  ulAssemblyCount;
4195         DWORD  ulRootManifestPathType;
4196         DWORD  ulRootManifestPathChars;
4197         DWORD  ulRootConfigurationPathType;
4198         DWORD  ulRootConfigurationPathChars;
4199         DWORD  ulAppDirPathType;
4200         DWORD  ulAppDirPathChars;
4201         PCWSTR lpRootManifestPath;
4202         PCWSTR lpRootConfigurationPath;
4203         PCWSTR lpAppDirPath;
4204     }
4205     alias ACTIVATION_CONTEXT_DETAILED_INFORMATION*
4206       PACTIVATION_CONTEXT_DETAILED_INFORMATION;
4207     alias const(ACTIVATION_CONTEXT_DETAILED_INFORMATION)*
4208       PCACTIVATION_CONTEXT_DETAILED_INFORMATION;
4209 
4210     struct ACTIVATION_CONTEXT_QUERY_INDEX {
4211         ULONG ulAssemblyIndex;
4212         ULONG ulFileIndexInAssembly;
4213     }
4214     alias ACTIVATION_CONTEXT_QUERY_INDEX*        PACTIVATION_CONTEXT_QUERY_INDEX;
4215     alias const(ACTIVATION_CONTEXT_QUERY_INDEX)* PCACTIVATION_CONTEXT_QUERY_INDEX;
4216 
4217     struct ASSEMBLY_FILE_DETAILED_INFORMATION {
4218         DWORD  ulFlags;
4219         DWORD  ulFilenameLength;
4220         DWORD  ulPathLength;
4221         PCWSTR lpFileName;
4222         PCWSTR lpFilePath;
4223     }
4224     alias ASSEMBLY_FILE_DETAILED_INFORMATION*
4225       PASSEMBLY_FILE_DETAILED_INFORMATION;
4226     alias const(ASSEMBLY_FILE_DETAILED_INFORMATION)*
4227       PCASSEMBLY_FILE_DETAILED_INFORMATION;
4228 }
4229 
4230 version (Unicode) {
4231     alias OSVERSIONINFOW OSVERSIONINFO;
4232     alias OSVERSIONINFOEXW OSVERSIONINFOEX;
4233 } else {
4234     alias OSVERSIONINFOA OSVERSIONINFO;
4235     alias OSVERSIONINFOEXA OSVERSIONINFOEX;
4236 }
4237 
4238 alias OSVERSIONINFO*   POSVERSIONINFO,   LPOSVERSIONINFO;
4239 alias OSVERSIONINFOEX* POSVERSIONINFOEX, LPOSVERSIONINFOEX;
4240 
4241 
4242 static if (_WIN32_WINNT >= 0x500) {
4243     extern (Windows) ULONGLONG VerSetConditionMask(ULONGLONG, DWORD, BYTE);
4244 }
4245 
4246 version (Win64) {
4247 enum WORD IMAGE_NT_OPTIONAL_HDR_MAGIC = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4248 
4249     alias IMAGE_ORDINAL_FLAG64 IMAGE_ORDINAL_FLAG;
4250     alias IMAGE_SNAP_BY_ORDINAL64 IMAGE_SNAP_BY_ORDINAL;
4251     alias IMAGE_ORDINAL64 IMAGE_ORDINAL;
4252     alias IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER;
4253     alias IMAGE_NT_HEADERS64 IMAGE_NT_HEADERS;
4254     alias IMAGE_THUNK_DATA64 IMAGE_THUNK_DATA;
4255     alias IMAGE_TLS_DIRECTORY64 IMAGE_TLS_DIRECTORY;
4256 } else {
4257 enum WORD IMAGE_NT_OPTIONAL_HDR_MAGIC = IMAGE_NT_OPTIONAL_HDR32_MAGIC;
4258 
4259     alias IMAGE_ORDINAL_FLAG32 IMAGE_ORDINAL_FLAG;
4260     alias IMAGE_ORDINAL32 IMAGE_ORDINAL;
4261     alias IMAGE_SNAP_BY_ORDINAL32 IMAGE_SNAP_BY_ORDINAL;
4262     alias IMAGE_OPTIONAL_HEADER32 IMAGE_OPTIONAL_HEADER;
4263     alias IMAGE_NT_HEADERS32 IMAGE_NT_HEADERS;
4264     alias IMAGE_THUNK_DATA32 IMAGE_THUNK_DATA;
4265     alias IMAGE_TLS_DIRECTORY32 IMAGE_TLS_DIRECTORY;
4266 }
4267 
4268 alias IMAGE_OPTIONAL_HEADER* PIMAGE_OPTIONAL_HEADER;
4269 alias IMAGE_NT_HEADERS* PIMAGE_NT_HEADERS;
4270 alias IMAGE_THUNK_DATA* PIMAGE_THUNK_DATA;
4271 alias IMAGE_TLS_DIRECTORY* PIMAGE_TLS_DIRECTORY;
4272 
4273 // TODO: MinGW implements these in assembly.  How to translate?
4274 PVOID GetCurrentFiber();
4275 PVOID GetFiberData();