I am writing a Windows application which does some console manipulation. First, I call GetStdHandle(STD_INPUT/OUTPUT_HANDLE)
, then GetConsoleMode/SetConsoleMode
. However, if stdin/stdout are redirected, GetStdHandle
will succeed, but then GetConsoleMode
will return an 'invalid handle' error, presumably because it expects a console handle but I'm providing it with a file handle.
Currently I propagate such errors up, since I have no way of telling if such an error is 'real' (i.e., caused by some programming error or an internal error) or if they have been caused by this handle type mismatch.
Is there some way to tell what 'type' of handle I have? Alternatively, is there some way to tell that stdin/stdout have been redirected? If not, am I supposed to just ignore these particular errors?