Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9293599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:10:39+00:00 2026-06-18T21:10:39+00:00

If I get a handle to stdin from a console app like so: HANDLE

  • 0

If I get a handle to stdin from a console app like so:

HANDLE hStdIn = ::GetStdHandle(STD_INPUT_HANDLE);

I can then read data from it:

BYTE buff[32];
DWORD dwcbRead = 0;
BOOL bReadRes = ::ReadFile(hStdIn, buff, SIZEOF(buff), &dwcbRead, NULL);

My question is, how do I know how many bytes are available before I read them?

PS. ReadFile seems to block if there’s no data available to read.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T21:10:40+00:00Added an answer on June 18, 2026 at 9:10 pm

    Use ReadConsoleInput to read raw input events and PeekConsoleInput to examine them without removing from the input queue. There is a bunch of caveats here:

    1. Your standard input might be redirected, then you’ll have to determine its type and act accordingly. If it’s a file, it won’t block and you just go ahead and read. If it’s a pipe, PeekNamedPipe provides some help.

    2. There is no one-to-one correspondence between input events and characters.

    3. If ENABLE_LINE_MODE is set on the console, ReadFile/ReadConsole would block if there is no newline yet entered; additionally, line editing facilities are unavailable before you actually call ReadConsole, and when you call ReadConsole, it will block.

    I would recommend doing ReadFile or ReadConsole (or trying the latter with fallback to the former) in a separate thread. Your main thread may do something useful and eventually check (or wait for) readyness of the reading thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I get a handle on my user control in JavaScript? <body> <form
How can we get and handle the sftp return codes in a C program
I am trying to get the handle of a window from a process. Now,
In Watir you can get WIN32OLE handle of IE window using next method. irb(main):059:0>
I need to suck data from stdin and create a object. The incoming data
I could get the handle to the google text doc i needed. I am
I'm trying to get a handle on whether we have a problem in our
I am trying to get a handle on Solrnet and interacting an ASP.NET site
I'm trying to get a handle to the foreground window in C#/Net 2.0/WinForms by
I have been trying to get a handle on using MVC 4.0 with EF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.