----------------------------------------------------------------------------------
--                                                                              --
-- Windows Base Types API interface Unit for Object Pascal                      --
--                                                                              --
-- Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft          --
-- Corporation. All Rights Reserved.                                            --
--                                                                              --
-- The original file is: basetsd.h, released August 2001. The original Pascal   --
-- code is: WinType.pas, released December 2000. The initial developer of the   --
-- Pascal code is Marcel van Brakel (brakelm att chello dott nl).               --
--                                                                              --
-- Portions created by Marcel van Brakel are Copyright (C) 1999-2001            --
-- Marcel van Brakel. All Rights Reserved.                                      --
--                                                                              --
-- Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI)        --
--                                                                              --
-- You may retrieve the latest version of this file at the Project JEDI         --
-- APILIB home page, located at http://jedi-apilib.sourceforge.net              --
--                                                                              --
-- The contents of this file are used with permission, subject to the Mozilla   --
-- Public License Version 1.1 (the "License"); you may not use this file except --
-- in compliance with the License. You may obtain a copy of the License at      --
-- http://www.mozilla.org/MPL/MPL-1.1.html                                      --
--                                                                              --
-- Software distributed under the License is distributed on an "AS IS" basis,   --
-- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for --
-- the specific language governing rights and limitations under the License.    --
--                                                                              --
-- Alternatively, the contents of this file may be used under the terms of the  --
-- GNU Lesser General Public License (the  "LGPL License"), in which case the   --
-- provisions of the LGPL License are applicable instead of those above.        --
-- If you wish to allow use of your version of this file only under the terms   --
-- of the LGPL License and not to allow others to use your version of this file --
-- under the MPL, indicate your decision by deleting  the provisions above and  --
-- replace  them with the notice and other provisions required by the LGPL      --
-- License.  If you do not delete the provisions above, a recipient may use     --
-- your version of this file under either the MPL or the LGPL License.          --
--                                                                              --
-- For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html --
--                                                                              --
----------------------------------------------------------------------------------

--  $Id: Jwa.Win_Type.ads,v 1.20 2007/10/07 23:55:45 dezipaitor Exp $

with
  Interfaces, System, Jwa.Utils;

use
  Interfaces, Jwa.Utils;

package Jwa.Win_Type is

--%%   EJwaError = class(Exception);
--%%   EJwaLoadLibraryError = class(EJwaError);
--%%   EJwaGetProcAddressError = class(EJwaError);

--%% {GetProcedureAddress loads a function using a module name and an function name.
--%% WARNING: Do not load a function defined by its index like PAnsiChar(123) in ProcName.
--%%  Instead simply use the number and thus the other GetProcedureAddress.
--%% }
--%% procedure GetProcedureAddress(var P: Pointer; const ModuleName, ProcName: AnsiString); overload;

--%% {GetProcedureAddress loads a function using a module name and an function index.}
--%% procedure GetProcedureAddress(var P: Pointer; const ModuleName : AnsiString; ProcNumber : DWORD); overload;

--%%   // (rom) moved from JwaRpc.pas
--%%   RPC_STATUS = Longint;
--%%   {$EXTERNALSYM RPC_STATUS}

-- ntdef.h

-- typedef double DOUBLE;

--%%   PQuad = ^TQuad;
--%%   _QUAD = record                // QUAD is for those times we want
--%%     DoNotUseThisField: Double;  // an 8 byte aligned 8 byte long structure
--%%   end;                          // which is NOT really a floating point
--%%   {$EXTERNALSYM _QUAD}          // number.  Use DOUBLE if you want an FP number.
--%%   QUAD = _QUAD;
--%%   {$EXTERNALSYM QUAD}
--%%   TQuad = _QUAD;

--
-- Unsigned Basics
--

   -- UCHAR has been silently aliased to Unsigned_8
   -- USHORT has been silently aliased to Unsigned_16
   -- ULONG has been silently aliased to Unsigned_32
--%%   UQUAD = QUAD;
--%%   {$EXTERNALSYM UQUAD}

--
-- __int64 is only supported by 2.0 and later midl.
-- __midl is set by the 2.0 midl and not by 1.0 midl.
--

   -- LONGLONG has been silently aliased to Integer_64
   -- ULONGLONG has been silently aliased to Unsigned_64

   Max_Long_Long : constant := 16#7FFF_FFFF_FFFF_FFFF#;

   -- PLONGLONG has been silently aliased to Integer_64_Ptr
   -- PULONGLONG has been silently aliased to Unsigned_64_Ptr

   -- BOOL has been silently aliased to Boolean_32

   -- DWORD has been silently aliased to Unsigned_32

   Anysize_Array : constant := 1;

--%%   MAX_NATURAL_ALIGNMENT = SizeOf(ULONG);
--%%   {$EXTERNALSYM MAX_NATURAL_ALIGNMENT}

--
-- Void
--

   -- PVOID has been silently aliased to System.Address
   -- PPVOID has been silently aliased to Address_Ptr
   -- PVOID64 has been silently aliased to System.Address

--
-- Basics
--

   -- SHORT has been silently aliased to Integer_16
   -- LONG has been silently aliased to Integer_32

--
-- UNICODE (Wide Character) types
--

   -- WCHAR has been silently aliased to Char_16

   -- PWCHAR has been silently aliased to Char_16_Ptr
   -- LPWCH has been silently aliased to Char_16_Ptr
   -- PWCH has been silently aliased to Char_16_Ptr
   -- LPCWCH has been silently aliased to Char_16_Ptr
   -- PCWCH has been silently aliased to Char_16_Ptr
   -- NWPSTR has been silently aliased to Char_16_Ptr
   -- LPWSTR has been silently aliased to Char_16_Ptr
   -- LPCWSTR has been silently aliased to Char_16_Ptr
   -- PWSTR has been silently aliased to Char_16_Ptr
   -- LPUWSTR has been silently aliased to Char_16_Ptr
   -- PUWSTR has been silently aliased to Char_16_Ptr
   -- LCPUWSTR has been silently aliased to Char_16_Ptr
   -- PCUWSTR has been silently aliased to Char_16_Ptr

--
-- ANSI (Multi-byte Character) types
--


   -- LPCH has been silently aliased to Char_8_Ptr
   -- PCH has been silently aliased to Char_8_Ptr

   -- LPCCH has been silently aliased to Char_8_Ptr
   -- PCCH has been silently aliased to Char_8_Ptr
   -- NPSTR has been silently aliased to Char_8_Ptr
   -- LPSTR has been silently aliased to Char_8_Ptr
   -- PSTR has been silently aliased to Char_8_Ptr
   -- LPCSTR has been silently aliased to Char_8_Ptr
   -- PCSTR has been silently aliased to Char_8_Ptr

-- (rom) moved down to have LPSTR etc always declared
   -- LPLPSTR has been silently aliased to Char_8_Ptr_Ptr
   -- LPLPCSTR has been silently aliased to Char_8_Ptr_Ptr
   -- LPLPCWSTR has been silently aliased to Char_16_Ptr_Ptr
   -- LPLPWSTR has been silently aliased to Char_16_Ptr_Ptr

   -- PLPWSTR has been silently aliased to Char_16_Ptr_Ptr
   -- PLPSTR has been silently aliased to Char_8_Ptr_Ptr
   -- PPWCHAR has been silently aliased to Char_16_Ptr_Ptr

   -- PPTSTR has been silently aliased to Char_16_Ptr_Ptr
   -- PPChar has been silently aliased to Char_8_Ptr_Ptr
   -- PPWideChar has been silently aliased to Char_16_Ptr_Ptr
   -- PPointer has been silently aliased to Address_Ptr

   -- GUID has been silently aliased to GUID_Type
   -- LPGUID has been silently aliased to GUID_Ptr
   -- CLSID has been silently aliased to GUID_Type

--
-- Neutral ANSI/UNICODE types and macros
--

--%% {$IFDEF UNICODE}

   -- TCHAR has been silently aliased to Char_16
   -- PTCHAR has been silently aliased to Char_16_Ptr
   -- TUCHAR has been silently aliased to Char_16
   -- PTUCHAR has been silently aliased to Char_16_Ptr

   -- LPCTCH has been silently aliased to Char_16_Ptr
   -- LPTCH has been silently aliased to Char_16_Ptr
   -- PTCH has been silently aliased to Char_16_Ptr
   -- PTSTR has been silently aliased to Char_16_Ptr
   -- LPTSTR has been silently aliased to Char_16_Ptr
   -- PCTSTR has been silently aliased to Char_16_Ptr
   -- LPCTSTR has been silently aliased to Char_16_Ptr

   -- PCUTSTR has been silently aliased to Char_16_Ptr
   -- LPCUTSTR has been silently aliased to Char_16_Ptr
   -- PUTSTR has been silently aliased to Char_16_Ptr
   -- LPUTSTR has been silently aliased to Char_16_Ptr

--%%   __TEXT = WideString;
--%%   {$EXTERNALSYM __TEXT}

--%% {$ELSE}

   -- TCHAR has been silently aliased to Char_16
   -- PTCHAR has been silently aliased to Char_16_Ptr
   -- TUCHAR has been silently aliased to Char_16
   -- PTUCHAR has been silently aliased to Char_16_Ptr

   -- LPCTCH has been silently aliased to Char_16_Ptr
   -- LPTCH has been silently aliased to Char_16_Ptr
   -- PTCH has been silently aliased to Char_16_Ptr
   -- PTSTR has been silently aliased to Char_16_Ptr
   -- LPTSTR has been silently aliased to Char_16_Ptr
   -- PCTSTR has been silently aliased to Char_16_Ptr
   -- LPCTSTR has been silently aliased to Char_16_Ptr

   -- PCUTSTR has been silently aliased to Char_16_Ptr
   -- LPCUTSTR has been silently aliased to Char_16_Ptr
   -- PUTSTR has been silently aliased to Char_16_Ptr
   -- LPUTSTR has been silently aliased to Char_16_Ptr

--%%   __TEXT = AnsiString;
--%%   {$EXTERNALSYM __TEXT}

--%% {$ENDIF UNICODE}

--%%   TEXT = __TEXT;
--%%   {$EXTERNALSYM TEXT}

--
-- Pointer to Basics
--

   -- PSHORT has been silently aliased to Integer_16_Ptr
   -- PLONG has been silently aliased to Integer_32_Ptr

--
-- Pointer to Unsigned Basics
--

   -- PUCHAR has been silently aliased to Unsigned_8_Ptr
   -- PUSHORT has been silently aliased to Unsigned_16_Ptr
   -- PULONG has been silently aliased to Unsigned_32_Ptr
--%%   PUQUAD = ^UQUAD;
--%%   {$EXTERNALSYM PUQUAD}

--
-- Signed characters
--

   -- SCHAR has been silently aliased to Integer_8
   -- PSCHAR has been silently aliased to Integer_8_Ptr

--
-- Handle to an Object
--

   -- HANDLE has been silently aliased to Handle_Type
   -- PHANDLE has been silently aliased to Handle_Ptr
   -- THandle has been silently aliased to Handle_Type

--
-- Flag (bit) fields
--

   subtype Fchar_Type is Unsigned_8;
   subtype Fchar_Ptr is Unsigned_8_Ptr;
   subtype Fchar_CPtr is Unsigned_8_CPtr;
   subtype Fshort_Type is Unsigned_16;
   subtype Fshort_Ptr is Unsigned_16_Ptr;
   subtype Fshort_CPtr is Unsigned_16_CPtr;
   subtype Flong_Type is Unsigned_32;
   subtype Flong_Ptr is Unsigned_32_Ptr;
   subtype Flong_CPtr is Unsigned_32_CPtr;

-- Component Object Model defines, and macros

--%%   HRESULT = System.HRESULT; // LONG;
--%%   {$EXTERNALSYM HRESULT}

--
-- Low order two bits of a handle are ignored by the system and available
-- for use by application code as tag bits.  The remaining bits are opaque
-- and used to store a serial number and table index.
--

   Obj_Handle_Tagbits : constant := 16#0000_0003#;

--
-- Cardinal Data Types [0 - 2**N-2)
--

--%%   CCHAR = Char;
--%%   {$EXTERNALSYM CCHAR}
--%%   CSHORT = Shortint;
--%%   {$EXTERNALSYM CSHORT}
   subtype Clong_Type is Unsigned_32;
   subtype Clong_Ptr is Unsigned_32_Ptr;
   subtype Clong_CPtr is Unsigned_32_CPtr;

--%%   PCCHAR = ^CCHAR;
--%%   {$EXTERNALSYM PCCHAR}
--%%   PCSHORT = ^CSHORT;
--%%   {$EXTERNALSYM PCSHORT}
--%%   PCLONG = ^CLONG;
--%%   {$EXTERNALSYM PCLONG}

--
-- NLS basics (Locale and Language Ids)
--

--%%   LCID = {$IFDEF USE_DELPHI_TYPES} Windows.LCID {$ELSE} DWORD {$ENDIF};
--%%   {$EXTERNALSYM LCID}
--%%   PLCID = ^LCID;
--%%   {$EXTERNALSYM PLCID}
--%%   LANGID = {$IFDEF USE_DELPHI_TYPES} Windows.LANGID {$ELSE} Word {$ENDIF};
--%%   {$EXTERNALSYM LANGID}
--%%   PLANGID = ^LANGID; // TODO Not in original header (used in MSI)

--
-- Logical Data Type - These are 32-bit logical values.
--

   subtype Logical_Type is Unsigned_32;
   subtype Logical_Ptr is Unsigned_32_Ptr;
   subtype Logical_CPtr is Unsigned_32_CPtr;
--%%   PLOGICAL = ^ULONG;
--%%   {$EXTERNALSYM PLOGICAL}

--
-- NTSTATUS
--

   subtype Ntstatus_Type is Integer_32;
   type Ntstatus_Ptr is access all Integer_32;
   type Ntstatus_CPtr is access constant Integer_32;
--%%   PNTSTATUS = ^NTSTATUS;
--%%   {$EXTERNALSYM PNTSTATUS}
--%%   TNTStatus = NTSTATUS;

--
--  Status values are 32 bit values layed out as follows:
--
--   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
--   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
--  +---+-+-------------------------+-------------------------------+
--  |Sev|C|       Facility          |               Code            |
--  +---+-+-------------------------+-------------------------------+
--
--  where
--
--      Sev - is the severity code
--
--          00 - Success
--          01 - Informational
--          10 - Warning
--          11 - Error
--
--      C - is the Customer code flag
--
--      Facility - is the facility code
--
--      Code - is the facility's status code
--

--
-- Generic test for success on any status value (non-negative numbers
-- indicate success).
--

--%% function NT_SUCCESS(Status: NTSTATUS): BOOL;
--%% {$EXTERNALSYM NT_SUCCESS}

--
-- Generic test for information on any status value.
--

--%% function NT_INFORMATION(Status: NTSTATUS): BOOL;
--%% {$EXTERNALSYM NT_INFORMATION}

--
-- Generic test for warning on any status value.
--

--%% function NT_WARNING(Status: NTSTATUS): BOOL;
--%% {$EXTERNALSYM NT_WARNING}

--
-- Generic test for error on any status value.
--

--%% function NT_ERROR(Status: NTSTATUS): BOOL;
--%% {$EXTERNALSYM NT_ERROR}

   Application_Error_Mask       : constant := 16#2000_0000#;
   Error_Severity_Success       : constant := 16#0000_0000#;
   Error_Severity_Informational : constant := 16#4000_0000#;
   Error_Severity_Warning       : constant := 16#8000_0000#;
   Error_Severity_Error         : constant := 16#C000_0000#;

--
-- Large (64-bit) integer types and operations
--

--%%   LPLARGE_INTEGER = ^LARGE_INTEGER;
--%%   {$EXTERNALSYM LPLARGE_INTEGER}

--%%   {$IFDEF USE_DELPHI_TYPES}
--%%   _LARGE_INTEGER = Windows._LARGE_INTEGER;
--%%   LARGE_INTEGER = Windows.LARGE_INTEGER;
--%%   TLargeInteger = Windows.TLargeInteger;
--%%   {$ELSE}
--%%   _LARGE_INTEGER = record
--%%     case Integer of
--%%     0: (
--%%       LowPart: DWORD;
--%%       HighPart: LONG);
--%%     1: (
--%%       QuadPart: LONGLONG);
--%%   end;
--%%   {$EXTERNALSYM _LARGE_INTEGER}
--%%   LARGE_INTEGER = _LARGE_INTEGER;
--%%   {$EXTERNALSYM LARGE_INTEGER}
--%%   TLargeInteger = LARGE_INTEGER;
--%%   {$ENDIF USE_DELPHI_TYPES}

--%%   PLARGE_INTEGER = ^LARGE_INTEGER;
--%%   {$EXTERNALSYM PLARGE_INTEGER}
--%%   PLargeInteger = LPLARGE_INTEGER;

--%%   LPULARGE_INTEGER = ^ULARGE_INTEGER;
--%%   {$EXTERNALSYM LPULARGE_INTEGER}

--%%   {$IFDEF USE_DELPHI_TYPES}
--%%   ULARGE_INTEGER = Windows.ULARGE_INTEGER;
--%%   TULargeInteger = Windows.TULargeInteger;
--%%   PULargeInteger = Windows.PULargeInteger;
--%%   {$ELSE}
--%%   ULARGE_INTEGER = record
--%%     case Integer of
--%%       0: (
--%%         LowPart: DWORD;
--%%         HighPart: DWORD);
--%%       1: (
--%%         QuadPart: LONGLONG);
--%%   end;
--%%   {$EXTERNALSYM ULARGE_INTEGER}
--%%   TULargeInteger = ULARGE_INTEGER;
--%%   PULargeInteger = LPULARGE_INTEGER;
--%%   {$ENDIF USE_DELPHI_TYPES}

--%%   PULARGE_INTEGER = ^ULARGE_INTEGER;
--%%   {$EXTERNALSYM PULARGE_INTEGER}

--%%   TIME = LARGE_INTEGER;
--%%   {$EXTERNALSYM TIME}
--%%   _TIME = _LARGE_INTEGER;
--%%   {$EXTERNALSYM _TIME}
--%%   PTIME = PLARGE_INTEGER;
--%%   {$EXTERNALSYM PTIME}

--
-- _M_IX86 included so that EM CONTEXT structure compiles with
-- x86 programs. *** TBD should this be for all architectures?
--

--
-- 16 byte aligned type for 128 bit floats
--

--
-- For we define a 128 bit structure and use __declspec(align(16)) pragma to
-- align to 128 bits.
--

--%%   PFloat128 = ^TFloat128;
--%%   _FLOAT128 = record
--%%     LowPart: Int64;
--%%     HighPart: Int64;
--%%   end;
--%%   {$EXTERNALSYM _FLOAT128}
--%%   FLOAT128 = _FLOAT128;
--%%   {$EXTERNALSYM FLOAT128}
--%%   TFloat128 = FLOAT128;

-- Update Sequence Number

   subtype Usn_Type is Integer_64;
   type Usn_Ptr is access all Integer_64;
   type Usn_CPtr is access constant Integer_64;

--
-- Locally Unique Identifier
--

--%%   PLuid = ^LUID;
--%%   _LUID = record
--%%     LowPart: DWORD;
--%%     HighPart: LONG;
--%%   end;
--%%   {$EXTERNALSYM _LUID}
--%%   LUID = _LUID;
--%%   {$EXTERNALSYM LUID}  
--%%   TLuid = LUID;

--%%   DWORDLONG = ULONGLONG;
--%%   {$EXTERNALSYM DWORDLONG}
--%%   PDWORDLONG = ^DWORDLONG;
--%%   {$EXTERNALSYM PDWORDLONG}

--
-- Physical address.
--

--%%   PHYSICAL_ADDRESS = LARGE_INTEGER;
--%%   {$EXTERNALSYM PHYSICAL_ADDRESS}
--%%   PPHYSICAL_ADDRESS = ^LARGE_INTEGER;
--%%   {$EXTERNALSYM PPHYSICAL_ADDRESS}

--
-- Define operations to logically shift an int64 by 0..31 bits and to multiply
-- 32-bits by 32-bits to form a 64-bit product.
--

--
-- The x86 C compiler understands inline assembler. Therefore, inline functions
-- that employ inline assembler are used for shifts of 0..31.  The multiplies
-- rely on the compiler recognizing the cast of the multiplicand to int64 to
-- generate the optimal code inline.
--

--%% function Int32x32To64(a, b: LONG): LONGLONG;
--%% {$EXTERNALSYM Int32x32To64}
--%% function UInt32x32To64(a, b: DWORD): ULONGLONG;
--%% {$EXTERNALSYM UInt32x32To64}

--%% function Int64ShllMod32(Value: ULONGLONG; ShiftCount: DWORD): ULONGLONG;

--%% {$EXTERNALSYM Int64ShllMod32}
--%% function Int64ShraMod32(Value: LONGLONG; ShiftCount: DWORD): LONGLONG;
--%% {$EXTERNALSYM Int64ShraMod32}
--%% function Int64ShrlMod32(Value: ULONGLONG; ShiftCount: DWORD): ULONGLONG;
--%% {$EXTERNALSYM Int64ShrlMod32}

--
-- Event type
--

--%%   _EVENT_TYPE = (NotificationEvent, SynchronizationEvent);
--%%   {$EXTERNALSYM _EVENT_TYPE}
--%%   EVENT_TYPE = _EVENT_TYPE;
--%%   {$EXTERNALSYM EVENT_TYPE}
--%%   TEventType = _EVENT_TYPE;

--
-- Timer type
--

--%%   _TIMER_TYPE = (NotificationTimer, SynchronizationTimer);
--%%   {$EXTERNALSYM _TIMER_TYPE}
--%%   TIMER_TYPE = _TIMER_TYPE;
--%%   {$EXTERNALSYM TIMER_TYPE}

--
-- Wait type
--

--%%   _WAIT_TYPE = (WaitAll, WaitAny);
--%%   {$EXTERNALSYM _WAIT_TYPE}
--%%   WAIT_TYPE = _WAIT_TYPE;
--%%   {$EXTERNALSYM WAIT_TYPE}

--
-- Pointer to an Asciiz string
--

--%%   PSZ = ^CHAR;
--%%   {$EXTERNALSYM PSZ}
--%%   PCSZ = ^CHAR;
--%%   {$EXTERNALSYM PCSZ}

--
-- Counted String
--

--%%   PString = ^TString;
--%%   _STRING = record
--%%     Length: USHORT;
--%%     MaximumLength: USHORT;
--%%     Buffer: PAnsiChar;
--%%   end;
--%%   {$EXTERNALSYM _STRING}
--%%   TString = _STRING;

--%%   ANSI_STRING = _STRING;
--%%   {$EXTERNALSYM ANSI_STRING}
--%%   PANSI_STRING = PSTRING;
--%%   {$EXTERNALSYM PANSI_STRING}

--%%   OEM_STRING = _STRING;
--%%   {$EXTERNALSYM OEM_STRING}
--%%   POEM_STRING = PSTRING;
--%%   {$EXTERNALSYM POEM_STRING}

--
-- CONSTCounted String
--

--%%   PCString = ^CSTRING;
--%%   _CSTRING = record
--%%     Length: USHORT;
--%%     MaximumLength: USHORT;
--%%     Buffer: PAnsiChar;
--%%   end;
--%%   {$EXTERNALSYM _CSTRING}
--%%   CSTRING = _CSTRING;
--%%   {$EXTERNALSYM CSTRING}
--%%   TCString = CSTRING;

--%%   ANSI_NULL = CHAR(0);
--%%   {$EXTERNALSYM ANSI_NULL}
--%%   UNICODE_NULL = WCHAR(0);
--%%   {$EXTERNALSYM UNICODE_NULL}
   Unicode_String_Max_Bytes : constant := 65534;
   Unicode_String_Max_Chars : constant := 32767;

--%%   CANSI_STRING = _STRING;
--%%   {$EXTERNALSYM CANSI_STRING}
--%%   PCANSI_STRING = PSTRING;
--%%   {$EXTERNALSYM PCANSI_STRING}

--
-- Unicode strings are counted 16-bit character strings. If they are
-- NULL terminated, Length does not include trailing NULL.
--

--%%   PUNICODE_STRING = ^UNICODE_STRING;
--%%   {$EXTERNALSYM PUNICODE_STRING}
--%%   _UNICODE_STRING = record
--%%     Length: USHORT;
--%%     MaximumLength: USHORT;
--%%     Buffer: PWSTR;
--%%   end;
--%%   {$EXTERNALSYM _UNICODE_STRING}
--%%   UNICODE_STRING = _UNICODE_STRING;
--%%   {$EXTERNALSYM UNICODE_STRING}
--%%   PCUNICODE_STRING = ^UNICODE_STRING;
--%%   {$EXTERNALSYM PCUNICODE_STRING}
--%%   TUnicodeString = UNICODE_STRING;
--%%   PUnicodeString = PUNICODE_STRING;

--
-- Boolean
--

-- typedef UCHAR BOOLEAN;
--%%   PBOOLEAN = ^ByteBool;
--%%   {$EXTERNALSYM PBOOLEAN}

--
--  Doubly linked list structure.  Can be used as either a list head, or
--  as link words.
--

--%%   PLIST_ENTRY = ^LIST_ENTRY;
--%%   {$EXTERNALSYM PLIST_ENTRY}

--%%   {$IFDEF USE_DELPHI_TYPES}
--%%   _LIST_ENTRY = Windows._LIST_ENTRY;
--%%   LIST_ENTRY = Windows.LIST_ENTRY;
--%%   TListEntry = Windows.TListEntry;
--%%   PListEntry = Windows.PListEntry;
--%%   {$ELSE}
--%%   _LIST_ENTRY = record
--%%     Flink: PLIST_ENTRY;
--%%     Blink: PLIST_ENTRY;
--%%   end;
--%%   {$EXTERNALSYM _LIST_ENTRY}
--%%   LIST_ENTRY = _LIST_ENTRY;
--%%   {$EXTERNALSYM LIST_ENTRY}
--%%   TListEntry = LIST_ENTRY;
--%%   PListEntry = PLIST_ENTRY;
--%%   {$ENDIF USE_DELPHI_TYPES}

--%%   PRLIST_ENTRY = ^LIST_ENTRY;
--%%   {$EXTERNALSYM PLIST_ENTRY}

--
--  Singly linked list structure. Can be used as either a list head, or
--  as link words.
--

   type Single_List_Entry_Type;
   type Single_List_Entry_Ptr is access all Single_List_Entry_Type;
   type Single_List_Entry_CPtr is access constant Single_List_Entry_Type;
   type Single_List_Entry_Type is record
      Next : SINGLE_LIST_ENTRY_Ptr;
   end record;

--
-- These are needed for portable debugger support.
--

--%%   PLIST_ENTRY32 = ^LIST_ENTRY32;
--%%   {$EXTERNALSYM PLIST_ENTRY32}  
--%%   {$EXTERNALSYM PLIST_ENTRY32}
--%%   LIST_ENTRY32 = record
--%%     Flink: DWORD;
--%%     Blink: DWORD;
--%%   end;
--%%   {$EXTERNALSYM LIST_ENTRY32}
--%%   TListEntry32 = LIST_ENTRY32;
--%%   PListEntry32 = PLIST_ENTRY32;

--%%   PLIST_ENTRY64 = ^LIST_ENTRY64;
--%%   {$EXTERNALSYM PLIST_ENTRY64}
--%%   LIST_ENTRY64 = record
--%%     Flink: ULONGLONG;
--%%     Blink: ULONGLONG;
--%%   end;
--%%   {$EXTERNALSYM LIST_ENTRY64}
--%%   TListEntry64 = LIST_ENTRY64;
--%%   PListEntry64 = PLIST_ENTRY64;

--%% procedure ListEntry32To64(l32: PLIST_ENTRY32; l64: PLIST_ENTRY64);
--%% {$EXTERNALSYM ListEntry32To64}

--%% procedure ListEntry64To32(l64: PLIST_ENTRY64; l32: PLIST_ENTRY32);
--%% {$EXTERNALSYM ListEntry64To32}

--
-- These macros are used to walk lists on a target system
--

--%% {
--%% #define CONTAINING_RECORD32(address, type, field) ( \
--%%                                                   (ULONG_PTR)(address) - \
--%%                                                   (ULONG_PTR)(&((type *)0)->field))

--%% #define CONTAINING_RECORD64(address, type, field) ( \
--%%                                                   (ULONGLONG)(address) - \
--%%                                                   (ULONGLONG)(&((type *)0)->field))
--%% }

--%%   PString32 = ^STRING32;
--%%   _STRING32 = record
--%%     Length: USHORT;
--%%     MaximumLength: USHORT;
--%%     Buffer: ULONG;
--%%   end;
--%%   {$EXTERNALSYM _STRING32}
--%%   STRING32 = _STRING32;
--%%   {$EXTERNALSYM STRING32}
--%%   TString32 = STRING32;

--%%   UNICODE_STRING32 = STRING32;
--%%   {$EXTERNALSYM UNICODE_STRING32}
--%%   PUNICODE_STRING32 = ^UNICODE_STRING32;
--%%   {$EXTERNALSYM PUNICODE_STRING32}

--%%   ANSI_STRING32 = STRING32;
--%%   {$EXTERNALSYM ANSI_STRING32}
--%%   PANSI_STRING32 = ^ANSI_STRING32;
--%%   {$EXTERNALSYM PANSI_STRING32}

--%%   PString64 = ^STRING64;
--%%   _STRING64 = record
--%%     Length: USHORT;
--%%     MaximumLength: USHORT;
--%%     Buffer: ULONGLONG;
--%%   end;
--%%   {$EXTERNALSYM _STRING64}
--%%   STRING64 = _STRING64;
--%%   {$EXTERNALSYM STRING64}
--%%   TString64 = STRING64;

--%%   UNICODE_STRING64 = STRING64;
--%%   {$EXTERNALSYM UNICODE_STRING64}
--%%   PUNICODE_STRING64 = ^UNICODE_STRING64;
--%%   {$EXTERNALSYM PUNICODE_STRING64}

--%%   ANSI_STRING64 = STRING64;
--%%   {$EXTERNALSYM ANSI_STRING64}
--%%   PANSI_STRING64 = ^ANSI_STRING64;
--%%   {$EXTERNALSYM PANSI_STRING64}

--
-- Valid values for the Attributes field
--

   Obj_Inherit          : constant := 16#0000_0002#;
   Obj_Permanent        : constant := 16#0000_0010#;
   Obj_Exclusive        : constant := 16#0000_0020#;
   Obj_Case_Insensitive : constant := 16#0000_0040#;
   Obj_Openif           : constant := 16#0000_0080#;
   Obj_Openlink         : constant := 16#0000_0100#;
   Obj_Kernel_Handle    : constant := 16#0000_0200#;
   Obj_Valid_Attributes : constant := 16#0000_03F2#;

--
-- Object Attributes structure
--

   type Object_Attributes_Type;
   type Object_Attributes_Ptr is access all Object_Attributes_Type;
   type Object_Attributes_CPtr is access constant Object_Attributes_Type;
   type Object_Attributes_Type is record
      Length : Unsigned_32;
      Root_Directory : Handle_Type;
      Object_Name : UNICODE_STRING_Ptr;
      Attributes : Unsigned_32;
      Security_Descriptor : System.Address;  -- Points to type SECURITY_DESCRIPTOR
      Security_Quality_Of_Service : System.Address; -- Points to type SECURITY_QUALITY_OF_SERVICE
   end record;

--%% procedure InitializeObjectAttributes(p: POBJECT_ATTRIBUTES; n: PUNICODE_STRING;
--%%   a: ULONG; r: HANDLE; s: PVOID{PSECURITY_DESCRIPTOR});
--%% {$EXTERNALSYM InitializeObjectAttributes}

--
-- Constants
--


-- #define FALSE   0
-- #define TRUE    1

   Null   : constant := 0;
   Null64 : constant := 0;

-- #include <guiddef.h>

--%%   PObjectId = ^OBJECTID;
--%%   _OBJECTID = record  // size is 20
--%%     Lineage: GUID;
--%%     Uniquifier: ULONG;
--%%   end;
--%%   {$EXTERNALSYM _OBJECTID}
--%%   OBJECTID = _OBJECTID;
--%%   {$EXTERNALSYM OBJECTID}
--%%   TObjectId = OBJECTID;

   Minchar   : constant := 16#80#;
   Maxchar   : constant := 16#7F#;
   Minshort  : constant := 16#8000#;
   Maxshort  : constant := 16#7FFF#;
   Minlong   : constant := 16#8000_0000#;
   Maxlong   : constant := 16#7FFF_FFFF#;
   Maxuchar  : constant := 16#FF#;
   Maxushort : constant := 16#FFFF#;
   Maxulong  : constant := 16#FFFF_FFFF#;

--
-- Useful Helper Macros
--

--
-- Determine if an argument is present by testing the value of the pointer
-- to the argument value.
--

--%% function ARGUMENT_PRESENT(ArgumentPointer: Pointer): BOOL;
--%% {$EXTERNALSYM ARGUMENT_PRESENT}

--
-- Exception handler routine definition.
--

-- struct _CONTEXT;
-- struct _EXCEPTION_RECORD;

-- type
--  PEXCEPTION_ROUTINE = function(ExceptionRecord: LP_EXCEPTION_RECORD;
--    EstablisherFrame: PVOID; ContextRecord: LPCONTEXT;
--    DispatcherContext: PVOID): EXCEPTION_DISPOSITION; stdcall;
--  {$EXTERNALSYM PEXCEPTION_ROUTINE}

--
-- Interrupt Request Level (IRQL)
--

   subtype Kirql_Type is Unsigned_8;
   subtype Kirql_Ptr is Unsigned_8_Ptr;
   subtype Kirql_CPtr is Unsigned_8_CPtr;
--%%   PKIRQL = ^KIRQL;
--%%   {$EXTERNALSYM PKIRQL}

--
-- Product types
--

--%%   _NT_PRODUCT_TYPE = (Filler0, NtProductWinNt, NtProductLanManNt, NtProductServer);
--%%   {$EXTERNALSYM _NT_PRODUCT_TYPE}
--%%   NT_PRODUCT_TYPE = _NT_PRODUCT_TYPE;
--%%   {$EXTERNALSYM NT_PRODUCT_TYPE}
--%%   PNT_PRODUCT_TYPE = ^NT_PRODUCT_TYPE;
--%%   TNtProductType = _NT_PRODUCT_TYPE;

--
-- the bit mask, SharedUserData->SuiteMask, is a ULONG
-- so there can be a maximum of 32 entries
-- in this enum.
--

--%%   _SUITE_TYPE = (
--%%     SmallBusiness,
--%%     Enterprise,
--%%     BackOffice,
--%%     CommunicationServer,
--%%     TerminalServer,
--%%     SmallBusinessRestricted,
--%%     EmbeddedNT,
--%%     DataCenter,
--%%     SingleUserTS,
--%%     MaxSuiteType);
--%%   {$EXTERNALSYM _SUITE_TYPE}
--%%   SUITE_TYPE = _SUITE_TYPE;
--%%   {$EXTERNALSYM SUITE_TYPE}
--%%   TSuiteType = SUITE_TYPE;


   Ver_Server_NT                      : constant := 16#8000_0000#;
   Ver_Workstation_NT                 : constant := 16#4000_0000#;
   Ver_Suite_Smallbusiness            : constant := 16#0000_0001#;
   Ver_Suite_Enterprise               : constant := 16#0000_0002#;
   Ver_Suite_Backoffice               : constant := 16#0000_0004#;
   Ver_Suite_Communications           : constant := 16#0000_0008#;
   Ver_Suite_Terminal                 : constant := 16#0000_0010#;
   Ver_Suite_Smallbusiness_Restricted : constant := 16#0000_0020#;
   Ver_Suite_Embeddednt               : constant := 16#0000_0040#;
   Ver_Suite_Datacenter               : constant := 16#0000_0080#;
   Ver_Suite_Singleuserts             : constant := 16#0000_0100#;
   Ver_Suite_Personal                 : constant := 16#0000_0200#;
   Ver_Suite_Blade                    : constant := 16#0000_0400#;

-- ntdef.h

--%%   error_status_t = Longword;
--%%   {$EXTERNALSYM error_status_t}
--%%   wchar_t = Word;
--%%   {$EXTERNALSYM wchar_t}

--
-- The following types are guaranteed to be signed and 32 bits wide.
--

--%%   INT_PTR = Integer;
--%%   {$EXTERNALSYM INT_PTR}
--%%   PINT_PTR = ^INT_PTR;
--%%   {$EXTERNALSYM PINT_PTR}
--%%   UINT_PTR = Longword;
--%%   {$EXTERNALSYM UINT_PTR}
--%%   PUINT_PTR = ^UINT_PTR;
--%%   {$EXTERNALSYM PUINT_PTR}
--%%   LONG_PTR = Longint;
--%%   {$EXTERNALSYM LONG_PTR}
--%%   PLONG_PTR = ^LONG_PTR;
--%%   {$EXTERNALSYM PLONG_PTR}
--%%   ULONG_PTR = Longword;
--%%   {$EXTERNALSYM ULONG_PTR}
--%%   PULONG_PTR = ^ULONG_PTR;
--%%   {$EXTERNALSYM PULONG_PTR}

--%%   LONG32 = Integer;
--%%   {$EXTERNALSYM LONG32}
--%%   PLONG32 = ^LONG32;
--%%   {$EXTERNALSYM PLONG32}
--%%   INT32 = Integer;
--%%   {$EXTERNALSYM INT32}
--%%   PINT32 = ^INT32;
--%%   {$EXTERNALSYM PINT32}

--
-- The following types are guaranteed to be unsigned and 32 bits wide.
--

--%%   ULONG32 = Longword;
--%%   {$EXTERNALSYM ULONG32}
--%%   PULONG32 = ^ULONG32;
--%%   {$EXTERNALSYM PULONG32}
--%%   DWORD32 = Longword;
--%%   {$EXTERNALSYM DWORD32}
--%%   PDWORD32 = ^DWORD32;
--%%   {$EXTERNALSYM PDWORD32}
--%%   UINT32 = Longword;
--%%   {$EXTERNALSYM UINT32}
--%%   PUINT32 = ^UINT32;
--%%   {$EXTERNALSYM PUINT32}

   Max_Path : constant := 260;


-- unsigned char       BYTE;
-- unsigned short      WORD;

--%%   FLOAT = Single;
--%%   {$EXTERNALSYM FLOAT}
--%%   PFLOAT = ^FLOAT;
--%%   {$EXTERNALSYM PFLOAT}
   -- PBOOL has been silently aliased to Boolean_32_Ptr
--%%   LPBOOL = {$IFDEF USE_DELPHI_TYPES} Windows.PBOOL {$ELSE} ^BOOL {$ENDIF};
--%%   {$EXTERNALSYM LPBOOL}
--%%   PBYTE = {$IFDEF USE_DELPHI_TYPES} Windows.PBYTE {$ELSE} ^Byte {$ENDIF};
--%%   {$EXTERNALSYM PBYTE}
--%%   LPBYTE = {$IFDEF USE_DELPHI_TYPES} Windows.PBYTE {$ELSE} ^Byte {$ENDIF};
--%%   {$EXTERNALSYM LPBYTE}
--%%   PINT = {$IFDEF USE_DELPHI_TYPES} Windows.PINT {$ELSE} ^INT {$ENDIF};
--%%   {$EXTERNALSYM PINT}
--%%   PUINT = {$IFDEF USE_DELPHI_TYPES} Windows.PUINT {$ELSE} ^UINT {$ENDIF};
--%%   {$EXTERNALSYM PUINT}
--%%   LPUINT = {$IFDEF USE_DELPHI_TYPES} Windows.PUINT {$ELSE} ^UINT {$ENDIF};
--%%   {$EXTERNALSYM LPUINT}
--%%   LPINT = {$IFDEF USE_DELPHI_TYPES} Windows.PINT {$ELSE} ^INT {$ENDIF};
--%%   {$EXTERNALSYM LPINT}
--%%   PWORD = {$IFDEF USE_DELPHI_TYPES} Windows.PWORD {$ELSE} ^WORD {$ENDIF};
--%%   {$EXTERNALSYM PWORD}
--%%   LPWORD = {$IFDEF USE_DELPHI_TYPES} Windows.PWORD {$ELSE} ^WORD {$ENDIF};
--%%   {$EXTERNALSYM LPWORD}
--%%   LPLONG = ^LONG;
--%%   {$EXTERNALSYM LPLONG}
--%%   PDWORD = {$IFDEF USE_DELPHI_TYPES} Windows.PDWORD {$ELSE} ^DWORD {$ENDIF};
--%%   {$EXTERNALSYM PDWORD}
--%%   LPDWORD = {$IFDEF USE_DELPHI_TYPES} Windows.LPDWORD {$ELSE} ^DWORD {$ENDIF};
--%%   {$EXTERNALSYM LPDWORD}
--%%   LPVOID = Pointer;
--%%   {$EXTERNALSYM LPVOID}
--%%   LPCVOID = Pointer;
--%%   {$EXTERNALSYM LPCVOID}
--%%   LPLPVOID = ^LPVOID;
--%%   {$NODEFINE LPVOID}

--%%   INT = Integer;
--%%   {$EXTERNALSYM INT}
--%%   UINT = {$IFDEF USE_DELPHI_TYPES} Windows.UINT {$ELSE} Longword {$ENDIF};
--%%   {$EXTERNALSYM UINT}

-- Types use for passing & returning polymorphic values

--%%   WPARAM = {$IFDEF USE_DELPHI_TYPES} Windows.WPARAM {$ELSE} UINT_PTR {$ENDIF};
--%%   {$EXTERNALSYM WPARAM}
--%%   LPARAM = {$IFDEF USE_DELPHI_TYPES} Windows.LPARAM {$ELSE} LONG_PTR {$ENDIF};
--%%   {$EXTERNALSYM LPARAM}
--%%   LRESULT = {$IFDEF USE_DELPHI_TYPES} Windows.LRESULT {$ELSE} LONG_PTR {$ENDIF};
--%%   {$EXTERNALSYM LRESULT}

--%% function MAKEWORD(a, b: BYTE): WORD;
--%% {$EXTERNALSYM MAKEWORD}
--%% function MAKELONG(a, b: WORD): DWORD;
--%% {$EXTERNALSYM MAKELONG}

--%% function LOWORD(L: DWORD): WORD;
--%% {$EXTERNALSYM LOWORD}
--%% function HIWORD(L: DWORD): WORD;
--%% {$EXTERNALSYM HIWORD}
--%% function LOBYTE(W: WORD): BYTE;
--%% {$EXTERNALSYM LOBYTE}
--%% function HIBYTE(W: WORD): BYTE;
--%% {$EXTERNALSYM HIBYTE}

--%%   HWND = {$IFDEF USE_DELPHI_TYPES} Windows.HWND {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HWND}
--%%   LPHWND = ^HWND;
--%%   {$EXTERNALSYM LPHWND}
--%%   HHOOK = {$IFDEF USE_DELPHI_TYPES} Windows.HHOOK {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HHOOK}
--%%   LPHHOOK = ^HHOOK;
--%%   {$EXTERNALSYM LPHHOOK}
   subtype Hevent_Type is Handle_Type;
   type Hevent_Ptr is access all Handle_Type;
   type Hevent_CPtr is access constant Handle_Type;

--%%   ATOM = {$IFDEF USE_DELPHI_TYPES} Windows.ATOM {$ELSE} WORD {$ENDIF};
--%%   {$EXTERNALSYM ATOM}

--%%   SPHANDLE = ^HANDLE;
--%%   {$EXTERNALSYM SPHANDLE}
--%%   LPHANDLE = ^HANDLE;
--%%   {$EXTERNALSYM LPHANDLE}
--%%   HGLOBAL = {$IFDEF USE_DELPHI_TYPES} Windows.HGLOBAL {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HGLOBAL}
--%%   HLOCAL = {$IFDEF USE_DELPHI_TYPES} Windows.HLOCAL {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HLOCAL}
--%%   //GLOBALHANDLE = HANDLE;
--%%   //{$EXTERNALSYM GLOBALHANDLE} // clashes with WinBase.GlobalHandle function
--%%   //LOCALHANDLE = HANDLE; // todo clashes with WinBase.LocalHandle function
--%%   //{$EXTERNALSYM LOCALHANDLE}
--%%   FARPROC = {$IFDEF USE_DELPHI_TYPES} Windows.FARPROC {$ELSE} function: Integer; stdcall {$ENDIF};
--%%   {$EXTERNALSYM FARPROC}
--%%   NEARPROC = function: Integer; stdcall;
--%%   {$EXTERNALSYM NEARPROC}
--%%   PROC = function: Integer; stdcall;
--%%   {$EXTERNALSYM PROC}

--%%   HGDIOBJ = {$IFDEF USE_DELPHI_TYPES} Windows.HGDIOBJ {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HGDIOBJ}

--%%   HKEY = {$IFDEF USE_DELPHI_TYPES} Windows.HKEY {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HKEY}
--%%   PHKEY = {$IFDEF USE_DELPHI_TYPES} Windows.PHKEY {$ELSE} ^HKEY {$ENDIF};
--%%   {$EXTERNALSYM PHKEY}

--%%   HACCEL = {$IFDEF USE_DELPHI_TYPES} Windows.HACCEL {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HACCEL}

--%%   HBITMAP = {$IFDEF USE_DELPHI_TYPES} Windows.HBITMAP {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HBITMAP}
--%%   HBRUSH = {$IFDEF USE_DELPHI_TYPES} Windows.HBRUSH {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HBRUSH}

--%%   HCOLORSPACE = {$IFDEF USE_DELPHI_TYPES} Windows.HCOLORSPACE {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HCOLORSPACE}

--%%   HDC = {$IFDEF USE_DELPHI_TYPES} Windows.HDC {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HDC}
--%%   HGLRC = {$IFDEF USE_DELPHI_TYPES} Windows.HGLRC {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HGLRC}
--%%   HDESK = {$IFDEF USE_DELPHI_TYPES} Windows.HDESK {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HDESK}
--%%   HENHMETAFILE = {$IFDEF USE_DELPHI_TYPES} Windows.HENHMETAFILE {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HENHMETAFILE}
--%%   HFONT = {$IFDEF USE_DELPHI_TYPES} Windows.HFONT {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HFONT}
--%%   HICON = {$IFDEF USE_DELPHI_TYPES} Windows.HICON {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HICON}
--%%   HMENU = {$IFDEF USE_DELPHI_TYPES} Windows.HMENU {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HMENU}
--%%   HMETAFILE = {$IFDEF USE_DELPHI_TYPES} Windows.HMETAFILE {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HMETAFILE}

--%%   // (rom) HINSTANCE collides with Delphi HInstance global variable
--%%   HINST = {$IFDEF USE_DELPHI_TYPES} Windows.HINST {$ELSE} HANDLE {$ENDIF};

--%%   HMODULE = {$IFDEF USE_DELPHI_TYPES} Windows.HMODULE {$ELSE} HINST {$ENDIF};
--%%   {$EXTERNALSYM HMODULE}
--%%   HPALETTE = {$IFDEF USE_DELPHI_TYPES} Windows.HPALETTE {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HPALETTE}
--%%   HPEN = {$IFDEF USE_DELPHI_TYPES} Windows.HPEN {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HPEN}
--%%   HRGN = {$IFDEF USE_DELPHI_TYPES} Windows.HRGN {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HRGN}
--%%   HRSRC = {$IFDEF USE_DELPHI_TYPES} Windows.HRSRC {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HRSRC}
--%%   HSTR = {$IFDEF USE_DELPHI_TYPES} Windows.HSTR {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HSTR}
--%%   HTASK = {$IFDEF USE_DELPHI_TYPES} Windows.HTASK {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HTASK}
--%%   HWINSTA = {$IFDEF USE_DELPHI_TYPES} Windows.HWINSTA {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HWINSTA}
--%%   HKL = {$IFDEF USE_DELPHI_TYPES} Windows.HKL {$ELSE} HANDLE {$ENDIF};
--%%   {$EXTERNALSYM HKL}
--%%   PHKL = {$IFDEF USE_DELPHI_TYPES} ^HKL {$ELSE} ^HANDLE {$ENDIF};
--%%   {$EXTERNALSYM PHKL}

   subtype Hmonitor_Type is Handle_Type;
   type Hmonitor_Ptr is access all Handle_Type;
   type Hmonitor_CPtr is access constant Handle_Type;
   subtype Hwineventhook_Type is Handle_Type;
   type Hwineventhook_Ptr is access all Handle_Type;
   type Hwineventhook_CPtr is access constant Handle_Type;
   subtype Humpd_Type is Handle_Type;
   type Humpd_Ptr is access all Handle_Type;
   type Humpd_CPtr is access constant Handle_Type;

--%%   HFILE = {$IFDEF USE_DELPHI_TYPES} Windows.HFILE {$ELSE} Longword {$ENDIF};
--%%   {$EXTERNALSYM HFILE}
--%%   HCURSOR = {$IFDEF USE_DELPHI_TYPES} Windows.HCURSOR {$ELSE} HICON {$ENDIF};
--%%   {$EXTERNALSYM HCURSOR}

--%%   COLORREF = {$IFDEF USE_DELPHI_TYPES} Windows.COLORREF {$ELSE} DWORD {$ENDIF};
--%%   {$EXTERNALSYM COLORREF}
--%%   LPCOLORREF = ^COLORREF;
--%%   {$EXTERNALSYM LPCOLORREF}

--%%   PHMODULE = ^HMODULE;
--%%   {$NODEFINE PHMODULE}

--%%   HFILE_ERROR = HFILE(-1);
--%%   {$EXTERNALSYM HFILE_ERROR}

--%%   LPRECT = ^RECT;
--%%   {$EXTERNALSYM LPRECT}
--%%   tagRECT = record
--%%     left: LONG;
--%%     top: LONG;
--%%     right: LONG;
--%%     bottom: LONG;
--%%   end;
--%%   {$EXTERNALSYM tagRECT}
--%%   RECT = {$IFDEF USE_DELPHI_TYPES} Windows.TRect {$ELSE} tagRECT {$ENDIF};
--%%   {$EXTERNALSYM RECT}
--%%   NPRECT = ^RECT;
--%%   {$EXTERNALSYM NPRECT}
--%%   LPCRECT = ^RECT;
--%%   {$EXTERNALSYM LPCRECT}
--%%   TRect = {$IFDEF USE_DELPHI_TYPES} Windows.TRect {$ELSE} RECT {$ENDIF};
--%%   PRect = {$IFDEF USE_DELPHI_TYPES} Windows.PRect {$ELSE} LPRECT {$ENDIF};

--%%   LPRECTL = ^RECTL;
--%%   {$EXTERNALSYM LPRECTL}
--%%   _RECTL = record
--%%     left: LONG;
--%%     top: LONG;
--%%     right: LONG;
--%%     bottom: LONG;
--%%   end;
--%%   {$EXTERNALSYM _RECTL}
--%%   RECTL = _RECTL;
--%%   {$EXTERNALSYM RECTL}
--%%   LPCRECTL = ^_RECTL;
--%%   {$EXTERNALSYM LPCRECTL}
--%%   TRectl = RECTL;
--%%   PRectl = LPRECTL;

--%%   LPPOINT = ^POINT;
--%%   {$EXTERNALSYM LPPOINT}
--%%   tagPOINT = record
--%%     x: LONG;
--%%     y: LONG;
--%%   end;
--%%   {$EXTERNALSYM tagPOINT}
--%%   NPPOINT = ^tagPoint;
--%%   {$EXTERNALSYM NPPOINT}
--%%   POINT = tagPOINT;
--%%   {$EXTERNALSYM tagPOINT}
--%%   TPoint = {$IFDEF USE_DELPHI_TYPES} Windows.TPoint {$ELSE} POINT {$ENDIF};
--%%   PPoint = {$IFDEF USE_DELPHI_TYPES} Windows.PPoint {$ELSE} LPPOINT {$ENDIF};

--%%   PPointl = ^POINTL;
--%%   _POINTL = record
--%%     x: LONG;
--%%     y: LONG;
--%%   end;
--%%   {$EXTERNALSYM _POINTL}
--%%   POINTL = _POINTL;
--%%   {$EXTERNALSYM POINTL}
--%%   TPointl = POINTL;

--%%   LPSIZE = ^TSize;
--%%   {$EXTERNALSYM LPSIZE}

--%%   {$IFDEF USE_DELPHI_TYPES}
--%%   TSize = Windows.TSize;
--%%   PSize = Windows.PSize;
--%%   {$ELSE}
--%%   tagSIZE = record
--%%     cx: LONG;
--%%     cy: LONG;
--%%   end;
--%%   {$EXTERNALSYM tagSIZE}
--%%   TSize = tagSIZE;
--%%   PSize = LPSIZE;
--%%   {$ENDIF USE_DELPHI_TYPES}

--%%   SIZE = TSize;
--%%   {$EXTERNALSYM SIZE}
--%%   SIZEL = TSize;
--%%   {$EXTERNALSYM SIZEL}
--%%   PSIZEL = PSize;
--%%   {$EXTERNALSYM PSIZEL}
--%%   LPSIZEL = PSize;
--%%   {$EXTERNALSYM LPSIZEL}

--%%   LPPOINTS = ^POINTS;
--%%   {$EXTERNALSYM LPPOINTS}
--%%   tagPOINTS = record
--%%     x: SHORT;
--%%     y: SHORT;
--%%   end;
--%%   {$EXTERNALSYM tagPOINTS}
--%%   POINTS = tagPOINTS;
--%%   {$EXTERNALSYM POINTS}
--%%   TPoints = POINTS;
--%%   PPoints = LPPOINTS;

--
--  File System time stamps are represented with the following structure:
--

--%%   _FILETIME = record
--%%     dwLowDateTime: DWORD;
--%%     dwHighDateTime: DWORD;
--%%   end;
--%%   {$EXTERNALSYM _FILETIME}
--%%   FILETIME = _FILETIME;
--%%   {$EXTERNALSYM FILETIME}
--%%   PFILETIME = ^FILETIME;
--%%   {$EXTERNALSYM PFILETIME}
--%%   LPFILETIME = PFILETIME;
--%%   {$EXTERNALSYM LPFILETIME}
--%%   TFileTime = FILETIME;

-- mode selections for the device mode function

   Dm_Update : constant := 1;
   Dm_Copy   : constant := 2;
   Dm_Prompt : constant := 4;
   Dm_Modify : constant := 8;

   Dm_In_Buffer   : constant := Dm_Modify;
   Dm_In_Prompt   : constant := Dm_Prompt;
   Dm_Out_Buffer  : constant := Dm_Copy;
   Dm_Out_Default : constant := Dm_Update;

-- device capabilities indices

   Dc_Fields           : constant := 1;
   Dc_Papers           : constant := 2;
   Dc_Papersize        : constant := 3;
   Dc_Minextent        : constant := 4;
   Dc_Maxextent        : constant := 5;
   Dc_Bins             : constant := 6;
   Dc_Duplex           : constant := 7;
   Dc_Size             : constant := 8;
   Dc_Extra            : constant := 9;
   Dc_Version          : constant := 10;
   Dc_Driver           : constant := 11;
   Dc_Binnames         : constant := 12;
   Dc_Enumresolutions  : constant := 13;
   Dc_Filedependencies : constant := 14;
   Dc_Truetype         : constant := 15;
   Dc_Papernames       : constant := 16;
   Dc_Orientation      : constant := 17;
   Dc_Copies           : constant := 18;

--
-- HALF_PTR is half the size of a pointer it intended for use with
-- within strcuture which contain a pointer and two small fields.
-- UHALF_PTR is the unsigned variation.
--

   Address_Tag_Bit : constant := 16#8000_0000#;

--%%   UHALF_PTR = Byte;
--%%   {$EXTERNALSYM UHALF_PTR}
--%%   PUHALF_PTR = ^UHALF_PTR;
--%%   {$EXTERNALSYM PUHALF_PTR}
--%%   HALF_PTR = Shortint;
--%%   {$EXTERNALSYM HALF_PTR}
--%%   PHALF_PTR = ^HALF_PTR;
--%%   {$EXTERNALSYM PHALF_PTR}

--%%   SHANDLE_PTR = Longint;
--%%   {$EXTERNALSYM SHANDLE_PTR}
--%%   HANDLE_PTR = Longint;
--%%   {$EXTERNALSYM HANDLE_PTR}

--
-- SIZE_T used for counts or ranges which need to span the range of
-- of a pointer.  SSIZE_T is the signed variation.
--

--%%   SIZE_T = ULONG_PTR;
--%%   {$EXTERNALSYM SIZE_T}
--%%   PSIZE_T = ^SIZE_T;
--%%   {$EXTERNALSYM PSIZE_T}
--%%   SSIZE_T = LONG_PTR;
--%%   {$EXTERNALSYM SSIZE_T}
--%%   PSSIZE_T = ^SSIZE_T;
--%%   {$EXTERNALSYM PSSIZE_T}

--
-- Add Windows flavor DWORD_PTR types
--

--%%   DWORD_PTR = ULONG_PTR;
--%%   {$EXTERNALSYM DWORD_PTR}
--%%   PDWORD_PTR = ^DWORD_PTR;
--%%   {$EXTERNALSYM PDWORD_PTR}

--
-- The following types are guaranteed to be signed and 64 bits wide.
--

--%%   LONG64 = Int64;
--%%   {$EXTERNALSYM LONG64}
--%%   PLONG64 = ^LONG64;
--%%   {$EXTERNALSYM PLONG64}

--%%   PINT64 = ^Int64;
--%%   {$EXTERNALSYM PINT64}

--
-- The following types are guaranteed to be unsigned and 64 bits wide.
--

--%%   ULONG64 = Int64;
--%%   {$EXTERNALSYM ULONG64}
--%%   PULONG64 = ^ULONG64;
--%%   {$EXTERNALSYM PULONG64}
--%%   DWORD64 = Int64;
--%%   {$EXTERNALSYM DWORD64}
--%%   PDWORD64 = ^DWORD64;
--%%   {$EXTERNALSYM PDWORD64}
--%%   UINT64 = Int64;
--%%   {$EXTERNALSYM UINT64}
--%%   PUINT64 = ^UINT64;
--%%   {$EXTERNALSYM PUINT64}

--%%   MAXUINT_PTR   = not UINT_PTR(0);
--%%   {$EXTERNALSYM MAXUINT_PTR}
--%%   MAXINT_PTR    = INT_PTR((MAXUINT_PTR shr 1));
--%%   {$EXTERNALSYM MAXINT_PTR}
--%%   MININT_PTR    = not MAXINT_PTR;
--%%   {$EXTERNALSYM MININT_PTR}

--%%   MAXULONG_PTR  = not ULONG_PTR(0);
--%%   {$EXTERNALSYM MAXULONG_PTR}
--%%   MAXLONG_PTR   = LONG_PTR(MAXULONG_PTR shr 1);
--%%   {$EXTERNALSYM MAXLONG_PTR}
--%%   MINLONG_PTR   = not MAXLONG_PTR;
--%%   {$EXTERNALSYM MINLONG_PTR}

--%%   MAXUHALF_PTR  = UHALF_PTR( not 0);
--%%   {$EXTERNALSYM MAXUHALF_PTR}
--%%   MAXHALF_PTR   = HALF_PTR(MAXUHALF_PTR shr 1);
--%%   {$EXTERNALSYM MAXHALF_PTR}
--%%   MINHALF_PTR   = not MAXHALF_PTR;
--%%   {$EXTERNALSYM MINHALF_PTR}

-- basetsd

--%%   INT8 = Shortint;
--%%   {$EXTERNALSYM INT8}
--%%   PINT8 = ^INT8;
--%%   {$EXTERNALSYM PINT8}
--%%   INT16 = Smallint;
--%%   {$EXTERNALSYM INT16}
--%%   PINT16 = ^INT16;
--%%   {$EXTERNALSYM PINT16}
--%%   UINT8 = Byte;
--%%   {$EXTERNALSYM UINT8}
--%%   PUINT8 = ^UINT8;
--%%   {$EXTERNALSYM PUINT8}
--%%   UINT16 = Word;
--%%   {$EXTERNALSYM UINT16}
--%%   PUINT16 = ^UINT16;
--%%   {$EXTERNALSYM PUINT16}

--
-- Thread affinity.
--

--%%   KAFFINITY = ULONG_PTR;
--%%   {$EXTERNALSYM KAFFINITY}
--%%   PKAFFINITY = ^KAFFINITY;
--%%   {$EXTERNALSYM PKAFFINITY}

--%%   // (rom) missing types
--%%   LPCASTR = ^AnsiChar;
--%%   LPASTR = ^AnsiChar;
--%%   PCASTR = ^AnsiChar;
--%%   PASTR = ^AnsiChar;

--%%   PPCWSTR = ^LPCWSTR;
--%%   PPCASTR = ^LPCASTR;
--%%   PPCSTR  = ^LPCTSTR;
--%%   PPWSTR = ^LPWSTR;
--%%   PPASTR = ^LPASTR;
--%%   PPSTR  = ^LPTSTR;
--%%   PPTCHAR = ^PTCHAR;
--%%   LPLPCTSTR = ^LPCTSTR;

--%%   TFarProc = Pointer;

--%% {$ENDIF JWA_IMPLEMENTATIONSECTION}
-- ***



--%% {$IFNDEF JWA_OMIT_SECTIONS}
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--%% implementation
--%%
--%% uses
--%%   JwaWinNT;
--%% {$ENDIF JWA_OMIT_SECTIONS}
--%%
--%% {$IFNDEF JWA_INTERFACESECTION}
--%%
--%% {$IFNDEF USE_DELPHI_TYPES}
--%% const
--%%   kernel32 = 'kernel32.dll';
--%% {$ENDIF !USE_DELPHI_TYPES}
--%%
--%% function Int32x32To64(a, b: LONG): LONGLONG;
--%% begin
--%%   Result := Int64(a) * Int64(b);
--%% end;
--%%
--%% function UInt32x32To64(a, b: DWORD): ULONGLONG;
--%% begin
--%%   Result := ULONGLONG(a) * ULONGLONG(b);
--%% end;
--%%
--%% function Int64ShllMod32(Value: ULONGLONG; ShiftCount: DWORD): ULONGLONG;
--%% asm
--%%         MOV     ECX, ShiftCount
--%%         MOV     EAX, DWORD PTR [Value]
--%%         MOV     EDX, DWORD PTR [Value + 4]
--%%         SHLD    EDX, EAX, CL
--%%         SHL     EAX, CL
--%% end;
--%%
--%% function Int64ShraMod32(Value: LONGLONG; ShiftCount: DWORD): LONGLONG;
--%% asm
--%%         MOV     ECX, ShiftCount
--%%         MOV     EAX, DWORD PTR [Value]
--%%         MOV     EDX, DWORD PTR [Value + 4]
--%%         SHRD    EAX, EDX, CL
--%%         SAR     EDX, CL
--%% end;
--%%
--%% function Int64ShrlMod32(Value: ULONGLONG; ShiftCount: DWORD): ULONGLONG;
--%% asm
--%%         MOV     ECX, ShiftCount
--%%         MOV     EAX, DWORD PTR [Value]
--%%         MOV     EDX, DWORD PTR [Value + 4]
--%%         SHRD    EAX, EDX, CL
--%%         SHR     EDX, CL
--%% end;
--%%
--%% procedure ListEntry32To64(l32: PLIST_ENTRY32; l64: PLIST_ENTRY64);
--%% begin
--%%   l64^.Flink := l32^.Flink;
--%%   l64^.Blink := l32^.Blink;
--%% end;
--%%
--%% procedure ListEntry64To32(l64: PLIST_ENTRY64; l32: PLIST_ENTRY32);
--%% begin
--%%   l32^.Flink := ULONG(l64^.Flink);
--%%   l32^.Blink := ULONG(l64^.Blink);
--%% end;
--%%
--%% function NT_SUCCESS(Status: NTSTATUS): BOOL;
--%% begin
--%%   Result := Status >= 0;
--%% end;
--%%
--%% function NT_INFORMATION(Status: NTSTATUS): BOOL;
--%% begin
--%%   Result := (ULONG(Status) shr 30) = 1;
--%% end;
--%%
--%% function NT_WARNING(Status: NTSTATUS): BOOL;
--%% begin
--%%   Result := (ULONG(Status) shr 30) = 2;
--%% end;
--%%
--%% function NT_ERROR(Status: NTSTATUS): BOOL;
--%% begin
--%%   Result := (ULONG(Status) shr 30) = 3;
--%% end;
--%%
--%% procedure InitializeObjectAttributes(p: POBJECT_ATTRIBUTES; n: PUNICODE_STRING;
--%%   a: ULONG; r: HANDLE; s: PVOID{PSECURITY_DESCRIPTOR});
--%% begin
--%%   p^.Length := SizeOf(OBJECT_ATTRIBUTES);
--%%   p^.RootDirectory := r;
--%%   p^.Attributes := a;
--%%   p^.ObjectName := n;
--%%   p^.SecurityDescriptor := s;
--%%   p^.SecurityQualityOfService := nil;
--%% end;
--%%
--%% function ARGUMENT_PRESENT(ArgumentPointer: Pointer): BOOL;
--%% begin
--%%   Result := ArgumentPointer <> nil;
--%% end;
--%%
--%% function MAKEWORD(a, b: BYTE): WORD;
--%% begin
--%%   Result := (b shl 8) or a;
--%% end;
--%%
--%% function MAKELONG(a, b: WORD): DWORD;
--%% begin
--%%   Result := (b shl 16) or a;
--%% end;
--%%
--%% function LOWORD(L: DWORD): WORD;
--%% begin
--%%   Result := L and $0000FFFF;
--%% end;
--%%
--%% function HIWORD(L: DWORD): WORD;
--%% begin
--%%   Result := L shr 16;
--%% end;
--%%
--%% function LOBYTE(W: WORD): BYTE;
--%% begin
--%%   Result := W and $FF;
--%% end;
--%%
--%% function HIBYTE(W: WORD): BYTE;
--%% begin
--%%   Result := W shr 8;
--%% end;
--%%
--%% {$IFDEF JWA_INCLUDEMODE}  //prevents stackoverflow in GetProcedureAddress
--%% function JwaWinType_GetModuleHandle(lpModuleName: LPCSTR): HMODULE; stdcall; external kernel32 name 'GetModuleHandleA';
--%% function JwaWinType_LoadLibrary(lpLibFileName: LPCSTR): HMODULE; stdcall; external kernel32 name 'LoadLibraryA';
--%% function JwaWinType_GetProcAddress(hModule: HMODULE; lpProcName: LPCSTR): FARPROC; stdcall; external kernel32 name 'GetProcAddress';
--%% {$ELSE}
--%% function GetModuleHandle(lpModuleName: LPCSTR): HMODULE; stdcall; external kernel32 name 'GetModuleHandleA';
--%% function LoadLibrary(lpLibFileName: LPCSTR): HMODULE; stdcall; external kernel32 name 'LoadLibraryA';
--%% function GetProcAddress(hModule: HMODULE; lpProcName: LPCSTR): FARPROC; stdcall; external kernel32 name 'GetProcAddress';
--%% {$ENDIF JWA_INCLUDEMODE}
--%%
--%% const
--%%   RsELibraryNotFound = 'Library not found: %0:s';
--%%   RsEFunctionNotFound = 'Function not found: %0:s.%1:s';
--%%   RsEFunctionNotFound2 = 'Function not found: %0:s.%1:d';
--%%
--%% procedure GetProcedureAddress(var P: Pointer; const ModuleName, ProcName: AnsiString);
--%% var
--%%   ModuleHandle: HMODULE;
--%% begin
--%%   if not Assigned(P) then
--%%   begin
--%%     ModuleHandle := {$IFDEF JWA_INCLUDEMODE}jwaWinType_GetModuleHandle
--%%                     {$ELSE}GetModuleHandleA
--%%                     {$ENDIF JWA_INCLUDEMODE}
--%%                     (PAnsiChar(AnsiString(ModuleName)));
--%%     if ModuleHandle = 0 then
--%%     begin
--%%       ModuleHandle := {$IFDEF JWA_INCLUDEMODE}jwaWinType_LoadLibrary
--%%                     {$ELSE}LoadLibraryA
--%%                     {$ENDIF JWA_INCLUDEMODE}(PAnsiChar(ModuleName));
--%%       if ModuleHandle = 0 then
--%%         raise EJwaLoadLibraryError.CreateFmt(RsELibraryNotFound, [ModuleName]);
--%%     end;
--%%     P := Pointer({$IFDEF JWA_INCLUDEMODE}jwaWinType_GetProcAddress
--%%                     {$ELSE}GetProcAddress
--%%                     {$ENDIF JWA_INCLUDEMODE}(ModuleHandle, PAnsiChar(ProcName)));
--%%     if not Assigned(P) then
--%%       raise EJwaGetProcAddressError.CreateFmt(RsEFunctionNotFound, [ModuleName, ProcName]);
--%%   end;
--%% end;
--%%
--%% procedure GetProcedureAddress(var P: Pointer; const ModuleName : AnsiString; ProcNumber : DWORD);
--%% var
--%%   ModuleHandle: HMODULE;
--%% begin
--%%   if not Assigned(P) then
--%%   begin
--%%     ModuleHandle := {$IFDEF JWA_INCLUDEMODE}jwaWinType_GetModuleHandle
--%%                     {$ELSE}GetModuleHandleA
--%%                     {$ENDIF JWA_INCLUDEMODE}
--%%                     (PAnsiChar(AnsiString(ModuleName)));
--%%     if ModuleHandle = 0 then
--%%     begin
--%%       ModuleHandle := {$IFDEF JWA_INCLUDEMODE}jwaWinType_LoadLibrary
--%%                     {$ELSE}LoadLibraryA
--%%                     {$ENDIF JWA_INCLUDEMODE}(PAnsiChar(ModuleName));
--%%       if ModuleHandle = 0 then
--%%         raise EJwaLoadLibraryError.CreateFmt(RsELibraryNotFound, [ModuleName]);
--%%     end;
--%%     P := Pointer({$IFDEF JWA_INCLUDEMODE}jwaWinType_GetProcAddress
--%%                     {$ELSE}GetProcAddress
--%%                     {$ENDIF JWA_INCLUDEMODE}(ModuleHandle, PAnsiChar(ProcNumber)));
--%%     if not Assigned(P) then
--%%       raise EJwaGetProcAddressError.CreateFmt(RsEFunctionNotFound2, [ModuleName, ProcNumber]);
--%%   end;
--%% end;
--%%
--%% {$ENDIF JWA_INTERFACESECTION}
--%%
--%%
--%% {$IFNDEF JWA_OMIT_SECTIONS}
--%% end.
--%% {$ENDIF JWA_OMIT_SECTIONS}
--%%
--%%
--%%
--%%
--%%
--%%
--%%
--%%
