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
,
37 CONSOLE_API_MESSAGE ApiMessage
;
38 PCSRSS_READ_CONSOLE ReadConsoleRequest
= &ApiMessage
.Data
.ReadConsoleRequest
;
39 PCSR_CAPTURE_BUFFER CaptureBuffer
;
42 /* Determine the needed size */
43 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
44 ReadConsoleRequest
->BufferSize
= nNumberOfCharsToRead
* CharSize
;
46 /* Allocate a Capture Buffer */
47 CaptureBuffer
= CsrAllocateCaptureBuffer(1, ReadConsoleRequest
->BufferSize
);
48 if (CaptureBuffer
== NULL
)
50 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
51 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
55 /* Allocate space in the Buffer */
56 CsrAllocateMessagePointer(CaptureBuffer
,
57 ReadConsoleRequest
->BufferSize
,
58 (PVOID
*)&ReadConsoleRequest
->Buffer
);
60 ReadConsoleRequest
->ConsoleHandle
= hConsoleInput
;
61 ReadConsoleRequest
->Unicode
= bUnicode
;
62 ReadConsoleRequest
->NrCharactersToRead
= (WORD
)nNumberOfCharsToRead
;
63 ReadConsoleRequest
->NrCharactersRead
= 0;
64 ReadConsoleRequest
->CtrlWakeupMask
= 0;
65 if (pInputControl
&& pInputControl
->nLength
== sizeof(CONSOLE_READCONSOLE_CONTROL
))
67 ReadConsoleRequest
->NrCharactersRead
= pInputControl
->nInitialChars
;
68 memcpy(ReadConsoleRequest
->Buffer
,
70 pInputControl
->nInitialChars
* sizeof(WCHAR
));
71 ReadConsoleRequest
->CtrlWakeupMask
= pInputControl
->dwCtrlWakeupMask
;
74 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
76 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepReadConsole
),
77 sizeof(CSRSS_READ_CONSOLE
));
78 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= ApiMessage
.Status
))
80 DPRINT1("CSR returned error in ReadConsole\n");
81 CsrFreeCaptureBuffer(CaptureBuffer
);
82 BaseSetLastNTError(Status
);
87 ReadConsoleRequest
->Buffer
,
88 ReadConsoleRequest
->NrCharactersRead
* CharSize
);
90 if (lpNumberOfCharsRead
!= NULL
)
91 *lpNumberOfCharsRead
= ReadConsoleRequest
->NrCharactersRead
;
93 if (pInputControl
&& pInputControl
->nLength
== sizeof(CONSOLE_READCONSOLE_CONTROL
))
94 pInputControl
->dwControlKeyState
= ReadConsoleRequest
->ControlKeyState
;
96 CsrFreeCaptureBuffer(CaptureBuffer
);
104 IntGetConsoleInput(HANDLE hConsoleInput
,
106 PINPUT_RECORD lpBuffer
,
108 LPDWORD lpNumberOfEventsRead
,
112 CONSOLE_API_MESSAGE ApiMessage
;
113 PCSRSS_GET_CONSOLE_INPUT GetConsoleInputRequest
= &ApiMessage
.Data
.GetConsoleInputRequest
;
114 PCSR_CAPTURE_BUFFER CaptureBuffer
;
117 if (lpBuffer
== NULL
)
119 SetLastError(ERROR_INVALID_PARAMETER
);
123 Size
= nLength
* sizeof(INPUT_RECORD
);
125 DPRINT("IntGetConsoleInput: %lx %p\n", Size
, lpNumberOfEventsRead
);
127 /* Allocate a Capture Buffer */
128 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
129 if (CaptureBuffer
== NULL
)
131 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
132 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
136 /* Allocate space in the Buffer */
137 CsrAllocateMessagePointer(CaptureBuffer
,
139 (PVOID
*)&GetConsoleInputRequest
->InputRecord
);
141 /* Set up the data to send to the Console Server */
142 GetConsoleInputRequest
->ConsoleHandle
= hConsoleInput
;
143 GetConsoleInputRequest
->Unicode
= bUnicode
;
144 GetConsoleInputRequest
->bRead
= bRead
;
147 GetConsoleInputRequest
->InputsRead
= 0;
149 GetConsoleInputRequest
->Length
= nLength
;
151 /* Call the server */
152 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
154 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetConsoleInput
),
155 sizeof(CSRSS_GET_CONSOLE_INPUT
));
156 DPRINT("Server returned: %x\n", ApiMessage
.Status
);
159 if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
161 // BaseSetLastNTError(Status); ????
162 if (GetConsoleInputRequest->InputsRead == 0)
164 /\* we couldn't read a single record, fail *\/
165 BaseSetLastNTError(Status);
170 /\* FIXME - fail gracefully in case we already read at least one record? *\/
177 ** TODO: !! Simplify the function !!
179 if (bRead
== TRUE
) // ReadConsoleInput call.
181 /* Check for success */
182 if (NT_SUCCESS(Status
) || NT_SUCCESS(Status
= ApiMessage
.Status
))
184 /* Return the number of events read */
185 DPRINT("Events read: %lx\n", GetConsoleInputRequest
->InputsRead
/*Length*/);
187 if (lpNumberOfEventsRead
!= NULL
)
188 *lpNumberOfEventsRead
= GetConsoleInputRequest
->InputsRead
/*Length*/;
190 /* Copy into the buffer */
191 DPRINT("Copying to buffer\n");
192 RtlCopyMemory(lpBuffer
,
193 GetConsoleInputRequest
->InputRecord
,
194 sizeof(INPUT_RECORD
) * GetConsoleInputRequest
->InputsRead
/*Length*/);
198 if (lpNumberOfEventsRead
!= NULL
)
199 *lpNumberOfEventsRead
= 0;
202 BaseSetLastNTError(ApiMessage
.Status
);
205 /* Release the capture buffer */
206 CsrFreeCaptureBuffer(CaptureBuffer
);
208 return (GetConsoleInputRequest
->InputsRead
> 0);
210 else // PeekConsoleInput call.
212 /* Check for success */
213 if (NT_SUCCESS(Status
) || NT_SUCCESS(ApiMessage
.Status
))
215 /* Return the number of events read */
216 DPRINT("Events read: %lx\n", GetConsoleInputRequest
->Length
);
218 if (lpNumberOfEventsRead
!= NULL
)
219 *lpNumberOfEventsRead
= GetConsoleInputRequest
->Length
;
221 /* Copy into the buffer */
222 DPRINT("Copying to buffer\n");
223 RtlCopyMemory(lpBuffer
,
224 GetConsoleInputRequest
->InputRecord
,
225 sizeof(INPUT_RECORD
) * GetConsoleInputRequest
->Length
);
229 if (lpNumberOfEventsRead
!= NULL
)
230 *lpNumberOfEventsRead
= 0;
233 BaseSetLastNTError(ApiMessage
.Status
);
236 /* Release the capture buffer */
237 CsrFreeCaptureBuffer(CaptureBuffer
);
239 /* Return TRUE or FALSE */
240 return NT_SUCCESS(ApiMessage
.Status
);
247 IntReadConsoleOutput(HANDLE hConsoleOutput
,
251 PSMALL_RECT lpReadRegion
,
254 CONSOLE_API_MESSAGE ApiMessage
;
255 PCSRSS_READ_CONSOLE_OUTPUT ReadConsoleOutputRequest
= &ApiMessage
.Data
.ReadConsoleOutputRequest
;
256 PCSR_CAPTURE_BUFFER CaptureBuffer
;
257 DWORD Size
, SizeX
, SizeY
;
259 if (lpBuffer
== NULL
)
261 SetLastError(ERROR_INVALID_PARAMETER
);
265 Size
= dwBufferSize
.X
* dwBufferSize
.Y
* sizeof(CHAR_INFO
);
267 DPRINT("IntReadConsoleOutput: %lx %p\n", Size
, lpReadRegion
);
269 /* Allocate a Capture Buffer */
270 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
271 if (CaptureBuffer
== NULL
)
273 DPRINT1("CsrAllocateCaptureBuffer failed with size 0x%x!\n", Size
);
274 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
278 /* Allocate space in the Buffer */
279 CsrAllocateMessagePointer(CaptureBuffer
,
281 (PVOID
*)&ReadConsoleOutputRequest
->CharInfo
);
283 /* Set up the data to send to the Console Server */
284 ReadConsoleOutputRequest
->ConsoleHandle
= hConsoleOutput
;
285 ReadConsoleOutputRequest
->Unicode
= bUnicode
;
286 ReadConsoleOutputRequest
->BufferSize
= dwBufferSize
;
287 ReadConsoleOutputRequest
->BufferCoord
= dwBufferCoord
;
288 ReadConsoleOutputRequest
->ReadRegion
= *lpReadRegion
;
290 /* Call the server */
291 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
293 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepReadConsoleOutput
),
294 sizeof(CSRSS_READ_CONSOLE_OUTPUT
));
295 DPRINT("Server returned: %x\n", ApiMessage
.Status
);
297 /* Check for success*/
298 if (NT_SUCCESS(ApiMessage
.Status
))
300 /* Copy into the buffer */
301 DPRINT("Copying to buffer\n");
302 SizeX
= ReadConsoleOutputRequest
->ReadRegion
.Right
-
303 ReadConsoleOutputRequest
->ReadRegion
.Left
+ 1;
304 SizeY
= ReadConsoleOutputRequest
->ReadRegion
.Bottom
-
305 ReadConsoleOutputRequest
->ReadRegion
.Top
+ 1;
306 RtlCopyMemory(lpBuffer
,
307 ReadConsoleOutputRequest
->CharInfo
,
308 sizeof(CHAR_INFO
) * SizeX
* SizeY
);
313 BaseSetLastNTError(ApiMessage
.Status
);
316 /* Return the read region */
317 DPRINT("read region: %lx\n", ReadConsoleOutputRequest
->ReadRegion
);
318 *lpReadRegion
= ReadConsoleOutputRequest
->ReadRegion
;
320 /* Release the capture buffer */
321 CsrFreeCaptureBuffer(CaptureBuffer
);
323 /* Return TRUE or FALSE */
324 return NT_SUCCESS(ApiMessage
.Status
);
330 IntReadConsoleOutputCode(HANDLE hConsoleOutput
,
335 LPDWORD lpNumberOfCodesRead
)
338 CONSOLE_API_MESSAGE ApiMessage
;
339 PCSRSS_READ_CONSOLE_OUTPUT_CODE ReadConsoleOutputCodeRequest
= &ApiMessage
.Data
.ReadConsoleOutputCodeRequest
;
340 PCSR_CAPTURE_BUFFER CaptureBuffer
;
341 ULONG SizeBytes
, CodeSize
;
342 DWORD
/*CodesRead = 0,*/ BytesRead
;
344 /* Determine the needed size */
348 CodeSize
= sizeof(CHAR
);
352 CodeSize
= sizeof(WCHAR
);
356 CodeSize
= sizeof(WORD
);
360 SetLastError(ERROR_INVALID_PARAMETER
);
363 SizeBytes
= nLength
* CodeSize
;
365 /* Allocate a Capture Buffer */
366 CaptureBuffer
= CsrAllocateCaptureBuffer(1, SizeBytes
);
367 if (CaptureBuffer
== NULL
)
369 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
370 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
374 /* Allocate space in the Buffer */
375 CsrAllocateMessagePointer(CaptureBuffer
,
377 (PVOID
*)&ReadConsoleOutputCodeRequest
->pCode
.pCode
);
380 ReadConsoleOutputCodeRequest
->ConsoleHandle
= hConsoleOutput
;
381 ReadConsoleOutputCodeRequest
->CodeType
= CodeType
;
382 ReadConsoleOutputCodeRequest
->ReadCoord
= dwReadCoord
;
384 // while (nLength > 0)
386 ReadConsoleOutputCodeRequest
->NumCodesToRead
= nLength
;
387 // SizeBytes = ReadConsoleOutputCodeRequest->NumCodesToRead * CodeSize;
389 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
391 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepReadConsoleOutputString
),
392 sizeof(CSRSS_READ_CONSOLE_OUTPUT_CODE
));
393 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= ApiMessage
.Status
))
395 BaseSetLastNTError(Status
);
396 CsrFreeCaptureBuffer(CaptureBuffer
);
400 BytesRead
= ReadConsoleOutputCodeRequest
->CodesRead
* CodeSize
;
401 memcpy(pCode
, ReadConsoleOutputCodeRequest
->pCode
.pCode
, BytesRead
);
402 // pCode = (PVOID)((ULONG_PTR)pCode + /*(ULONG_PTR)*/BytesRead);
403 // nLength -= ReadConsoleOutputCodeRequest->CodesRead;
404 // CodesRead += ReadConsoleOutputCodeRequest->CodesRead;
406 ReadConsoleOutputCodeRequest
->ReadCoord
= ReadConsoleOutputCodeRequest
->EndCoord
;
409 if (lpNumberOfCodesRead
!= NULL
)
410 *lpNumberOfCodesRead
= /*CodesRead;*/ ReadConsoleOutputCodeRequest
->CodesRead
;
412 CsrFreeCaptureBuffer(CaptureBuffer
);
424 IntWriteConsole(HANDLE hConsoleOutput
,
426 DWORD nNumberOfCharsToWrite
,
427 LPDWORD lpNumberOfCharsWritten
,
431 PCSR_API_MESSAGE Request
;
435 ULONG SizeBytes
, CharSize
;
438 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
439 Request
= RtlAllocateHeap(RtlGetProcessHeap(),
441 max(sizeof(CSR_API_MESSAGE
),
442 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE
) + min(nNumberOfCharsToWrite
,
443 CSRSS_MAX_WRITE_CONSOLE
/ CharSize
) * CharSize
));
446 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
450 CsrRequest
= CSR_CREATE_API_NUMBER(CSR_CONSOLE
, WRITE_CONSOLE
);
452 while (nNumberOfCharsToWrite
> 0)
454 Request
->Data
.WriteConsoleRequest
.ConsoleHandle
= hConsoleOutput
;
455 Request
->Data
.WriteConsoleRequest
.Unicode
= bUnicode
;
457 nChars
= (USHORT
)min(nNumberOfCharsToWrite
, CSRSS_MAX_WRITE_CONSOLE
/ CharSize
);
458 Request
->Data
.WriteConsoleRequest
.NrCharactersToWrite
= nChars
;
460 SizeBytes
= nChars
* CharSize
;
462 memcpy(Request
->Data
.WriteConsoleRequest
.Buffer
, lpBuffer
, SizeBytes
);
464 Status
= CsrClientCallServer(Request
,
467 max(sizeof(CSR_API_MESSAGE
),
468 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE
) + SizeBytes
));
470 if (Status
== STATUS_PENDING
)
472 WaitForSingleObject(Request
->Data
.WriteConsoleRequest
.UnpauseEvent
, INFINITE
);
473 CloseHandle(Request
->Data
.WriteConsoleRequest
.UnpauseEvent
);
476 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
478 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
479 BaseSetLastNTError(Status
);
483 nNumberOfCharsToWrite
-= nChars
;
484 lpBuffer
= (PVOID
)((ULONG_PTR
)lpBuffer
+ (ULONG_PTR
)SizeBytes
);
485 Written
+= Request
->Data
.WriteConsoleRequest
.NrCharactersWritten
;
488 if (lpNumberOfCharsWritten
!= NULL
)
490 *lpNumberOfCharsWritten
= Written
;
492 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
500 IntWriteConsoleInput(HANDLE hConsoleInput
,
501 PINPUT_RECORD lpBuffer
,
503 LPDWORD lpNumberOfEventsWritten
,
506 CSR_API_MESSAGE Request
;
507 PCSR_CAPTURE_BUFFER CaptureBuffer
;
510 if (lpBuffer
== NULL
)
512 SetLastError(ERROR_INVALID_PARAMETER
);
516 Size
= nLength
* sizeof(INPUT_RECORD
);
518 /* Allocate a Capture Buffer */
519 DPRINT("IntWriteConsoleInput: %lx %p\n", Size
, lpNumberOfEventsWritten
);
520 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
521 if (CaptureBuffer
== NULL
)
523 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
524 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
528 /* Allocate space in the Buffer */
529 CsrCaptureMessageBuffer(CaptureBuffer
,
532 (PVOID
*)&Request
.Data
.WriteConsoleInputRequest
.InputRecord
);
534 /* Set up the data to send to the Console Server */
535 Request
.Data
.WriteConsoleInputRequest
.ConsoleHandle
= hConsoleInput
;
536 Request
.Data
.WriteConsoleInputRequest
.Unicode
= bUnicode
;
537 Request
.Data
.WriteConsoleInputRequest
.Length
= nLength
;
539 /* Call the server */
540 CsrClientCallServer(&Request
,
542 CSR_CREATE_API_NUMBER(CSR_CONSOLE
, WRITE_CONSOLE_INPUT
),
543 sizeof(CSR_API_MESSAGE
));
544 DPRINT("Server returned: %x\n", Request
.Status
);
546 /* Check for success*/
547 if (NT_SUCCESS(Request
.Status
))
549 /* Return the number of events read */
550 DPRINT("Events read: %lx\n", Request
.Data
.WriteConsoleInputRequest
.Length
);
551 *lpNumberOfEventsWritten
= Request
.Data
.WriteConsoleInputRequest
.Length
;
556 *lpNumberOfEventsWritten
= 0;
557 BaseSetLastNTError(Request
.Status
);
560 /* Release the capture buffer */
561 CsrFreeCaptureBuffer(CaptureBuffer
);
563 /* Return TRUE or FALSE */
564 return NT_SUCCESS(Request
.Status
);
570 IntWriteConsoleOutput(HANDLE hConsoleOutput
,
571 CONST CHAR_INFO
*lpBuffer
,
574 PSMALL_RECT lpWriteRegion
,
577 CSR_API_MESSAGE Request
;
578 PCSR_CAPTURE_BUFFER CaptureBuffer
;
581 Size
= dwBufferSize
.Y
* dwBufferSize
.X
* sizeof(CHAR_INFO
);
583 /* Allocate a Capture Buffer */
584 DPRINT("IntWriteConsoleOutput: %lx %p\n", Size
, lpWriteRegion
);
585 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
586 if (CaptureBuffer
== NULL
)
588 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
589 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
593 /* Allocate space in the Buffer */
594 CsrCaptureMessageBuffer(CaptureBuffer
,
597 (PVOID
*)&Request
.Data
.WriteConsoleOutputRequest
.CharInfo
);
599 /* Copy from the buffer */
600 RtlCopyMemory(Request
.Data
.WriteConsoleOutputRequest
.CharInfo
, lpBuffer
, Size
);
602 /* Set up the data to send to the Console Server */
603 Request
.Data
.WriteConsoleOutputRequest
.ConsoleHandle
= hConsoleOutput
;
604 Request
.Data
.WriteConsoleOutputRequest
.Unicode
= bUnicode
;
605 Request
.Data
.WriteConsoleOutputRequest
.BufferSize
= dwBufferSize
;
606 Request
.Data
.WriteConsoleOutputRequest
.BufferCoord
= dwBufferCoord
;
607 Request
.Data
.WriteConsoleOutputRequest
.WriteRegion
= *lpWriteRegion
;
609 /* Call the server */
610 CsrClientCallServer(&Request
,
612 CSR_CREATE_API_NUMBER(CSR_CONSOLE
, WRITE_CONSOLE_OUTPUT
),
613 sizeof(CSR_API_MESSAGE
));
614 DPRINT("Server returned: %x\n", Request
.Status
);
616 /* Check for success*/
617 if (!NT_SUCCESS(Request
.Status
))
620 BaseSetLastNTError(Request
.Status
);
623 /* Return the read region */
624 DPRINT("read region: %lx\n", Request
.Data
.WriteConsoleOutputRequest
.WriteRegion
);
625 *lpWriteRegion
= Request
.Data
.WriteConsoleOutputRequest
.WriteRegion
;
627 /* Release the capture buffer */
628 CsrFreeCaptureBuffer(CaptureBuffer
);
630 /* Return TRUE or FALSE */
631 return NT_SUCCESS(Request
.Status
);
637 IntWriteConsoleOutputCharacter(HANDLE hConsoleOutput
,
641 LPDWORD lpNumberOfCharsWritten
,
644 PCSR_API_MESSAGE Request
;
647 ULONG CharSize
, nChars
;
651 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
653 nChars
= min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
/ CharSize
);
654 //SizeBytes = nChars * CharSize;
656 Request
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
657 max(sizeof(CSR_API_MESSAGE
),
658 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
)
659 + min (nChars
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR
/ CharSize
) * CharSize
));
662 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
666 CsrRequest
= CSR_CREATE_API_NUMBER(CSR_CONSOLE
, WRITE_CONSOLE_OUTPUT_CHAR
);
667 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= dwWriteCoord
;
673 Request
->Data
.WriteConsoleOutputCharRequest
.ConsoleHandle
= hConsoleOutput
;
674 Request
->Data
.WriteConsoleOutputCharRequest
.Unicode
= bUnicode
;
675 Request
->Data
.WriteConsoleOutputCharRequest
.Length
= (WORD
)min(nLength
, nChars
);
676 BytesWrite
= Request
->Data
.WriteConsoleOutputCharRequest
.Length
* CharSize
;
678 memcpy(Request
->Data
.WriteConsoleOutputCharRequest
.String
, lpCharacter
, BytesWrite
);
680 Status
= CsrClientCallServer(Request
,
683 max(sizeof(CSR_API_MESSAGE
),
684 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR
) + BytesWrite
));
686 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
688 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
689 BaseSetLastNTError(Status
);
693 nLength
-= Request
->Data
.WriteConsoleOutputCharRequest
.NrCharactersWritten
;
694 lpCharacter
= (PVOID
)((ULONG_PTR
)lpCharacter
+ (ULONG_PTR
)(Request
->Data
.WriteConsoleOutputCharRequest
.NrCharactersWritten
* CharSize
));
695 Written
+= Request
->Data
.WriteConsoleOutputCharRequest
.NrCharactersWritten
;
697 Request
->Data
.WriteConsoleOutputCharRequest
.Coord
= Request
->Data
.WriteConsoleOutputCharRequest
.EndCoord
;
700 if (lpNumberOfCharsWritten
!= NULL
)
702 *lpNumberOfCharsWritten
= Written
;
705 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
713 IntFillConsoleOutputCharacter(HANDLE hConsoleOutput
,
717 LPDWORD lpNumberOfCharsWritten
,
720 CSR_API_MESSAGE Request
;
723 Request
.Data
.FillOutputRequest
.ConsoleHandle
= hConsoleOutput
;
724 Request
.Data
.FillOutputRequest
.Unicode
= bUnicode
;
727 Request
.Data
.FillOutputRequest
.Char
.UnicodeChar
= *((WCHAR
*)cCharacter
);
729 Request
.Data
.FillOutputRequest
.Char
.AsciiChar
= *((CHAR
*)cCharacter
);
731 Request
.Data
.FillOutputRequest
.Position
= dwWriteCoord
;
732 Request
.Data
.FillOutputRequest
.Length
= (WORD
)nLength
;
734 Status
= CsrClientCallServer(&Request
,
736 CSR_CREATE_API_NUMBER(CSR_CONSOLE
, FILL_OUTPUT
),
737 sizeof(CSR_API_MESSAGE
));
739 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
741 BaseSetLastNTError(Status
);
745 if(lpNumberOfCharsWritten
!= NULL
)
747 *lpNumberOfCharsWritten
= Request
.Data
.FillOutputRequest
.NrCharactersWritten
;
754 /* FUNCTIONS ******************************************************************/
760 /*--------------------------------------------------------------
767 ReadConsoleW(HANDLE hConsoleInput
,
769 DWORD nNumberOfCharsToRead
,
770 LPDWORD lpNumberOfCharsRead
,
771 PCONSOLE_READCONSOLE_CONTROL pInputControl
)
773 return IntReadConsole(hConsoleInput
,
775 nNumberOfCharsToRead
,
782 /*--------------------------------------------------------------
789 ReadConsoleA(HANDLE hConsoleInput
,
791 DWORD nNumberOfCharsToRead
,
792 LPDWORD lpNumberOfCharsRead
,
793 PCONSOLE_READCONSOLE_CONTROL pInputControl
)
795 return IntReadConsole(hConsoleInput
,
797 nNumberOfCharsToRead
,
804 /*--------------------------------------------------------------
811 PeekConsoleInputW(HANDLE hConsoleInput
,
812 PINPUT_RECORD lpBuffer
,
814 LPDWORD lpNumberOfEventsRead
)
816 return IntGetConsoleInput(hConsoleInput
,
820 lpNumberOfEventsRead
,
825 /*--------------------------------------------------------------
832 PeekConsoleInputA(HANDLE hConsoleInput
,
833 PINPUT_RECORD lpBuffer
,
835 LPDWORD lpNumberOfEventsRead
)
837 return IntGetConsoleInput(hConsoleInput
,
841 lpNumberOfEventsRead
,
846 /*--------------------------------------------------------------
853 ReadConsoleInputW(HANDLE hConsoleInput
,
854 PINPUT_RECORD lpBuffer
,
856 LPDWORD lpNumberOfEventsRead
)
858 return IntGetConsoleInput(hConsoleInput
,
862 lpNumberOfEventsRead
,
867 /*--------------------------------------------------------------
874 ReadConsoleInputA(HANDLE hConsoleInput
,
875 PINPUT_RECORD lpBuffer
,
877 LPDWORD lpNumberOfEventsRead
)
879 return IntGetConsoleInput(hConsoleInput
,
883 lpNumberOfEventsRead
,
890 ReadConsoleInputExW(HANDLE hConsole
, LPVOID lpBuffer
, DWORD dwLen
, LPDWORD Unknown1
, DWORD Unknown2
)
899 ReadConsoleInputExA(HANDLE hConsole
, LPVOID lpBuffer
, DWORD dwLen
, LPDWORD Unknown1
, DWORD Unknown2
)
906 /*--------------------------------------------------------------
913 ReadConsoleOutputW(HANDLE hConsoleOutput
,
917 PSMALL_RECT lpReadRegion
)
919 return IntReadConsoleOutput(hConsoleOutput
,
928 /*--------------------------------------------------------------
935 ReadConsoleOutputA(HANDLE hConsoleOutput
,
939 PSMALL_RECT lpReadRegion
)
941 return IntReadConsoleOutput(hConsoleOutput
,
950 /*--------------------------------------------------------------
951 * ReadConsoleOutputCharacterW
957 ReadConsoleOutputCharacterW(HANDLE hConsoleOutput
,
961 LPDWORD lpNumberOfCharsRead
)
963 return IntReadConsoleOutputCode(hConsoleOutput
,
968 lpNumberOfCharsRead
);
972 /*--------------------------------------------------------------
973 * ReadConsoleOutputCharacterA
979 ReadConsoleOutputCharacterA(HANDLE hConsoleOutput
,
983 LPDWORD lpNumberOfCharsRead
)
985 return IntReadConsoleOutputCode(hConsoleOutput
,
990 lpNumberOfCharsRead
);
994 /*--------------------------------------------------------------
995 * ReadConsoleOutputAttribute
1001 ReadConsoleOutputAttribute(HANDLE hConsoleOutput
,
1005 LPDWORD lpNumberOfAttrsRead
)
1007 return IntReadConsoleOutputCode(hConsoleOutput
,
1012 lpNumberOfAttrsRead
);
1016 /*******************
1018 *******************/
1020 /*--------------------------------------------------------------
1027 WriteConsoleW(HANDLE hConsoleOutput
,
1028 CONST VOID
*lpBuffer
,
1029 DWORD nNumberOfCharsToWrite
,
1030 LPDWORD lpNumberOfCharsWritten
,
1033 return IntWriteConsole(hConsoleOutput
,
1035 nNumberOfCharsToWrite
,
1036 lpNumberOfCharsWritten
,
1042 /*--------------------------------------------------------------
1049 WriteConsoleA(HANDLE hConsoleOutput
,
1050 CONST VOID
*lpBuffer
,
1051 DWORD nNumberOfCharsToWrite
,
1052 LPDWORD lpNumberOfCharsWritten
,
1055 return IntWriteConsole(hConsoleOutput
,
1057 nNumberOfCharsToWrite
,
1058 lpNumberOfCharsWritten
,
1064 /*--------------------------------------------------------------
1065 * WriteConsoleInputW
1071 WriteConsoleInputW(HANDLE hConsoleInput
,
1072 CONST INPUT_RECORD
*lpBuffer
,
1074 LPDWORD lpNumberOfEventsWritten
)
1076 return IntWriteConsoleInput(hConsoleInput
,
1077 (PINPUT_RECORD
)lpBuffer
,
1079 lpNumberOfEventsWritten
,
1084 /*--------------------------------------------------------------
1085 * WriteConsoleInputA
1091 WriteConsoleInputA(HANDLE hConsoleInput
,
1092 CONST INPUT_RECORD
*lpBuffer
,
1094 LPDWORD lpNumberOfEventsWritten
)
1096 return IntWriteConsoleInput(hConsoleInput
,
1097 (PINPUT_RECORD
)lpBuffer
,
1099 lpNumberOfEventsWritten
,
1104 /*--------------------------------------------------------------
1105 * WriteConsoleOutputW
1111 WriteConsoleOutputW(HANDLE hConsoleOutput
,
1112 CONST CHAR_INFO
*lpBuffer
,
1114 COORD dwBufferCoord
,
1115 PSMALL_RECT lpWriteRegion
)
1117 return IntWriteConsoleOutput(hConsoleOutput
,
1126 /*--------------------------------------------------------------
1127 * WriteConsoleOutputA
1133 WriteConsoleOutputA(HANDLE hConsoleOutput
,
1134 CONST CHAR_INFO
*lpBuffer
,
1136 COORD dwBufferCoord
,
1137 PSMALL_RECT lpWriteRegion
)
1139 return IntWriteConsoleOutput(hConsoleOutput
,
1148 /*--------------------------------------------------------------
1149 * WriteConsoleOutputCharacterW
1155 WriteConsoleOutputCharacterW(HANDLE hConsoleOutput
,
1156 LPCWSTR lpCharacter
,
1159 LPDWORD lpNumberOfCharsWritten
)
1161 return IntWriteConsoleOutputCharacter(hConsoleOutput
,
1165 lpNumberOfCharsWritten
,
1170 /*--------------------------------------------------------------
1171 * WriteConsoleOutputCharacterA
1177 WriteConsoleOutputCharacterA(HANDLE hConsoleOutput
,
1181 LPDWORD lpNumberOfCharsWritten
)
1183 return IntWriteConsoleOutputCharacter(hConsoleOutput
,
1187 lpNumberOfCharsWritten
,
1192 /*--------------------------------------------------------------
1193 * WriteConsoleOutputAttribute
1199 WriteConsoleOutputAttribute(HANDLE hConsoleOutput
,
1200 CONST WORD
*lpAttribute
,
1203 LPDWORD lpNumberOfAttrsWritten
)
1205 PCSR_API_MESSAGE Request
;
1210 Request
= RtlAllocateHeap(RtlGetProcessHeap(),
1212 max(sizeof(CSR_API_MESSAGE
),
1213 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB
)
1214 + min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
/ sizeof(WORD
)) * sizeof(WORD
)));
1215 if (Request
== NULL
)
1217 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1221 CsrRequest
= CSR_CREATE_API_NUMBER(CSR_CONSOLE
, WRITE_CONSOLE_OUTPUT_ATTRIB
);
1222 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= dwWriteCoord
;
1224 if (lpNumberOfAttrsWritten
)
1225 *lpNumberOfAttrsWritten
= nLength
;
1228 Size
= (WORD
)min(nLength
, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB
/ sizeof(WORD
));
1229 Request
->Data
.WriteConsoleOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
1230 Request
->Data
.WriteConsoleOutputAttribRequest
.Length
= Size
;
1231 memcpy(Request
->Data
.WriteConsoleOutputAttribRequest
.Attribute
, lpAttribute
, Size
* sizeof(WORD
));
1233 Status
= CsrClientCallServer(Request
,
1236 max(sizeof(CSR_API_MESSAGE
),
1237 CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB
) + Size
* sizeof(WORD
)));
1239 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
->Status
))
1241 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
1242 BaseSetLastNTError (Status
);
1246 lpAttribute
+= Size
;
1247 Request
->Data
.WriteConsoleOutputAttribRequest
.Coord
= Request
->Data
.WriteConsoleOutputAttribRequest
.EndCoord
;
1250 RtlFreeHeap(RtlGetProcessHeap(), 0, Request
);
1256 /*--------------------------------------------------------------
1257 * FillConsoleOutputCharacterW
1263 FillConsoleOutputCharacterW(HANDLE hConsoleOutput
,
1267 LPDWORD lpNumberOfCharsWritten
)
1269 return IntFillConsoleOutputCharacter(hConsoleOutput
,
1273 lpNumberOfCharsWritten
,
1278 /*--------------------------------------------------------------
1279 * FillConsoleOutputCharacterA
1285 FillConsoleOutputCharacterA(HANDLE hConsoleOutput
,
1289 LPDWORD lpNumberOfCharsWritten
)
1291 return IntFillConsoleOutputCharacter(hConsoleOutput
,
1295 lpNumberOfCharsWritten
,
1300 /*--------------------------------------------------------------
1301 * FillConsoleOutputAttribute
1307 FillConsoleOutputAttribute(HANDLE hConsoleOutput
,
1311 LPDWORD lpNumberOfAttrsWritten
)
1313 CSR_API_MESSAGE Request
;
1316 Request
.Data
.FillOutputAttribRequest
.ConsoleHandle
= hConsoleOutput
;
1317 Request
.Data
.FillOutputAttribRequest
.Attribute
= (CHAR
)wAttribute
;
1318 Request
.Data
.FillOutputAttribRequest
.Coord
= dwWriteCoord
;
1319 Request
.Data
.FillOutputAttribRequest
.Length
= (WORD
)nLength
;
1321 Status
= CsrClientCallServer(&Request
,
1323 CSR_CREATE_API_NUMBER(CSR_CONSOLE
, FILL_OUTPUT_ATTRIB
),
1324 sizeof(CSR_API_MESSAGE
));
1325 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= Request
.Status
))
1327 BaseSetLastNTError ( Status
);
1331 if (lpNumberOfAttrsWritten
)
1332 *lpNumberOfAttrsWritten
= nLength
;