Using WINAPI ReadConsole

Posted by Jim Fell on Stack Overflow See other posts from Stack Overflow or by Jim Fell
Published on 2010-05-04T15:21:56Z Indexed on 2010/05/04 16:28 UTC
Read the original article Hit count: 250

I am trying to use the WINAPI ReadConsole() to wait for any keypress at the end of my Win32 console application.

CONSOLE_READCONSOLE_CONTROL tControl;
char pStr[65536];
DWORD dwBufLen = 1;
DWORD dwCtl;

tControl_c.nLength = sizeof( CONSOLE_READCONSOLE_CONTROL );
tControl_c.nInitialChars = 0;
tControl_c.dwControlKeyState = 0;
tControl_c.dwCtrlWakeupMask = NULL;

pBuf[0] = 0x00;

do
{
   ReadConsole( hConsole_c, pStr, (*pBufLen) * sizeof(TCHAR), pBufLen, &tControl );
}
while ( pStr[0] == 0x00 );

The code executes without throwing an exception. However, when the ReadConsole() function executes the error code ERROR_INVALID_HANDLE (0x06) is flagged. I have verified hConsole_c to be a valid handle. Does anyone have any insight as to what I am doing wrongly? I am using Visual C++ 2008 Express Edition. Thanks.

© Stack Overflow or respective owner

Related posts about c++

Related posts about winapi