Von Stackoverflow:
Delphi-Quellcode:
function IAmAConsoleApp: Boolean;
var
Stdout: THandle;
begin
Stdout := GetStdHandle(Std_Output_Handle);
Win32Check(Stdout <> Invalid_Handle_Value);
Result := Stdout <> 0;
end;
Zitat:
Call GetStdHandle(Std_Output_Handle). If it succeeds and returns zero, then there is no console to write to. Other return values indicate that a console is attached to the process, so you can write to it (although the console may not be the most desirable place to log messages in a console program since they'll interfere with the normal output).