2 * Win32 kernel 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 UINT console_input_codepage
;
59 static UINT console_output_codepage
;
62 /* map input records to ASCII */
63 static void input_records_WtoA( INPUT_RECORD
*buffer
, int count
)
68 for (i
= 0; i
< count
; i
++)
70 if (buffer
[i
].EventType
!= KEY_EVENT
) continue;
71 WideCharToMultiByte( GetConsoleCP(), 0,
72 &buffer
[i
].Event
.KeyEvent
.uChar
.UnicodeChar
, 1, &ch
, 1, NULL
, NULL
);
73 buffer
[i
].Event
.KeyEvent
.uChar
.AsciiChar
= ch
;
77 /* map input records to Unicode */
78 static void input_records_AtoW( INPUT_RECORD
*buffer
, int count
)
83 for (i
= 0; i
< count
; i
++)
85 if (buffer
[i
].EventType
!= KEY_EVENT
) continue;
86 MultiByteToWideChar( GetConsoleCP(), 0,
87 &buffer
[i
].Event
.KeyEvent
.uChar
.AsciiChar
, 1, &ch
, 1 );
88 buffer
[i
].Event
.KeyEvent
.uChar
.UnicodeChar
= ch
;
92 /* map char infos to ASCII */
93 static void char_info_WtoA( CHAR_INFO
*buffer
, int count
)
99 WideCharToMultiByte( GetConsoleOutputCP(), 0, &buffer
->Char
.UnicodeChar
, 1,
100 &ch
, 1, NULL
, NULL
);
101 buffer
->Char
.AsciiChar
= ch
;
106 /* map char infos to Unicode */
107 static void char_info_AtoW( CHAR_INFO
*buffer
, int count
)
113 MultiByteToWideChar( GetConsoleOutputCP(), 0, &buffer
->Char
.AsciiChar
, 1, &ch
, 1 );
114 buffer
->Char
.UnicodeChar
= ch
;
120 /******************************************************************************
121 * GetConsoleWindow [KERNEL32.@]
123 HWND WINAPI
GetConsoleWindow(VOID
)
130 /******************************************************************************
131 * GetConsoleCP [KERNEL32.@] Returns the OEM code page for the console
136 UINT WINAPI
GetConsoleCP(VOID
)
138 if (!console_input_codepage
)
140 console_input_codepage
= GetOEMCP();
141 TRACE("%u\n", console_input_codepage
);
143 return console_input_codepage
;
147 /******************************************************************************
148 * SetConsoleCP [KERNEL32.@]
150 BOOL WINAPI
SetConsoleCP(UINT cp
)
152 if (!IsValidCodePage( cp
)) return FALSE
;
153 console_input_codepage
= cp
;
158 /***********************************************************************
159 * GetConsoleOutputCP (KERNEL32.@)
161 UINT WINAPI
GetConsoleOutputCP(VOID
)
163 if (!console_output_codepage
)
165 console_output_codepage
= GetOEMCP();
166 TRACE("%u\n", console_output_codepage
);
168 return console_output_codepage
;
172 /******************************************************************************
173 * SetConsoleOutputCP [KERNEL32.@] Set the output codepage used by the console
176 * cp [I] code page to set
182 BOOL WINAPI
SetConsoleOutputCP(UINT cp
)
184 if (!IsValidCodePage( cp
)) return FALSE
;
185 console_output_codepage
= cp
;
190 /***********************************************************************
193 BOOL WINAPI
Beep( DWORD dwFreq
, DWORD dwDur
)
195 static const char beep
= '\a';
196 /* dwFreq and dwDur are ignored by Win95 */
197 if (isatty(2)) write( 2, &beep
, 1 );
202 /******************************************************************
203 * OpenConsoleW (KERNEL32.@)
206 * Open a handle to the current process console.
207 * Returns INVALID_HANDLE_VALUE on failure.
209 HANDLE WINAPI
OpenConsoleW(LPCWSTR name
, DWORD access
, BOOL inherit
, DWORD creation
)
211 static const WCHAR coninW
[] = {'C','O','N','I','N','$',0};
212 static const WCHAR conoutW
[] = {'C','O','N','O','U','T','$',0};
216 if (strcmpiW(coninW
, name
) == 0)
218 else if (strcmpiW(conoutW
, name
) == 0)
222 SetLastError(ERROR_INVALID_NAME
);
223 return INVALID_HANDLE_VALUE
;
225 if (creation
!= OPEN_EXISTING
)
227 SetLastError(ERROR_INVALID_PARAMETER
);
228 return INVALID_HANDLE_VALUE
;
231 SERVER_START_REQ( open_console
)
234 req
->access
= access
;
235 req
->share
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
236 req
->inherit
= inherit
;
238 wine_server_call_err( req
);
242 return ret
? console_handle_map(ret
) : INVALID_HANDLE_VALUE
;
245 /******************************************************************
246 * VerifyConsoleIoHandle (KERNEL32.@)
250 BOOL WINAPI
VerifyConsoleIoHandle(HANDLE handle
)
254 if (!is_console_handle(handle
)) return FALSE
;
255 SERVER_START_REQ(get_console_mode
)
257 req
->handle
= console_handle_unmap(handle
);
258 ret
= !wine_server_call_err( req
);
264 /******************************************************************
265 * DuplicateConsoleHandle (KERNEL32.@)
269 HANDLE WINAPI
DuplicateConsoleHandle(HANDLE handle
, DWORD access
, BOOL inherit
,
274 if (!is_console_handle(handle
) ||
275 !DuplicateHandle(GetCurrentProcess(), console_handle_unmap(handle
),
276 GetCurrentProcess(), &ret
, access
, inherit
, options
))
277 return INVALID_HANDLE_VALUE
;
278 return console_handle_map(ret
);
281 /******************************************************************
282 * CloseConsoleHandle (KERNEL32.@)
286 BOOL WINAPI
CloseConsoleHandle(HANDLE handle
)
288 if (!is_console_handle(handle
))
290 SetLastError(ERROR_INVALID_PARAMETER
);
293 return CloseHandle(console_handle_unmap(handle
));
296 /******************************************************************
297 * GetConsoleInputWaitHandle (KERNEL32.@)
301 HANDLE WINAPI
GetConsoleInputWaitHandle(void)
303 static HANDLE console_wait_event
;
305 /* FIXME: this is not thread safe */
306 if (!console_wait_event
)
308 SERVER_START_REQ(get_console_wait_event
)
310 if (!wine_server_call_err( req
)) console_wait_event
= reply
->handle
;
314 return console_wait_event
;
318 /******************************************************************************
319 * WriteConsoleInputA [KERNEL32.@]
321 BOOL WINAPI
WriteConsoleInputA( HANDLE handle
, const INPUT_RECORD
*buffer
,
322 DWORD count
, LPDWORD written
)
327 if (!(recW
= HeapAlloc( GetProcessHeap(), 0, count
* sizeof(*recW
) ))) return FALSE
;
328 memcpy( recW
, buffer
, count
*sizeof(*recW
) );
329 input_records_AtoW( recW
, count
);
330 ret
= WriteConsoleInputW( handle
, recW
, count
, written
);
331 HeapFree( GetProcessHeap(), 0, recW
);
336 /******************************************************************************
337 * WriteConsoleInputW [KERNEL32.@]
339 BOOL WINAPI
WriteConsoleInputW( HANDLE handle
, const INPUT_RECORD
*buffer
,
340 DWORD count
, LPDWORD written
)
344 TRACE("(%p,%p,%ld,%p)\n", handle
, buffer
, count
, written
);
346 if (written
) *written
= 0;
347 SERVER_START_REQ( write_console_input
)
349 req
->handle
= console_handle_unmap(handle
);
350 wine_server_add_data( req
, buffer
, count
* sizeof(INPUT_RECORD
) );
351 if ((ret
= !wine_server_call_err( req
)) && written
)
352 *written
= reply
->written
;
360 /***********************************************************************
361 * WriteConsoleOutputA (KERNEL32.@)
363 BOOL WINAPI
WriteConsoleOutputA( HANDLE hConsoleOutput
, const CHAR_INFO
*lpBuffer
,
364 COORD size
, COORD coord
, LPSMALL_RECT region
)
368 COORD new_size
, new_coord
;
371 new_size
.X
= min( region
->Right
- region
->Left
+ 1, size
.X
- coord
.X
);
372 new_size
.Y
= min( region
->Bottom
- region
->Top
+ 1, size
.Y
- coord
.Y
);
374 if (new_size
.X
<= 0 || new_size
.Y
<= 0)
376 region
->Bottom
= region
->Top
+ new_size
.Y
- 1;
377 region
->Right
= region
->Left
+ new_size
.X
- 1;
381 /* only copy the useful rectangle */
382 if (!(ciw
= HeapAlloc( GetProcessHeap(), 0, sizeof(CHAR_INFO
) * new_size
.X
* new_size
.Y
)))
384 for (y
= 0; y
< new_size
.Y
; y
++)
386 memcpy( &ciw
[y
* new_size
.X
], &lpBuffer
[(y
+ coord
.Y
) * size
.X
+ coord
.X
],
387 new_size
.X
* sizeof(CHAR_INFO
) );
388 char_info_AtoW( ciw
, new_size
.X
);
390 new_coord
.X
= new_coord
.Y
= 0;
391 ret
= WriteConsoleOutputW( hConsoleOutput
, ciw
, new_size
, new_coord
, region
);
392 if (ciw
) HeapFree( GetProcessHeap(), 0, ciw
);
397 /***********************************************************************
398 * WriteConsoleOutputW (KERNEL32.@)
400 BOOL WINAPI
WriteConsoleOutputW( HANDLE hConsoleOutput
, const CHAR_INFO
*lpBuffer
,
401 COORD size
, COORD coord
, LPSMALL_RECT region
)
403 int width
, height
, y
;
406 TRACE("(%p,%p,(%d,%d),(%d,%d),(%d,%dx%d,%d)\n",
407 hConsoleOutput
, lpBuffer
, size
.X
, size
.Y
, coord
.X
, coord
.Y
,
408 region
->Left
, region
->Top
, region
->Right
, region
->Bottom
);
410 width
= min( region
->Right
- region
->Left
+ 1, size
.X
- coord
.X
);
411 height
= min( region
->Bottom
- region
->Top
+ 1, size
.Y
- coord
.Y
);
413 if (width
> 0 && height
> 0)
415 for (y
= 0; y
< height
; y
++)
417 SERVER_START_REQ( write_console_output
)
419 req
->handle
= console_handle_unmap(hConsoleOutput
);
420 req
->x
= region
->Left
;
421 req
->y
= region
->Top
+ y
;
422 req
->mode
= CHAR_INFO_MODE_TEXTATTR
;
424 wine_server_add_data( req
, &lpBuffer
[(y
+ coord
.Y
) * size
.X
+ coord
.X
],
425 width
* sizeof(CHAR_INFO
));
426 if ((ret
= !wine_server_call_err( req
)))
428 width
= min( width
, reply
->width
- region
->Left
);
429 height
= min( height
, reply
->height
- region
->Top
);
436 region
->Bottom
= region
->Top
+ height
- 1;
437 region
->Right
= region
->Left
+ width
- 1;
442 /******************************************************************************
443 * WriteConsoleOutputCharacterA [KERNEL32.@] Copies character to consecutive
444 * cells in the console screen buffer
447 * hConsoleOutput [I] Handle to screen buffer
448 * str [I] Pointer to buffer with chars to write
449 * length [I] Number of cells to write to
450 * coord [I] Coords of first cell
451 * lpNumCharsWritten [O] Pointer to number of cells written
453 BOOL WINAPI
WriteConsoleOutputCharacterA( HANDLE hConsoleOutput
, LPCSTR str
, DWORD length
,
454 COORD coord
, LPDWORD lpNumCharsWritten
)
460 TRACE("(%p,%s,%ld,%dx%d,%p)\n", hConsoleOutput
,
461 debugstr_an(str
, length
), length
, coord
.X
, coord
.Y
, lpNumCharsWritten
);
463 lenW
= MultiByteToWideChar( GetConsoleOutputCP(), 0, str
, length
, NULL
, 0 );
465 if (lpNumCharsWritten
) *lpNumCharsWritten
= 0;
467 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) ))) return FALSE
;
468 MultiByteToWideChar( GetConsoleOutputCP(), 0, str
, length
, strW
, lenW
);
470 ret
= WriteConsoleOutputCharacterW( hConsoleOutput
, strW
, lenW
, coord
, lpNumCharsWritten
);
471 HeapFree( GetProcessHeap(), 0, strW
);
476 /******************************************************************************
477 * WriteConsoleOutputAttribute [KERNEL32.@] Sets attributes for some cells in
478 * the console screen buffer
481 * hConsoleOutput [I] Handle to screen buffer
482 * attr [I] Pointer to buffer with write attributes
483 * length [I] Number of cells to write to
484 * coord [I] Coords of first cell
485 * lpNumAttrsWritten [O] Pointer to number of cells written
492 BOOL WINAPI
WriteConsoleOutputAttribute( HANDLE hConsoleOutput
, CONST WORD
*attr
, DWORD length
,
493 COORD coord
, LPDWORD lpNumAttrsWritten
)
497 TRACE("(%p,%p,%ld,%dx%d,%p)\n", hConsoleOutput
,attr
,length
,coord
.X
,coord
.Y
,lpNumAttrsWritten
);
499 SERVER_START_REQ( write_console_output
)
501 req
->handle
= console_handle_unmap(hConsoleOutput
);
504 req
->mode
= CHAR_INFO_MODE_ATTR
;
506 wine_server_add_data( req
, attr
, length
* sizeof(WORD
) );
507 if ((ret
= !wine_server_call_err( req
)))
509 if (lpNumAttrsWritten
) *lpNumAttrsWritten
= reply
->written
;
517 /******************************************************************************
518 * FillConsoleOutputCharacterA [KERNEL32.@]
521 * hConsoleOutput [I] Handle to screen buffer
522 * ch [I] Character to write
523 * length [I] Number of cells to write to
524 * coord [I] Coords of first cell
525 * lpNumCharsWritten [O] Pointer to number of cells written
531 BOOL WINAPI
FillConsoleOutputCharacterA( HANDLE hConsoleOutput
, CHAR ch
, DWORD length
,
532 COORD coord
, LPDWORD lpNumCharsWritten
)
536 MultiByteToWideChar( GetConsoleOutputCP(), 0, &ch
, 1, &wch
, 1 );
537 return FillConsoleOutputCharacterW(hConsoleOutput
, wch
, length
, coord
, lpNumCharsWritten
);
541 /******************************************************************************
542 * FillConsoleOutputCharacterW [KERNEL32.@] Writes characters to console
545 * hConsoleOutput [I] Handle to screen buffer
546 * ch [I] Character to write
547 * length [I] Number of cells to write to
548 * coord [I] Coords of first cell
549 * lpNumCharsWritten [O] Pointer to number of cells written
555 BOOL WINAPI
FillConsoleOutputCharacterW( HANDLE hConsoleOutput
, WCHAR ch
, DWORD length
,
556 COORD coord
, LPDWORD lpNumCharsWritten
)
560 TRACE("(%p,%s,%ld,(%dx%d),%p)\n",
561 hConsoleOutput
, debugstr_wn(&ch
, 1), length
, coord
.X
, coord
.Y
, lpNumCharsWritten
);
563 SERVER_START_REQ( fill_console_output
)
565 req
->handle
= console_handle_unmap(hConsoleOutput
);
568 req
->mode
= CHAR_INFO_MODE_TEXT
;
572 if ((ret
= !wine_server_call_err( req
)))
574 if (lpNumCharsWritten
) *lpNumCharsWritten
= reply
->written
;
582 /******************************************************************************
583 * FillConsoleOutputAttribute [KERNEL32.@] Sets attributes for console
586 * hConsoleOutput [I] Handle to screen buffer
587 * attr [I] Color attribute to write
588 * length [I] Number of cells to write to
589 * coord [I] Coords of first cell
590 * lpNumAttrsWritten [O] Pointer to number of cells written
596 BOOL WINAPI
FillConsoleOutputAttribute( HANDLE hConsoleOutput
, WORD attr
, DWORD length
,
597 COORD coord
, LPDWORD lpNumAttrsWritten
)
601 TRACE("(%p,%d,%ld,(%dx%d),%p)\n",
602 hConsoleOutput
, attr
, length
, coord
.X
, coord
.Y
, lpNumAttrsWritten
);
604 SERVER_START_REQ( fill_console_output
)
606 req
->handle
= console_handle_unmap(hConsoleOutput
);
609 req
->mode
= CHAR_INFO_MODE_ATTR
;
611 req
->data
.attr
= attr
;
613 if ((ret
= !wine_server_call_err( req
)))
615 if (lpNumAttrsWritten
) *lpNumAttrsWritten
= reply
->written
;
623 /******************************************************************************
624 * ReadConsoleOutputCharacterA [KERNEL32.@]
627 BOOL WINAPI
ReadConsoleOutputCharacterA(HANDLE hConsoleOutput
, LPSTR lpstr
, DWORD count
,
628 COORD coord
, LPDWORD read_count
)
632 LPWSTR wptr
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
));
634 if (read_count
) *read_count
= 0;
635 if (!wptr
) return FALSE
;
637 if ((ret
= ReadConsoleOutputCharacterW( hConsoleOutput
, wptr
, count
, coord
, &read
)))
639 read
= WideCharToMultiByte( GetConsoleOutputCP(), 0, wptr
, read
, lpstr
, count
, NULL
, NULL
);
640 if (read_count
) *read_count
= read
;
642 HeapFree( GetProcessHeap(), 0, wptr
);
647 /******************************************************************************
648 * ReadConsoleOutputCharacterW [KERNEL32.@]
651 BOOL WINAPI
ReadConsoleOutputCharacterW( HANDLE hConsoleOutput
, LPWSTR buffer
, DWORD count
,
652 COORD coord
, LPDWORD read_count
)
656 TRACE( "(%p,%p,%ld,%dx%d,%p)\n", hConsoleOutput
, buffer
, count
, coord
.X
, coord
.Y
, read_count
);
658 SERVER_START_REQ( read_console_output
)
660 req
->handle
= console_handle_unmap(hConsoleOutput
);
663 req
->mode
= CHAR_INFO_MODE_TEXT
;
665 wine_server_set_reply( req
, buffer
, count
* sizeof(WCHAR
) );
666 if ((ret
= !wine_server_call_err( req
)))
668 if (read_count
) *read_count
= wine_server_reply_size(reply
) / sizeof(WCHAR
);
676 /******************************************************************************
677 * ReadConsoleOutputAttribute [KERNEL32.@]
679 BOOL WINAPI
ReadConsoleOutputAttribute(HANDLE hConsoleOutput
, LPWORD lpAttribute
, DWORD length
,
680 COORD coord
, LPDWORD read_count
)
684 TRACE("(%p,%p,%ld,%dx%d,%p)\n",
685 hConsoleOutput
, lpAttribute
, length
, coord
.X
, coord
.Y
, read_count
);
687 SERVER_START_REQ( read_console_output
)
689 req
->handle
= console_handle_unmap(hConsoleOutput
);
692 req
->mode
= CHAR_INFO_MODE_ATTR
;
694 wine_server_set_reply( req
, lpAttribute
, length
* sizeof(WORD
) );
695 if ((ret
= !wine_server_call_err( req
)))
697 if (read_count
) *read_count
= wine_server_reply_size(reply
) / sizeof(WORD
);
705 /******************************************************************************
706 * ReadConsoleOutputA [KERNEL32.@]
709 BOOL WINAPI
ReadConsoleOutputA( HANDLE hConsoleOutput
, LPCHAR_INFO lpBuffer
, COORD size
,
710 COORD coord
, LPSMALL_RECT region
)
715 ret
= ReadConsoleOutputW( hConsoleOutput
, lpBuffer
, size
, coord
, region
);
716 if (ret
&& region
->Right
>= region
->Left
)
718 for (y
= 0; y
<= region
->Bottom
- region
->Top
; y
++)
720 char_info_WtoA( &lpBuffer
[(coord
.Y
+ y
) * size
.X
+ coord
.X
],
721 region
->Right
- region
->Left
+ 1 );
728 /******************************************************************************
729 * ReadConsoleOutputW [KERNEL32.@]
731 * NOTE: The NT4 (sp5) kernel crashes on me if size is (0,0). I don't
732 * think we need to be *that* compatible. -- AJ
734 BOOL WINAPI
ReadConsoleOutputW( HANDLE hConsoleOutput
, LPCHAR_INFO lpBuffer
, COORD size
,
735 COORD coord
, LPSMALL_RECT region
)
737 int width
, height
, y
;
740 width
= min( region
->Right
- region
->Left
+ 1, size
.X
- coord
.X
);
741 height
= min( region
->Bottom
- region
->Top
+ 1, size
.Y
- coord
.Y
);
743 if (width
> 0 && height
> 0)
745 for (y
= 0; y
< height
; y
++)
747 SERVER_START_REQ( read_console_output
)
749 req
->handle
= console_handle_unmap(hConsoleOutput
);
750 req
->x
= region
->Left
;
751 req
->y
= region
->Top
+ y
;
752 req
->mode
= CHAR_INFO_MODE_TEXTATTR
;
754 wine_server_set_reply( req
, &lpBuffer
[(y
+coord
.Y
) * size
.X
+ coord
.X
],
755 width
* sizeof(CHAR_INFO
) );
756 if ((ret
= !wine_server_call_err( req
)))
758 width
= min( width
, reply
->width
- region
->Left
);
759 height
= min( height
, reply
->height
- region
->Top
);
766 region
->Bottom
= region
->Top
+ height
- 1;
767 region
->Right
= region
->Left
+ width
- 1;
772 /******************************************************************************
773 * ReadConsoleInputA [KERNEL32.@] Reads data from a console
776 * handle [I] Handle to console input buffer
777 * buffer [O] Address of buffer for read data
778 * count [I] Number of records to read
779 * pRead [O] Address of number of records read
785 BOOL WINAPI
ReadConsoleInputA( HANDLE handle
, LPINPUT_RECORD buffer
, DWORD count
, LPDWORD pRead
)
789 if (!ReadConsoleInputW( handle
, buffer
, count
, &read
)) return FALSE
;
790 input_records_WtoA( buffer
, read
);
791 if (pRead
) *pRead
= read
;
796 /***********************************************************************
797 * PeekConsoleInputA (KERNEL32.@)
799 * Gets 'count' first events (or less) from input queue.
801 BOOL WINAPI
PeekConsoleInputA( HANDLE handle
, LPINPUT_RECORD buffer
, DWORD count
, LPDWORD pRead
)
805 if (!PeekConsoleInputW( handle
, buffer
, count
, &read
)) return FALSE
;
806 input_records_WtoA( buffer
, read
);
807 if (pRead
) *pRead
= read
;
812 /***********************************************************************
813 * PeekConsoleInputW (KERNEL32.@)
815 BOOL WINAPI
PeekConsoleInputW( HANDLE handle
, LPINPUT_RECORD buffer
, DWORD count
, LPDWORD read
)
818 SERVER_START_REQ( read_console_input
)
820 req
->handle
= console_handle_unmap(handle
);
822 wine_server_set_reply( req
, buffer
, count
* sizeof(INPUT_RECORD
) );
823 if ((ret
= !wine_server_call_err( req
)))
825 if (read
) *read
= count
? reply
->read
: 0;
833 /***********************************************************************
834 * GetNumberOfConsoleInputEvents (KERNEL32.@)
836 BOOL WINAPI
GetNumberOfConsoleInputEvents( HANDLE handle
, LPDWORD nrofevents
)
839 SERVER_START_REQ( read_console_input
)
841 req
->handle
= console_handle_unmap(handle
);
843 if ((ret
= !wine_server_call_err( req
)))
845 if (nrofevents
) *nrofevents
= reply
->read
;
853 /******************************************************************************
856 * Helper function for ReadConsole, ReadConsoleInput and FlushConsoleInputBuffer
859 * 0 for error, 1 for no INPUT_RECORD ready, 2 with INPUT_RECORD ready
861 enum read_console_input_return
{rci_error
= 0, rci_timeout
= 1, rci_gotone
= 2};
862 static enum read_console_input_return
read_console_input(HANDLE handle
, LPINPUT_RECORD ir
, DWORD timeout
)
864 enum read_console_input_return ret
;
866 if (WaitForSingleObject(GetConsoleInputWaitHandle(), timeout
) != WAIT_OBJECT_0
)
868 SERVER_START_REQ( read_console_input
)
870 req
->handle
= console_handle_unmap(handle
);
872 wine_server_set_reply( req
, ir
, sizeof(INPUT_RECORD
) );
873 if (wine_server_call_err( req
) || !reply
->read
) ret
= rci_error
;
874 else ret
= rci_gotone
;
882 /***********************************************************************
883 * FlushConsoleInputBuffer (KERNEL32.@)
885 BOOL WINAPI
FlushConsoleInputBuffer( HANDLE handle
)
887 enum read_console_input_return last
;
890 while ((last
= read_console_input(handle
, &ir
, 0)) == rci_gotone
);
892 return last
== rci_timeout
;
896 /***********************************************************************
897 * SetConsoleTitleA (KERNEL32.@)
899 BOOL WINAPI
SetConsoleTitleA( LPCSTR title
)
904 DWORD len
= MultiByteToWideChar( GetConsoleOutputCP(), 0, title
, -1, NULL
, 0 );
905 if (!(titleW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
)))) return FALSE
;
906 MultiByteToWideChar( GetConsoleOutputCP(), 0, title
, -1, titleW
, len
);
907 ret
= SetConsoleTitleW(titleW
);
908 HeapFree(GetProcessHeap(), 0, titleW
);
913 /***********************************************************************
914 * GetConsoleTitleA (KERNEL32.@)
916 DWORD WINAPI
GetConsoleTitleA(LPSTR title
, DWORD size
)
918 WCHAR
*ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * size
);
922 ret
= GetConsoleTitleW( ptr
, size
);
925 WideCharToMultiByte( GetConsoleOutputCP(), 0, ptr
, ret
+ 1, title
, size
, NULL
, NULL
);
928 HeapFree(GetProcessHeap(), 0, ptr
);
933 /******************************************************************************
934 * GetConsoleTitleW [KERNEL32.@] Retrieves title string for console
937 * title [O] Address of buffer for title
938 * size [I] Size of buffer
941 * Success: Length of string copied
944 DWORD WINAPI
GetConsoleTitleW(LPWSTR title
, DWORD size
)
948 SERVER_START_REQ( get_console_input_info
)
951 wine_server_set_reply( req
, title
, (size
-1) * sizeof(WCHAR
) );
952 if (!wine_server_call_err( req
))
954 ret
= wine_server_reply_size(reply
) / sizeof(WCHAR
);
963 /***********************************************************************
964 * GetLargestConsoleWindowSize (KERNEL32.@)
967 * This should return a COORD, but calling convention for returning
968 * structures is different between Windows and gcc on i386.
973 #undef GetLargestConsoleWindowSize
974 DWORD WINAPI
GetLargestConsoleWindowSize(HANDLE hConsoleOutput
)
982 TRACE("(%p), returning %dx%d (%lx)\n", hConsoleOutput
, x
.c
.X
, x
.c
.Y
, x
.w
);
985 #endif /* defined(__i386__) */
988 /***********************************************************************
989 * GetLargestConsoleWindowSize (KERNEL32.@)
992 * This should return a COORD, but calling convention for returning
993 * structures is different between Windows and gcc on i386.
998 COORD WINAPI
GetLargestConsoleWindowSize(HANDLE hConsoleOutput
)
1003 TRACE("(%p), returning %dx%d\n", hConsoleOutput
, c
.X
, x
.Y
);
1006 #endif /* defined(__i386__) */
1008 static WCHAR
* S_EditString
/* = NULL */;
1009 static unsigned S_EditStrPos
/* = 0 */;
1011 /***********************************************************************
1012 * FreeConsole (KERNEL32.@)
1014 BOOL WINAPI
FreeConsole(VOID
)
1018 SERVER_START_REQ(free_console
)
1020 ret
= !wine_server_call_err( req
);
1026 /******************************************************************
1027 * start_console_renderer
1029 * helper for AllocConsole
1030 * starts the renderer process
1032 static BOOL
start_console_renderer_helper(const char* appname
, STARTUPINFOA
* si
,
1037 PROCESS_INFORMATION pi
;
1039 /* FIXME: use dynamic allocation for most of the buffers below */
1040 ret
= snprintf(buffer
, sizeof(buffer
), "%s --use-event=%d", appname
, (INT
)hEvent
);
1041 if ((ret
> -1) && (ret
< sizeof(buffer
)) &&
1042 CreateProcessA(NULL
, buffer
, NULL
, NULL
, TRUE
, DETACHED_PROCESS
,
1043 NULL
, NULL
, si
, &pi
))
1045 if (WaitForSingleObject(hEvent
, INFINITE
) != WAIT_OBJECT_0
) return FALSE
;
1047 TRACE("Started wineconsole pid=%08lx tid=%08lx\n",
1048 pi
.dwProcessId
, pi
.dwThreadId
);
1055 static BOOL
start_console_renderer(STARTUPINFOA
* si
)
1059 OBJECT_ATTRIBUTES attr
;
1062 attr
.Length
= sizeof(attr
);
1063 attr
.RootDirectory
= 0;
1064 attr
.Attributes
= OBJ_INHERIT
;
1065 attr
.ObjectName
= NULL
;
1066 attr
.SecurityDescriptor
= NULL
;
1067 attr
.SecurityQualityOfService
= NULL
;
1069 NtCreateEvent(&hEvent
, EVENT_ALL_ACCESS
, &attr
, TRUE
, FALSE
);
1070 if (!hEvent
) return FALSE
;
1072 /* first try environment variable */
1073 if ((p
= getenv("WINECONSOLE")) != NULL
)
1075 ret
= start_console_renderer_helper(p
, si
, hEvent
);
1077 ERR("Couldn't launch Wine console from WINECONSOLE env var (%s)... "
1078 "trying default access\n", p
);
1081 /* then try the regular PATH */
1083 ret
= start_console_renderer_helper("wineconsole", si
, hEvent
);
1085 CloseHandle(hEvent
);
1089 /***********************************************************************
1090 * AllocConsole (KERNEL32.@)
1092 * creates an xterm with a pty to our program
1094 BOOL WINAPI
AllocConsole(void)
1096 HANDLE handle_in
= INVALID_HANDLE_VALUE
;
1097 HANDLE handle_out
= INVALID_HANDLE_VALUE
;
1098 HANDLE handle_err
= INVALID_HANDLE_VALUE
;
1099 STARTUPINFOA siCurrent
;
1100 STARTUPINFOA siConsole
;
1102 SECURITY_ATTRIBUTES sa
;
1106 handle_in
= CreateFileA( "CONIN$", GENERIC_READ
|GENERIC_WRITE
|SYNCHRONIZE
,
1107 0, NULL
, OPEN_EXISTING
, 0, 0 );
1109 if (handle_in
!= INVALID_HANDLE_VALUE
)
1111 /* we already have a console opened on this process, don't create a new one */
1112 CloseHandle(handle_in
);
1116 GetStartupInfoA(&siCurrent
);
1118 memset(&siConsole
, 0, sizeof(siConsole
));
1119 siConsole
.cb
= sizeof(siConsole
);
1120 /* setup a view arguments for wineconsole (it'll use them as default values) */
1121 if (siCurrent
.dwFlags
& STARTF_USECOUNTCHARS
)
1123 siConsole
.dwFlags
|= STARTF_USECOUNTCHARS
;
1124 siConsole
.dwXCountChars
= siCurrent
.dwXCountChars
;
1125 siConsole
.dwYCountChars
= siCurrent
.dwYCountChars
;
1127 if (siCurrent
.dwFlags
& STARTF_USEFILLATTRIBUTE
)
1129 siConsole
.dwFlags
|= STARTF_USEFILLATTRIBUTE
;
1130 siConsole
.dwFillAttribute
= siCurrent
.dwFillAttribute
;
1132 /* FIXME (should pass the unicode form) */
1133 if (siCurrent
.lpTitle
)
1134 siConsole
.lpTitle
= siCurrent
.lpTitle
;
1135 else if (GetModuleFileNameA(0, buffer
, sizeof(buffer
)))
1136 siConsole
.lpTitle
= buffer
;
1138 if (!start_console_renderer(&siConsole
))
1141 /* all std I/O handles are inheritable by default */
1142 sa
.nLength
= sizeof(sa
);
1143 sa
.lpSecurityDescriptor
= NULL
;
1144 sa
.bInheritHandle
= TRUE
;
1146 handle_in
= CreateFileA( "CONIN$", GENERIC_READ
|GENERIC_WRITE
|SYNCHRONIZE
,
1147 0, &sa
, OPEN_EXISTING
, 0, 0 );
1148 if (handle_in
== INVALID_HANDLE_VALUE
) goto the_end
;
1150 handle_out
= CreateFileA( "CONOUT$", GENERIC_READ
|GENERIC_WRITE
,
1151 0, &sa
, OPEN_EXISTING
, 0, 0 );
1152 if (handle_out
== INVALID_HANDLE_VALUE
) goto the_end
;
1154 if (!DuplicateHandle(GetCurrentProcess(), handle_out
, GetCurrentProcess(), &handle_err
,
1155 0, TRUE
, DUPLICATE_SAME_ACCESS
))
1158 /* NT resets the STD_*_HANDLEs on console alloc */
1159 SetStdHandle(STD_INPUT_HANDLE
, handle_in
);
1160 SetStdHandle(STD_OUTPUT_HANDLE
, handle_out
);
1161 SetStdHandle(STD_ERROR_HANDLE
, handle_err
);
1163 SetLastError(ERROR_SUCCESS
);
1168 ERR("Can't allocate console\n");
1169 if (handle_in
!= INVALID_HANDLE_VALUE
) CloseHandle(handle_in
);
1170 if (handle_out
!= INVALID_HANDLE_VALUE
) CloseHandle(handle_out
);
1171 if (handle_err
!= INVALID_HANDLE_VALUE
) CloseHandle(handle_err
);
1177 /***********************************************************************
1178 * ReadConsoleA (KERNEL32.@)
1180 BOOL WINAPI
ReadConsoleA(HANDLE hConsoleInput
, LPVOID lpBuffer
, DWORD nNumberOfCharsToRead
,
1181 LPDWORD lpNumberOfCharsRead
, LPVOID lpReserved
)
1183 LPWSTR ptr
= HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead
* sizeof(WCHAR
));
1187 if ((ret
= ReadConsoleW(hConsoleInput
, ptr
, nNumberOfCharsToRead
, &ncr
, NULL
)))
1188 ncr
= WideCharToMultiByte(CP_ACP
, 0, ptr
, ncr
, lpBuffer
, nNumberOfCharsToRead
, NULL
, NULL
);
1190 if (lpNumberOfCharsRead
) *lpNumberOfCharsRead
= ncr
;
1191 HeapFree(GetProcessHeap(), 0, ptr
);
1196 /***********************************************************************
1197 * ReadConsoleW (KERNEL32.@)
1199 BOOL WINAPI
ReadConsoleW(HANDLE hConsoleInput
, LPVOID lpBuffer
,
1200 DWORD nNumberOfCharsToRead
, LPDWORD lpNumberOfCharsRead
, LPVOID lpReserved
)
1203 LPWSTR xbuf
= (LPWSTR
)lpBuffer
;
1206 TRACE("(%p,%p,%ld,%p,%p)\n",
1207 hConsoleInput
, lpBuffer
, nNumberOfCharsToRead
, lpNumberOfCharsRead
, lpReserved
);
1209 if (!GetConsoleMode(hConsoleInput
, &mode
))
1212 if (mode
& ENABLE_LINE_INPUT
)
1214 if (!S_EditString
|| S_EditString
[S_EditStrPos
] == 0)
1216 if (S_EditString
) HeapFree(GetProcessHeap(), 0, S_EditString
);
1217 if (!(S_EditString
= CONSOLE_Readline(hConsoleInput
)))
1221 charsread
= lstrlenW(&S_EditString
[S_EditStrPos
]);
1222 if (charsread
> nNumberOfCharsToRead
) charsread
= nNumberOfCharsToRead
;
1223 memcpy(xbuf
, &S_EditString
[S_EditStrPos
], charsread
* sizeof(WCHAR
));
1224 S_EditStrPos
+= charsread
;
1229 DWORD timeout
= INFINITE
;
1231 /* FIXME: should we read at least 1 char? The SDK does not say */
1232 /* wait for at least one available input record (it doesn't mean we'll have
1233 * chars stored in xbuf...)
1238 if (read_console_input(hConsoleInput
, &ir
, timeout
) != rci_gotone
) break;
1240 if (ir
.EventType
== KEY_EVENT
&& ir
.Event
.KeyEvent
.bKeyDown
&&
1241 ir
.Event
.KeyEvent
.uChar
.UnicodeChar
&&
1242 !(ir
.Event
.KeyEvent
.dwControlKeyState
& ENHANCED_KEY
))
1244 xbuf
[charsread
++] = ir
.Event
.KeyEvent
.uChar
.UnicodeChar
;
1246 } while (charsread
< nNumberOfCharsToRead
);
1247 /* nothing has been read */
1248 if (timeout
== INFINITE
) return FALSE
;
1251 if (lpNumberOfCharsRead
) *lpNumberOfCharsRead
= charsread
;
1257 /***********************************************************************
1258 * ReadConsoleInputW (KERNEL32.@)
1260 BOOL WINAPI
ReadConsoleInputW(HANDLE hConsoleInput
, LPINPUT_RECORD lpBuffer
,
1261 DWORD nLength
, LPDWORD lpNumberOfEventsRead
)
1264 DWORD timeout
= INFINITE
;
1268 if (lpNumberOfEventsRead
) *lpNumberOfEventsRead
= 0;
1272 /* loop until we get at least one event */
1273 while (read_console_input(hConsoleInput
, &lpBuffer
[idx
], timeout
) == rci_gotone
&&
1277 if (lpNumberOfEventsRead
) *lpNumberOfEventsRead
= idx
;
1282 /******************************************************************************
1283 * WriteConsoleOutputCharacterW [KERNEL32.@] Copies character to consecutive
1284 * cells in the console screen buffer
1287 * hConsoleOutput [I] Handle to screen buffer
1288 * str [I] Pointer to buffer with chars to write
1289 * length [I] Number of cells to write to
1290 * coord [I] Coords of first cell
1291 * lpNumCharsWritten [O] Pointer to number of cells written
1298 BOOL WINAPI
WriteConsoleOutputCharacterW( HANDLE hConsoleOutput
, LPCWSTR str
, DWORD length
,
1299 COORD coord
, LPDWORD lpNumCharsWritten
)
1303 TRACE("(%p,%s,%ld,%dx%d,%p)\n", hConsoleOutput
,
1304 debugstr_wn(str
, length
), length
, coord
.X
, coord
.Y
, lpNumCharsWritten
);
1306 SERVER_START_REQ( write_console_output
)
1308 req
->handle
= console_handle_unmap(hConsoleOutput
);
1311 req
->mode
= CHAR_INFO_MODE_TEXT
;
1313 wine_server_add_data( req
, str
, length
* sizeof(WCHAR
) );
1314 if ((ret
= !wine_server_call_err( req
)))
1316 if (lpNumCharsWritten
) *lpNumCharsWritten
= reply
->written
;
1324 /******************************************************************************
1325 * SetConsoleTitleW [KERNEL32.@] Sets title bar string for console
1328 * title [I] Address of new title
1334 BOOL WINAPI
SetConsoleTitleW(LPCWSTR title
)
1338 TRACE("(%s)\n", debugstr_w(title
));
1339 SERVER_START_REQ( set_console_input_info
)
1342 req
->mask
= SET_CONSOLE_INPUT_INFO_TITLE
;
1343 wine_server_add_data( req
, title
, strlenW(title
) * sizeof(WCHAR
) );
1344 ret
= !wine_server_call_err( req
);
1351 /***********************************************************************
1352 * GetNumberOfConsoleMouseButtons (KERNEL32.@)
1354 BOOL WINAPI
GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons
)
1356 FIXME("(%p): stub\n", nrofbuttons
);
1361 /******************************************************************************
1362 * SetConsoleInputExeNameW [KERNEL32.@]
1367 BOOL WINAPI
SetConsoleInputExeNameW(LPCWSTR name
)
1369 FIXME("(%s): stub!\n", debugstr_w(name
));
1371 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1375 /******************************************************************************
1376 * SetConsoleInputExeNameA [KERNEL32.@]
1381 BOOL WINAPI
SetConsoleInputExeNameA(LPCSTR name
)
1383 int len
= MultiByteToWideChar(CP_ACP
, 0, name
, -1, NULL
, 0);
1384 LPWSTR xptr
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1387 if (!xptr
) return FALSE
;
1389 MultiByteToWideChar(CP_ACP
, 0, name
, -1, xptr
, len
);
1390 ret
= SetConsoleInputExeNameW(xptr
);
1391 HeapFree(GetProcessHeap(), 0, xptr
);
1396 /******************************************************************
1397 * CONSOLE_DefaultHandler
1399 * Final control event handler
1401 static BOOL WINAPI
CONSOLE_DefaultHandler(DWORD dwCtrlType
)
1403 FIXME("Terminating process %lx on event %lx\n", GetCurrentProcessId(), dwCtrlType
);
1405 /* should never go here */
1409 /******************************************************************************
1410 * SetConsoleCtrlHandler [KERNEL32.@] Adds function to calling process list
1413 * func [I] Address of handler function
1414 * add [I] Handler to add or remove
1421 * James Sutherland (JamesSutherland@gmx.de)
1422 * Added global variables console_ignore_ctrl_c and handlers[]
1423 * Does not yet do any error checking, or set LastError if failed.
1424 * This doesn't yet matter, since these handlers are not yet called...!
1427 struct ConsoleHandler
{
1428 PHANDLER_ROUTINE handler
;
1429 struct ConsoleHandler
* next
;
1432 static unsigned int CONSOLE_IgnoreCtrlC
= 0; /* FIXME: this should be inherited somehow */
1433 static struct ConsoleHandler CONSOLE_DefaultConsoleHandler
= {CONSOLE_DefaultHandler
, NULL
};
1434 static struct ConsoleHandler
* CONSOLE_Handlers
= &CONSOLE_DefaultConsoleHandler
;
1436 static CRITICAL_SECTION CONSOLE_CritSect
;
1437 static CRITICAL_SECTION_DEBUG critsect_debug
=
1439 0, 0, &CONSOLE_CritSect
,
1440 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1441 0, 0, { 0, (DWORD
)(__FILE__
": CONSOLE_CritSect") }
1443 static CRITICAL_SECTION CONSOLE_CritSect
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1445 /*****************************************************************************/
1447 BOOL WINAPI
SetConsoleCtrlHandler(PHANDLER_ROUTINE func
, BOOL add
)
1451 FIXME("(%p,%i) - no error checking or testing yet\n", func
, add
);
1455 CONSOLE_IgnoreCtrlC
= add
;
1459 struct ConsoleHandler
* ch
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct ConsoleHandler
));
1461 if (!ch
) return FALSE
;
1463 RtlEnterCriticalSection(&CONSOLE_CritSect
);
1464 ch
->next
= CONSOLE_Handlers
;
1465 CONSOLE_Handlers
= ch
;
1466 RtlLeaveCriticalSection(&CONSOLE_CritSect
);
1470 struct ConsoleHandler
** ch
;
1471 RtlEnterCriticalSection(&CONSOLE_CritSect
);
1472 for (ch
= &CONSOLE_Handlers
; *ch
; *ch
= (*ch
)->next
)
1474 if ((*ch
)->handler
== func
) break;
1478 struct ConsoleHandler
* rch
= *ch
;
1481 if (rch
== &CONSOLE_DefaultConsoleHandler
)
1483 ERR("Who's trying to remove default handler???\n");
1490 HeapFree(GetProcessHeap(), 0, rch
);
1495 WARN("Attempt to remove non-installed CtrlHandler %p\n", func
);
1498 RtlLeaveCriticalSection(&CONSOLE_CritSect
);
1503 static WINE_EXCEPTION_FILTER(CONSOLE_CtrlEventHandler
)
1505 TRACE("(%lx)\n", GetExceptionCode());
1506 return EXCEPTION_EXECUTE_HANDLER
;
1509 static DWORD WINAPI
CONSOLE_HandleCtrlCEntry(void* pmt
)
1511 struct ConsoleHandler
* ch
;
1513 RtlEnterCriticalSection(&CONSOLE_CritSect
);
1514 /* the debugger didn't continue... so, pass to ctrl handlers */
1515 for (ch
= CONSOLE_Handlers
; ch
; ch
= ch
->next
)
1517 if (ch
->handler((DWORD
)pmt
)) break;
1519 RtlLeaveCriticalSection(&CONSOLE_CritSect
);
1523 /******************************************************************
1524 * CONSOLE_HandleCtrlC
1526 * Check whether the shall manipulate CtrlC events
1528 int CONSOLE_HandleCtrlC(unsigned sig
)
1530 /* FIXME: better test whether a console is attached to this process ??? */
1531 extern unsigned CONSOLE_GetNumHistoryEntries(void);
1532 if (CONSOLE_GetNumHistoryEntries() == (unsigned)-1) return 0;
1533 if (CONSOLE_IgnoreCtrlC
) return 1;
1535 /* try to pass the exception to the debugger
1536 * if it continues, there's nothing more to do
1537 * otherwise, we need to send the ctrl-event to the handlers
1541 RaiseException( DBG_CONTROL_C
, 0, 0, NULL
);
1543 __EXCEPT(CONSOLE_CtrlEventHandler
)
1545 /* Create a separate thread to signal all the events. This would allow to
1546 * synchronize between setting the handlers and actually calling them
1548 CreateThread(NULL
, 0, CONSOLE_HandleCtrlCEntry
, (void*)CTRL_C_EVENT
, 0, NULL
);
1554 /******************************************************************************
1555 * GenerateConsoleCtrlEvent [KERNEL32.@] Simulate a CTRL-C or CTRL-BREAK
1558 * dwCtrlEvent [I] Type of event
1559 * dwProcessGroupID [I] Process group ID to send event to
1563 * Failure: False (and *should* [but doesn't] set LastError)
1565 BOOL WINAPI
GenerateConsoleCtrlEvent(DWORD dwCtrlEvent
,
1566 DWORD dwProcessGroupID
)
1570 TRACE("(%ld, %ld)\n", dwCtrlEvent
, dwProcessGroupID
);
1572 if (dwCtrlEvent
!= CTRL_C_EVENT
&& dwCtrlEvent
!= CTRL_BREAK_EVENT
)
1574 ERR("Invalid event %ld for PGID %ld\n", dwCtrlEvent
, dwProcessGroupID
);
1578 SERVER_START_REQ( send_console_signal
)
1580 req
->signal
= dwCtrlEvent
;
1581 req
->group_id
= dwProcessGroupID
;
1582 ret
= !wine_server_call_err( req
);
1590 /******************************************************************************
1591 * CreateConsoleScreenBuffer [KERNEL32.@] Creates a console screen buffer
1594 * dwDesiredAccess [I] Access flag
1595 * dwShareMode [I] Buffer share mode
1596 * sa [I] Security attributes
1597 * dwFlags [I] Type of buffer to create
1598 * lpScreenBufferData [I] Reserved
1601 * Should call SetLastError
1604 * Success: Handle to new console screen buffer
1605 * Failure: INVALID_HANDLE_VALUE
1607 HANDLE WINAPI
CreateConsoleScreenBuffer(DWORD dwDesiredAccess
, DWORD dwShareMode
,
1608 LPSECURITY_ATTRIBUTES sa
, DWORD dwFlags
,
1609 LPVOID lpScreenBufferData
)
1611 HANDLE ret
= INVALID_HANDLE_VALUE
;
1613 TRACE("(%ld,%ld,%p,%ld,%p)\n",
1614 dwDesiredAccess
, dwShareMode
, sa
, dwFlags
, lpScreenBufferData
);
1616 if (dwFlags
!= CONSOLE_TEXTMODE_BUFFER
|| lpScreenBufferData
!= NULL
)
1618 SetLastError(ERROR_INVALID_PARAMETER
);
1619 return INVALID_HANDLE_VALUE
;
1622 SERVER_START_REQ(create_console_output
)
1625 req
->access
= dwDesiredAccess
;
1626 req
->share
= dwShareMode
;
1627 req
->inherit
= (sa
&& sa
->bInheritHandle
);
1628 if (!wine_server_call_err( req
)) ret
= reply
->handle_out
;
1636 /***********************************************************************
1637 * GetConsoleScreenBufferInfo (KERNEL32.@)
1639 BOOL WINAPI
GetConsoleScreenBufferInfo(HANDLE hConsoleOutput
, LPCONSOLE_SCREEN_BUFFER_INFO csbi
)
1643 SERVER_START_REQ(get_console_output_info
)
1645 req
->handle
= console_handle_unmap(hConsoleOutput
);
1646 if ((ret
= !wine_server_call_err( req
)))
1648 csbi
->dwSize
.X
= reply
->width
;
1649 csbi
->dwSize
.Y
= reply
->height
;
1650 csbi
->dwCursorPosition
.X
= reply
->cursor_x
;
1651 csbi
->dwCursorPosition
.Y
= reply
->cursor_y
;
1652 csbi
->wAttributes
= reply
->attr
;
1653 csbi
->srWindow
.Left
= reply
->win_left
;
1654 csbi
->srWindow
.Right
= reply
->win_right
;
1655 csbi
->srWindow
.Top
= reply
->win_top
;
1656 csbi
->srWindow
.Bottom
= reply
->win_bottom
;
1657 csbi
->dwMaximumWindowSize
.X
= reply
->max_width
;
1658 csbi
->dwMaximumWindowSize
.Y
= reply
->max_height
;
1663 TRACE("(%p,(%d,%d) (%d,%d) %d (%d,%d-%d,%d) (%d,%d)\n",
1664 hConsoleOutput
, csbi
->dwSize
.X
, csbi
->dwSize
.Y
,
1665 csbi
->dwCursorPosition
.X
, csbi
->dwCursorPosition
.Y
,
1667 csbi
->srWindow
.Left
, csbi
->srWindow
.Top
, csbi
->srWindow
.Right
, csbi
->srWindow
.Bottom
,
1668 csbi
->dwMaximumWindowSize
.X
, csbi
->dwMaximumWindowSize
.Y
);
1674 /******************************************************************************
1675 * SetConsoleActiveScreenBuffer [KERNEL32.@] Sets buffer to current console
1681 BOOL WINAPI
SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput
)
1685 TRACE("(%p)\n", hConsoleOutput
);
1687 SERVER_START_REQ( set_console_input_info
)
1690 req
->mask
= SET_CONSOLE_INPUT_INFO_ACTIVE_SB
;
1691 req
->active_sb
= hConsoleOutput
;
1692 ret
= !wine_server_call_err( req
);
1699 /***********************************************************************
1700 * GetConsoleMode (KERNEL32.@)
1702 BOOL WINAPI
GetConsoleMode(HANDLE hcon
, LPDWORD mode
)
1706 SERVER_START_REQ(get_console_mode
)
1708 req
->handle
= console_handle_unmap(hcon
);
1709 ret
= !wine_server_call_err( req
);
1710 if (ret
&& mode
) *mode
= reply
->mode
;
1717 /******************************************************************************
1718 * SetConsoleMode [KERNEL32.@] Sets input mode of console's input buffer
1721 * hcon [I] Handle to console input or screen buffer
1722 * mode [I] Input or output mode to set
1729 * ENABLE_PROCESSED_INPUT 0x01
1730 * ENABLE_LINE_INPUT 0x02
1731 * ENABLE_ECHO_INPUT 0x04
1732 * ENABLE_WINDOW_INPUT 0x08
1733 * ENABLE_MOUSE_INPUT 0x10
1735 BOOL WINAPI
SetConsoleMode(HANDLE hcon
, DWORD mode
)
1739 SERVER_START_REQ(set_console_mode
)
1741 req
->handle
= console_handle_unmap(hcon
);
1743 ret
= !wine_server_call_err( req
);
1746 /* FIXME: when resetting a console input to editline mode, I think we should
1747 * empty the S_EditString buffer
1750 TRACE("(%p,%lx) retval == %d\n", hcon
, mode
, ret
);
1756 /******************************************************************
1757 * CONSOLE_WriteChars
1759 * WriteConsoleOutput helper: hides server call semantics
1760 * writes a string at a given pos with standard attribute
1762 int CONSOLE_WriteChars(HANDLE hCon
, LPCWSTR lpBuffer
, int nc
, COORD
* pos
)
1768 SERVER_START_REQ( write_console_output
)
1770 req
->handle
= console_handle_unmap(hCon
);
1773 req
->mode
= CHAR_INFO_MODE_TEXTSTDATTR
;
1775 wine_server_add_data( req
, lpBuffer
, nc
* sizeof(WCHAR
) );
1776 if (!wine_server_call_err( req
)) written
= reply
->written
;
1780 if (written
> 0) pos
->X
+= written
;
1784 /******************************************************************
1787 * WriteConsoleOutput helper: handles passing to next line (+scrolling if necessary)
1790 static int next_line(HANDLE hCon
, CONSOLE_SCREEN_BUFFER_INFO
* csbi
)
1796 csbi
->dwCursorPosition
.X
= 0;
1797 csbi
->dwCursorPosition
.Y
++;
1799 if (csbi
->dwCursorPosition
.Y
< csbi
->dwSize
.Y
) return 1;
1802 src
.Bottom
= csbi
->dwSize
.Y
- 1;
1804 src
.Right
= csbi
->dwSize
.X
- 1;
1809 ci
.Attributes
= csbi
->wAttributes
;
1810 ci
.Char
.UnicodeChar
= ' ';
1812 csbi
->dwCursorPosition
.Y
--;
1813 if (!ScrollConsoleScreenBufferW(hCon
, &src
, NULL
, dst
, &ci
))
1818 /******************************************************************
1821 * WriteConsoleOutput helper: writes a block of non special characters
1822 * Block can spread on several lines, and wrapping, if needed, is
1826 static int write_block(HANDLE hCon
, CONSOLE_SCREEN_BUFFER_INFO
* csbi
,
1827 DWORD mode
, LPWSTR ptr
, int len
)
1829 int blk
; /* number of chars to write on current line */
1830 int done
; /* number of chars already written */
1832 if (len
<= 0) return 1;
1834 if (mode
& ENABLE_WRAP_AT_EOL_OUTPUT
) /* writes remaining on next line */
1836 for (done
= 0; done
< len
; done
+= blk
)
1838 blk
= min(len
- done
, csbi
->dwSize
.X
- csbi
->dwCursorPosition
.X
);
1840 if (CONSOLE_WriteChars(hCon
, ptr
+ done
, blk
, &csbi
->dwCursorPosition
) != blk
)
1842 if (csbi
->dwCursorPosition
.X
== csbi
->dwSize
.X
&& !next_line(hCon
, csbi
))
1848 int pos
= csbi
->dwCursorPosition
.X
;
1849 /* FIXME: we could reduce the number of loops
1850 * but, in most cases we wouldn't gain lots of time (it would only
1851 * happen if we're asked to overwrite more than twice the part of the line,
1854 for (blk
= done
= 0; done
< len
; done
+= blk
)
1856 blk
= min(len
- done
, csbi
->dwSize
.X
- csbi
->dwCursorPosition
.X
);
1858 csbi
->dwCursorPosition
.X
= pos
;
1859 if (CONSOLE_WriteChars(hCon
, ptr
+ done
, blk
, &csbi
->dwCursorPosition
) != blk
)
1867 /***********************************************************************
1868 * WriteConsoleW (KERNEL32.@)
1870 BOOL WINAPI
WriteConsoleW(HANDLE hConsoleOutput
, LPCVOID lpBuffer
, DWORD nNumberOfCharsToWrite
,
1871 LPDWORD lpNumberOfCharsWritten
, LPVOID lpReserved
)
1875 WCHAR
* psz
= (WCHAR
*)lpBuffer
;
1876 CONSOLE_SCREEN_BUFFER_INFO csbi
;
1879 TRACE("%p %s %ld %p %p\n",
1880 hConsoleOutput
, debugstr_wn(lpBuffer
, nNumberOfCharsToWrite
),
1881 nNumberOfCharsToWrite
, lpNumberOfCharsWritten
, lpReserved
);
1883 if (lpNumberOfCharsWritten
) *lpNumberOfCharsWritten
= 0;
1885 if (!GetConsoleMode(hConsoleOutput
, &mode
) ||
1886 !GetConsoleScreenBufferInfo(hConsoleOutput
, &csbi
))
1889 if (mode
& ENABLE_PROCESSED_OUTPUT
)
1893 for (i
= 0; i
< nNumberOfCharsToWrite
; i
++)
1897 case '\b': case '\t': case '\n': case '\a': case '\r':
1898 /* don't handle here the i-th char... done below */
1899 if ((k
= i
- first
) > 0)
1901 if (!write_block(hConsoleOutput
, &csbi
, mode
, &psz
[first
], k
))
1911 if (csbi
.dwCursorPosition
.X
> 0) csbi
.dwCursorPosition
.X
--;
1915 WCHAR tmp
[8] = {' ',' ',' ',' ',' ',' ',' ',' '};
1917 if (!write_block(hConsoleOutput
, &csbi
, mode
, tmp
,
1918 ((csbi
.dwCursorPosition
.X
+ 8) & ~7) - csbi
.dwCursorPosition
.X
))
1923 next_line(hConsoleOutput
, &csbi
);
1929 csbi
.dwCursorPosition
.X
= 0;
1937 /* write the remaining block (if any) if processed output is enabled, or the
1938 * entire buffer otherwise
1940 if ((k
= nNumberOfCharsToWrite
- first
) > 0)
1942 if (!write_block(hConsoleOutput
, &csbi
, mode
, &psz
[first
], k
))
1948 SetConsoleCursorPosition(hConsoleOutput
, csbi
.dwCursorPosition
);
1949 if (lpNumberOfCharsWritten
) *lpNumberOfCharsWritten
= nw
;
1954 /***********************************************************************
1955 * WriteConsoleA (KERNEL32.@)
1957 BOOL WINAPI
WriteConsoleA(HANDLE hConsoleOutput
, LPCVOID lpBuffer
, DWORD nNumberOfCharsToWrite
,
1958 LPDWORD lpNumberOfCharsWritten
, LPVOID lpReserved
)
1964 n
= MultiByteToWideChar(CP_ACP
, 0, lpBuffer
, nNumberOfCharsToWrite
, NULL
, 0);
1966 if (lpNumberOfCharsWritten
) *lpNumberOfCharsWritten
= 0;
1967 xstring
= HeapAlloc(GetProcessHeap(), 0, n
* sizeof(WCHAR
));
1968 if (!xstring
) return 0;
1970 MultiByteToWideChar(CP_ACP
, 0, lpBuffer
, nNumberOfCharsToWrite
, xstring
, n
);
1972 ret
= WriteConsoleW(hConsoleOutput
, xstring
, n
, lpNumberOfCharsWritten
, 0);
1974 HeapFree(GetProcessHeap(), 0, xstring
);
1979 /******************************************************************************
1980 * SetConsoleCursorPosition [KERNEL32.@]
1981 * Sets the cursor position in console
1984 * hConsoleOutput [I] Handle of console screen buffer
1985 * dwCursorPosition [I] New cursor position coordinates
1989 BOOL WINAPI
SetConsoleCursorPosition(HANDLE hcon
, COORD pos
)
1992 CONSOLE_SCREEN_BUFFER_INFO csbi
;
1996 TRACE("%p %d %d\n", hcon
, pos
.X
, pos
.Y
);
1998 SERVER_START_REQ(set_console_output_info
)
2000 req
->handle
= console_handle_unmap(hcon
);
2001 req
->cursor_x
= pos
.X
;
2002 req
->cursor_y
= pos
.Y
;
2003 req
->mask
= SET_CONSOLE_OUTPUT_INFO_CURSOR_POS
;
2004 ret
= !wine_server_call_err( req
);
2008 if (!ret
|| !GetConsoleScreenBufferInfo(hcon
, &csbi
))
2011 /* if cursor is no longer visible, scroll the visible window... */
2012 w
= csbi
.srWindow
.Right
- csbi
.srWindow
.Left
+ 1;
2013 h
= csbi
.srWindow
.Bottom
- csbi
.srWindow
.Top
+ 1;
2014 if (pos
.X
< csbi
.srWindow
.Left
)
2016 csbi
.srWindow
.Left
= min(pos
.X
, csbi
.dwSize
.X
- w
);
2019 else if (pos
.X
> csbi
.srWindow
.Right
)
2021 csbi
.srWindow
.Left
= max(pos
.X
, w
) - w
+ 1;
2024 csbi
.srWindow
.Right
= csbi
.srWindow
.Left
+ w
- 1;
2026 if (pos
.Y
< csbi
.srWindow
.Top
)
2028 csbi
.srWindow
.Top
= min(pos
.Y
, csbi
.dwSize
.Y
- h
);
2031 else if (pos
.Y
> csbi
.srWindow
.Bottom
)
2033 csbi
.srWindow
.Top
= max(pos
.Y
, h
) - h
+ 1;
2036 csbi
.srWindow
.Bottom
= csbi
.srWindow
.Top
+ h
- 1;
2038 ret
= (do_move
) ? SetConsoleWindowInfo(hcon
, TRUE
, &csbi
.srWindow
) : TRUE
;
2043 /******************************************************************************
2044 * GetConsoleCursorInfo [KERNEL32.@] Gets size and visibility of console
2047 * hcon [I] Handle to console screen buffer
2048 * cinfo [O] Address of cursor information
2054 BOOL WINAPI
GetConsoleCursorInfo(HANDLE hCon
, LPCONSOLE_CURSOR_INFO cinfo
)
2058 SERVER_START_REQ(get_console_output_info
)
2060 req
->handle
= console_handle_unmap(hCon
);
2061 ret
= !wine_server_call_err( req
);
2064 cinfo
->dwSize
= reply
->cursor_size
;
2065 cinfo
->bVisible
= reply
->cursor_visible
;
2070 TRACE("(%p) returning (%ld,%d)\n", hCon
, cinfo
->dwSize
, cinfo
->bVisible
);
2075 /******************************************************************************
2076 * SetConsoleCursorInfo [KERNEL32.@] Sets size and visibility of cursor
2079 * hcon [I] Handle to console screen buffer
2080 * cinfo [I] Address of cursor information
2085 BOOL WINAPI
SetConsoleCursorInfo(HANDLE hCon
, LPCONSOLE_CURSOR_INFO cinfo
)
2089 TRACE("(%p,%ld,%d)\n", hCon
, cinfo
->dwSize
, cinfo
->bVisible
);
2090 SERVER_START_REQ(set_console_output_info
)
2092 req
->handle
= console_handle_unmap(hCon
);
2093 req
->cursor_size
= cinfo
->dwSize
;
2094 req
->cursor_visible
= cinfo
->bVisible
;
2095 req
->mask
= SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM
;
2096 ret
= !wine_server_call_err( req
);
2103 /******************************************************************************
2104 * SetConsoleWindowInfo [KERNEL32.@] Sets size and position of console
2107 * hcon [I] Handle to console screen buffer
2108 * bAbsolute [I] Coordinate type flag
2109 * window [I] Address of new window rectangle
2114 BOOL WINAPI
SetConsoleWindowInfo(HANDLE hCon
, BOOL bAbsolute
, LPSMALL_RECT window
)
2116 SMALL_RECT p
= *window
;
2119 TRACE("(%p,%d,(%d,%d-%d,%d))\n", hCon
, bAbsolute
, p
.Left
, p
.Top
, p
.Right
, p
.Bottom
);
2123 CONSOLE_SCREEN_BUFFER_INFO csbi
;
2125 if (!GetConsoleScreenBufferInfo(hCon
, &csbi
))
2127 p
.Left
+= csbi
.srWindow
.Left
;
2128 p
.Top
+= csbi
.srWindow
.Top
;
2129 p
.Right
+= csbi
.srWindow
.Right
;
2130 p
.Bottom
+= csbi
.srWindow
.Bottom
;
2132 SERVER_START_REQ(set_console_output_info
)
2134 req
->handle
= console_handle_unmap(hCon
);
2135 req
->win_left
= p
.Left
;
2136 req
->win_top
= p
.Top
;
2137 req
->win_right
= p
.Right
;
2138 req
->win_bottom
= p
.Bottom
;
2139 req
->mask
= SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW
;
2140 ret
= !wine_server_call_err( req
);
2148 /******************************************************************************
2149 * SetConsoleTextAttribute [KERNEL32.@] Sets colors for text
2151 * Sets the foreground and background color attributes of characters
2152 * written to the screen buffer.
2158 BOOL WINAPI
SetConsoleTextAttribute(HANDLE hConsoleOutput
, WORD wAttr
)
2162 TRACE("(%p,%d)\n", hConsoleOutput
, wAttr
);
2163 SERVER_START_REQ(set_console_output_info
)
2165 req
->handle
= console_handle_unmap(hConsoleOutput
);
2167 req
->mask
= SET_CONSOLE_OUTPUT_INFO_ATTR
;
2168 ret
= !wine_server_call_err( req
);
2175 /******************************************************************************
2176 * SetConsoleScreenBufferSize [KERNEL32.@] Changes size of console
2179 * hConsoleOutput [I] Handle to console screen buffer
2180 * dwSize [I] New size in character rows and cols
2186 BOOL WINAPI
SetConsoleScreenBufferSize(HANDLE hConsoleOutput
, COORD dwSize
)
2190 TRACE("(%p,(%d,%d))\n", hConsoleOutput
, dwSize
.X
, dwSize
.Y
);
2191 SERVER_START_REQ(set_console_output_info
)
2193 req
->handle
= console_handle_unmap(hConsoleOutput
);
2194 req
->width
= dwSize
.X
;
2195 req
->height
= dwSize
.Y
;
2196 req
->mask
= SET_CONSOLE_OUTPUT_INFO_SIZE
;
2197 ret
= !wine_server_call_err( req
);
2204 /******************************************************************************
2205 * ScrollConsoleScreenBufferA [KERNEL32.@]
2208 BOOL WINAPI
ScrollConsoleScreenBufferA(HANDLE hConsoleOutput
, LPSMALL_RECT lpScrollRect
,
2209 LPSMALL_RECT lpClipRect
, COORD dwDestOrigin
,
2214 ciw
.Attributes
= lpFill
->Attributes
;
2215 MultiByteToWideChar(CP_ACP
, 0, &lpFill
->Char
.AsciiChar
, 1, &ciw
.Char
.UnicodeChar
, 1);
2217 return ScrollConsoleScreenBufferW(hConsoleOutput
, lpScrollRect
, lpClipRect
,
2218 dwDestOrigin
, &ciw
);
2221 /******************************************************************
2222 * CONSOLE_FillLineUniform
2224 * Helper function for ScrollConsoleScreenBufferW
2225 * Fills a part of a line with a constant character info
2227 void CONSOLE_FillLineUniform(HANDLE hConsoleOutput
, int i
, int j
, int len
, LPCHAR_INFO lpFill
)
2229 SERVER_START_REQ( fill_console_output
)
2231 req
->handle
= console_handle_unmap(hConsoleOutput
);
2232 req
->mode
= CHAR_INFO_MODE_TEXTATTR
;
2237 req
->data
.ch
= lpFill
->Char
.UnicodeChar
;
2238 req
->data
.attr
= lpFill
->Attributes
;
2239 wine_server_call_err( req
);
2244 /******************************************************************************
2245 * ScrollConsoleScreenBufferW [KERNEL32.@]
2249 BOOL WINAPI
ScrollConsoleScreenBufferW(HANDLE hConsoleOutput
, LPSMALL_RECT lpScrollRect
,
2250 LPSMALL_RECT lpClipRect
, COORD dwDestOrigin
,
2258 CONSOLE_SCREEN_BUFFER_INFO csbi
;
2262 TRACE("(%p,(%d,%d-%d,%d),(%d,%d-%d,%d),%d-%d,%p)\n", hConsoleOutput
,
2263 lpScrollRect
->Left
, lpScrollRect
->Top
,
2264 lpScrollRect
->Right
, lpScrollRect
->Bottom
,
2265 lpClipRect
->Left
, lpClipRect
->Top
,
2266 lpClipRect
->Right
, lpClipRect
->Bottom
,
2267 dwDestOrigin
.X
, dwDestOrigin
.Y
, lpFill
);
2269 TRACE("(%p,(%d,%d-%d,%d),(nil),%d-%d,%p)\n", hConsoleOutput
,
2270 lpScrollRect
->Left
, lpScrollRect
->Top
,
2271 lpScrollRect
->Right
, lpScrollRect
->Bottom
,
2272 dwDestOrigin
.X
, dwDestOrigin
.Y
, lpFill
);
2274 if (!GetConsoleScreenBufferInfo(hConsoleOutput
, &csbi
))
2277 /* step 1: get dst rect */
2278 dst
.Left
= dwDestOrigin
.X
;
2279 dst
.Top
= dwDestOrigin
.Y
;
2280 dst
.Right
= dst
.Left
+ (lpScrollRect
->Right
- lpScrollRect
->Left
);
2281 dst
.Bottom
= dst
.Top
+ (lpScrollRect
->Bottom
- lpScrollRect
->Top
);
2283 /* step 2a: compute the final clip rect (optional passed clip and screen buffer limits */
2286 clip
.Left
= max(0, lpClipRect
->Left
);
2287 clip
.Right
= min(csbi
.dwSize
.X
- 1, lpClipRect
->Right
);
2288 clip
.Top
= max(0, lpClipRect
->Top
);
2289 clip
.Bottom
= min(csbi
.dwSize
.Y
- 1, lpClipRect
->Bottom
);
2294 clip
.Right
= csbi
.dwSize
.X
- 1;
2296 clip
.Bottom
= csbi
.dwSize
.Y
- 1;
2298 if (clip
.Left
> clip
.Right
|| clip
.Top
> clip
.Bottom
) return FALSE
;
2300 /* step 2b: clip dst rect */
2301 if (dst
.Left
< clip
.Left
) dst
.Left
= clip
.Left
;
2302 if (dst
.Top
< clip
.Top
) dst
.Top
= clip
.Top
;
2303 if (dst
.Right
> clip
.Right
) dst
.Right
= clip
.Right
;
2304 if (dst
.Bottom
> clip
.Bottom
) dst
.Bottom
= clip
.Bottom
;
2306 /* step 3: transfer the bits */
2307 SERVER_START_REQ(move_console_output
)
2309 req
->handle
= console_handle_unmap(hConsoleOutput
);
2310 req
->x_src
= lpScrollRect
->Left
;
2311 req
->y_src
= lpScrollRect
->Top
;
2312 req
->x_dst
= dst
.Left
;
2313 req
->y_dst
= dst
.Top
;
2314 req
->w
= dst
.Right
- dst
.Left
+ 1;
2315 req
->h
= dst
.Bottom
- dst
.Top
+ 1;
2316 ret
= !wine_server_call_err( req
);
2320 if (!ret
) return FALSE
;
2322 /* step 4: clean out the exposed part */
2324 /* have to write cell [i,j] if it is not in dst rect (because it has already
2325 * been written to by the scroll) and is in clip (we shall not write
2328 for (j
= max(lpScrollRect
->Top
, clip
.Top
); j
<= min(lpScrollRect
->Bottom
, clip
.Bottom
); j
++)
2330 inside
= dst
.Top
<= j
&& j
<= dst
.Bottom
;
2332 for (i
= max(lpScrollRect
->Left
, clip
.Left
); i
<= min(lpScrollRect
->Right
, clip
.Right
); i
++)
2334 if (inside
&& dst
.Left
<= i
&& i
<= dst
.Right
)
2338 CONSOLE_FillLineUniform(hConsoleOutput
, start
, j
, i
- start
, lpFill
);
2344 if (start
== -1) start
= i
;
2348 CONSOLE_FillLineUniform(hConsoleOutput
, start
, j
, i
- start
, lpFill
);
2355 /* ====================================================================
2357 * Console manipulation functions
2359 * ====================================================================*/
2361 /* some missing functions...
2362 * FIXME: those are likely to be defined as undocumented function in kernel32 (or part of them)
2363 * should get the right API and implement them
2364 * GetConsoleCommandHistory[AW] (dword dword dword)
2365 * GetConsoleCommandHistoryLength[AW]
2366 * SetConsoleCommandHistoryMode
2367 * SetConsoleNumberOfCommands[AW]
2369 int CONSOLE_GetHistory(int idx
, WCHAR
* buf
, int buf_len
)
2373 SERVER_START_REQ( get_console_input_history
)
2377 if (buf
&& buf_len
> 1)
2379 wine_server_set_reply( req
, buf
, (buf_len
- 1) * sizeof(WCHAR
) );
2381 if (!wine_server_call_err( req
))
2383 if (buf
) buf
[wine_server_reply_size(reply
) / sizeof(WCHAR
)] = 0;
2384 len
= reply
->total
/ sizeof(WCHAR
) + 1;
2391 /******************************************************************
2392 * CONSOLE_AppendHistory
2396 BOOL
CONSOLE_AppendHistory(const WCHAR
* ptr
)
2398 size_t len
= strlenW(ptr
);
2401 while (len
&& (ptr
[len
- 1] == '\n' || ptr
[len
- 1] == '\r')) len
--;
2403 SERVER_START_REQ( append_console_input_history
)
2406 wine_server_add_data( req
, ptr
, len
* sizeof(WCHAR
) );
2407 ret
= !wine_server_call_err( req
);
2413 /******************************************************************
2414 * CONSOLE_GetNumHistoryEntries
2418 unsigned CONSOLE_GetNumHistoryEntries(void)
2421 SERVER_START_REQ(get_console_input_info
)
2424 if (!wine_server_call_err( req
)) ret
= reply
->history_index
;
2430 /******************************************************************
2431 * CONSOLE_GetEditionMode
2435 BOOL
CONSOLE_GetEditionMode(HANDLE hConIn
, int* mode
)
2437 unsigned ret
= FALSE
;
2438 SERVER_START_REQ(get_console_input_info
)
2440 req
->handle
= console_handle_unmap(hConIn
);
2441 if ((ret
= !wine_server_call_err( req
)))
2442 *mode
= reply
->edition_mode
;