From: william e. <MrU...@po...> - 2007-11-19 04:26:08
|
Hi Group, I'm having another problem with some code. I am trying to make my code wait for console input ( block until something is entered ). The Get and Set ConsoleMode calls are failing. The WaitForSingleObject is not waiting, either is the ReadConsoleInput. What an I missing? Thanks for your time. -- William Estrada MrU...@po... Mt-Umunhum-Wireless.net ( http://Mt-Umunhum-Wireless.net ) Ymessenger: MrUmunhum /* Copyright(C) by William Estrada Sep 2007, All rights reserved * * Mr_Umunhum@Mt-Umunhum-Wireless.net * * * * Permission to use, copy, modify, and distribute this software * * is freely granted, provided that this notice and Greeting are * * preserved. */ #include <stdio.h> #include <tchar.h> #include <fcntl.h> #include <windows.h> #include <winbase.h> #include <wininet.h> #include <mmsystem.h> #define ERR_MSG(F,M) { \ fprintf( stderr, "## %s %s:%d ", argv[0],__FILE__,__LINE__); \ fprintf( stderr, F, M ); } /* ------------------------------------------------------------ */ int main( int argc, char **argv ) { //Greeting(); DWORD Read; DWORD Result; DWORD Buf_Size = 256; DWORD Old_Mode, New_Mode; HANDLE Console; INPUT_RECORD Con_Buf[Buf_Size]; int C = 1; Console = GetStdHandle( STD_INPUT_HANDLE ); if( Console == INVALID_HANDLE_VALUE ) { ERR_MSG( " GetStdHandle failed: %d\n", Console ); } else { ERR_MSG( " Console Handle: %d\n", Console ); } Result = GetConsoleMode( Console, &Old_Mode ); if(! Result ) { ERR_MSG( " GetConsoleMode failed: %d\n", Result ); } New_Mode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT | ENABLE_LINE_INPUT; Result = SetConsoleMode( Console, New_Mode ); if(! Result ) { ERR_MSG( " SetConsoleMode failed: %d\n", Result ); } ERR_MSG( " Console read%s","\n" ); while(1) { WaitForSingleObject( Console, INFINITE ); Result = ReadConsoleInput( Console, Con_Buf, Buf_Size, &Read ); if( Result == 0 ) { ERR_MSG( " Console Read Failed: Result = %d\n", Result ); } else { ERR_MSG( " Buffer: '%s'\n", Con_Buf ); } if( C++ > 2 ) break; } return; } /* ------------------------------------------------------------ */ |