-
HANDLE type
Does anyone know how I can get the type of an arbitrary HANDLE, i.e. if it's a file, a thread, whatever?
If that's not possible, is there at least some reliable way to distinguish between console screen buffer handles and other handles that allow Read/WriteFile calls?
Basically, I'm trying to find out whether stdout is attached to a console or redirected to a file, so that I set the colour of the text if it's a console.
Under POSIX I'd call ttyname() to get the same effect.
-
MSCRT has _isatty(), which basically uses GetFileType().
I've also heard of folks calling GetConsoleMode() and "knowing something" if it fails - but I think GetFileType() is enough in this case.
gg
-
Maybe this Sysinternals link can be of some help. About halfway down the first page of the thread is a HandlesList.zip file written by Napalm which may meet your requirements.
-
The _isatty implementation in my CRT doesn't use GetFileType(), but I used it. Thanks a lot. I spent more than an hour on MSDN searching for this.
-
Yeah, mine didn't use it directly either - I tracked it down to _open_osfhandle() in osfinfo.c (old VS 6.0 CRT source)
gg