2 * Win32 console functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 * Copyright 1997 Karl Garrison
6 * Copyright 1998 John Richardson
7 * Copyright 1998 Marcus Meissner
8 * Copyright 2001,2002,2004,2005 Eric Pouech
9 * Copyright 2001 Alexandre Julliard
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 /* Reference applications:
27 * - IDA (interactive disassembler) full version 3.75. Works.
28 * - LYNX/W32. Works mostly, some keys crash it.
32 #include "wine/port.h"
47 #include "wine/winbase16.h"
48 #include "wine/server.h"
49 #include "wine/exception.h"
50 #include "wine/unicode.h"
51 #include "wine/debug.h"
53 #include "console_private.h"
54 #include "kernel_private.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(console);
58 static const WCHAR coninW[] = {'C','O','N','I','N','$',0};
59 static const WCHAR conoutW[] = {'C','O','N','O','U','T','$',0};
61 /* map input records to ASCII */
62 static void input_records_WtoA( INPUT_RECORD *buffer, int count )
67 for (i = 0; i < count; i++)
69 if (buffer[i].EventType != KEY_EVENT) continue;
70 WideCharToMultiByte( GetConsoleCP(), 0,
71 &buffer[i].Event.KeyEvent.uChar.UnicodeChar, 1, &ch, 1, NULL, NULL );
72 buffer[i].Event.KeyEvent.uChar.AsciiChar = ch;
76 /* map input records to Unicode */
77 static void input_records_AtoW( INPUT_RECORD *buffer, int count )
82 for (i = 0; i < count; i++)
84 if (buffer[i].EventType != KEY_EVENT) continue;
85 MultiByteToWideChar( GetConsoleCP(), 0,
86 &buffer[i].Event.KeyEvent.uChar.AsciiChar, 1, &ch, 1 );
87 buffer[i].Event.KeyEvent.uChar.UnicodeChar = ch;
91 /* map char infos to ASCII */
92 static void char_info_WtoA( CHAR_INFO *buffer, int count )
98 WideCharToMultiByte( GetConsoleOutputCP(), 0, &buffer->Char.UnicodeChar, 1,
100 buffer->Char.AsciiChar = ch;
105 /* map char infos to Unicode */
106 static void char_info_AtoW( CHAR_INFO *buffer, int count )
112 MultiByteToWideChar( GetConsoleOutputCP(), 0, &buffer->Char.AsciiChar, 1, &ch, 1 );
113 buffer->Char.UnicodeChar = ch;
119 /******************************************************************************
120 * GetConsoleWindow [KERNEL32.@] Get hwnd of the console window.
123 * Success: hwnd of the console window.
126 HWND WINAPI GetConsoleWindow(VOID)
130 SERVER_START_REQ(get_console_input_info)
133 if (!wine_server_call_err(req)) hWnd = reply->win;
141 /******************************************************************************
142 * GetConsoleCP [KERNEL32.@] Returns the OEM code page for the console
147 UINT WINAPI GetConsoleCP(VOID)
150 UINT codepage = GetOEMCP(); /* default value */
152 SERVER_START_REQ(get_console_input_info)
155 ret = !wine_server_call_err(req);
156 if (ret && reply->input_cp)
157 codepage = reply->input_cp;
165 /******************************************************************************
166 * SetConsoleCP [KERNEL32.@]
168 BOOL WINAPI SetConsoleCP(UINT cp)
172 if (!IsValidCodePage(cp))
174 SetLastError(ERROR_INVALID_PARAMETER);
178 SERVER_START_REQ(set_console_input_info)
181 req->mask = SET_CONSOLE_INPUT_INFO_INPUT_CODEPAGE;
183 ret = !wine_server_call_err(req);
191 /***********************************************************************
192 * GetConsoleOutputCP (KERNEL32.@)
194 UINT WINAPI GetConsoleOutputCP(VOID)
197 UINT codepage = GetOEMCP(); /* default value */
199 SERVER_START_REQ(get_console_input_info)
202 ret = !wine_server_call_err(req);
203 if (ret && reply->output_cp)
204 codepage = reply->output_cp;
212 /******************************************************************************
213 * SetConsoleOutputCP [KERNEL32.@] Set the output codepage used by the console
216 * cp [I] code page to set
222 BOOL WINAPI SetConsoleOutputCP(UINT cp)
226 if (!IsValidCodePage(cp))
228 SetLastError(ERROR_INVALID_PARAMETER);
232 SERVER_START_REQ(set_console_input_info)
235 req->mask = SET_CONSOLE_INPUT_INFO_OUTPUT_CODEPAGE;
237 ret = !wine_server_call_err(req);
245 /***********************************************************************
248 BOOL WINAPI Beep( DWORD dwFreq, DWORD dwDur )
250 static const char beep = '\a';
251 /* dwFreq and dwDur are ignored by Win95 */
252 if (isatty(2)) write( 2, &beep, 1 );
257 /******************************************************************
258 * OpenConsoleW (KERNEL32.@)
261 * Open a handle to the current process console.
262 * Returns INVALID_HANDLE_VALUE on failure.
264 HANDLE WINAPI OpenConsoleW(LPCWSTR name, DWORD access, BOOL inherit, DWORD creation)
269 if (strcmpiW(coninW, name) == 0)
270 output = (HANDLE) FALSE;
271 else if (strcmpiW(conoutW, name) == 0)
272 output = (HANDLE) TRUE;
275 SetLastError(ERROR_INVALID_NAME);
276 return INVALID_HANDLE_VALUE;
278 if (creation != OPEN_EXISTING)
280 SetLastError(ERROR_INVALID_PARAMETER);
281 return INVALID_HANDLE_VALUE;
284 SERVER_START_REQ( open_console )
287 req->access = access;
288 req->attributes = inherit ? OBJ_INHERIT : 0;
289 req->share = FILE_SHARE_READ | FILE_SHARE_WRITE;
291 wine_server_call_err( req );
296 ret = console_handle_map(ret);
299 /* likely, we're not attached to wineconsole
300 * let's try to return a handle to the unix-console
302 int fd = open("/dev/tty", output ? O_WRONLY : O_RDONLY);
303 ret = INVALID_HANDLE_VALUE;
306 DWORD access = (output ? GENERIC_WRITE : GENERIC_READ) | SYNCHRONIZE;
307 wine_server_fd_to_handle(fd, access, inherit ? OBJ_INHERIT : 0, &ret);
314 /******************************************************************
315 * VerifyConsoleIoHandle (KERNEL32.@)
319 BOOL WINAPI VerifyConsoleIoHandle(HANDLE handle)
323 if (!is_console_handle(handle)) return FALSE;
324 SERVER_START_REQ(get_console_mode)
326 req->handle = console_handle_unmap(handle);
327 ret = !wine_server_call_err( req );
333 /******************************************************************
334 * DuplicateConsoleHandle (KERNEL32.@)
338 HANDLE WINAPI DuplicateConsoleHandle(HANDLE handle, DWORD access, BOOL inherit,
343 if (!is_console_handle(handle) ||
344 !DuplicateHandle(GetCurrentProcess(), console_handle_unmap(handle),
345 GetCurrentProcess(), &ret, access, inherit, options))
346 return INVALID_HANDLE_VALUE;
347 return console_handle_map(ret);
350 /******************************************************************
351 * CloseConsoleHandle (KERNEL32.@)
355 BOOL WINAPI CloseConsoleHandle(HANDLE handle)
357 if (!is_console_handle(handle))
359 SetLastError(ERROR_INVALID_PARAMETER);
362 return CloseHandle(console_handle_unmap(handle));
365 /******************************************************************
366 * GetConsoleInputWaitHandle (KERNEL32.@)
370 HANDLE WINAPI GetConsoleInputWaitHandle(void)
372 static HANDLE console_wait_event;
374 /* FIXME: this is not thread safe */
375 if (!console_wait_event)
377 SERVER_START_REQ(get_console_wait_event)
379 if (!wine_server_call_err( req )) console_wait_event = reply->handle;
383 return console_wait_event;
387 /******************************************************************************
388 * WriteConsoleInputA [KERNEL32.@]
390 BOOL WINAPI WriteConsoleInputA( HANDLE handle, const INPUT_RECORD *buffer,
391 DWORD count, LPDWORD written )
396 if (!(recW = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*recW) ))) return FALSE;
397 memcpy( recW, buffer, count*sizeof(*recW) );
398 input_records_AtoW( recW, count );
399 ret = WriteConsoleInputW( handle, recW, count, written );
400 HeapFree( GetProcessHeap(), 0, recW );
405 /******************************************************************************
406 * WriteConsoleInputW [KERNEL32.@]
408 BOOL WINAPI WriteConsoleInputW( HANDLE handle, const INPUT_RECORD *buffer,
409 DWORD count, LPDWORD written )
413 TRACE("(%p,%p,%d,%p)\n", handle, buffer, count, written);
415 if (written) *written = 0;
416 SERVER_START_REQ( write_console_input )
418 req->handle = console_handle_unmap(handle);
419 wine_server_add_data( req, buffer, count * sizeof(INPUT_RECORD) );
420 if ((ret = !wine_server_call_err( req )) && written)
421 *written = reply->written;
429 /***********************************************************************
430 * WriteConsoleOutputA (KERNEL32.@)
432 BOOL WINAPI WriteConsoleOutputA( HANDLE hConsoleOutput, const CHAR_INFO *lpBuffer,
433 COORD size, COORD coord, LPSMALL_RECT region )
437 COORD new_size, new_coord;
440 new_size.X = min( region->Right - region->Left + 1, size.X - coord.X );
441 new_size.Y = min( region->Bottom - region->Top + 1, size.Y - coord.Y );
443 if (new_size.X <= 0 || new_size.Y <= 0)
445 region->Bottom = region->Top + new_size.Y - 1;
446 region->Right = region->Left + new_size.X - 1;
450 /* only copy the useful rectangle */
451 if (!(ciw = HeapAlloc( GetProcessHeap(), 0, sizeof(CHAR_INFO) * new_size.X * new_size.Y )))
453 for (y = 0; y < new_size.Y; y++)
455 memcpy( &ciw[y * new_size.X], &lpBuffer[(y + coord.Y) * size.X + coord.X],
456 new_size.X * sizeof(CHAR_INFO) );
457 char_info_AtoW( &ciw[ y * new_size.X ], new_size.X );
459 new_coord.X = new_coord.Y = 0;
460 ret = WriteConsoleOutputW( hConsoleOutput, ciw, new_size, new_coord, region );
461 HeapFree( GetProcessHeap(), 0, ciw );
466 /***********************************************************************
467 * WriteConsoleOutputW (KERNEL32.@)
469 BOOL WINAPI WriteConsoleOutputW( HANDLE hConsoleOutput, const CHAR_INFO *lpBuffer,
470 COORD size, COORD coord, LPSMALL_RECT region )
472 int width, height, y;
475 TRACE("(%p,%p,(%d,%d),(%d,%d),(%d,%dx%d,%d)\n",
476 hConsoleOutput, lpBuffer, size.X, size.Y, coord.X, coord.Y,
477 region->Left, region->Top, region->Right, region->Bottom);
479 width = min( region->Right - region->Left + 1, size.X - coord.X );
480 height = min( region->Bottom - region->Top + 1, size.Y - coord.Y );
482 if (width > 0 && height > 0)
484 for (y = 0; y < height; y++)
486 SERVER_START_REQ( write_console_output )
488 req->handle = console_handle_unmap(hConsoleOutput);
489 req->x = region->Left;
490 req->y = region->Top + y;
491 req->mode = CHAR_INFO_MODE_TEXTATTR;
493 wine_server_add_data( req, &lpBuffer[(y + coord.Y) * size.X + coord.X],
494 width * sizeof(CHAR_INFO));
495 if ((ret = !wine_server_call_err( req )))
497 width = min( width, reply->width - region->Left );
498 height = min( height, reply->height - region->Top );
505 region->Bottom = region->Top + height - 1;
506 region->Right = region->Left + width - 1;
511 /******************************************************************************
512 * WriteConsoleOutputCharacterA [KERNEL32.@]
514 * See WriteConsoleOutputCharacterW.
516 BOOL WINAPI WriteConsoleOutputCharacterA( HANDLE hConsoleOutput, LPCSTR str, DWORD length,
517 COORD coord, LPDWORD lpNumCharsWritten )
523 TRACE("(%p,%s,%d,%dx%d,%p)\n", hConsoleOutput,
524 debugstr_an(str, length), length, coord.X, coord.Y, lpNumCharsWritten);
526 lenW = MultiByteToWideChar( GetConsoleOutputCP(), 0, str, length, NULL, 0 );
528 if (lpNumCharsWritten) *lpNumCharsWritten = 0;
530 if (!(strW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) ))) return FALSE;
531 MultiByteToWideChar( GetConsoleOutputCP(), 0, str, length, strW, lenW );
533 ret = WriteConsoleOutputCharacterW( hConsoleOutput, strW, lenW, coord, lpNumCharsWritten );
534 HeapFree( GetProcessHeap(), 0, strW );
539 /******************************************************************************
540 * WriteConsoleOutputAttribute [KERNEL32.@] Sets attributes for some cells in
541 * the console screen buffer
544 * hConsoleOutput [I] Handle to screen buffer
545 * attr [I] Pointer to buffer with write attributes
546 * length [I] Number of cells to write to
547 * coord [I] Coords of first cell
548 * lpNumAttrsWritten [O] Pointer to number of cells written
555 BOOL WINAPI WriteConsoleOutputAttribute( HANDLE hConsoleOutput, CONST WORD *attr, DWORD length,
556 COORD coord, LPDWORD lpNumAttrsWritten )
560 TRACE("(%p,%p,%d,%dx%d,%p)\n", hConsoleOutput,attr,length,coord.X,coord.Y,lpNumAttrsWritten);
562 SERVER_START_REQ( write_console_output )
564 req->handle = console_handle_unmap(hConsoleOutput);
567 req->mode = CHAR_INFO_MODE_ATTR;
569 wine_server_add_data( req, attr, length * sizeof(WORD) );
570 if ((ret = !wine_server_call_err( req )))
572 if (lpNumAttrsWritten) *lpNumAttrsWritten = reply->written;
580 /******************************************************************************
581 * FillConsoleOutputCharacterA [KERNEL32.@]
583 * See FillConsoleOutputCharacterW.
585 BOOL WINAPI FillConsoleOutputCharacterA( HANDLE hConsoleOutput, CHAR ch, DWORD length,
586 COORD coord, LPDWORD lpNumCharsWritten )
590 MultiByteToWideChar( GetConsoleOutputCP(), 0, &ch, 1, &wch, 1 );
591 return FillConsoleOutputCharacterW(hConsoleOutput, wch, length, coord, lpNumCharsWritten);
595 /******************************************************************************
596 * FillConsoleOutputCharacterW [KERNEL32.@] Writes characters to console
599 * hConsoleOutput [I] Handle to screen buffer
600 * ch [I] Character to write
601 * length [I] Number of cells to write to
602 * coord [I] Coords of first cell
603 * lpNumCharsWritten [O] Pointer to number of cells written
609 BOOL WINAPI FillConsoleOutputCharacterW( HANDLE hConsoleOutput, WCHAR ch, DWORD length,
610 COORD coord, LPDWORD lpNumCharsWritten)
614 TRACE("(%p,%s,%d,(%dx%d),%p)\n",
615 hConsoleOutput, debugstr_wn(&ch, 1), length, coord.X, coord.Y, lpNumCharsWritten);
617 SERVER_START_REQ( fill_console_output )
619 req->handle = console_handle_unmap(hConsoleOutput);
622 req->mode = CHAR_INFO_MODE_TEXT;
626 if ((ret = !wine_server_call_err( req )))
628 if (lpNumCharsWritten) *lpNumCharsWritten = reply->written;
636 /******************************************************************************
637 * FillConsoleOutputAttribute [KERNEL32.@] Sets attributes for console
640 * hConsoleOutput [I] Handle to screen buffer
641 * attr [I] Color attribute to write
642 * length [I] Number of cells to write to
643 * coord [I] Coords of first cell
644 * lpNumAttrsWritten [O] Pointer to number of cells written
650 BOOL WINAPI FillConsoleOutputAttribute( HANDLE hConsoleOutput, WORD attr, DWORD length,
651 COORD coord, LPDWORD lpNumAttrsWritten )
655 TRACE("(%p,%d,%d,(%dx%d),%p)\n",
656 hConsoleOutput, attr, length, coord.X, coord.Y, lpNumAttrsWritten);
658 SERVER_START_REQ( fill_console_output )
660 req->handle = console_handle_unmap(hConsoleOutput);
663 req->mode = CHAR_INFO_MODE_ATTR;
665 req->data.attr = attr;
667 if ((ret = !wine_server_call_err( req )))
669 if (lpNumAttrsWritten) *lpNumAttrsWritten = reply->written;
677 /******************************************************************************
678 * ReadConsoleOutputCharacterA [KERNEL32.@]
681 BOOL WINAPI ReadConsoleOutputCharacterA(HANDLE hConsoleOutput, LPSTR lpstr, DWORD count,
682 COORD coord, LPDWORD read_count)
686 LPWSTR wptr = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
688 if (read_count) *read_count = 0;
689 if (!wptr) return FALSE;
691 if ((ret = ReadConsoleOutputCharacterW( hConsoleOutput, wptr, count, coord, &read )))
693 read = WideCharToMultiByte( GetConsoleOutputCP(), 0, wptr, read, lpstr, count, NULL, NULL);
694 if (read_count) *read_count = read;
696 HeapFree( GetProcessHeap(), 0, wptr );
701 /******************************************************************************
702 * ReadConsoleOutputCharacterW [KERNEL32.@]
705 BOOL WINAPI ReadConsoleOutputCharacterW( HANDLE hConsoleOutput, LPWSTR buffer, DWORD count,
706 COORD coord, LPDWORD read_count )
710 TRACE( "(%p,%p,%d,%dx%d,%p)\n", hConsoleOutput, buffer, count, coord.X, coord.Y, read_count );
712 SERVER_START_REQ( read_console_output )
714 req->handle = console_handle_unmap(hConsoleOutput);
717 req->mode = CHAR_INFO_MODE_TEXT;
719 wine_server_set_reply( req, buffer, count * sizeof(WCHAR) );
720 if ((ret = !wine_server_call_err( req )))
722 if (read_count) *read_count = wine_server_reply_size(reply) / sizeof(WCHAR);
730 /******************************************************************************
731 * ReadConsoleOutputAttribute [KERNEL32.@]
733 BOOL WINAPI ReadConsoleOutputAttribute(HANDLE hConsoleOutput, LPWORD lpAttribute, DWORD length,
734 COORD coord, LPDWORD read_count)
738 TRACE("(%p,%p,%d,%dx%d,%p)\n",
739 hConsoleOutput, lpAttribute, length, coord.X, coord.Y, read_count);
741 SERVER_START_REQ( read_console_output )
743 req->handle = console_handle_unmap(hConsoleOutput);
746 req->mode = CHAR_INFO_MODE_ATTR;
748 wine_server_set_reply( req, lpAttribute, length * sizeof(WORD) );
749 if ((ret = !wine_server_call_err( req )))
751 if (read_count) *read_count = wine_server_reply_size(reply) / sizeof(WORD);
759 /******************************************************************************
760 * ReadConsoleOutputA [KERNEL32.@]
763 BOOL WINAPI ReadConsoleOutputA( HANDLE hConsoleOutput, LPCHAR_INFO lpBuffer, COORD size,
764 COORD coord, LPSMALL_RECT region )
769 ret = ReadConsoleOutputW( hConsoleOutput, lpBuffer, size, coord, region );
770 if (ret && region->Right >= region->Left)
772 for (y = 0; y <= region->Bottom - region->Top; y++)
774 char_info_WtoA( &lpBuffer[(coord.Y + y) * size.X + coord.X],
775 region->Right - region->Left + 1 );
782 /******************************************************************************
783 * ReadConsoleOutputW [KERNEL32.@]
785 * NOTE: The NT4 (sp5) kernel crashes on me if size is (0,0). I don't
786 * think we need to be *that* compatible. -- AJ
788 BOOL WINAPI ReadConsoleOutputW( HANDLE hConsoleOutput, LPCHAR_INFO lpBuffer, COORD size,
789 COORD coord, LPSMALL_RECT region )
791 int width, height, y;
794 width = min( region->Right - region->Left + 1, size.X - coord.X );
795 height = min( region->Bottom - region->Top + 1, size.Y - coord.Y );
797 if (width > 0 && height > 0)
799 for (y = 0; y < height; y++)
801 SERVER_START_REQ( read_console_output )
803 req->handle = console_handle_unmap(hConsoleOutput);
804 req->x = region->Left;
805 req->y = region->Top + y;
806 req->mode = CHAR_INFO_MODE_TEXTATTR;
808 wine_server_set_reply( req, &lpBuffer[(y+coord.Y) * size.X + coord.X],
809 width * sizeof(CHAR_INFO) );
810 if ((ret = !wine_server_call_err( req )))
812 width = min( width, reply->width - region->Left );
813 height = min( height, reply->height - region->Top );
820 region->Bottom = region->Top + height - 1;
821 region->Right = region->Left + width - 1;
826 /******************************************************************************
827 * ReadConsoleInputA [KERNEL32.@] Reads data from a console
830 * handle [I] Handle to console input buffer
831 * buffer [O] Address of buffer for read data
832 * count [I] Number of records to read
833 * pRead [O] Address of number of records read
839 BOOL WINAPI ReadConsoleInputA( HANDLE handle, PINPUT_RECORD buffer, DWORD count, LPDWORD pRead )
843 if (!ReadConsoleInputW( handle, buffer, count, &read )) return FALSE;
844 input_records_WtoA( buffer, read );
845 if (pRead) *pRead = read;
850 /***********************************************************************
851 * PeekConsoleInputA (KERNEL32.@)
853 * Gets 'count' first events (or less) from input queue.
855 BOOL WINAPI PeekConsoleInputA( HANDLE handle, PINPUT_RECORD buffer, DWORD count, LPDWORD pRead )
859 if (!PeekConsoleInputW( handle, buffer, count, &read )) return FALSE;
860 input_records_WtoA( buffer, read );
861 if (pRead) *pRead = read;
866 /***********************************************************************
867 * PeekConsoleInputW (KERNEL32.@)
869 BOOL WINAPI PeekConsoleInputW( HANDLE handle, PINPUT_RECORD buffer, DWORD count, LPDWORD read )
872 SERVER_START_REQ( read_console_input )
874 req->handle = console_handle_unmap(handle);
876 wine_server_set_reply( req, buffer, count * sizeof(INPUT_RECORD) );
877 if ((ret = !wine_server_call_err( req )))
879 if (read) *read = count ? reply->read : 0;
887 /***********************************************************************
888 * GetNumberOfConsoleInputEvents (KERNEL32.@)
890 BOOL WINAPI GetNumberOfConsoleInputEvents( HANDLE handle, LPDWORD nrofevents )
893 SERVER_START_REQ( read_console_input )
895 req->handle = console_handle_unmap(handle);
897 if ((ret = !wine_server_call_err( req )))
899 if (nrofevents) *nrofevents = reply->read;
907 /******************************************************************************
910 * Helper function for ReadConsole, ReadConsoleInput and FlushConsoleInputBuffer
913 * 0 for error, 1 for no INPUT_RECORD ready, 2 with INPUT_RECORD ready
915 enum read_console_input_return {rci_error = 0, rci_timeout = 1, rci_gotone = 2};
916 static enum read_console_input_return read_console_input(HANDLE handle, PINPUT_RECORD ir, DWORD timeout)
918 enum read_console_input_return ret;
920 if (WaitForSingleObject(GetConsoleInputWaitHandle(), timeout) != WAIT_OBJECT_0)
922 SERVER_START_REQ( read_console_input )
924 req->handle = console_handle_unmap(handle);
926 wine_server_set_reply( req, ir, sizeof(INPUT_RECORD) );
927 if (wine_server_call_err( req ) || !reply->read) ret = rci_error;
928 else ret = rci_gotone;
936 /***********************************************************************
937 * FlushConsoleInputBuffer (KERNEL32.@)
939 BOOL WINAPI FlushConsoleInputBuffer( HANDLE handle )
941 enum read_console_input_return last;
944 while ((last = read_console_input(handle, &ir, 0)) == rci_gotone);
946 return last == rci_timeout;
950 /***********************************************************************
951 * SetConsoleTitleA (KERNEL32.@)
953 BOOL WINAPI SetConsoleTitleA( LPCSTR title )
958 DWORD len = MultiByteToWideChar( GetConsoleOutputCP(), 0, title, -1, NULL, 0 );
959 if (!(titleW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)))) return FALSE;
960 MultiByteToWideChar( GetConsoleOutputCP(), 0, title, -1, titleW, len );
961 ret = SetConsoleTitleW(titleW);
962 HeapFree(GetProcessHeap(), 0, titleW);
967 /***********************************************************************
968 * GetConsoleKeyboardLayoutNameA (KERNEL32.@)
970 BOOL WINAPI GetConsoleKeyboardLayoutNameA(LPSTR layoutName)
972 FIXME( "stub %p\n", layoutName);
976 /***********************************************************************
977 * GetConsoleKeyboardLayoutNameW (KERNEL32.@)
979 BOOL WINAPI GetConsoleKeyboardLayoutNameW(LPWSTR layoutName)
981 FIXME( "stub %p\n", layoutName);
985 /***********************************************************************
986 * GetConsoleInputExeNameA (KERNEL32.@)
988 DWORD WINAPI GetConsoleInputExeNameA(DWORD BufferLength, LPSTR lpBuffer)
991 FIXME( "stub %u %p\n", BufferLength, lpBuffer);
995 /***********************************************************************
996 * GetConsoleInputExeNameW (KERNEL32.@)
998 DWORD WINAPI GetConsoleInputExeNameW(DWORD BufferLength, LPWSTR lpBuffer)
1001 FIXME( "stub %u %p\n", BufferLength, lpBuffer);
1005 /***********************************************************************
1006 * GetConsoleTitleA (KERNEL32.@)
1008 * See GetConsoleTitleW.
1010 DWORD WINAPI GetConsoleTitleA(LPSTR title, DWORD size)
1012 WCHAR *ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * size);
1016 ret = GetConsoleTitleW( ptr, size );
1019 WideCharToMultiByte( GetConsoleOutputCP(), 0, ptr, ret + 1, title, size, NULL, NULL);
1020 ret = strlen(title);
1022 HeapFree(GetProcessHeap(), 0, ptr);
1027 /******************************************************************************
1028 * GetConsoleTitleW [KERNEL32.@] Retrieves title string for console
1031 * title [O] Address of buffer for title
1032 * size [I] Size of buffer
1035 * Success: Length of string copied
1038 DWORD WINAPI GetConsoleTitleW(LPWSTR title, DWORD size)
1042 SERVER_START_REQ( get_console_input_info )
1045 wine_server_set_reply( req, title, (size-1) * sizeof(WCHAR) );
1046 if (!wine_server_call_err( req ))
1048 ret = wine_server_reply_size(reply) / sizeof(WCHAR);
1057 /***********************************************************************
1058 * GetLargestConsoleWindowSize (KERNEL32.@)
1061 * This should return a COORD, but calling convention for returning
1062 * structures is different between Windows and gcc on i386.
1067 #undef GetLargestConsoleWindowSize
1068 DWORD WINAPI GetLargestConsoleWindowSize(HANDLE hConsoleOutput)
1076 TRACE("(%p), returning %dx%d (%x)\n", hConsoleOutput, x.c.X, x.c.Y, x.w);
1079 #endif /* defined(__i386__) */
1082 /***********************************************************************
1083 * GetLargestConsoleWindowSize (KERNEL32.@)
1086 * This should return a COORD, but calling convention for returning
1087 * structures is different between Windows and gcc on i386.
1092 COORD WINAPI GetLargestConsoleWindowSize(HANDLE hConsoleOutput)
1097 TRACE("(%p), returning %dx%d\n", hConsoleOutput, c.X, c.Y);
1100 #endif /* defined(__i386__) */
1102 static WCHAR* S_EditString /* = NULL */;
1103 static unsigned S_EditStrPos /* = 0 */;
1105 /***********************************************************************
1106 * FreeConsole (KERNEL32.@)
1108 BOOL WINAPI FreeConsole(VOID)
1112 SERVER_START_REQ(free_console)
1114 ret = !wine_server_call_err( req );
1120 /******************************************************************
1121 * start_console_renderer
1123 * helper for AllocConsole
1124 * starts the renderer process
1126 static BOOL start_console_renderer_helper(const char* appname, STARTUPINFOA* si,
1131 PROCESS_INFORMATION pi;
1133 /* FIXME: use dynamic allocation for most of the buffers below */
1134 ret = snprintf(buffer, sizeof(buffer), "%s --use-event=%ld", appname, (DWORD_PTR)hEvent);
1135 if ((ret > -1) && (ret < sizeof(buffer)) &&
1136 CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS,
1137 NULL, NULL, si, &pi))
1139 if (WaitForSingleObject(hEvent, INFINITE) != WAIT_OBJECT_0) return FALSE;
1141 TRACE("Started wineconsole pid=%08x tid=%08x\n",
1142 pi.dwProcessId, pi.dwThreadId);
1149 static BOOL start_console_renderer(STARTUPINFOA* si)
1153 OBJECT_ATTRIBUTES attr;
1156 attr.Length = sizeof(attr);
1157 attr.RootDirectory = 0;
1158 attr.Attributes = OBJ_INHERIT;
1159 attr.ObjectName = NULL;
1160 attr.SecurityDescriptor = NULL;
1161 attr.SecurityQualityOfService = NULL;
1163 NtCreateEvent(&hEvent, EVENT_ALL_ACCESS, &attr, TRUE, FALSE);
1164 if (!hEvent) return FALSE;
1166 /* first try environment variable */
1167 if ((p = getenv("WINECONSOLE")) != NULL)
1169 ret = start_console_renderer_helper(p, si, hEvent);
1171 ERR("Couldn't launch Wine console from WINECONSOLE env var (%s)... "
1172 "trying default access\n", p);
1175 /* then try the regular PATH */
1177 ret = start_console_renderer_helper("wineconsole", si, hEvent);
1179 CloseHandle(hEvent);
1183 /***********************************************************************
1184 * AllocConsole (KERNEL32.@)
1186 * creates an xterm with a pty to our program
1188 BOOL WINAPI AllocConsole(void)
1190 HANDLE handle_in = INVALID_HANDLE_VALUE;
1191 HANDLE handle_out = INVALID_HANDLE_VALUE;
1192 HANDLE handle_err = INVALID_HANDLE_VALUE;
1193 STARTUPINFOA siCurrent;
1194 STARTUPINFOA siConsole;
1199 handle_in = OpenConsoleW( coninW, GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
1200 FALSE, OPEN_EXISTING );
1202 if (VerifyConsoleIoHandle(handle_in))
1204 /* we already have a console opened on this process, don't create a new one */
1205 CloseHandle(handle_in);
1208 /* happens when we're running on a Unix console */
1209 if (handle_in != INVALID_HANDLE_VALUE) CloseHandle(handle_in);
1211 GetStartupInfoA(&siCurrent);
1213 memset(&siConsole, 0, sizeof(siConsole));
1214 siConsole.cb = sizeof(siConsole);
1215 /* setup a view arguments for wineconsole (it'll use them as default values) */
1216 if (siCurrent.dwFlags & STARTF_USECOUNTCHARS)
1218 siConsole.dwFlags |= STARTF_USECOUNTCHARS;
1219 siConsole.dwXCountChars = siCurrent.dwXCountChars;
1220 siConsole.dwYCountChars = siCurrent.dwYCountChars;
1222 if (siCurrent.dwFlags & STARTF_USEFILLATTRIBUTE)
1224 siConsole.dwFlags |= STARTF_USEFILLATTRIBUTE;
1225 siConsole.dwFillAttribute = siCurrent.dwFillAttribute;
1227 if (siCurrent.dwFlags & STARTF_USESHOWWINDOW)
1229 siConsole.dwFlags |= STARTF_USESHOWWINDOW;
1230 siConsole.wShowWindow = siCurrent.wShowWindow;
1232 /* FIXME (should pass the unicode form) */
1233 if (siCurrent.lpTitle)
1234 siConsole.lpTitle = siCurrent.lpTitle;
1235 else if (GetModuleFileNameA(0, buffer, sizeof(buffer)))
1237 buffer[sizeof(buffer) - 1] = '\0';
1238 siConsole.lpTitle = buffer;
1241 if (!start_console_renderer(&siConsole))
1244 if( !(siCurrent.dwFlags & STARTF_USESTDHANDLES) ) {
1245 /* all std I/O handles are inheritable by default */
1246 handle_in = OpenConsoleW( coninW, GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
1247 TRUE, OPEN_EXISTING );
1248 if (handle_in == INVALID_HANDLE_VALUE) goto the_end;
1250 handle_out = OpenConsoleW( conoutW, GENERIC_READ|GENERIC_WRITE,
1251 TRUE, OPEN_EXISTING );
1252 if (handle_out == INVALID_HANDLE_VALUE) goto the_end;
1254 if (!DuplicateHandle(GetCurrentProcess(), handle_out, GetCurrentProcess(),
1255 &handle_err, 0, TRUE, DUPLICATE_SAME_ACCESS))
1258 /* STARTF_USESTDHANDLES flag: use handles from StartupInfo */
1259 handle_in = siCurrent.hStdInput;
1260 handle_out = siCurrent.hStdOutput;
1261 handle_err = siCurrent.hStdError;
1264 /* NT resets the STD_*_HANDLEs on console alloc */
1265 SetStdHandle(STD_INPUT_HANDLE, handle_in);
1266 SetStdHandle(STD_OUTPUT_HANDLE, handle_out);
1267 SetStdHandle(STD_ERROR_HANDLE, handle_err);
1269 SetLastError(ERROR_SUCCESS);
1274 ERR("Can't allocate console\n");
1275 if (handle_in != INVALID_HANDLE_VALUE) CloseHandle(handle_in);
1276 if (handle_out != INVALID_HANDLE_VALUE) CloseHandle(handle_out);
1277 if (handle_err != INVALID_HANDLE_VALUE) CloseHandle(handle_err);
1283 /***********************************************************************
1284 * ReadConsoleA (KERNEL32.@)
1286 BOOL WINAPI ReadConsoleA(HANDLE hConsoleInput, LPVOID lpBuffer, DWORD nNumberOfCharsToRead,
1287 LPDWORD lpNumberOfCharsRead, LPVOID lpReserved)
1289 LPWSTR ptr = HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead * sizeof(WCHAR));
1293 if ((ret = ReadConsoleW(hConsoleInput, ptr, nNumberOfCharsToRead, &ncr, NULL)))
1294 ncr = WideCharToMultiByte(GetConsoleCP(), 0, ptr, ncr, lpBuffer, nNumberOfCharsToRead, NULL, NULL);
1296 if (lpNumberOfCharsRead) *lpNumberOfCharsRead = ncr;
1297 HeapFree(GetProcessHeap(), 0, ptr);
1302 /***********************************************************************
1303 * ReadConsoleW (KERNEL32.@)
1305 BOOL WINAPI ReadConsoleW(HANDLE hConsoleInput, LPVOID lpBuffer,
1306 DWORD nNumberOfCharsToRead, LPDWORD lpNumberOfCharsRead, LPVOID lpReserved)
1309 LPWSTR xbuf = (LPWSTR)lpBuffer;
1312 TRACE("(%p,%p,%d,%p,%p)\n",
1313 hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, lpReserved);
1315 if (!GetConsoleMode(hConsoleInput, &mode))
1318 if (mode & ENABLE_LINE_INPUT)
1320 if (!S_EditString || S_EditString[S_EditStrPos] == 0)
1322 HeapFree(GetProcessHeap(), 0, S_EditString);
1323 if (!(S_EditString = CONSOLE_Readline(hConsoleInput)))
1327 charsread = lstrlenW(&S_EditString[S_EditStrPos]);
1328 if (charsread > nNumberOfCharsToRead) charsread = nNumberOfCharsToRead;
1329 memcpy(xbuf, &S_EditString[S_EditStrPos], charsread * sizeof(WCHAR));
1330 S_EditStrPos += charsread;
1335 DWORD timeout = INFINITE;
1337 /* FIXME: should we read at least 1 char? The SDK does not say */
1338 /* wait for at least one available input record (it doesn't mean we'll have
1339 * chars stored in xbuf...)
1344 if (read_console_input(hConsoleInput, &ir, timeout) != rci_gotone) break;
1346 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown &&
1347 ir.Event.KeyEvent.uChar.UnicodeChar &&
1348 !(ir.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
1350 xbuf[charsread++] = ir.Event.KeyEvent.uChar.UnicodeChar;
1352 } while (charsread < nNumberOfCharsToRead);
1353 /* nothing has been read */
1354 if (timeout == INFINITE) return FALSE;
1357 if (lpNumberOfCharsRead) *lpNumberOfCharsRead = charsread;
1363 /***********************************************************************
1364 * ReadConsoleInputW (KERNEL32.@)
1366 BOOL WINAPI ReadConsoleInputW(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer,
1367 DWORD nLength, LPDWORD lpNumberOfEventsRead)
1370 DWORD timeout = INFINITE;
1374 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = 0;
1378 /* loop until we get at least one event */
1379 while (read_console_input(hConsoleInput, &lpBuffer[idx], timeout) == rci_gotone &&
1383 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = idx;
1388 /******************************************************************************
1389 * WriteConsoleOutputCharacterW [KERNEL32.@]
1391 * Copy character to consecutive cells in the console screen buffer.
1394 * hConsoleOutput [I] Handle to screen buffer
1395 * str [I] Pointer to buffer with chars to write
1396 * length [I] Number of cells to write to
1397 * coord [I] Coords of first cell
1398 * lpNumCharsWritten [O] Pointer to number of cells written
1405 BOOL WINAPI WriteConsoleOutputCharacterW( HANDLE hConsoleOutput, LPCWSTR str, DWORD length,
1406 COORD coord, LPDWORD lpNumCharsWritten )
1410 TRACE("(%p,%s,%d,%dx%d,%p)\n", hConsoleOutput,
1411 debugstr_wn(str, length), length, coord.X, coord.Y, lpNumCharsWritten);
1413 SERVER_START_REQ( write_console_output )
1415 req->handle = console_handle_unmap(hConsoleOutput);
1418 req->mode = CHAR_INFO_MODE_TEXT;
1420 wine_server_add_data( req, str, length * sizeof(WCHAR) );
1421 if ((ret = !wine_server_call_err( req )))
1423 if (lpNumCharsWritten) *lpNumCharsWritten = reply->written;
1431 /******************************************************************************
1432 * SetConsoleTitleW [KERNEL32.@] Sets title bar string for console
1435 * title [I] Address of new title
1441 BOOL WINAPI SetConsoleTitleW(LPCWSTR title)
1445 TRACE("(%s)\n", debugstr_w(title));
1446 SERVER_START_REQ( set_console_input_info )
1449 req->mask = SET_CONSOLE_INPUT_INFO_TITLE;
1450 wine_server_add_data( req, title, strlenW(title) * sizeof(WCHAR) );
1451 ret = !wine_server_call_err( req );
1458 /***********************************************************************
1459 * GetNumberOfConsoleMouseButtons (KERNEL32.@)
1461 BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
1463 FIXME("(%p): stub\n", nrofbuttons);
1468 /******************************************************************************
1469 * SetConsoleInputExeNameW [KERNEL32.@]
1474 BOOL WINAPI SetConsoleInputExeNameW(LPCWSTR name)
1476 FIXME("(%s): stub!\n", debugstr_w(name));
1478 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1482 /******************************************************************************
1483 * SetConsoleInputExeNameA [KERNEL32.@]
1488 BOOL WINAPI SetConsoleInputExeNameA(LPCSTR name)
1490 int len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
1491 LPWSTR xptr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1494 if (!xptr) return FALSE;
1496 MultiByteToWideChar(CP_ACP, 0, name, -1, xptr, len);
1497 ret = SetConsoleInputExeNameW(xptr);
1498 HeapFree(GetProcessHeap(), 0, xptr);
1503 /******************************************************************
1504 * CONSOLE_DefaultHandler
1506 * Final control event handler
1508 static BOOL WINAPI CONSOLE_DefaultHandler(DWORD dwCtrlType)
1510 FIXME("Terminating process %x on event %x\n", GetCurrentProcessId(), dwCtrlType);
1512 /* should never go here */
1516 /******************************************************************************
1517 * SetConsoleCtrlHandler [KERNEL32.@] Adds function to calling process list
1520 * func [I] Address of handler function
1521 * add [I] Handler to add or remove
1528 struct ConsoleHandler
1530 PHANDLER_ROUTINE handler;
1531 struct ConsoleHandler* next;
1534 static struct ConsoleHandler CONSOLE_DefaultConsoleHandler = {CONSOLE_DefaultHandler, NULL};
1535 static struct ConsoleHandler* CONSOLE_Handlers = &CONSOLE_DefaultConsoleHandler;
1537 static CRITICAL_SECTION CONSOLE_CritSect;
1538 static CRITICAL_SECTION_DEBUG critsect_debug =
1540 0, 0, &CONSOLE_CritSect,
1541 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1542 0, 0, { (DWORD_PTR)(__FILE__ ": CONSOLE_CritSect") }
1544 static CRITICAL_SECTION CONSOLE_CritSect = { &critsect_debug, -1, 0, 0, 0, 0 };
1546 /*****************************************************************************/
1548 /******************************************************************
1549 * SetConsoleCtrlHandler (KERNEL32.@)
1551 BOOL WINAPI SetConsoleCtrlHandler(PHANDLER_ROUTINE func, BOOL add)
1555 TRACE("(%p,%i)\n", func, add);
1559 RtlEnterCriticalSection(&CONSOLE_CritSect);
1561 NtCurrentTeb()->Peb->ProcessParameters->ConsoleFlags |= 1;
1563 NtCurrentTeb()->Peb->ProcessParameters->ConsoleFlags &= ~1;
1564 RtlLeaveCriticalSection(&CONSOLE_CritSect);
1568 struct ConsoleHandler* ch = HeapAlloc(GetProcessHeap(), 0, sizeof(struct ConsoleHandler));
1570 if (!ch) return FALSE;
1572 RtlEnterCriticalSection(&CONSOLE_CritSect);
1573 ch->next = CONSOLE_Handlers;
1574 CONSOLE_Handlers = ch;
1575 RtlLeaveCriticalSection(&CONSOLE_CritSect);
1579 struct ConsoleHandler** ch;
1580 RtlEnterCriticalSection(&CONSOLE_CritSect);
1581 for (ch = &CONSOLE_Handlers; *ch; ch = &(*ch)->next)
1583 if ((*ch)->handler == func) break;
1587 struct ConsoleHandler* rch = *ch;
1590 if (rch == &CONSOLE_DefaultConsoleHandler)
1592 ERR("Who's trying to remove default handler???\n");
1593 SetLastError(ERROR_INVALID_PARAMETER);
1599 HeapFree(GetProcessHeap(), 0, rch);
1604 WARN("Attempt to remove non-installed CtrlHandler %p\n", func);
1605 SetLastError(ERROR_INVALID_PARAMETER);
1608 RtlLeaveCriticalSection(&CONSOLE_CritSect);
1613 static WINE_EXCEPTION_FILTER(CONSOLE_CtrlEventHandler)
1615 TRACE("(%x)\n", GetExceptionCode());
1616 return EXCEPTION_EXECUTE_HANDLER;
1619 /******************************************************************
1620 * CONSOLE_SendEventThread
1622 * Internal helper to pass an event to the list on installed handlers
1624 static DWORD WINAPI CONSOLE_SendEventThread(void* pmt)
1626 DWORD_PTR event = (DWORD_PTR)pmt;
1627 struct ConsoleHandler* ch;
1629 if (event == CTRL_C_EVENT)
1631 BOOL caught_by_dbg = TRUE;
1632 /* First, try to pass the ctrl-C event to the debugger (if any)
1633 * If it continues, there's nothing more to do
1634 * Otherwise, we need to send the ctrl-C event to the handlers
1638 RaiseException( DBG_CONTROL_C, 0, 0, NULL );
1640 __EXCEPT(CONSOLE_CtrlEventHandler)
1642 caught_by_dbg = FALSE;
1645 if (caught_by_dbg) return 0;
1646 /* the debugger didn't continue... so, pass to ctrl handlers */
1648 RtlEnterCriticalSection(&CONSOLE_CritSect);
1649 for (ch = CONSOLE_Handlers; ch; ch = ch->next)
1651 if (ch->handler(event)) break;
1653 RtlLeaveCriticalSection(&CONSOLE_CritSect);
1657 /******************************************************************
1658 * CONSOLE_HandleCtrlC
1660 * Check whether the shall manipulate CtrlC events
1662 int CONSOLE_HandleCtrlC(unsigned sig)
1664 /* FIXME: better test whether a console is attached to this process ??? */
1665 extern unsigned CONSOLE_GetNumHistoryEntries(void);
1666 if (CONSOLE_GetNumHistoryEntries() == (unsigned)-1) return 0;
1668 /* check if we have to ignore ctrl-C events */
1669 if (!(NtCurrentTeb()->Peb->ProcessParameters->ConsoleFlags & 1))
1671 /* Create a separate thread to signal all the events.
1672 * This is needed because:
1673 * - this function can be called in an Unix signal handler (hence on an
1674 * different stack than the thread that's running). This breaks the
1675 * Win32 exception mechanisms (where the thread's stack is checked).
1676 * - since the current thread, while processing the signal, can hold the
1677 * console critical section, we need another execution environment where
1678 * we can wait on this critical section
1680 CreateThread(NULL, 0, CONSOLE_SendEventThread, (void*)CTRL_C_EVENT, 0, NULL);
1685 /******************************************************************************
1686 * GenerateConsoleCtrlEvent [KERNEL32.@] Simulate a CTRL-C or CTRL-BREAK
1689 * dwCtrlEvent [I] Type of event
1690 * dwProcessGroupID [I] Process group ID to send event to
1694 * Failure: False (and *should* [but doesn't] set LastError)
1696 BOOL WINAPI GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
1697 DWORD dwProcessGroupID)
1701 TRACE("(%d, %d)\n", dwCtrlEvent, dwProcessGroupID);
1703 if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
1705 ERR("Invalid event %d for PGID %d\n", dwCtrlEvent, dwProcessGroupID);
1709 SERVER_START_REQ( send_console_signal )
1711 req->signal = dwCtrlEvent;
1712 req->group_id = dwProcessGroupID;
1713 ret = !wine_server_call_err( req );
1717 /* FIXME: shall this function be synchronous, ie only return when all events
1718 * have been handled by all processes in the given group ?
1719 * As of today, we don't wait...
1725 /******************************************************************************
1726 * CreateConsoleScreenBuffer [KERNEL32.@] Creates a console screen buffer
1729 * dwDesiredAccess [I] Access flag
1730 * dwShareMode [I] Buffer share mode
1731 * sa [I] Security attributes
1732 * dwFlags [I] Type of buffer to create
1733 * lpScreenBufferData [I] Reserved
1736 * Should call SetLastError
1739 * Success: Handle to new console screen buffer
1740 * Failure: INVALID_HANDLE_VALUE
1742 HANDLE WINAPI CreateConsoleScreenBuffer(DWORD dwDesiredAccess, DWORD dwShareMode,
1743 LPSECURITY_ATTRIBUTES sa, DWORD dwFlags,
1744 LPVOID lpScreenBufferData)
1746 HANDLE ret = INVALID_HANDLE_VALUE;
1748 TRACE("(%d,%d,%p,%d,%p)\n",
1749 dwDesiredAccess, dwShareMode, sa, dwFlags, lpScreenBufferData);
1751 if (dwFlags != CONSOLE_TEXTMODE_BUFFER || lpScreenBufferData != NULL)
1753 SetLastError(ERROR_INVALID_PARAMETER);
1754 return INVALID_HANDLE_VALUE;
1757 SERVER_START_REQ(create_console_output)
1760 req->access = dwDesiredAccess;
1761 req->attributes = (sa && sa->bInheritHandle) ? OBJ_INHERIT : 0;
1762 req->share = dwShareMode;
1763 if (!wine_server_call_err( req )) ret = reply->handle_out;
1771 /***********************************************************************
1772 * GetConsoleScreenBufferInfo (KERNEL32.@)
1774 BOOL WINAPI GetConsoleScreenBufferInfo(HANDLE hConsoleOutput, LPCONSOLE_SCREEN_BUFFER_INFO csbi)
1778 SERVER_START_REQ(get_console_output_info)
1780 req->handle = console_handle_unmap(hConsoleOutput);
1781 if ((ret = !wine_server_call_err( req )))
1783 csbi->dwSize.X = reply->width;
1784 csbi->dwSize.Y = reply->height;
1785 csbi->dwCursorPosition.X = reply->cursor_x;
1786 csbi->dwCursorPosition.Y = reply->cursor_y;
1787 csbi->wAttributes = reply->attr;
1788 csbi->srWindow.Left = reply->win_left;
1789 csbi->srWindow.Right = reply->win_right;
1790 csbi->srWindow.Top = reply->win_top;
1791 csbi->srWindow.Bottom = reply->win_bottom;
1792 csbi->dwMaximumWindowSize.X = reply->max_width;
1793 csbi->dwMaximumWindowSize.Y = reply->max_height;
1798 TRACE("(%p,(%d,%d) (%d,%d) %d (%d,%d-%d,%d) (%d,%d)\n",
1799 hConsoleOutput, csbi->dwSize.X, csbi->dwSize.Y,
1800 csbi->dwCursorPosition.X, csbi->dwCursorPosition.Y,
1802 csbi->srWindow.Left, csbi->srWindow.Top, csbi->srWindow.Right, csbi->srWindow.Bottom,
1803 csbi->dwMaximumWindowSize.X, csbi->dwMaximumWindowSize.Y);
1809 /******************************************************************************
1810 * SetConsoleActiveScreenBuffer [KERNEL32.@] Sets buffer to current console
1816 BOOL WINAPI SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
1820 TRACE("(%p)\n", hConsoleOutput);
1822 SERVER_START_REQ( set_console_input_info )
1825 req->mask = SET_CONSOLE_INPUT_INFO_ACTIVE_SB;
1826 req->active_sb = hConsoleOutput;
1827 ret = !wine_server_call_err( req );
1834 /***********************************************************************
1835 * GetConsoleMode (KERNEL32.@)
1837 BOOL WINAPI GetConsoleMode(HANDLE hcon, LPDWORD mode)
1841 SERVER_START_REQ(get_console_mode)
1843 req->handle = console_handle_unmap(hcon);
1844 ret = !wine_server_call_err( req );
1845 if (ret && mode) *mode = reply->mode;
1852 /******************************************************************************
1853 * SetConsoleMode [KERNEL32.@] Sets input mode of console's input buffer
1856 * hcon [I] Handle to console input or screen buffer
1857 * mode [I] Input or output mode to set
1864 * ENABLE_PROCESSED_INPUT 0x01
1865 * ENABLE_LINE_INPUT 0x02
1866 * ENABLE_ECHO_INPUT 0x04
1867 * ENABLE_WINDOW_INPUT 0x08
1868 * ENABLE_MOUSE_INPUT 0x10
1870 BOOL WINAPI SetConsoleMode(HANDLE hcon, DWORD mode)
1874 SERVER_START_REQ(set_console_mode)
1876 req->handle = console_handle_unmap(hcon);
1878 ret = !wine_server_call_err( req );
1881 /* FIXME: when resetting a console input to editline mode, I think we should
1882 * empty the S_EditString buffer
1885 TRACE("(%p,%x) retval == %d\n", hcon, mode, ret);
1891 /******************************************************************
1892 * CONSOLE_WriteChars
1894 * WriteConsoleOutput helper: hides server call semantics
1895 * writes a string at a given pos with standard attribute
1897 static int CONSOLE_WriteChars(HANDLE hCon, LPCWSTR lpBuffer, int nc, COORD* pos)
1903 SERVER_START_REQ( write_console_output )
1905 req->handle = console_handle_unmap(hCon);
1908 req->mode = CHAR_INFO_MODE_TEXTSTDATTR;
1910 wine_server_add_data( req, lpBuffer, nc * sizeof(WCHAR) );
1911 if (!wine_server_call_err( req )) written = reply->written;
1915 if (written > 0) pos->X += written;
1919 /******************************************************************
1922 * WriteConsoleOutput helper: handles passing to next line (+scrolling if necessary)
1925 static int next_line(HANDLE hCon, CONSOLE_SCREEN_BUFFER_INFO* csbi)
1931 csbi->dwCursorPosition.X = 0;
1932 csbi->dwCursorPosition.Y++;
1934 if (csbi->dwCursorPosition.Y < csbi->dwSize.Y) return 1;
1937 src.Bottom = csbi->dwSize.Y - 1;
1939 src.Right = csbi->dwSize.X - 1;
1944 ci.Attributes = csbi->wAttributes;
1945 ci.Char.UnicodeChar = ' ';
1947 csbi->dwCursorPosition.Y--;
1948 if (!ScrollConsoleScreenBufferW(hCon, &src, NULL, dst, &ci))
1953 /******************************************************************
1956 * WriteConsoleOutput helper: writes a block of non special characters
1957 * Block can spread on several lines, and wrapping, if needed, is
1961 static int write_block(HANDLE hCon, CONSOLE_SCREEN_BUFFER_INFO* csbi,
1962 DWORD mode, LPCWSTR ptr, int len)
1964 int blk; /* number of chars to write on current line */
1965 int done; /* number of chars already written */
1967 if (len <= 0) return 1;
1969 if (mode & ENABLE_WRAP_AT_EOL_OUTPUT) /* writes remaining on next line */
1971 for (done = 0; done < len; done += blk)
1973 blk = min(len - done, csbi->dwSize.X - csbi->dwCursorPosition.X);
1975 if (CONSOLE_WriteChars(hCon, ptr + done, blk, &csbi->dwCursorPosition) != blk)
1977 if (csbi->dwCursorPosition.X == csbi->dwSize.X && !next_line(hCon, csbi))
1983 int pos = csbi->dwCursorPosition.X;
1984 /* FIXME: we could reduce the number of loops
1985 * but, in most cases we wouldn't gain lots of time (it would only
1986 * happen if we're asked to overwrite more than twice the part of the line,
1989 for (blk = done = 0; done < len; done += blk)
1991 blk = min(len - done, csbi->dwSize.X - csbi->dwCursorPosition.X);
1993 csbi->dwCursorPosition.X = pos;
1994 if (CONSOLE_WriteChars(hCon, ptr + done, blk, &csbi->dwCursorPosition) != blk)
2002 /***********************************************************************
2003 * WriteConsoleW (KERNEL32.@)
2005 BOOL WINAPI WriteConsoleW(HANDLE hConsoleOutput, LPCVOID lpBuffer, DWORD nNumberOfCharsToWrite,
2006 LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
2010 const WCHAR* psz = lpBuffer;
2011 CONSOLE_SCREEN_BUFFER_INFO csbi;
2014 TRACE("%p %s %d %p %p\n",
2015 hConsoleOutput, debugstr_wn(lpBuffer, nNumberOfCharsToWrite),
2016 nNumberOfCharsToWrite, lpNumberOfCharsWritten, lpReserved);
2018 if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = 0;
2020 if (!GetConsoleMode(hConsoleOutput, &mode) ||
2021 !GetConsoleScreenBufferInfo(hConsoleOutput, &csbi))
2024 if (mode & ENABLE_PROCESSED_OUTPUT)
2028 for (i = 0; i < nNumberOfCharsToWrite; i++)
2032 case '\b': case '\t': case '\n': case '\a': case '\r':
2033 /* don't handle here the i-th char... done below */
2034 if ((k = i - first) > 0)
2036 if (!write_block(hConsoleOutput, &csbi, mode, &psz[first], k))
2046 if (csbi.dwCursorPosition.X > 0) csbi.dwCursorPosition.X--;
2050 WCHAR tmp[8] = {' ',' ',' ',' ',' ',' ',' ',' '};
2052 if (!write_block(hConsoleOutput, &csbi, mode, tmp,
2053 ((csbi.dwCursorPosition.X + 8) & ~7) - csbi.dwCursorPosition.X))
2058 next_line(hConsoleOutput, &csbi);
2064 csbi.dwCursorPosition.X = 0;
2072 /* write the remaining block (if any) if processed output is enabled, or the
2073 * entire buffer otherwise
2075 if ((k = nNumberOfCharsToWrite - first) > 0)
2077 if (!write_block(hConsoleOutput, &csbi, mode, &psz[first], k))
2083 SetConsoleCursorPosition(hConsoleOutput, csbi.dwCursorPosition);
2084 if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = nw;
2089 /***********************************************************************
2090 * WriteConsoleA (KERNEL32.@)
2092 BOOL WINAPI WriteConsoleA(HANDLE hConsoleOutput, LPCVOID lpBuffer, DWORD nNumberOfCharsToWrite,
2093 LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
2099 n = MultiByteToWideChar(GetConsoleOutputCP(), 0, lpBuffer, nNumberOfCharsToWrite, NULL, 0);
2101 if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = 0;
2102 xstring = HeapAlloc(GetProcessHeap(), 0, n * sizeof(WCHAR));
2103 if (!xstring) return 0;
2105 MultiByteToWideChar(GetConsoleOutputCP(), 0, lpBuffer, nNumberOfCharsToWrite, xstring, n);
2107 ret = WriteConsoleW(hConsoleOutput, xstring, n, lpNumberOfCharsWritten, 0);
2109 HeapFree(GetProcessHeap(), 0, xstring);
2114 /******************************************************************************
2115 * SetConsoleCursorPosition [KERNEL32.@]
2116 * Sets the cursor position in console
2119 * hConsoleOutput [I] Handle of console screen buffer
2120 * dwCursorPosition [I] New cursor position coordinates
2126 BOOL WINAPI SetConsoleCursorPosition(HANDLE hcon, COORD pos)
2129 CONSOLE_SCREEN_BUFFER_INFO csbi;
2133 TRACE("%p %d %d\n", hcon, pos.X, pos.Y);
2135 SERVER_START_REQ(set_console_output_info)
2137 req->handle = console_handle_unmap(hcon);
2138 req->cursor_x = pos.X;
2139 req->cursor_y = pos.Y;
2140 req->mask = SET_CONSOLE_OUTPUT_INFO_CURSOR_POS;
2141 ret = !wine_server_call_err( req );
2145 if (!ret || !GetConsoleScreenBufferInfo(hcon, &csbi))
2148 /* if cursor is no longer visible, scroll the visible window... */
2149 w = csbi.srWindow.Right - csbi.srWindow.Left + 1;
2150 h = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
2151 if (pos.X < csbi.srWindow.Left)
2153 csbi.srWindow.Left = min(pos.X, csbi.dwSize.X - w);
2156 else if (pos.X > csbi.srWindow.Right)
2158 csbi.srWindow.Left = max(pos.X, w) - w + 1;
2161 csbi.srWindow.Right = csbi.srWindow.Left + w - 1;
2163 if (pos.Y < csbi.srWindow.Top)
2165 csbi.srWindow.Top = min(pos.Y, csbi.dwSize.Y - h);
2168 else if (pos.Y > csbi.srWindow.Bottom)
2170 csbi.srWindow.Top = max(pos.Y, h) - h + 1;
2173 csbi.srWindow.Bottom = csbi.srWindow.Top + h - 1;
2175 ret = (do_move) ? SetConsoleWindowInfo(hcon, TRUE, &csbi.srWindow) : TRUE;
2180 /******************************************************************************
2181 * GetConsoleCursorInfo [KERNEL32.@] Gets size and visibility of console
2184 * hcon [I] Handle to console screen buffer
2185 * cinfo [O] Address of cursor information
2191 BOOL WINAPI GetConsoleCursorInfo(HANDLE hCon, LPCONSOLE_CURSOR_INFO cinfo)
2195 SERVER_START_REQ(get_console_output_info)
2197 req->handle = console_handle_unmap(hCon);
2198 ret = !wine_server_call_err( req );
2201 cinfo->dwSize = reply->cursor_size;
2202 cinfo->bVisible = reply->cursor_visible;
2207 TRACE("(%p) returning (%d,%d)\n", hCon, cinfo->dwSize, cinfo->bVisible);
2212 /******************************************************************************
2213 * SetConsoleCursorInfo [KERNEL32.@] Sets size and visibility of cursor
2216 * hcon [I] Handle to console screen buffer
2217 * cinfo [I] Address of cursor information
2222 BOOL WINAPI SetConsoleCursorInfo(HANDLE hCon, LPCONSOLE_CURSOR_INFO cinfo)
2226 TRACE("(%p,%d,%d)\n", hCon, cinfo->dwSize, cinfo->bVisible);
2227 SERVER_START_REQ(set_console_output_info)
2229 req->handle = console_handle_unmap(hCon);
2230 req->cursor_size = cinfo->dwSize;
2231 req->cursor_visible = cinfo->bVisible;
2232 req->mask = SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM;
2233 ret = !wine_server_call_err( req );
2240 /******************************************************************************
2241 * SetConsoleWindowInfo [KERNEL32.@] Sets size and position of console
2244 * hcon [I] Handle to console screen buffer
2245 * bAbsolute [I] Coordinate type flag
2246 * window [I] Address of new window rectangle
2251 BOOL WINAPI SetConsoleWindowInfo(HANDLE hCon, BOOL bAbsolute, LPSMALL_RECT window)
2253 SMALL_RECT p = *window;
2256 TRACE("(%p,%d,(%d,%d-%d,%d))\n", hCon, bAbsolute, p.Left, p.Top, p.Right, p.Bottom);
2260 CONSOLE_SCREEN_BUFFER_INFO csbi;
2262 if (!GetConsoleScreenBufferInfo(hCon, &csbi))
2264 p.Left += csbi.srWindow.Left;
2265 p.Top += csbi.srWindow.Top;
2266 p.Right += csbi.srWindow.Right;
2267 p.Bottom += csbi.srWindow.Bottom;
2269 SERVER_START_REQ(set_console_output_info)
2271 req->handle = console_handle_unmap(hCon);
2272 req->win_left = p.Left;
2273 req->win_top = p.Top;
2274 req->win_right = p.Right;
2275 req->win_bottom = p.Bottom;
2276 req->mask = SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW;
2277 ret = !wine_server_call_err( req );
2285 /******************************************************************************
2286 * SetConsoleTextAttribute [KERNEL32.@] Sets colors for text
2288 * Sets the foreground and background color attributes of characters
2289 * written to the screen buffer.
2295 BOOL WINAPI SetConsoleTextAttribute(HANDLE hConsoleOutput, WORD wAttr)
2299 TRACE("(%p,%d)\n", hConsoleOutput, wAttr);
2300 SERVER_START_REQ(set_console_output_info)
2302 req->handle = console_handle_unmap(hConsoleOutput);
2304 req->mask = SET_CONSOLE_OUTPUT_INFO_ATTR;
2305 ret = !wine_server_call_err( req );
2312 /******************************************************************************
2313 * SetConsoleScreenBufferSize [KERNEL32.@] Changes size of console
2316 * hConsoleOutput [I] Handle to console screen buffer
2317 * dwSize [I] New size in character rows and cols
2323 BOOL WINAPI SetConsoleScreenBufferSize(HANDLE hConsoleOutput, COORD dwSize)
2327 TRACE("(%p,(%d,%d))\n", hConsoleOutput, dwSize.X, dwSize.Y);
2328 SERVER_START_REQ(set_console_output_info)
2330 req->handle = console_handle_unmap(hConsoleOutput);
2331 req->width = dwSize.X;
2332 req->height = dwSize.Y;
2333 req->mask = SET_CONSOLE_OUTPUT_INFO_SIZE;
2334 ret = !wine_server_call_err( req );
2341 /******************************************************************************
2342 * ScrollConsoleScreenBufferA [KERNEL32.@]
2345 BOOL WINAPI ScrollConsoleScreenBufferA(HANDLE hConsoleOutput, LPSMALL_RECT lpScrollRect,
2346 LPSMALL_RECT lpClipRect, COORD dwDestOrigin,
2351 ciw.Attributes = lpFill->Attributes;
2352 MultiByteToWideChar(GetConsoleOutputCP(), 0, &lpFill->Char.AsciiChar, 1, &ciw.Char.UnicodeChar, 1);
2354 return ScrollConsoleScreenBufferW(hConsoleOutput, lpScrollRect, lpClipRect,
2355 dwDestOrigin, &ciw);
2358 /******************************************************************
2359 * CONSOLE_FillLineUniform
2361 * Helper function for ScrollConsoleScreenBufferW
2362 * Fills a part of a line with a constant character info
2364 void CONSOLE_FillLineUniform(HANDLE hConsoleOutput, int i, int j, int len, LPCHAR_INFO lpFill)
2366 SERVER_START_REQ( fill_console_output )
2368 req->handle = console_handle_unmap(hConsoleOutput);
2369 req->mode = CHAR_INFO_MODE_TEXTATTR;
2374 req->data.ch = lpFill->Char.UnicodeChar;
2375 req->data.attr = lpFill->Attributes;
2376 wine_server_call_err( req );
2381 /******************************************************************************
2382 * ScrollConsoleScreenBufferW [KERNEL32.@]
2386 BOOL WINAPI ScrollConsoleScreenBufferW(HANDLE hConsoleOutput, LPSMALL_RECT lpScrollRect,
2387 LPSMALL_RECT lpClipRect, COORD dwDestOrigin,
2395 CONSOLE_SCREEN_BUFFER_INFO csbi;
2400 TRACE("(%p,(%d,%d-%d,%d),(%d,%d-%d,%d),%d-%d,%p)\n", hConsoleOutput,
2401 lpScrollRect->Left, lpScrollRect->Top,
2402 lpScrollRect->Right, lpScrollRect->Bottom,
2403 lpClipRect->Left, lpClipRect->Top,
2404 lpClipRect->Right, lpClipRect->Bottom,
2405 dwDestOrigin.X, dwDestOrigin.Y, lpFill);
2407 TRACE("(%p,(%d,%d-%d,%d),(nil),%d-%d,%p)\n", hConsoleOutput,
2408 lpScrollRect->Left, lpScrollRect->Top,
2409 lpScrollRect->Right, lpScrollRect->Bottom,
2410 dwDestOrigin.X, dwDestOrigin.Y, lpFill);
2412 if (!GetConsoleScreenBufferInfo(hConsoleOutput, &csbi))
2415 src.X = lpScrollRect->Left;
2416 src.Y = lpScrollRect->Top;
2418 /* step 1: get dst rect */
2419 dst.Left = dwDestOrigin.X;
2420 dst.Top = dwDestOrigin.Y;
2421 dst.Right = dst.Left + (lpScrollRect->Right - lpScrollRect->Left);
2422 dst.Bottom = dst.Top + (lpScrollRect->Bottom - lpScrollRect->Top);
2424 /* step 2a: compute the final clip rect (optional passed clip and screen buffer limits */
2427 clip.Left = max(0, lpClipRect->Left);
2428 clip.Right = min(csbi.dwSize.X - 1, lpClipRect->Right);
2429 clip.Top = max(0, lpClipRect->Top);
2430 clip.Bottom = min(csbi.dwSize.Y - 1, lpClipRect->Bottom);
2435 clip.Right = csbi.dwSize.X - 1;
2437 clip.Bottom = csbi.dwSize.Y - 1;
2439 if (clip.Left > clip.Right || clip.Top > clip.Bottom) return FALSE;
2441 /* step 2b: clip dst rect */
2442 if (dst.Left < clip.Left ) {src.X += clip.Left - dst.Left; dst.Left = clip.Left;}
2443 if (dst.Top < clip.Top ) {src.Y += clip.Top - dst.Top; dst.Top = clip.Top;}
2444 if (dst.Right > clip.Right ) dst.Right = clip.Right;
2445 if (dst.Bottom > clip.Bottom) dst.Bottom = clip.Bottom;
2447 /* step 3: transfer the bits */
2448 SERVER_START_REQ(move_console_output)
2450 req->handle = console_handle_unmap(hConsoleOutput);
2453 req->x_dst = dst.Left;
2454 req->y_dst = dst.Top;
2455 req->w = dst.Right - dst.Left + 1;
2456 req->h = dst.Bottom - dst.Top + 1;
2457 ret = !wine_server_call_err( req );
2461 if (!ret) return FALSE;
2463 /* step 4: clean out the exposed part */
2465 /* have to write cell [i,j] if it is not in dst rect (because it has already
2466 * been written to by the scroll) and is in clip (we shall not write
2469 for (j = max(lpScrollRect->Top, clip.Top); j <= min(lpScrollRect->Bottom, clip.Bottom); j++)
2471 inside = dst.Top <= j && j <= dst.Bottom;
2473 for (i = max(lpScrollRect->Left, clip.Left); i <= min(lpScrollRect->Right, clip.Right); i++)
2475 if (inside && dst.Left <= i && i <= dst.Right)
2479 CONSOLE_FillLineUniform(hConsoleOutput, start, j, i - start, lpFill);
2485 if (start == -1) start = i;
2489 CONSOLE_FillLineUniform(hConsoleOutput, start, j, i - start, lpFill);
2495 /******************************************************************
2496 * AttachConsole (KERNEL32.@)
2498 BOOL WINAPI AttachConsole(DWORD dwProcessId)
2500 FIXME("stub %x\n",dwProcessId);
2505 /* ====================================================================
2507 * Console manipulation functions
2509 * ====================================================================*/
2511 /* some missing functions...
2512 * FIXME: those are likely to be defined as undocumented function in kernel32 (or part of them)
2513 * should get the right API and implement them
2514 * GetConsoleCommandHistory[AW] (dword dword dword)
2515 * GetConsoleCommandHistoryLength[AW]
2516 * SetConsoleCommandHistoryMode
2517 * SetConsoleNumberOfCommands[AW]
2519 int CONSOLE_GetHistory(int idx, WCHAR* buf, int buf_len)
2523 SERVER_START_REQ( get_console_input_history )
2527 if (buf && buf_len > 1)
2529 wine_server_set_reply( req, buf, (buf_len - 1) * sizeof(WCHAR) );
2531 if (!wine_server_call_err( req ))
2533 if (buf) buf[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
2534 len = reply->total / sizeof(WCHAR) + 1;
2541 /******************************************************************
2542 * CONSOLE_AppendHistory
2546 BOOL CONSOLE_AppendHistory(const WCHAR* ptr)
2548 size_t len = strlenW(ptr);
2551 while (len && (ptr[len - 1] == '\n' || ptr[len - 1] == '\r')) len--;
2552 if (!len) return FALSE;
2554 SERVER_START_REQ( append_console_input_history )
2557 wine_server_add_data( req, ptr, len * sizeof(WCHAR) );
2558 ret = !wine_server_call_err( req );
2564 /******************************************************************
2565 * CONSOLE_GetNumHistoryEntries
2569 unsigned CONSOLE_GetNumHistoryEntries(void)
2572 SERVER_START_REQ(get_console_input_info)
2575 if (!wine_server_call_err( req )) ret = reply->history_index;
2581 /******************************************************************
2582 * CONSOLE_GetEditionMode
2586 BOOL CONSOLE_GetEditionMode(HANDLE hConIn, int* mode)
2588 unsigned ret = FALSE;
2589 SERVER_START_REQ(get_console_input_info)
2591 req->handle = console_handle_unmap(hConIn);
2592 if ((ret = !wine_server_call_err( req )))
2593 *mode = reply->edition_mode;