2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/console/readwrite.c
5 * PURPOSE: Win32 Console Client read-write functions
6 * PROGRAMMERS: Emanuele Aliberti
8 * Filip Navara (xnavara@volny.cz)
9 * Thomas Weidenmueller (w3seek@reactos.org)
13 /* INCLUDES *******************************************************************/
21 /* PRIVATE FUNCTIONS **********************************************************/
29 IntReadConsole(HANDLE hConsoleInput
,
31 DWORD nNumberOfCharsToRead
,
32 LPDWORD lpNumberOfCharsRead
,
33 PCONSOLE_READCONSOLE_CONTROL pInputControl
,
36 CONSOLE_API_MESSAGE ApiMessage
;
37 PCONSOLE_READCONSOLE ReadConsoleRequest
= &ApiMessage
.Data
.ReadConsoleRequest
;
38 PCSR_CAPTURE_BUFFER CaptureBuffer
;
41 /* Determine the needed size */
42 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
43 ReadConsoleRequest
->BufferSize
= nNumberOfCharsToRead
* CharSize
;
45 /* Allocate a Capture Buffer */
46 CaptureBuffer
= CsrAllocateCaptureBuffer(1, ReadConsoleRequest
->BufferSize
);
47 if (CaptureBuffer
== NULL
)
49 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
50 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
54 /* Allocate space in the Buffer */
55 CsrAllocateMessagePointer(CaptureBuffer
,
56 ReadConsoleRequest
->BufferSize
,
57 (PVOID
*)&ReadConsoleRequest
->Buffer
);
59 /* Set up the data to send to the Console Server */
60 ReadConsoleRequest
->InputHandle
= hConsoleInput
;
61 ReadConsoleRequest
->Unicode
= bUnicode
;
62 ReadConsoleRequest
->NrCharactersToRead
= nNumberOfCharsToRead
;
63 ReadConsoleRequest
->NrCharactersRead
= 0;
64 ReadConsoleRequest
->CtrlWakeupMask
= 0;
65 if (pInputControl
&& pInputControl
->nLength
== sizeof(CONSOLE_READCONSOLE_CONTROL
))
68 * From MSDN (ReadConsole function), the description
69 * for pInputControl says:
70 * "This parameter requires Unicode input by default.
71 * For ANSI mode, set this parameter to NULL."
73 ReadConsoleRequest
->NrCharactersRead
= pInputControl
->nInitialChars
;
74 RtlCopyMemory(ReadConsoleRequest
->Buffer
,
76 pInputControl
->nInitialChars
* sizeof(WCHAR
));
77 ReadConsoleRequest
->CtrlWakeupMask
= pInputControl
->dwCtrlWakeupMask
;
81 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
83 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepReadConsole
),
84 sizeof(*ReadConsoleRequest
));
86 /* Check for success */
87 if (NT_SUCCESS(ApiMessage
.Status
))
89 RtlCopyMemory(lpBuffer
,
90 ReadConsoleRequest
->Buffer
,
91 ReadConsoleRequest
->NrCharactersRead
* CharSize
);
93 if (lpNumberOfCharsRead
!= NULL
)
94 *lpNumberOfCharsRead
= ReadConsoleRequest
->NrCharactersRead
;
96 if (pInputControl
&& pInputControl
->nLength
== sizeof(CONSOLE_READCONSOLE_CONTROL
))
97 pInputControl
->dwControlKeyState
= ReadConsoleRequest
->ControlKeyState
;
101 DPRINT1("CSR returned error in ReadConsole\n");
103 if (lpNumberOfCharsRead
!= NULL
)
104 *lpNumberOfCharsRead
= 0;
107 BaseSetLastNTError(ApiMessage
.Status
);
110 CsrFreeCaptureBuffer(CaptureBuffer
);
112 /* Return TRUE or FALSE */
114 return (ReadConsoleRequest
->NrCharactersRead
> 0);
115 // return NT_SUCCESS(ApiMessage.Status);
121 IntGetConsoleInput(HANDLE hConsoleInput
,
122 PINPUT_RECORD lpBuffer
,
124 LPDWORD lpNumberOfEventsRead
,
128 CONSOLE_API_MESSAGE ApiMessage
;
129 PCONSOLE_GETINPUT GetInputRequest
= &ApiMessage
.Data
.GetInputRequest
;
130 PCSR_CAPTURE_BUFFER CaptureBuffer
= NULL
;
132 if (lpBuffer
== NULL
)
134 SetLastError(ERROR_INVALID_ACCESS
);
138 if (!IsConsoleHandle(hConsoleInput
))
140 SetLastError(ERROR_INVALID_HANDLE
);
142 if (lpNumberOfEventsRead
!= NULL
)
143 *lpNumberOfEventsRead
= 0;
148 DPRINT("IntGetConsoleInput: %lx %p\n", nLength
, lpNumberOfEventsRead
);
150 /* Set up the data to send to the Console Server */
151 GetInputRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
152 GetInputRequest
->InputHandle
= hConsoleInput
;
153 GetInputRequest
->NumRecords
= nLength
;
154 GetInputRequest
->Flags
= wFlags
;
155 GetInputRequest
->Unicode
= bUnicode
;
158 * For optimization purposes, Windows (and hence ReactOS, too, for
159 * compatibility reasons) uses a static buffer if no more than five
160 * input records are read. Otherwise a new buffer is allocated.
161 * This behaviour is also expected in the server-side.
163 if (nLength
<= sizeof(GetInputRequest
->RecordStaticBuffer
)/sizeof(INPUT_RECORD
))
165 GetInputRequest
->RecordBufPtr
= GetInputRequest
->RecordStaticBuffer
;
166 // CaptureBuffer = NULL;
170 ULONG Size
= nLength
* sizeof(INPUT_RECORD
);
172 /* Allocate a Capture Buffer */
173 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
174 if (CaptureBuffer
== NULL
)
176 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
177 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
181 /* Allocate space in the Buffer */
182 CsrAllocateMessagePointer(CaptureBuffer
,
184 (PVOID
*)&GetInputRequest
->RecordBufPtr
);
187 /* Call the server */
188 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
190 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetConsoleInput
),
191 sizeof(*GetInputRequest
));
193 /* Check for success */
194 if (NT_SUCCESS(ApiMessage
.Status
))
196 /* Return the number of events read */
197 DPRINT("Events read: %lx\n", GetInputRequest
->NumRecords
);
199 if (lpNumberOfEventsRead
!= NULL
)
200 *lpNumberOfEventsRead
= GetInputRequest
->NumRecords
;
202 /* Copy into the buffer */
203 RtlCopyMemory(lpBuffer
,
204 GetInputRequest
->RecordBufPtr
,
205 GetInputRequest
->NumRecords
* sizeof(INPUT_RECORD
));
209 if (lpNumberOfEventsRead
!= NULL
)
210 *lpNumberOfEventsRead
= 0;
213 BaseSetLastNTError(ApiMessage
.Status
);
216 /* Release the capture buffer if needed */
217 if (CaptureBuffer
) CsrFreeCaptureBuffer(CaptureBuffer
);
219 /* Return TRUE or FALSE */
220 return NT_SUCCESS(ApiMessage
.Status
);
226 IntReadConsoleOutput(HANDLE hConsoleOutput
,
230 PSMALL_RECT lpReadRegion
,
233 CONSOLE_API_MESSAGE ApiMessage
;
234 PCONSOLE_READOUTPUT ReadOutputRequest
= &ApiMessage
.Data
.ReadOutputRequest
;
235 PCSR_CAPTURE_BUFFER CaptureBuffer
;
236 DWORD Size
, SizeX
, SizeY
;
238 if (lpBuffer
== NULL
)
240 SetLastError(ERROR_INVALID_ACCESS
);
244 Size
= dwBufferSize
.X
* dwBufferSize
.Y
* sizeof(CHAR_INFO
);
246 DPRINT("IntReadConsoleOutput: %lx %p\n", Size
, lpReadRegion
);
248 /* Allocate a Capture Buffer */
249 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
250 if (CaptureBuffer
== NULL
)
252 DPRINT1("CsrAllocateCaptureBuffer failed with size 0x%x!\n", Size
);
253 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
257 /* Allocate space in the Buffer */
258 CsrAllocateMessagePointer(CaptureBuffer
,
260 (PVOID
*)&ReadOutputRequest
->CharInfo
);
262 /* Set up the data to send to the Console Server */
263 ReadOutputRequest
->OutputHandle
= hConsoleOutput
;
264 ReadOutputRequest
->Unicode
= bUnicode
;
265 ReadOutputRequest
->BufferSize
= dwBufferSize
;
266 ReadOutputRequest
->BufferCoord
= dwBufferCoord
;
267 ReadOutputRequest
->ReadRegion
= *lpReadRegion
;
269 /* Call the server */
270 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
272 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepReadConsoleOutput
),
273 sizeof(*ReadOutputRequest
));
275 /* Check for success */
276 if (NT_SUCCESS(ApiMessage
.Status
))
278 /* Copy into the buffer */
279 DPRINT("Copying to buffer\n");
280 SizeX
= ReadOutputRequest
->ReadRegion
.Right
-
281 ReadOutputRequest
->ReadRegion
.Left
+ 1;
282 SizeY
= ReadOutputRequest
->ReadRegion
.Bottom
-
283 ReadOutputRequest
->ReadRegion
.Top
+ 1;
284 RtlCopyMemory(lpBuffer
,
285 ReadOutputRequest
->CharInfo
,
286 sizeof(CHAR_INFO
) * SizeX
* SizeY
);
291 BaseSetLastNTError(ApiMessage
.Status
);
294 /* Return the read region */
295 DPRINT("read region: %p\n", ReadOutputRequest
->ReadRegion
);
296 *lpReadRegion
= ReadOutputRequest
->ReadRegion
;
298 /* Release the capture buffer */
299 CsrFreeCaptureBuffer(CaptureBuffer
);
301 /* Return TRUE or FALSE */
302 return NT_SUCCESS(ApiMessage
.Status
);
308 IntReadConsoleOutputCode(HANDLE hConsoleOutput
,
313 LPDWORD lpNumberOfCodesRead
)
315 CONSOLE_API_MESSAGE ApiMessage
;
316 PCONSOLE_READOUTPUTCODE ReadOutputCodeRequest
= &ApiMessage
.Data
.ReadOutputCodeRequest
;
317 PCSR_CAPTURE_BUFFER CaptureBuffer
= NULL
;
318 ULONG SizeBytes
, CodeSize
;
320 DPRINT("IntReadConsoleOutputCode\n");
322 /* Set up the data to send to the Console Server */
323 ReadOutputCodeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
324 ReadOutputCodeRequest
->OutputHandle
= hConsoleOutput
;
325 ReadOutputCodeRequest
->Coord
= dwReadCoord
;
326 ReadOutputCodeRequest
->NumCodes
= nLength
;
328 /* Determine the needed size */
329 ReadOutputCodeRequest
->CodeType
= CodeType
;
333 CodeSize
= sizeof(CHAR
);
337 CodeSize
= sizeof(WCHAR
);
341 CodeSize
= sizeof(WORD
);
345 SetLastError(ERROR_INVALID_PARAMETER
);
348 SizeBytes
= nLength
* CodeSize
;
351 * For optimization purposes, Windows (and hence ReactOS, too, for
352 * compatibility reasons) uses a static buffer if no more than eighty
353 * bytes are read. Otherwise a new buffer is allocated.
354 * This behaviour is also expected in the server-side.
356 if (SizeBytes
<= sizeof(ReadOutputCodeRequest
->CodeStaticBuffer
))
358 ReadOutputCodeRequest
->pCode
.pCode
= ReadOutputCodeRequest
->CodeStaticBuffer
;
359 // CaptureBuffer = NULL;
363 /* Allocate a Capture Buffer */
364 CaptureBuffer
= CsrAllocateCaptureBuffer(1, SizeBytes
);
365 if (CaptureBuffer
== NULL
)
367 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
368 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
372 /* Allocate space in the Buffer */
373 CsrAllocateMessagePointer(CaptureBuffer
,
375 (PVOID
*)&ReadOutputCodeRequest
->pCode
.pCode
);
378 /* Call the server */
379 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
381 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepReadConsoleOutputString
),
382 sizeof(*ReadOutputCodeRequest
));
384 /* Check for success */
385 if (NT_SUCCESS(ApiMessage
.Status
))
387 DWORD NumCodes
= ReadOutputCodeRequest
->NumCodes
;
389 ReadOutputCodeRequest
->pCode
.pCode
,
390 NumCodes
* CodeSize
);
392 if (lpNumberOfCodesRead
!= NULL
)
393 *lpNumberOfCodesRead
= NumCodes
;
397 if (lpNumberOfCodesRead
!= NULL
)
398 *lpNumberOfCodesRead
= 0;
401 BaseSetLastNTError(ApiMessage
.Status
);
404 /* Release the capture buffer if needed */
405 if (CaptureBuffer
) CsrFreeCaptureBuffer(CaptureBuffer
);
407 /* Return TRUE or FALSE */
408 return NT_SUCCESS(ApiMessage
.Status
);
418 IntWriteConsole(HANDLE hConsoleOutput
,
420 DWORD nNumberOfCharsToWrite
,
421 LPDWORD lpNumberOfCharsWritten
,
426 CONSOLE_API_MESSAGE ApiMessage
;
427 PCONSOLE_WRITECONSOLE WriteConsoleRequest
= &ApiMessage
.Data
.WriteConsoleRequest
;
428 PCSR_CAPTURE_BUFFER CaptureBuffer
;
431 /* Determine the needed size */
432 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
433 WriteConsoleRequest
->BufferSize
= nNumberOfCharsToWrite
* CharSize
;
435 /* Allocate a Capture Buffer */
436 CaptureBuffer
= CsrAllocateCaptureBuffer(1, WriteConsoleRequest
->BufferSize
);
437 if (CaptureBuffer
== NULL
)
439 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
440 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
444 /* Capture the buffer to write */
445 CsrCaptureMessageBuffer(CaptureBuffer
,
447 WriteConsoleRequest
->BufferSize
,
448 (PVOID
*)&WriteConsoleRequest
->Buffer
);
451 WriteConsoleRequest
->NrCharactersToWrite
= nNumberOfCharsToWrite
;
452 WriteConsoleRequest
->OutputHandle
= hConsoleOutput
;
453 WriteConsoleRequest
->Unicode
= bUnicode
;
455 /* Call the server */
456 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
458 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepWriteConsole
),
459 sizeof(*WriteConsoleRequest
));
461 /* Check for success */
462 if (NT_SUCCESS(ApiMessage
.Status
))
464 if (lpNumberOfCharsWritten
!= NULL
)
465 *lpNumberOfCharsWritten
= WriteConsoleRequest
->NrCharactersWritten
;
471 if (lpNumberOfCharsWritten
!= NULL
)
472 *lpNumberOfCharsWritten
= 0;
475 BaseSetLastNTError(ApiMessage
.Status
);
479 CsrFreeCaptureBuffer(CaptureBuffer
);
487 IntWriteConsoleInput(HANDLE hConsoleInput
,
488 PINPUT_RECORD lpBuffer
,
490 LPDWORD lpNumberOfEventsWritten
,
492 BOOLEAN bAppendToEnd
)
494 CONSOLE_API_MESSAGE ApiMessage
;
495 PCONSOLE_WRITEINPUT WriteInputRequest
= &ApiMessage
.Data
.WriteInputRequest
;
496 PCSR_CAPTURE_BUFFER CaptureBuffer
= NULL
;
498 if (lpBuffer
== NULL
)
500 SetLastError(ERROR_INVALID_ACCESS
);
504 DPRINT("IntWriteConsoleInput: %lx %p\n", nLength
, lpNumberOfEventsWritten
);
506 /* Set up the data to send to the Console Server */
507 WriteInputRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
508 WriteInputRequest
->InputHandle
= hConsoleInput
;
509 WriteInputRequest
->NumRecords
= nLength
;
510 WriteInputRequest
->Unicode
= bUnicode
;
511 WriteInputRequest
->AppendToEnd
= bAppendToEnd
;
514 * For optimization purposes, Windows (and hence ReactOS, too, for
515 * compatibility reasons) uses a static buffer if no more than five
516 * input records are written. Otherwise a new buffer is allocated.
517 * This behaviour is also expected in the server-side.
519 if (nLength
<= sizeof(WriteInputRequest
->RecordStaticBuffer
)/sizeof(INPUT_RECORD
))
521 WriteInputRequest
->RecordBufPtr
= WriteInputRequest
->RecordStaticBuffer
;
522 // CaptureBuffer = NULL;
524 RtlCopyMemory(WriteInputRequest
->RecordBufPtr
,
526 nLength
* sizeof(INPUT_RECORD
));
530 ULONG Size
= nLength
* sizeof(INPUT_RECORD
);
532 /* Allocate a Capture Buffer */
533 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
534 if (CaptureBuffer
== NULL
)
536 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
537 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
541 /* Capture the user buffer */
542 CsrCaptureMessageBuffer(CaptureBuffer
,
545 (PVOID
*)&WriteInputRequest
->RecordBufPtr
);
548 /* Call the server */
549 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
551 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepWriteConsoleInput
),
552 sizeof(*WriteInputRequest
));
554 /* Release the capture buffer if needed */
555 if (CaptureBuffer
) CsrFreeCaptureBuffer(CaptureBuffer
);
557 /* Check for success */
558 if (NT_SUCCESS(ApiMessage
.Status
))
560 /* Return the number of events written */
561 DPRINT("Events written: %lx\n", WriteInputRequest
->NumRecords
);
563 if (lpNumberOfEventsWritten
!= NULL
)
564 *lpNumberOfEventsWritten
= WriteInputRequest
->NumRecords
;
568 if (lpNumberOfEventsWritten
!= NULL
)
569 *lpNumberOfEventsWritten
= 0;
572 BaseSetLastNTError(ApiMessage
.Status
);
575 /* Return TRUE or FALSE */
576 return NT_SUCCESS(ApiMessage
.Status
);
582 IntWriteConsoleOutput(HANDLE hConsoleOutput
,
583 CONST CHAR_INFO
*lpBuffer
,
586 PSMALL_RECT lpWriteRegion
,
589 CONSOLE_API_MESSAGE ApiMessage
;
590 PCONSOLE_WRITEOUTPUT WriteOutputRequest
= &ApiMessage
.Data
.WriteOutputRequest
;
591 PCSR_CAPTURE_BUFFER CaptureBuffer
;
594 if ((lpBuffer
== NULL
) || (lpWriteRegion
== NULL
))
596 SetLastError(ERROR_INVALID_ACCESS
);
600 if (lpWriteRegion == NULL)
602 SetLastError(ERROR_INVALID_PARAMETER);
607 Size
= dwBufferSize
.Y
* dwBufferSize
.X
* sizeof(CHAR_INFO
);
609 DPRINT("IntWriteConsoleOutput: %lx %p\n", Size
, lpWriteRegion
);
611 /* Allocate a Capture Buffer */
612 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
613 if (CaptureBuffer
== NULL
)
615 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
616 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
620 /* Capture the user buffer */
621 CsrCaptureMessageBuffer(CaptureBuffer
,
624 (PVOID
*)&WriteOutputRequest
->CharInfo
);
626 /* Set up the data to send to the Console Server */
627 WriteOutputRequest
->OutputHandle
= hConsoleOutput
;
628 WriteOutputRequest
->Unicode
= bUnicode
;
629 WriteOutputRequest
->BufferSize
= dwBufferSize
;
630 WriteOutputRequest
->BufferCoord
= dwBufferCoord
;
631 WriteOutputRequest
->WriteRegion
= *lpWriteRegion
;
633 /* Call the server */
634 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
636 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepWriteConsoleOutput
),
637 sizeof(*WriteOutputRequest
));
639 /* Check for success */
640 if (!NT_SUCCESS(ApiMessage
.Status
))
643 BaseSetLastNTError(ApiMessage
.Status
);
646 /* Return the read region */
647 DPRINT("read region: %p\n", WriteOutputRequest
->WriteRegion
);
648 *lpWriteRegion
= WriteOutputRequest
->WriteRegion
;
650 /* Release the capture buffer */
651 CsrFreeCaptureBuffer(CaptureBuffer
);
653 /* Return TRUE or FALSE */
654 return NT_SUCCESS(ApiMessage
.Status
);
660 IntWriteConsoleOutputCode(HANDLE hConsoleOutput
,
665 LPDWORD lpNumberOfCodesWritten
)
667 CONSOLE_API_MESSAGE ApiMessage
;
668 PCONSOLE_WRITEOUTPUTCODE WriteOutputCodeRequest
= &ApiMessage
.Data
.WriteOutputCodeRequest
;
669 PCSR_CAPTURE_BUFFER CaptureBuffer
= NULL
;
670 ULONG SizeBytes
, CodeSize
;
674 SetLastError(ERROR_INVALID_ACCESS
);
678 DPRINT("IntWriteConsoleOutputCode\n");
680 /* Set up the data to send to the Console Server */
681 WriteOutputCodeRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
682 WriteOutputCodeRequest
->OutputHandle
= hConsoleOutput
;
683 WriteOutputCodeRequest
->Coord
= dwWriteCoord
;
684 WriteOutputCodeRequest
->NumCodes
= nLength
;
686 /* Determine the needed size */
687 WriteOutputCodeRequest
->CodeType
= CodeType
;
691 CodeSize
= sizeof(CHAR
);
695 CodeSize
= sizeof(WCHAR
);
699 CodeSize
= sizeof(WORD
);
703 SetLastError(ERROR_INVALID_PARAMETER
);
706 SizeBytes
= nLength
* CodeSize
;
709 * For optimization purposes, Windows (and hence ReactOS, too, for
710 * compatibility reasons) uses a static buffer if no more than eighty
711 * bytes are written. Otherwise a new buffer is allocated.
712 * This behaviour is also expected in the server-side.
714 if (SizeBytes
<= sizeof(WriteOutputCodeRequest
->CodeStaticBuffer
))
716 WriteOutputCodeRequest
->pCode
.pCode
= WriteOutputCodeRequest
->CodeStaticBuffer
;
717 // CaptureBuffer = NULL;
719 RtlCopyMemory(WriteOutputCodeRequest
->pCode
.pCode
,
725 /* Allocate a Capture Buffer */
726 CaptureBuffer
= CsrAllocateCaptureBuffer(1, SizeBytes
);
727 if (CaptureBuffer
== NULL
)
729 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
730 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
734 /* Capture the buffer to write */
735 CsrCaptureMessageBuffer(CaptureBuffer
,
738 (PVOID
*)&WriteOutputCodeRequest
->pCode
.pCode
);
741 /* Call the server */
742 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
744 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepWriteConsoleOutputString
),
745 sizeof(*WriteOutputCodeRequest
));
747 /* Release the capture buffer if needed */
748 if (CaptureBuffer
) CsrFreeCaptureBuffer(CaptureBuffer
);
750 /* Check for success */
751 if (NT_SUCCESS(ApiMessage
.Status
))
753 if (lpNumberOfCodesWritten
!= NULL
)
754 *lpNumberOfCodesWritten
= WriteOutputCodeRequest
->NumCodes
;
758 if (lpNumberOfCodesWritten
!= NULL
)
759 *lpNumberOfCodesWritten
= 0;
762 BaseSetLastNTError(ApiMessage
.Status
);
765 /* Return TRUE or FALSE */
766 return NT_SUCCESS(ApiMessage
.Status
);
772 IntFillConsoleOutputCode(HANDLE hConsoleOutput
,
777 LPDWORD lpNumberOfCodesWritten
)
779 CONSOLE_API_MESSAGE ApiMessage
;
780 PCONSOLE_FILLOUTPUTCODE FillOutputRequest
= &ApiMessage
.Data
.FillOutputRequest
;
782 /* Set up the data to send to the Console Server */
783 FillOutputRequest
->ConsoleHandle
= NtCurrentPeb()->ProcessParameters
->ConsoleHandle
;
784 FillOutputRequest
->OutputHandle
= hConsoleOutput
;
785 FillOutputRequest
->WriteCoord
= dwWriteCoord
;
786 FillOutputRequest
->NumCodes
= nLength
;
788 FillOutputRequest
->CodeType
= CodeType
;
792 FillOutputRequest
->Code
.AsciiChar
= *(PCHAR
)pCode
;
796 FillOutputRequest
->Code
.UnicodeChar
= *(PWCHAR
)pCode
;
800 FillOutputRequest
->Code
.Attribute
= *(PWORD
)pCode
;
804 SetLastError(ERROR_INVALID_PARAMETER
);
808 /* Call the server */
809 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
811 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFillConsoleOutput
),
812 sizeof(*FillOutputRequest
));
814 /* Check for success */
815 if (NT_SUCCESS(ApiMessage
.Status
))
817 if (lpNumberOfCodesWritten
!= NULL
)
818 *lpNumberOfCodesWritten
= FillOutputRequest
->NumCodes
;
822 if (lpNumberOfCodesWritten
!= NULL
)
823 *lpNumberOfCodesWritten
= 0;
825 BaseSetLastNTError(ApiMessage
.Status
);
828 /* Return TRUE or FALSE */
829 return NT_SUCCESS(ApiMessage
.Status
);
833 /* FUNCTIONS ******************************************************************/
839 /*--------------------------------------------------------------
846 ReadConsoleW(HANDLE hConsoleInput
,
848 DWORD nNumberOfCharsToRead
,
849 LPDWORD lpNumberOfCharsRead
,
850 PCONSOLE_READCONSOLE_CONTROL pInputControl
)
852 return IntReadConsole(hConsoleInput
,
854 nNumberOfCharsToRead
,
861 /*--------------------------------------------------------------
868 ReadConsoleA(HANDLE hConsoleInput
,
870 DWORD nNumberOfCharsToRead
,
871 LPDWORD lpNumberOfCharsRead
,
872 PCONSOLE_READCONSOLE_CONTROL pInputControl
)
874 return IntReadConsole(hConsoleInput
,
876 nNumberOfCharsToRead
,
883 /*--------------------------------------------------------------
890 PeekConsoleInputW(HANDLE hConsoleInput
,
891 PINPUT_RECORD lpBuffer
,
893 LPDWORD lpNumberOfEventsRead
)
895 return IntGetConsoleInput(hConsoleInput
,
898 lpNumberOfEventsRead
,
899 CONSOLE_READ_KEEPEVENT
| CONSOLE_READ_CONTINUE
,
904 /*--------------------------------------------------------------
911 PeekConsoleInputA(HANDLE hConsoleInput
,
912 PINPUT_RECORD lpBuffer
,
914 LPDWORD lpNumberOfEventsRead
)
916 return IntGetConsoleInput(hConsoleInput
,
919 lpNumberOfEventsRead
,
920 CONSOLE_READ_KEEPEVENT
| CONSOLE_READ_CONTINUE
,
925 /*--------------------------------------------------------------
932 ReadConsoleInputW(HANDLE hConsoleInput
,
933 PINPUT_RECORD lpBuffer
,
935 LPDWORD lpNumberOfEventsRead
)
937 return IntGetConsoleInput(hConsoleInput
,
940 lpNumberOfEventsRead
,
946 /*--------------------------------------------------------------
953 ReadConsoleInputA(HANDLE hConsoleInput
,
954 PINPUT_RECORD lpBuffer
,
956 LPDWORD lpNumberOfEventsRead
)
958 return IntGetConsoleInput(hConsoleInput
,
961 lpNumberOfEventsRead
,
967 /*--------------------------------------------------------------
968 * ReadConsoleInputExW
974 ReadConsoleInputExW(HANDLE hConsoleInput
,
975 PINPUT_RECORD lpBuffer
,
977 LPDWORD lpNumberOfEventsRead
,
980 return IntGetConsoleInput(hConsoleInput
,
983 lpNumberOfEventsRead
,
989 /*--------------------------------------------------------------
990 * ReadConsoleInputExA
996 ReadConsoleInputExA(HANDLE hConsoleInput
,
997 PINPUT_RECORD lpBuffer
,
999 LPDWORD lpNumberOfEventsRead
,
1002 return IntGetConsoleInput(hConsoleInput
,
1005 lpNumberOfEventsRead
,
1011 /*--------------------------------------------------------------
1012 * ReadConsoleOutputW
1018 ReadConsoleOutputW(HANDLE hConsoleOutput
,
1019 PCHAR_INFO lpBuffer
,
1021 COORD dwBufferCoord
,
1022 PSMALL_RECT lpReadRegion
)
1024 return IntReadConsoleOutput(hConsoleOutput
,
1033 /*--------------------------------------------------------------
1034 * ReadConsoleOutputA
1040 ReadConsoleOutputA(HANDLE hConsoleOutput
,
1041 PCHAR_INFO lpBuffer
,
1043 COORD dwBufferCoord
,
1044 PSMALL_RECT lpReadRegion
)
1046 return IntReadConsoleOutput(hConsoleOutput
,
1055 /*--------------------------------------------------------------
1056 * ReadConsoleOutputCharacterW
1062 ReadConsoleOutputCharacterW(HANDLE hConsoleOutput
,
1066 LPDWORD lpNumberOfCharsRead
)
1068 return IntReadConsoleOutputCode(hConsoleOutput
,
1073 lpNumberOfCharsRead
);
1077 /*--------------------------------------------------------------
1078 * ReadConsoleOutputCharacterA
1084 ReadConsoleOutputCharacterA(HANDLE hConsoleOutput
,
1088 LPDWORD lpNumberOfCharsRead
)
1090 return IntReadConsoleOutputCode(hConsoleOutput
,
1095 lpNumberOfCharsRead
);
1099 /*--------------------------------------------------------------
1100 * ReadConsoleOutputAttribute
1106 ReadConsoleOutputAttribute(HANDLE hConsoleOutput
,
1110 LPDWORD lpNumberOfAttrsRead
)
1112 return IntReadConsoleOutputCode(hConsoleOutput
,
1117 lpNumberOfAttrsRead
);
1121 /*******************
1123 *******************/
1125 /*--------------------------------------------------------------
1132 WriteConsoleW(HANDLE hConsoleOutput
,
1133 CONST VOID
*lpBuffer
,
1134 DWORD nNumberOfCharsToWrite
,
1135 LPDWORD lpNumberOfCharsWritten
,
1138 return IntWriteConsole(hConsoleOutput
,
1140 nNumberOfCharsToWrite
,
1141 lpNumberOfCharsWritten
,
1147 /*--------------------------------------------------------------
1154 WriteConsoleA(HANDLE hConsoleOutput
,
1155 CONST VOID
*lpBuffer
,
1156 DWORD nNumberOfCharsToWrite
,
1157 LPDWORD lpNumberOfCharsWritten
,
1160 return IntWriteConsole(hConsoleOutput
,
1162 nNumberOfCharsToWrite
,
1163 lpNumberOfCharsWritten
,
1169 /*--------------------------------------------------------------
1170 * WriteConsoleInputW
1176 WriteConsoleInputW(HANDLE hConsoleInput
,
1177 CONST INPUT_RECORD
*lpBuffer
,
1179 LPDWORD lpNumberOfEventsWritten
)
1181 return IntWriteConsoleInput(hConsoleInput
,
1182 (PINPUT_RECORD
)lpBuffer
,
1184 lpNumberOfEventsWritten
,
1190 /*--------------------------------------------------------------
1191 * WriteConsoleInputA
1197 WriteConsoleInputA(HANDLE hConsoleInput
,
1198 CONST INPUT_RECORD
*lpBuffer
,
1200 LPDWORD lpNumberOfEventsWritten
)
1202 return IntWriteConsoleInput(hConsoleInput
,
1203 (PINPUT_RECORD
)lpBuffer
,
1205 lpNumberOfEventsWritten
,
1211 /*--------------------------------------------------------------
1212 * WriteConsoleInputVDMW
1218 WriteConsoleInputVDMW(HANDLE hConsoleInput
,
1219 CONST INPUT_RECORD
*lpBuffer
,
1221 LPDWORD lpNumberOfEventsWritten
)
1223 return IntWriteConsoleInput(hConsoleInput
,
1224 (PINPUT_RECORD
)lpBuffer
,
1226 lpNumberOfEventsWritten
,
1232 /*--------------------------------------------------------------
1233 * WriteConsoleInputVDMA
1239 WriteConsoleInputVDMA(HANDLE hConsoleInput
,
1240 CONST INPUT_RECORD
*lpBuffer
,
1242 LPDWORD lpNumberOfEventsWritten
)
1244 return IntWriteConsoleInput(hConsoleInput
,
1245 (PINPUT_RECORD
)lpBuffer
,
1247 lpNumberOfEventsWritten
,
1253 /*--------------------------------------------------------------
1254 * WriteConsoleOutputW
1260 WriteConsoleOutputW(HANDLE hConsoleOutput
,
1261 CONST CHAR_INFO
*lpBuffer
,
1263 COORD dwBufferCoord
,
1264 PSMALL_RECT lpWriteRegion
)
1266 return IntWriteConsoleOutput(hConsoleOutput
,
1275 /*--------------------------------------------------------------
1276 * WriteConsoleOutputA
1282 WriteConsoleOutputA(HANDLE hConsoleOutput
,
1283 CONST CHAR_INFO
*lpBuffer
,
1285 COORD dwBufferCoord
,
1286 PSMALL_RECT lpWriteRegion
)
1288 return IntWriteConsoleOutput(hConsoleOutput
,
1297 /*--------------------------------------------------------------
1298 * WriteConsoleOutputCharacterW
1304 WriteConsoleOutputCharacterW(HANDLE hConsoleOutput
,
1305 LPCWSTR lpCharacter
,
1308 LPDWORD lpNumberOfCharsWritten
)
1310 return IntWriteConsoleOutputCode(hConsoleOutput
,
1315 lpNumberOfCharsWritten
);
1319 /*--------------------------------------------------------------
1320 * WriteConsoleOutputCharacterA
1326 WriteConsoleOutputCharacterA(HANDLE hConsoleOutput
,
1330 LPDWORD lpNumberOfCharsWritten
)
1332 return IntWriteConsoleOutputCode(hConsoleOutput
,
1337 lpNumberOfCharsWritten
);
1341 /*--------------------------------------------------------------
1342 * WriteConsoleOutputAttribute
1348 WriteConsoleOutputAttribute(HANDLE hConsoleOutput
,
1349 CONST WORD
*lpAttribute
,
1352 LPDWORD lpNumberOfAttrsWritten
)
1354 return IntWriteConsoleOutputCode(hConsoleOutput
,
1359 lpNumberOfAttrsWritten
);
1363 /*--------------------------------------------------------------
1364 * FillConsoleOutputCharacterW
1370 FillConsoleOutputCharacterW(HANDLE hConsoleOutput
,
1374 LPDWORD lpNumberOfCharsWritten
)
1376 return IntFillConsoleOutputCode(hConsoleOutput
,
1381 lpNumberOfCharsWritten
);
1385 /*--------------------------------------------------------------
1386 * FillConsoleOutputCharacterA
1392 FillConsoleOutputCharacterA(HANDLE hConsoleOutput
,
1396 LPDWORD lpNumberOfCharsWritten
)
1398 return IntFillConsoleOutputCode(hConsoleOutput
,
1403 lpNumberOfCharsWritten
);
1407 /*--------------------------------------------------------------
1408 * FillConsoleOutputAttribute
1414 FillConsoleOutputAttribute(HANDLE hConsoleOutput
,
1418 LPDWORD lpNumberOfAttrsWritten
)
1420 return IntFillConsoleOutputCode(hConsoleOutput
,
1425 lpNumberOfAttrsWritten
);