In a console application, how does it know if the console standard handle has been redirected (to a pipe or file) or not?

You can use GetStdHandle to get the standard handle, then use GetFileType to determine the type of the handle.

If the file type is not FILE_TYPE_CHAR, you know the console handle is redirected.