Using WINAPI ReadConsole
I am trying to use WINAPI ReadConsole()
to wait for any key press at the end of a 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 runs without exception. However, when the function ReadConsole()
executes the error code ERROR_INVALID_HANDLE
(0x06) is flagged. I have checked hConsole_c
as a valid handle. Does anyone have any idea what I am doing wrong? I am using Visual C ++ 2008 Express Edition. Thanks.
+2
a source to share
3 answers