package Claw.Low_Level.Miscellaneous is
    --
    -- CLAW - Class Library for Ada and Windows.
    --
    -- This is the place where various commonly used low-level routines
    -- are collected.
    --
    -- This child package holds hard-to-categorize routines or bodies of
    -- routines too small to warrant a separate child.
    --
    -- It is a child of a private package, so it cannot be withed by user
    -- code.
    --
    --
    -- Copyright 1996, 1997  R.R. Software, Inc.
    -- P.O. Box 1512, Madison WI  53701
    -- All rights reserved.
    --

    use Claw.Win32;

	--DLL processing routines:
	--
    function Load_Library (LibFile:	in Lpcstr) return HInstance;
    pragma Import (StdCall, Load_Library, "LoadLibraryA");

    function Load_Library_Ex (LibFile:	in Lpcstr;
			      File:	in Uint := 0; -- Reserved.
			      Flags:	in DWord) return HInstance;
    pragma Import (StdCall, Load_Library_Ex, "LoadLibraryExA");

    function Free_Library (LibModule:  in HInstance) return Bool;
    pragma Import (StdCall, Free_Library, "FreeLibrary");

    function Get_Module_Handle (LibFile:  in Lpcstr) return HInstance;
    pragma Import (StdCall, Get_Module_Handle, "GetModuleHandleA");

    function Get_Proc_Address_Lpcstr (Module:	in HInstance;
			              Proc:	in Lpcstr)
				return Any_Subprogram_Access_Type;
    pragma Import (StdCall, Get_Proc_Address_Lpcstr, "GetProcAddress");

    function Get_Proc_Address_DWord (Module:	in HInstance;
				     Proc:	in DWord)
				return Any_Subprogram_Access_Type;
    pragma Import (StdCall, Get_Proc_Address_DWord, "GetProcAddress");

    function Get_Module_File_Name (Handle:	in HInstance;
				   Path_Str:	in Lpcstr;
				   Len:		in DWord) return DWord;
    pragma Import (StdCall, Get_Module_File_Name, "GetModuleFileNameA");


    -- Common dialog routines:

    function Comm_Dlg_Extended_Error return DWord;
    pragma Import (StdCall, Comm_Dlg_Extended_Error, "CommDlgExtendedError");

    -- Beep routines:

    type Beep_Kinds is new Claw.UInt;
    Standard_Beep : constant Beep_Kinds := 16#FFFF_FFFF#;
    OK_Sound : constant Beep_Kinds := 16#0#;
    Hand_Sound : constant Beep_Kinds := 16#10#;
    Question_Sound : constant Beep_Kinds := 16#20#;
    Exclamation_Sound : constant Beep_Kinds := 16#30#;
    Asterisk_Sound : constant Beep_Kinds := 16#40#;

    function Message_Beep (Kind : in Beep_Kinds) return Claw.Win32.Bool;
    pragma Import (StdCall, Message_Beep, "MessageBeep");

    function Beep(Hertz : in Claw.DWord; MS : in Claw.DWord) return Claw.Win32.Bool;
	-- Note: In Win95 the parameters are ignored and "Default Sound" is played
    pragma Import (StdCall, Beep, "Beep");

    -- Accelerator routines:

    function Load_Accelerators (Instance : in Claw.Win32.HInstance;
				Name : in Claw.Win32.LPCStr)
	return Claw.Win32.HAccel;
    pragma Import (StdCall, Load_Accelerators, "LoadAcceleratorsA");

    type CAccel is record
	Flags: Byte;
	Key  : Word;
	Cmd  : Word;
    end record;

    function Create_Accelerator_Table (Table : access CAccel; -- Really an array.
				       Count : Claw.Int)
	return Claw.Win32.HAccel;
    pragma Import (StdCall, Create_Accelerator_Table, "CreateAcceleratorTableA");

    function Destroy_Accelerator_Table (Accel : in Claw.Win32.HAccel)
	return Claw.Win32.Bool;
    pragma Import (StdCall, Destroy_Accelerator_Table, "DestroyAcceleratorTable");

    -- Directory management routines:
    -- (Note: Security not supported.)

    function Set_Current_Directory (Path_Name : in Claw.Win32.LpCStr) return Claw.Win32.Bool;
    pragma Import (StdCall, Set_Current_Directory, "SetCurrentDirectoryA");

    function Get_Current_Directory (Buffer_Len : in DWord;
				    Buffer     : in Claw.Win32.LpCStr) return Claw.DWord;
    pragma Import (StdCall, Get_Current_Directory, "GetCurrentDirectoryA");

    function Get_Windows_Directory (Buffer     : in Claw.Win32.LpCStr;
				    Buffer_Len : in DWord) return Claw.DWord;
    pragma Import (StdCall, Get_Windows_Directory, "GetWindowsDirectoryA");

    function Get_System_Directory (Buffer     : in Claw.Win32.LpCStr;
				   Buffer_Len : in DWord) return Claw.DWord;
    pragma Import (StdCall, Get_System_Directory, "GetSystemDirectoryA");

    function Create_Directory (Path_Name : in Claw.Win32.LpCStr;
			       Sec_Attrib: in Claw.DWord := 0) return Claw.Win32.Bool;
    pragma Import (StdCall, Create_Directory, "CreateDirectoryA");

    function Create_Directory_Ex (Template_Directory : in Claw.Win32.LpCStr;
			          New_Directory	     : in Claw.Win32.LpCStr;
			          Sec_Attrib	     : in Claw.DWord := 0) return Claw.Win32.Bool;
    pragma Import (StdCall, Create_Directory_Ex, "CreateDirectoryExA");

    function Remove_Directory (Path_Name : in Claw.Win32.LpCStr) return Claw.Win32.Bool;
    pragma Import (StdCall, Remove_Directory, "RemoveDirectoryA");

    function Get_Disk_Free_Space (Root_Path_Name	: in Claw.Win32.LpCStr;
				  Sectors_per_Cluster	: access DWord;
				  Bytes_per_Sectors	: access DWord;
				  Number_of_Free_Clusters : access DWord;
				  Total_Number_of_Clusters: access DWord) return Claw.Win32.Bool;
    pragma Import (StdCall, Get_Disk_Free_Space, "GetDiskFreeSpaceA");


    -- Error handling:
    function Set_Error_Mode (Mode : in UInt) return UInt;
    pragma Import (StdCall, Set_Error_Mode, "SetErrorMode");

    -- Global memory management.  (Needed mainly for a few interfaces).

    -- Global Memory Flags
    GMEM_FIXED		: constant UInt := 16#0000#;
    GMEM_MOVEABLE       : constant UInt := 16#0002#;
    GMEM_NOCOMPACT      : constant UInt := 16#0010#;
    GMEM_NODISCARD      : constant UInt := 16#0020#;
    GMEM_ZEROINIT       : constant UInt := 16#0040#;
    GMEM_MODIFY         : constant UInt := 16#0080#;
    GMEM_DISCARDABLE    : constant UInt := 16#0100#;
    GMEM_DDESHARE       : constant UInt := 16#2000#;
    GMEM_DISCARDED      : constant UInt := 16#4000#;
    GMEM_INVALID_HANDLE : constant UInt := 16#8000#;

    -- Global_Discard = Global_ReAlloc (Handle, 0, GMEM_MOVABLE);

    type Memory_Status_Type is record
	Length : DWord;
	Memory_Load : DWord; -- % Utilization.
	Total_Physical_Memory : DWord;
	Available_Physical_Memory : DWord;
	Total_Page_File : DWord;
	Available_Page_File : DWord;
	Total_Virtual : DWord; -- for this process.
	Available_Virtual : DWord;
    end record;

    type LPVoid is access all UInt; -- Placeholder for a void pointer.

    function Global_Alloc (Flags : in UInt;
			   Bytes : in DWord) return HGlobal;
    pragma Import (StdCall, Global_Alloc, "GlobalAlloc");

    function Global_Realloc (Handle: in HGlobal;
			     Flags : in UInt;
			     Bytes : in DWord) return HGlobal;
    pragma Import (StdCall, Global_Realloc, "GlobalReAlloc");

    procedure Global_Memory_Status (Data : access Memory_Status_Type);
    pragma Import (StdCall, Global_Memory_Status, "GlobalMemoryStatus");

    function Global_Size (Handle: in HGlobal) return DWord;
    pragma Import (StdCall, Global_Size, "GlobalSize");

    function Global_Flags (Handle: in HGlobal) return UInt;
    pragma Import (StdCall, Global_Flags, "GlobalFlags");

    function Global_Lock (Handle: in HGlobal) return LPVoid;
    pragma Import (StdCall, Global_Lock, "GlobalLock");

    function Global_Unlock (Handle: in HGlobal) return Claw.Win32.Bool;
    pragma Import (StdCall, Global_Unlock, "GlobalUnlock");

    function Global_Handle (Ptr: in LPVoid) return HGlobal;
    pragma Import (StdCall, Global_Handle, "GlobalHandle");

    function Global_Free (Handle: in HGlobal) return HGlobal;
    pragma Import (StdCall, Global_Free, "GlobalFree");

    -- Profile management:
    function Get_Profile_String (App_Name : in Lpcstr;
				 Key_Name : in Lpcstr;
				 Default  : in Lpcstr;
				 Result   : in Lpcstr; -- Really Lpstr.
				 Size     : in DWord) return DWord;
    pragma Import (StdCall, Get_Profile_String, "GetProfileStringA");

    function Write_Profile_String (App_Name : in Lpcstr;
				   Key_Name : in Lpcstr;
				   Value    : in Lpcstr) return DWord;
    pragma Import (StdCall, Write_Profile_String, "WriteProfileStringA");

    -- System parameters info:

    -- (Which version of the System_Parameters_Info_xxx routines to use
    -- are noted with the constants.  If not noted, no routine with the
    -- correct parameters is defined.).

    SPI_GETBEEP			: constant UInt :=  1; -- SPI_Get_Bool
    SPI_SETBEEP			: constant UInt :=  2; -- SPI_Set_Bool
    SPI_GETMOUSE		: constant UInt :=  3;
    SPI_SETMOUSE		: constant UInt :=  4;
    SPI_GETBORDER		: constant UInt :=  5; -- SPI_Get_Int
    SPI_SETBORDER		: constant UInt :=  6; -- SPI_Set_Int
    SPI_GETKEYBOARDSPEED	: constant UInt := 10; -- SPI_Get_Int
    SPI_SETKEYBOARDSPEED	: constant UInt := 11; -- SPI_Set_Int
    SPI_LANGDRIVER		: constant UInt := 12; -- (not supported)
    SPI_ICONHORIZONTALSPACING	: constant UInt := 13; -- SPI_Set_Int
    SPI_GETSCREENSAVETIMEOUT	: constant UInt := 14; -- SPI_Get_Int
    SPI_SETSCREENSAVETIMEOUT	: constant UInt := 15; -- SPI_Set_Int
    SPI_GETSCREENSAVEACTIVE     : constant UInt := 16; -- SPI_Get_Bool
    SPI_SETSCREENSAVEACTIVE	: constant UInt := 17; -- SPI_Set_Bool
    SPI_GETGRIDGRANULARITY	: constant UInt := 18; -- SPI_Get_Int
    SPI_SETGRIDGRANULARITY	: constant UInt := 19; -- SPI_Set_Int
    SPI_SETDESKWALLPAPER	: constant UInt := 20;
    SPI_SETDESKPATTERN		: constant UInt := 21; -- SPI_Set_Int (Value = 0).
    SPI_GETKEYBOARDDELAY	: constant UInt := 22; -- SPI_Get_Int
    SPI_SETKEYBOARDDELAY	: constant UInt := 23; -- SPI_Set_Int
    SPI_ICONVERTICALSPACING	: constant UInt := 24; -- SPI_Set_Int
    SPI_GETICONTITLEWRAP	: constant UInt := 25; -- SPI_Get_Bool
    SPI_SETICONTITLEWRAP	: constant UInt := 26; -- SPI_Set_Bool
    SPI_GETMENUDROPALIGNMENT	: constant UInt := 27; -- SPI_Get_Bool
    SPI_SETMENUDROPALIGNMENT	: constant UInt := 28; -- SPI_Set_Bool
    SPI_SETDOUBLECLKWIDTH	: constant UInt := 29; -- SPI_Set_Int
    SPI_SETDOUBLECLKHEIGHT	: constant UInt := 30; -- SPI_Set_Int
    SPI_GETICONTITLELOGFONT	: constant UInt := 31; -- SPI_Ptr
    SPI_SETDOUBLECLICKTIME	: constant UInt := 32; -- SPI_Set_Int
    SPI_SETMOUSEBUTTONSWAP	: constant UInt := 33; -- SPI_Set_Bool
    SPI_SETICONTITLELOGFONT	: constant UInt := 34; -- SPI_Ptr
    SPI_GETFASTTASKSWITCH	: constant UInt := 35; -- SPI_Get_Bool (Obsolete)
    SPI_SETFASTTASKSWITCH	: constant UInt := 36; -- SPI_Set_Bool (Obsolete)

    SPI_GETFILTERKEYS		: constant UInt := 50;
    SPI_SETFILTERKEYS		: constant UInt := 51;
    SPI_GETTOGGLEKEYS		: constant UInt := 52;
    SPI_SETTOGGLEKEYS		: constant UInt := 53;
    SPI_GETMOUSEKEYS		: constant UInt := 54;
    SPI_SETMOUSEKEYS		: constant UInt := 55;
    SPI_GETSHOWSOUNDS		: constant UInt := 56; -- SPI_Get_Bool (use GetSystemMetrics instead)
    SPI_SETSHOWSOUNDS		: constant UInt := 57; -- SPI_Set_Bool
    SPI_GETSTICKYKEYS		: constant UInt := 58;
    SPI_SETSTICKYKEYS		: constant UInt := 59;
    SPI_GETACCESSTIMEOUT	: constant UInt := 60;
    SPI_SETACCESSTIMEOUT	: constant UInt := 61;
    SPI_GETSOUNDSENTRY		: constant UInt := 64;
    SPI_SETSOUNDSENTRY		: constant UInt := 65;

    -- All of the values below here are supported on Windows 4.x only.
    SPI_SETDRAGFULLWINDOWS	: constant UInt := 37; -- SPI_Get_Bool
    SPI_GETDRAGFULLWINDOWS	: constant UInt := 38; -- SPI_Set_Bool
    SPI_GETNONCLIENTMETRICS	: constant UInt := 41; -- SPI_Ptr
    SPI_SETNONCLIENTMETRICS	: constant UInt := 42; -- SPI_Ptr
    SPI_GETMINIMIZEDMETRICS	: constant UInt := 43;
    SPI_SETMINIMIZEDMETRICS	: constant UInt := 44;
    SPI_GETICONMETRICS		: constant UInt := 45;
    SPI_SETICONMETRICS		: constant UInt := 46;
    SPI_SETWORKAREA		: constant UInt := 47; -- SPI_Rect
    SPI_GETWORKAREA		: constant UInt := 48; -- SPI_Rect
    SPI_SETPENWINDOWS		: constant UInt := 49; -- SPI_Bool
    SPI_GETSERIALKEYS		: constant UInt := 62;
    SPI_SETSERIALKEYS		: constant UInt := 63;
    SPI_GETHIGHCONTRAST		: constant UInt := 66;
    SPI_SETHIGHCONTRAST		: constant UInt := 67;
    SPI_GETKEYBOARDPREF		: constant UInt := 68; -- SPI_Get_Bool
    SPI_SETKEYBOARDPREF		: constant UInt := 69; -- SPI_Set_Bool
    SPI_GETSCREENREADER		: constant UInt := 70; -- SPI_Get_Bool
    SPI_SETSCREENREADER		: constant UInt := 71; -- SPI_Set_Bool
    SPI_GETANIMATION		: constant UInt := 72;
    SPI_SETANIMATION		: constant UInt := 73;
    SPI_GETFONTSMOOTHING	: constant UInt := 74; -- SPI_Get_Bool
    SPI_SETFONTSMOOTHING	: constant UInt := 75; -- SPI_Set_Bool
    SPI_SETDRAGWIDTH		: constant UInt := 76; -- SPI_Set_Int
    SPI_SETDRAGHEIGHT		: constant UInt := 77; -- SPI_Set_Int
    SPI_SETHANDHELD		: constant UInt := 78; -- (Used internally)
    SPI_GETLOWPOWERTIMEOUT	: constant UInt := 79; -- SPI_Get_Int (not supported)
    SPI_GETPOWEROFFTIMEOUT	: constant UInt := 80; -- SPI_Get_Int (not supported)
    SPI_SETLOWPOWERTIMEOUT	: constant UInt := 81; -- SPI_Set_Int
    SPI_SETPOWEROFFTIMEOUT	: constant UInt := 82; -- SPI_Set_Int
    SPI_GETLOWPOWERACTIVE	: constant UInt := 83; -- SPI_Get_Bool (not supported)
    SPI_GETPOWEROFFACTIVE	: constant UInt := 84; -- SPI_Get_Bool (not supported)
    SPI_SETLOWPOWERACTIVE	: constant UInt := 85; -- SPI_Set_Bool
    SPI_SETPOWEROFFACTIVE	: constant UInt := 86; -- SPI_Set_Bool
    SPI_SETCURSORS		: constant UInt := 87;
    SPI_SETICONS		: constant UInt := 88;
    SPI_GETDEFAULTINPUTLANG	: constant UInt := 89;
    SPI_SETDEFAULTINPUTLANG	: constant UInt := 90;
    SPI_SETLANGTOGGLE		: constant UInt := 91; -- SPI_Set_Int (Value = 0)
    SPI_GETWINDOWSEXTENSION	: constant UInt := 92; -- SPI_Set_Int (Value = 1), function result.
    SPI_SETMOUSETRAILS		: constant UInt := 93; -- SPI_Int
    SPI_GETMOUSETRAILS		: constant UInt := 94; -- SPI_Int
    SPI_SCREENSAVERRUNNING	: constant UInt := 97; -- (Internal use only)

    -- Values for Winini (Sets only).
    SPIF_NONE		: constant UInt := 0;
    SPIF_UPDATEINIFILE  : constant UInt := 1;
    SPIF_SENDWININICHANGE:constant UInt := 2;
    SPIF_UPDATEANDSENDINI:constant UInt := 3;

    function System_Parameters_Info_Rect (Command : in UInt;
					  Unused  : in UInt := 0;
					  Rect    : access Rectangle_Type;
					  Winini  : in UInt := SPIF_NONE) return Claw.Win32.Bool;
    pragma Import (StdCall, System_Parameters_Info_Rect, "SystemParametersInfoA");

    function System_Parameters_Info_Get_Bool (Command : in UInt;
					      Unused  : in UInt := 0;
					      Result  : access Win32.Bool;
					      Winini  : in UInt := SPIF_NONE) return Claw.Win32.Bool;
    pragma Import (StdCall, System_Parameters_Info_Get_Bool, "SystemParametersInfoA");

    function System_Parameters_Info_Set_Bool (Command : in UInt;
					      Value   : in Win32.Bool;
					      Unused  : in UInt := 0;
					      Winini  : in UInt := SPIF_NONE) return Claw.Win32.Bool;
    pragma Import (StdCall, System_Parameters_Info_Set_Bool, "SystemParametersInfoA");

    function System_Parameters_Info_Get_Int (Command : in UInt;
					     Unused  : in UInt := 0;
					     Result  : access Int;
					     Winini  : in UInt := SPIF_NONE) return Claw.Win32.Bool;
    pragma Import (StdCall, System_Parameters_Info_Get_Int, "SystemParametersInfoA");

    function System_Parameters_Info_Set_Int (Command : in UInt;
					     Value   : in Int;
					     Unused  : in UInt := 0;
					     Winini  : in UInt := SPIF_NONE) return Claw.Win32.Bool;
    pragma Import (StdCall, System_Parameters_Info_Set_Int, "SystemParametersInfoA");

    function System_Parameters_Info_Get_UInt (Command : in UInt;
					      Unused  : in UInt := 0;
					      Result  : access UInt;
					      Winini  : in UInt := SPIF_NONE) return Claw.Win32.Bool;
    pragma Import (StdCall, System_Parameters_Info_Get_UInt, "SystemParametersInfoA");

    function System_Parameters_Info_Set_UInt (Command : in UInt;
					      Value   : in UInt;
					      Unused  : in UInt := 0;
					      Winini  : in UInt := SPIF_NONE) return Claw.Win32.Bool;
    pragma Import (StdCall, System_Parameters_Info_Set_UInt, "SystemParametersInfoA");

    function System_Parameters_Info_Ptr (Command : in UInt;
					 Unused  : in UInt := 0;
					 Result  : in LPVoid;
					 Winini  : in UInt := SPIF_NONE) return Claw.Win32.Bool;
    pragma Import (StdCall, System_Parameters_Info_Ptr, "SystemParametersInfoA");

    -- Probably will need others here.

end Claw.Low_Level.Miscellaneous;