Is there any way to read from and write to the console asynchronously, using APC completion routines, without creating new threads? Like it is possible with named pipes.
The problem is that in case of console, FILE_FLAG_OVERLAPPED
is ignored by CreateFile
function.
Edit. This is to clarify, what I'm trying to do.
Windows provides functions ReadFileEx
and WriteFileEx
for working with Asynchronous Procedure Calls. Documentaion to these function says about parameter hFile
:
This parameter can be any handle opened with the FILE_FLAG_OVERLAPPED flag by the CreateFile function<...>
Then, documentation to CreateFile
says that if pass CONIN$
or CONOUT&
to them, than FILE_FLAG_OVERLAPPED
is ignored.
And indeed, when I try following sequence:
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
if(!WriteFileEx(h, ...)) {
auto errorCode = GetLastError(); //I get 6 here
}
...I get error code 6 - ERROR_INVALID_HANDLE
. If use named pipe instead of console handles, all works perfectly.
So my question is whether there is some way to make ReadFileEx
and WriteFileEx
to work with console handles.