Home

STDOUTPUTHANDLE

STDOUTPUTHANDLE, typically referred to in Windows documentation as STD_OUTPUT_HANDLE, is a Windows API constant used to obtain the process’s standard output handle. It is defined as a DWORD value equal to -11 and is supplied to the GetStdHandle function to request the corresponding device handle for standard output.

The primary use is GetStdHandle(STD_OUTPUT_HANDLE), which returns a HANDLE to the standard output device. In a

If the process is not attached to a console, GetStdHandle may return NULL, and the caller should

Related constants include STD_INPUT_HANDLE and STD_ERROR_HANDLE, which request the standard input and standard error handles, respectively.

console
application,
this
handle
usually
represents
the
console
screen
buffer.
If
the
process’s
standard
output
has
been
redirected
to
another
destination,
such
as
a
file
or
a
pipe,
the
returned
handle
refers
to
that
destination
instead.
The
HANDLE
can
then
be
used
with
low-level
I/O
functions
such
as
WriteFile,
or
with
other
Windows
APIs
that
operate
on
file
handles.
check
for
success.
In
such
cases,
GetLastError
can
indicate
the
reason,
typically
ERROR_INVALID_HANDLE.
The
constant
is
a
low-level
alternative
to
the
standard
C
library
stdout;
while
the
CRT
may
coordinate
with
the
Windows
console,
STD_OUTPUT_HANDLE
is
part
of
the
Win32
API
and
is
used
for
direct
handle-based
I/O.
STD_OUTPUT_HANDLE
is
commonly
used
in
console
and
system-level
programming
to
perform
direct,
unbuffered
or
file-descriptor-style
output
operations.