Author: Odd Gunnar Malin
Date: 01:39:46 09/25/04
Go up one level in this thread
On September 25, 2004 at 01:06:33, Andrey Popov wrote: >The best way is to use PeekNamedPipe and ReadFile functions from the "windows" >unit. >You can ask whether some input is available (through PeekNamedPipe). >If there are some characters or PeekNamedPipe returned "false" >then ReadFile. Since he have the input in its own thread he do not need to peek the input first. Here is my routine for exactly this task in C++. It is for use in many programs but for reading gui message it set: it->hRead=GetStdHandle(STD_INPUT_HANDLE); void InputThread::threadLoop(void* lpv) { char c; InputThread* it=(InputThread*)lpv; string line=""; DWORD dwRead; DWORD dwError; it->abortcode=0; while (!it->abort) { if (it->hRead==NULL) break; if (!ReadFile(it->hRead, &c, 1, &dwRead, NULL)) { dwError=GetLastError(); if ((dwError==ERROR_BROKEN_PIPE) || (dwError==ERROR_HANDLE_EOF)) // if (dwError==ERROR_HANDLE_EOF) { it->abortcode=dwError; break; } } if (dwRead) { if (c=='\n') { if (it->callbackFunc!=NULL) { if (!it->callbackFunc(line.c_str(),it->callbackData)) { it->abortcode=-1; break; } } line=""; }else if (c!='\r') { line+=c; } } }; _endthread(); } it->abortcode is just to give some info in the logfile. Odd Gunnar
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.