Home

GetStdHandleDWORD

GetStdHandleDWORD is not a standard Windows API function. The Windows API includes a function named GetStdHandle, which takes a DWORD parameter and returns a HANDLE. If you see GetStdHandleDWORD in code or documentation, it is usually a misnomer or a wrapper around GetStdHandle, or a user-defined alias. The correct invocation uses the constants STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, and STD_ERROR_HANDLE, defined as DWORD values (-10, -11, -12). These are used to obtain the standard input, output, or error handles associated with the current process.

The function declaration (in kernel32.dll) is: HANDLE GetStdHandle(DWORD nStdHandle). On success, it returns a valid handle

Usage of GetStdHandle involves retrieving a handle and performing I/O with Windows API functions such as ReadFile

Limitations and behavior notes: GetStdHandle does not create or attach consoles; it only returns existing handles.

to
the
requested
standard
device.
On
failure,
it
returns
INVALID_HANDLE_VALUE,
and
extended
error
information
can
be
obtained
with
GetLastError.
If
the
process
has
no
console,
GetStdHandle
may
return
NULL
for
STD_INPUT_HANDLE
or
STD_OUTPUT_HANDLE
or
STD_ERROR_HANDLE.
or
WriteFile,
or
other
APIs
that
operate
on
handles.
It
is
common
in
console
applications
to
read
from
standard
input
or
write
to
standard
output
and
error,
as
well
as
in
programs
that
redirect
I/O
to
files
or
pipes.
In
GUI
applications
or
services
without
a
console,
the
standard
handles
may
be
absent
or
redirected,
in
which
case
the
function
may
return
NULL
or
INVALID_HANDLE_VALUE
and
GetLastError
can
provide
details.