' winnt.ab

'#include <ctype.h>
Const ANYSIZE_ARRAY = 1

'#include <specstrings.h>

'RESTRICTED_POINTER

'UNALIGNED
'UNALIGNED64

#ifdef _WIN64
Const MAX_NATURAL_ALIGNMENT = SizeOf (QWord)
Const MEMORY_ALLOCATION_ALIGNMENT = 16
#else
Const MAX_NATURAL_ALIGNMENT = SizeOf (DWord)
Const MEMORY_ALLOCATION_ALIGNMENT = 8
#endif

'TYPE_ALIGNMENT
'PROBE_ALIGNMENT
'PROBE_ALIGNMENT32

'Const C_ASSERT(e) = 0

'#require <basetsd.ab>
#ifdef _WIN64
TypeDef LONG_PTR =  Int64
TypeDef ULONG_PTR = QWord
TypeDef HALF_PTR = Long
TypeDef UHALF_PTR = DWord
#else
TypeDef LONG_PTR = Long
TypeDef ULONG_PTR = DWord
TypeDef HALF_PTR = Integer
TypeDef UHALF_PTR = Word
#endif
TypeDef DWORD_PTR = ULONG_PTR

TypeDef SIZE_T = ULONG_PTR
TypeDef SSIZE_T = LONG_PTR

Const SYSTEM_CACHE_ALIGNMENT_SIZE = 64

Const DECLSPEC_CACHEALIGN = 4
/*
#ifdef DEPRECATE_DDK_FUNCTIONS
#ifdef _NTDDK_
#define DECLSPEC_DEPRECATED_DDK DECLSPEC_DEPRECATED
#ifdef DEPRECATE_SUPPORTED
#define PRAGMA_DEPRECATED_DDK 1
#endif
#else
#define DECLSPEC_DEPRECATED_DDK
#define PRAGMA_DEPRECATED_DDK 1
#endif
#else
#define DECLSPEC_DEPRECATED_DDK
#define PRAGMA_DEPRECATED_DDK 0
#endif
*/

TypeDef PVOID = VoidPtr
#ifdef _WIN64
TypeDef PVOID64 = VoidPtr
#else
TypeDef PVOID64 = QWord
#endif

TypeDef CHAR = SByte
TypeDef SHORT = Integer
TypeDef LONG = Long
TypeDef INT = Long

TypeDef WCHAR = Word

TypeDef PWCHAR = *WCHAR
TypeDef LPWCH = *WCHAR
TypeDef PWCH = *WCHAR
TypeDef LPCWCH = *WCHAR
TypeDef NWPSTR = *WCHAR
TypeDef LPWSTR = *WCHAR
TypeDef PWSTR = *WCHAR
TypeDef PZPWSTR = *PWSTR
TypeDef PCZPWSTR = *PWSTR
TypeDef LPUWSTR = *WCHAR
TypeDef PUWSTR = *WCHAR
TypeDef LPCWSTR = *WCHAR
TypeDef PCWSTR = *WCHAR
TypeDef PZPCWSTR = *PCWSTR
TypeDef LPCUWSTR = *WCHAR
TypeDef PCUWSTR = *WCHAR

TypeDef LPCWCHAR = *WCHAR
TypeDef PCWCHAR = *WCHAR
TypeDef LPCUWCHAR = *WCHAR
TypeDef PCUWCHAR = *WCHAR

TypeDef UCSCHAR = DWord

Const UCSCHAR_INVALID_CHARACTER = &hffffffff As UCSCHAR
Const MIN_UCSCHAR = 0 As UCSCHAR
Const MAX_UCSCHAR = &h0010ffff As UCSCHAR

TypeDef PUCSCHAR = *UCSCHAR
TypeDef PCUCSCHAR = *UCSCHAR

TypeDef PUCSSTR = *UCSCHAR
TypeDef PUUCSSTR = *UCSCHAR

TypeDef PCUCSSTR = *UCSCHAR
TypeDef PCUUCSSTR = *UCSCHAR

TypeDef PUUCSCHAR = *UCSCHAR
TypeDef PCUUCSCHAR = *UCSCHAR

TypeDef PCHAR = *CHAR
TypeDef LPCH = *CHAR
TypeDef PCH = *CHAR
TypeDef LPCCH = *CHAR
TypeDef PCCH = *CHAR

TypeDef NPSTR = *CHAR
TypeDef LPSTR = *CHAR
TypeDef PSTR = *CHAR
TypeDef PZPSTR = *PSTR
TypeDef PCZPSTR = *PSTR
TypeDef PCSTR = *CHAR
TypeDef LPCSTR = *CHAR
TypeDef PZPCSTR = *PCSTR

#ifdef UNICODE
TypeDef TCHAR = WCHAR
TypeDef PTCHAR = *WCHAR
TypeDef TBYTE = WCHAR
TypeDef PTBYTE = *WCHAR

TypeDef PTCH = PWCH
TypeDef LPTCH = LPWCH
TypeDef PTSTR = PWSTR
TypeDef LPTSTR = LPWSTR
TypeDef PCTSTR = PCWSTR
TypeDef LPCTSTR = LPCWSTR
TypeDef PUTSTR = PUWSTR
TypeDef LPUTSTR = LPUWSTR
TypeDef PCUTSTR = PCUWSTR
TypeDef LPCUTSTR = LPCUWSTR
'TypeDef LP = LPWSTR
#else
TypeDef TCHAR = Char
TypeDef PTCHAR = *Char
TypeDef TBYTE = Byte
TypeDef PTBYTE = *Byte

TypeDef PTCH = PCH
TypeDef LPTCH = LPCH
TypeDef PTSTR = PSTR
TypeDef LPTSTR = LPSTR
TypeDef PUTSTR = PSTR
TypeDef LPUTSTR = LPSTR
TypeDef PCTSTR = PCSTR
TypeDef LPCTSTR = LPCSTR
TypeDef PCUTSTR = PCSTR
TypeDef LPCUTSTR = LPCSTR
#endif

'TypeDef PSHORT = SHORT
'TypeDef PLONG = *Long

TypeDef HANDLE = VoidPtr
TypeDef PHANDLE = *HANDLE

TypeDef FCHAR = Byte
TypeDef FSHORT = Word
TypeDef FLONG = DWord

TypeDef HRESULT = Long

TypeDef CCHAR = CHAR
TypeDef LCID = DWord
TypeDef PLCID = *DWord
TypeDef LANGID = Word
Const APPLICATION_ERROR_MASK = &h20000000
Const ERROR_SEVERITY_SUCCESS = &h00000000
Const ERROR_SEVERITY_INFORMATIONAL = &h40000000
Const ERROR_SEVERITY_WARNING = &h80000000
Const ERROR_SEVERITY_ERROR = &hC0000000

Type FLOAT128
	LowPart As Int64
	HighPart As Int64
End Type
TypeDef PFLOAT128 = FLOAT128

TypeDef LONGLONG = Int64
TypeDef ULONGLONG = QWord

Const MAXLONGLONG = (&h7fffffffffffffff)

TypeDef PLONGLONG = *LONGLONG
TypeDef PULONGLONG = *ULONGLONG

TypeDef USN = LONGLONG

Type LARGE_INTEGER
	LowPart As DWord
	HighPart As Long
End Type
TypeDef PLARGE_INTEGER = *LARGE_INTEGER

Type ULARGE_INTEGER
	LowPart As DWord
	HighPart As DWord
End Type
TypeDef PULARGE_INTEGER = *ULARGE_INTEGER

Type LUID
	LowPart As DWord
	HighPart As Long
End Type
TypeDef PLUID = *LUID

'TypeDef DWORDLONG = ULONGLONG
'TypeDef PDWORDLONG = DWORDLONG

Const Int32x32To64(a, b) = (((a) As Long) As Int64 * ((b) As Long) As Int64)
Const UInt32x32To64(a, b) = (((a) As DWord) As QWord * ((b) As DWord) As QWord)
Const Int64ShllMod32(a, b) = ((a) As QWord << (b))
Const Int64ShraMod32(a, b) = ((a) As Int64 >> (b))
Const Int64ShrlMod32(a, b) = ((a) As QWord >> (b))

Const ANSI_NULL = (0 As CHAR)
Const UNICODE_NULL = (0 As WCHAR)
Const UNICODE_STRING_MAX_BYTES = (65534 As Word)
Const UNICODE_STRING_MAX_CHARS = (32767)
TypeDef BOOLEAN = BYTE
TypeDef PBOOLEAN = *BOOLEAN

Type LIST_ENTRY
	Flink As *LIST_ENTRY
	Blink As *LIST_ENTRY
End Type
TypeDef PLIST_ENTRY = *LIST_ENTRY
TypeDef PRLIST_ENTRY = *LIST_ENTRY

Type SINGLE_LIST_ENTRY
	Next As *SINGLE_LIST_ENTRY
End Type
TypeDef PSINGLE_LIST_ENTRY = *SINGLE_LIST_ENTRY

Type LIST_ENTRY32
	Flink As DWord
	Blink As DWord
End Type
TypeDef PLIST_ENTRY32 = *LIST_ENTRY32

Type LIST_ENTRY64
	Flink As QWord
	Blink As QWord
End Type
TypeDef PLIST_ENTRY64 = *LIST_ENTRY64

#require <guiddef.ab>

Type OBJECTID
	Lineage As GUID
	Uniquifier As DWord
End Type

Const MINCHAR = &h80
Const MAXCHAR = &h7f
Const MINSHORT = &h8000
Const MAXSHORT = &h7fff
Const MINLONG = &h80000000
Const MAXLONG = &h7fffffff
Const MAXBYTE = &hff
Const MAXWORD = &hffff
Const MAXDWORD = &hffffffff

'FIELD_OFFSET
'RTL_FIELD_SIZE
'RTL_SIZEOF_THROUGH_FIELD
'RTL_CONTAINS_FIELD
Const RTL_NUMBER_OF_V1(A) = (Len (A) \ Len(A[0]))
'RtlpNumberOf
Const RTL_NUMBER_OF(A) = RTL_NUMBER_OF_V1(A)
Const ARRAYSIZE(A) = RTL_NUMBER_OF_V1(A) 'RTL_NUMBER_OF_V2(A)
Const _ARRAYSIZE(A) = RTL_NUMBER_OF_V1(A)
'RTL_FIELD_TYPE
'RTL_NUMBER_OF_FIELD
'RTL_PADDING_BETWEEN_FIELDS
'RTL_CONST_CAST
'RTL_BITS_OF
'RTL_BITS_OF_FIELD
'CONTAINING_RECORD

Const VER_SERVER_NT = &h80000000
Const VER_WORKSTATION_NT = &h40000000
Const VER_SUITE_SMALLBUSINESS = &h00000001
Const VER_SUITE_ENTERPRISE = &h00000002
Const VER_SUITE_BACKOFFICE = &h00000004
Const VER_SUITE_COMMUNICATIONS = &h00000008
Const VER_SUITE_TERMINAL = &h00000010
Const VER_SUITE_SMALLBUSINESS_RESTRICTED = &h00000020
Const VER_SUITE_EMBEDDEDNT = &h00000040
Const VER_SUITE_DATACENTER = &h00000080
Const VER_SUITE_SINGLEUSERTS = &h00000100
Const VER_SUITE_PERSONAL = &h00000200
Const VER_SUITE_BLADE = &h00000400
Const VER_SUITE_EMBEDDED_RESTRICTED = &h00000800
Const VER_SUITE_SECURITY_APPLIANCE = &h00001000
Const VER_SUITE_STORAGE_SERVER = &h00002000
Const VER_SUITE_COMPUTE_SERVER = &h00004000

Const PRODUCT_UNDEFINED = &h00000000

Const PRODUCT_ULTIMATE = &h00000001
Const PRODUCT_HOME_BASIC = &h00000002
Const PRODUCT_HOME_PREMIUM = &h00000003
Const PRODUCT_ENTERPRISE = &h00000004
Const PRODUCT_HOME_BASIC_N = &h00000005
Const PRODUCT_BUSINESS = &h00000006
Const PRODUCT_STANDARD_SERVER = &h00000007
Const PRODUCT_DATACENTER_SERVER = &h00000008
Const PRODUCT_SMALLBUSINESS_SERVER = &h00000009
Const PRODUCT_ENTERPRISE_SERVER = &h0000000A
Const PRODUCT_STARTER = &h0000000B
Const PRODUCT_DATACENTER_SERVER_CORE = &h0000000C
Const PRODUCT_STANDARD_SERVER_CORE = &h0000000D
Const PRODUCT_ENTERPRISE_SERVER_CORE = &h0000000E
Const PRODUCT_ENTERPRISE_SERVER_IA64 = &h0000000F
Const PRODUCT_BUSINESS_N = &h00000010
Const PRODUCT_WEB_SERVER = &h00000011
Const PRODUCT_CLUSTER_SERVER = &h00000012
Const PRODUCT_HOME_SERVER = &h00000013
Const PRODUCT_STORAGE_EXPRESS_SERVER = &h00000014
Const PRODUCT_STORAGE_STANDARD_SERVER = &h00000015
Const PRODUCT_STORAGE_WORKGROUP_SERVER = &h00000016
Const PRODUCT_STORAGE_ENTERPRISE_SERVER = &h00000017
Const PRODUCT_SERVER_FOR_SMALLBUSINESS = &h00000018
Const PRODUCT_SMALLBUSINESS_SERVER_PREMIUM = &h00000019

Const PRODUCT_UNLICENSED = &hABCDABCD

'#require <sdkddkver.ab>

'  Primary language IDs.
Const LANG_NEUTRAL = &h00
Const LANG_INVARIANT = &h7f

Const LANG_AFRIKAANS = &h36
Const LANG_ALBANIAN = &h1c
Const LANG_ALSATIAN = &h84
Const LANG_AMHARIC = &h5e
Const LANG_ARABIC = &h01
Const LANG_ARMENIAN = &h2b
Const LANG_ASSAMESE = &h4d
Const LANG_AZERI = &h2c
Const LANG_BASHKIR = &h6d
Const LANG_BASQUE = &h2d
Const LANG_BELARUSIAN = &h23
Const LANG_BENGALI = &h45
Const LANG_BRETON = &h7e
Const LANG_BOSNIAN = &h1a
Const LANG_BOSNIAN_NEUTRAL = &h781a
Const LANG_BULGARIAN = &h02
Const LANG_CATALAN = &h03
Const LANG_CHINESE = &h04
Const LANG_CHINESE_SIMPLIFIED = &h04
Const LANG_CHINESE_TRADITIONAL = &h7c04
Const LANG_CORSICAN = &h83
Const LANG_CROATIAN = &h1a
Const LANG_CZECH = &h05
Const LANG_DANISH = &h06
Const LANG_DARI = &h8c
Const LANG_DIVEHI = &h65
Const LANG_DUTCH = &h13
Const LANG_ENGLISH = &h09
Const LANG_ESTONIAN = &h25
Const LANG_FAEROESE = &h38
Const LANG_FARSI = &h29
Const LANG_FILIPINO = &h64
Const LANG_FINNISH = &h0b
Const LANG_FRENCH = &h0c
Const LANG_FRISIAN = &h62
Const LANG_GALICIAN = &h56
Const LANG_GEORGIAN = &h37
Const LANG_GERMAN = &h07
Const LANG_GREEK = &h08
Const LANG_GREENLANDIC = &h6f
Const LANG_GUJARATI = &h47
Const LANG_HAUSA = &h68
Const LANG_HEBREW = &h0d
Const LANG_HINDI = &h39
Const LANG_HUNGARIAN = &h0e
Const LANG_ICELANDIC = &h0f
Const LANG_IGBO = &h70
Const LANG_INDONESIAN = &h21
Const LANG_INUKTITUT = &h5d
Const LANG_IRISH = &h3c
Const LANG_ITALIAN = &h10
Const LANG_JAPANESE = &h11
Const LANG_KANNADA = &h4b
Const LANG_KASHMIRI = &h60
Const LANG_KAZAK = &h3f
Const LANG_KHMER = &h53
Const LANG_KICHE = &h86
Const LANG_KINYARWANDA = &h87
Const LANG_KONKANI = &h57
Const LANG_KOREAN = &h12
Const LANG_KYRGYZ = &h40
Const LANG_LAO = &h54
Const LANG_LATVIAN = &h26
Const LANG_LITHUANIAN = &h27
Const LANG_LOWER_SORBIAN = &h2e
Const LANG_LUXEMBOURGISH = &h6e
Const LANG_MACEDONIAN = &h2f
Const LANG_MALAY = &h3e
Const LANG_MALAYALAM = &h4c
Const LANG_MALTESE = &h3a
Const LANG_MANIPURI = &h58
Const LANG_MAORI = &h81
Const LANG_MAPUDUNGUN = &h7a
Const LANG_MARATHI = &h4e
Const LANG_MOHAWK = &h7c
Const LANG_MONGOLIAN = &h50
Const LANG_NEPALI = &h61
Const LANG_NORWEGIAN = &h14
Const LANG_OCCITAN = &h82
Const LANG_ORIYA = &h48
Const LANG_PASHTO = &h63
Const LANG_PERSIAN = &h29
Const LANG_POLISH = &h15
Const LANG_PORTUGUESE = &h16
Const LANG_PUNJABI = &h46
Const LANG_QUECHUA = &h6b
Const LANG_ROMANIAN = &h18
Const LANG_ROMANSH = &h17
Const LANG_RUSSIAN = &h19
Const LANG_SAMI = &h3b
Const LANG_SANSKRIT = &h4f
Const LANG_SERBIAN = &h1a
Const LANG_SERBIAN_NEUTRAL = &h7c1a
Const LANG_SINDHI = &h59
Const LANG_SINHALESE = &h5b
Const LANG_SLOVAK = &h1b
Const LANG_SLOVENIAN = &h24
Const LANG_SOTHO = &h6c
Const LANG_SPANISH = &h0a
Const LANG_SWAHILI = &h41
Const LANG_SWEDISH = &h1d
Const LANG_SYRIAC = &h5a
Const LANG_TAJIK = &h28
Const LANG_TAMAZIGHT = &h5f
Const LANG_TAMIL = &h49
Const LANG_TATAR = &h44
Const LANG_TELUGU = &h4a
Const LANG_THAI = &h1e
Const LANG_TIBETAN = &h51
Const LANG_TIGRIGNA = &h73
Const LANG_TSWANA = &h32
Const LANG_TURKISH = &h1f
Const LANG_TURKMEN = &h42
Const LANG_UIGHUR = &h80
Const LANG_UKRAINIAN = &h22
Const LANG_UPPER_SORBIAN = &h2e
Const LANG_URDU = &h20
Const LANG_UZBEK = &h43
Const LANG_VIETNAMESE = &h2a
Const LANG_WELSH = &h52
Const LANG_WOLOF = &h88
Const LANG_XHOSA = &h34
Const LANG_YAKUT = &h85
Const LANG_YI = &h78
Const LANG_YORUBA = &h6a
Const LANG_ZULU = &h35

' Sublanguage IDs.
Const SUBLANG_NEUTRAL = &h00
Const SUBLANG_DEFAULT = &h01
Const SUBLANG_SYS_DEFAULT = &h02
Const SUBLANG_CUSTOM_DEFAULT = &h03
Const SUBLANG_CUSTOM_UNSPECIFIED = &h04
Const SUBLANG_UI_CUSTOM_DEFAULT = &h05

Const SUBLANG_AFRIKAANS_SOUTH_AFRICA = &h01
Const SUBLANG_ALBANIAN_ALBANIA = &h01
Const SUBLANG_ALSATIAN_FRANCE = &h01
Const SUBLANG_AMHARIC_ETHIOPIA = &h01
Const SUBLANG_ARABIC_SAUDI_ARABIA = &h01
Const SUBLANG_ARABIC_IRAQ = &h02
Const SUBLANG_ARABIC_EGYPT = &h03
Const SUBLANG_ARABIC_LIBYA = &h04
Const SUBLANG_ARABIC_ALGERIA = &h05
Const SUBLANG_ARABIC_MOROCCO = &h06
Const SUBLANG_ARABIC_TUNISIA = &h07
Const SUBLANG_ARABIC_OMAN = &h08
Const SUBLANG_ARABIC_YEMEN = &h09
Const SUBLANG_ARABIC_SYRIA = &h0a
Const SUBLANG_ARABIC_JORDAN = &h0b
Const SUBLANG_ARABIC_LEBANON = &h0c
Const SUBLANG_ARABIC_KUWAIT = &h0d
Const SUBLANG_ARABIC_UAE = &h0e
Const SUBLANG_ARABIC_BAHRAIN = &h0f
Const SUBLANG_ARABIC_QATAR = &h10
Const SUBLANG_ARMENIAN_ARMENIA = &h01
Const SUBLANG_ASSAMESE_INDIA = &h01
Const SUBLANG_AZERI_LATIN = &h01
Const SUBLANG_AZERI_CYRILLIC = &h02
Const SUBLANG_BASHKIR_RUSSIA = &h01
Const SUBLANG_BASQUE_BASQUE = &h01
Const SUBLANG_BELARUSIAN_BELARUS = &h01
Const SUBLANG_BENGALI_INDIA = &h01
Const SUBLANG_BENGALI_BANGLADESH = &h02
Const SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN = &h05
Const SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC = &h08
Const SUBLANG_BRETON_FRANCE = &h01
Const SUBLANG_BULGARIAN_BULGARIA = &h01
Const SUBLANG_CATALAN_CATALAN = &h01
Const SUBLANG_CHINESE_TRADITIONAL = &h01
Const SUBLANG_CHINESE_SIMPLIFIED = &h02
Const SUBLANG_CHINESE_HONGKONG = &h03
Const SUBLANG_CHINESE_SINGAPORE = &h04
Const SUBLANG_CHINESE_MACAU = &h05
Const SUBLANG_CORSICAN_FRANCE = &h01
Const SUBLANG_CZECH_CZECH_REPUBLIC = &h01
Const SUBLANG_CROATIAN_CROATIA = &h01
Const SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN = &h04
Const SUBLANG_DANISH_DENMARK = &h01
Const SUBLANG_DARI_AFGHANISTAN = &h01
Const SUBLANG_DIVEHI_MALDIVES = &h01
Const SUBLANG_DUTCH = &h01
Const SUBLANG_DUTCH_BELGIAN = &h02
Const SUBLANG_ENGLISH_US = &h01
Const SUBLANG_ENGLISH_UK = &h02
Const SUBLANG_ENGLISH_AUS = &h03
Const SUBLANG_ENGLISH_CAN = &h04
Const SUBLANG_ENGLISH_NZ = &h05
Const SUBLANG_ENGLISH_EIRE = &h06
Const SUBLANG_ENGLISH_SOUTH_AFRICA = &h07
Const SUBLANG_ENGLISH_JAMAICA = &h08
Const SUBLANG_ENGLISH_CARIBBEAN = &h09
Const SUBLANG_ENGLISH_BELIZE = &h0a
Const SUBLANG_ENGLISH_TRINIDAD = &h0b
Const SUBLANG_ENGLISH_ZIMBABWE = &h0c
Const SUBLANG_ENGLISH_PHILIPPINES = &h0d
Const SUBLANG_ENGLISH_INDIA = &h10
Const SUBLANG_ENGLISH_MALAYSIA = &h11
Const SUBLANG_ENGLISH_SINGAPORE = &h12
Const SUBLANG_ESTONIAN_ESTONIA = &h01
Const SUBLANG_FAEROESE_FAROE_ISLANDS = &h01
Const SUBLANG_FILIPINO_PHILIPPINES = &h01
Const SUBLANG_FINNISH_FINLAND = &h01
Const SUBLANG_FRENCH = &h01
Const SUBLANG_FRENCH_BELGIAN = &h02
Const SUBLANG_FRENCH_CANADIAN = &h03
Const SUBLANG_FRENCH_SWISS = &h04
Const SUBLANG_FRENCH_LUXEMBOURG = &h05
Const SUBLANG_FRENCH_MONACO = &h06
Const SUBLANG_FRISIAN_NETHERLANDS = &h01
Const SUBLANG_GALICIAN_GALICIAN = &h01
Const SUBLANG_GEORGIAN_GEORGIA = &h01
Const SUBLANG_GERMAN = &h01
Const SUBLANG_GERMAN_SWISS = &h02
Const SUBLANG_GERMAN_AUSTRIAN = &h03
Const SUBLANG_GERMAN_LUXEMBOURG = &h04
Const SUBLANG_GERMAN_LIECHTENSTEIN = &h05
Const SUBLANG_GREEK_GREECE = &h01
Const SUBLANG_GREENLANDIC_GREENLAND = &h01
Const SUBLANG_GUJARATI_INDIA = &h01
Const SUBLANG_HAUSA_NIGERIA_LATIN = &h01
Const SUBLANG_HEBREW_ISRAEL = &h01
Const SUBLANG_HINDI_INDIA = &h01
Const SUBLANG_HUNGARIAN_HUNGARY = &h01
Const SUBLANG_ICELANDIC_ICELAND = &h01
Const SUBLANG_IGBO_NIGERIA = &h01
Const SUBLANG_INDONESIAN_INDONESIA = &h01
Const SUBLANG_INUKTITUT_CANADA = &h01
Const SUBLANG_INUKTITUT_CANADA_LATIN = &h02
Const SUBLANG_IRISH_IRELAND = &h02
Const SUBLANG_ITALIAN = &h01
Const SUBLANG_ITALIAN_SWISS = &h02
Const SUBLANG_JAPANESE_JAPAN = &h01
Const SUBLANG_KANNADA_INDIA = &h01
Const SUBLANG_KASHMIRI_SASIA = &h02
Const SUBLANG_KASHMIRI_INDIA = &h02
Const SUBLANG_KAZAK_KAZAKHSTAN = &h01
Const SUBLANG_KHMER_CAMBODIA = &h01
Const SUBLANG_KICHE_GUATEMALA = &h01
Const SUBLANG_KINYARWANDA_RWANDA = &h01
Const SUBLANG_KONKANI_INDIA = &h01
Const SUBLANG_KOREAN = &h01
Const SUBLANG_KYRGYZ_KYRGYZSTAN = &h01
Const SUBLANG_LAO_LAO = &h01
Const SUBLANG_LATVIAN_LATVIA = &h01
Const SUBLANG_LITHUANIAN = &h01
Const SUBLANG_LOWER_SORBIAN_GERM = &h02
Const SUBLANG_LUXEMBOURGISH_LUXEMBOURG = &h01
Const SUBLANG_MACEDONIAN_MACEDONIA = &h01
Const SUBLANG_MALAY_MALAYSIA = &h01
Const SUBLANG_MALAY_BRUNEI_DARUSSALAM = &h02
Const SUBLANG_MALAYALAM_INDIA = &h01
Const SUBLANG_MALTESE_MALTA = &h01
Const SUBLANG_MAORI_NEW_ZEALAND = &h01
Const SUBLANG_MAPUDUNGUN_CHILE = &h01
Const SUBLANG_MARATHI_INDIA = &h01
Const SUBLANG_MOHAWK_MOHAWK = &h01
Const SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA = &h01
Const SUBLANG_MONGOLIAN_PRC = &h02
Const SUBLANG_NEPALI_INDIA = &h02
Const SUBLANG_NEPALI_NEPAL = &h01
Const SUBLANG_NORWEGIAN_BOKMAL = &h01
Const SUBLANG_NORWEGIAN_NYNORSK = &h02
Const SUBLANG_OCCITAN_FRANCE = &h01
Const SUBLANG_ORIYA_INDIA = &h01
Const SUBLANG_PASHTO_AFGHANISTAN = &h01
Const SUBLANG_PERSIAN_IRAN = &h01
Const SUBLANG_POLISH_POLAND = &h01
Const SUBLANG_PORTUGUESE = &h02
Const SUBLANG_PORTUGUESE_BRAZILIAN = &h01
Const SUBLANG_PUNJABI_INDIA = &h01
Const SUBLANG_QUECHUA_BOLIVIA = &h01
Const SUBLANG_QUECHUA_ECUADOR = &h02
Const SUBLANG_QUECHUA_PERU = &h03
Const SUBLANG_ROMANIAN_ROMANIA = &h01
Const SUBLANG_ROMANSH_SWITZERLAND = &h01
Const SUBLANG_RUSSIAN_RUSSIA = &h01
Const SUBLANG_SAMI_NORTHERN_NORWAY = &h01
Const SUBLANG_SAMI_NORTHERN_SWEDEN = &h02
Const SUBLANG_SAMI_NORTHERN_FINLAND = &h03
Const SUBLANG_SAMI_LULE_NORWAY = &h04
Const SUBLANG_SAMI_LULE_SWEDEN = &h05
Const SUBLANG_SAMI_SOUTHERN_NORWAY = &h06
Const SUBLANG_SAMI_SOUTHERN_SWEDEN = &h07
Const SUBLANG_SAMI_SKOLT_FINLAND = &h08
Const SUBLANG_SAMI_INARI_FINLAND = &h09
Const SUBLANG_SANSKRIT_INDIA = &h01
Const SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_LATIN = &h06
Const SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_CYRILLIC = &h07
Const SUBLANG_SERBIAN_CROATIA = &h01
Const SUBLANG_SERBIAN_LATIN = &h02
Const SUBLANG_SERBIAN_CYRILLIC = &h03
Const SUBLANG_SINDHI_INDIA = &h01
Const SUBLANG_SINDHI_PAKISTAN = &h02
Const SUBLANG_SINDHI_AFGHANISTAN = &h02
Const SUBLANG_SINHALESE_SRI_LANKA = &h01
Const SUBLANG_SOTHO_NORTHERN_SOUTH_AFRICA = &h01
Const SUBLANG_SLOVAK_SLOVAKIA = &h01
Const SUBLANG_SLOVENIAN_SLOVENIA = &h01
Const SUBLANG_SPANISH = &h01
Const SUBLANG_SPANISH_MEXICAN = &h02
Const SUBLANG_SPANISH_MODERN = &h03
Const SUBLANG_SPANISH_GUATEMALA = &h04
Const SUBLANG_SPANISH_COSTA_RICA = &h05
Const SUBLANG_SPANISH_PANAMA = &h06
Const SUBLANG_SPANISH_DOMINICAN_REPUBLIC = &h07
Const SUBLANG_SPANISH_VENEZUELA = &h08
Const SUBLANG_SPANISH_COLOMBIA = &h09
Const SUBLANG_SPANISH_PERU = &h0a
Const SUBLANG_SPANISH_ARGENTINA = &h0b
Const SUBLANG_SPANISH_ECUADOR = &h0c
Const SUBLANG_SPANISH_CHILE = &h0d
Const SUBLANG_SPANISH_URUGUAY = &h0e
Const SUBLANG_SPANISH_PARAGUAY = &h0f
Const SUBLANG_SPANISH_BOLIVIA = &h10
Const SUBLANG_SPANISH_EL_SALVADOR = &h11
Const SUBLANG_SPANISH_HONDURAS = &h12
Const SUBLANG_SPANISH_NICARAGUA = &h13
Const SUBLANG_SPANISH_PUERTO_RICO = &h14
Const SUBLANG_SPANISH_US = &h15
Const SUBLANG_SWAHILI_KENYA = &h01
Const SUBLANG_SWEDISH = &h01
Const SUBLANG_SWEDISH_FINLAND = &h02
Const SUBLANG_SYRIAC_SYRIA = &h01
Const SUBLANG_TAJIK_TAJIKISTAN = &h01
Const SUBLANG_TAMAZIGHT_ALGERIA_LATIN = &h02
Const SUBLANG_TAMIL_INDIA = &h01
Const SUBLANG_TATAR_RUSSIA = &h01
Const SUBLANG_TELUGU_INDIA = &h01
Const SUBLANG_THAI_THAILAND = &h01
Const SUBLANG_TIBETAN_PRC = &h01
Const SUBLANG_TIGRIGNA_ERITREA = &h02
Const SUBLANG_TSWANA_SOUTH_AFRICA = &h01
Const SUBLANG_TURKISH_TURKEY = &h01
Const SUBLANG_TURKMEN_TURKMENISTAN = &h01
Const SUBLANG_UIGHUR_PRC = &h01
Const SUBLANG_UKRAINIAN_UKRAINE = &h01
Const SUBLANG_UPPER_SORBIAN_GERMANY = &h01
Const SUBLANG_URDU_PAKISTAN = &h01
Const SUBLANG_URDU_INDIA = &h02
Const SUBLANG_UZBEK_LATIN = &h01
Const SUBLANG_UZBEK_CYRILLIC = &h02
Const SUBLANG_VIETNAMESE_VIETNAM = &h01
Const SUBLANG_WELSH_UNITED_KINGDOM = &h01
Const SUBLANG_WOLOF_SENEGAL = &h01
Const SUBLANG_XHOSA_SOUTH_AFRICA = &h01
Const SUBLANG_YAKUT_RUSSIA = &h01
Const SUBLANG_YI_PRC = &h01
Const SUBLANG_YORUBA_NIGERIA = &h01
Const SUBLANG_ZULU_SOUTH_AFRICA = &h01

' Sorting IDs.
Const SORT_DEFAULT = &h0

Const SORT_INVARIANT_MATH = &h1

Const SORT_JAPANESE_XJIS = &h0
Const SORT_JAPANESE_UNICODE = &h1
Const SORT_JAPANESE_RADICALSTROKE = &h4

Const SORT_CHINESE_BIG5 = &h0
Const SORT_CHINESE_PRCP = &h0
Const SORT_CHINESE_UNICODE = &h1
Const SORT_CHINESE_PRC = &h2
Const SORT_CHINESE_BOPOMOFO = &h3

Const SORT_KOREAN_KSC = &h0
Const SORT_KOREAN_UNICODE = &h1

Const SORT_GERMAN_PHONE_BOOK = &h1

Const SORT_HUNGARIAN_DEFAULT = &h0
Const SORT_HUNGARIAN_TECHNICAL = &h1

Const SORT_GEORGIAN_TRADITIONAL = &h0
Const SORT_GEORGIAN_MODERN = &h1

Const MAKELANGID(p, s) = ((((s) As Word) << 10) Or (p) As Word)
Const PRIMARYLANGID(lgid) = ((lgid) As Word And &h3ff)
Const SUBLANGID(lgid) = ((lgid) As Word >> 10)

Const NLS_VALID_LOCALE_MASK = &h000fffff

Const MAKELCID(lgid, srtid) = ((((((srtid) As Word) As DWord) << 16) Or (((lgid) As Word) As DWord)) As DWord)
Const MAKESORTLCID(lgid, srtid, ver) = (((MAKELCID(lgid, srtid)) Or ((((ver) As Word)) As DWord << 20)) As DWord)
Const LANGIDFROMLCID(lcid) = ((lcid) As Word)
Const SORTIDFROMLCID(lcid) = (((((lcid) As DWord) >> 16) And &hf) As Word)
Const SORTVERSIONFROMLCID(lcid) = (((((lcid) As DWord) >> 20) And &hf) As Word)

Const LOCALE_NAME_MAX_LENGTH = 85

Const LANG_SYSTEM_DEFAULT = (MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT))
Const LANG_USER_DEFAULT = (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))

Const LOCALE_SYSTEM_DEFAULT = (MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT))
Const LOCALE_USER_DEFAULT = (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT))

Const LOCALE_CUSTOM_DEFAULT = (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_CUSTOM_DEFAULT), SORT_DEFAULT))
Const LOCALE_CUSTOM_UNSPECIFIED = (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_CUSTOM_UNSPECIFIED), SORT_DEFAULT))
Const LOCALE_CUSTOM_UI_DEFAULT = (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_UI_CUSTOM_DEFAULT), SORT_DEFAULT))
Const LOCALE_NEUTRAL = (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT))
Const LOCALE_INVARIANT = (MAKELCID(MAKELANGID(LANG_INVARIANT, SUBLANG_NEUTRAL), SORT_DEFAULT))

' DEFAULT_UNREACHABLE

#ifndef WIN32_NO_STATUS
Const STATUS_WAIT_0 = (&h00000000 As DWord)
Const STATUS_ABANDONED_WAIT_0 = (&h00000080 As DWord)
Const STATUS_USER_APC = (&h000000C0 As DWord)
Const STATUS_TIMEOUT = (&h00000102 As DWord)
Const STATUS_PENDING = (&h00000103 As DWord)
Const DBG_EXCEPTION_HANDLED = (&h00010001 As DWord)
Const DBG_CONTINUE = (&h00010002 As DWord)
Const STATUS_SEGMENT_NOTIFICATION = (&h40000005 As DWord)
Const DBG_TERMINATE_THREAD = (&h40010003 As DWord)
Const DBG_TERMINATE_PROCESS = (&h40010004 As DWord)
Const DBG_CONTROL_C = (&h40010005 As DWord)
Const DBG_CONTROL_BREAK = (&h40010008 As DWord)
Const DBG_COMMAND_EXCEPTION = (&h40010009 As DWord)
Const STATUS_GUARD_PAGE_VIOLATION = (&h80000001 As DWord)
Const STATUS_DATATYPE_MISALIGNMENT = (&h80000002 As DWord)
Const STATUS_BREAKPOINT = (&h80000003 As DWord)
Const STATUS_SINGLE_STEP = (&h80000004 As DWord)
Const DBG_EXCEPTION_NOT_HANDLED = (&h80010001 As DWord)
Const STATUS_ACCESS_VIOLATION = (&hC0000005 As DWord)
Const STATUS_IN_PAGE_ERROR = (&hC0000006 As DWord)
Const STATUS_INVALID_HANDLE = (&hC0000008 As DWord)
Const STATUS_NO_MEMORY = (&hC0000017 As DWord)
Const STATUS_ILLEGAL_INSTRUCTION = (&hC000001D As DWord)
Const STATUS_NONCONTINUABLE_EXCEPTION = (&hC0000025 As DWord)
Const STATUS_INVALID_DISPOSITION = (&hC0000026 As DWord)
Const STATUS_ARRAY_BOUNDS_EXCEEDED = (&hC000008C As DWord)
Const STATUS_FLOAT_DENORMAL_OPERAND = (&hC000008D As DWord)
Const STATUS_FLOAT_DIVIDE_BY_ZERO = (&hC000008E As DWord)
Const STATUS_FLOAT_INEXACT_RESULT = (&hC000008F As DWord)
Const STATUS_FLOAT_INVALID_OPERATION = (&hC0000090 As DWord)
Const STATUS_FLOAT_OVERFLOW = (&hC0000091 As DWord)
Const STATUS_FLOAT_STACK_CHECK = (&hC0000092 As DWord)
Const STATUS_FLOAT_UNDERFLOW = (&hC0000093 As DWord)
Const STATUS_INTEGER_DIVIDE_BY_ZERO = (&hC0000094 As DWord)
Const STATUS_INTEGER_OVERFLOW = (&hC0000095 As DWord)
Const STATUS_PRIVILEGED_INSTRUCTION = (&hC0000096 As DWord)
Const STATUS_STACK_OVERFLOW = (&hC00000FD As DWord)
Const STATUS_CONTROL_C_EXIT = (&hC000013A As DWord)
Const STATUS_FLOAT_MULTIPLE_FAULTS = (&hC00002B4 As DWord)
Const STATUS_FLOAT_MULTIPLE_TRAPS = (&hC00002B5 As DWord)
Const STATUS_REG_NAT_CONSUMPTION = (&hC00002C9 As DWord)
'#if defined(STATUS_SUCCESS) || (_WIN32_WINNT > 0x0500) || (_WIN32_FUSION >= 0x0100)
Const STATUS_SXS_EARLY_DEACTIVATION = (&hC015000F As DWord)
Const STATUS_SXS_INVALID_DEACTIVATION = (&hC0150010 As DWord)
'#endif
#endif

Const MAXIMUM_WAIT_OBJECTS = 64

Const MAXIMUM_SUSPEND_COUNT = MAXCHAR

TypeDef KSPIN_LOCK = ULONG_PTR
TypeDef PKSPIN_LOCK = KSPIN_LOCK

#ifdef _WIN64

Const EXCEPTION_READ_FAULT = 0
Const EXCEPTION_WRITE_FAULT = 1
Const EXCEPTION_EXECUTE_FAULT = 8

Const CONTEXT_AMD64 = &h100000

Const CONTEXT_CONTROL = (CONTEXT_AMD64 Or &h1)
Const CONTEXT_INTEGER = (CONTEXT_AMD64 Or &h2)
Const CONTEXT_SEGMENTS = (CONTEXT_AMD64 Or &h4)
Const CONTEXT_FLOATING_POINT  = (CONTEXT_AMD64 Or &h8)
Const CONTEXT_DEBUG_REGISTERS = (CONTEXT_AMD64 Or &h10)

Const CONTEXT_FULL = (CONTEXT_CONTROL Or CONTEXT_INTEGER Or CONTEXT_FLOATING_POINT)

Const CONTEXT_ALL = (CONTEXT_CONTROL Or CONTEXT_INTEGER Or CONTEXT_SEGMENTS Or CONTEXT_FLOATING_POINT Or CONTEXT_DEBUG_REGISTERS)

Const CONTEXT_EXCEPTION_ACTIVE = &h8000000
Const CONTEXT_SERVICE_ACTIVE = &h10000000
Const CONTEXT_EXCEPTION_REQUEST = &h40000000
Const CONTEXT_EXCEPTION_REPORTING = &h80000000

Const INITIAL_MXCSR = &h1f80
Const INITIAL_FPCSR = &h027f

Type Align(16) M128A
	Low As QWord
	High As Int64
End Type
TypeDef PM128A = *M128A

Type XMM_SAVE_AREA32
	ControlWord As Word
	StatusWord As Word
	TagWord As Byte
	Reserved1 As Byte
	ErrorOpcode As Word
	ErrorOffset As DWord
	ErrorSelector As Word
	Reserved2 As Word
	DataOffset As DWord
	DataSelector As Word
	Reserved3 As Word
	MxCsr As DWord
	MxCsr_Mask As DWord
	FloatRegisters[ELM(8)] As M128A
	XmmRegisters[ELM(16)] As M128A
	Reserved4[ELM(96)] As Byte
End Type
TypeDef PXMM_SAVE_AREA32 = *XMM_SAVE_AREA32

Const LEGACY_SAVE_AREA_LENGTH = SizeOf (XMM_SAVE_AREA32)

Type Align(16) CONTEXT
	'Register parameter home addresses.
	P1Home As QWord
	P2Home As QWord
	P3Home As QWord
	P4Home As QWord
	P5Home As QWord
	P6Home As QWord
	'Control flags.
	ContextFlags As DWord
	MxCsr As DWord
	'Segment Registers and processor flags.
	SegCs As Word
	SegDs As Word
	SegEs As Word
	SegFs As Word
	SegGs As Word
	SegSs As Word
	EFlags As DWord
	'Debug registers
	Dr0 As QWord
	Dr1 As QWord
	Dr2 As QWord
	Dr3 As QWord
	Dr6 As QWord
	Dr7 As QWord
	'Integer registers.
	Rax As QWord
	Rcx As QWord
	Rdx As QWord
	Rbx As QWord
	Rsp As QWord
	Rbp As QWord
	Rsi As QWord
	Rdi As QWord
	R8 As QWord
	R9 As QWord
	R10 As QWord
	R11 As QWord
	R12 As QWord
	R13 As QWord
	R14 As QWord
	R15 As QWord
	'Program counter.
	Rip As QWord
	'MMX/floating point state.
	Header[ELM(2)] As M128A
	Legacy[ELM(8)] As M128A
	Xmm0 As M128A
	Xmm1 As M128A
	Xmm2 As M128A
	Xmm3 As M128A
	Xmm4 As M128A
	Xmm5 As M128A
	Xmm6 As M128A
	Xmm7 As M128A
	Xmm8 As M128A
	Xmm9 As M128A
	Xmm10 As M128A
	Xmm11 As M128A
	Xmm12 As M128A
	Xmm13 As M128A
	Xmm14 As M128A
	Xmm15 As M128A
	Reserve[ELM(96)] As Byte
	'Vector registers
	VectorRegisters[ELM(26)] As M128A
	VectorControl As QWord
	'Special debug control registers.
	DebugControl As QWord
	LastBranchToRip As QWord
	LastBranchFromRip As QWord
	LastExceptionToRip As QWord
	LastExceptionFromRip As QWord
End Type
TypeDef PCONTEXT = *CONTEXT

Const RUNTIME_FUNCTION_INDIRECT = &h1

Type RUNTIME_FUNCTION
	BeginAddress As DWord
	EndAddress As DWord
	UnwindData As DWord
End Type
TypeDef PRUNTIME_FUNCTION = *RUNTIME_FUNCTION

TypeDef PGET_RUNTIME_FUNCTION_CALLBACK = *Function(ControlPc As QWord, Context As PVOID) As PRUNTIME_FUNCTION

TypeDef POUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK = *Function(Process As HANDLE, TableAddress As PVOID, Entries As *DWord, ByRef Functions As PRUNTIME_FUNCTION) As DWord

Const OUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK_EXPORT_NAME = "OutOfProcessFunctionTableCallback"

Declare Sub RtlRestoreContext Lib "kernel32" (ByRef ContextRecord As CONTEXT, ExceptionRecord As *EXCEPTION_RECORD)
Declare Function RtlAddFunctionTable Lib "kernel32" (FunctionTable As PRUNTIME_FUNCTION, EntryCount As DWord, BaseAddress As QWord) As BOOLEAN
Declare Function RtlInstallFunctionTableCallback Lib "kernel32" (TableIdentifier As QWord, BaseAddress As QWord, Length As DWord, Callback As PGET_RUNTIME_FUNCTION_CALLBACK, Context As PVOID, OutOfProcessCallbackDll As PCWSTR) As BOOLEAN
Declare Function RtlDeleteFunctionTable Lib "kernel32" (FunctionTable As PRUNTIME_FUNCTION) As BOOLEAN

'#endif '_WIN64
#else
'#ifdef _WIN32
'InterlockedBitTestAndSet
'InterlockedBitTestAndReset
'InterlockedBitTestAndComplement


'MemoryBarrier
'PreFetchCacheLine
'ReadForWriteAccess

'ReadPMC
'ReadTimeStampCounter

'DbgRaiseAssertionFailure

'GetFiberData
'GetCurrentFibe

Const EXCEPTION_READ_FAULT = 0
Const EXCEPTION_WRITE_FAULT = 1
Const EXCEPTION_EXECUTE_FAULT = 8

Const SIZE_OF_80387_REGISTERS = 80

Const CONTEXT_i386 = &h00010000
Const CONTEXT_i486 = &h00010000

Const CONTEXT_CONTROL = (CONTEXT_i386 Or &h00000001) ' SS:SP, CS:IP, FLAGS, BP
Const CONTEXT_INTEGER = (CONTEXT_i386 Or &h00000002) ' AX, BX, CX, DX, SI, DI
Const CONTEXT_SEGMENTS = (CONTEXT_i386 Or &h00000004) ' DS, ES, FS, GS
Const CONTEXT_FLOATING_POINT = (CONTEXT_i386 Or &h00000008) ' 387 state
Const CONTEXT_DEBUG_REGISTERS = (CONTEXT_i386 Or &h00000010) ' DB 0-3,6,7
Const CONTEXT_EXTENDED_REGISTERS = (CONTEXT_i386 Or &h00000020) ' cpu specific extensions
Const CONTEXT_FULL = (CONTEXT_CONTROL Or CONTEXT_INTEGER Or CONTEXT_SEGMENTS)
Const CONTEXT_ALL = (CONTEXT_CONTROL Or CONTEXT_INTEGER Or CONTEXT_SEGMENTS Or  CONTEXT_FLOATING_POINT Or CONTEXT_DEBUG_REGISTERS Or  CONTEXT_EXTENDED_REGISTERS)

Const MAXIMUM_SUPPORTED_EXTENSION = 512

Type FLOATING_SAVE_AREA
	ControlWord As DWord
	StatusWord As DWord
	TagWord As DWord
	ErrorOffset As DWord
	ErrorSelector As DWord
	DataOffset As DWord
	DataSelector As DWord
	RegisterArea[ELM(SIZE_OF_80387_REGISTERS)] As Byte
	Cr0NpxState As DWord
End Type
TypeDef PFLOATING_SAVE_AREA = FLOATING_SAVE_AREA

Type CONTEXT
	ContextFlags As DWord

	Dr0 As DWord
	Dr1 As DWord
	Dr2 As DWord
	Dr3 As DWord
	Dr6 As DWord
	Dr7 As DWord

	FloatSave As FLOATING_SAVE_AREA

	SegGs As DWord
	SegFs As DWord
	SegEs As DWord
	SegDs As DWord

	Edi As DWord
	Esi As DWord
	Ebx As DWord
	Edx As DWord
	Ecx As DWord
	Eax As DWord

	Ebp As DWord
	Eip As DWord
	SegCs As DWord
	EFlags As DWord
	Esp As DWord
	SegSs As DWord

	ExtendedRegisters[ELM(MAXIMUM_SUPPORTED_EXTENSION)] As Byte
End Type

TypeDef PCONTEXT = *CONTEXT

#endif

Type LDT_ENTRY
	LimitLow As Word
	BaseLow As Word
	BaseMid As Byte
	Flags1 As Byte
	Flags2 As Byte
	BaseHi As Byte
End Type
TypeDef PLDT_ENTRY = *LDT_ENTRY

Const WOW64_CONTEXT_i386 = &h00010000
Const WOW64_CONTEXT_i486 = &h00010000

Const WOW64_CONTEXT_CONTROL = (WOW64_CONTEXT_i386 Or &h00000001) ' SS:SP, CS:IP, FLAGS, BP
Const WOW64_CONTEXT_INTEGER = (WOW64_CONTEXT_i386 Or &h00000002) ' AX, BX, CX, DX, SI, DI
Const WOW64_CONTEXT_SEGMENTS = (WOW64_CONTEXT_i386 Or &h00000004) ' DS, ES, FS, GS
Const WOW64_CONTEXT_FLOATING_POINT = (WOW64_CONTEXT_i386 Or &h00000008) ' 387 state
Const WOW64_CONTEXT_DEBUG_REGISTERS = (WOW64_CONTEXT_i386 Or &h00000010) ' DB 0-3,6,7
Const WOW64_CONTEXT_EXTENDED_REGISTERS = (WOW64_CONTEXT_i386 Or &h00000020) ' cpu specific extensions
Const WOW64_CONTEXT_FULL = (WOW64_CONTEXT_CONTROL Or WOW64_CONTEXT_INTEGER Or WOW64_CONTEXT_SEGMENTS)
Const WOW64_CONTEXT_ALL = (WOW64_CONTEXT_CONTROL Or WOW64_CONTEXT_INTEGER Or WOW64_CONTEXT_SEGMENTS Or WOW64_CONTEXT_FLOATING_POINT Or WOW64_CONTEXT_DEBUG_REGISTERS Or WOW64_CONTEXT_EXTENDED_REGISTERS)

Const WOW64_SIZE_OF_80387_REGISTERS = 80

Const WOW64_MAXIMUM_SUPPORTED_EXTENSION = 512

Type WOW64_FLOATING_SAVE_AREA
	ControlWord As DWord
	StatusWord As DWord
	TagWord As DWord
	ErrorOffset As DWord
	ErrorSelector As DWord
	DataOffset As DWord
	DataSelector As DWord
	RegisterArea[ELM(WOW64_SIZE_OF_80387_REGISTERS)] As Byte
	Cr0NpxState As DWord
End Type
TypeDef PWOW64_FLOATING_SAVE_AREA = *WOW64_FLOATING_SAVE_AREA

Type WOW64_CONTEXT
	ContextFlags As DWord

	Dr0 As DWord
	Dr1 As DWord
	Dr2 As DWord
	Dr3 As DWord
	Dr6 As DWord
	Dr7 As DWord

	FloatSave As WOW64_FLOATING_SAVE_AREA

	SegGs As DWord
	SegFs As DWord
	SegEs As DWord
	SegDs As DWord

	Edi As DWord
	Esi As DWord
	Ebx As DWord
	Edx As DWord
	Ecx As DWord
	Eax As DWord

	Ebp As DWord
	Eip As DWord
	SegCs As DWord
	EFlags As DWord
	Esp As DWord
	SegSs As DWord

	ExtendedRegisters[ELM(WOW64_MAXIMUM_SUPPORTED_EXTENSION)] As Byte
End Type

TypeDef PWOW64_CONTEXT = *WOW64_CONTEXT

Const EXCEPTION_NONCONTINUABLE = &h1
Const EXCEPTION_MAXIMUM_PARAMETERS = 15

Type EXCEPTION_RECORD
	ExceptionCode As DWord
	ExceptionFlags As DWord
	ExceptionRecord As *EXCEPTION_RECORD
	ExceptionAddress As PVOID
	NumberParameters As DWord
	ExceptionInformation[ELM(EXCEPTION_MAXIMUM_PARAMETERS)] As ULONG_PTR
End Type
TypeDef PEXCEPTION_RECORD = *EXCEPTION_RECORD

Type EXCEPTION_RECORD32
	ExceptionCode As DWord
	ExceptionFlags As DWord
	ExceptionRecord As DWord
	ExceptionAddress As DWord
	NumberParameters As DWord
	ExceptionInformation[ELM(EXCEPTION_MAXIMUM_PARAMETERS)] As DWord
End Type
TypeDef PEXCEPTION_RECORD32 = *EXCEPTION_RECORD32

Type EXCEPTION_RECORD64
	ExceptionCode As DWord
	ExceptionFlags As DWord
	ExceptionRecord As QWord
	ExceptionAddress As QWord
	NumberParameters As DWord
	__unusedAlignment As DWord
	ExceptionInformation[ELM(EXCEPTION_MAXIMUM_PARAMETERS)] As QWord
End Type
TypeDef PEXCEPTION_RECORD64 = *EXCEPTION_RECORD64

Type EXCEPTION_POINTERS
	ExceptionRecord As PEXCEPTION_RECORD
	ContextRecord As PCONTEXT
End Type
TypeDef PEXCEPTION_POINTERS = *EXCEPTION_POINTERS

TypeDef PACCESS_TOKEN = PVOID
'TypeDef PSECURITY_DESCRIPTOR = PVOID
'TypeDef PSID = PVOID

'ACCESS MASK
TypeDef ACCESS_MASK = DWord
TypeDef PACCESS_MASK = *ACCESS_MASK

'ACCESS TYPES

'Const DELETE = (&h00010000)
Const READ_CONTROL = (&h00020000)
Const WRITE_DAC = (&h00040000)
Const WRITE_OWNER = (&h00080000)
Const SYNCHRONIZE = (&h00100000)

Const STANDARD_RIGHTS_REQUIRED = (&h000F0000)

Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Const STANDARD_RIGHTS_EXECUTE = (READ_CONTROL)

Const STANDARD_RIGHTS_ALL = (&h001F0000)

Const SPECIFIC_RIGHTS_ALL = (&h0000FFFF)

Const ACCESS_SYSTEM_SECURITY = (&h01000000)

Const MAXIMUM_ALLOWED = (&h02000000)

Const GENERIC_READ = (&h80000000)
Const GENERIC_WRITE = (&h40000000)
Const GENERIC_EXECUTE = (&h20000000)
Const GENERIC_ALL = (&h10000000)

Type GENERIC_MAPPING
	GenericRead As ACCESS_MASK
	GenericWrite As ACCESS_MASK
	GenericExecute As ACCESS_MASK
	GenericAll As ACCESS_MASK
End Type
TypeDef PGENERIC_MAPPING = *GENERIC_MAPPING

' LUID_AND_ATTRIBUTES
Type Align(4) LUID_AND_ATTRIBUTES
	Luid As LUID
	Attributes As DWord
End Type
'TypeDef LUID_AND_ATTRIBUTES_ARRAY = LUID_AND_ATTRIBUTES[ANYSIZE_ARRAY]
'TypeDef PLUID_AND_ATTRIBUTES_ARRAY = *LUID_AND_ATTRIBUTES_ARRAY

' Security Id (SID)

Type SID_IDENTIFIER_AUTHORITY
	Value[ELM(6)] As Byte
End Type
TypeDef PSID_IDENTIFIER_AUTHORITY = *SID_IDENTIFIER_AUTHORITY

Type SID
	Revision As Byte
	SubAuthorityCount As Byte
	IdentifierAuthority As SID_IDENTIFIER_AUTHORITY
	SubAuthority[ELM(ANYSIZE_ARRAY)] As DWord
End Type
TypeDef PSID = *SID

Const SID_REVISION = (1)
Const SID_MAX_SUB_AUTHORITIES = (15)
Const SID_RECOMMENDED_SUB_AUTHORITIES = (1)

Const SECURITY_MAX_SID_SIZE = (SizeOf (SID) - SizeOf (DWord) + (SID_MAX_SUB_AUTHORITIES * SizeOf (DWord)))

Enum SID_NAME_USE
	SidTypeUser = 1
	SidTypeGroup
	SidTypeDomain
	SidTypeAlias
	SidTypeWellKnownGroup
	SidTypeDeletedAccount
	SidTypeInvalid
	SidTypeUnknown
	SidTypeComputer
	SidTypeLabel
End Enum
TypeDef PSID_NAME_USE = *SID_NAME_USE

Type SID_AND_ATTRIBUTES
	Sid As PSID
	Attributes As DWord
End Type
TypeDef PSID_AND_ATTRIBUTES = *SID_AND_ATTRIBUTES

'TypeDef SID_AND_ATTRIBUTES_ARRAY = SID_AND_ATTRIBUTES[ANYSIZE_ARRAY]
'TypeDef PSID_AND_ATTRIBUTES_ARRAY = *SID_AND_ATTRIBUTES_ARRAY

Const SID_HASH_SIZE = 32
TypeDef SID_HASH_ENTRY = ULONG_PTR
TypeDef PSID_HASH_ENTRY = *SID_HASH_ENTRY

Type SID_AND_ATTRIBUTES_HASH
	SidCount As DWord
	SidAttr As PSID_AND_ATTRIBUTES
	Hash[ELM(SID_HASH_SIZE)] As SID_HASH_ENTRY
End Type
TypeDef PSID_AND_ATTRIBUTES_HASH = *SID_AND_ATTRIBUTES_HASH

' Universal well-known SIDs
'Const SECURITY_NULL_SID_AUTHORITY = [0, 0, 0, 0, 0, 0] As SID_IDENTIFIER_AUTHORITY
'Const SECURITY_WORLD_SID_AUTHORITY = [0, 0, 0, 0, 0, 1] As SID_IDENTIFIER_AUTHORITY
'Const SECURITY_LOCAL_SID_AUTHORITY = [0, 0, 0, 0, 0, 2] As SID_IDENTIFIER_AUTHORITY
'Const SECURITY_CREATOR_SID_AUTHORITY = [0, 0, 0, 0, 0, 3] As SID_IDENTIFIER_AUTHORITY
'Const SECURITY_NON_UNIQUE_AUTHORITY = [0, 0, 0, 0, 0, 4] As SID_IDENTIFIER_AUTHORITY
'Const SECURITY_RESOURCE_MANAGER_AUTHORITY = [0, 0, 0, 0, 0, 9] As SID_IDENTIFIER_AUTHORITY

Const SECURITY_NULL_RID = (&h00000000)
Const SECURITY_WORLD_RID = (&h00000000)
Const SECURITY_LOCAL_RID = (&h00000000)

Const SECURITY_CREATOR_OWNER_RID = (&h00000000)
Const SECURITY_CREATOR_GROUP_RID = (&h00000001)

Const SECURITY_CREATOR_OWNER_SERVER_RID = (&h00000002)
Const SECURITY_CREATOR_GROUP_SERVER_RID = (&h00000003)

Const SECURITY_CREATOR_OWNER_RIGHTS_RID = (&h00000004)

' NT well-known SIDs
'Const SECURITY_NT_AUTHORITY = [0, 0, 0, 0, 0, 9] As SID_IDENTIFIER_AUTHORITY

Const SECURITY_DIALUP_RID = (&h00000001)
Const SECURITY_NETWORK_RID = (&h00000002)
Const SECURITY_BATCH_RID = (&h00000003)
Const SECURITY_INTERACTIVE_RID = (&h00000004)
Const SECURITY_LOGON_IDS_RID = (&h00000005)
Const SECURITY_LOGON_IDS_RID_COUNT = (3)
Const SECURITY_SERVICE_RID = (&h00000006)
Const SECURITY_ANONYMOUS_LOGON_RID = (&h00000007)
Const SECURITY_PROXY_RID = (&h00000008)
Const SECURITY_ENTERPRISE_CONTROLLERS_RID = (&h00000009)
Const SECURITY_SERVER_LOGON_RID = SECURITY_ENTERPRISE_CONTROLLERS_RID
Const SECURITY_PRINCIPAL_SELF_RID = (&h0000000A)
Const SECURITY_AUTHENTICATED_USER_RID = (&h0000000B)
Const SECURITY_RESTRICTED_CODE_RID = (&h0000000C)
Const SECURITY_TERMINAL_SERVER_RID = (&h0000000D)
Const SECURITY_REMOTE_LOGON_RID = (&h0000000E)
Const SECURITY_THIS_ORGANIZATION_RID = (&h0000000F)
Const SECURITY_IUSER_RID = (&h00000011)
Const SECURITY_LOCAL_SYSTEM_RID = (&h00000012)
Const SECURITY_LOCAL_SERVICE_RID = (&h00000013)
Const SECURITY_NETWORK_SERVICE_RID = (&h00000014)

Const SECURITY_NT_NON_UNIQUE = (&h00000015)
Const SECURITY_NT_NON_UNIQUE_SUB_AUTH_COUNT = (3)

Const SECURITY_ENTERPRISE_READONLY_CONTROLLERS_RID = (&h00000016)

Const SECURITY_BUILTIN_DOMAIN_RID = (&h00000020)
Const SECURITY_WRITE_RESTRICTED_CODE_RID = (&h00000021)


Const SECURITY_PACKAGE_BASE_RID = (&h00000040)
Const SECURITY_PACKAGE_RID_COUNT = (2)
Const SECURITY_PACKAGE_NTLM_RID = (&h0000000A)
Const SECURITY_PACKAGE_SCHANNEL_RID = (&h0000000E)
Const SECURITY_PACKAGE_DIGEST_RID = (&h00000015)

Const SECURITY_SERVICE_ID_BASE_RID = (&h00000050)
Const SECURITY_SERVICE_ID_RID_COUNT = (6)

Const SECURITY_RESERVED_ID_BASE_RID = (&h00000051)

Const SECURITY_MAX_ALWAYS_FILTERED = (&h000003E7)
Const SECURITY_MIN_NEVER_FILTERED = (&h000003E8)

Const SECURITY_OTHER_ORGANIZATION_RID = (&h000003E8)

' well-known domain relative sub-authority values (RIDs)...
' Well-known users ...
Const FOREST_USER_RID_MAX = (&h000001F3)

Const DOMAIN_USER_RID_ADMIN = (&h000001F4)
Const DOMAIN_USER_RID_GUEST = (&h000001F5)
Const DOMAIN_USER_RID_KRBTGT = (&h000001F6)

Const DOMAIN_USER_RID_MAX = (&h000003E7)

' well-known groups ...
Const DOMAIN_GROUP_RID_ADMINS = (&h00000200)
Const DOMAIN_GROUP_RID_USERS = (&h00000201)
Const DOMAIN_GROUP_RID_GUESTS = (&h00000202)
Const DOMAIN_GROUP_RID_COMPUTERS = (&h00000203)
Const DOMAIN_GROUP_RID_CONTROLLERS = (&h00000204)
Const DOMAIN_GROUP_RID_CERT_ADMINS = (&h00000205)
Const DOMAIN_GROUP_RID_SCHEMA_ADMINS = (&h00000206)
Const DOMAIN_GROUP_RID_ENTERPRISE_ADMINS = (&h00000207)
Const DOMAIN_GROUP_RID_POLICY_ADMINS = (&h00000208)
Const DOMAIN_GROUP_RID_READONLY_CONTROLLERS = (&h00000209)

' well-known aliases ...
Const DOMAIN_ALIAS_RID_ADMINS = (&h00000220)
Const DOMAIN_ALIAS_RID_USERS = (&h00000221)
Const DOMAIN_ALIAS_RID_GUESTS = (&h00000222)
Const DOMAIN_ALIAS_RID_POWER_USERS = (&h00000223)

Const DOMAIN_ALIAS_RID_ACCOUNT_OPS = (&h00000224)
Const DOMAIN_ALIAS_RID_SYSTEM_OPS = (&h00000225)
Const DOMAIN_ALIAS_RID_PRINT_OPS = (&h00000226)
Const DOMAIN_ALIAS_RID_BACKUP_OPS = (&h00000227)

Const DOMAIN_ALIAS_RID_REPLICATOR = (&h00000228)
Const DOMAIN_ALIAS_RID_RAS_SERVERS = (&h00000229)
Const DOMAIN_ALIAS_RID_PREW2KCOMPACCESS = (&h0000022A)
Const DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS = (&h0000022B)
Const DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS = (&h0000022C)
Const DOMAIN_ALIAS_RID_INCOMING_FOREST_TRUST_BUILDERS = (&h0000022D)

Const DOMAIN_ALIAS_RID_MONITORING_USERS = (&h0000022E)
Const DOMAIN_ALIAS_RID_LOGGING_USERS = (&h0000022F)
Const DOMAIN_ALIAS_RID_AUTHORIZATIONACCESS = (&h00000230)
Const DOMAIN_ALIAS_RID_TS_LICENSE_SERVERS = (&h00000231)
Const DOMAIN_ALIAS_RID_DCOM_USERS = (&h00000232)
Const DOMAIN_ALIAS_RID_IUSERS = (&h00000238)
Const DOMAIN_ALIAS_RID_CRYPTO_OPERATORS = (&h00000239)
Const DOMAIN_ALIAS_RID_CACHEABLE_PRINCIPALS_GROUP = (&h0000023B)
Const DOMAIN_ALIAS_RID_NON_CACHEABLE_PRINCIPALS_GROUP = (&h0000023C)
Const DOMAIN_ALIAS_RID_EVENT_LOG_READERS_GROUP = (&h0000023D)

'Const SECURITY_MANDATORY_LABEL_AUTHORITY = [0, 0, 0, 0 ,0, 16] As SID_IDENTIFIER_AUTHORITY
Const SECURITY_MANDATORY_UNTRUSTED_RID = (&h00000000)
Const SECURITY_MANDATORY_LOW_RID = (&h00001000)
Const SECURITY_MANDATORY_MEDIUM_RID = (&h00002000)
Const SECURITY_MANDATORY_HIGH_RID = (&h00003000)
Const SECURITY_MANDATORY_SYSTEM_RID = (&h00004000)
Const SECURITY_MANDATORY_PROTECTED_PROCESS_RID = (&h00005000)


Const SECURITY_MANDATORY_MAXIMUM_USER_RID = SECURITY_MANDATORY_SYSTEM_RID

Const MANDATORY_LEVEL_TO_MANDATORY_RID(I) = (I * &h1000)

' Well known SID definitions for lookup.
Const Enum WELL_KNOWN_SID_TYPE
	WinNullSid = 0
	WinWorldSid = 1
	WinLocalSid = 2
	WinCreatorOwnerSid = 3
	WinCreatorGroupSid = 4
	WinCreatorOwnerServerSid = 5
	WinCreatorGroupServerSid = 6
	WinNtAuthoritySid = 7
	WinDialupSid = 8
	WinNetworkSid = 9
	WinBatchSid = 10
	WinInteractiveSid = 11
	WinServiceSid = 12
	WinAnonymousSid = 13
	WinProxySid = 14
	WinEnterpriseControllersSid = 15
	WinSelfSid = 16
	WinAuthenticatedUserSid = 17
	WinRestrictedCodeSid = 18
	WinTerminalServerSid = 19
	WinRemoteLogonIdSid = 20
	WinLogonIdsSid = 21
	WinLocalSystemSid = 22
	WinLocalServiceSid = 23
	WinNetworkServiceSid = 24
	WinBuiltinDomainSid = 25
	WinBuiltinAdministratorsSid = 26
	WinBuiltinUsersSid = 27
	WinBuiltinGuestsSid = 28
	WinBuiltinPowerUsersSid = 29
	WinBuiltinAccountOperatorsSid = 30
	WinBuiltinSystemOperatorsSid = 31
	WinBuiltinPrintOperatorsSid = 32
	WinBuiltinBackupOperatorsSid = 33
	WinBuiltinReplicatorSid = 34
	WinBuiltinPreWindows2000CompatibleAccessSid = 35
	WinBuiltinRemoteDesktopUsersSid = 36
	WinBuiltinNetworkConfigurationOperatorsSid = 37
	WinAccountAdministratorSid = 38
	WinAccountGuestSid = 39
	WinAccountKrbtgtSid = 40
	WinAccountDomainAdminsSid = 41
	WinAccountDomainUsersSid = 42
	WinAccountDomainGuestsSid = 43
	WinAccountComputersSid = 44
	WinAccountControllersSid = 45
	WinAccountCertAdminsSid = 46
	WinAccountSchemaAdminsSid = 47
	WinAccountEnterpriseAdminsSid = 48
	WinAccountPolicyAdminsSid = 49
	WinAccountRasAndIasServersSid = 50
	WinNTLMAuthenticationSid = 51
	WinDigestAuthenticationSid = 52
	WinSChannelAuthenticationSid = 53
	WinThisOrganizationSid = 54
	WinOtherOrganizationSid = 55
	WinBuiltinIncomingForestTrustBuildersSid = 56
	WinBuiltinPerfMonitoringUsersSid = 57
	WinBuiltinPerfLoggingUsersSid = 58
	WinBuiltinAuthorizationAccessSid = 59
	WinBuiltinTerminalServerLicenseServersSid = 60
	WinBuiltinDCOMUsersSid = 61
	WinBuiltinIUsersSid = 62
	WinIUserSid = 63
	WinBuiltinCryptoOperatorsSid = 64
	WinUntrustedLabelSid = 65
	WinLowLabelSid = 66
	WinMediumLabelSid = 67
	WinHighLabelSid = 68
	WinSystemLabelSid = 69
	WinWriteRestrictedCodeSid = 70
	WinCreatorOwnerRightsSid = 71
	WinCacheablePrincipalsGroupSid = 72
	WinNonCacheablePrincipalsGroupSid = 73
	WinEnterpriseReadonlyControllersSid = 74
	WinAccountReadonlyControllersSid = 75
	WinBuiltinEventLogReadersGroup = 76
End Enum

'Const SYSTEM_LUID = [&h3e7, &h0] As LUID
'Const ANONYMOUS_LOGON_LUID = [&h3e6, &h0] As LUID
'Const LOCALSERVICE_LUID = [&h3e5, &h0] As LUID
'Const NETWORKSERVICE_LUID = [&h3e4, &h0] As LUID
'Const IUSER_LUID = [&h3e3, &h0] As LUID

' User and Group related SID attributes

' Group attributes
Const SE_GROUP_MANDATORY = (&h00000001)
Const SE_GROUP_ENABLED_BY_DEFAULT = (&h00000002)
Const SE_GROUP_ENABLED = (&h00000004)
Const SE_GROUP_OWNER = (&h00000008)
Const SE_GROUP_USE_FOR_DENY_ONLY = (&h00000010)
Const SE_GROUP_INTEGRITY = (&h00000020)
Const SE_GROUP_INTEGRITY_ENABLED = (&h00000040)
Const SE_GROUP_LOGON_ID = (&hC0000000)
Const SE_GROUP_RESOURCE = (&h20000000)

Const SE_GROUP_VALID_ATTRIBUTES = (SE_GROUP_MANDATORY Or SE_GROUP_ENABLED_BY_DEFAULT Or SE_GROUP_ENABLED Or SE_GROUP_OWNER Or SE_GROUP_USE_FOR_DENY_ONLY Or SE_GROUP_LOGON_ID  Or SE_GROUP_RESOURCE Or SE_GROUP_INTEGRITY Or SE_GROUP_INTEGRITY_ENABLED)

' ACL  and  ACE
Const ACL_REVISION = (2)
Const ACL_REVISION_DS = (4)

Const ACL_REVISION1 = (1)
Const MIN_ACL_REVISION = ACL_REVISION2
Const ACL_REVISION2 = (2)
Const ACL_REVISION3 = (3)
Const ACL_REVISION4 = (4)
Const MAX_ACL_REVISION = ACL_REVISION4

Type ACL
	AclRevision As Byte
	Sbz1 As Byte
	AclSize As Word
	AceCount As Word
	Sbz2 As Word
End Type
TypeDef PACL = ACL

Type ACE_HEADER
	AceType As Byte
	AceFlags As Byte
	AceSize As Word
End Type
TypeDef PACE_HEADER = *ACE_HEADER

Const ACCESS_MIN_MS_ACE_TYPE = (&h0)
Const ACCESS_ALLOWED_ACE_TYPE = (&h0)
Const ACCESS_DENIED_ACE_TYPE = (&h1)
Const SYSTEM_AUDIT_ACE_TYPE = (&h2)
Const SYSTEM_ALARM_ACE_TYPE = (&h3)
Const ACCESS_MAX_MS_V2_ACE_TYPE = (&h3)

Const ACCESS_ALLOWED_COMPOUND_ACE_TYPE = (&h4)
Const ACCESS_MAX_MS_V3_ACE_TYPE = (&h4)

Const ACCESS_MIN_MS_OBJECT_ACE_TYPE = (&h5)
Const ACCESS_ALLOWED_OBJECT_ACE_TYPE = (&h5)
Const ACCESS_DENIED_OBJECT_ACE_TYPE = (&h6)
Const SYSTEM_AUDIT_OBJECT_ACE_TYPE = (&h7)
Const SYSTEM_ALARM_OBJECT_ACE_TYPE = (&h8)
Const ACCESS_MAX_MS_OBJECT_ACE_TYPE = (&h8)

Const ACCESS_MAX_MS_V4_ACE_TYPE = (&h8)
Const ACCESS_MAX_MS_ACE_TYPE = (&h8)

Const ACCESS_ALLOWED_CALLBACK_ACE_TYPE = (&h9)
Const ACCESS_DENIED_CALLBACK_ACE_TYPE = (&hA)
Const ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE = (&hB)
Const ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE = (&hC)
Const SYSTEM_AUDIT_CALLBACK_ACE_TYPE = (&hD)
Const SYSTEM_ALARM_CALLBACK_ACE_TYPE = (&hE)
Const SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE = (&hF)
Const SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE = (&h10)

Const SYSTEM_MANDATORY_LABEL_ACE_TYPE = (&h11)
Const ACCESS_MAX_MS_V5_ACE_TYPE = (&h11)

Const OBJECT_INHERIT_ACE = (&h1)
Const CONTAINER_INHERIT_ACE = (&h2)
Const NO_PROPAGATE_INHERIT_ACE = (&h4)
Const INHERIT_ONLY_ACE = (&h8)
Const INHERITED_ACE = (&h10)
Const VALID_INHERIT_FLAGS = (&h1F)

Const SUCCESSFUL_ACCESS_ACE_FLAG = (&h40)
Const FAILED_ACCESS_ACE_FLAG = (&h80)

Type ACCESS_ALLOWED_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	SidStart As DWord
End Type
TypeDef PACCESS_ALLOWED_ACE = *ACCESS_ALLOWED_ACE

Type ACCESS_DENIED_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	SidStart As DWord
End Type
TypeDef PACCESS_DENIED_ACE = *ACCESS_DENIED_ACE

Type SYSTEM_AUDIT_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	SidStart As DWord
End Type
TypeDef PSYSTEM_AUDIT_ACE = *SYSTEM_AUDIT_ACE

Type SYSTEM_ALARM_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	SidStart As DWord
End Type
TypeDef PSYSTEM_ALARM_ACE = *SYSTEM_ALARM_ACE

Type SYSTEM_MANDATORY_LABEL_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	SidStart As DWord
End Type
TypeDef PSYSTEM_MANDATORY_LABEL_ACE = *SYSTEM_MANDATORY_LABEL_ACE

Const SYSTEM_MANDATORY_LABEL_NO_WRITE_UP = &h1
Const SYSTEM_MANDATORY_LABEL_NO_READ_UP = &h2
Const SYSTEM_MANDATORY_LABEL_NO_EXECUTE_UP = &h4

Const SYSTEM_MANDATORY_LABEL_VALID_MASK = (SYSTEM_MANDATORY_LABEL_NO_WRITE_UP Or SYSTEM_MANDATORY_LABEL_NO_READ_UP Or SYSTEM_MANDATORY_LABEL_NO_EXECUTE_UP)

Type ACCESS_ALLOWED_OBJECT_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	Flags As DWord
	ObjectType As GUID
	InheritedObjectType As GUID
	SidStart As DWord
End Type
TypeDef PACCESS_ALLOWED_OBJECT_ACE = *ACCESS_ALLOWED_OBJECT_ACE

Type ACCESS_DENIED_OBJECT_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	Flags As DWord
	ObjectType As GUID
	InheritedObjectType As GUID
	SidStart As DWord
End Type
TypeDef PACCESS_DENIED_OBJECT_ACE = *ACCESS_DENIED_OBJECT_ACE

Type SYSTEM_AUDIT_OBJECT_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	Flags As DWord
	ObjectType As GUID
	InheritedObjectType As GUID
	SidStart As DWord
End Type
TypeDef PSYSTEM_AUDIT_OBJECT_ACE = *SYSTEM_AUDIT_OBJECT_ACE

Type SYSTEM_ALARM_OBJECT_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	Flags As DWord
	ObjectType As GUID
	InheritedObjectType As GUID
	SidStart As DWord
End Type
TypeDef PSYSTEM_ALARM_OBJECT_ACE = *SYSTEM_ALARM_OBJECT_ACE

Type ACCESS_ALLOWED_CALLBACK_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	SidStart As DWord
End Type
TypeDef PACCESS_ALLOWED_CALLBACK_ACE = *ACCESS_ALLOWED_CALLBACK_ACE

Type ACCESS_DENIED_CALLBACK_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	SidStart As DWord
End Type
TypeDef PACCESS_DENIED_CALLBACK_ACE = *ACCESS_DENIED_CALLBACK_ACE

Type SYSTEM_AUDIT_CALLBACK_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	SidStart As DWord
End Type
TypeDef PSYSTEM_AUDIT_CALLBACK_ACE = *SYSTEM_AUDIT_CALLBACK_ACE

Type SYSTEM_ALARM_CALLBACK_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	SidStart As DWord
End Type
TypeDef PSYSTEM_ALARM_CALLBACK_ACE = *SYSTEM_ALARM_CALLBACK_ACE

Type ACCESS_ALLOWED_CALLBACK_OBJECT_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	Flags As DWord
	ObjectType As GUID
	InheritedObjectType As GUID
	SidStart As DWord
End Type
TypeDef PACCESS_ALLOWED_CALLBACK_OBJECT_ACE = *ACCESS_ALLOWED_CALLBACK_OBJECT_ACE

Type ACCESS_DENIED_CALLBACK_OBJECT_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	Flags As DWord
	ObjectType As GUID
	InheritedObjectType As GUID
	SidStart As DWord
End Type
TypeDef PACCESS_DENIED_CALLBACK_OBJECT_ACE = *ACCESS_DENIED_CALLBACK_OBJECT_ACE

Type SYSTEM_AUDIT_CALLBACK_OBJECT_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	Flags As DWord
	ObjectType As GUID
	InheritedObjectType As GUID
	SidStart As DWord
End Type
TypeDef PSYSTEM_AUDIT_CALLBACK_OBJECT_ACE = *SYSTEM_AUDIT_CALLBACK_OBJECT_ACE

Type SYSTEM_ALARM_CALLBACK_OBJECT_ACE
	Header As ACE_HEADER
	Mask As ACCESS_MASK
	Flags As DWord
	ObjectType As GUID
	InheritedObjectType As GUID
	SidStart As DWord
End Type
TypeDef PSYSTEM_ALARM_CALLBACK_OBJECT_ACE = *SYSTEM_ALARM_CALLBACK_OBJECT_ACE

Const ACE_OBJECT_TYPE_PRESENT = &h1
Const ACE_INHERITED_OBJECT_TYPE_PRESENT = &h2

Enum ACL_INFORMATION_CLASS
	AclRevisionInformation = 1
	AclSizeInformation
End Enum

Type ACL_REVISION_INFORMATION
	AclRevision As DWord
End Type
TypeDef PACL_REVISION_INFORMATION = *ACL_REVISION_INFORMATION

Type ACL_SIZE_INFORMATION
AceCount As DWord
AclBytesInUse As DWord
AclBytesFree As DWord
End Type
TypeDef PACL_SIZE_INFORMATION = *ACL_SIZE_INFORMATION

' SECURITY_DESCRIPTOR
Const SECURITY_DESCRIPTOR_REVISION = (1)
Const SECURITY_DESCRIPTOR_REVISION1 = (1)

Const SECURITY_DESCRIPTOR_MIN_LENGTH = (SizeOf (SECURITY_DESCRIPTOR))

TypeDef SECURITY_DESCRIPTOR_CONTROL = Word
TypeDef PSECURITY_DESCRIPTOR_CONTROL = *SECURITY_DESCRIPTOR_CONTROL

Const SE_OWNER_DEFAULTED = (&h0001)
Const SE_GROUP_DEFAULTED = (&h0002)
Const SE_DACL_PRESENT = (&h0004)
Const SE_DACL_DEFAULTED = (&h0008)
Const SE_SACL_PRESENT = (&h0010)
Const SE_SACL_DEFAULTED = (&h0020)
Const SE_DACL_AUTO_INHERIT_REQ = (&h0100)
Const SE_SACL_AUTO_INHERIT_REQ = (&h0200)
Const SE_DACL_AUTO_INHERITED = (&h0400)
Const SE_SACL_AUTO_INHERITED = (&h0800)
Const SE_DACL_PROTECTED = (&h1000)
Const SE_SACL_PROTECTED = (&h2000)
Const SE_RM_CONTROL_VALID = (&h4000)
Const SE_SELF_RELATIVE = (&h8000)

Type SECURITY_DESCRIPTOR_RELATIVE
	Revision As Byte
	Sbz1 As Byte
	Control As SECURITY_DESCRIPTOR_CONTROL
	Owner As DWord
	Group As DWord
	Sacl As DWord
	Dacl As DWord
End Type
TypeDef PSECURITY_DESCRIPTOR_RELATIVE = *SECURITY_DESCRIPTOR_RELATIVE

Type SECURITY_DESCRIPTOR
	Revision As Byte
	Sbz1 As Byte
	Control As SECURITY_DESCRIPTOR_CONTROL
	Owner As PSID
	Group As PSID
	Sacl As PACL
	Dacl As PACL
End Type
TypeDef PSECURITY_DESCRIPTOR = *SECURITY_DESCRIPTOR

Type OBJECT_TYPE_LIST
	Level As Word
	Sbz As Word
	ObjectType As *GUID
End Type
TypeDef POBJECT_TYPE_LIST = *OBJECT_TYPE_LIST

Const ACCESS_OBJECT_GUID = 0
Const ACCESS_PROPERTY_SET_GUID = 1
Const ACCESS_PROPERTY_GUID = 2

Const ACCESS_MAX_LEVEL = 4

Const Enum AUDIT_EVENT_TYPE
	AuditEventObjectAccess,
	AuditEventDirectoryServiceAccess
End Enum
TypeDef PAUDIT_EVENT_TYPE = *AUDIT_EVENT_TYPE

Const AUDIT_ALLOW_NO_PRIVILEGE = &h1

'Const ACCESS_DS_SOURCE_A = "DS"
'Const ACCESS_DS_SOURCE_W = L"DS"
'Const ACCESS_DS_OBJECT_TYPE_NAME_A = "Directory Service Object"
'Const ACCESS_DS_OBJECT_TYPE_NAME_W = L"Directory Service Object"
Const ACCESS_DS_SOURCE = "DS"
Const ACCESS_DS_OBJECT_TYPE_NAME = "Directory Service Object"

Const SE_PRIVILEGE_ENABLED_BY_DEFAULT = (&h00000001)
Const SE_PRIVILEGE_ENABLED = (&h00000002)
Const SE_PRIVILEGE_REMOVED = (&h00000004)
Const SE_PRIVILEGE_USED_FOR_ACCESS = (&h80000000)

Const SE_PRIVILEGE_VALID_ATTRIBUTES = (SE_PRIVILEGE_ENABLED_BY_DEFAULT Or SE_PRIVILEGE_ENABLED  Or SE_PRIVILEGE_REMOVED  Or SE_PRIVILEGE_USED_FOR_ACCESS)

Const PRIVILEGE_SET_ALL_NECESSARY = (1)

Type PRIVILEGE_SET
	PrivilegeCount As DWord
	Control As DWord
	Privilege[ELM(ANYSIZE_ARRAY)] As LUID_AND_ATTRIBUTES
End Type
TypeDef PPRIVILEGE_SET = *PRIVILEGE_SET

' NT Defined Privileges
Const SE_CREATE_TOKEN_NAME = "SeCreateTokenPrivilege"
Const SE_ASSIGNPRIMARYTOKEN_NAME = "SeAssignPrimaryTokenPrivilege"
Const SE_LOCK_MEMORY_NAME = "SeLockMemoryPrivilege"
Const SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege"
Const SE_UNSOLICITED_INPUT_NAME = "SeUnsolicitedInputPrivilege"
Const SE_MACHINE_ACCOUNT_NAME = "SeMachineAccountPrivilege"
Const SE_TCB_NAME = "SeTcbPrivilege"
Const SE_SECURITY_NAME = "SeSecurityPrivilege"
Const SE_TAKE_OWNERSHIP_NAME = "SeTakeOwnershipPrivilege"
Const SE_LOAD_DRIVER_NAME = "SeLoadDriverPrivilege"
Const SE_SYSTEM_PROFILE_NAME = "SeSystemProfilePrivilege"
Const SE_SYSTEMTIME_NAME = "SeSystemtimePrivilege"
Const SE_PROF_SINGLE_PROCESS_NAME = "SeProfileSingleProcessPrivilege"
Const SE_INC_BASE_PRIORITY_NAME = "SeIncreaseBasePriorityPrivilege"
Const SE_CREATE_PAGEFILE_NAME = "SeCreatePagefilePrivilege"
Const SE_CREATE_PERMANENT_NAME = "SeCreatePermanentPrivilege"
Const SE_BACKUP_NAME = "SeBackupPrivilege"
Const SE_RESTORE_NAME = "SeRestorePrivilege"
Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
Const SE_DEBUG_NAME = "SeDebugPrivilege"
Const SE_AUDIT_NAME = "SeAuditPrivilege"
Const SE_SYSTEM_ENVIRONMENT_NAME = "SeSystemEnvironmentPrivilege"
Const SE_CHANGE_NOTIFY_NAME = "SeChangeNotifyPrivilege"
Const SE_REMOTE_SHUTDOWN_NAME = "SeRemoteShutdownPrivilege"
Const SE_UNDOCK_NAME = "SeUndockPrivilege"
Const SE_SYNC_AGENT_NAME = "SeSyncAgentPrivilege"
Const SE_ENABLE_DELEGATION_NAME = "SeEnableDelegationPrivilege"
Const SE_MANAGE_VOLUME_NAME = "SeManageVolumePrivilege"
Const SE_IMPERSONATE_NAME = "SeImpersonatePrivilege"
Const SE_CREATE_GLOBAL_NAME = "SeCreateGlobalPrivilege"
Const SE_TRUSTED_CREDMAN_ACCESS_NAME = "SeTrustedCredManAccessPrivilege"
Const SE_RELABEL_NAME = "SeRelabelPrivilege"
Const SE_INC_WORKING_SET_NAME = "SeIncreaseWorkingSetPrivilege"
Const SE_TIME_ZONE_NAME = "SeTimeZonePrivilege"
Const SE_CREATE_SYMBOLIC_LINK_NAME = "SeCreateSymbolicLinkPrivilege"

' Security Quality Of Service
Const Enum SECURITY_IMPERSONATION_LEVEL
	SecurityAnonymous
	SecurityIdentification
	SecurityImpersonation
	SecurityDelegation
End Enum
TypeDef PSECURITY_IMPERSONATION_LEVEL = *SECURITY_IMPERSONATION_LEVEL

Const SECURITY_MAX_IMPERSONATION_LEVEL = SecurityDelegation
Const SECURITY_MIN_IMPERSONATION_LEVEL = SecurityAnonymous
Const DEFAULT_IMPERSONATION_LEVEL = SecurityImpersonation
Const VALID_IMPERSONATION_LEVEL(L) = (((L) >= SECURITY_MIN_IMPERSONATION_LEVEL) And ((L) <= SECURITY_MAX_IMPERSONATION_LEVEL))

' Token Object Definitions

' Token Specific Access Rights.
Const TOKEN_ASSIGN_PRIMARY = (&h0001)
Const TOKEN_DUPLICATE = (&h0002)
Const TOKEN_IMPERSONATE = (&h0004)
Const TOKEN_QUERY = (&h0008)
Const TOKEN_QUERY_SOURCE = (&h0010)
Const TOKEN_ADJUST_PRIVILEGES = (&h0020)
Const TOKEN_ADJUST_GROUPS = (&h0040)
Const TOKEN_ADJUST_DEFAULT = (&h0080)
Const TOKEN_ADJUST_SESSIONID = (&h0100)

Const TOKEN_ALL_ACCESS_P = (STANDARD_RIGHTS_REQUIRED Or TOKEN_ASSIGN_PRIMARY Or TOKEN_DUPLICATE  Or TOKEN_IMPERSONATE Or TOKEN_QUERY  Or TOKEN_QUERY_SOURCE Or TOKEN_ADJUST_PRIVILEGES Or TOKEN_ADJUST_GROUPS Or TOKEN_ADJUST_DEFAULT)
'#if ((defined(_WIN32_WINNT) And (_WIN32_WINNT > &h0400)) Or (!defined(_WIN32_WINNT)))
Const TOKEN_ALL_ACCESS = (TOKEN_ALL_ACCESS_P Or TOKEN_ADJUST_SESSIONID)
'#else
'Const TOKEN_ALL_ACCESS = (TOKEN_ALL_ACCESS_P)
'#endif
Const TOKEN_READ = (STANDARD_RIGHTS_READ Or TOKEN_QUERY)
Const TOKEN_WRITE = (STANDARD_RIGHTS_WRITE Or TOKEN_ADJUST_PRIVILEGES Or TOKEN_ADJUST_GROUPS Or TOKEN_ADJUST_DEFAULT)
Const TOKEN_EXECUTE = (STANDARD_RIGHTS_EXECUTE)

' Token Types
Const Enum TOKEN_TYPE
	TokenPrimary = 1
	TokenImpersonation
End Enum
TypeDef PTOKEN_TYPE = *TOKEN_TYPE

Const Enum TOKEN_ELEVATION_TYPE
	TokenElevationTypeDefault = 1
	TokenElevationTypeFull
	TokenElevationTypeLimited
End Enum
TypeDef PTOKEN_ELEVATION_TYPE = TOKEN_ELEVATION_TYPE

' Token Information Classes.
Const Enum TOKEN_INFORMATION_CLASS
	TokenUser = 1
	TokenGroups
	TokenPrivileges
	TokenOwner
	TokenPrimaryGroup
	TokenDefaultDacl
	TokenSource
	TokenType
	TokenImpersonationLevel
	TokenStatistics
	TokenRestrictedSids
	TokenSessionId
	TokenGroupsAndPrivileges
	TokenSessionReference
	TokenSandBoxInert
	TokenAuditPolicy
	TokenOrigin
	TokenElevationType
	TokenLinkedToken
	TokenElevation
	TokenHasRestrictions
	TokenAccessInformation
	TokenVirtualizationAllowed
	TokenVirtualizationEnabled
	TokenIntegrityLevel
	TokenUIAccess
	TokenMandatoryPolicy
	TokenLogonSid
	MaxTokenInfoClass
End Enum
TypeDef PTOKEN_INFORMATION_CLASS = TOKEN_INFORMATION_CLASS

Type TOKEN_USER
	User As SID_AND_ATTRIBUTES
End Type
TypeDef PTOKEN_USER = *TOKEN_USER

Type TOKEN_GROUPS
	GroupCount As DWord
	Groups[ELM(ANYSIZE_ARRAY)] As SID_AND_ATTRIBUTES
End Type
TypeDef PTOKEN_GROUPS = *TOKEN_GROUPS

Type TOKEN_PRIVILEGES
	PrivilegeCount As DWord
	Privileges[ELM(ANYSIZE_ARRAY)] As LUID_AND_ATTRIBUTES
End Type
TypeDef PTOKEN_PRIVILEGES = *TOKEN_PRIVILEGES

Type TOKEN_OWNER
	Owner As PSID
End Type
TypeDef PTOKEN_OWNER = TOKEN_OWNER

Type TOKEN_PRIMARY_GROUP
	PrimaryGroup As PSID
End Type
TypeDef PTOKEN_PRIMARY_GROUP = TOKEN_PRIMARY_GROUP

Type TOKEN_DEFAULT_DACL
	DefaultDacl As PACL
End Type
TypeDef PTOKEN_DEFAULT_DACL = *TOKEN_DEFAULT_DACL

Type TOKEN_GROUPS_AND_PRIVILEGES
	SidCount As DWord
	SidLength As DWord
	Sids As PSID_AND_ATTRIBUTES
	RestrictedSidCount As DWord
	RestrictedSidLength As DWord
	RestrictedSids As PSID_AND_ATTRIBUTES
	PrivilegeCount As DWord
	PrivilegeLength As DWord
	Privileges As VoidPtr 'PLUID_AND_ATTRIBUTES
	AuthenticationId As LUID
End Type
TypeDef PTOKEN_GROUPS_AND_PRIVILEGES = *TOKEN_GROUPS_AND_PRIVILEGES

Type TOKEN_LINKED_TOKEN
	LinkedToken As HANDLE
End Type
TypeDef PTOKEN_LINKED_TOKEN = *TOKEN_LINKED_TOKEN

Type TOKEN_ELEVATION
	TokenIsElevated As DWord
End Type
TypeDef PTOKEN_ELEVATION = *TOKEN_ELEVATION

Type TOKEN_MANDATORY_LABEL
	Label As SID_AND_ATTRIBUTES
End Type
TypeDef PTOKEN_MANDATORY_LABEL = *TOKEN_MANDATORY_LABEL

Const TOKEN_MANDATORY_POLICY_OFF = &h0
Const TOKEN_MANDATORY_POLICY_NO_WRITE_UP = &h1
Const TOKEN_MANDATORY_POLICY_NEW_PROCESS_MIN = &h2

Const TOKEN_MANDATORY_POLICY_VALID_MASK = (TOKEN_MANDATORY_POLICY_NO_WRITE_UP Or TOKEN_MANDATORY_POLICY_NEW_PROCESS_MIN)

Type TOKEN_MANDATORY_POLICY
	Policy As DWord
End Type
TypeDef PTOKEN_MANDATORY_POLICY = *TOKEN_MANDATORY_POLICY

Type TOKEN_ACCESS_INFORMATION
	SidHash As PSID_AND_ATTRIBUTES_HASH
	RestrictedSidHash As PSID_AND_ATTRIBUTES_HASH
	Privileges As PTOKEN_PRIVILEGES
	AuthenticationId As LUID
	TokenType As TOKEN_TYPE
	ImpersonationLevel As SECURITY_IMPERSONATION_LEVEL
	MandatoryPolicy As TOKEN_MANDATORY_POLICY
	Flags As DWord
End Type
TypeDef PTOKEN_ACCESS_INFORMATION = *TOKEN_ACCESS_INFORMATION

Const POLICY_AUDIT_SUBCATEGORY_COUNT = (50)

Type TOKEN_AUDIT_POLICY
	PerUserPolicy[ELM(((POLICY_AUDIT_SUBCATEGORY_COUNT) >> 1) + 1)] As Byte
End Type
TypeDef PTOKEN_AUDIT_POLICY = TOKEN_AUDIT_POLICY

Const TOKEN_SOURCE_LENGTH = 8

Type TOKEN_SOURCE
	SourceName[ELM(TOKEN_SOURCE_LENGTH)] As CHAR
	SourceIdentifier As LUID
End Type
TypeDef PTOKEN_SOURCE = *TOKEN_SOURCE

Type TOKEN_STATISTICS
	TokenId As LUID
	AuthenticationId As LUID
	ExpirationTime As LARGE_INTEGER
	TokenType As TOKEN_TYPE
	ImpersonationLevel As SECURITY_IMPERSONATION_LEVEL
	DynamicCharged As DWord
	DynamicAvailable As DWord
	GroupCount As DWord
	PrivilegeCount As DWord
	ModifiedId As LUID
End Type
TypeDef PTOKEN_STATISTICS = *TOKEN_STATISTICS

Type TOKEN_CONTROL
	TokenId As LUID
	AuthenticationId As LUID
	ModifiedId As LUID
	TokenSource As TOKEN_SOURCE
End Type
TypeDef PTOKEN_CONTROL = *TOKEN_CONTROL

Type TOKEN_ORIGIN
	OriginatingLogonSession As LUID
End Type
TypeDef PTOKEN_ORIGIN = *TOKEN_ORIGIN

Const Enum MANDATORY_LEVEL
	MandatoryLevelUntrusted = 0
	MandatoryLevelLow
	MandatoryLevelMedium
	MandatoryLevelHigh
	MandatoryLevelSystem
	MandatoryLevelSecureProcess
	MandatoryLevelCount
End Enum
TypeDef PMANDATORY_LEVEL = *MANDATORY_LEVEL

Const SECURITY_DYNAMIC_TRACKING = (TRUE)
Const SECURITY_STATIC_TRACKING = (FALSE)

TypeDef SECURITY_CONTEXT_TRACKING_MODE = BOOLEAN
TypeDef PSECURITY_CONTEXT_TRACKING_MODE = *BOOLEAN

Type SECURITY_QUALITY_OF_SERVICE
	Length As DWord
	ImpersonationLevel As SECURITY_IMPERSONATION_LEVEL
	ContextTrackingMode As SECURITY_CONTEXT_TRACKING_MODE
	EffectiveOnly As BOOLEAN
End Type
TypeDef PSECURITY_QUALITY_OF_SERVICE = *SECURITY_QUALITY_OF_SERVICE

Type SE_IMPERSONATION_STATE
	Token As PACCESS_TOKEN
	CopyOnOpen As BOOLEAN
	EffectiveOnly As BOOLEAN
	Level As SECURITY_IMPERSONATION_LEVEL
End Type
TypeDef PSE_IMPERSONATION_STATE = *SE_IMPERSONATION_STATE

Const DISABLE_MAX_PRIVILEGE = &h1
Const SANDBOX_INERT = &h2
Const LUA_TOKEN = &h4
Const WRITE_RESTRICTED = &h8

TypeDef SECURITY_INFORMATION = DWord
TypeDef PSECURITY_INFORMATION = *DWord

Const OWNER_SECURITY_INFORMATION = (&h00000001)
Const GROUP_SECURITY_INFORMATION = (&h00000002)
Const DACL_SECURITY_INFORMATION = (&h00000004)
Const SACL_SECURITY_INFORMATION = (&h00000008)
Const LABEL_SECURITY_INFORMATION = (&h00000010)

Const PROTECTED_DACL_SECURITY_INFORMATION = (&h80000000)
Const PROTECTED_SACL_SECURITY_INFORMATION = (&h40000000)
Const UNPROTECTED_DACL_SECURITY_INFORMATION = (&h20000000)
Const UNPROTECTED_SACL_SECURITY_INFORMATION = (&h10000000)

Const PROCESS_TERMINATE = (&h0001)
Const PROCESS_CREATE_THREAD = (&h0002)
Const PROCESS_SET_SESSIONID = (&h0004)
Const PROCESS_VM_OPERATION = (&h0008)
Const PROCESS_VM_READ = (&h0010)
Const PROCESS_VM_WRITE = (&h0020)
Const PROCESS_DUP_HANDLE = (&h0040)
Const PROCESS_CREATE_PROCESS = (&h0080)
Const PROCESS_SET_QUOTA = (&h0100)
Const PROCESS_SET_INFORMATION = (&h0200)
Const PROCESS_QUERY_INFORMATION = (&h0400)
Const PROCESS_SUSPEND_RESUME = (&h0800)
Const PROCESS_QUERY_LIMITED_INFORMATION = (&h1000)
'#if (NTDDI_VERSION >= NTDDI_LONGHORN)
'Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &hFFFF)
'#else
Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &hFFF)
'#endif

#ifdef _WIN64
Const MAXIMUM_PROCESSORS = 64
#else
Const MAXIMUM_PROCESSORS = 32
#endif

Const THREAD_TERMINATE = (&h0001)
Const THREAD_SUSPEND_RESUME = (&h0002)
Const THREAD_GET_CONTEXT = (&h0008)
Const THREAD_SET_CONTEXT = (&h0010)
Const THREAD_QUERY_INFORMATION = (&h0040)
Const THREAD_SET_INFORMATION = (&h0020)
Const THREAD_SET_THREAD_TOKEN = (&h0080)
Const THREAD_IMPERSONATE = (&h0100)
Const THREAD_DIRECT_IMPERSONATION = (&h0200)
Const THREAD_SET_LIMITED_INFORMATION = (&h0400)
Const THREAD_QUERY_LIMITED_INFORMATION = (&h0800)
'#if (NTDDI_VERSION >= NTDDI_LONGHORN)
'Const THREAD_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &hFFFF)
'#else
Const THREAD_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &h3FF)
'#endif
Const JOB_OBJECT_ASSIGN_PROCESS = (&h0001)
Const JOB_OBJECT_SET_ATTRIBUTES = (&h0002)
Const JOB_OBJECT_QUERY = (&h0004)
Const JOB_OBJECT_TERMINATE = (&h0008)
Const JOB_OBJECT_SET_SECURITY_ATTRIBUTES = (&h0010)
Const JOB_OBJECT_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &h1F)

Type JOB_SET_ARRAY
	JobHandle As HANDLE
	MemberLevel As DWord
	Flags As DWord
End Type
TypeDef PJOB_SET_ARRAY = *JOB_SET_ARRAY

Const FLS_MAXIMUM_AVAILABLE = 128
Const TLS_MINIMUM_AVAILABLE = 64

Type NT_TIB
	ExceptionList As VoidPtr '*EXCEPTION_REGISTRATION_RECORD
	StackBase As PVOID
	StackLimit As PVOID
	SubSystemTib As PVOID
'	Union
		FiberData As PVOID
'		Version As DWord
'	End Union
	PVOID ArbitraryUserPointer As PVOID
	Self As *NT_TIB
End Type
TypeDef PNT_TIB = *NT_TIB

Type NT_TIB32
	ExceptionList As DWord
	StackBase As DWord
	StackLimit As DWord
	SubSystemTib As DWord
'	Union
		FiberData As DWord
'		Version As DWord
'	End Union
	ArbitraryUserPointer As DWord
	Self As DWord
End Type
TypeDef PNT_TIB32 = *NT_TIB32

Type NT_TIB64
	ExceptionList As QWord
	StackBase As QWord
	StackLimit As QWord
	SubSystemTib As QWord
'	Union
		FiberData As QWord
'		Version As QWord
'	End Union
	ArbitraryUserPointer As QWord
	Self As QWord
End Type
TypeDef PNT_TIB64 = *NT_TIB64

Const THREAD_BASE_PRIORITY_LOWRT = 15
Const THREAD_BASE_PRIORITY_MAX = 2
Const THREAD_BASE_PRIORITY_MIN = (-2)
Const THREAD_BASE_PRIORITY_IDLE = (-15)

Type QUOTA_LIMITS
	PagedPoolLimit As SIZE_T
	NonPagedPoolLimit As SIZE_T
	MinimumWorkingSetSize As SIZE_T
	MaximumWorkingSetSize As SIZE_T
	PagefileLimit As SIZE_T
	TimeLimit As LARGE_INTEGER
End Type
TypeDef PQUOTA_LIMITS = *QUOTA_LIMITS

Const QUOTA_LIMITS_HARDWS_MIN_ENABLE = &h00000001
Const QUOTA_LIMITS_HARDWS_MIN_DISABLE = &h00000002
Const QUOTA_LIMITS_HARDWS_MAX_ENABLE = &h00000004
Const QUOTA_LIMITS_HARDWS_MAX_DISABLE = &h00000008
Const QUOTA_LIMITS_USE_DEFAULT_LIMITS = &h00000010

Const PS_RATE_PHASE_BITS = 4
Const PS_RATE_PHASE_MASK = ((1 As DWord << PS_RATE_PHASE_BITS) - 1)

Const Enum PS_RATE_PHASE
	PsRateOneSecond = 0
	PsRateTwoSecond
	PsRateThreeSecond
	PsRateMaxPhase
End Enum

Type RATE_QUOTA_LIMIT
	RateData As DWord
	dummy As DWord
'	Type
'		DWORD RatePhase     : PS_RATE_PHASE_BITS;
'		DWORD RatePercent   : 28;
'	End Type
End Type
TypeDef PRATE_QUOTA_LIMIT = *RATE_QUOTA_LIMIT

'#if !defined(SORTPP_PASS) && !defined(MIDL_PASS) && !defined(RC_INVOKED) && defined(_WIN64) && !defined(_X86AMD64_)
'C_ASSERT (sizeof (DWORD) * 8 - PS_RATE_PHASE_BITS == 28);
'#endif

Type QUOTA_LIMITS_EX
	PagedPoolLimit As SIZE_T
	NonPagedPoolLimit As SIZE_T
	MinimumWorkingSetSize As SIZE_T
	MaximumWorkingSetSize As SIZE_T
	PagefileLimit As SIZE_T
	TimeLimit As LARGE_INTEGER
	WorkingSetLimit As SIZE_T
	Reserved2 As SIZE_T
	Reserved3 As SIZE_T
	Reserved4 As SIZE_T
	Flags As DWord
	CpuRateLimit As RATE_QUOTA_LIMIT
End Type
TypeDef PQUOTA_LIMITS_EX = *QUOTA_LIMITS_EX

Type IO_COUNTERS
	ReadOperationCount As QWord
	WriteOperationCount As QWord
	OtherOperationCount As QWord
	ReadTransferCount As QWord
	WriteTransferCount As QWord
	OtherTransferCount As QWord
End Type
TypeDef PIO_COUNTERS = IO_COUNTERS

Type JOBOBJECT_BASIC_ACCOUNTING_INFORMATION
	TotalUserTime As LARGE_INTEGER
	TotalKernelTime As LARGE_INTEGER
	ThisPeriodTotalUserTime As LARGE_INTEGER
	ThisPeriodTotalKernelTime As LARGE_INTEGER
	TotalPageFaultCount As DWord
	TotalProcesses As DWord
	ActiveProcesses As DWord
	TotalTerminatedProcesses As DWord
End Type
TypeDef PJOBOBJECT_BASIC_ACCOUNTING_INFORMATION = *JOBOBJECT_BASIC_ACCOUNTING_INFORMATION

Type JOBOBJECT_BASIC_LIMIT_INFORMATION
	PerProcessUserTimeLimit As LARGE_INTEGER
	PerJobUserTimeLimit As LARGE_INTEGER
	LimitFlags As DWord
	MinimumWorkingSetSize As SIZE_T
	MaximumWorkingSetSize As SIZE_T
	ActiveProcessLimit As DWord
	Affinity As ULONG_PTR
	PriorityClass As DWord
	SchedulingClass As DWord
End Type
TypeDef PJOBOBJECT_BASIC_LIMIT_INFORMATION = *JOBOBJECT_BASIC_LIMIT_INFORMATION

Type JOBOBJECT_EXTENDED_LIMIT_INFORMATION
	BasicLimitInformation As JOBOBJECT_BASIC_LIMIT_INFORMATION
	IoInfo As IO_COUNTERS
	ProcessMemoryLimit As SIZE_T
	JobMemoryLimitt As SIZE_T
	PeakProcessMemoryUsedt As SIZE_T
	PeakJobMemoryUsedt As SIZE_T
End Type
TypeDef PJOBOBJECT_EXTENDED_LIMIT_INFORMATION = *JOBOBJECT_EXTENDED_LIMIT_INFORMATION

Type JOBOBJECT_BASIC_PROCESS_ID_LIST
	NumberOfAssignedProcesses As DWord
	NumberOfProcessIdsInList As DWord
	ProcessIdList[1] As ULONG_PTR
End Type
TypeDef PJOBOBJECT_BASIC_PROCESS_ID_LIST = *JOBOBJECT_BASIC_PROCESS_ID_LIST

Type JOBOBJECT_BASIC_UI_RESTRICTIONS
	UIRestrictionsClass As DWord
End Type
TypeDef PJOBOBJECT_BASIC_UI_RESTRICTIONS = *JOBOBJECT_BASIC_UI_RESTRICTIONS

Type JOBOBJECT_SECURITY_LIMIT_INFORMATION
	SecurityLimitFlags As DWord
	JobToken As HANDLE
	SidsToDisable As PTOKEN_GROUPS
	PrivilegesToDelete As PTOKEN_PRIVILEGES
	RestrictedSids As PTOKEN_GROUPS
End Type
TypeDef PJOBOBJECT_SECURITY_LIMIT_INFORMATION = *JOBOBJECT_SECURITY_LIMIT_INFORMATION

Type JOBOBJECT_END_OF_JOB_TIME_INFORMATION
	EndOfJobTimeAction As DWord
End Type
TypeDef PJOBOBJECT_END_OF_JOB_TIME_INFORMATION = *JOBOBJECT_END_OF_JOB_TIME_INFORMATION

Type JOBOBJECT_ASSOCIATE_COMPLETION_PORT
	CompletionKey As PVOID
	CompletionPort As HANDLE
End Type
TypeDef PJOBOBJECT_ASSOCIATE_COMPLETION_PORT = *JOBOBJECT_ASSOCIATE_COMPLETION_PORT

Type JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION
	BasicInfo As JOBOBJECT_BASIC_ACCOUNTING_INFORMATION
	IoInfo As IO_COUNTERS
End Type
TypeDef PJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION = *JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION

Type JOBOBJECT_JOBSET_INFORMATION
	MemberLevel As DWord
End Type
TypeDef PJOBOBJECT_JOBSET_INFORMATION = *JOBOBJECT_JOBSET_INFORMATION

Const JOB_OBJECT_TERMINATE_AT_END_OF_JOB = 0
Const JOB_OBJECT_POST_AT_END_OF_JOB = 1

' Completion Port Messages for job objects
Const JOB_OBJECT_MSG_END_OF_JOB_TIME = 1
Const JOB_OBJECT_MSG_END_OF_PROCESS_TIME = 2
Const JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT = 3
Const JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO = 4
Const JOB_OBJECT_MSG_NEW_PROCESS = 6
Const JOB_OBJECT_MSG_EXIT_PROCESS = 7
Const JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS = 8
Const JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT = 9
Const JOB_OBJECT_MSG_JOB_MEMORY_LIMIT = 10

' Basic Limits
Const JOB_OBJECT_LIMIT_WORKINGSET = &h00000001
Const JOB_OBJECT_LIMIT_PROCESS_TIME = &h00000002
Const JOB_OBJECT_LIMIT_JOB_TIME = &h00000004
Const JOB_OBJECT_LIMIT_ACTIVE_PROCESS = &h00000008
Const JOB_OBJECT_LIMIT_AFFINITY = &h00000010
Const JOB_OBJECT_LIMIT_PRIORITY_CLASS = &h00000020
Const JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME = &h00000040
Const JOB_OBJECT_LIMIT_SCHEDULING_CLASS = &h00000080

' Extended Limits
Const JOB_OBJECT_LIMIT_PROCESS_MEMORY = &h00000100
Const JOB_OBJECT_LIMIT_JOB_MEMORY = &h00000200
Const JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION = &h00000400
Const JOB_OBJECT_LIMIT_BREAKAWAY_OK = &h00000800
Const JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK = &h00001000
Const JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE = &h00002000

Const JOB_OBJECT_LIMIT_RESERVED2 = &h00004000
Const JOB_OBJECT_LIMIT_RESERVED3 = &h00008000
Const JOB_OBJECT_LIMIT_RESERVED4 = &h00010000
Const JOB_OBJECT_LIMIT_RESERVED5 = &h00020000
Const JOB_OBJECT_LIMIT_RESERVED6 = &h00040000


Const JOB_OBJECT_LIMIT_VALID_FLAGS = &h0007ffff

Const JOB_OBJECT_BASIC_LIMIT_VALID_FLAGS = &h000000ff
Const JOB_OBJECT_EXTENDED_LIMIT_VALID_FLAGS = &h00003fff
Const JOB_OBJECT_RESERVED_LIMIT_VALID_FLAGS = &h0007ffff

' UI restrictions for jobs
Const JOB_OBJECT_UILIMIT_NONE = &h00000000

Const JOB_OBJECT_UILIMIT_HANDLES = &h00000001
Const JOB_OBJECT_UILIMIT_READCLIPBOARD = &h00000002
Const JOB_OBJECT_UILIMIT_WRITECLIPBOARD = &h00000004
Const JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS = &h00000008
Const JOB_OBJECT_UILIMIT_DISPLAYSETTINGS = &h00000010
Const JOB_OBJECT_UILIMIT_GLOBALATOMS = &h00000020
Const JOB_OBJECT_UILIMIT_DESKTOP = &h00000040
Const JOB_OBJECT_UILIMIT_EXITWINDOWS = &h00000080

Const JOB_OBJECT_UILIMIT_ALL = &h000000FF

Const JOB_OBJECT_UI_VALID_FLAGS = &h000000FF

Const JOB_OBJECT_SECURITY_NO_ADMIN = &h00000001
Const JOB_OBJECT_SECURITY_RESTRICTED_TOKEN = &h00000002
Const JOB_OBJECT_SECURITY_ONLY_TOKEN = &h00000004
Const JOB_OBJECT_SECURITY_FILTER_TOKENS = &h00000008

Const JOB_OBJECT_SECURITY_VALID_FLAGS = &h0000000f

Enum JOBOBJECTINFOCLASS
	JobObjectBasicAccountingInformation = 1
	JobObjectBasicLimitInformation
	JobObjectBasicProcessIdList
	JobObjectBasicUIRestrictions
	JobObjectSecurityLimitInformation
	JobObjectEndOfJobTimeInformation
	JobObjectAssociateCompletionPortInformation
	JobObjectBasicAndIoAccountingInformation
	JobObjectExtendedLimitInformation
	JobObjectJobSetInformation
	MaxJobObjectInfoClass
End Enum

Const EVENT_MODIFY_STATE = &h0002
Const EVENT_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &h3)
Const MUTANT_QUERY_STATE = &h0001

Const MUTANT_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or MUTANT_QUERY_STATE)
Const SEMAPHORE_MODIFY_STATE = &h0002
Const SEMAPHORE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &h3)

' Timer Specific Access Rights.
Const TIMER_QUERY_STATE = &h0001
Const TIMER_MODIFY_STATE = &h0002

Const TIMER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or TIMER_QUERY_STATE Or TIMER_MODIFY_STATE)

Const TIME_ZONE_ID_UNKNOWN = 0
Const TIME_ZONE_ID_STANDARD = 1
Const TIME_ZONE_ID_DAYLIGHT = 2

Enum LOGICAL_PROCESSOR_RELATIONSHIP
	RelationProcessorCore
	RelationNumaNode
	RelationCache
	RelationProcessorPackage
End Enum

Const LTP_PC_SMT = 1

Enum PROCESSOR_CACHE_TYPE
	CacheUnified
	CacheInstruction
	CacheData
	CacheTrace
End Enum

Const CACHE_FULLY_ASSOCIATIVE = &hFF

Type CACHE_DESCRIPTOR
	Level As Byte
	Associativity As Byte
	LineSize As Word
	Size As DWord
	Type_ As PROCESSOR_CACHE_TYPE
End Type
TypeDef PCACHE_DESCRIPTOR = *CACHE_DESCRIPTOR

Type SYSTEM_LOGICAL_PROCESSOR_INFORMATION
	ProcessorMask As ULONG_PTR
	Relationship As LOGICAL_PROCESSOR_RELATIONSHIP
'	Union
'		struct {
'			Flags As Byte
'		} ProcessorCore;
'		struct {
'			NodeNumber As DWord
'		} NumaNode;
		Cache As CACHE_DESCRIPTOR
'		Reserved[ELM(2)] As ULONGLONG
'	End Union
End Type
TypeDef PSYSTEM_LOGICAL_PROCESSOR_INFORMATION = *SYSTEM_LOGICAL_PROCESSOR_INFORMATION

Const PROCESSOR_INTEL_386 = 386
Const PROCESSOR_INTEL_486 = 486
Const PROCESSOR_INTEL_PENTIUM = 586
Const PROCESSOR_INTEL_IA64 = 2200
Const PROCESSOR_AMD_X8664 = 8664
Const PROCESSOR_MIPS_R4000 = 4000    ' incl R4101 & R3910 for Windows CE
Const PROCESSOR_ALPHA_21064 = 21064
Const PROCESSOR_PPC_601 = 601
Const PROCESSOR_PPC_603 = 603
Const PROCESSOR_PPC_604 = 604
Const PROCESSOR_PPC_620 = 620
Const PROCESSOR_HITACHI_SH3 = 10003   ' Windows CE
Const PROCESSOR_HITACHI_SH3E = 10004  ' Windows CE
Const PROCESSOR_HITACHI_SH4 = 10005   ' Windows CE
Const PROCESSOR_MOTOROLA_821 = 821    ' Windows CE
Const PROCESSOR_SHx_SH3 = 103         ' Windows CE
Const PROCESSOR_SHx_SH4 = 104         ' Windows CE
Const PROCESSOR_STRONGARM = 2577      ' Windows CE - 0xA11
Const PROCESSOR_ARM720 = 1824         ' Windows CE - 0x720
Const PROCESSOR_ARM820 = 2080         ' Windows CE - 0x820
Const PROCESSOR_ARM920 = 2336         ' Windows CE - 0x920
Const PROCESSOR_ARM_7TDMI = 70001     ' Windows CE
Const PROCESSOR_OPTIL = &h494f        ' MSIL

Const PROCESSOR_ARCHITECTURE_INTEL = 0
Const PROCESSOR_ARCHITECTURE_MIPS = 1
Const PROCESSOR_ARCHITECTURE_ALPHA = 2
Const PROCESSOR_ARCHITECTURE_PPC = 3
Const PROCESSOR_ARCHITECTURE_SHX = 4
Const PROCESSOR_ARCHITECTURE_ARM = 5
Const PROCESSOR_ARCHITECTURE_IA64 = 6
Const PROCESSOR_ARCHITECTURE_ALPHA64 = 7
Const PROCESSOR_ARCHITECTURE_MSIL = 8
Const PROCESSOR_ARCHITECTURE_AMD64 = 9
Const PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 = 10

Const PROCESSOR_ARCHITECTURE_UNKNOWN = &hFFFF

Const PF_FLOATING_POINT_PRECISION_ERRATA = 0
Const PF_FLOATING_POINT_EMULATED = 1
Const PF_COMPARE_EXCHANGE_DOUBLE = 2
Const PF_MMX_INSTRUCTIONS_AVAILABLE = 3
Const PF_PPC_MOVEMEM_64BIT_OK = 4
Const PF_ALPHA_BYTE_INSTRUCTIONS = 5
Const PF_XMMI_INSTRUCTIONS_AVAILABLE = 6
Const PF_3DNOW_INSTRUCTIONS_AVAILABLE = 7
Const PF_RDTSC_INSTRUCTION_AVAILABLE = 8
Const PF_PAE_ENABLED = 9
Const PF_XMMI64_INSTRUCTIONS_AVAILABLE = 10
Const PF_SSE_DAZ_MODE_AVAILABLE = 11
Const PF_NX_ENABLED = 12
Const PF_SSE3_INSTRUCTIONS_AVAILABLE = 13
Const PF_COMPARE_EXCHANGE128 = 14
Const PF_COMPARE64_EXCHANGE128 = 15
Const PF_CHANNELS_ENABLED = 16

Type MEMORY_BASIC_INFORMATION
	BaseAddress As VoidPtr
	AllocationBase As VoidPtr
	AllocationProtect As DWord
	RegionSize As SIZE_T
	State As DWord
	Protect As DWord
	MBIType As DWord
End Type
TypeDef PMEMORY_BASIC_INFORMATION = *MEMORY_BASIC_INFORMATION

Type MEMORY_BASIC_INFORMATION32
	BaseAddress As DWord
	AllocationBase As DWord
	AllocationProtect As DWord
	RegionSize As DWord
	State As DWord
	Protect As DWord
	Type_ As DWord
End Type
TypeDef PMEMORY_BASIC_INFORMATION32 = *MEMORY_BASIC_INFORMATION32

Type Align(16) MEMORY_BASIC_INFORMATION64
	BaseAddress As QWord
	AllocationBase As QWord
	AllocationProtect As DWord
	__alignment1 As DWord
	RegionSize As QWord
	State As DWord
	Protect As DWord
	Type_ As DWord
	__alignment2 As DWord
End Type
TypeDef PMEMORY_BASIC_INFORMATION64 = *MEMORY_BASIC_INFORMATION64

Const SECTION_QUERY = &h0001
Const SECTION_MAP_WRITE = &h0002
Const SECTION_MAP_READ = &h0004
Const SECTION_MAP_EXECUTE = &h0008
Const SECTION_EXTEND_SIZE = &h0010
Const SECTION_MAP_EXECUTE_EXPLICIT = &h0020

Const SECTION_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SECTION_QUERY Or SECTION_MAP_WRITE Or SECTION_MAP_READ Or SECTION_MAP_EXECUTE Or SECTION_EXTEND_SIZE)

Const SESSION_QUERY_ACCESS = &h0001
Const SESSION_MODIFY_ACCESS = &h0002

Const SESSION_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SESSION_QUERY_ACCESS Or SESSION_MODIFY_ACCESS)

Const PAGE_NOACCESS = &h01
Const PAGE_READONLY = &h02
Const PAGE_READWRITE = &h04
Const PAGE_WRITECOPY = &h08
Const PAGE_EXECUTE = &h10
Const PAGE_EXECUTE_READ = &h20
Const PAGE_EXECUTE_READWRITE = &h40
Const PAGE_EXECUTE_WRITECOPY = &h80
Const PAGE_GUARD = &h100
Const PAGE_NOCACHE = &h200
Const PAGE_WRITECOMBINE = &h400
Const MEM_COMMIT = &h1000
Const MEM_RESERVE = &h2000
Const MEM_DECOMMIT = &h4000
Const MEM_RELEASE = &h8000
Const MEM_FREE = &h10000
Const MEM_PRIVATE = &h20000
Const MEM_MAPPED = &h40000
Const MEM_RESET = &h80000
Const MEM_TOP_DOWN = &h100000
Const MEM_WRITE_WATCH = &h200000
Const MEM_PHYSICAL = &h400000
Const MEM_ROTATE = &h800000
Const MEM_LARGE_PAGES = &h20000000
Const MEM_4MB_PAGES = &h80000000
Const SEC_FILE = &h800000
Const SEC_IMAGE = &h1000000
Const SEC_PROTECTED_IMAGE = &h2000000
Const SEC_RESERVE = &h4000000
Const SEC_COMMIT = &h8000000
Const SEC_NOCACHE = &h10000000
Const SEC_WRITECOMBINE = &h40000000
Const SEC_LARGE_PAGES = &h80000000
Const MEM_IMAGE = SEC_IMAGE
Const WRITE_WATCH_FLAG_RESET = &h01

' Define access rights to files and directories
Const FILE_READ_DATA = &h0001                 ' file & pipe
Const FILE_LIST_DIRECTORY = &h0001            ' directory

Const FILE_WRITE_DATA = &h0002                ' file & pipe
Const FILE_ADD_FILE = &h0002                  ' directory

Const FILE_APPEND_DATA = &h0004               ' file
Const FILE_ADD_SUBDIRECTORY = &h0004          ' directory
Const FILE_CREATE_PIPE_INSTANCE = &h0004      ' named pipe


Const FILE_READ_EA = &h0008                   ' file & directory

Const FILE_WRITE_EA = &h0010                  ' file & directory

Const FILE_EXECUTE = &h0020                   ' file
Const FILE_TRAVERSE = &h0020                  ' directory

Const FILE_DELETE_CHILD = &h0040              ' directory

Const FILE_READ_ATTRIBUTES = &h0080           ' all

Const FILE_WRITE_ATTRIBUTES = &h0100          ' all

Const FILE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &h1FF)
Const FILE_GENERIC_READ = (STANDARD_RIGHTS_READ Or FILE_READ_DATA Or FILE_READ_ATTRIBUTES Or FILE_READ_EA Or SYNCHRONIZE)
Const FILE_GENERIC_WRITE = (STANDARD_RIGHTS_WRITE Or FILE_WRITE_DATA Or FILE_WRITE_ATTRIBUTES Or FILE_WRITE_EA Or FILE_APPEND_DATA Or SYNCHRONIZE)
Const FILE_GENERIC_EXECUTE = (STANDARD_RIGHTS_EXECUTE Or FILE_READ_ATTRIBUTES Or FILE_EXECUTE Or SYNCHRONIZE)

Const FILE_SHARE_READ = &h00000001
Const FILE_SHARE_WRITE = &h00000002
Const FILE_SHARE_DELETE = &h00000004
Const FILE_ATTRIBUTE_READONLY = &h00000001
Const FILE_ATTRIBUTE_HIDDEN = &h00000002
Const FILE_ATTRIBUTE_SYSTEM = &h00000004
Const FILE_ATTRIBUTE_DIRECTORY = &h00000010
Const FILE_ATTRIBUTE_ARCHIVE = &h00000020
Const FILE_ATTRIBUTE_DEVICE = &h00000040
Const FILE_ATTRIBUTE_NORMAL = &h00000080
Const FILE_ATTRIBUTE_TEMPORARY = &h00000100
Const FILE_ATTRIBUTE_SPARSE_FILE = &h00000200
Const FILE_ATTRIBUTE_REPARSE_POINT = &h00000400
Const FILE_ATTRIBUTE_COMPRESSED = &h00000800
Const FILE_ATTRIBUTE_OFFLINE = &h00001000
Const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = &h00002000
Const FILE_ATTRIBUTE_ENCRYPTED = &h00004000
Const FILE_ATTRIBUTE_VIRTUAL = &h00010000
Const FILE_NOTIFY_CHANGE_FILE_NAME = &h00000001
Const FILE_NOTIFY_CHANGE_DIR_NAME = &h00000002
Const FILE_NOTIFY_CHANGE_ATTRIBUTES = &h00000004
Const FILE_NOTIFY_CHANGE_SIZE = &h00000008
Const FILE_NOTIFY_CHANGE_LAST_WRITE = &h00000010
Const FILE_NOTIFY_CHANGE_LAST_ACCESS = &h00000020
Const FILE_NOTIFY_CHANGE_CREATION = &h00000040
Const FILE_NOTIFY_CHANGE_SECURITY = &h00000100
Const FILE_ACTION_ADDED = &h00000001
Const FILE_ACTION_REMOVED = &h00000002
Const FILE_ACTION_MODIFIED = &h00000003
Const FILE_ACTION_RENAMED_OLD_NAME = &h00000004
Const FILE_ACTION_RENAMED_NEW_NAME = &h00000005
Const MAILSLOT_NO_MESSAGE = (-1 As DWord)
Const MAILSLOT_WAIT_FOREVER = (-1 As DWord)
Const FILE_CASE_SENSITIVE_SEARCH = &h00000001
Const FILE_CASE_PRESERVED_NAMES = &h00000002
Const FILE_UNICODE_ON_DISK = &h00000004
Const FILE_PERSISTENT_ACLS = &h00000008
Const FILE_FILE_COMPRESSION = &h00000010
Const FILE_VOLUME_QUOTAS = &h00000020
Const FILE_SUPPORTS_SPARSE_FILES = &h00000040
Const FILE_SUPPORTS_REPARSE_POINTS = &h00000080
Const FILE_SUPPORTS_REMOTE_STORAGE = &h00000100
Const FILE_VOLUME_IS_COMPRESSED = &h00008000
Const FILE_SUPPORTS_OBJECT_IDS = &h00010000
Const FILE_SUPPORTS_ENCRYPTION = &h00020000
Const FILE_NAMED_STREAMS = &h00040000
Const FILE_READ_ONLY_VOLUME = &h00080000
Const FILE_SEQUENTIAL_WRITE_ONCE = &h00100000
Const FILE_SUPPORTS_TRANSACTIONS = &h00200000

Type FILE_NOTIFY_INFORMATION
	NextEntryOffset As DWord
	Action As DWord
	FileNameLength As DWord
	FileName[ELM(1)] As WCHAR
End Type
TypeDef PFILE_NOTIFY_INFORMATION = *FILE_NOTIFY_INFORMATION

Type /*Union*/ FILE_SEGMENT_ELEMENT
	Buffer As PVOID64
'	Alignment As QWord
End Type 'Union
TypeDef PFILE_SEGMENT_ELEMENT = *FILE_SEGMENT_ELEMENT

Type REPARSE_GUID_DATA_BUFFER
	ReparseTag As DWord
	ReparseDataLength As Word
	Reserved As Word
	ReparseGuid As GUID
'	struct {
		DataBuffer[ELM(1)] As Byte
'	} GenericReparseBuffer;
End Type
TypeDef PREPARSE_GUID_DATA_BUFFER = *REPARSE_GUID_DATA_BUFFER

'Const REPARSE_GUID_DATA_BUFFER_HEADER_SIZE = FIELD_OFFSET(REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer)

' Maximum allowed size of the reparse data.
Const MAXIMUM_REPARSE_DATA_BUFFER_SIZE = (16 * 1024)

' Predefined reparse tags.
Const IO_REPARSE_TAG_RESERVED_ZERO = 0
Const IO_REPARSE_TAG_RESERVED_ONE = 1

Const IO_REPARSE_TAG_RESERVED_RANGE = IO_REPARSE_TAG_RESERVED_ONE


Const IsReparseTagMicrosoft(_tag) = ((_tag) And &h80000000)
Const IsReparseTagNameSurrogate(_tag) = ((_tag) And &h0000000)

Const IO_REPARSE_TAG_MOUNT_POINT = &hA0000003
Const IO_REPARSE_TAG_HSM = &hC0000004
Const IO_REPARSE_TAG_SIS = &h80000007
Const IO_REPARSE_TAG_DFS = &h8000000A
Const IO_REPARSE_TAG_SYMLINK = &hA000000C
Const IO_REPARSE_TAG_DFSR = &h80000012

Const IO_COMPLETION_MODIFY_STATE = &h0002
Const IO_COMPLETION_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &h3)

Const DUPLICATE_CLOSE_SOURCE = &h00000001
Const DUPLICATE_SAME_ACCESS = &h00000002
/*
' Define GUIDs which represent well-known power schemes

DEFINE_GUID( GUID_MAX_POWER_SAVINGS, 0xA1841308, 0x3541, 0x4FAB, 0xBC, 0x81, 0xF7, 0x15, 0x56, 0xF2, 0x0B, 0x4A );
DEFINE_GUID( GUID_MIN_POWER_SAVINGS, 0x8C5E7FDA, 0xE8BF, 0x4A96, 0x9A, 0x85, 0xA6, 0xE2, 0x3A, 0x8C, 0x63, 0x5C );
DEFINE_GUID( GUID_TYPICAL_POWER_SAVINGS, 0x381B4222, 0xF694, 0x41F0, 0x96, 0x85, 0xFF, 0x5B, 0xB2, 0x60, 0xDF, 0x2E );
DEFINE_GUID( NO_SUBGROUP_GUID, 0xFEA3413E, 0x7E05, 0x4911, 0x9A, 0x71, 0x70, 0x03, 0x31, 0xF1, 0xC2, 0x94 );
DEFINE_GUID( ALL_POWERSCHEMES_GUID, 0x68A1E95E, 0x13EA, 0x41E1, 0x80, 0x11, 0x0C, 0x49, 0x6C, 0xA4, 0x90, 0xB0 );
DEFINE_GUID( GUID_POWERSCHEME_PERSONALITY, 0x245D8541, 0x3943, 0x4422, 0xB0, 0x25, 0x13, 0xA7, 0x84, 0xF6, 0x79, 0xB7 );
DEFINE_GUID( GUID_ACTIVE_POWERSCHEME, 0x31F9F286, 0x5084, 0x42FE, 0xB7, 0x20, 0x2B, 0x02, 0x64, 0x99, 0x37, 0x63 );

' Define GUIDs which represent well-known power settings

' Video settings

DEFINE_GUID( GUID_VIDEO_SUBGROUP, 0x7516B95F, 0xF776, 0x4464, 0x8C, 0x53, 0x06, 0x16, 0x7F, 0x40, 0xCC, 0x99 );
DEFINE_GUID( GUID_VIDEO_POWERDOWN_TIMEOUT, 0x3C0BC021, 0xC8A8, 0x4E07, 0xA9, 0x73, 0x6B, 0x14, 0xCB, 0xCB, 0x2B, 0x7E );
DEFINE_GUID( GUID_VIDEO_ADAPTIVE_POWERDOWN, 0x90959D22, 0xD6A1, 0x49B9, 0xAF, 0x93, 0xBC, 0xE8, 0x85, 0xAD, 0x33, 0x5B );
DEFINE_GUID( GUID_MONITOR_POWER_ON, 0x02731015, 0x4510, 0x4526, 0x99, 0xE6, 0xE5, 0xA1, 0x7E, 0xBD, 0x1A, 0xEA );

' Harddisk settings
DEFINE_GUID( GUID_DISK_SUBGROUP, 0x0012EE47, 0x9041, 0x4B5D, 0x9B, 0x77, 0x53, 0x5F, 0xBA, 0x8B, 0x14, 0x42 );
DEFINE_GUID( GUID_DISK_POWERDOWN_TIMEOUT, 0x6738E2C4, 0xE8A5, 0x4A42, 0xB1, 0x6A, 0xE0, 0x40, 0xE7, 0x69, 0x75, 0x6E );
DEFINE_GUID( GUID_DISK_ADAPTIVE_POWERDOWN, 0x396A32E1, 0x499A, 0x40B2, 0x91, 0x24, 0xA9, 0x6A, 0xFE, 0x70, 0x76, 0x67 );

' System sleep settings
DEFINE_GUID( GUID_SLEEP_SUBGROUP, 0x238C9FA8, 0x0AAD, 0x41ED, 0x83, 0xF4, 0x97, 0xBE, 0x24, 0x2C, 0x8F, 0x20 );
DEFINE_GUID( GUID_SLEEP_IDLE_THRESHOLD, 0x81cd32e0, 0x7833, 0x44f3, 0x87, 0x37, 0x70, 0x81, 0xf3, 0x8d, 0x1f, 0x70 );
DEFINE_GUID( GUID_STANDBY_TIMEOUT, 0x29F6C1DB, 0x86DA, 0x48C5, 0x9F, 0xDB, 0xF2, 0xB6, 0x7B, 0x1F, 0x44, 0xDA );
DEFINE_GUID( GUID_HIBERNATE_TIMEOUT, 0x9D7815A6, 0x7EE4, 0x497E, 0x88, 0x88, 0x51, 0x5A, 0x05, 0xF0, 0x23, 0x64 );
DEFINE_GUID( GUID_HIBERNATE_FASTS4_POLICY, 0x94AC6D29, 0x73CE, 0x41A6, 0x80, 0x9F, 0x63, 0x63, 0xBA, 0x21, 0xB4, 0x7E );
DEFINE_GUID( GUID_CRITICAL_POWER_TRANSITION,  0xB7A27025, 0xE569, 0x46c2, 0xA5, 0x04, 0x2B, 0x96, 0xCA, 0xD2, 0x25, 0xA1);
DEFINE_GUID( GUID_SYSTEM_AWAYMODE, 0x98A7F580, 0x01F7, 0x48AA, 0x9C, 0x0F, 0x44, 0x35, 0x2C, 0x29, 0xE5, 0xC0 );
DEFINE_GUID( GUID_ALLOW_AWAYMODE, 0x25dfa149, 0x5dd1, 0x4736, 0xb5, 0xab, 0xe8, 0xa3, 0x7b, 0x5b, 0x81, 0x87 );
DEFINE_GUID( GUID_ALLOW_STANDBY_STATES, 0xabfc2519, 0x3608, 0x4c2a, 0x94, 0xea, 0x17, 0x1b, 0x0e, 0xd5, 0x46, 0xab );
DEFINE_GUID( GUID_ALLOW_RTC_WAKE, 0xBD3B718A, 0x0680, 0x4D9D, 0x8A, 0xB2, 0xE1, 0xD2, 0xB4, 0xAC, 0x80, 0x6D );

' System button actions
DEFINE_GUID( GUID_SYSTEM_BUTTON_SUBGROUP, 0x4F971E89, 0xEEBD, 0x4455, 0xA8, 0xDE, 0x9E, 0x59, 0x04, 0x0E, 0x73, 0x47 );
DEFINE_GUID( GUID_POWERBUTTON_ACTION, 0x7648EFA3, 0xDD9C, 0x4E3E, 0xB5, 0x66, 0x50, 0xF9, 0x29, 0x38, 0x62, 0x80 );
DEFINE_GUID( GUID_POWERBUTTON_ACTION_FLAGS, 0x857E7FAC, 0x034B, 0x4704, 0xAB, 0xB1, 0xBC, 0xA5, 0x4A, 0xA3, 0x14, 0x78 );
DEFINE_GUID( GUID_SLEEPBUTTON_ACTION, 0x96996BC0, 0xAD50, 0x47EC, 0x92, 0x3B, 0x6F, 0x41, 0x87, 0x4D, 0xD9, 0xEB );
DEFINE_GUID( GUID_SLEEPBUTTON_ACTION_FLAGS, 0x2A160AB1, 0xB69D, 0x4743, 0xB7, 0x18, 0xBF, 0x14, 0x41, 0xD5, 0xE4, 0x93 );
DEFINE_GUID( GUID_USERINTERFACEBUTTON_ACTION, 0xA7066653, 0x8D6C, 0x40A8, 0x91, 0x0E, 0xA1, 0xF5, 0x4B, 0x84, 0xC7, 0xE5 );
DEFINE_GUID( GUID_LIDCLOSE_ACTION, 0x5CA83367, 0x6E45, 0x459F, 0xA2, 0x7B, 0x47, 0x6B, 0x1D, 0x01, 0xC9, 0x36 );
DEFINE_GUID( GUID_LIDCLOSE_ACTION_FLAGS, 0x97E969AC, 0x0D6C, 0x4D08, 0x92, 0x7C, 0xD7, 0xBD, 0x7A, 0xD7, 0x85, 0x7B );
DEFINE_GUID( GUID_LIDOPEN_POWERSTATE, 0x99FF10E7, 0x23B1, 0x4C07, 0xA9, 0xD1, 0x5C, 0x32, 0x06, 0xD7, 0x41, 0xB4 );

' Battery Discharge Settings
DEFINE_GUID( GUID_BATTERY_SUBGROUP, 0xE73A048D, 0xBF27, 0x4F12, 0x97, 0x31, 0x8B, 0x20, 0x76, 0xE8, 0x89, 0x1F );
' 4 battery discharge alarm settings.
DEFINE_GUID( GUID_BATTERY_DISCHARGE_ACTION_0, 0x637EA02F, 0xBBCB, 0x4015, 0x8E, 0x2C, 0xA1, 0xC7, 0xB9, 0xC0, 0xB5, 0x46 );
DEFINE_GUID( GUID_BATTERY_DISCHARGE_LEVEL_0, 0x9A66D8D7, 0x4FF7, 0x4EF9, 0xB5, 0xA2, 0x5A, 0x32, 0x6C, 0xA2, 0xA4, 0x69 );
DEFINE_GUID( GUID_BATTERY_DISCHARGE_FLAGS_0, 0x5dbb7c9f, 0x38e9, 0x40d2, 0x97, 0x49, 0x4f, 0x8a, 0x0e, 0x9f, 0x64, 0x0f );

DEFINE_GUID( GUID_BATTERY_DISCHARGE_ACTION_1, 0xD8742DCB, 0x3E6A, 0x4B3C, 0xB3, 0xFE, 0x37, 0x46, 0x23, 0xCD, 0xCF, 0x06 );
DEFINE_GUID( GUID_BATTERY_DISCHARGE_LEVEL_1, 0x8183BA9A, 0xE910, 0x48DA, 0x87, 0x69, 0x14, 0xAE, 0x6D, 0xC1, 0x17, 0x0A );
DEFINE_GUID( GUID_BATTERY_DISCHARGE_FLAGS_1, 0xbcded951, 0x187b, 0x4d05, 0xbc, 0xcc, 0xf7, 0xe5, 0x19, 0x60, 0xc2, 0x58 );

DEFINE_GUID( GUID_BATTERY_DISCHARGE_ACTION_2, 0x421CBA38, 0x1A8E, 0x4881, 0xAC, 0x89, 0xE3, 0x3A, 0x8B, 0x04, 0xEC, 0xE4 );
DEFINE_GUID( GUID_BATTERY_DISCHARGE_LEVEL_2, 0x07A07CA2, 0xADAF, 0x40D7, 0xB0, 0x77, 0x53, 0x3A, 0xAD, 0xED, 0x1B, 0xFA );
DEFINE_GUID( GUID_BATTERY_DISCHARGE_FLAGS_2, 0x7fd2f0c4, 0xfeb7, 0x4da3, 0x81, 0x17, 0xe3, 0xfb, 0xed, 0xc4, 0x65, 0x82 );

DEFINE_GUID( GUID_BATTERY_DISCHARGE_ACTION_3, 0x80472613, 0x9780, 0x455E, 0xB3, 0x08, 0x72, 0xD3, 0x00, 0x3C, 0xF2, 0xF8 );
DEFINE_GUID( GUID_BATTERY_DISCHARGE_LEVEL_3, 0x58AFD5A6, 0xC2DD, 0x47D2, 0x9F, 0xBF, 0xEF, 0x70, 0xCC, 0x5C, 0x59, 0x65 );
DEFINE_GUID( GUID_BATTERY_DISCHARGE_FLAGS_3, 0x73613ccf, 0xdbfa, 0x4279, 0x83, 0x56, 0x49, 0x35, 0xf6, 0xbf, 0x62, 0xf3 );

' Processor power settings
DEFINE_GUID( GUID_PROCESSOR_SETTINGS_SUBGROUP, 0x54533251, 0x82BE, 0x4824, 0x96, 0xC1, 0x47, 0xB6, 0x0B, 0x74, 0x0D, 0x00 );
DEFINE_GUID( GUID_PROCESSOR_THROTTLE_POLICY, 0x57027304, 0x4AF6, 0x4104, 0x92, 0x60, 0xE3, 0xD9, 0x52, 0x48, 0xFC, 0x36 );
DEFINE_GUID( GUID_PROCESSOR_THROTTLE_MAXIMUM, 0xBC5038F7, 0x23E0, 0x4960, 0x96, 0xDA, 0x33, 0xAB, 0xAF, 0x59, 0x35, 0xEC );
DEFINE_GUID( GUID_PROCESSOR_THROTTLE_MINIMUM, 0x893DEE8E, 0x2BEF, 0x41E0, 0x89, 0xC6, 0xB5, 0x5D, 0x09, 0x29, 0x96, 0x4C );
DEFINE_GUID( GUID_PROCESSOR_IDLESTATE_POLICY, 0x68f262a7, 0xf621, 0x4069, 0xb9, 0xa5, 0x48, 0x74, 0x16, 0x9b, 0xe2, 0x3c);
DEFINE_GUID( GUID_PROCESSOR_PERFSTATE_POLICY, 0xBBDC3814, 0x18E9, 0x4463, 0x8A, 0x55, 0xD1, 0x97, 0x32, 0x7C, 0x45, 0xC0);
DEFINE_GUID( GUID_SYSTEM_COOLING_POLICY, 0x94D3A615, 0xA899, 0x4AC5, 0xAE, 0x2B, 0xE4, 0xD8, 0xF6, 0x34, 0x36, 0x7F);

' Lock Console on Wake
DEFINE_GUID( GUID_LOCK_CONSOLE_ON_WAKE, 0x0E796BDB, 0x100D, 0x47D6, 0xA2, 0xD5, 0xF7, 0xD2, 0xDA, 0xA5, 0x1F, 0x51 );

' AC/DC power source
DEFINE_GUID( GUID_ACDC_POWER_SOURCE, 0x5D3E9A59, 0xE9D5, 0x4B00, 0xA6, 0xBD, 0xFF, 0x34, 0xFF, 0x51, 0x65, 0x48 );

' Lid state changes
DEFINE_GUID( GUID_LIDSWITCH_STATE_CHANGE,  0xBA3E0F4D, 0xB817, 0x4094, 0xA2, 0xD1, 0xD5, 0x63, 0x79, 0xE6, 0xA0, 0xF3 );

' Battery life remaining
DEFINE_GUID( GUID_BATTERY_PERCENTAGE_REMAINING, 0xA7AD8041, 0xB45A, 0x4CAE, 0x87, 0xA3, 0xEE, 0xCB, 0xB4, 0x68, 0xA9, 0xE1 );
DEFINE_GUID( GUID_IDLE_BACKGROUND_TASK, 0x515C31D8, 0xF734, 0x163D, 0xA0, 0xFD, 0x11, 0xA0, 0x8C, 0x91, 0xE8, 0xF1 );
DEFINE_GUID( GUID_BACKGROUND_TASK_NOTIFICATION, 0xCF23F240, 0x2A54, 0x48D8, 0xB1, 0x14, 0xDE, 0x15, 0x18, 0xFF, 0x05, 0x2E );
DEFINE_GUID( GUID_APPLAUNCH_BUTTON, 0x1A689231, 0x7399, 0x4E9A, 0x8F, 0x99, 0xB7, 0x1F, 0x99, 0x9D, 0xB3, 0xFA );
DEFINE_GUID( GUID_PCIEXPRESS_SETTINGS_SUBGROUP, 0x501a4d13, 0x42af,0x4429, 0x9f, 0xd1, 0xa8, 0x21, 0x8c, 0x26, 0x8e, 0x20 );
DEFINE_GUID( GUID_PCIEXPRESS_ASPM_POLICY, 0xee12f906, 0xd277, 0x404b, 0xb6, 0xda, 0xe5, 0xfa, 0x1a, 0x57, 0x6d, 0xf5 );
*/
Enum SYSTEM_POWER_STATE
	PowerSystemUnspecified = 0
	PowerSystemWorking = 1
	PowerSystemSleeping1 = 2
	PowerSystemSleeping2 = 3
	PowerSystemSleeping3 = 4
	PowerSystemHibernate = 5
	PowerSystemShutdown = 6
	PowerSystemMaximum = 7
End Enum
TypeDef PSYSTEM_POWER_STATE = *SYSTEM_POWER_STATE

Const POWER_SYSTEM_MAXIMUM = 7

Enum POWER_ACTION
	PowerActionNone = 0
	PowerActionReserved
	PowerActionSleep
	PowerActionHibernate
	PowerActionShutdown
	PowerActionShutdownReset
	PowerActionShutdownOff
	PowerActionWarmEject
End Enum
TypeDef PPOWER_ACTION = *POWER_ACTION

Enum DEVICE_POWER_STATE
	PowerDeviceUnspecified = 0
	PowerDeviceD0
	PowerDeviceD1
	PowerDeviceD2
	PowerDeviceD3
	PowerDeviceMaximum
End Enum
TypeDef PDEVICE_POWER_STATE = *DEVICE_POWER_STATE

Const ES_SYSTEM_REQUIRED = (&h00000001 As DWord)
Const ES_DISPLAY_REQUIRED = (&h00000002 As DWord)
Const ES_USER_PRESENT = (&h00000004 As DWord)
Const ES_AWAYMODE_REQUIRED = (&h00000040 As DWord)
Const ES_CONTINUOUS = (&h80000000 As DWord)

TypeDef EXECUTION_STATE = DWord

Enum LATENCY_TIME
	LT_DONT_CARE
	LT_LOWEST_LATENCY
End Enum

'#if (NTDDI_VERSION >= NTDDI_WINXP)

' Device Power Information
Const PDCAP_D0_SUPPORTED = &h00000001
Const PDCAP_D1_SUPPORTED = &h00000002
Const PDCAP_D2_SUPPORTED = &h00000004
Const PDCAP_D3_SUPPORTED = &h00000008
Const PDCAP_WAKE_FROM_D0_SUPPORTED = &h00000010
Const PDCAP_WAKE_FROM_D1_SUPPORTED = &h00000020
Const PDCAP_WAKE_FROM_D2_SUPPORTED = &h00000040
Const PDCAP_WAKE_FROM_D3_SUPPORTED = &h00000080
Const PDCAP_WARM_EJECT_SUPPORTED = &h00000100

Type CM_POWER_DATA
	PD_Size As DWord
	PD_MostRecentPowerState As DEVICE_POWER_STATE
	PD_Capabilities As DWord
	PD_D1Latency As DWord
	PD_D2Latency As DWord
	PD_D3Latency As DWord
	PD_PowerStateMapping[POWER_SYSTEM_MAXIMUM] As DEVICE_POWER_STATE
	PD_DeepestSystemWake As SYSTEM_POWER_STATE
End Type
TypeDef PCM_POWER_DATA = *CM_POWER_DATA

'#endif // (NTDDI_VERSION >= NTDDI_WINXP)

Enum POWER_INFORMATION_LEVEL
	SystemPowerPolicyAc
	SystemPowerPolicyDc
	VerifySystemPolicyAc
	VerifySystemPolicyDc
	SystemPowerCapabilities
	SystemBatteryState
	SystemPowerStateHandler
	ProcessorStateHandler
	SystemPowerPolicyCurrent
	AdministratorPowerPolicy
	SystemReserveHiberFile
	ProcessorInformation
	SystemPowerInformation
	ProcessorStateHandler2
	LastWakeTime                        ' Compare with KeQueryInterruptTime()
	LastSleepTime                       ' Compare with KeQueryInterruptTime()
	SystemExecutionState
	SystemPowerStateNotifyHandler
	ProcessorPowerPolicyAc
	ProcessorPowerPolicyDc
	VerifyProcessorPowerPolicyAc
	VerifyProcessorPowerPolicyDc
	ProcessorPowerPolicyCurrent
	SystemPowerStateLogging
	SystemPowerLoggingEntry
	SetPowerSettingValue
	NotifyUserPowerSetting
	GetPowerTransitionVetoes
	SetPowerTransitionVeto
	SystemVideoState
	TraceApplicationPowerMessage
	TraceApplicationPowerMessageEnd
	ProcessorPerfStates
	ProcessorIdleStates
	ProcessorThrottleStates
	SystemWakeSource
	SystemHiberFileInformation
	TraceServicePowerMessage
	ProcessorLoad
	PowerShutdownNotification
End Enum

' Power Transition Vetos
Const PO_TRANSITION_VETO_TYPE_WINDOW = &h00000001
Const PO_TRANSITION_VETO_TYPE_SERVICE = &h00000002
'Const PO_TRANSITION_VETO_TYPE_DRIVER = &h00000004

Const PO_TRANSITION_VETO_TYPE_ALL = (PO_TRANSITION_VETO_TYPE_WINDOW Or PO_TRANSITION_VETO_TYPE_SERVICE)

Type PO_TRANSITION_VETO_REASON
	ResourceId As DWord
	ModuleNameOffset As DWord
End Type
TypeDef PPO_TRANSITION_VETO_REASON = *PO_TRANSITION_VETO_REASON

Type PO_TRANSITION_VETO_WINDOW
	Handle As HANDLE
End Type
TypeDef PPO_TRANSITION_VETO_WINDOW = *PO_TRANSITION_VETO_WINDOW

Type PO_TRANSITION_VETO_SERVICE
	ServiceNameOffset As DWord
End Type
TypeDef PPO_TRANSITION_VETO_SERVICE = *PO_TRANSITION_VETO_SERVICE

/*
Type PO_TRANSITION_VETO_DRIVER
	InstancePathOffset As DWord
	DriverNameOffset As DWord
End Type
TypeDef PPO_TRANSITION_VETO_DRIVER = *PO_TRANSITION_VETO_DRIVER
*/

Type PO_TRANSITION_VETO
	Type_ As DWord
	Reason As PO_TRANSITION_VETO_REASON
	ProcessId As DWord
'	Union
		Window_ As PO_TRANSITION_VETO_WINDOW
'		Service As PO_TRANSITION_VETO_SERVICE
'		' Driver As PO_TRANSITION_VETO_DRIVER
'	End Union
End Type
TypeDef PPO_TRANSITION_VETO = *PO_TRANSITION_VETO

Type PO_TRANSITION_VETOES
	Count As DWord
	Vetoes[ELM(ANYSIZE_ARRAY)] As PO_TRANSITION_VETO
End Type
TypeDef PPO_TRANSITION_VETOES = *PO_TRANSITION_VETOES

Enum SYSTEM_POWER_CONDITION
	PoAc
	PoDc
	PoHot
	PoConditionMaximum
End Enum

Type SET_POWER_SETTING_VALUE
	Version As DWord
	Guid As GUID
	PowerCondition As SYSTEM_POWER_CONDITION
	DataLength As DWord
	Data[ELM(ANYSIZE_ARRAY)] As Byte
End Type
TypeDef PSET_POWER_SETTING_VALUE = *SET_POWER_SETTING_VALUE

Const POWER_SETTING_VALUE_VERSION = &h1

Type NOTIFY_USER_POWER_SETTING
	Guid As GUID
End Type
TypeDef PNOTIFY_USER_POWER_SETTING = *NOTIFY_USER_POWER_SETTING

Type APPLICATIONLAUNCH_SETTING_VALUE
	ActivationTime As LARGE_INTEGER
	Flags As DWord
	ButtonInstanceID As DWord
End Type
TypeDef PAPPLICATIONLAUNCH_SETTING_VALUE = *APPLICATIONLAUNCH_SETTING_VALUE

Enum POWER_PLATFORM_ROLE
	PlatformRoleUnspecified = 0
	PlatformRoleDesktop
	PlatformRoleMobile
	PlatformRoleWorkstation
	PlatformRoleEnterpriseServer
	PlatformRoleSOHOServer
	PlatformRoleAppliancePC
	PlatformRolePerformanceServer
	PlatformRoleMaximum
End Enum

Enum PO_WAKE_SOURCE_TYPE
	DeviceWakeSourceType
	FixedWakeSourceType
End Enum
TypeDef PPO_WAKE_SOURCE_TYPE = *PO_WAKE_SOURCE_TYPE

Enum PO_FIXED_WAKE_SOURCE_TYPE
	FixedWakeSourcePowerButton
	FixedWakeSourceSleepButton
	FixedWakeSourceRtc
End Enum
TypeDef PPO_FIXED_WAKE_SOURCE_TYPE = *PO_FIXED_WAKE_SOURCE_TYPE

Type PO_WAKE_SOURCE_HEADER
	Type_ As PO_WAKE_SOURCE_TYPE
	Size As DWord
End Type
TypeDef PPO_WAKE_SOURCE_HEADER = *PO_WAKE_SOURCE_HEADER

Type PO_WAKE_SOURCE_DEVICE
	Header As PO_WAKE_SOURCE_HEADER
	InstancePath[ELM(ANYSIZE_ARRAY)] As WCHAR
End Type
TypeDef PPO_WAKE_SOURCE_DEVICE = *PO_WAKE_SOURCE_DEVICE

Type PO_WAKE_SOURCE_FIXED
	Header As PO_WAKE_SOURCE_HEADER
	FixedWakeSourceType As PO_FIXED_WAKE_SOURCE_TYPE
End Type
TypeDef PPO_WAKE_SOURCE_FIXED = *PO_WAKE_SOURCE_FIXED

Type PO_WAKE_SOURCE_INFO
	Count As DWord
	Offsets[ELM(ANYSIZE_ARRAY)] As DWord
End Type
TypeDef PPO_WAKE_SOURCE_INFO = *PO_WAKE_SOURCE_INFO

Type PO_WAKE_SOURCE_HISTORY
	Count As DWord
	Offsets[ELM(ANYSIZE_ARRAY)] As DWord
End Type
TypeDef PPO_WAKE_SOURCE_HISTORY = *PO_WAKE_SOURCE_HISTORY

'#if (NTDDI_VERSION >= NTDDI_WINXP) || !defined(_BATCLASS_)
Type BATTERY_REPORTING_SCALE
	Granularity As DWord
	Capacity As DWord
End Type
TypeDef PBATTERY_REPORTING_SCALE = *BATTERY_REPORTING_SCALE
'#endif

Type PPM_SIMULATED_PROCESSOR_LOAD
	Enabled As BOOLEAN
	PercentBusy[ELM(MAXIMUM_PROCESSORS)] As Byte
End Type
TypeDef PPPM_SIMULATED_PROCESSOR_LOAD = *PPM_SIMULATED_PROCESSOR_LOAD

Type PPM_WMI_LEGACY_PERFSTATE
	Frequency As DWord
	Flags As DWord
	PercentFrequency As DWord
End Type
TypeDef PPPM_WMI_LEGACY_PERFSTATE = *PPM_WMI_LEGACY_PERFSTATE

Type PPM_WMI_IDLE_STATE
	Latency As DWord
	Power As DWord
	TimeCheck As DWord
	PromotePercent As Byte
	DemotePercent As Byte
	StateType As Byte
	Reserved As Byte
	StateFlags As DWord
	Context As DWord
	IdleHandler As DWord
	Reserved1 As DWord
End Type
TypeDef PPPM_WMI_IDLE_STATE = *PPM_WMI_IDLE_STATE

Type PPM_WMI_IDLE_STATES
	Type_ As DWord
	Count As DWord
	TargetState As DWord
	OldState As DWord
	TargetProcessors As QWord
	State[ELM(ANYSIZE_ARRAY)] As PPM_WMI_IDLE_STATE
End Type
TypeDef PPPM_WMI_IDLE_STATES = *PPM_WMI_IDLE_STATES

Type PPM_WMI_PERF_STATE
	Frequency As DWord
	Power As DWord
	PercentFrequency As Byte
	IncreaseLevel As Byte
	DecreaseLevel As Byte
	Type_  As Byte
	IncreaseTime As DWord
	DecreaseTime As DWord
	Control As QWord
	Status As QWord
	HitCount As DWord
	Reserved1 As DWord
	Reserved2 As QWord
	Reserved3 As QWord
End Type
TypeDef PPPM_WMI_PERF_STATE = *PPM_WMI_PERF_STATE

Type PPM_WMI_PERF_STATES
	Count As DWord
	MaxFrequency As DWord
	CurrentState As DWord
	MaxPerfState As DWord
	MinPerfState As DWord
	LowestPerfState As DWord
	ThermalConstraint As DWord
	BusyAdjThreshold As Byte
	PolicyType As Byte
	Type_ As Byte
	Reserved As Byte
	TimerInterval As DWord
	TargetProcessors As QWord
	PStateHandler As DWord
	PStateContext As DWord
	TStateHandler As DWord
	TStateContext As DWord
	FeedbackHandler As DWord
	Reserved1 As DWord
	Reserved2 As QWord
	State[ELM(ANYSIZE_ARRAY)] As PPM_WMI_PERF_STATE
End Type
TypeDef PPPM_WMI_PERF_STATES = *PPM_WMI_PERF_STATES

Const PROC_IDLE_BUCKET_COUNT = 6

Type PPM_IDLE_STATE_ACCOUNTING
	IdleTransitions As DWord
	FailedTransitions As DWord
	InvalidBucketIndex As DWord
	TotalTime As QWord
	IdleTimeBuckets[ELM(PROC_IDLE_BUCKET_COUNT)] As DWord
End Type
TypeDef PPPM_IDLE_STATE_ACCOUNTING = *PPM_IDLE_STATE_ACCOUNTING

Type PPM_IDLE_ACCOUNTING
	StateCount As DWord
	TotalTransitions As DWord
	ResetCount As DWord
	StartTime As QWord
	State[ELM(ANYSIZE_ARRAY)] As PPM_IDLE_STATE_ACCOUNTING
End Type
TypeDef PPPM_IDLE_ACCOUNTING = *PPM_IDLE_ACCOUNTING

Const ACPI_PPM_SOFTWARE_ALL = &hFC
Const ACPI_PPM_SOFTWARE_ANY = &hFD
Const ACPI_PPM_HARDWARE_ALL = &hFE

Const MS_PPM_SOFTWARE_ALL = &h1

' Processor Power Management WMI interface.
/*
// {A5B32DDD-7F39-4abc-B892-900E43B59EBB}
DEFINE_GUID(PPM_PERFSTATE_CHANGE_GUID,
0xa5b32ddd, 0x7f39, 0x4abc, 0xb8, 0x92, 0x90, 0xe, 0x43, 0xb5, 0x9e, 0xbb);

// {995e6b7f-d653-497a-b978-36a30c29bf01}
DEFINE_GUID(PPM_PERFSTATE_DOMAIN_CHANGE_GUID,
0x995e6b7f, 0xd653, 0x497a, 0xb9, 0x78, 0x36, 0xa3, 0xc, 0x29, 0xbf, 0x1);

// {4838fe4f-f71c-4e51-9ecc-8430a7ac4c6c}
DEFINE_GUID(PPM_IDLESTATE_CHANGE_GUID,
0x4838fe4f, 0xf71c, 0x4e51, 0x9e, 0xcc, 0x84, 0x30, 0xa7, 0xac, 0x4c, 0x6c);

// {5708cc20-7d40-4bf4-b4aa-2b01338d0126}
DEFINE_GUID(PPM_PERFSTATES_DATA_GUID,
0x5708cc20, 0x7d40, 0x4bf4, 0xb4, 0xaa, 0x2b, 0x01, 0x33, 0x8d, 0x01, 0x26);

// {ba138e10-e250-4ad7-8616-cf1a7ad410e7}
DEFINE_GUID(PPM_IDLESTATES_DATA_GUID,
0xba138e10, 0xe250, 0x4ad7, 0x86, 0x16, 0xcf, 0x1a, 0x7a, 0xd4, 0x10, 0xe7);

// {e2a26f78-ae07-4ee0-a30f-ce354f5a94cd}
DEFINE_GUID(PPM_IDLE_ACCOUNTING_GUID,
0xe2a26f78, 0xae07, 0x4ee0, 0xa3, 0x0f, 0xce, 0x54, 0xf5, 0x5a, 0x94, 0xcd);

// {a852c2c8-1a4c-423b-8c2c-f30d82931a88}
DEFINE_GUID(PPM_THERMALCONSTRAINT_GUID,
0xa852c2c8, 0x1a4c, 0x423b, 0x8c, 0x2c, 0xf3, 0x0d, 0x82, 0x93, 0x1a, 0x88);

// {7fd18652-0cfe-40d2-b0a1-0b066a87759e}
DEFINE_GUID(PPM_PERFMON_PERFSTATE_GUID,
0x7fd18652, 0xcfe, 0x40d2, 0xb0, 0xa1, 0xb, 0x6, 0x6a, 0x87, 0x75, 0x9e);

// {48f377b8-6880-4c7b-8bdc-380176c6654d}
DEFINE_GUID(PPM_THERMAL_POLICY_CHANGE_GUID,
0x48f377b8, 0x6880, 0x4c7b, 0x8b, 0xdc, 0x38, 0x1, 0x76, 0xc6, 0x65, 0x4d);
*/
Type PPM_PERFSTATE_EVENT
	State As DWord
	Status As DWord
	Latency As DWord
	Speed As DWord
	Processor As DWord
End Type
TypeDef PPPM_PERFSTATE_EVENT = *PPM_PERFSTATE_EVENT

Type PPM_PERFSTATE_DOMAIN_EVENT
	State As DWord
	Latency As DWord
	Speed As DWord
	Processors As QWord
End Type
TypeDef PPPM_PERFSTATE_DOMAIN_EVENT = *PPM_PERFSTATE_DOMAIN_EVENT

Type PPM_IDLESTATE_EVENT
	NewState As DWord
	OldState As DWord
	Processors As QWord
End Type
TypeDef PPPM_IDLESTATE_EVENT = *PPM_IDLESTATE_EVENT

Type PPM_THERMALCHANGE_EVENT
	ThermalConstraint As DWord
	Processors As QWord
End Type
TypeDef PPPM_THERMALCHANGE_EVENT = *PPM_THERMALCHANGE_EVENT

Type PPM_THERMAL_POLICY_EVENT
	Mode As Byte
	Processors As QWord
End Type
TypeDef PPPM_THERMAL_POLICY_EVENT = *PPM_THERMAL_POLICY_EVENT

Type POWER_ACTION_POLICY
	Action As POWER_ACTION
	Flags As DWord
	EventCode As DWord
End Type
TypeDef PPOWER_ACTION_POLICY = *POWER_ACTION_POLICY

' POWER_ACTION_POLICY->Flags:
Const POWER_ACTION_QUERY_ALLOWED = &h00000001
Const POWER_ACTION_UI_ALLOWED = &h00000002
Const POWER_ACTION_OVERRIDE_APPS = &h00000004
Const POWER_ACTION_LIGHTEST_FIRST = &h10000000
Const POWER_ACTION_LOCK_CONSOLE = &h20000000
Const POWER_ACTION_DISABLE_WAKES = &h40000000
Const POWER_ACTION_CRITICAL = &h80000000

' POWER_ACTION_POLICY->EventCode flags
Const POWER_LEVEL_USER_NOTIFY_TEXT = &h00000001
Const POWER_LEVEL_USER_NOTIFY_SOUND = &h00000002
Const POWER_LEVEL_USER_NOTIFY_EXEC = &h00000004
Const POWER_USER_NOTIFY_BUTTON = &h00000008
Const POWER_USER_NOTIFY_SHUTDOWN = &h00000010
Const POWER_FORCE_TRIGGER_RESET = &h80000000

Const BATTERY_DISCHARGE_FLAGS_EVENTCODE_MASK = &h00000007
Const BATTERY_DISCHARGE_FLAGS_ENABLE = &h80000000

Type SYSTEM_POWER_LEVEL
	Enable As BOOLEAN
	Spare[ELM(3)] As Byte
	BatteryLevel As DWord
	PowerPolicy As POWER_ACTION_POLICY
	MinSystemState As POWER_ACTION_POLICY
End Type
TypeDef PSYSTEM_POWER_LEVEL = *SYSTEM_POWER_LEVEL

Const NUM_DISCHARGE_POLICIES = 4
Const DISCHARGE_POLICY_CRITICAL= 0
Const DISCHARGE_POLICY_LOW = 1

Type SYSTEM_POWER_POLICY
	Revision As DWord

	PowerButton As POWER_ACTION_POLICY
	SleepButton As POWER_ACTION_POLICY
	LidClose As POWER_ACTION_POLICY
	LidOpenWake As SYSTEM_POWER_STATE
	Reserved As DWord

	Idle As POWER_ACTION_POLICY
	IdleTimeout As DWord
	IdleSensitivity As Byte

	DynamicThrottle As Byte
	Spare2[ELM(2)] As Byte

	MinSleep As SYSTEM_POWER_STATE
	MaxSleep As SYSTEM_POWER_STATE
	ReducedLatencySleep As SYSTEM_POWER_STATE
	WinLogonFlags As DWord

	Spare3 As DWord

	DozeS4Timeout As DWord

	BroadcastCapacityResolution; As DWord
	DischargePolicy[ELM(NUM_DISCHARGE_POLICIES)] As SYSTEM_POWER_LEVEL

	VideoTimeout As DWord
	VideoDimDisplay As BOOLEAN
	VideoReserved[ELM(3)] As DWord

	SpindownTimeout As DWord

	OptimizeForPower As BOOLEAN
	FanThrottleTolerance As Byte
	ForcedThrottle As Byte
	MinThrottle As Byte
	OverThrottled As POWER_ACTION_POLICY
End Type
TypeDef PSYSTEM_POWER_POLICY = *SYSTEM_POWER_POLICY

' processor power policy state

Const PROCESSOR_IDLESTATE_POLICY_COUNT = &h3

Type PROCESSOR_IDLESTATE_INFO
	TimeCheck As DWord
	DemotePercent As Byte
	PromotePercent As Byte
	Spare[ELM(2)] As Byte
End Type
TypeDef PPROCESSOR_IDLESTATE_INFO = *PROCESSOR_IDLESTATE_INFO

Type PROCESSOR_IDLESTATE_POLICY
	Revision As Word
	FlagsAsWRORD As Word
'	Union
'		AsWORD As Word
'		struct {
'			WORD   AllowScaling : 1;
'			WORD   Disabled : 1;
'			WORD   Reserved : 14;
'		};
'	} Flags;

	PolicyCount As DWord
	Policy[ELM(PROCESSOR_IDLESTATE_POLICY_COUNT)] As PROCESSOR_IDLESTATE_INFO
End Type
TypeDef PPROCESSOR_IDLESTATE_POLICY = *PROCESSOR_IDLESTATE_POLICY

Const PO_THROTTLE_NONE = 0
Const PO_THROTTLE_CONSTANT = 1
Const PO_THROTTLE_DEGRADE = 2
Const PO_THROTTLE_ADAPTIVE = 3
Const PO_THROTTLE_MAXIMUM = 4

Type PROCESSOR_POWER_POLICY_INFO
	TimeCheck As DWord
	DemoteLimit As DWord
	PromoteLimit As DWord

	DemotePercent As Byte
	PromotePercent As Byte
	Spare[ELM(2)] As Byte
	Allow As DWord
'	AllowDemotion:1 As DWord
'	AllowPromotion:1 As DWord
'	Reserved:30 As DWord
End Type
TypeDef PPROCESSOR_POWER_POLICY_INFO = *PROCESSOR_POWER_POLICY_INFO

Type PROCESSOR_POWER_POLICY
	Revision As DWord

	DynamicThrottle As Byte
	Spare[ELM(3)] As Byte

	DisableCStates/*:1*/ As DWord
'	Reserved:31 As DWord

	PolicyCount As DWord
	Policy[ELM(3)] As PROCESSOR_POWER_POLICY_INFO
End Type
TypeDef PPROCESSOR_POWER_POLICY = *PROCESSOR_POWER_POLICY

' Processor Perf State Policy.
Const PERFSTATE_POLICY_CHANGE_IDEAL = &h00
Const PERFSTATE_POLICY_CHANGE_SINGLE = &h01
Const PERFSTATE_POLICY_CHANGE_ROCKET = &h02
Const PERFSTATE_POLICY_CHANGE_MAX = PERFSTATE_POLICY_CHANGE_ROCKET

Type PROCESSOR_PERFSTATE_POLICY '귺깋귽깛긽깛긣빟딠궔갎
	Revision As DWord
	MaxThrottle As Byte
	MinThrottle As Byte
	BusyAdjThreshold As Byte
	FlagsAsBYTE As Byte '돷궻떎뾭뫬긽깛긫궻븫빁
'	Union
'		Spare As Byte
'		Union
'			AsBYTE As Byte
'			Type
'				NoDomainAccounting : 1 As Byte
'				IncreasePolicy: 2 As Byte
'				DecreasePolicy: 2 As Byte
'				Reserved : 3 As Byte
'			End Type
'		} Flags;
'	};
	TimeCheck As DWord
	IncreaseTime As DWord
	DecreaseTime As DWord
	IncreasePercent As DWord
	DecreasePercent As DWord
End Type
TypeDef PPROCESSOR_PERFSTATE_POLICY = *PROCESSOR_PERFSTATE_POLICY

Type ADMINISTRATOR_POWER_POLICY
	MinSleep As SYSTEM_POWER_STATE
	MaxSleep As SYSTEM_POWER_STATE

	MinVideoTimeout As DWord
	MaxVideoTimeout As DWord

	MinSpindownTimeout As DWord
	MaxSpindownTimeout As DWord
End Type
TypeDef PADMINISTRATOR_POWER_POLICY = *ADMINISTRATOR_POWER_POLICY

Type SYSTEM_POWER_CAPABILITIES
	PowerButtonPresent As BOOLEAN
	SleepButtonPresent As BOOLEAN
	LidPresent As BOOLEAN
	SystemS1 As BOOLEAN
	SystemS2 As BOOLEAN
	SystemS3 As BOOLEAN
	SystemS4 As BOOLEAN
	SystemS5 As BOOLEAN
	HiberFilePresent As BOOLEAN
	FullWake As BOOLEAN
	VideoDimPresent As BOOLEAN
	ApmPresent As BOOLEAN
	UpsPresent As BOOLEAN

	ThermalControl As BOOLEAN
	ProcessorThrottle As BOOLEAN
	ProcessorMinThrottle As Byte

'#if (NTDDI_VERSION < NTDDI_WINXP)
'	ProcessorThrottleScale As Byte
'	spare2[ELM(4)] As Byte
'#else
	ProcessorMaxThrottle As Byte
	FastSystemS4 As BOOLEAN
	spare2[(3)] As Byte
'#endif // (NTDDI_VERSION < NTDDI_WINXP)

	DiskSpinDown As BOOLEAN
	spare3[ELM(8)] As Byte

	SystemBatteriesPresent As BOOLEAN
	BatteriesAreShortTerm As BOOLEAN
	BatteryScale[ELM(3)] As BATTERY_REPORTING_SCALE

	AcOnLineWake As SYSTEM_POWER_STATE
	SoftLidWake As SYSTEM_POWER_STATE
	RtcWake As SYSTEM_POWER_STATE
	MinDeviceWakeState As SYSTEM_POWER_STATE
	DefaultLowLatencyWake As SYSTEM_POWER_STATE
End Type
TypeDef PSYSTEM_POWER_CAPABILITIES = *SYSTEM_POWER_CAPABILITIES

Type SYSTEM_BATTERY_STATE
	AcOnLine As BOOLEAN
	BatteryPresent As BOOLEAN
	Charging As BOOLEAN
	Discharging As BOOLEAN
	Spare1[ELM(4)] As BOOLEAN

	MaxCapacity As DWord
	RemainingCapacity As DWord
	Rate As DWord
	EstimatedTime As DWord

	DefaultAlert1 As DWord
	DefaultAlert2 As DWord
End Type
TypeDef PSYSTEM_BATTERY_STATE = *SYSTEM_BATTERY_STATE

Const IMAGE_DOS_SIGNATURE = &h5A4D    ' MZ
Const IMAGE_OS2_SIGNATURE = &h454E    ' NE
Const IMAGE_OS2_SIGNATURE_LE = &h454C ' LE
Const IMAGE_VXD_SIGNATURE = &h454C    ' LE
Const IMAGE_NT_SIGNATURE = &h00004550 ' PE00

Type Align(2) IMAGE_DOS_HEADER          ' DOS .EXE header
	e_magic As Word                     ' Magic number
	e_cblp As Word                      ' Bytes on last page of file
	e_cp As Word                        ' Pages in file
	e_crlc As Word                      ' Relocations
	e_cparhdr As Word                   ' Size of header in paragraphs
	e_minalloc As Word                  ' Minimum extra paragraphs needed
	e_maxalloc As Word                  ' Maximum extra paragraphs needed
	e_ss As Word                        ' Initial (relative) SS value
	e_sp As Word                        ' Initial SP value
	e_csum As Word                      ' Checksum
	e_ip As Word                        ' Initial IP value
	e_cs As Word                        ' Initial (relative) CS value
	e_lfarlc As Word                    ' File address of relocation table
	e_ovno As Word                      ' Overlay number
	e_res[ELM(4)] As Word               ' Reserved words
	e_oemid As Word                     ' OEM identifier (for e_oeminfo)
	e_oeminfo As Word                   ' OEM information; e_oemid specific
	e_res2[ELM(10)] As Word             ' Reserved words
	e_lfanew As Long                    ' File address of new exe header
End Type
TypeDef PIMAGE_DOS_HEADER = *IMAGE_DOS_HEADER

Type Align(2) IMAGE_OS2_HEADER          ' OS/2 .EXE header
	ne_magic As Word                    ' Magic number
	ne_ver As CHAR                      ' Version number
	ne_rev As CHAR                      ' Revision number
	ne_enttab As Word                   ' Offset of Entry Table
	ne_cbenttab As Word                 ' Number of bytes in Entry Table
	ne_crc As Long                      ' Checksum of whole file
	ne_flags As Word                    ' Flag word
	ne_autodata As Word                 ' Automatic data segment number
	ne_heap As Word                     ' Initial heap allocation
	ne_stack As Word                    ' Initial stack allocation
	ne_csip As Long                     ' Initial CS:IP setting
	ne_sssp As Long                     ' Initial SS:SP setting
	ne_cseg As Word                     ' Count of file segments
	ne_cmod As Word                     ' Entries in Module Reference Table
	ne_cbnrestab As Word                ' Size of non-resident name table
	ne_segtab As Word                   ' Offset of Segment Table
	ne_rsrctab As Word                  ' Offset of Resource Table
	ne_restab As Word                   ' Offset of resident name table
	ne_modtab As Word                   ' Offset of Module Reference Table
	ne_imptab As Word                   ' Offset of Imported Names Table
	ne_nrestab As Long                  ' Offset of Non-resident Names Table
	ne_cmovent As Word                  ' Count of movable entries
	ne_align As Word                    ' Segment alignment shift count
	ne_cres As Word                     ' Count of resource segments
	ne_exetyp As Byte                   ' Target Operating system
	ne_flagsothers As Byte              ' Other .EXE flags
	ne_pretthunks As Word               ' offset to return thunks
	ne_psegrefbytes As Word             ' offset to segment ref. bytes
	ne_swaparea As Word                 ' Minimum code swap area size
	ne_expver As Word                   ' Expected Windows version number
End Type
TypeDef PIMAGE_OS2_HEADER = *IMAGE_OS2_HEADER

Type Align(2) IMAGE_VXD_HEADER          ' Windows VXD header
	e32_magic As Word                   ' Magic number
	e32_border As Byte                  ' The byte ordering for the VXD
	e32_worder As Byte                  ' The word ordering for the VXD
	e32_level As DWord                  ' The EXE format level for now = 0
	e32_cpu As Word                     ' The CPU type
	e32_os As Word                      ' The OS type
	e32_ver As DWord                    ' Module version
	e32_mflags As DWord                 ' Module flags
	e32_mpages As DWord                 ' Module # pages
	e32_startobj As DWord               ' Object # for instruction pointer
	e32_eip As DWord                    ' Extended instruction pointer
	e32_stackobj As DWord               ' Object # for stack pointer
	e32_esp As DWord                    ' Extended stack pointer
	e32_pagesize As DWord               ' VXD page size
	e32_lastpagesize As DWord           ' Last page size in VXD
	e32_fixupsize As DWord              ' Fixup section size
	e32_fixupsum As DWord               ' Fixup section checksum
	e32_ldrsize As DWord                ' Loader section size
	e32_ldrsum As DWord                 ' Loader section checksum
	e32_objtab As DWord                 ' Object table offset
	e32_objcnt As DWord                 ' Number of objects in module
	e32_objmap As DWord                 ' Object page map offset
	e32_itermap As DWord                ' Object iterated data map offset
	e32_rsrctab As DWord                ' Offset of Resource Table
	e32_rsrccnt As DWord                ' Number of resource entries
	e32_restab As DWord                 ' Offset of resident name table
	e32_enttab As DWord                 ' Offset of Entry Table
	e32_dirtab As DWord                 ' Offset of Module Directive Table
	e32_dircnt As DWord                 ' Number of module directives
	e32_fpagetab As DWord               ' Offset of Fixup Page Table
	e32_frectab As DWord                ' Offset of Fixup Record Table
	e32_impmod As DWord                 ' Offset of Import Module Name Table
	e32_impmodcnt As DWord              ' Number of entries in Import Module Name Table
	e32_impproc As DWord                ' Offset of Import Procedure Name Table
	e32_pagesum As DWord                ' Offset of Per-Page Checksum Table
	e32_datapage As DWord               ' Offset of Enumerated Data Pages
	e32_preload As DWord                ' Number of preload pages
	e32_nrestab As DWord                ' Offset of Non-resident Names Table
	e32_cbnrestab As DWord              ' Size of Non-resident Name Table
	e32_nressum As DWord                ' Non-resident Name Table Checksum
	e32_autodata As DWord               ' Object # for automatic data object
	e32_debuginfo As DWord              ' Offset of the debugging information
	e32_debuglen As DWord               ' The length of the debugging info. in bytes
	e32_instpreload As DWord            ' Number of instance pages in preload section of VXD file
	e32_instdemand As DWord             ' Number of instance pages in demand load section of VXD file
	e32_heapsize As DWord               ' Size of heap - for 16-bit apps
	e32_res3[ELM(12)] As Byte           ' Reserved words
	e32_winresoff As DWord
	e32_winreslen As DWord
	e32_devid As Word                   ' Device ID for VxD
	e32_ddkver As Word                  ' DDK version for VxD
End Type
TypeDef PIMAGE_VXD_HEADER = *IMAGE_VXD_HEADER

' File header format.
Type Align(4) IMAGE_FILE_HEADER
	Machine As Word
	NumberOfSections As Word
	TimeDateStamp As DWord
	PointerToSymbolTable As DWord
	NumberOfSymbols As DWord
	SizeOfOptionalHeader As Word
	Characteristics As Word
End Type
TypeDef PIMAGE_FILE_HEADER = *IMAGE_FILE_HEADER

Const IMAGE_SIZEOF_FILE_HEADER = 20

Const IMAGE_FILE_RELOCS_STRIPPED         = &h0001  ' Relocation info stripped from file.
Const IMAGE_FILE_EXECUTABLE_IMAGE        = &h0002  ' File is executable  (i.e. no unresolved externel references).
Const IMAGE_FILE_LINE_NUMS_STRIPPED      = &h0004  ' Line nunbers stripped from file.
Const IMAGE_FILE_LOCAL_SYMS_STRIPPED     = &h0008  ' Local symbols stripped from file.
Const IMAGE_FILE_AGGRESIVE_WS_TRIM       = &h0010  ' Agressively trim working set
Const IMAGE_FILE_LARGE_ADDRESS_AWARE     = &h0020  ' App can handle >2gb addresses
Const IMAGE_FILE_BYTES_REVERSED_LO       = &h0080  ' Bytes of machine word are reversed.
Const IMAGE_FILE_32BIT_MACHINE           = &h0100  ' 32 bit word machine.
Const IMAGE_FILE_DEBUG_STRIPPED          = &h0200  ' Debugging info stripped from file in .DBG file
Const IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = &h0400  ' If Image is on removable media, copy and run from the swap file.
Const IMAGE_FILE_NET_RUN_FROM_SWAP       = &h0800  ' If Image is on Net, copy and run from the swap file.
Const IMAGE_FILE_SYSTEM                  = &h1000  ' System File.
Const IMAGE_FILE_DLL                     = &h2000  ' File is a DLL.
Const IMAGE_FILE_UP_SYSTEM_ONLY          = &h4000  ' File should only be run on a UP machine
Const IMAGE_FILE_BYTES_REVERSED_HI       = &h8000  ' Bytes of machine word are reversed.

Const IMAGE_FILE_MACHINE_UNKNOWN         = 0
Const IMAGE_FILE_MACHINE_I386            = &h014c  ' Intel 386.
Const IMAGE_FILE_MACHINE_R3000           = &h0162  ' MIPS little-endian, 0x160 big-endian
Const IMAGE_FILE_MACHINE_R4000           = &h0166  ' MIPS little-endian
Const IMAGE_FILE_MACHINE_R10000          = &h0168  ' MIPS little-endian
Const IMAGE_FILE_MACHINE_WCEMIPSV2       = &h0169  ' MIPS little-endian WCE v2
Const IMAGE_FILE_MACHINE_ALPHA           = &h0184  ' Alpha_AXP
Const IMAGE_FILE_MACHINE_SH3             = &h01a2  ' SH3 little-endian
Const IMAGE_FILE_MACHINE_SH3DSP          = &h01a3
Const IMAGE_FILE_MACHINE_SH3E            = &h01a4  ' SH3E little-endian
Const IMAGE_FILE_MACHINE_SH4             = &h01a6  ' SH4 little-endian
Const IMAGE_FILE_MACHINE_SH5             = &h01a8  ' SH5
Const IMAGE_FILE_MACHINE_ARM             = &h01c0  ' ARM Little-Endian
Const IMAGE_FILE_MACHINE_THUMB           = &h01c2
Const IMAGE_FILE_MACHINE_AM33            = &h01d3
Const IMAGE_FILE_MACHINE_POWERPC         = &h01F0  ' IBM PowerPC Little-Endian
Const IMAGE_FILE_MACHINE_POWERPCFP       = &h01f1
Const IMAGE_FILE_MACHINE_IA64            = &h0200  ' Intel 64
Const IMAGE_FILE_MACHINE_MIPS16          = &h0266  ' MIPS
Const IMAGE_FILE_MACHINE_ALPHA64         = &h0284  ' ALPHA64
Const IMAGE_FILE_MACHINE_MIPSFPU         = &h0366  ' MIPS
Const IMAGE_FILE_MACHINE_MIPSFPU16       = &h0466  ' MIPS
Const IMAGE_FILE_MACHINE_AXP64           = IMAGE_FILE_MACHINE_ALPHA64
Const IMAGE_FILE_MACHINE_TRICORE         = &h0520  ' Infineon
Const IMAGE_FILE_MACHINE_CEF             = &h0CEF
Const IMAGE_FILE_MACHINE_EBC             = &h0EBC  ' EFI Byte Code
Const IMAGE_FILE_MACHINE_AMD64           = &h8664  ' AMD64 (K8)
Const IMAGE_FILE_MACHINE_M32R            = &h9041  ' M32R little-endian
Const IMAGE_FILE_MACHINE_CEE             = &hC0EE

' Directory format.
Type IMAGE_DATA_DIRECTORY
	VirtualAddress As DWord
	Size As DWord
End Type
TypeDef PIMAGE_DATA_DIRECTORY = *IMAGE_DATA_DIRECTORY

Const IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16

' Optional header format.
Type IMAGE_OPTIONAL_HEADER32
	Magic As Word
	MajorLinkerVersion As Byte
	MinorLinkerVersion As Byte
	SizeOfCode As DWord
	SizeOfInitializedData As DWord
	SizeOfUninitializedData As DWord
	AddressOfEntryPoint As DWord
	BaseOfCode As DWord
	BaseOfData As DWord

	ImageBase As DWord
	SectionAlignment As DWord
	FileAlignment As DWord
	MajorOperatingSystemVersion As Word
	MinorOperatingSystemVersion As Word
	MajorImageVersion As Word
	MinorImageVersion As Word
	MajorSubsystemVersion As Word
	MinorSubsystemVersion As Word
	Win32VersionValue As Word
	SizeOfImage As DWord
	SizeOfHeaders As DWord
	CheckSum As DWord
	Subsystem As Word
	DllCharacteristics As Word
	SizeOfStackReserve As DWord
	SizeOfStackCommit As DWord
	SizeOfHeapReserve As DWord
	SizeOfHeapCommit As DWord
	LoaderFlags As DWord
	NumberOfRvaAndSizes As DWord
	DataDirectory[ELM(IMAGE_NUMBEROF_DIRECTORY_ENTRIES)] As IMAGE_DATA_DIRECTORY
End Type
TypeDef PIMAGE_OPTIONAL_HEADER32 = *IMAGE_OPTIONAL_HEADER32

Type IMAGE_ROM_OPTIONAL_HEADER
	Magic As Word
	MajorLinkerVersion As Byte
	MinorLinkerVersion As Byte
	SizeOfCode As DWord
	SizeOfInitializedData As DWord
	SizeOfUninitializedData As DWord
	AddressOfEntryPoint As DWord
	BaseOfCode As DWord
	BaseOfData As DWord
	BaseOfBss As DWord
	GprMask As DWord
	CprMask[ELM(4)] As DWord
	GpValue As DWord
End Type
TypeDef PIMAGE_ROM_OPTIONAL_HEADER = *IMAGE_ROM_OPTIONAL_HEADER

Type IMAGE_OPTIONAL_HEADER64
	Magic As Word
	MajorLinkerVersion As Byte
	MinorLinkerVersion As Byte
	SizeOfCode As DWord
	SizeOfInitializedData As DWord
	SizeOfUninitializedData As DWord
	AddressOfEntryPoint As DWord
	BaseOfCode As DWord
	ImageBase As QWord
	SectionAlignment As DWord
	FileAlignment As DWord
	MajorOperatingSystemVersion As Word
	MinorOperatingSystemVersion As Word
	MajorImageVersion As Word
	MinorImageVersion As Word
	MajorSubsystemVersion As Word
	MinorSubsystemVersion As Word
	Win32VersionValue As DWord
	SizeOfImage As DWord
	SizeOfHeaders As DWord
	CheckSum As DWord
	Subsystem As Word
	DllCharacteristics As Word
	SizeOfStackReserve As QWord
	SizeOfStackCommit As QWord
	SizeOfHeapReserve As QWord
	SizeOfHeapCommit As QWord
	LoaderFlags As DWord
	NumberOfRvaAndSizes As DWord
	DataDirectory[ELM(IMAGE_NUMBEROF_DIRECTORY_ENTRIES)] As IMAGE_DATA_DIRECTORY
End Type
TypeDef PIMAGE_OPTIONAL_HEADER64 = *IMAGE_OPTIONAL_HEADER64

Const IMAGE_NT_OPTIONAL_HDR32_MAGIC = &h10b
Const IMAGE_NT_OPTIONAL_HDR64_MAGIC = &h20b
Const IMAGE_ROM_OPTIONAL_HDR_MAGIC = &h107

#ifdef _WIN64
TypeDef IMAGE_OPTIONAL_HEADER = IMAGE_OPTIONAL_HEADER64
TypeDef PIMAGE_OPTIONAL_HEADER = PIMAGE_OPTIONAL_HEADER64
Const IMAGE_NT_OPTIONAL_HDR_MAGIC = IMAGE_NT_OPTIONAL_HDR64_MAGIC
#else
TypeDef IMAGE_OPTIONAL_HEADER = IMAGE_OPTIONAL_HEADER32
TypeDef PIMAGE_OPTIONAL_HEADER = PIMAGE_OPTIONAL_HEADER32
Const IMAGE_NT_OPTIONAL_HDR_MAGIC = IMAGE_NT_OPTIONAL_HDR32_MAGIC
#endif

Type IMAGE_NT_HEADERS64
	Signature As DWord
	FileHeader As IMAGE_FILE_HEADER
	OptionalHeader As IMAGE_OPTIONAL_HEADER64
End Type
TypeDef PIMAGE_NT_HEADERS64 = *IMAGE_NT_HEADERS64

Type IMAGE_NT_HEADERS32
	Signature As DWord
	FileHeader As IMAGE_FILE_HEADER
	OptionalHeader As IMAGE_OPTIONAL_HEADER32
End Type
TypeDef PIMAGE_NT_HEADERS32 = *IMAGE_NT_HEADERS32

Type IMAGE_ROM_HEADERS
	FileHeader As IMAGE_FILE_HEADER
	OptionalHeader As IMAGE_ROM_OPTIONAL_HEADER
End Type
TypeDef PIMAGE_ROM_HEADERS = *IMAGE_ROM_HEADERS

#ifdef _WIN64
TypeDef IMAGE_NT_HEADERS = IMAGE_NT_HEADERS64
TypeDef PIMAGE_NT_HEADERS = PIMAGE_NT_HEADERS64
#else
TypeDef IMAGE_NT_HEADERS = IMAGE_NT_HEADERS32
TypeDef PIMAGE_NT_HEADERS = PIMAGE_NT_HEADERS32
#endif
/*
Const IMAGE_FIRST_SECTION( ntheader ) (        \_
    ((ntheader) As ULONG_PTR +                                              _
     FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) +                 _
     ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader   _
    ) As PIMAGE_SECTION_HEADER)
*/
Const IMAGE_SUBSYSTEM_UNKNOWN             = 0   ' Unknown subsystem.
Const IMAGE_SUBSYSTEM_NATIVE              = 1   ' Image doesn't require a subsystem.
Const IMAGE_SUBSYSTEM_WINDOWS_GUI         = 2   ' Image runs in the Windows GUI subsystem.
Const IMAGE_SUBSYSTEM_WINDOWS_CUI         = 3   ' Image runs in the Windows character subsystem.
Const IMAGE_SUBSYSTEM_OS2_CUI             = 5   ' image runs in the OS/2 character subsystem.
Const IMAGE_SUBSYSTEM_POSIX_CUI           = 7   ' image runs in the Posix character subsystem.
Const IMAGE_SUBSYSTEM_NATIVE_WINDOWS      = 8   ' image is a native Win9x driver.
Const IMAGE_SUBSYSTEM_WINDOWS_CE_GUI      = 9   ' Image runs in the Windows CE subsystem.
Const IMAGE_SUBSYSTEM_EFI_APPLICATION     = 10  '
Const IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER = 11   '
Const IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER  = 12  '
Const IMAGE_SUBSYSTEM_EFI_ROM             = 13
Const IMAGE_SUBSYSTEM_XBOX                = 14
Const IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION = 16

'      IMAGE_LIBRARY_PROCESS_INIT           = &h0001    ' Reserved.
'      IMAGE_LIBRARY_PROCESS_TERM           = &h0002    ' Reserved.
'      IMAGE_LIBRARY_THREAD_INIT            = &h0004    ' Reserved.
'      IMAGE_LIBRARY_THREAD_TERM            = &h0008    ' Reserved.
Const IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE = &h0040     ' DLL can move.
Const IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY   = &h0080     ' Code Integrity Image
Const IMAGE_DLLCHARACTERISTICS_NX_COMPAT    = &h0100     ' Image is NX compatible
Const IMAGE_DLLCHARACTERISTICS_NO_ISOLATION = &h0200     ' Image understands isolation and doesn't want it
Const IMAGE_DLLCHARACTERISTICS_NO_SEH       = &h0400     ' Image does not use SEH.  No SE handler may reside in this image
Const IMAGE_DLLCHARACTERISTICS_NO_BIND      = &h0800     ' Do not bind this image.
'                                            = &h1000    ' Reserved.
Const IMAGE_DLLCHARACTERISTICS_WDM_DRIVER   = &h2000     ' Driver uses WDM model
'                                           = &h4000    ' Reserved.
Const IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE    = &h8000

Const IMAGE_DIRECTORY_ENTRY_EXPORT         = 0   ' Export Directory
Const IMAGE_DIRECTORY_ENTRY_IMPORT         = 1   ' Import Directory
Const IMAGE_DIRECTORY_ENTRY_RESOURCE       = 2   ' Resource Directory
Const IMAGE_DIRECTORY_ENTRY_EXCEPTION      = 3   ' Exception Directory
Const IMAGE_DIRECTORY_ENTRY_SECURITY       = 4   ' Security Directory
Const IMAGE_DIRECTORY_ENTRY_BASERELOC      = 5   ' Base Relocation Table
Const IMAGE_DIRECTORY_ENTRY_DEBUG          = 6   ' Debug Directory
'      IMAGE_DIRECTORY_ENTRY_COPYRIGHT      = 7  ' (X86 usage)
Const IMAGE_DIRECTORY_ENTRY_ARCHITECTURE   = 7   ' Architecture Specific Data
Const IMAGE_DIRECTORY_ENTRY_GLOBALPTR      = 8   ' RVA of GP
Const IMAGE_DIRECTORY_ENTRY_TLS            = 9   ' TLS Directory
Const IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG   = 10   ' Load Configuration Directory
Const IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT  = 11   ' Bound Import Directory in headers
Const IMAGE_DIRECTORY_ENTRY_IAT           = 12   ' Import Address Table
Const IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT  = 13   ' Delay Load Import Descriptors
Const IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR = 14  ' COM Runtime descriptor

' Non-COFF Object file header
Type ANON_OBJECT_HEADER
	Sig1 As Word             ' Must be IMAGE_FILE_MACHINE_UNKNOWN
	Sig2 As Word             ' Must be 0xffff
	Version As Word  ' >= 1 (implies the CLSID field is present)
	Machine As Word
	TimeDateStamp As DWord
	ClassID As CLSID       ' Used to invoke CoCreateInstance
	SizeOfData As DWord    ' Size of data that follows the header
End Type

Type ANON_OBJECT_HEADER_V2
	Sig1 As Word            ' Must be IMAGE_FILE_MACHINE_UNKNOWN
	Sig2 As Word            ' Must be 0xffff
	Version As Word         ' >= 2 (implies the Flags field is present - otherwise V1)
	Machine As Word
	TimeDateStamp As DWord
	ClassID As CLSID         ' Used to invoke CoCreateInstance
	SizeOfData As DWord      ' Size of data that follows the header
	Flags As DWord           ' 0x1 -> contains metadata
	MetaDataSize As DWord    ' Size of CLR metadata
	MetaDataOffset As DWord  ' Offset of CLR metadata
End Type

Const IMAGE_SIZEOF_SHORT_NAME = 8

Type IMAGE_SECTION_HEADER
	Name[ELM(IMAGE_SIZEOF_SHORT_NAME)] As Byte
	'Union
		PhysicalAddress As DWord
'		VirtualSize As DWord
'	} Misc
	VirtualAddress As DWord
	SizeOfRawData As DWord
	PointerToRawData As DWord
	PointerToRelocations As DWord
	PointerToLinenumbers As DWord
	NumberOfRelocations As Word
	NumberOfLinenumbers As Word
	Characteristics As DWord
End Type
TypeDef PIMAGE_SECTION_HEADER = *IMAGE_SECTION_HEADER

Const IMAGE_SIZEOF_SECTION_HEADER = 40

' Section characteristics.
'      IMAGE_SCN_TYPE_REG                 = &h00000000 ' Reserved.
'      IMAGE_SCN_TYPE_DSECT               = &h00000001 ' Reserved.
'      IMAGE_SCN_TYPE_NOLOAD              = &h00000002 ' Reserved.
'      IMAGE_SCN_TYPE_GROUP               = &h00000004 ' Reserved.
Const IMAGE_SCN_TYPE_NO_PAD              = &h00000008  ' Reserved.
'      IMAGE_SCN_TYPE_COPY                = &h00000010 ' Reserved.

Const IMAGE_SCN_CNT_CODE                 = &h00000020  ' Section contains code.
Const IMAGE_SCN_CNT_INITIALIZED_DATA     = &h00000040  ' Section contains initialized data.
Const IMAGE_SCN_CNT_UNINITIALIZED_DATA   = &h00000080  ' Section contains uninitialized data.

Const IMAGE_SCN_LNK_OTHER                = &h00000100  ' Reserved.
Const IMAGE_SCN_LNK_INFO                 = &h00000200  ' Section contains comments or some other type of information.
'      IMAGE_SCN_TYPE_OVER                = &h00000400 ' Reserved.
Const IMAGE_SCN_LNK_REMOVE               = &h00000800  ' Section contents will not become part of image.
Const IMAGE_SCN_LNK_COMDAT               = &h00001000  ' Section contents comdat.
'                                         = &h00002000 ' Reserved.
'      IMAGE_SCN_MEM_PROTECTED - Obsolete = &h00004000
Const IMAGE_SCN_NO_DEFER_SPEC_EXC        = &h00004000  ' Reset speculative exceptions handling bits in the TLB entries for this section.
Const IMAGE_SCN_GPREL                    = &h00008000  ' Section content can be accessed relative to GP
Const IMAGE_SCN_MEM_FARDATA              = &h00008000
'      IMAGE_SCN_MEM_SYSHEAP  - Obsolete  = &h00010000
Const IMAGE_SCN_MEM_PURGEABLE            = &h00020000
Const IMAGE_SCN_MEM_16BIT                = &h00020000
Const IMAGE_SCN_MEM_LOCKED               = &h00040000
Const IMAGE_SCN_MEM_PRELOAD              = &h00080000

Const IMAGE_SCN_ALIGN_1BYTES             = &h00100000  '
Const IMAGE_SCN_ALIGN_2BYTES             = &h00200000  '
Const IMAGE_SCN_ALIGN_4BYTES             = &h00300000  '
Const IMAGE_SCN_ALIGN_8BYTES             = &h00400000  '
Const IMAGE_SCN_ALIGN_16BYTES            = &h00500000  ' Default alignment if no others are specified.
Const IMAGE_SCN_ALIGN_32BYTES            = &h00600000  '
Const IMAGE_SCN_ALIGN_64BYTES            = &h00700000  '
Const IMAGE_SCN_ALIGN_128BYTES           = &h00800000  '
Const IMAGE_SCN_ALIGN_256BYTES           = &h00900000  '
Const IMAGE_SCN_ALIGN_512BYTES           = &h00A00000  '
Const IMAGE_SCN_ALIGN_1024BYTES          = &h00B00000  '
Const IMAGE_SCN_ALIGN_2048BYTES          = &h00C00000  '
Const IMAGE_SCN_ALIGN_4096BYTES          = &h00D00000  '
Const IMAGE_SCN_ALIGN_8192BYTES          = &h00E00000  '
' Unused                                  = &h00F00000
Const IMAGE_SCN_ALIGN_MASK               = &h00F00000

Const IMAGE_SCN_LNK_NRELOC_OVFL          = &h01000000  ' Section contains extended relocations.
Const IMAGE_SCN_MEM_DISCARDABLE          = &h02000000  ' Section can be discarded.
Const IMAGE_SCN_MEM_NOT_CACHED           = &h04000000  ' Section is not cachable.
Const IMAGE_SCN_MEM_NOT_PAGED            = &h08000000  ' Section is not pageable.
Const IMAGE_SCN_MEM_SHARED               = &h10000000  ' Section is shareable.
Const IMAGE_SCN_MEM_EXECUTE              = &h20000000  ' Section is executable.
Const IMAGE_SCN_MEM_READ                 = &h40000000  ' Section is readable.
Const IMAGE_SCN_MEM_WRITE                = &h80000000  ' Section is writeable.

' TLS Chaacteristic Flags
Const IMAGE_SCN_SCALE_INDEX              = &h00000001  ' Tls index is scaled

' Symbol format.
Type Align(2) IMAGE_SYMBOL
'	Union
		ShortName[ELM(8)] As Byte
'		Type
'			Short As DWord
'			Long As DWord
'		} Name
'		LongName[ELM(2)] As DWord ' PBYTE [ELM(2)]
'	} N
	Value AS DWord
	SectionNumber As Integer
	Type_ As Word
	StorageClass As Byte
	NumberOfAuxSymbols As Byte
End Type
TypeDef PIMAGE_SYMBOL = * /*UNALIGNED*/ IMAGE_SYMBOL

Const IMAGE_SIZEOF_SYMBOL  = 18

' Section values.
Const IMAGE_SYM_UNDEFINED   = 0 As Integer         ' Symbol is undefined or is common.
Const IMAGE_SYM_ABSOLUTE    = -1 As Integer        ' Symbol is an absolute value.
Const IMAGE_SYM_DEBUG       = -2 As Integer        ' Symbol is a special debug item.
Const IMAGE_SYM_SECTION_MAX = &hFEFF               ' Values 0xFF00-0xFFFF are special

' Type (fundamental) values.

Const IMAGE_SYM_TYPE_NULL               = &h0000  ' no type.
Const IMAGE_SYM_TYPE_VOID               = &h0001  '
Const IMAGE_SYM_TYPE_CHAR               = &h0002  ' type character.
Const IMAGE_SYM_TYPE_SHORT              = &h0003  ' type short integer.
Const IMAGE_SYM_TYPE_INT                = &h0004  '
Const IMAGE_SYM_TYPE_LONG               = &h0005  '
Const IMAGE_SYM_TYPE_FLOAT              = &h0006  '
Const IMAGE_SYM_TYPE_DOUBLE             = &h0007  '
Const IMAGE_SYM_TYPE_STRUCT             = &h0008  '
Const IMAGE_SYM_TYPE_UNION              = &h0009  '
Const IMAGE_SYM_TYPE_ENUM               = &h000A  ' enumeration.
Const IMAGE_SYM_TYPE_MOE                = &h000B  ' member of enumeration.
Const IMAGE_SYM_TYPE_BYTE               = &h000C  '
Const IMAGE_SYM_TYPE_WORD               = &h000D  '
Const IMAGE_SYM_TYPE_UINT               = &h000E  '
Const IMAGE_SYM_TYPE_DWORD              = &h000F  '
Const IMAGE_SYM_TYPE_PCODE              = &h8000  '

'Type (derived) values.

Const IMAGE_SYM_DTYPE_NULL              = 0       ' no derived type.
Const IMAGE_SYM_DTYPE_POINTER           = 1       ' pointer.
Const IMAGE_SYM_DTYPE_FUNCTION          = 2       ' function.
Const IMAGE_SYM_DTYPE_ARRAY             = 3       ' array.

' Storage classes.
Const IMAGE_SYM_CLASS_END_OF_FUNCTION = -1 As Byte
Const IMAGE_SYM_CLASS_NULL = &h0000
Const IMAGE_SYM_CLASS_AUTOMATIC = &h0001
Const IMAGE_SYM_CLASS_EXTERNAL = &h0002
Const IMAGE_SYM_CLASS_STATIC = &h0003
Const IMAGE_SYM_CLASS_REGISTER = &h0004
Const IMAGE_SYM_CLASS_EXTERNAL_DEF = &h0005
Const IMAGE_SYM_CLASS_LABEL = &h0006
Const IMAGE_SYM_CLASS_UNDEFINED_LABEL = &h0007
Const IMAGE_SYM_CLASS_MEMBER_OF_STRUCT = &h0008
Const IMAGE_SYM_CLASS_ARGUMENT = &h0009
Const IMAGE_SYM_CLASS_STRUCT_TAG = &h000A
Const IMAGE_SYM_CLASS_MEMBER_OF_UNION = &h000B
Const IMAGE_SYM_CLASS_UNION_TAG = &h000C
Const IMAGE_SYM_CLASS_TYPE_DEFINITION = &h000D
Const IMAGE_SYM_CLASS_UNDEFINED_STATIC = &h000E
Const IMAGE_SYM_CLASS_ENUM_TAG = &h000F
Const IMAGE_SYM_CLASS_MEMBER_OF_ENUM = &h0010
Const IMAGE_SYM_CLASS_REGISTER_PARAM = &h0011
Const IMAGE_SYM_CLASS_BIT_FIELD = &h0012

Const IMAGE_SYM_CLASS_FAR_EXTERNAL = &h0044

Const IMAGE_SYM_CLASS_BLOCK = &h0064
Const IMAGE_SYM_CLASS_FUNCTION = &h0065
Const IMAGE_SYM_CLASS_END_OF_STRUCT = &h0066
Const IMAGE_SYM_CLASS_FILE = &h0067
' new
Const IMAGE_SYM_CLASS_SECTION = &h0068
Const IMAGE_SYM_CLASS_WEAK_EXTERNAL = &h0069

Const IMAGE_SYM_CLASS_CLR_TOKEN = &h006B

' type packing constants
Const N_BTMASK = &h000F
Const N_TMASK = &h0030
Const N_TMASK1 = &h00C0
Const N_TMASK2 = &h00F0
Const N_BTSHFT = 4
Const N_TSHIFT = 2

Const BTYPE(x) = ((x) And N_BTMASK)
Const ISPTR(x) = (((x) And N_TMASK) = (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
Const ISFCN(x) = (((x) And N_TMASK) = (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
Const ISARY(x) = (((x) And N_TMASK) = (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
Const ISTAG(x) = ((x) = IMAGE_SYM_CLASS_STRUCT_TAG Or (x) = IMAGE_SYM_CLASS_UNION_TAG Or (x) = IMAGE_SYM_CLASS_ENUM_TAG)
Const INCREF(x) = ((((x) And (Not N_BTMASK)) << N_TSHIFT) Or (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT) Or ((x) And N_BTMASK))
Const DECREF(x) = ((((x) >> N_TSHIFT) And (Not N_BTMASK)) Or ((x) And N_BTMASK))

' Auxiliary entry format.
Type /*Union*/ Align(2) IMAGE_AUX_SYMBOL
'	Type
'		TagIndex As DWord                     ' struct, union, or enum tag index
'		Union
'			Type
'				Linenumber As Word            ' declaration line number
'				Size As Word                  ' size of struct, union, or enum
'			} LnSz
'			TotalSize As DWord
'		} Misc
'		Union
'			Type                              ' if ISFCN, tag, or .bb
'			PointerToLinenumber As DWord
'				PointerToNextFunction As DWord
'			} Function
'			Type                              ' if ISARY, up to 4 dimen.
'				Dimension[ELM(4)] As Word
'			} Array
'		} FcnAry
'		TvIndex As Word                       ' tv index
'	} Sym
'	Type
'		Name[ELM(IMAGE_SIZEOF_SYMBOL)] As Byte
'	} File
'	Type
		Length As DWord                 ' section length
		NumberOfRelocations As Word     ' number of relocation entries
		NumberOfLinenumbers As Word     ' number of line numbers
		CheckSum As DWord               ' checksum for communal
		Number As Integer               ' section number to associate with
		Selection As Byte               ' communal selection type
'	} Section
End Type 'Union
TypeDef PIMAGE_AUX_SYMBOL = * /*UNALIGNED*/ IMAGE_AUX_SYMBOL

Enum IMAGE_AUX_SYMBOL_TYPE
	IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF = 1
End Enum

Type Align(2) IMAGE_AUX_SYMBOL_TOKEN_DEF
	bAuxType As Byte
	bReserved As Byte
	SymbolTableIndex As DWord
	rgbReserved[ELM(12)] As Byte
End Type
TypeDef PIMAGE_AUX_SYMBOL_TOKEN_DEF = * /*UNALIGNED*/ IMAGE_AUX_SYMBOL_TOKEN_DEF

' Communal selection types.
Const IMAGE_COMDAT_SELECT_NODUPLICATES = 1
Const IMAGE_COMDAT_SELECT_ANY = 2
Const IMAGE_COMDAT_SELECT_SAME_SIZE = 3
Const IMAGE_COMDAT_SELECT_EXACT_MATCH = 4
Const IMAGE_COMDAT_SELECT_ASSOCIATIVE = 5
Const IMAGE_COMDAT_SELECT_LARGEST = 6
Const IMAGE_COMDAT_SELECT_NEWEST = 7

Const IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY = 1
Const IMAGE_WEAK_EXTERN_SEARCH_LIBRARY = 2
Const IMAGE_WEAK_EXTERN_SEARCH_ALIAS = 3

' Relocation format.
Type Align(2) IMAGE_RELOCATION
'	Union
'		VirtualAddress As DWord
		RelocCount As DWord
'	End Union
	SymbolTableIndex As DWord
	Type_ As Word
End Type
TypeDef PIMAGE_RELOCATION = * /*UNALIGNED*/ IMAGE_RELOCATION

' I386 relocation types.
Const IMAGE_REL_I386_ABSOLUTE       = &h0000  ' Reference is absolute, no relocation is necessary
Const IMAGE_REL_I386_DIR16          = &h0001  ' Direct 16-bit reference to the symbols virtual address
Const IMAGE_REL_I386_REL16          = &h0002  ' PC-relative 16-bit reference to the symbols virtual address
Const IMAGE_REL_I386_DIR32          = &h0006  ' Direct 32-bit reference to the symbols virtual address
Const IMAGE_REL_I386_DIR32NB        = &h0007  ' Direct 32-bit reference to the symbols virtual address, base not included
Const IMAGE_REL_I386_SEG12          = &h0009  ' Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
Const IMAGE_REL_I386_SECTION        = &h000A
Const IMAGE_REL_I386_SECREL         = &h000B
Const IMAGE_REL_I386_TOKEN          = &h000C  ' clr token
Const IMAGE_REL_I386_SECREL7        = &h000D  ' 7 bit offset from base of section containing target
Const IMAGE_REL_I386_REL32          = &h0014  ' PC-relative 32-bit reference to the symbols virtual address

' MIPS relocation types.
Const IMAGE_REL_MIPS_ABSOLUTE       = &h0000  ' Reference is absolute, no relocation is necessary
Const IMAGE_REL_MIPS_REFHALF        = &h0001
Const IMAGE_REL_MIPS_REFWORD        = &h0002
Const IMAGE_REL_MIPS_JMPADDR        = &h0003
Const IMAGE_REL_MIPS_REFHI          = &h0004
Const IMAGE_REL_MIPS_REFLO          = &h0005
Const IMAGE_REL_MIPS_GPREL          = &h0006
Const IMAGE_REL_MIPS_LITERAL        = &h0007
Const IMAGE_REL_MIPS_SECTION        = &h000A
Const IMAGE_REL_MIPS_SECREL         = &h000B
Const IMAGE_REL_MIPS_SECRELLO       = &h000C  ' Low 16-bit section relative referemce (used for >32k TLS)
Const IMAGE_REL_MIPS_SECRELHI       = &h000D  ' High 16-bit section relative reference (used for >32k TLS)
Const IMAGE_REL_MIPS_TOKEN          = &h000E  ' clr token
Const IMAGE_REL_MIPS_JMPADDR16      = &h0010
Const IMAGE_REL_MIPS_REFWORDNB      = &h0022
Const IMAGE_REL_MIPS_PAIR           = &h0025

' Alpha Relocation types.
Const IMAGE_REL_ALPHA_ABSOLUTE      = &h0000
Const IMAGE_REL_ALPHA_REFLONG       = &h0001
Const IMAGE_REL_ALPHA_REFQUAD       = &h0002
Const IMAGE_REL_ALPHA_GPREL32       = &h0003
Const IMAGE_REL_ALPHA_LITERAL       = &h0004
Const IMAGE_REL_ALPHA_LITUSE        = &h0005
Const IMAGE_REL_ALPHA_GPDISP        = &h0006
Const IMAGE_REL_ALPHA_BRADDR        = &h0007
Const IMAGE_REL_ALPHA_HINT          = &h0008
Const IMAGE_REL_ALPHA_INLINE_REFLONG= &h0009
Const IMAGE_REL_ALPHA_REFHI         = &h000A
Const IMAGE_REL_ALPHA_REFLO         = &h000B
Const IMAGE_REL_ALPHA_PAIR          = &h000C
Const IMAGE_REL_ALPHA_MATCH         = &h000D
Const IMAGE_REL_ALPHA_SECTION       = &h000E
Const IMAGE_REL_ALPHA_SECREL        = &h000F
Const IMAGE_REL_ALPHA_REFLONGNB     = &h0010
Const IMAGE_REL_ALPHA_SECRELLO      = &h0011  ' Low 16-bit section relative reference
Const IMAGE_REL_ALPHA_SECRELHI      = &h0012  ' High 16-bit section relative reference
Const IMAGE_REL_ALPHA_REFQ3         = &h0013  ' High 16 bits of 48 bit reference
Const IMAGE_REL_ALPHA_REFQ2         = &h0014  ' Middle 16 bits of 48 bit reference
Const IMAGE_REL_ALPHA_REFQ1         = &h0015  ' Low 16 bits of 48 bit reference
Const IMAGE_REL_ALPHA_GPRELLO       = &h0016  ' Low 16-bit GP relative reference
Const IMAGE_REL_ALPHA_GPRELHI       = &h0017  ' High 16-bit GP relative reference

' IBM PowerPC relocation types.
Const IMAGE_REL_PPC_ABSOLUTE        = &h0000  ' NOP
Const IMAGE_REL_PPC_ADDR64          = &h0001  ' 64-bit address
Const IMAGE_REL_PPC_ADDR32          = &h0002  ' 32-bit address
Const IMAGE_REL_PPC_ADDR24          = &h0003  ' 26-bit address, shifted left 2 (branch absolute)
Const IMAGE_REL_PPC_ADDR16          = &h0004  ' 16-bit address
Const IMAGE_REL_PPC_ADDR14          = &h0005  ' 16-bit address, shifted left 2 (load doubleword)
Const IMAGE_REL_PPC_REL24           = &h0006  ' 26-bit PC-relative offset, shifted left 2 (branch relative)
Const IMAGE_REL_PPC_REL14           = &h0007  ' 16-bit PC-relative offset, shifted left 2 (br cond relative)
Const IMAGE_REL_PPC_TOCREL16        = &h0008  ' 16-bit offset from TOC base
Const IMAGE_REL_PPC_TOCREL14        = &h0009  ' 16-bit offset from TOC base, shifted left 2 (load doubleword)

Const IMAGE_REL_PPC_ADDR32NB        = &h000A  ' 32-bit addr w/o image base
Const IMAGE_REL_PPC_SECREL          = &h000B  ' va of containing section (as in an image sectionhdr)
Const IMAGE_REL_PPC_SECTION         = &h000C  ' sectionheader number
Const IMAGE_REL_PPC_IFGLUE          = &h000D  ' substitute TOC restore instruction iff symbol is glue code
Const IMAGE_REL_PPC_IMGLUE          = &h000E  ' symbol is glue code; virtual address is TOC restore instruction
Const IMAGE_REL_PPC_SECREL16        = &h000F  ' va of containing section (limited to 16 bits)
Const IMAGE_REL_PPC_REFHI           = &h0010
Const IMAGE_REL_PPC_REFLO           = &h0011
Const IMAGE_REL_PPC_PAIR            = &h0012
Const IMAGE_REL_PPC_SECRELLO        = &h0013  ' Low 16-bit section relative reference (used for >32k TLS)
Const IMAGE_REL_PPC_SECRELHI        = &h0014  ' High 16-bit section relative reference (used for >32k TLS)
Const IMAGE_REL_PPC_GPREL           = &h0015
Const IMAGE_REL_PPC_TOKEN           = &h0016  ' clr token

Const IMAGE_REL_PPC_TYPEMASK        = &h00FF  ' mask to isolate above values in IMAGE_RELOCATION.Type

' Flag bits in IMAGE_RELOCATION.TYPE

Const IMAGE_REL_PPC_NEG             = &h0100  ' subtract reloc value rather than adding it
Const IMAGE_REL_PPC_BRTAKEN         = &h0200  ' fix branch prediction bit to predict branch taken
Const IMAGE_REL_PPC_BRNTAKEN        = &h0400  ' fix branch prediction bit to predict branch not taken
Const IMAGE_REL_PPC_TOCDEFN         = &h0800  ' toc slot defined in file (or, data in toc)

' Hitachi SH3 relocation types.
Const IMAGE_REL_SH3_ABSOLUTE        = &h0000  ' No relocation
Const IMAGE_REL_SH3_DIRECT16        = &h0001  ' 16 bit direct
Const IMAGE_REL_SH3_DIRECT32        = &h0002  ' 32 bit direct
Const IMAGE_REL_SH3_DIRECT8         = &h0003  ' 8 bit direct, -128..255
Const IMAGE_REL_SH3_DIRECT8_WORD    = &h0004  ' 8 bit direct .W (0 ext.)
Const IMAGE_REL_SH3_DIRECT8_LONG    = &h0005  ' 8 bit direct .L (0 ext.)
Const IMAGE_REL_SH3_DIRECT4         = &h0006  ' 4 bit direct (0 ext.)
Const IMAGE_REL_SH3_DIRECT4_WORD    = &h0007  ' 4 bit direct .W (0 ext.)
Const IMAGE_REL_SH3_DIRECT4_LONG    = &h0008  ' 4 bit direct .L (0 ext.)
Const IMAGE_REL_SH3_PCREL8_WORD     = &h0009  ' 8 bit PC relative .W
Const IMAGE_REL_SH3_PCREL8_LONG     = &h000A  ' 8 bit PC relative .L
Const IMAGE_REL_SH3_PCREL12_WORD    = &h000B  ' 12 LSB PC relative .W
Const IMAGE_REL_SH3_STARTOF_SECTION = &h000C  ' Start of EXE section
Const IMAGE_REL_SH3_SIZEOF_SECTION  = &h000D  ' Size of EXE section
Const IMAGE_REL_SH3_SECTION         = &h000E  ' Section table index
Const IMAGE_REL_SH3_SECREL          = &h000F  ' Offset within section
Const IMAGE_REL_SH3_DIRECT32_NB     = &h0010  ' 32 bit direct not based
Const IMAGE_REL_SH3_GPREL4_LONG     = &h0011  ' GP-relative addressing
Const IMAGE_REL_SH3_TOKEN           = &h0012  ' clr token
Const IMAGE_REL_SHM_PCRELPT         = &h0013  ' Offset from current
                                                '  instruction in longwords
                                                '  if not NOMODE, insert the
                                                '  inverse of the low bit at
                                                '  bit 32 to select PTA/PTB
Const IMAGE_REL_SHM_REFLO           = &h0014  ' Low bits of 32-bit address
Const IMAGE_REL_SHM_REFHALF         = &h0015  ' High bits of 32-bit address
Const IMAGE_REL_SHM_RELLO           = &h0016  ' Low bits of relative reference
Const IMAGE_REL_SHM_RELHALF         = &h0017  ' High bits of relative reference
Const IMAGE_REL_SHM_PAIR            = &h0018  ' offset operand for relocation

Const IMAGE_REL_SH_NOMODE           = &h8000  ' relocation ignores section mode


Const IMAGE_REL_ARM_ABSOLUTE        = &h0000  ' No relocation required
Const IMAGE_REL_ARM_ADDR32          = &h0001  ' 32 bit address
Const IMAGE_REL_ARM_ADDR32NB        = &h0002  ' 32 bit address w/o image base
Const IMAGE_REL_ARM_BRANCH24        = &h0003  ' 24 bit offset << 2 & sign ext.
Const IMAGE_REL_ARM_BRANCH11        = &h0004  ' Thumb: 2 11 bit offsets
Const IMAGE_REL_ARM_TOKEN           = &h0005  ' clr token
Const IMAGE_REL_ARM_GPREL12         = &h0006  ' GP-relative addressing (ARM)
Const IMAGE_REL_ARM_GPREL7          = &h0007  ' GP-relative addressing (Thumb)
Const IMAGE_REL_ARM_BLX24           = &h0008
Const IMAGE_REL_ARM_BLX11           = &h0009
Const IMAGE_REL_ARM_SECTION         = &h000E  ' Section table index
Const IMAGE_REL_ARM_SECREL          = &h000F  ' Offset within section

Const IMAGE_REL_AM_ABSOLUTE         = &h0000
Const IMAGE_REL_AM_ADDR32           = &h0001
Const IMAGE_REL_AM_ADDR32NB         = &h0002
Const IMAGE_REL_AM_CALL32           = &h0003
Const IMAGE_REL_AM_FUNCINFO         = &h0004
Const IMAGE_REL_AM_REL32_1          = &h0005
Const IMAGE_REL_AM_REL32_2          = &h0006
Const IMAGE_REL_AM_SECREL           = &h0007
Const IMAGE_REL_AM_SECTION          = &h0008
Const IMAGE_REL_AM_TOKEN            = &h0009

' x64 relocations
Const IMAGE_REL_AMD64_ABSOLUTE      = &h0000  ' Reference is absolute, no relocation is necessary
Const IMAGE_REL_AMD64_ADDR64        = &h0001  ' 64-bit address (VA).
Const IMAGE_REL_AMD64_ADDR32        = &h0002  ' 32-bit address (VA).
Const IMAGE_REL_AMD64_ADDR32NB      = &h0003  ' 32-bit address w/o image base (RVA).
Const IMAGE_REL_AMD64_REL32         = &h0004  ' 32-bit relative address from byte following reloc
Const IMAGE_REL_AMD64_REL32_1       = &h0005  ' 32-bit relative address from byte distance 1 from reloc
Const IMAGE_REL_AMD64_REL32_2       = &h0006  ' 32-bit relative address from byte distance 2 from reloc
Const IMAGE_REL_AMD64_REL32_3       = &h0007  ' 32-bit relative address from byte distance 3 from reloc
Const IMAGE_REL_AMD64_REL32_4       = &h0008  ' 32-bit relative address from byte distance 4 from reloc
Const IMAGE_REL_AMD64_REL32_5       = &h0009  ' 32-bit relative address from byte distance 5 from reloc
Const IMAGE_REL_AMD64_SECTION       = &h000A  ' Section index
Const IMAGE_REL_AMD64_SECREL        = &h000B  ' 32 bit offset from base of section containing target
Const IMAGE_REL_AMD64_SECREL7       = &h000C  ' 7 bit unsigned offset from base of section containing target
Const IMAGE_REL_AMD64_TOKEN         = &h000D  ' 32 bit metadata token
Const IMAGE_REL_AMD64_SREL32        = &h000E  ' 32 bit signed span-dependent value emitted into object
Const IMAGE_REL_AMD64_PAIR          = &h000F
Const IMAGE_REL_AMD64_SSPAN32       = &h0010  ' 32 bit signed span-dependent value applied at link time

' IA64 relocation types.

Const IMAGE_REL_IA64_ABSOLUTE       = &h0000
Const IMAGE_REL_IA64_IMM14          = &h0001
Const IMAGE_REL_IA64_IMM22          = &h0002
Const IMAGE_REL_IA64_IMM64          = &h0003
Const IMAGE_REL_IA64_DIR32          = &h0004
Const IMAGE_REL_IA64_DIR64          = &h0005
Const IMAGE_REL_IA64_PCREL21B       = &h0006
Const IMAGE_REL_IA64_PCREL21M       = &h0007
Const IMAGE_REL_IA64_PCREL21F       = &h0008
Const IMAGE_REL_IA64_GPREL22        = &h0009
Const IMAGE_REL_IA64_LTOFF22        = &h000A
Const IMAGE_REL_IA64_SECTION        = &h000B
Const IMAGE_REL_IA64_SECREL22       = &h000C
Const IMAGE_REL_IA64_SECREL64I      = &h000D
Const IMAGE_REL_IA64_SECREL32       = &h000E
'
Const IMAGE_REL_IA64_DIR32NB        = &h0010
Const IMAGE_REL_IA64_SREL14         = &h0011
Const IMAGE_REL_IA64_SREL22         = &h0012
Const IMAGE_REL_IA64_SREL32         = &h0013
Const IMAGE_REL_IA64_UREL32         = &h0014
Const IMAGE_REL_IA64_PCREL60X       = &h0015  ' This is always a BRL and never converted
Const IMAGE_REL_IA64_PCREL60B       = &h0016  ' If possible, convert to MBB bundle with NOP.B in slot 1
Const IMAGE_REL_IA64_PCREL60F       = &h0017  ' If possible, convert to MFB bundle with NOP.F in slot 1
Const IMAGE_REL_IA64_PCREL60I       = &h0018  ' If possible, convert to MIB bundle with NOP.I in slot 1
Const IMAGE_REL_IA64_PCREL60M       = &h0019  ' If possible, convert to MMB bundle with NOP.M in slot 1
Const IMAGE_REL_IA64_IMMGPREL64     = &h001A
Const IMAGE_REL_IA64_TOKEN          = &h001B  ' clr token
Const IMAGE_REL_IA64_GPREL32        = &h001C
Const IMAGE_REL_IA64_ADDEND         = &h001F

' CEF relocation types.
Const IMAGE_REL_CEF_ABSOLUTE        = &h0000  ' Reference is absolute, no relocation is necessary
Const IMAGE_REL_CEF_ADDR32          = &h0001  ' 32-bit address (VA).
Const IMAGE_REL_CEF_ADDR64          = &h0002  ' 64-bit address (VA).
Const IMAGE_REL_CEF_ADDR32NB        = &h0003  ' 32-bit address w/o image base (RVA).
Const IMAGE_REL_CEF_SECTION         = &h0004  ' Section index
Const IMAGE_REL_CEF_SECREL          = &h0005  ' 32 bit offset from base of section containing target
Const IMAGE_REL_CEF_TOKEN           = &h0006  ' 32 bit metadata token

' clr relocation types.
Const IMAGE_REL_CEE_ABSOLUTE        = &h0000  ' Reference is absolute, no relocation is necessary
Const IMAGE_REL_CEE_ADDR32          = &h0001  ' 32-bit address (VA).
Const IMAGE_REL_CEE_ADDR64          = &h0002  ' 64-bit address (VA).
Const IMAGE_REL_CEE_ADDR32NB        = &h0003  ' 32-bit address w/o image base (RVA).
Const IMAGE_REL_CEE_SECTION         = &h0004  ' Section index
Const IMAGE_REL_CEE_SECREL          = &h0005  ' 32 bit offset from base of section containing target
Const IMAGE_REL_CEE_TOKEN           = &h0006  ' 32 bit metadata token


Const IMAGE_REL_M32R_ABSOLUTE       = &h0000  ' No relocation required
Const IMAGE_REL_M32R_ADDR32         = &h0001  ' 32 bit address
Const IMAGE_REL_M32R_ADDR32NB       = &h0002  ' 32 bit address w/o image base
Const IMAGE_REL_M32R_ADDR24         = &h0003  ' 24 bit address
Const IMAGE_REL_M32R_GPREL16        = &h0004  ' GP relative addressing
Const IMAGE_REL_M32R_PCREL24        = &h0005  ' 24 bit offset << 2 & sign ext.
Const IMAGE_REL_M32R_PCREL16        = &h0006  ' 16 bit offset << 2 & sign ext.
Const IMAGE_REL_M32R_PCREL8         = &h0007  ' 8 bit offset << 2 & sign ext.
Const IMAGE_REL_M32R_REFHALF        = &h0008  ' 16 MSBs
Const IMAGE_REL_M32R_REFHI          = &h0009  ' 16 MSBs; adj for LSB sign ext.
Const IMAGE_REL_M32R_REFLO          = &h000A  ' 16 LSBs
Const IMAGE_REL_M32R_PAIR           = &h000B  ' Link HI and LO
Const IMAGE_REL_M32R_SECTION        = &h000C  ' Section table index
Const IMAGE_REL_M32R_SECREL32       = &h000D  ' 32 bit section relative reference
Const IMAGE_REL_M32R_TOKEN          = &h000E  ' clr token

Const IMAGE_REL_EBC_ABSOLUTE        = &h0000  ' No relocation required
Const IMAGE_REL_EBC_ADDR32NB        = &h0001  ' 32 bit address w/o image base
Const IMAGE_REL_EBC_REL32           = &h0002  ' 32-bit relative address from byte following reloc
Const IMAGE_REL_EBC_SECTION         = &h0003  ' Section table index
Const IMAGE_REL_EBC_SECREL          = &h0004  ' Offset within section

'Const EXT_IMM64(Value, Address, Size, InstPos, ValPos)  /* Intel-IA64-Filler * /           \
'    Value |= (((ULONGLONG)((*(Address) >> InstPos) & (((ULONGLONG)1 << Size) - 1))) << ValPos)  // Intel-IA64-Filler

'Const INS_IMM64(Value, Address, Size, InstPos, ValPos)  /* Intel-IA64-Filler * /\
'    *(PDWORD)Address = (*(PDWORD)Address & ~(((1 << Size) - 1) << InstPos)) | /* Intel-IA64-Filler * /\
'          ((DWORD)((((ULONGLONG)Value >> ValPos) & (((ULONGLONG)1 << Size) - 1))) << InstPos)  // Intel-IA64-Filler

Const EMARCH_ENC_I17_IMM7B_INST_WORD_X       = 3  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM7B_SIZE_X            = 7  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM7B_INST_WORD_POS_X   = 4  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM7B_VAL_POS_X         = 0  ' Intel-IA64-Filler

Const EMARCH_ENC_I17_IMM9D_INST_WORD_X       = 3  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM9D_SIZE_X            = 9  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM9D_INST_WORD_POS_X   = 18 ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM9D_VAL_POS_X         = 7  ' Intel-IA64-Filler

Const EMARCH_ENC_I17_IMM5C_INST_WORD_X       = 3  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM5C_SIZE_X            = 5  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM5C_INST_WORD_POS_X   = 13 ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM5C_VAL_POS_X         = 16 ' Intel-IA64-Filler

Const EMARCH_ENC_I17_IC_INST_WORD_X          = 3  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IC_SIZE_X               = 1  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IC_INST_WORD_POS_X      = 12 ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IC_VAL_POS_X            = 21 ' Intel-IA64-Filler

Const EMARCH_ENC_I17_IMM41a_INST_WORD_X      = 1  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM41a_SIZE_X           = 10 ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM41a_INST_WORD_POS_X  = 14 ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM41a_VAL_POS_X        = 22 ' Intel-IA64-Filler

Const EMARCH_ENC_I17_IMM41b_INST_WORD_X      = 1  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM41b_SIZE_X           = 8  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM41b_INST_WORD_POS_X  = 24 ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM41b_VAL_POS_X        = 32 ' Intel-IA64-Filler

Const EMARCH_ENC_I17_IMM41c_INST_WORD_X      = 2  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM41c_SIZE_X           = 23 ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM41c_INST_WORD_POS_X  = 0  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_IMM41c_VAL_POS_X        = 40 ' Intel-IA64-Filler

Const EMARCH_ENC_I17_SIGN_INST_WORD_X        = 3  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_SIGN_SIZE_X             = 1  ' Intel-IA64-Filler
Const EMARCH_ENC_I17_SIGN_INST_WORD_POS_X    = 27 ' Intel-IA64-Filler
Const EMARCH_ENC_I17_SIGN_VAL_POS_X          = 63 ' Intel-IA64-Filler

Const X3_OPCODE_INST_WORD_X                  = 3  ' Intel-IA64-Filler
Const X3_OPCODE_SIZE_X                       = 4  ' Intel-IA64-Filler
Const X3_OPCODE_INST_WORD_POS_X              = 28 ' Intel-IA64-Filler
Const X3_OPCODE_SIGN_VAL_POS_X               = 0  ' Intel-IA64-Filler

Const X3_I_INST_WORD_X                       = 3  ' Intel-IA64-Filler
Const X3_I_SIZE_X                            = 1  ' Intel-IA64-Filler
Const X3_I_INST_WORD_POS_X                   = 27 ' Intel-IA64-Filler
Const X3_I_SIGN_VAL_POS_X                    = 59 ' Intel-IA64-Filler

Const X3_D_WH_INST_WORD_X                    = 3  ' Intel-IA64-Filler
Const X3_D_WH_SIZE_X                         = 3  ' Intel-IA64-Filler
Const X3_D_WH_INST_WORD_POS_X                = 24 ' Intel-IA64-Filler
Const X3_D_WH_SIGN_VAL_POS_X                 = 0  ' Intel-IA64-Filler

Const X3_IMM20_INST_WORD_X                   = 3  ' Intel-IA64-Filler
Const X3_IMM20_SIZE_X                        = 20 ' Intel-IA64-Filler
Const X3_IMM20_INST_WORD_POS_X               = 4  ' Intel-IA64-Filler
Const X3_IMM20_SIGN_VAL_POS_X                = 0  ' Intel-IA64-Filler

Const X3_IMM39_1_INST_WORD_X                 = 2  ' Intel-IA64-Filler
Const X3_IMM39_1_SIZE_X                      = 23 ' Intel-IA64-Filler
Const X3_IMM39_1_INST_WORD_POS_X             = 0  ' Intel-IA64-Filler
Const X3_IMM39_1_SIGN_VAL_POS_X              = 36 ' Intel-IA64-Filler

Const X3_IMM39_2_INST_WORD_X                 = 1  ' Intel-IA64-Filler
Const X3_IMM39_2_SIZE_X                      = 16 ' Intel-IA64-Filler
Const X3_IMM39_2_INST_WORD_POS_X             = 16 ' Intel-IA64-Filler
Const X3_IMM39_2_SIGN_VAL_POS_X              = 20 ' Intel-IA64-Filler

Const X3_P_INST_WORD_X                       = 3  ' Intel-IA64-Filler
Const X3_P_SIZE_X                            = 4  ' Intel-IA64-Filler
Const X3_P_INST_WORD_POS_X                   = 0  ' Intel-IA64-Filler
Const X3_P_SIGN_VAL_POS_X                    = 0  ' Intel-IA64-Filler

Const X3_TMPLT_INST_WORD_X                   = 0  ' Intel-IA64-Filler
Const X3_TMPLT_SIZE_X                        = 4  ' Intel-IA64-Filler
Const X3_TMPLT_INST_WORD_POS_X               = 0  ' Intel-IA64-Filler
Const X3_TMPLT_SIGN_VAL_POS_X                = 0  ' Intel-IA64-Filler

Const X3_BTYPE_QP_INST_WORD_X                = 2  ' Intel-IA64-Filler
Const X3_BTYPE_QP_SIZE_X                     = 9  ' Intel-IA64-Filler
Const X3_BTYPE_QP_INST_WORD_POS_X            = 23 ' Intel-IA64-Filler
Const X3_BTYPE_QP_INST_VAL_POS_X             = 0  ' Intel-IA64-Filler

Const X3_EMPTY_INST_WORD_X                   = 1  ' Intel-IA64-Filler
Const X3_EMPTY_SIZE_X                        = 2  ' Intel-IA64-Filler
Const X3_EMPTY_INST_WORD_POS_X               = 14 ' Intel-IA64-Filler
Const X3_EMPTY_INST_VAL_POS_X                = 0  ' Intel-IA64-Filler

' Line number format.
Type Align(2) IMAGE_LINENUMBER
'	Union
		SymbolTableIndex As DWord
'		VirtualAddress As DWord
'	End Union
	Linenumber As Word
End Type
TypeDef PIMAGE_LINENUMBER = * /*UNALIGNED*/ IMAGE_LINENUMBER

' Based relocation format.
Type IMAGE_BASE_RELOCATION
	VirtualAddress As DWord
	SizeOfBlock As DWord
'	TypeOffset[ELM(1)] As Word
End Type
TypeDef PIMAGE_BASE_RELOCATION = * /*UNALIGNED*/ IMAGE_BASE_RELOCATION

' Based relocation types.
Const IMAGE_REL_BASED_ABSOLUTE = 0
Const IMAGE_REL_BASED_HIGH = 1
Const IMAGE_REL_BASED_LOW = 2
Const IMAGE_REL_BASED_HIGHLOW = 3
Const IMAGE_REL_BASED_HIGHADJ = 4
Const IMAGE_REL_BASED_MIPS_JMPADDR = 5
Const IMAGE_REL_BASED_MIPS_JMPADDR16 = 9
Const IMAGE_REL_BASED_IA64_IMM64 = 9
Const IMAGE_REL_BASED_DIR64 = 10

' Archive format.
Const IMAGE_ARCHIVE_START_SIZE = 8
Const IMAGE_ARCHIVE_START = Ex"!<arch>\n"
Const IMAGE_ARCHIVE_END = Ex"`\n"
Const IMAGE_ARCHIVE_PAD = Ex"\n"
Const IMAGE_ARCHIVE_LINKER_MEMBER = Ex"/               "
Const IMAGE_ARCHIVE_LONGNAMES_MEMBER = Ex"//              "

Type IMAGE_ARCHIVE_MEMBER_HEADER
	Name[ELM(16)] As Byte
	Date[ELM(12)] As Byte
	UserID[ELM(6)] As Byte
	GroupID[ELM(6)] As Byte
	Mode[ELM(8)] As Byte
	Size[ELM(10)] As Byte
	EndHeader[ELM(2)] As Byte
End Type
TypeDef PIMAGE_ARCHIVE_MEMBER_HEADER = *IMAGE_ARCHIVE_MEMBER_HEADER

Const IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR = 60

' DLL support.

' Export Format
Type IMAGE_EXPORT_DIRECTORY
	Characteristics As DWord
	TimeDateStamp As DWord
	MajorVersion As DWord
	MinorVersion As DWord
	Name As Word
	Base As Word
	NumberOfFunctions As DWord
	NumberOfNames As DWord
	AddressOfFunctions As DWord
	AddressOfNames As DWord
	AddressOfNameOrdinals As DWord
End Type
TypeDef PIMAGE_EXPORT_DIRECTORY = *IMAGE_EXPORT_DIRECTORY

' Import Format
Type IMAGE_IMPORT_BY_NAME
	Hint As Word
	Name[ELM(1)] As Byte
End Type
TypeDef PIMAGE_IMPORT_BY_NAME = *IMAGE_IMPORT_BY_NAME

Type Align(8) IMAGE_THUNK_DATA64
'	Union
		ForwarderString As QWord 'PBYTE
'		Function_ As QWord 'PDWORD
'		Ordinal As QWord
'		AddressOfData As QWord 'PIMAGE_IMPORT_BY_NAME
'	} u1
End Type
TypeDef PIMAGE_THUNK_DATA64 = *IMAGE_THUNK_DATA64

Type IMAGE_THUNK_DATA32
'	Union
		ForwarderString As DWORD 'PBYTE
'		Function_ As DWORD 'PDWORD
'		Ordinal As DWORD
'		AddressOfData As DWORD 'PIMAGE_IMPORT_BY_NAME
'	} u1
End Type
TypeDef PIMAGE_THUNK_DATA32 = *IMAGE_THUNK_DATA32

Const IMAGE_ORDINAL_FLAG64 = &h8000000000000000
Const IMAGE_ORDINAL_FLAG32 = &h80000000
Const IMAGE_ORDINAL64(Ordinal) = (Ordinal And &hffff)
Const IMAGE_ORDINAL32(Ordinal) = (Ordinal And &hffff)
Const IMAGE_SNAP_BY_ORDINAL64(Ordinal) = ((Ordinal And IMAGE_ORDINAL_FLAG64) <> 0)
Const IMAGE_SNAP_BY_ORDINAL32(Ordinal) = ((Ordinal And IMAGE_ORDINAL_FLAG32) <> 0)

' Thread Local Storage
TypeDef PIMAGE_TLS_CALLBACK = *Sub(DllHandle As PVOID, Reason As DWord, Reserved As PVOID)

Type IMAGE_TLS_DIRECTORY64
	StartAddressOfRawData As QWord
	EndAddressOfRawData As QWord
	AddressOfIndex As QWord 'PDWORD
	AddressOfCallBacks As QWord 'PIMAGE_TLS_CALLBACK *
	SizeOfZeroFill As DWord
	Characteristics As DWord
End Type
TypeDef PIMAGE_TLS_DIRECTORY64 = *IMAGE_TLS_DIRECTORY64

Type IMAGE_TLS_DIRECTORY32
	StartAddressOfRawData As DWord
	EndAddressOfRawData As DWord
	AddressOfIndex As DWord 'PDWORD
	AddressOfCallBacks As DWord 'PIMAGE_TLS_CALLBACK *
	SizeOfZeroFill As DWord
	Characteristics As DWord
End Type
TypeDef PIMAGE_TLS_DIRECTORY32 = *IMAGE_TLS_DIRECTORY32

#ifdef _WIN64
Const IMAGE_ORDINAL_FLAG = IMAGE_ORDINAL_FLAG64
Const IMAGE_ORDINAL(Ordinal) = IMAGE_ORDINAL64(Ordinal)
TypeDef IMAGE_THUNK_DATA = IMAGE_THUNK_DATA64
TypeDef PIMAGE_THUNK_DATA = PIMAGE_THUNK_DATA64
Const IMAGE_SNAP_BY_ORDINAL(Ordinal) = IMAGE_SNAP_BY_ORDINAL64(Ordinal)
TypeDef IMAGE_TLS_DIRECTORY = IMAGE_TLS_DIRECTORY64
TypeDef PIMAGE_TLS_DIRECTORY = PIMAGE_TLS_DIRECTORY64
#else
Const IMAGE_ORDINAL_FLAG = IMAGE_ORDINAL_FLAG32
Const IMAGE_ORDINAL(Ordinal) = IMAGE_ORDINAL32(Ordinal)
TypeDef IMAGE_THUNK_DATA = IMAGE_THUNK_DATA32
TypeDef PIMAGE_THUNK_DATA = PIMAGE_THUNK_DATA32
Const IMAGE_SNAP_BY_ORDINAL(Ordinal) = IMAGE_SNAP_BY_ORDINAL32(Ordinal)
TypeDef IMAGE_TLS_DIRECTORY = IMAGE_TLS_DIRECTORY32
TypeDef PIMAGE_TLS_DIRECTORY = PIMAGE_TLS_DIRECTORY32
#endif

Type IMAGE_IMPORT_DESCRIPTOR
'	Union
		Characteristics As DWord
'		OriginalFirstThunk As DWord
'	End Union
	TimeDateStamp As DWord
	ForwarderChain As DWord
	Name As DWord
	FirstThunk As DWord
End Type
TypeDef PIMAGE_IMPORT_DESCRIPTOR = * /*UNALIGNED*/ IMAGE_IMPORT_DESCRIPTOR

' New format import descriptors pointed to by DataDirectory[ IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT ]
Type IMAGE_BOUND_IMPORT_DESCRIPTOR
	TimeDateStamp As DWord
	OffsetModuleName As Word
	NumberOfModuleForwarderRefs As Word
End Type
TypeDef PIMAGE_BOUND_IMPORT_DESCRIPTOR = IMAGE_BOUND_IMPORT_DESCRIPTOR

Type IMAGE_BOUND_FORWARDER_REF
	TimeDateStamp As DWord
	OffsetModuleName As Word
	Reserved As Word
End Type
TypeDef PIMAGE_BOUND_FORWARDER_REF = *IMAGE_BOUND_FORWARDER_REF

' Resource Format.
Type IMAGE_RESOURCE_DIRECTORY
	Characteristics As DWord
	TimeDateStamp As DWord
	MajorVersion As Word
	MinorVersion As Word
	NumberOfNamedEntries As Word
	NumberOfIdEntries As Word
End Type
TypeDef PIMAGE_RESOURCE_DIRECTORY = *IMAGE_RESOURCE_DIRECTORY

Const IMAGE_RESOURCE_NAME_IS_STRING = &h80000000
Const IMAGE_RESOURCE_DATA_IS_DIRECTORY = &h80000000

Type IMAGE_RESOURCE_DIRECTORY_ENTRY
'	Union
'		Type
'			NameOffset : 31 As DWord
'			NameIsString :  As DWord
'		End Type
		Name As DWord
'		Id As DWord
'	End Union
'	Union
		OffsetToData As DWord
'		Type
'			OffsetToDirectory : 31 As DWord
'			DataIsDirectory : 1 As DWord
'		End Type
'	End Union
End Type
TypeDef PIMAGE_RESOURCE_DIRECTORY_ENTRY = *IMAGE_RESOURCE_DIRECTORY_ENTRY

Type IMAGE_RESOURCE_DIRECTORY_STRING
	Length As Word
	NameString[ELM(1)] As CHAR
End Type
TypeDef PIMAGE_RESOURCE_DIRECTORY_STRING = *IMAGE_RESOURCE_DIRECTORY_STRING

Type IMAGE_RESOURCE_DIR_STRING_U
	Length As Word
	NameString[ELM(1)] As WCHAR
End Type
TypeDef PIMAGE_RESOURCE_DIR_STRING_U = *IMAGE_RESOURCE_DIR_STRING_U

Type IMAGE_RESOURCE_DATA_ENTRY
	OffsetToData As DWord
	Size As DWord
	CodePage As DWord
	Reserved As DWord
End Type
TypeDef PIMAGE_RESOURCE_DATA_ENTRY = *IMAGE_RESOURCE_DATA_ENTRY

' Load Configuration Directory Entry

Type IMAGE_LOAD_CONFIG_DIRECTORY32
	Size As DWord
	TimeDateStamp As DWord
	MajorVersion As Word
	MinorVersion As Word
	GlobalFlagsClear As DWord
	GlobalFlagsSet As DWord
	CriticalSectionDefaultTimeout As DWord
	DeCommitFreeBlockThreshold As DWord
	DeCommitTotalFreeThreshold As DWord
	LockPrefixTable As DWord
	MaximumAllocationSize As DWord
	VirtualMemoryThreshold As DWord
	ProcessHeapFlags As DWord
	ProcessAffinityMask As DWord
	CSDVersion As Word
	Reserved1 As Word
	EditList As DWord
	SecurityCookie As DWord
	SEHandlerTable As DWord
	SEHandlerCount As DWord
End Type
TypeDef PIMAGE_LOAD_CONFIG_DIRECTORY32 = *IMAGE_LOAD_CONFIG_DIRECTORY32

Type IMAGE_LOAD_CONFIG_DIRECTORY64
	Size As DWord
	TimeDateStamp As DWord
	MajorVersion As Word
	MinorVersion As Word
	GlobalFlagsClear As DWord
	GlobalFlagsSet As DWord
	CriticalSectionDefaultTimeout As DWord
	DeCommitFreeBlockThreshold As QWord
	DeCommitTotalFreeThreshold As QWord
	LockPrefixTable As QWord
	MaximumAllocationSize As QWord
	VirtualMemoryThreshold As QWord
	ProcessAffinityMask As QWord
	ProcessHeapFlags As DWord
	CSDVersion As Word
	Reserved1 As Word
	EditList As QWord
	SecurityCookie As QWord
	SEHandlerTable As QWord
	SEHandlerCount As QWord
End Type
TypeDef PIMAGE_LOAD_CONFIG_DIRECTORY64 = *IMAGE_LOAD_CONFIG_DIRECTORY64

#ifdef _WIN64
TypeDef IMAGE_LOAD_CONFIG_DIRECTORY = IMAGE_LOAD_CONFIG_DIRECTORY64
TypeDef PIMAGE_LOAD_CONFIG_DIRECTORY = PIMAGE_LOAD_CONFIG_DIRECTORY64
#else
TypeDef IMAGE_LOAD_CONFIG_DIRECTORY = IMAGE_LOAD_CONFIG_DIRECTORY32
TypeDef PIMAGE_LOAD_CONFIG_DIRECTORY = PIMAGE_LOAD_CONFIG_DIRECTORY32
#endif

' WIN CE Exception table format

' Function table entry format

Type IMAGE_CE_RUNTIME_FUNCTION_ENTRY
	FuncStart As DWord
	dummy As DWord
'	PrologLen : 8 As DWord
'	FuncLen : 22 As DWord
'	ThirtyTwoBit : 1 As DWord
'	ExceptionFlag : 1 As DWord
End Type
TypeDef PIMAGE_CE_RUNTIME_FUNCTION_ENTRY = *IMAGE_CE_RUNTIME_FUNCTION_ENTRY

Type IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY
	BeginAddress As QWord
	EndAddress As QWord
	ExceptionHandler As QWord
	HandlerData As QWord
	PrologEndAddress As QWord
End Type
TypeDef PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY = *IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY

Type IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY
	BeginAddress As DWord
	EndAddress As DWord
	ExceptionHandler As DWord
	HandlerData As DWord
	PrologEndAddress As DWord
End Type
TypeDef PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY = *IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY

Type _IMAGE_RUNTIME_FUNCTION_ENTRY
	BeginAddress As DWord
	EndAddress As DWord
	UnwindInfoAddress As DWord
End Type
TypeDef _PIMAGE_RUNTIME_FUNCTION_ENTRY = *_IMAGE_RUNTIME_FUNCTION_ENTRY

TypeDef IMAGE_IA64_RUNTIME_FUNCTION_ENTRY = _IMAGE_RUNTIME_FUNCTION_ENTRY
TypeDef PIMAGE_IA64_RUNTIME_FUNCTION_ENTRY = _PIMAGE_RUNTIME_FUNCTION_ENTRY

TypeDef IMAGE_RUNTIME_FUNCTION_ENTRY = _IMAGE_RUNTIME_FUNCTION_ENTRY
TypeDef PIMAGE_RUNTIME_FUNCTION_ENTRY = _PIMAGE_RUNTIME_FUNCTION_ENTRY

' Debug Format
Type IMAGE_DEBUG_DIRECTORY
	Characteristics As DWord
	TimeDateStamp As DWord
	MajorVersion As Word
	MinorVersion As Word
	Type_ As DWord
	SizeOfData As DWord
	AddressOfRawData As DWord
	PointerToRawData As DWord
End Type
TypeDef PIMAGE_DEBUG_DIRECTORY = *IMAGE_DEBUG_DIRECTORY

Const IMAGE_DEBUG_TYPE_UNKNOWN = 0
Const IMAGE_DEBUG_TYPE_COFF = 1
Const IMAGE_DEBUG_TYPE_CODEVIEW = 2
Const IMAGE_DEBUG_TYPE_FPO = 3
Const IMAGE_DEBUG_TYPE_MISC = 4
Const IMAGE_DEBUG_TYPE_EXCEPTION = 5
Const IMAGE_DEBUG_TYPE_FIXUP = 6
Const IMAGE_DEBUG_TYPE_OMAP_TO_SRC = 7
Const IMAGE_DEBUG_TYPE_OMAP_FROM_SRC = 8
Const IMAGE_DEBUG_TYPE_BORLAND = 9
Const IMAGE_DEBUG_TYPE_RESERVED10 = 10
Const IMAGE_DEBUG_TYPE_CLSID = 11

Type IMAGE_COFF_SYMBOLS_HEADER
	NumberOfSymbols As DWord
	LvaToFirstSymbol As DWord
	NumberOfLinenumbers As DWord
	LvaToFirstLinenumber As DWord
	RvaToFirstByteOfCode As DWord
	RvaToLastByteOfCode As DWord
	RvaToFirstByteOfData As DWord
	RvaToLastByteOfData As DWord
End Type
TypeDef PIMAGE_COFF_SYMBOLS_HEADER = *IMAGE_COFF_SYMBOLS_HEADER

Const FRAME_FPO = 0
Const FRAME_TRAP = 1
Const FRAME_TSS = 2
Const FRAME_NONFPO = 3

Type FPO_DATA
	ulOffStart As DWord
	cbProcSize As DWord
	cdwLocals As DWord
	cdwParams As Word
	dummy As Word
'	cbProlog : 8 As Word
'	cbRegs   : 3 As Word
'	fHasSEH  : 1 As Word
'	fUseBP   : 1 As Word
'	reserved : 1 As Word
'	cbFrame  : 2 As Word
End Type
TypeDef PFPO_DATA = *FPO_DATA
Const SIZEOF_RFPO_DATA = 16

Const IMAGE_DEBUG_MISC_EXENAME = 1

Type IMAGE_DEBUG_MISC
	DataType As DWord
	Length As DWord
	Unicode As BOOLEAN
	Reserved[ELM(3)] As Byte
	Data[ELM(1)] As Byte
End Type
TypeDef PIMAGE_DEBUG_MISC = *IMAGE_DEBUG_MISC

Type IMAGE_FUNCTION_ENTRY
	StartingAddress As DWord
	EndingAddress As DWord
	EndOfPrologue As DWord
End Type
TypeDef PIMAGE_FUNCTION_ENTRY = *IMAGE_FUNCTION_ENTRY

Type IMAGE_FUNCTION_ENTRY64
	StartingAddress As QWord
	EndingAddress As QWord
'	Union
		EndOfPrologue As QWord
'		UnwindInfoAddress As QWord
'End Union
End Type
TypeDef PIMAGE_FUNCTION_ENTRY64 = *IMAGE_FUNCTION_ENTRY64

Type IMAGE_SEPARATE_DEBUG_HEADER
	Signature As Word
	Flags As Word
	Machine As Word
	Characteristics As Word
	TimeDateStamp As DWord
	CheckSum As DWord
	ImageBase As DWord
	SizeOfImage As DWord
	NumberOfSections As DWord
	ExportedNamesSize As DWord
	DebugDirectorySize As DWord
	SectionAlignment As DWord
	Reserved[ELM(2)] As DWord
End Type
TypeDef PIMAGE_SEPARATE_DEBUG_HEADER = *IMAGE_SEPARATE_DEBUG_HEADER

Type NON_PAGED_DEBUG_INFO
	Signature As Word
	Flags As Word
	Size As DWord
	Machine As Word
	Characteristics As Word
	TimeDateStamp As DWord
	CheckSum As DWord
	SizeOfImage As DWord
	ImageBase As QWord
End Type
TypeDef PNON_PAGED_DEBUG_INFO = *NON_PAGED_DEBUG_INFO

Const IMAGE_SEPARATE_DEBUG_SIGNATURE = &h4449 'DI
Const NON_PAGED_DEBUG_SIGNATURE = &h4E49 ' NI

Const IMAGE_SEPARATE_DEBUG_FLAGS_MASK = &h8000
Const IMAGE_SEPARATE_DEBUG_MISMATCH = &h8000

Type IMAGE_ARCHITECTURE_HEADER
	AmaskValue As Byte
'	AmaskValue: 1 As DWord
'	: 7 As Long
	AmaskShift As Byte
'	AmaskShift: 8 As DWord
	dummy As Word
'	: 16 As Long
	FirstEntryRVA As DWord
End Type
TypeDef PIMAGE_ARCHITECTURE_HEADER = *IMAGE_ARCHITECTURE_HEADER

Type IMAGE_ARCHITECTURE_ENTRY
	FixupInstRVA As DWord
	NewInst As DWord
End Type
TypeDef PIMAGE_ARCHITECTURE_ENTRY = *IMAGE_ARCHITECTURE_ENTRY

Const IMPORT_OBJECT_HDR_SIG2 = &hffff

Type IMPORT_OBJECT_HEADER
	Sig1 As Word
	Sig2 As Word
	Version As Word
	Machine As Word
	TimeDateStamp As DWord
	SizeOfData As DWord

'	Union
		Ordinal As Word
'		Hint As Word
'	End Union

	Reserved As Word
'	Type : 2 As Word
'	NameType : 3 As Word
'	Reserved : 11 As Word
End Type

Enum IMPORT_OBJECT_TYPE
	IMPORT_OBJECT_CODE = 0
	IMPORT_OBJECT_DATA = 1
	IMPORT_OBJECT_CONST = 2
End Enum

Enum IMPORT_OBJECT_NAME_TYPE
	IMPORT_OBJECT_ORDINAL = 0
	IMPORT_OBJECT_NAME = 1
	IMPORT_OBJECT_NAME_NO_PREFIX = 2
	IMPORT_OBJECT_NAME_UNDECORATE = 3
End Enum

#ifndef __IMAGE_COR20_HEADER_DEFINED__
#define __IMAGE_COR20_HEADER_DEFINED__

Enum ReplacesCorHdrNumericDefines
' COM+ Header entry point flags.
	COMIMAGE_FLAGS_ILONLY               = &h00000001
	COMIMAGE_FLAGS_32BITREQUIRED        = &h00000002
	COMIMAGE_FLAGS_IL_LIBRARY           = &h00000004
	COMIMAGE_FLAGS_STRONGNAMESIGNED     = &h00000008
	COMIMAGE_FLAGS_TRACKDEBUGDATA       = &h00010000
' Version flags for image.
	COR_VERSION_MAJOR_V2                = 2
	COR_VERSION_MAJOR                   = COR_VERSION_MAJOR_V2
	COR_VERSION_MINOR                   = 0
	COR_DELETED_NAME_LENGTH             = 8
	COR_VTABLEGAP_NAME_LENGTH           = 8
' Maximum size of a NativeType descriptor.
	NATIVE_TYPE_MAX_CB                  = 1
	COR_ILMETHOD_SECT_SMALL_MAX_DATASIZE= &hFF
' Consts for the MIH FLAGS
	IMAGE_COR_MIH_METHODRVA             = &h01
	IMAGE_COR_MIH_EHRVA                 = &h02
	IMAGE_COR_MIH_BASICBLOCK            = &h08
' V-table constants
	COR_VTABLE_32BIT                    = &h01          ' V-table slots are 32-bits in size.
	COR_VTABLE_64BIT                    = &h02          ' V-table slots are 64-bits in size.
	COR_VTABLE_FROM_UNMANAGED           = &h04          ' If set, transition from unmanaged.
	COR_VTABLE_FROM_UNMANAGED_RETAIN_APPDOMAIN  = &h08  ' If set, transition from unmanaged with keeping the current appdomain.
	COR_VTABLE_CALL_MOST_DERIVED        = &h10          ' Call most derived method described by
' EATJ constants
	IMAGE_COR_EATJ_THUNK_SIZE           = 32            ' Size of a jump thunk reserved range.
' Max name lengths
	'@todo: Change to unlimited name lengths.
	MAX_CLASS_NAME                      = 1024
	MAX_PACKAGE_NAME                    = 1024
End Enum

' CLR 2.0 header structure.
Type IMAGE_COR20_HEADER
	' Header versioning
	cb As DWord
	MajorRuntimeVersion As Word
	MinorRuntimeVersion As Word
	' Symbol table and startup information
	MetaData As IMAGE_DATA_DIRECTORY
	Flags As DWord
	EntryPointToken As DWord
	' Binding information
	Resources As IMAGE_DATA_DIRECTORY
	StrongNameSignature As IMAGE_DATA_DIRECTORY
	' Regular fixup and binding information
	CodeManagerTable As IMAGE_DATA_DIRECTORY
	VTableFixups As IMAGE_DATA_DIRECTORY
	ExportAddressTableJumps As IMAGE_DATA_DIRECTORY
	' Precompiled image info (internal use only - set to zero)
	ManagedNativeHeader As IMAGE_DATA_DIRECTORY
End Type
TypeDef PIMAGE_COR20_HEADER = *IMAGE_COR20_HEADER

#endif

#ifdef _WIN64
Type Align(16) SLIST_ENTRY
	Next_ As *SLIST_ENTRY
End Type
TypeDef PSLIST_ENTRY = *SLIST_ENTRY
#else
TypeDef SLIST_ENTRY = SINGLE_LIST_ENTRY
'TypeDef _SLIST_ENTRY = _SINGLE_LIST_ENTRY
TypeDef PSLIST_ENTRY = PSINGLE_LIST_ENTRY
#endif

#ifdef _WIN64

Type /*Union*/ Align(16) SLIST_HEADER
'	Type ' original struct
		Alignment As QWord
		Region As QWord
'	End Type
'	Type ' 8-byte header
'		Depth:16 As QWord
'		Sequence:9 As QWord
'		NextEntry:39 As QWord
'		HeaderType:1 As QWord ' 0: 8-byte As QWord 1: 16-byte
'		Init:1 As QWord       ' 0: uninitialized As QWord 1: initialized
'		Reserved:59 As QWord
'		Region:3 As QWord
'	} Header8
'	Type ' 16-byte header
'		Depth:16 As QWord
'		Sequence:48 As QWord
'		HeaderType:1 As QWord ' 0: 8-byte As QWord 1: 16-byte
'		Init:1 As QWord       ' 0: uninitialized As QWord 1: initialized
'		Reserved:2 As QWord
'		NextEntry:60 As QWord ' last 4 bits are always 0's
'	} Header16
End Type 'Union
TypeDef PSLIST_HEADER = *SLIST_HEADER

#else

Type /*Union*/ SLIST_HEADER
'	Alignment As QWord
'	Type
		Next_ As SLIST_ENTRY
		Depth As Word
		Sequence As Word
'	End Type
End Type 'Union
TypeDef PSLIST_HEADER = *SLIST_HEADER

#endif


Declare Sub RtlInitializeSListHead Lib "kernel32" (/*IN*/ ByRef ListHead As SLIST_HEADER)
Declare Function RtlFirstEntrySList Lib "kernel32" (/*IN*/ ByRef ListHead As /*Const*/ SLIST_HEADER) As PSLIST_ENTRY
Declare Function RtlInterlockedPopEntrySList Lib "kernel32" (/*IN*/ ByRef ListHead As SLIST_HEADER) As PSLIST_ENTRY
Declare Function RtlInterlockedPushEntrySList Lib "kernel32" (/*IN*/ ByRef ListHead As SLIST_HEADER, /*IN*/ ListEntry As PSLIST_ENTRY) As PSLIST_ENTRY
Declare Function RtlInterlockedFlushSList Lib "kernel32" (/*IN*/ ByRef ListHead As SLIST_HEADER) As PSLIST_ENTRY
Declare Function RtlQueryDepthSList Lib "kernel32" (/*IN*/ ByRef ListHead As SLIST_HEADER) As Word

'Const RTL_RUN_ONCE_INIT {0} 'Static initializer

Const RTL_RUN_ONCE_CHECK_ONLY = &h00000001
Const RTL_RUN_ONCE_ASYNC = &h00000002
Const RTL_RUN_ONCE_INIT_FAILED = &h00000004

Const RTL_RUN_ONCE_CTX_RESERVED_BITS = 2

Type /*Union*/ RTL_RUN_ONCE
	Ptr As VoidPtr
End Type 'Union
TypeDef PRTL_RUN_ONCE = *RTL_RUN_ONCE

TypeDef PRTL_RUN_ONCE_INIT_FN = *Function(ByRef RunOnce As RTL_RUN_ONCE, Parameter As VoidPtr, ByRef Context As VoidPtr) As DWord'LOGICAL

Declare Sub RtlRunOnceInitialize Lib "kernel32" (ByRef RunOnce As RTL_RUN_ONCE)
Declare Function RtlRunOnceExecuteOnce Lib "kernel32" (ByRef RunOnce As RTL_RUN_ONCE, InitFn As PRTL_RUN_ONCE_INIT_FN, Parameter As PVOID, ByRef Context As PVOID) As DWord
Declare Function RtlRunOnceBeginInitialize Lib "kernel32" (ByRef RunOnce As RTL_RUN_ONCE, Flags As DWord, ByRef Context As PVOID) As DWord
Declare Function RtlRunOnceComplete Lib "kernel32" (ByRef RunOnce As RTL_RUN_ONCE, Flags As DWord, Context As PVOID) As DWord

Const HEAP_NO_SERIALIZE = &h00000001
Const HEAP_GROWABLE = &h00000002
Const HEAP_GENERATE_EXCEPTIONS = &h00000004
Const HEAP_ZERO_MEMORY = &h00000008
Const HEAP_REALLOC_IN_PLACE_ONLY = &h00000010
Const HEAP_TAIL_CHECKING_ENABLED = &h00000020
Const HEAP_FREE_CHECKING_ENABLED = &h00000040
Const HEAP_DISABLE_COALESCE_ON_FREE = &h00000080
Const HEAP_CREATE_ALIGN_16 = &h00010000
Const HEAP_CREATE_ENABLE_TRACING = &h00020000
Const HEAP_CREATE_ENABLE_EXECUTE = &h00040000
Const HEAP_MAXIMUM_TAG = &h0FFF
Const HEAP_PSEUDO_TAG_FLAG = &h8000
Const HEAP_TAG_SHIFT = 18

Const HEAP_MAKE_TAG_FLAGS (TagBase /*As DWord*/, Tag /*As DWord*/) /*As DWord*/ = (((TagBase) + ((Tag) << HEAP_TAG_SHIFT)) As DWord)

'#if (NTDDI_VERSION > NTDDI_WINXP)
'Declare Function RtlCaptureStackBackTrace Lib "kernel32" (FramesToSkip As DWord, FramesToCapture A sDWord, ByRef BackTrace As PVOID, BackTraceHash As *DWord) As Word
'#endif

'#if (NTDDI_VERSION > NTDDI_WIN2K)
'Declare Sub RtlCaptureContext Lib "kernel32" (ByRef ContextRecord As CONTEXT)
'#endif

Const IS_TEXT_UNICODE_ASCII16 = &h0001
Const IS_TEXT_UNICODE_REVERSE_ASCII16 = &h0010

Const IS_TEXT_UNICODE_STATISTICS = &h0002
Const IS_TEXT_UNICODE_REVERSE_STATISTICS = &h0020

Const IS_TEXT_UNICODE_CONTROLS = &h0004
Const IS_TEXT_UNICODE_REVERSE_CONTROLS = &h0040

Const IS_TEXT_UNICODE_SIGNATURE = &h0008
Const IS_TEXT_UNICODE_REVERSE_SIGNATURE = &h0080

Const IS_TEXT_UNICODE_ILLEGAL_CHARS = &h0100
Const IS_TEXT_UNICODE_ODD_LENGTH = &h0200
Const IS_TEXT_UNICODE_DBCS_LEADBYTE = &h0400
Const IS_TEXT_UNICODE_NULL_BYTES = &h1000

Const IS_TEXT_UNICODE_UNICODE_MASK = &h000F
Const IS_TEXT_UNICODE_REVERSE_MASK = &h00F0
Const IS_TEXT_UNICODE_NOT_UNICODE_MASK = &h0F00
Const IS_TEXT_UNICODE_NOT_ASCII_MASK = &hF000

Const COMPRESSION_FORMAT_NONE = &h0000
Const COMPRESSION_FORMAT_DEFAULT = &h0001
Const COMPRESSION_FORMAT_LZNT1 = &h0002
Const COMPRESSION_ENGINE_STANDARD = &h0000
Const COMPRESSION_ENGINE_MAXIMUM = &h0100
Const COMPRESSION_ENGINE_HIBER = &h0200

'#if _DBG_MEMCPY_INLINE_ && !defined(MIDL_PASS) && !defined(_MEMCPY_INLINE_) && !defined(_CRTBLD)
'#define _MEMCPY_INLINE_
/*
FORCEINLINE
PVOID
__cdecl
memcpy_inline (
    void *dst,
    const void *src,
    size_t size
    )
{
    if (((char *)dst > (char *)src) &&
        ((char *)dst < ((char *)src + size))) {
        __debugbreak();
    }
    return memcpy(dst, src, size);
}
Const memcpy memcpy_inline
*/
'#endif

'#if (NTDDI_VERSION >= NTDDI_WIN2K)
'Declare Function RtlCompareMemory Lib "kernel32" (Source1 As VoidPtr, Source2 As VoidPtr, Length As SIZE_T) As SIZE_T
'#endif
/*
Const RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
Const RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
Const RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
Const RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
Const RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
*/
Function RtlSecureZeroMemory(ptr As VoidPtr, cnt As SIZE_T) As VoidPtr
	Dim vptr = ptr As * /*Volatile*/ Byte
#ifdef _WIN64
	FillMemory(vptr, cnt, 0)
#else

	While (cnt > 0)
		vptr = 0
		vptr++
		cnt--
	Wend
#endif
	RtlSecureZeroMemory = ptr
End Function

Const SEF_DACL_AUTO_INHERIT = &h01
Const SEF_SACL_AUTO_INHERIT = &h02
Const SEF_DEFAULT_DESCRIPTOR_FOR_OBJECT = &h04
Const SEF_AVOID_PRIVILEGE_CHECK = &h08
Const SEF_AVOID_OWNER_CHECK = &h10
Const SEF_DEFAULT_OWNER_FROM_PARENT = &h20
Const SEF_DEFAULT_GROUP_FROM_PARENT = &h40
Const SEF_MACL_NO_WRITE_UP = &h100
Const SEF_MACL_NO_READ_UP = &h200
Const SEF_MACL_NO_EXECUTE_UP = &h400
Const SEF_AVOID_OWNER_RESTRICTION = &h1000

Const SEF_MACL_VALID_FLAGS = (SEF_MACL_NO_WRITE_UP OR SEF_MACL_NO_READ_UP Or SEF_MACL_NO_EXECUTE_UP)

Type MESSAGE_RESOURCE_ENTRY
	Length As Word
	Flags As Word
	Text[ELM(1)] As Byte
End Type
TypeDef PMESSAGE_RESOURCE_ENTRY = *MESSAGE_RESOURCE_ENTRY

Const MESSAGE_RESOURCE_UNICODE = &h0001

Type MESSAGE_RESOURCE_BLOCK
	LowId As DWord
	HighId As DWord
	OffsetToEntries As DWord
End Type
TypeDef PMESSAGE_RESOURCE_BLOCK = *MESSAGE_RESOURCE_BLOCK

Type MESSAGE_RESOURCE_DATA
	NumberOfBlocks As DWord
	Blocks[ELM(1)] As MESSAGE_RESOURCE_BLOCK
End Type
TypeDef PMESSAGE_RESOURCE_DATA = *MESSAGE_RESOURCE_DATA

Type OSVERSIONINFOA
	dwOSVersionInfoSize As DWord
	dwMajorVersion As DWord
	dwMinorVersion As DWord
	dwBuildNumber As DWord
	dwPlatformId As DWord
	szCSDVersion[ELM(128)] As CHAR
End Type
TypeDef POSVERSIONINFOA = *OSVERSIONINFOA
TypeDef LPOSVERSIONINFOA = *OSVERSIONINFOA
Type OSVERSIONINFOW
	dwOSVersionInfoSize As DWord
	dwMajorVersion As DWord
	dwMinorVersion As DWord
	dwBuildNumber As DWord
	dwPlatformId As DWord
	szCSDVersion[ELM(128)] As WCHAR
End Type
TypeDef POSVERSIONINFOW = *OSVERSIONINFOW
TypeDef LPOSVERSIONINFOW = *OSVERSIONINFOW
TypeDef RTL_OSVERSIONINFOW = OSVERSIONINFOW
TypeDef PRTL_OSVERSIONINFOW = *OSVERSIONINFOW
#ifdef UNICODE
TypeDef OSVERSIONINFO = OSVERSIONINFOW
TypeDef POSVERSIONINFO = POSVERSIONINFOW
TypeDef LPOSVERSIONINFO = LPOSVERSIONINFOW
#else
TypeDef OSVERSIONINFO = OSVERSIONINFOA
TypeDef POSVERSIONINFO = POSVERSIONINFOA
TypeDef LPOSVERSIONINFO = LPOSVERSIONINFOA
#endif
Type OSVERSIONINFOEXA
	dwOSVersionInfoSize As DWord
	dwMajorVersion As DWord
	dwMinorVersion As DWord
	dwBuildNumber As DWord
	dwPlatformId As DWord
	szCSDVersion[ELM(128)] As CHAR
	wServicePackMajor As Word
	wServicePackMinor As Word
	wSuiteMask As Word
	wProductType As Byte
	wReserved As Byte
End Type
TypeDef POSVERSIONINFOEXA = *OSVERSIONINFOEXA
TypeDef LPOSVERSIONINFOEXA = *OSVERSIONINFOEXA
Type OSVERSIONINFOEXW
	dwOSVersionInfoSize As DWord
	dwMajorVersion As DWord
	dwMinorVersion As DWord
	dwBuildNumber As DWord
	dwPlatformId As DWord
	szCSDVersion[ELM(128)] As WCHAR
	wServicePackMajor As Word
	wServicePackMinor As Word
	wSuiteMask As Word
	wProductType As Byte
	wReserved As Byte
End Type
TypeDef POSVERSIONINFOEXW = *OSVERSIONINFOEXW
TypeDef LPOSVERSIONINFOEXW = *OSVERSIONINFOEXW
TypeDef RTL_OSVERSIONINFOEXW = OSVERSIONINFOEXW
TypeDef PRTL_OSVERSIONINFOEXW = *OSVERSIONINFOEXW
#ifdef UNICODE
TypeDef OSVERSIONINFOEX = OSVERSIONINFOEXW
TypeDef POSVERSIONINFOEX = POSVERSIONINFOEXW
TypeDef LPOSVERSIONINFOEX = LPOSVERSIONINFOEXW
#else
TypeDef OSVERSIONINFOEX = OSVERSIONINFOEXA
TypeDef POSVERSIONINFOEX = POSVERSIONINFOEXA
TypeDef LPOSVERSIONINFOEX = LPOSVERSIONINFOEXA
#endif

' RtlVerifyVersionInfo() conditions
Const VER_EQUAL = 1
Const VER_GREATER = 2
Const VER_GREATER_EQUAL = 3
Const VER_LESS = 4
Const VER_LESS_EQUAL = 5
Const VER_AND = 6
Const VER_OR = 7

Const VER_CONDITION_MASK = 7
Const VER_NUM_BITS_PER_CONDITION_MASK = 3

' RtlVerifyVersionInfo() type mask bits
Const VER_MINORVERSION = 0000001
Const VER_MAJORVERSION = 0000002
Const VER_BUILDNUMBER = 0000004
Const VER_PLATFORMID = 0000008
Const VER_SERVICEPACKMINOR = 0000010
Const VER_SERVICEPACKMAJOR = 0000020
Const VER_SUITENAME = 0000040
Const VER_PRODUCT_TYPE = 0000080

' RtlVerifyVersionInfo() os product type values
Const VER_NT_WORKSTATION = 0000001
Const VER_NT_DOMAIN_CONTROLLER = 0000002
Const VER_NT_SERVER = 0000003

' dwPlatformId defines:
Const VER_PLATFORM_WIN32s        = 0
Const VER_PLATFORM_WIN32_WINDOWS = 1
Const VER_PLATFORM_WIN32_NT      = 2
Const VER_PLATFORM_WIN32_CE      = 3

' VerifyVersionInfo() macro to set the condition mask
' VER_SET_CONDITION

'#if (NTDDI_VERSION >= NTDDI_WIN2K)
'Declare Function VerSetConditionMask Lib "kernel32" (ConditionMask As QWord, TypeMask As DWord, Condition As Byte) As QWord
'#endif

'#if (NTDDI_VERSION >= NTDDI_LONGHORN)
'Declare Function RtlGetProductInfo Lib "kernel32" (OSMajorVersion As DWord, OSMinorVersion As DWord, SpMajorVersion As DWord, SpMinorVersion As DWord, ByRef ReturnedProductType As DWord) As BOOLEAN
'#endif

Type RTL_CRITICAL_SECTION_DEBUG
	Type_ As Word
	CreatorBackTraceIndex As Word
	CriticalSection As VoidPtr '!*RTL_CRITICAL_SECTION
	ProcessLocksList As LIST_ENTRY
	EntryCount As DWord
	ContentionCount As DWord
	Flags As DWord
	CreatorBackTraceIndexHigh As Word
	SpareWORD As Word
End Type
TypeDef PRTL_CRITICAL_SECTION_DEBUG = *RTL_CRITICAL_SECTION_DEBUG
TypeDef RTL_RESOURCE_DEBUG = RTL_CRITICAL_SECTION_DEBUG
TypeDef PRTL_RESOURCE_DEBUG = *RTL_RESOURCE_DEBUG

Const RTL_CRITSECT_TYPE = 0
Const RTL_RESOURCE_TYPE = 1

Const RTL_CRITICAL_SECTION_FLAG_NO_DEBUG_INFO = &h01000000
Const RTL_CRITICAL_SECTION_FLAG_DYNAMIC_SPIN = &h02000000
Const RTL_CRITICAL_SECTION_FLAG_STATIC_INIT = &h04000000
Const RTL_CRITICAL_SECTION_ALL_FLAG_BITS = &hFF000000
Const RTL_CRITICAL_SECTION_FLAG_RESERVED = (RTL_CRITICAL_SECTION_ALL_FLAG_BITS And (Not (RTL_CRITICAL_SECTION_FLAG_NO_DEBUG_INFO Or RTL_CRITICAL_SECTION_FLAG_DYNAMIC_SPIN Or RTL_CRITICAL_SECTION_FLAG_STATIC_INIT)))

Const RTL_CRITICAL_SECTION_DEBUG_FLAG_STATIC_INIT = &h00000001

Type Align(8) RTL_CRITICAL_SECTION
	 DebugInfo As PRTL_CRITICAL_SECTION_DEBUG
	LockCount As Long
	RecursionCount As Long
	OwningThread As HANDLE
	LockSemaphore As HANDLE
	SpinCount As ULONG_PTR
End Type
TypeDef PRTL_CRITICAL_SECTION = *RTL_CRITICAL_SECTION

Type RTL_SRWLOCK
	Ptr As VoidPtr
End Type
TypeDef PRTL_SRWLOCK = *RTL_SRWLOCK
'Const RTL_SRWLOCK_INIT {0}
Type RTL_CONDITION_VARIABLE
	Ptr As VoidPtr
End Type
TypeDef PRTL_CONDITION_VARIABLE = *RTL_CONDITION_VARIABLE
'Const RTL_CONDITION_VARIABLE_INIT {0}
Const RTL_CONDITION_VARIABLE_LOCKMODE_SHARED = &h1
TypeDef PVECTORED_EXCEPTION_HANDLER = *Function(ByRef ExceptionInfo As EXCEPTION_POINTERS) As Long

Enum HEAP_INFORMATION_CLASS
	HeapCompatibilityInformation
	HeapEnableTerminationOnCorruption
End Enum

Const WT_EXECUTEDEFAULT = &h00000000
Const WT_EXECUTEINIOTHREAD = &h00000001
Const WT_EXECUTEINUITHREAD = &h00000002
Const WT_EXECUTEINWAITTHREAD = &h00000004
Const WT_EXECUTEONLYONCE = &h00000008
Const WT_EXECUTEINTIMERTHREAD = &h00000020
Const WT_EXECUTELONGFUNCTION = &h00000010
Const WT_EXECUTEINPERSISTENTIOTHREAD = &h00000040
Const WT_EXECUTEINPERSISTENTTHREAD = &h00000080
Const WT_TRANSFER_IMPERSONATION = &h00000100
'Const WT_SET_MAX_THREADPOOL_THREADS(Flags, Limit)  ((Flags) Or= (Limit)<<16)
TypeDef WAITORTIMERCALLBACKFUNC = *Sub(p As VoidPtr, b As Boolean)
TypeDef WORKERCALLBACKFUNC = *Sub(p As VoidPtr)
TypeDef APC_CALLBACK_FUNCTION = *Sub(dw AS DWord, p1 As VoidPtr, p2 As VoidPtr)
TypeDef PFLS_CALLBACK_FUNCTION = *Sub(lpFlsData As VoidPtr)
Const WT_EXECUTEINLONGTHREAD = &h00000010
Const WT_EXECUTEDELETEWAIT = &h00000008

Enum ACTIVATION_CONTEXT_INFO_CLASS
	ActivationContextBasicInformation = 1
	ActivationContextDetailedInformation = 2
	AssemblyDetailedInformationInActivationContext = 3
	FileInformationInAssemblyOfAssemblyInActivationContext = 4
	RunlevelInformationInActivationContext = 5
	MaxActivationContextInfoClass
	' compatibility with old names
	AssemblyDetailedInformationInActivationContxt = 3
	FileInformationInAssemblyOfAssemblyInActivationContxt = 4
End Enum

TypeDef ACTIVATIONCONTEXTINFOCLASS = ACTIVATION_CONTEXT_INFO_CLASS

Type ACTIVATION_CONTEXT_QUERY_INDEX
	ulAssemblyIndex As DWord
	ulFileIndexInAssembly; As DWord
End Type
TypeDef PACTIVATION_CONTEXT_QUERY_INDEX = *ACTIVATION_CONTEXT_QUERY_INDEX

TypeDef PCACTIVATION_CONTEXT_QUERY_INDEX = * /*Const*/ ACTIVATION_CONTEXT_QUERY_INDEX

Const ACTIVATION_CONTEXT_PATH_TYPE_NONE = 1
Const ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE = 2
Const ACTIVATION_CONTEXT_PATH_TYPE_URL = 3
Const ACTIVATION_CONTEXT_PATH_TYPE_ASSEMBLYREF = 4

Type ASSEMBLY_FILE_DETAILED_INFORMATION
	ulFlags As DWord
	ulFilenameLength As PCWSTR
	ulPathLength As PCWSTR
	lpFileName As PCWSTR
	lpFilePath As PCWSTR
End Type
TypeDef PASSEMBLY_FILE_DETAILED_INFORMATION = *ASSEMBLY_FILE_DETAILED_INFORMATION
TypeDef PCASSEMBLY_FILE_DETAILED_INFORMATION = * /*Const*/ ASSEMBLY_FILE_DETAILED_INFORMATION

' compatibility with old names
TypeDef  _ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION =  ASSEMBLY_FILE_DETAILED_INFORMATION
TypeDef   ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION =  ASSEMBLY_FILE_DETAILED_INFORMATION
TypeDef  PASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION =  PASSEMBLY_FILE_DETAILED_INFORMATION
TypeDef PCASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION = PCASSEMBLY_FILE_DETAILED_INFORMATION

Type ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION
	ulFlags As DWord
	ulEncodedAssemblyIdentityLength As DWord
	ulManifestPathType As DWord
	liManifestLastWriteTime As LARGE_INTEGER
	ulPolicyPathType As DWord
	ulPolicyPathLength As DWord
	liPolicyLastWriteTime As LARGE_INTEGER
	ulMetadataSatelliteRosterIndex As DWord
	ulManifestVersionMajor As DWord
	ulManifestVersionMinor As DWord
	ulPolicyVersionMajor As DWord
	ulPolicyVersionMinor As DWord
	ulAssemblyDirectoryNameLength As DWord
	lpAssemblyEncodedAssemblyIdentity As PCWSTR
	lpAssemblyManifestPath As PCWSTR
	lpAssemblyPolicyPath As PCWSTR
	lpAssemblyDirectoryName As PCWSTR
	ulFileCount As DWord
End Type
TypeDef PACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION = *ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION
TypeDef PCACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION = * /*Const*/ ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION

Enum ACTCTX_REQUESTED_RUN_LEVEL
	ACTCTX_RUN_LEVEL_UNSPECIFIED = 0
	ACTCTX_RUN_LEVEL_AS_INVOKER
	ACTCTX_RUN_LEVEL_HIGHEST_AVAILABLE
	ACTCTX_RUN_LEVEL_REQUIRE_ADMIN
	ACTCTX_RUN_LEVEL_NUMBERS
End Enum

Type ACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION
	ulFlags As DWord
	RunLevel As ACTCTX_REQUESTED_RUN_LEVEL
	UiAccess As DWord
End Type
TypeDef PACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION = ACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION
TypeDef PCACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION = * /*Const*/ACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION

Type ACTIVATION_CONTEXT_DETAILED_INFORMATION
	dwFlags As DWord
	ulFormatVersion As DWord
	ulAssemblyCount As DWord
	ulRootManifestPathType As DWord
	ulRootManifestPathChars As DWord
	ulRootConfigurationPathType As DWord
	ulRootConfigurationPathChars As DWord
	ulAppDirPathType As DWord
	ulAppDirPathChars As DWord
	lpRootManifestPath As PCWSTR
	lpRootConfigurationPath As PCWSTR
	lpAppDirPath As PCWSTR
End Type
TypeDef PACTIVATION_CONTEXT_DETAILED_INFORMATION = *ACTIVATION_CONTEXT_DETAILED_INFORMATION
TypeDef PCACTIVATION_CONTEXT_DETAILED_INFORMATION = * /*Const*/ ACTIVATION_CONTEXT_DETAILED_INFORMATION

Const DLL_PROCESS_ATTACH = 1
Const DLL_THREAD_ATTACH = 2
Const DLL_THREAD_DETACH = 3
Const DLL_PROCESS_DETACH = 0

Const EVENTLOG_SEQUENTIAL_READ = &h0001
Const EVENTLOG_SEEK_READ = &h0002
Const EVENTLOG_FORWARDS_READ = &h0004
Const EVENTLOG_BACKWARDS_READ = &h0008

Const EVENTLOG_SUCCESS = &h0000
Const EVENTLOG_ERROR_TYPE = &h0001
Const EVENTLOG_WARNING_TYPE = &h0002
Const EVENTLOG_INFORMATION_TYPE = &h0004
Const EVENTLOG_AUDIT_SUCCESS = &h0008
Const EVENTLOG_AUDIT_FAILURE = &h0010

Const EVENTLOG_START_PAIRED_EVENT = &h0001
Const EVENTLOG_END_PAIRED_EVENT = &h0002
Const EVENTLOG_END_ALL_PAIRED_EVENTS = &h0004
Const EVENTLOG_PAIRED_EVENT_ACTIVE = &h0008
Const EVENTLOG_PAIRED_EVENT_INACTIVE = &h0010

Type EVENTLOGRECORD
	Length As DWord
	Reserved As DWord
	RecordNumber As DWord
	TimeGenerated As DWord
	TimeWritten As DWord
	EventID As DWord
	EventType As Word
	NumStrings As Word
	EventCategory As Word
	ReservedFlags As Word
	ClosingRecordNumber As DWord
	StringOffset As DWord
	UserSidLength As DWord
	UserSidOffset As DWord
	DataLength As DWord
	DataOffset As DWord
	' Then follow:
	' WCHAR SourceName[]
	' WCHAR Computername[]
	' SID   UserSid
	' WCHAR Strings[]
	' BYTE  Data[]
	' CHAR  Pad[]
	' DWORD Length;
End Type
TypeDef PEVENTLOGRECORD = *EVENTLOGRECORD

Const MAXLOGICALLOGNAMESIZE = 256

Type EVENTSFORLOGFILE
	ulSize As DWord
	szLogicalLogFile[ELM(MAXLOGICALLOGNAMESIZE)] As WCHAR
	ulNumRecords As DWord
	pEventLogRecords[ELM(ANYSIZE_ARRAY)] As EVENTLOGRECORD 'pEventLogRecords[] As EVENTLOGRECORD
End Type
TypeDef PEVENTSFORLOGFILE = *EVENTSFORLOGFILE

Type PACKEDEVENTINFO
	ulSize As DWord
	ulNumEventsForLogFile As DWord
	ulOffsets[ELM(ANYSIZE_ARRAY)] As DWord 'ulOffsets[] As DWord
End Type
TypeDef PPACKEDEVENTINFO = *PACKEDEVENTINFO

Const KEY_QUERY_VALUE = &h0001
Const KEY_SET_VALUE = &h0002
Const KEY_CREATE_SUB_KEY = &h0004
Const KEY_ENUMERATE_SUB_KEYS = &h0008
Const KEY_NOTIFY = &h0010
Const KEY_CREATE_LINK = &h0020
Const KEY_WOW64_32KEY = &h0200
Const KEY_WOW64_64KEY = &h0100
Const KEY_WOW64_RES = &h0300
Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))
Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Const REG_OPTION_RESERVED = &h00000000
Const REG_OPTION_NON_VOLATILE = &h00000000
Const REG_OPTION_VOLATILE = &h00000001
Const REG_OPTION_CREATE_LINK = &h00000002
Const REG_OPTION_BACKUP_RESTORE = &h00000004
Const REG_OPTION_OPEN_LINK = &h00000008
Const REG_LEGAL_OPTION = (REG_OPTION_RESERVED Or REG_OPTION_NON_VOLATILE Or REG_OPTION_VOLATILE Or REG_OPTION_CREATE_LINK Or REG_OPTION_BACKUP_RESTORE Or REG_OPTION_OPEN_LINK)
Const REG_CREATED_NEW_KEY = &h00000001
Const REG_OPENED_EXISTING_KEY = &h00000002

Const REG_STANDARD_FORMAT = 1
Const REG_LATEST_FORMAT = 2
Const REG_NO_COMPRESSION = 4

Const REG_WHOLE_HIVE_VOLATILE = &h00000001
Const REG_REFRESH_HIVE = &h00000002
Const REG_NO_LAZY_FLUSH = &h00000004
Const REG_FORCE_RESTORE = &h00000008
Const REG_APP_HIVE = &h00000010
Const REG_PROCESS_PRIVATE = &h00000020
Const REG_START_JOURNAL = &h00000040
Const REG_HIVE_EXACT_FILE_GROWTH = &h00000080
Const REG_HIVE_NO_RM = &h00000100
Const REG_HIVE_SINGLE_LOG = &h00000200

Const REG_FORCE_UNLOAD = 1

Const REG_NOTIFY_CHANGE_NAME = &h00000001
Const REG_NOTIFY_CHANGE_ATTRIBUTES = &h00000002
Const REG_NOTIFY_CHANGE_LAST_SET = &h00000004
Const REG_NOTIFY_CHANGE_SECURITY = &h00000008

Const REG_LEGAL_CHANGE_FILTER = (REG_NOTIFY_CHANGE_NAME Or REG_NOTIFY_CHANGE_ATTRIBUTES Or REG_NOTIFY_CHANGE_LAST_SET Or REG_NOTIFY_CHANGE_SECURITY)

Const REG_NONE = 0
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2

Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_DWORD_LITTLE_ENDIAN = 4
Const REG_DWORD_BIG_ENDIAN = 5
Const REG_LINK = 6
Const REG_MULTI_SZ = 7
Const REG_RESOURCE_LIST = 8
Const REG_FULL_RESOURCE_DESCRIPTOR = 9
Const REG_RESOURCE_REQUIREMENTS_LIST = 10
Const REG_QWORD = 11
Const REG_QWORD_LITTLE_ENDIAN = 11

Const SERVICE_KERNEL_DRIVER = &h00000001
Const SERVICE_FILE_SYSTEM_DRIVER = &h00000002
Const SERVICE_ADAPTER = &h00000004
Const SERVICE_RECOGNIZER_DRIVER = &h00000008

Const SERVICE_DRIVER = (SERVICE_KERNEL_DRIVER Or SERVICE_FILE_SYSTEM_DRIVER Or SERVICE_RECOGNIZER_DRIVER)

Const SERVICE_WIN32_OWN_PROCESS = &h00000010
Const SERVICE_WIN32_SHARE_PROCESS = &h00000020
Const SERVICE_WIN32 = (SERVICE_WIN32_OWN_PROCESS Or SERVICE_WIN32_SHARE_PROCESS)

Const SERVICE_INTERACTIVE_PROCESS = &h00000100

Const SERVICE_TYPE_ALL = (SERVICE_WIN32 Or SERVICE_ADAPTER Or SERVICE_DRIVER Or SERVICE_INTERACTIVE_PROCESS)

Const SERVICE_BOOT_START = &h00000000
Const SERVICE_SYSTEM_START = &h00000001
Const SERVICE_AUTO_START = &h00000002
Const SERVICE_DEMAND_START = &h00000003
Const SERVICE_DISABLED = &h00000004

Const SERVICE_ERROR_IGNORE = &h00000000
Const SERVICE_ERROR_NORMAL = &h00000001
Const SERVICE_ERROR_SEVERE = &h00000002
Const SERVICE_ERROR_CRITICAL = &h00000003

Enum _SERVICE_NODE_TYPE
	DriverType = SERVICE_KERNEL_DRIVER
	FileSystemType = SERVICE_FILE_SYSTEM_DRIVER
	Win32ServiceOwnProcess = SERVICE_WIN32_OWN_PROCESS
	Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS
	AdapterType = SERVICE_ADAPTER
	RecognizerType = SERVICE_RECOGNIZER_DRIVER
End Enum

Enum SERVICE_LOAD_TYPE
	BootLoad = SERVICE_BOOT_START
	SystemLoad = SERVICE_SYSTEM_START
	AutoLoad = SERVICE_AUTO_START
	DemandLoad = SERVICE_DEMAND_START
	DisableLoad = SERVICE_DISABLED
End Enum

Enum SERVICE_ERROR_TYPE
	IgnoreError = SERVICE_ERROR_IGNORE
	NormalError = SERVICE_ERROR_NORMAL
	SevereError = SERVICE_ERROR_SEVERE
	CriticalError = SERVICE_ERROR_CRITICAL
End Enum

Const TAPE_ERASE_SHORT = 0
Const TAPE_ERASE_LONG = 1

Type TAPE_ERASE
	Type_ As DWord
	Immediate As BOOLEAN
End Type
TypeDef PTAPE_ERASE = *TAPE_ERASE

Const TAPE_LOAD = 0
Const TAPE_UNLOAD = 1
Const TAPE_TENSION = 2
Const TAPE_LOCK = 3
Const TAPE_UNLOCK = 4
Const TAPE_FORMAT = 5

Type TAPE_PREPARE
	Operation As DWord
	Immediate As BOOLEAN
End Type
TypeDef PTAPE_PREPARE = *TAPE_PREPARE

Const TAPE_SETMARKS = 0
Const TAPE_FILEMARKS = 1
Const TAPE_SHORT_FILEMARKS = 2
Const TAPE_LONG_FILEMARKS = 3

Type TAPE_WRITE_MARKS
	Type_ As DWord
	Count As DWord
	Immediate As BOOLEAN
End Type
TypeDef PTAPE_WRITE_MARKS = *TAPE_WRITE_MARKS

Const TAPE_ABSOLUTE_POSITION = 0
Const TAPE_LOGICAL_POSITION = 1
Const TAPE_PSEUDO_LOGICAL_POSITION = 2

Type TAPE_GET_POSITION
	Type_ As DWord
	Partition As DWord
	Offset As LARGE_INTEGER
End Type
TypeDef PTAPE_GET_POSITION = *TAPE_GET_POSITION

Const TAPE_REWIND = 0
Const TAPE_ABSOLUTE_BLOCK = 1
Const TAPE_LOGICAL_BLOCK = 2
Const TAPE_PSEUDO_LOGICAL_BLOCK = 3
Const TAPE_SPACE_END_OF_DATA = 4
Const TAPE_SPACE_RELATIVE_BLOCKS = 5
Const TAPE_SPACE_FILEMARKS = 6
Const TAPE_SPACE_SEQUENTIAL_FMKS = 7
Const TAPE_SPACE_SETMARKS = 8
Const TAPE_SPACE_SEQUENTIAL_SMKS = 9

Type TAPE_SET_POSITION
	Method As DWord
	Partition As DWord
	Offset As LARGE_INTEGER
	Immediate As BOOLEAN
End Type
TypeDef PTAPE_SET_POSITION = *TAPE_SET_POSITION

Const TAPE_DRIVE_FIXED = &h00000001
Const TAPE_DRIVE_SELECT = &h00000002
Const TAPE_DRIVE_INITIATOR = &h00000004

Const TAPE_DRIVE_ERASE_SHORT = &h00000010
Const TAPE_DRIVE_ERASE_LONG = &h00000020
Const TAPE_DRIVE_ERASE_BOP_ONLY = &h00000040
Const TAPE_DRIVE_ERASE_IMMEDIATE = &h00000080

Const TAPE_DRIVE_TAPE_CAPACITY = &h00000100
Const TAPE_DRIVE_TAPE_REMAINING = &h00000200
Const TAPE_DRIVE_FIXED_BLOCK = &h00000400
Const TAPE_DRIVE_VARIABLE_BLOCK = &h00000800

Const TAPE_DRIVE_WRITE_PROTECT = &h00001000
Const TAPE_DRIVE_EOT_WZ_SIZE = &h00002000

Const TAPE_DRIVE_ECC = &h00010000
Const TAPE_DRIVE_COMPRESSION = &h00020000
Const TAPE_DRIVE_PADDING = &h00040000
Const TAPE_DRIVE_REPORT_SMKS = &h00080000

Const TAPE_DRIVE_GET_ABSOLUTE_BLK = &h00100000
Const TAPE_DRIVE_GET_LOGICAL_BLK = &h00200000
Const TAPE_DRIVE_SET_EOT_WZ_SIZE = &h00400000

Const TAPE_DRIVE_EJECT_MEDIA = &h01000000
Const TAPE_DRIVE_CLEAN_REQUESTS = &h02000000
Const TAPE_DRIVE_SET_CMP_BOP_ONLY = &h04000000

Const TAPE_DRIVE_RESERVED_BIT = &h80000000

Const TAPE_DRIVE_LOAD_UNLOAD = &h80000001
Const TAPE_DRIVE_TENSION = &h80000002
Const TAPE_DRIVE_LOCK_UNLOCK = &h80000004
Const TAPE_DRIVE_REWIND_IMMEDIATE = &h80000008

Const TAPE_DRIVE_SET_BLOCK_SIZE = &h80000010
Const TAPE_DRIVE_LOAD_UNLD_IMMED = &h80000020
Const TAPE_DRIVE_TENSION_IMMED = &h80000040
Const TAPE_DRIVE_LOCK_UNLK_IMMED = &h80000080

Const TAPE_DRIVE_SET_ECC = &h80000100
Const TAPE_DRIVE_SET_COMPRESSION = &h80000200
Const TAPE_DRIVE_SET_PADDING = &h80000400
Const TAPE_DRIVE_SET_REPORT_SMKS = &h80000800

Const TAPE_DRIVE_ABSOLUTE_BLK = &h80001000
Const TAPE_DRIVE_ABS_BLK_IMMED = &h80002000
Const TAPE_DRIVE_LOGICAL_BLK = &h80004000
Const TAPE_DRIVE_LOG_BLK_IMMED = &h80008000

Const TAPE_DRIVE_END_OF_DATA = &h80010000
Const TAPE_DRIVE_RELATIVE_BLKS = &h80020000
Const TAPE_DRIVE_FILEMARKS = &h80040000
Const TAPE_DRIVE_SEQUENTIAL_FMKS = &h80080000

Const TAPE_DRIVE_SETMARKS = &h80100000
Const TAPE_DRIVE_SEQUENTIAL_SMKS = &h80200000
Const TAPE_DRIVE_REVERSE_POSITION = &h80400000
Const TAPE_DRIVE_SPACE_IMMEDIATE = &h80800000

Const TAPE_DRIVE_WRITE_SETMARKS = &h81000000
Const TAPE_DRIVE_WRITE_FILEMARKS = &h82000000
Const TAPE_DRIVE_WRITE_SHORT_FMKS = &h84000000
Const TAPE_DRIVE_WRITE_LONG_FMKS = &h88000000

Const TAPE_DRIVE_WRITE_MARK_IMMED = &h90000000
Const TAPE_DRIVE_FORMAT = &hA0000000
Const TAPE_DRIVE_FORMAT_IMMEDIATE = &hC0000000
Const TAPE_DRIVE_HIGH_FEATURES = &h80000000

Type TAPE_GET_DRIVE_PARAMETERS
	ECC As BOOLEAN
	Compression As BOOLEAN
	DataPadding As BOOLEAN
	ReportSetmarks As BOOLEAN
	DefaultBlockSize As DWord
	MaximumBlockSize As DWord
	MinimumBlockSize As DWord
	MaximumPartitionCount As DWord
	FeaturesLow As DWord
	FeaturesHigh As DWord
	EOTWarningZoneSize As DWord
End Type
TypeDef PTAPE_GET_DRIVE_PARAMETERS = *TAPE_GET_DRIVE_PARAMETERS

Type TAPE_SET_DRIVE_PARAMETERS
	ECC As BOOLEAN
	Compression As BOOLEAN
	DataPadding As BOOLEAN
	ReportSetmarks As BOOLEAN
	EOTWarningZoneSize As DWord
End Type
TypeDef PTAPE_SET_DRIVE_PARAMETERS = *TAPE_SET_DRIVE_PARAMETERS

Type TAPE_GET_MEDIA_PARAMETERS
	Capacity As LARGE_INTEGER
	Remaining As LARGE_INTEGER
	BlockSize As DWord
	PartitionCount As DWord
	WriteProtected As BOOLEAN
End Type
TypeDef PTAPE_GET_MEDIA_PARAMETERS = *TAPE_GET_MEDIA_PARAMETERS

Type TAPE_SET_MEDIA_PARAMETERS
	BlockSize As DWord
End Type
TypeDef PTAPE_SET_MEDIA_PARAMETERS = *TAPE_SET_MEDIA_PARAMETERS

Const TAPE_FIXED_PARTITIONS = 0
Const TAPE_SELECT_PARTITIONS = 1
Const TAPE_INITIATOR_PARTITIONS = 2

Type TAPE_CREATE_PARTITION
	Method As DWord
	Count As DWord
	Size As DWord
End Type
TypeDef PTAPE_CREATE_PARTITION = *TAPE_CREATE_PARTITION

Const TAPE_QUERY_DRIVE_PARAMETERS = 0
Const TAPE_QUERY_MEDIA_CAPACITY = 1
Const TAPE_CHECK_FOR_DRIVE_PROBLEM = 2
Const TAPE_QUERY_IO_ERROR_DATA = 3
Const TAPE_QUERY_DEVICE_ERROR_DATA = 4

Type TAPE_WMI_OPERATIONS
	Method As DWord
	DataBufferSize As DWord
	DataBuffer As VoidPtr
End Type
TypeDef PTAPE_WMI_OPERATIONS = *TAPE_WMI_OPERATIONS

Enum TAPE_DRIVE_PROBLEM_TYPE
	TapeDriveProblemNone
	TapeDriveReadWriteWarning
	TapeDriveReadWriteError
	TapeDriveReadWarning
	TapeDriveWriteWarning
	TapeDriveReadError
	TapeDriveWriteError
	TapeDriveHardwareError
	TapeDriveUnsupportedMedia
	TapeDriveScsiConnectionError
	TapeDriveTimetoClean
	TapeDriveCleanDriveNow
	TapeDriveMediaLifeExpired
	TapeDriveSnappedTape
End Enum

'#ifndef _NTTMAPI_
'#define _NTTMAPI_

'#include <ktmtypes.ab>

' Types for Nt level TM calls
Const TRANSACTIONMANAGER_QUERY_INFORMATION = &h0001
Const TRANSACTIONMANAGER_SET_INFORMATION = &h0002
Const TRANSACTIONMANAGER_RECOVER = &h0004
Const TRANSACTIONMANAGER_RENAME = &h0008
Const TRANSACTIONMANAGER_CREATE_RM = &h0010
Const TRANSACTIONMANAGER_BIND_TRANSACTION = &h0020
Const TRANSACTIONMANAGER_GENERIC_READ = (STANDARD_RIGHTS_READ Or TRANSACTIONMANAGER_QUERY_INFORMATION)
Const TRANSACTIONMANAGER_GENERIC_WRITE = (STANDARD_RIGHTS_WRITE Or TRANSACTIONMANAGER_SET_INFORMATION Or TRANSACTIONMANAGER_RECOVER Or TRANSACTIONMANAGER_RENAME Or TRANSACTIONMANAGER_CREATE_RM)
Const TRANSACTIONMANAGER_GENERIC_EXECUTE = (STANDARD_RIGHTS_EXECUTE)
Const TRANSACTIONMANAGER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or TRANSACTIONMANAGER_GENERIC_READ Or TRANSACTIONMANAGER_GENERIC_WRITE Or TRANSACTIONMANAGER_GENERIC_EXECUTE Or TRANSACTIONMANAGER_BIND_TRANSACTION)

Const TRANSACTION_QUERY_INFORMATION = &h0001
Const TRANSACTION_SET_INFORMATION = &h0002
Const TRANSACTION_ENLIST = &h0004
Const TRANSACTION_COMMIT = &h0008
Const TRANSACTION_ROLLBACK = &h0010
Const TRANSACTION_PROPAGATE = &h0020
Const TRANSACTION_SAVEPOINT = &h0040
Const TRANSACTION_MARSHALL = ( TRANSACTION_QUERY_INFORMATION )
Const TRANSACTION_GENERIC_READ = (STANDARD_RIGHTS_READ Or TRANSACTION_QUERY_INFORMATION Or SYNCHRONIZE)
Const TRANSACTION_GENERIC_WRITE = (STANDARD_RIGHTS_WRITE Or TRANSACTION_SET_INFORMATION Or TRANSACTION_COMMIT Or TRANSACTION_ENLIST Or TRANSACTION_ROLLBACK Or TRANSACTION_PROPAGATE Or TRANSACTION_SAVEPOINT Or SYNCHRONIZE)
Const TRANSACTION_GENERIC_EXECUTE = (STANDARD_RIGHTS_EXECUTE Or TRANSACTION_COMMIT Or TRANSACTION_ROLLBACK Or SYNCHRONIZE)
Const TRANSACTION_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or TRANSACTION_GENERIC_READ Or TRANSACTION_GENERIC_WRITE Or TRANSACTION_GENERIC_EXECUTE)
Const TRANSACTION_RESOURCE_MANAGER_RIGHTS = (TRANSACTION_GENERIC_READ Or STANDARD_RIGHTS_WRITE Or TRANSACTION_SET_INFORMATION Or TRANSACTION_ENLIST Or TRANSACTION_ROLLBACK Or TRANSACTION_PROPAGATE Or SYNCHRONIZE)

Const RESOURCEMANAGER_QUERY_INFORMATION = &h0001
Const RESOURCEMANAGER_SET_INFORMATION = &h0002
Const RESOURCEMANAGER_RECOVER = &h0004
Const RESOURCEMANAGER_ENLIST = &h0008
Const RESOURCEMANAGER_GET_NOTIFICATION = &h0010
Const RESOURCEMANAGER_REGISTER_PROTOCOL = &h0020
Const RESOURCEMANAGER_COMPLETE_PROPAGATION = &h0040
Const RESOURCEMANAGER_GENERIC_READ = (STANDARD_RIGHTS_READ Or RESOURCEMANAGER_QUERY_INFORMATION Or SYNCHRONIZE)
Const RESOURCEMANAGER_GENERIC_WRITE = (STANDARD_RIGHTS_WRITE Or RESOURCEMANAGER_SET_INFORMATION Or RESOURCEMANAGER_RECOVER Or RESOURCEMANAGER_ENLIST Or RESOURCEMANAGER_GET_NOTIFICATION Or RESOURCEMANAGER_REGISTER_PROTOCOL Or RESOURCEMANAGER_COMPLETE_PROPAGATION Or SYNCHRONIZE)
Const RESOURCEMANAGER_GENERIC_EXECUTE = (STANDARD_RIGHTS_EXECUTE Or RESOURCEMANAGER_RECOVER Or RESOURCEMANAGER_ENLIST Or RESOURCEMANAGER_GET_NOTIFICATION Or RESOURCEMANAGER_COMPLETE_PROPAGATION Or SYNCHRONIZE)
Const RESOURCEMANAGER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or RESOURCEMANAGER_GENERIC_READ Or RESOURCEMANAGER_GENERIC_WRITE Or RESOURCEMANAGER_GENERIC_EXECUTE)


Const ENLISTMENT_QUERY_INFORMATION = &h0001
Const ENLISTMENT_SET_INFORMATION = &h0002
Const ENLISTMENT_RECOVER = &h0004
Const ENLISTMENT_SUBORDINATE_RIGHTS = &h0008
Const ENLISTMENT_SUPERIOR_RIGHTS = &h0010
Const ENLISTMENT_GENERIC_READ = (STANDARD_RIGHTS_READ Or ENLISTMENT_QUERY_INFORMATION)
Const ENLISTMENT_GENERIC_WRITE = (STANDARD_RIGHTS_WRITE Or ENLISTMENT_SET_INFORMATION Or ENLISTMENT_RECOVER Or ENLISTMENT_SUBORDINATE_RIGHTS Or ENLISTMENT_SUPERIOR_RIGHTS)
Const ENLISTMENT_GENERIC_EXECUTE = (STANDARD_RIGHTS_EXECUTE Or ENLISTMENT_RECOVER Or ENLISTMENT_SUBORDINATE_RIGHTS Or ENLISTMENT_SUPERIOR_RIGHTS)
Const ENLISTMENT_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or ENLISTMENT_GENERIC_READ Or ENLISTMENT_GENERIC_WRITE Or ENLISTMENT_GENERIC_EXECUTE)

' Transaction outcomes.

Enum TRANSACTION_OUTCOME
	TransactionOutcomeUndetermined = 1
	TransactionOutcomeCommitted
	TransactionOutcomeAborted
End Enum

Enum TRANSACTION_STATE
	TransactionStateNormal = 1
	TransactionStateIndoubt
	TransactionStateCommittedNotify
End Enum

Type TRANSACTION_BASIC_INFORMATION
	TransactionId As GUID
	State As DWord
	Outcome As DWord
End Type
TypeDef PTRANSACTION_BASIC_INFORMATION = *TRANSACTION_BASIC_INFORMATION

Type TRANSACTIONMANAGER_BASIC_INFORMATION
	TmIdentity As GUID
	VirtualClock As LARGE_INTEGER
End Type
TypeDef PTRANSACTIONMANAGER_BASIC_INFORMATION = *TRANSACTIONMANAGER_BASIC_INFORMATION

Type TRANSACTIONMANAGER_LOG_INFORMATION
	LogIdentity As GUID
End Type
TypeDef PTRANSACTIONMANAGER_LOG_INFORMATION = *TRANSACTIONMANAGER_LOG_INFORMATION

Type TRANSACTIONMANAGER_LOGPATH_INFORMATION
	LogPathLength As DWord
	/*__field_ecount(LogPathLength)*/ LogPath[ELM(1)] As WCHAR 'Variable size
'	Data[ELM(1)] 'Variable size data not declared
End Type
TypeDef PTRANSACTIONMANAGER_LOGPATH_INFORMATION = *TRANSACTIONMANAGER_LOGPATH_INFORMATION

Type TRANSACTION_PROPERTIES_INFORMATION
	IsolationLevel As DWord
	IsolationFlags As DWord
	Timeout As LARGE_INTEGER
	Outcome As DWord
	DescriptionLength As DWord
	Description[ELM(1)] As WCHAR 'Variable size
'	Data[ELM(1)] 'Variable size data not declared
End Type
TypeDef PTRANSACTION_PROPERTIES_INFORMATION = *TRANSACTION_PROPERTIES_INFORMATION

Type TRANSACTION_BIND_INFORMATION
	TmHandle As HANDLE
End Type
TypeDef PTRANSACTION_BIND_INFORMATION = *TRANSACTION_BIND_INFORMATION

Type TRANSACTION_ENLISTMENT_PAIR
	EnlistmentId As GUID
	ResourceManagerId As GUID
End Type
TypeDef PTRANSACTION_ENLISTMENT_PAIR = *TRANSACTION_ENLISTMENT_PAIR

Type TRANSACTION_ENLISTMENTS_INFORMATION
	NumberOfEnlistments As DWord
	EnlistmentPair[ELM(1)] As TRANSACTION_ENLISTMENT_PAIR 'Variable size
End Type
TypeDef PTRANSACTION_ENLISTMENTS_INFORMATION = *TRANSACTION_ENLISTMENTS_INFORMATION

Type TRANSACTION_FULL_INFORMATION
	NameLength As DWord
End Type
TypeDef PTRANSACTION_FULL_INFORMATION = *TRANSACTION_FULL_INFORMATION

Type RESOURCEMANAGER_BASIC_INFORMATION
	ResourceManagerId As GUID
	DescriptionLength As DWord
	Description[ELM(1)] As WCHAR 'Variable size
End Type
TypeDef PRESOURCEMANAGER_BASIC_INFORMATION = *RESOURCEMANAGER_BASIC_INFORMATION

Type RESOURCEMANAGER_COMPLETION_INFORMATION
	IoCompletionPortHandle As HANDLE
	CompletionKey As ULONG_PTR
End Type
TypeDef PRESOURCEMANAGER_COMPLETION_INFORMATION = *RESOURCEMANAGER_COMPLETION_INFORMATION

Type TRANSACTION_NAME_INFORMATION
	NameLength As DWord
	Name[ELM(1)] As WCHAR 'Variable length string
End Type
TypeDef PTRANSACTION_NAME_INFORMATION = *TRANSACTION_NAME_INFORMATION

Enum TRANSACTION_INFORMATION_CLASS
	TransactionBasicInformation
	TransactionPropertiesInformation
	TransactionEnlistmentInformation
	TransactionFullInformation
	TransactionBindInformation
'	TransactionNameInformation
End Enum

Enum TRANSACTIONMANAGER_INFORMATION_CLASS
	TransactionManagerBasicInformation
	TransactionManagerLogInformation
	TransactionManagerLogPathInformation
	TransactionManagerOnlineProbeInformation
End Enum

Enum RESOURCEMANAGER_INFORMATION_CLASS
	ResourceManagerBasicInformation
	ResourceManagerCompletionInformation
	ResourceManagerFullInformation
	ResourceManagerNameInformation
End Enum

Type ENLISTMENT_BASIC_INFORMATION
	EnlistmentId As GUID
	TransactionId As GUID
	ResourceManagerId As GUID
End Type
TypeDef PENLISTMENT_BASIC_INFORMATION = *ENLISTMENT_BASIC_INFORMATION

Enum ENLISTMENT_INFORMATION_CLASS
	EnlistmentBasicInformation
	EnlistmentRecoveryInformation
	EnlistmentFullInformation
	EnlistmentNameInformation
End Enum

Type TRANSACTION_LIST_ENTRY
'	UOW As UOW
End Type

TypeDef PTRANSACTION_LIST_ENTRY = *TRANSACTION_LIST_ENTRY

Type TRANSACTION_LIST_INFORMATION
	NumberOfTransactions As DWord
	TransactionInformation[ELM(1)] As TRANSACTION_LIST_ENTRY
End Type
TypeDef PTRANSACTION_LIST_INFORMATION = *TRANSACTION_LIST_INFORMATION

' Types of objects known to the kernel transaction manager.
Enum KTMOBJECT_TYPE
	KTMOBJECT_TRANSACTION
	KTMOBJECT_TRANSACTION_MANAGER
	KTMOBJECT_RESOURCE_MANAGER
	KTMOBJECT_ENLISTMENT
	KTMOBJECT_INVALID
End Enum
TypeDef PKTMOBJECT_TYPE = *KTMOBJECT_TYPE

' KTMOBJECT_CURSOR
Type KTMOBJECT_CURSOR
	LastQuery As GUID
	ObjectIdCount As DWord
	ObjectIds[ELM(1)] As GUID
End Type
TypeDef PKTMOBJECT_CURSOR = *KTMOBJECT_CURSOR

'#endif

TypeDef TP_VERSION = DWord
TypeDef PTP_VERSION = *TP_VERSION

TypeDef PTP_CALLBACK_INSTANCE = VoidPtr
'typedef struct _TP_CALLBACK_INSTANCE TP_CALLBACK_INSTANCE, *PTP_CALLBACK_INSTANCE;

TypeDef PTP_SIMPLE_CALLBACK = *Sub(Instance As PTP_CALLBACK_INSTANCE, Context As VoidPtr)
TypeDef PTP_POOL = VoidPtr
'typedef struct _TP_POOL TP_POOL, *PTP_POOL;
TypeDef PTP_CLEANUP_GROUP = VoidPtr
'typedef struct _TP_CLEANUP_GROUP TP_CLEANUP_GROUP, *PTP_CLEANUP_GROUP;
TypeDef PTP_CLEANUP_GROUP_CANCEL_CALLBACK = *Sub(ObjectContext As VoidPtr, CleanupContext As VoidPtr)

TypeDef PACTIVATION_CONTEXT = VoidPtr

Type TP_CALLBACK_ENVIRON
	Version As TP_VERSION
	Pool As PTP_POOL
	CleanupGroup As PTP_CLEANUP_GROUP
	CleanupGroupCancelCallback As PTP_CLEANUP_GROUP_CANCEL_CALLBACK
	RaceDll As VoidPtr
	ActivationContext As PACTIVATION_CONTEXT
	FinalizationCallback As PTP_SIMPLE_CALLBACK
'	Union
		Flags As DWord
'		Type
'			LongFunction :  1 As DWord
'			Private_     : 31 As DWord
'		} s;
'	End Union
End Type
TypeDef PTP_CALLBACK_ENVIRON = *TP_CALLBACK_ENVIRON

Sub /*FORCEINLINE*/ TpInitializeCallbackEnviron(ByRef CallbackEnviron As TP_CALLBACK_ENVIRON)
	With CallbackEnviron
		.Version = 1
		.Pool = NULL
		.CleanupGroup = NULL
		.CleanupGroupCancelCallback = NULL
		.RaceDll = NULL
		.ActivationContext = NULL
		.FinalizationCallback = NULL
		.Flags = 0
	End With
End Sub

Sub /*FORCEINLINE*/ TpSetCallbackThreadpool(ByRef CallbackEnviron As TP_CALLBACK_ENVIRON, Pool As PTP_POOL)
	CallbackEnviron.Pool = Pool
End Sub

Sub /*FORCEINLINE*/ TpSetCallbackCleanupGroup(ByRef CallbackEnviron As TP_CALLBACK_ENVIRON, CleanupGroup As PTP_CLEANUP_GROUP, CleanupGroupCancelCallback As PTP_CLEANUP_GROUP_CANCEL_CALLBACK)
	CallbackEnviron.CleanupGroup = CleanupGroup
	CallbackEnviron.CleanupGroupCancelCallback = CleanupGroupCancelCallback
End Sub

Sub /*FORCEINLINE*/ TpSetCallbackActivationContext(ByRef CallbackEnviron As TP_CALLBACK_ENVIRON, ActivationContext As PACTIVATION_CONTEXT)
	CallbackEnviron.ActivationContext = ActivationContext
End Sub

Sub /*FORCEINLINE*/ TpSetCallbackNoActivationContext(ByRef CallbackEnviron As TP_CALLBACK_ENVIRON)
	CallbackEnviron.ActivationContext = (-1 As LONG_PTR) As PACTIVATION_CONTEXT
End Sub

Sub /*FORCEINLINE*/ TpSetCallbackLongFunction(ByRef CallbackEnviron As TP_CALLBACK_ENVIRON)
	CallbackEnviron.Flags = 1 'u.s.LongFunction = 1
End Sub

Sub /*FORCEINLINE*/ TpSetCallbackRaceWithDll(ByRef CallbackEnviron As TP_CALLBACK_ENVIRON, DllHandle As VoidPtr)
	CallbackEnviron.RaceDll = DllHandle
End Sub

Sub /*FORCEINLINE*/ TpSetCallbackFinalizationCallback(ByRef CallbackEnviron As TP_CALLBACK_ENVIRON, FinalizationCallback As PTP_SIMPLE_CALLBACK)
	CallbackEnviron.FinalizationCallback = FinalizationCallback
End Sub

Sub /*FORCEINLINE*/ TpDestroyCallbackEnviron(ByRef CallbackEnviron As TP_CALLBACK_ENVIRON)
'	UNREFERENCED_PARAMETER(CallbackEnviron)
End Sub

TypeDef PTP_WORK = VoidPtr
'typedef struct _TP_WORK TP_WORK, *PTP_WORK;

TypeDef PTP_WORK_CALLBACK = *Sub(Instance As PTP_CALLBACK_INSTANCE, Context As VoidPtr, Work As PTP_WORK)

TypeDef PTP_TIMER = *VoidPtr
'typedef struct _TP_TIMER TP_TIMER, *PTP_TIMER;

TypeDef PTP_TIMER_CALLBACK = *Sub(Instance As PTP_CALLBACK_INSTANCE, Context As VoidPtr, Timer As PTP_TIMER)

TypeDef TP_WAIT_RESULT = DWord

TypeDef PTP_WAIT = VoidPtr
'typedef struct _TP_WAIT TP_WAIT, *PTP_WAIT;

TypeDef PTP_WAIT_CALLBACK = *Sub(Instance As PTP_CALLBACK_INSTANCE, Context As VoidPtr, Wait As PTP_WAIT, WaitResult As TP_WAIT_RESULT)

TypeDef PTP_IO = VoidPtr
'typedef struct _TP_IO TP_IO, *PTP_IO;

'NtCurrentTeb()
'GetCurrentFiber()
'GetFiberData ()

'#if (_WIN32_WINNT > 0x0500) Or (_WIN32_FUSION >= 0x0100) Or ISOLATION_AWARE_ENABLED
Const ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION = 1
Const ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION = 2
Const ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION = 3
Const ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION = 4
Const ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION = 5
Const ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION = 6
Const ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION = 7
Const ACTIVATION_CONTEXT_SECTION_GLOBAL_OBJECT_RENAME_TABLE = 8
Const ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES = 9
Const ACTIVATION_CONTEXT_SECTION_APPLICATION_SETTINGS = 10
'#endif // winnt_only

