ReadConsole() / ReadConsoleInput()

This is a discussion on ReadConsole() / ReadConsoleInput() within the Windows Programming forums, part of the Platform Specific Boards category; I'm writing a console class. I have used WriteConsole() successfully for Print() function in my class and am trying to ...

  1. #1
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856

    ReadConsole() / ReadConsoleInput()

    I'm writing a console class. I have used WriteConsole() successfully for Print() function in my class and am trying to implement a Read() function using ReadConsole() or ReadConsoleInput(), but I just can't get it to work.

    I want it to be a function that will block further processing until the user provides input and hits enter. Every time I call ReadConsole() it just returns without offering an opportunity for the user to enter data. I tried using while loops to sit and keep trying, but then it doesn't allow any key input...

    Any help is greatly appreciated (ie, an example successfully using ReadConsole()). Thanks.

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Here's a code snippet of how I'm currently trying to get this job done:
    Code:
    DWORD saveMode;
    GetConsoleMode(_scr, &saveMode);
    SetConsoleMode(_scr, 0);
    
    if (WaitForSingleObject(_scr, INFINITE) == WAIT_OBJECT_0) {
      DWORD num;
      ReadConsole(_scr, buf, size, &num, NULL);
    }
    
    SetConsoleMode(_scr, saveMode);
    WaitForSingleObject() is returning WAIT_FAILED and GetLastError() returns zero! WTF?

    Again, I'd really appeciate your shedding the light on what I need to do to accomplish this. Also, if you notice something wrong with this snippet (for example, maybe using the wrong mode for SetConsoleMode()), let me know homie.

    Thanks again.

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Ok. One more update.

    Instead of trying to wait and read with my class's console HANDLE which wasn't working, I switched it with the standard input handle (using GetStdHandle(STD_INPUT_HANDLE)) and it worked fine...

    So I guess you can't read input using a different console handle. Right?
    Last edited by LuckY; 02-10-2003 at 11:58 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ReadConsoleInput behaves bad.
    By antex in forum Windows Programming
    Replies: 2
    Last Post: 10-25-2005, 12:02 PM
  2. help with ReadConsoleInput()
    By Verbenaca in forum Windows Programming
    Replies: 6
    Last Post: 06-09-2005, 04:24 PM
  3. help with ReadConsoleInput please
    By Verbenaca in forum Windows Programming
    Replies: 1
    Last Post: 05-21-2005, 07:19 AM
  4. ReadConsoleInput Reading Multiple Records
    By manofsteel972 in forum Windows Programming
    Replies: 1
    Last Post: 10-26-2004, 10:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21