GetStdHandle

  HANDLE GetStdHandle(fdwDevice)    
  DWORD fdwDevice; /* specifies input, output, or error device */

The GetStdHandle function returns a handle for the standard input, standard output, or standard error device.

Parameters

fdwDevice

Specifies the device to return the handle for. This parameter can have one of the following values:

Value Handle

STD_INPUT_HANDLE The standard input handle.
STD_OUTPUT_HANDLE The standard output handle.
STD_ERROR_HANDLE The standard error handle.

Return Value

The return value is a handle for the specified device if the function is successful. Otherwise, it is INVALID_HANDLE_VALUE. Use the GetLastError function to obtain extended error information.

Comments

Handles returned by GetStdHandle can be used by applications that wish to read from or write to the console. When a console is created, the Standard Input handle is a handle to the console's input buffer, and the Standard Output and Standard Error handles are handles to the console's active screen buffer. These handles can be used in ReadFile, WriteFile, or any of the console functions that access the console input buffer or a screen buffer (for example, ReadConsoleInput, WriteConsole, or GetConsoleScreenBufferInfo).

All handles returned by this function have GENERIC_READ | GENERIC_WRITE access unless SetStdHandle has been used to set a standard handle to be some handle with a lesser access.

The standard handles of a process may have been redirected by a call to SetStdHandle, in which case GetStdHandle will return the redirected handle. CreateFile(“CONIN$”, . . .) and CreateFile(“CONOUT$”, . . .) can be used to get handles to keyboard input and the screen display even if the standard handles have been redirected.

See Also

SetStdHandle