WriteConsole

  BOOL WriteConsole(hConsoleOutput, lpvBuffer, cchToWrite, lpcchWritten, lpvReserved)    
  HANDLE hConsoleOutput; /* identifies console screen buffer */
  CONST VOID *lpvBuffer; /* points to buffer to write from */
  DWORD cchToWrite; /* number of characters to write */
  LPDWORD lpcchWritten; /* number of characters written */
  LPVOID lpvReserved; /* reserved */

The WriteConsole function writes a character string to a console screen buffer beginning at the current cursor location.

Parameters

hConsoleOutput

Identifies the console screen buffer to write to. The handle must have been created with GENERIC_WRITE access.

lpvBuffer

Points to a buffer to containing characters to be written to the screen buffer.

cchToWrite

Specifies the number of characters to write.

lpcchWritten

Points to a variable that will be set to the number of characters actually written.

lpvReserved

Reserved for future use.

Return Value

The return value is TRUE if the function was successful, or FALSE if an error occurred. Use the GetLastError function to obtain extended error information.

Comments

WriteConsole writes characters to a console screen buffer. It behaves like WriteFile writing to a screen buffer except that it can be used to read in either wide-character or ANSI mode. Applications that want to be compatible with both modes should use WriteConsole rather than WriteFile.

Characters are written to the screen buffer at the current cursor position. The cursor position advances as characters are written. Use SetConsoleCursorPosition to set the current cursor position.

Characters are written using the foreground and background color attributes associated with this screen buffer. Use SetConsoleTextAttribute to change these colors.

Use GetConsoleScreenBufferInfo to determine the current color attributes and the current cursor position.

All of the input modes that affect the behavior of WriteFile have the same effect on WriteConsole.

The WriteConsole function may be used as either a wide-character function (where the characters to be written must be Unicode) or an ANSI function (where the characters to be written must be from the Windows 3.x character set installed).

See Also

ReadConsole, WriteConsoleOutput, WriteConsoleOutputCharacter, SetConsoleTextAttribute, GetConsoleMode, SetConsoleMode