comp.lang.ada
 help / color / mirror / Atom feed
* GDB Bug: Problem with ReadConsoleInput
@ 1999-08-04  0:00 Richard S. Kirkland
  0 siblings, 0 replies; only message in thread
From: Richard S. Kirkland @ 1999-08-04  0:00 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 5028 bytes --]

I am porting an old DOS Ada program to Win32 on NT.  I have a task which

handles input via ReadConsoleInput.  When the program runs outside GDB,
keys are processed via this task.  When I call ReadConsoleInput from
this task within GDB, I get error code 6 (ERROR_INVALID_HANDLE).  The
handle is the same as when running without GDB.  Any clues as to why GDB

would affect the reading of the console input?

Code Sample Follows:

task body Console_task is
   use Win32;
   use type Win32.Winnt.HANDLE;
   use type Interfaces.C.Unsigned_Long;
   function Scan_Code_To_Key_Stroke is new Unchecked_Conversion(
      Win32.BYTE, KEY_STROKE_CLASS.PRIMITIVE_TYPE );
   function To_Int is new Unchecked_Conversion(
      Win32.Winnt.HANDLE, Integer );

   hConsole_In : Win32.Winnt.HANDLE;
   In_Rec      : aliased Win32.Wincon.INPUT_RECORD;
   Num_Read    : aliased Win32.DWORD;
   Success     : Win32.BOOL := 0;
   KeyEv       : Win32.Wincon.KEY_EVENT_RECORD;
   KeyStroke   : KEY_STROKE_CLASS.PRIMITIVE_TYPE;

   ALT_KEY_PRESSED : Win32.DWORD := Win32.Wincon.RIGHT_ALT_PRESSED or
                                 Win32.Wincon.LEFT_ALT_PRESSED;

   CTRL_KEY_PRESSED : Win32.DWORD := Win32.Wincon.RIGHT_CTRL_PRESSED or
                                 Win32.Wincon.LEFT_CTRL_PRESSED;

   LSB :  Win32.BYTE;
   ErrorInt : Integer;
begin
    accept Start;
       HConsole_In := Win32.Winbase.GetStdHandle(
                         Win32.Winbase.STD_INPUT_HANDLE);
       if HConsole_In = Win32.Winbase.INVALID_HANDLE_VALUE
       then
          ErrorInt := Integer( Win32.Winbase.GetLastError );
          Debug_IO.Log( ErrorInt, "Console_Task called GetStdHandle");
       end if;

       loop
          Success := Win32.Wincon.ReadConsoleInput(
             hConsoleInput        => hConsole_In,
             lpBuffer             => In_Rec'Unchecked_Access,
             nLength              => 1,
             lpNumberOfEventsRead => Num_Read'Unchecked_Access );

          if Success = 0 then
             ErrorInt := Integer( Win32.Winbase.GetLastError );
             Key_Fail := Key_Fail + 1;
             if Key_Fail = 20 then
                -- Always get here when in GDB, never get here out of
GDB
                Debug_IO.Log("Key_Fail = 20", "Console_Task");
                Debug_IO.Log( ErrorInt, "Fail");
                Debug_IO.Log( To_Int( HConsole_In), "hConsole_In");

                -- Check to see if the Std Input has been changed by
GDB???
                HConsole_In := Win32.Winbase.GetStdHandle(
                         Win32.Winbase.STD_INPUT_HANDLE);
                Debug_IO.Log( To_Int( HConsole_In), "hConsole_In");
             end if;
          else
             Key_Count := Key_Count + 1;
             if Key_Count = 20 then
                -- Always get here without GDB, never get here in GDB
                Debug_IO.Log("Key_Count = 20", "Console_Task");
             end if;
             case In_Rec.EventType is
                when Win32.Wincon.KEY_EVENT =>

--     type KEY_EVENT_RECORD is                                --
wincon.h:41
--         record
--             bKeyDown         : Win32.BOOL;                  --
wincon.h:42
--             wRepeatCount     : Win32.WORD;                  --
wincon.h:43
--             wVirtualKeyCode  : Win32.WORD;                  --
wincon.h:44
--             wVirtualScanCode : Win32.WORD;                  --
wincon.h:45
--             uChar            : union_anonymous0_t;          --
wincon.h:49
--             dwControlKeyState: Win32.DWORD;                 --
wincon.h:50
--         end record;

                   KeyEv := In_Rec.Event.KeyEvent;

                   --
                   -- Set the "special" keys if the appropriate bit mask

                   -- of the Control Key State does not equal 0
                   --
                   SELF.ALT_PRESSED     := 0 /= (
                      KeyEv.dwControlKeyState and ALT_KEY_PRESSED );
                   SELF.CONTROL_PRESSED := 0 /= (
                      KeyEv.dwControlKeyState and CTRL_KEY_PRESSED );
                   SELF.EXTENDED_KEY    := 0 /= (
                      KeyEv.dwControlKeyState and Wincon.ENHANCED_KEY );

                   SELF.SHIFT_PRESSED   := 0 /= (
                      KeyEv.dwControlKeyState and Wincon.SHIFT_PRESSED
);

                   -- Process Keys on the Down Stroke
                   if KeyEv.bKeyDown = 1 then
                      -- set spinner to show interrupt being processed
                      MSG.Set_Spinner_Char(
                         SELF => SELF.SPINNER.all,
                         CHAR => 'U' );

                      LSB  := Win32.Utils.LOBYTE( KeyEv.WVirtualScanCode

);
                      KeyStroke := Scan_Code_To_Key_Stroke( LSB );

                      Process_Normal_Keystroke( KeyStroke );

                      MSG.Change_Spinner( SELF => SELF.SPINNER.all );

                   end if;
             when others => null;
             end case;
          end if;
       end loop;

end Console_Task;

[-- Attachment #2: Card for Richard S. Kirkland --]
[-- Type: text/x-vcard, Size: 297 bytes --]

begin:vcard 
n:Kirkland;Richard
x-mozilla-html:FALSE
org:Raytheon Systems Company
adr:;;2501 W. University, M/S 8052;McKinney;TX;75070;USA
version:2.1
email;internet:rkirklan@ieee.org
tel;fax:972-952-2600
tel;home:817-577-9575
tel;work:972-952-4921
x-mozilla-cpt:;0
fn:Kirkland, Richard
end:vcard

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-08-04  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-04  0:00 GDB Bug: Problem with ReadConsoleInput Richard S. Kirkland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox