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 /* Set up the data to send to the Console Server */
61 ReadConsoleRequest
->ConsoleHandle
= hConsoleInput
;
62 ReadConsoleRequest
->Unicode
= bUnicode
;
63 ReadConsoleRequest
->NrCharactersToRead
= (WORD
)nNumberOfCharsToRead
;
64 ReadConsoleRequest
->NrCharactersRead
= 0;
65 ReadConsoleRequest
->CtrlWakeupMask
= 0;
66 if (pInputControl
&& pInputControl
->nLength
== sizeof(CONSOLE_READCONSOLE_CONTROL
))
68 ReadConsoleRequest
->NrCharactersRead
= pInputControl
->nInitialChars
;
69 memcpy(ReadConsoleRequest
->Buffer
,
71 pInputControl
->nInitialChars
* sizeof(WCHAR
));
72 ReadConsoleRequest
->CtrlWakeupMask
= pInputControl
->dwCtrlWakeupMask
;
76 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
78 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepReadConsole
),
79 sizeof(CSRSS_READ_CONSOLE
));
81 /* Check for success */
82 if (NT_SUCCESS(Status
) || NT_SUCCESS(Status
= ApiMessage
.Status
))
85 ReadConsoleRequest
->Buffer
,
86 ReadConsoleRequest
->NrCharactersRead
* CharSize
);
88 if (lpNumberOfCharsRead
!= NULL
)
89 *lpNumberOfCharsRead
= ReadConsoleRequest
->NrCharactersRead
;
91 if (pInputControl
&& pInputControl
->nLength
== sizeof(CONSOLE_READCONSOLE_CONTROL
))
92 pInputControl
->dwControlKeyState
= ReadConsoleRequest
->ControlKeyState
;
96 DPRINT1("CSR returned error in ReadConsole\n");
98 if (lpNumberOfCharsRead
!= NULL
)
99 *lpNumberOfCharsRead
= 0;
102 BaseSetLastNTError(Status
/* ApiMessage.Status */);
105 CsrFreeCaptureBuffer(CaptureBuffer
);
107 /* Return TRUE or FALSE */
109 return (ReadConsoleRequest
->NrCharactersRead
> 0);
110 // return NT_SUCCESS(ApiMessage.Status);
116 IntGetConsoleInput(HANDLE hConsoleInput
,
118 PINPUT_RECORD lpBuffer
,
120 LPDWORD lpNumberOfEventsRead
,
124 CONSOLE_API_MESSAGE ApiMessage
;
125 PCSRSS_GET_CONSOLE_INPUT GetConsoleInputRequest
= &ApiMessage
.Data
.GetConsoleInputRequest
;
126 PCSR_CAPTURE_BUFFER CaptureBuffer
;
129 if (lpBuffer
== NULL
)
131 SetLastError(ERROR_INVALID_PARAMETER
);
135 Size
= nLength
* sizeof(INPUT_RECORD
);
137 DPRINT("IntGetConsoleInput: %lx %p\n", Size
, lpNumberOfEventsRead
);
139 /* Allocate a Capture Buffer */
140 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
141 if (CaptureBuffer
== NULL
)
143 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
144 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
148 /* Allocate space in the Buffer */
149 CsrAllocateMessagePointer(CaptureBuffer
,
151 (PVOID
*)&GetConsoleInputRequest
->InputRecord
);
153 /* Set up the data to send to the Console Server */
154 GetConsoleInputRequest
->ConsoleHandle
= hConsoleInput
;
155 GetConsoleInputRequest
->Unicode
= bUnicode
;
156 GetConsoleInputRequest
->bRead
= bRead
;
157 GetConsoleInputRequest
->InputsRead
= 0;
158 GetConsoleInputRequest
->Length
= nLength
;
160 /* Call the server */
161 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
163 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetConsoleInput
),
164 sizeof(CSRSS_GET_CONSOLE_INPUT
));
165 DPRINT("Server returned: %x\n", ApiMessage
.Status
);
167 /* Check for success */
168 if (NT_SUCCESS(Status
) || NT_SUCCESS(Status
= ApiMessage
.Status
))
170 /* Return the number of events read */
171 DPRINT("Events read: %lx\n", GetConsoleInputRequest
->InputsRead
);
173 if (lpNumberOfEventsRead
!= NULL
)
174 *lpNumberOfEventsRead
= GetConsoleInputRequest
->InputsRead
;
176 /* Copy into the buffer */
177 DPRINT("Copying to buffer\n");
178 RtlCopyMemory(lpBuffer
,
179 GetConsoleInputRequest
->InputRecord
,
180 sizeof(INPUT_RECORD
) * GetConsoleInputRequest
->InputsRead
);
184 if (lpNumberOfEventsRead
!= NULL
)
185 *lpNumberOfEventsRead
= 0;
188 BaseSetLastNTError(ApiMessage
.Status
);
191 // BaseSetLastNTError(Status); ????
192 if (GetConsoleInputRequest->InputsRead == 0)
194 /\* we couldn't read a single record, fail *\/
195 BaseSetLastNTError(Status);
200 /\* FIXME - fail gracefully in case we already read at least one record? *\/
206 /* Release the capture buffer */
207 CsrFreeCaptureBuffer(CaptureBuffer
);
209 /* Return TRUE or FALSE */
210 return (GetConsoleInputRequest
->InputsRead
> 0);
211 // return NT_SUCCESS(ApiMessage.Status);
217 IntReadConsoleOutput(HANDLE hConsoleOutput
,
221 PSMALL_RECT lpReadRegion
,
224 CONSOLE_API_MESSAGE ApiMessage
;
225 PCSRSS_READ_CONSOLE_OUTPUT ReadConsoleOutputRequest
= &ApiMessage
.Data
.ReadConsoleOutputRequest
;
226 PCSR_CAPTURE_BUFFER CaptureBuffer
;
227 DWORD Size
, SizeX
, SizeY
;
229 if (lpBuffer
== NULL
)
231 SetLastError(ERROR_INVALID_PARAMETER
);
235 Size
= dwBufferSize
.X
* dwBufferSize
.Y
* sizeof(CHAR_INFO
);
237 DPRINT("IntReadConsoleOutput: %lx %p\n", Size
, lpReadRegion
);
239 /* Allocate a Capture Buffer */
240 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
241 if (CaptureBuffer
== NULL
)
243 DPRINT1("CsrAllocateCaptureBuffer failed with size 0x%x!\n", Size
);
244 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
248 /* Allocate space in the Buffer */
249 CsrAllocateMessagePointer(CaptureBuffer
,
251 (PVOID
*)&ReadConsoleOutputRequest
->CharInfo
);
253 /* Set up the data to send to the Console Server */
254 ReadConsoleOutputRequest
->ConsoleHandle
= hConsoleOutput
;
255 ReadConsoleOutputRequest
->Unicode
= bUnicode
;
256 ReadConsoleOutputRequest
->BufferSize
= dwBufferSize
;
257 ReadConsoleOutputRequest
->BufferCoord
= dwBufferCoord
;
258 ReadConsoleOutputRequest
->ReadRegion
= *lpReadRegion
;
260 /* Call the server */
261 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
263 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepReadConsoleOutput
),
264 sizeof(CSRSS_READ_CONSOLE_OUTPUT
));
265 DPRINT("Server returned: %x\n", ApiMessage
.Status
);
267 /* Check for success*/
268 if (NT_SUCCESS(ApiMessage
.Status
))
270 /* Copy into the buffer */
271 DPRINT("Copying to buffer\n");
272 SizeX
= ReadConsoleOutputRequest
->ReadRegion
.Right
-
273 ReadConsoleOutputRequest
->ReadRegion
.Left
+ 1;
274 SizeY
= ReadConsoleOutputRequest
->ReadRegion
.Bottom
-
275 ReadConsoleOutputRequest
->ReadRegion
.Top
+ 1;
276 RtlCopyMemory(lpBuffer
,
277 ReadConsoleOutputRequest
->CharInfo
,
278 sizeof(CHAR_INFO
) * SizeX
* SizeY
);
283 BaseSetLastNTError(ApiMessage
.Status
);
286 /* Return the read region */
287 DPRINT("read region: %lx\n", ReadConsoleOutputRequest
->ReadRegion
);
288 *lpReadRegion
= ReadConsoleOutputRequest
->ReadRegion
;
290 /* Release the capture buffer */
291 CsrFreeCaptureBuffer(CaptureBuffer
);
293 /* Return TRUE or FALSE */
294 return NT_SUCCESS(ApiMessage
.Status
);
300 IntReadConsoleOutputCode(HANDLE hConsoleOutput
,
305 LPDWORD lpNumberOfCodesRead
)
308 CONSOLE_API_MESSAGE ApiMessage
;
309 PCSRSS_READ_CONSOLE_OUTPUT_CODE ReadConsoleOutputCodeRequest
= &ApiMessage
.Data
.ReadConsoleOutputCodeRequest
;
310 PCSR_CAPTURE_BUFFER CaptureBuffer
;
311 ULONG SizeBytes
, CodeSize
;
312 DWORD
/*CodesRead = 0,*/ BytesRead
;
314 /* Determine the needed size */
318 CodeSize
= sizeof(CHAR
);
322 CodeSize
= sizeof(WCHAR
);
326 CodeSize
= sizeof(WORD
);
330 SetLastError(ERROR_INVALID_PARAMETER
);
333 SizeBytes
= nLength
* CodeSize
;
335 /* Allocate a Capture Buffer */
336 CaptureBuffer
= CsrAllocateCaptureBuffer(1, SizeBytes
);
337 if (CaptureBuffer
== NULL
)
339 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
340 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
344 /* Allocate space in the Buffer */
345 CsrAllocateMessagePointer(CaptureBuffer
,
347 (PVOID
*)&ReadConsoleOutputCodeRequest
->pCode
.pCode
);
350 ReadConsoleOutputCodeRequest
->ConsoleHandle
= hConsoleOutput
;
351 ReadConsoleOutputCodeRequest
->CodeType
= CodeType
;
352 ReadConsoleOutputCodeRequest
->ReadCoord
= dwReadCoord
;
354 // while (nLength > 0)
356 ReadConsoleOutputCodeRequest
->NumCodesToRead
= nLength
;
357 // SizeBytes = ReadConsoleOutputCodeRequest->NumCodesToRead * CodeSize;
359 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
361 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepReadConsoleOutputString
),
362 sizeof(CSRSS_READ_CONSOLE_OUTPUT_CODE
));
363 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= ApiMessage
.Status
))
365 BaseSetLastNTError(Status
);
366 CsrFreeCaptureBuffer(CaptureBuffer
);
370 BytesRead
= ReadConsoleOutputCodeRequest
->CodesRead
* CodeSize
;
371 memcpy(pCode
, ReadConsoleOutputCodeRequest
->pCode
.pCode
, BytesRead
);
372 // pCode = (PVOID)((ULONG_PTR)pCode + /*(ULONG_PTR)*/BytesRead);
373 // nLength -= ReadConsoleOutputCodeRequest->CodesRead;
374 // CodesRead += ReadConsoleOutputCodeRequest->CodesRead;
376 ReadConsoleOutputCodeRequest
->ReadCoord
= ReadConsoleOutputCodeRequest
->EndCoord
;
379 if (lpNumberOfCodesRead
!= NULL
)
380 *lpNumberOfCodesRead
= /*CodesRead;*/ ReadConsoleOutputCodeRequest
->CodesRead
;
382 CsrFreeCaptureBuffer(CaptureBuffer
);
394 IntWriteConsole(HANDLE hConsoleOutput
,
396 DWORD nNumberOfCharsToWrite
,
397 LPDWORD lpNumberOfCharsWritten
,
402 CONSOLE_API_MESSAGE ApiMessage
;
403 PCSRSS_WRITE_CONSOLE WriteConsoleRequest
= &ApiMessage
.Data
.WriteConsoleRequest
;
404 PCSR_CAPTURE_BUFFER CaptureBuffer
;
406 ULONG
/* SizeBytes, */ CharSize
;
407 // DWORD Written = 0;
409 /* Determine the needed size */
410 CharSize
= (bUnicode
? sizeof(WCHAR
) : sizeof(CHAR
));
411 WriteConsoleRequest
->BufferSize
= nNumberOfCharsToWrite
* CharSize
;
413 /* Allocate a Capture Buffer */
414 CaptureBuffer
= CsrAllocateCaptureBuffer(1, WriteConsoleRequest
->BufferSize
);
415 if (CaptureBuffer
== NULL
)
417 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
418 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
422 /* Capture the buffer to write */
423 CsrCaptureMessageBuffer(CaptureBuffer
,
425 WriteConsoleRequest
->BufferSize
,
426 (PVOID
*)&WriteConsoleRequest
->Buffer
);
429 WriteConsoleRequest
->NrCharactersToWrite
= nNumberOfCharsToWrite
;
430 WriteConsoleRequest
->ConsoleHandle
= hConsoleOutput
;
431 WriteConsoleRequest
->Unicode
= bUnicode
;
433 // while (nNumberOfCharsToWrite > 0)
435 //// nChars = (USHORT)min(nNumberOfCharsToWrite, CSRSS_MAX_WRITE_CONSOLE / CharSize);
436 // nChars = nNumberOfCharsToWrite;
437 // WriteConsoleRequest->NrCharactersToWrite = nChars;
439 // SizeBytes = nChars * CharSize;
441 // memcpy(WriteConsoleRequest->Buffer, lpBuffer, SizeBytes);
443 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
445 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepWriteConsole
),
446 sizeof(CSRSS_WRITE_CONSOLE
));
447 /** FIXME: Added in 47359 for pausing
449 if (Status == STATUS_PENDING)
451 WaitForSingleObject(WriteConsoleRequest->UnpauseEvent, INFINITE);
452 CloseHandle(WriteConsoleRequest->UnpauseEvent);
456 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= ApiMessage
.Status
))
458 CsrFreeCaptureBuffer(CaptureBuffer
);
459 BaseSetLastNTError(Status
);
463 // nNumberOfCharsToWrite -= nChars;
464 // lpBuffer = (PVOID)((ULONG_PTR)lpBuffer + (ULONG_PTR)SizeBytes);
465 // Written += WriteConsoleRequest->NrCharactersWritten;
468 if (lpNumberOfCharsWritten
!= NULL
)
469 // *lpNumberOfCharsWritten = Written;
470 *lpNumberOfCharsWritten
= WriteConsoleRequest
->NrCharactersWritten
;
472 CsrFreeCaptureBuffer(CaptureBuffer
);
480 IntWriteConsoleInput(HANDLE hConsoleInput
,
481 PINPUT_RECORD lpBuffer
,
483 LPDWORD lpNumberOfEventsWritten
,
486 CONSOLE_API_MESSAGE ApiMessage
;
487 PCSRSS_WRITE_CONSOLE_INPUT WriteConsoleInputRequest
= &ApiMessage
.Data
.WriteConsoleInputRequest
;
488 PCSR_CAPTURE_BUFFER CaptureBuffer
;
491 if (lpBuffer
== NULL
)
493 SetLastError(ERROR_INVALID_PARAMETER
);
497 Size
= nLength
* sizeof(INPUT_RECORD
);
499 DPRINT("IntWriteConsoleInput: %lx %p\n", Size
, lpNumberOfEventsWritten
);
501 /* Allocate a Capture Buffer */
502 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
503 if (CaptureBuffer
== NULL
)
505 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
506 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
510 /* Capture the user buffer */
511 CsrCaptureMessageBuffer(CaptureBuffer
,
514 (PVOID
*)&WriteConsoleInputRequest
->InputRecord
);
516 /* Set up the data to send to the Console Server */
517 WriteConsoleInputRequest
->ConsoleHandle
= hConsoleInput
;
518 WriteConsoleInputRequest
->Unicode
= bUnicode
;
519 WriteConsoleInputRequest
->Length
= nLength
;
521 /* Call the server */
522 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
524 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepWriteConsoleInput
),
525 sizeof(CSRSS_WRITE_CONSOLE_INPUT
));
526 DPRINT("Server returned: %x\n", ApiMessage
.Status
);
528 /* Check for success*/
529 if (NT_SUCCESS(ApiMessage
.Status
))
531 /* Return the number of events read */
532 DPRINT("Events read: %lx\n", WriteConsoleInputRequest
->Length
);
534 if (lpNumberOfEventsWritten
!= NULL
)
535 *lpNumberOfEventsWritten
= WriteConsoleInputRequest
->Length
;
539 if (lpNumberOfEventsWritten
!= NULL
)
540 *lpNumberOfEventsWritten
= 0;
543 BaseSetLastNTError(ApiMessage
.Status
);
546 /* Release the capture buffer */
547 CsrFreeCaptureBuffer(CaptureBuffer
);
549 /* Return TRUE or FALSE */
550 return NT_SUCCESS(ApiMessage
.Status
);
556 IntWriteConsoleOutput(HANDLE hConsoleOutput
,
557 CONST CHAR_INFO
*lpBuffer
,
560 PSMALL_RECT lpWriteRegion
,
563 CONSOLE_API_MESSAGE ApiMessage
;
564 PCSRSS_WRITE_CONSOLE_OUTPUT WriteConsoleOutputRequest
= &ApiMessage
.Data
.WriteConsoleOutputRequest
;
565 PCSR_CAPTURE_BUFFER CaptureBuffer
;
568 if ((lpBuffer
== NULL
) || (lpWriteRegion
== NULL
))
570 SetLastError(ERROR_INVALID_PARAMETER
);
574 Size
= dwBufferSize
.Y
* dwBufferSize
.X
* sizeof(CHAR_INFO
);
576 DPRINT("IntWriteConsoleOutput: %lx %p\n", Size
, lpWriteRegion
);
578 /* Allocate a Capture Buffer */
579 CaptureBuffer
= CsrAllocateCaptureBuffer(1, Size
);
580 if (CaptureBuffer
== NULL
)
582 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
583 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
587 /* Capture the user buffer */
588 CsrCaptureMessageBuffer(CaptureBuffer
,
591 (PVOID
*)&WriteConsoleOutputRequest
->CharInfo
);
593 /* Set up the data to send to the Console Server */
594 WriteConsoleOutputRequest
->ConsoleHandle
= hConsoleOutput
;
595 WriteConsoleOutputRequest
->Unicode
= bUnicode
;
596 WriteConsoleOutputRequest
->BufferSize
= dwBufferSize
;
597 WriteConsoleOutputRequest
->BufferCoord
= dwBufferCoord
;
598 WriteConsoleOutputRequest
->WriteRegion
= *lpWriteRegion
;
600 /* Call the server */
601 CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
603 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepWriteConsoleOutput
),
604 sizeof(CSRSS_WRITE_CONSOLE_OUTPUT
));
605 DPRINT("Server returned: %x\n", ApiMessage
.Status
);
607 /* Check for success*/
608 if (!NT_SUCCESS(ApiMessage
.Status
))
611 BaseSetLastNTError(ApiMessage
.Status
);
614 /* Return the read region */
615 DPRINT("read region: %lx\n", WriteConsoleOutputRequest
->WriteRegion
);
616 *lpWriteRegion
= WriteConsoleOutputRequest
->WriteRegion
;
618 /* Release the capture buffer */
619 CsrFreeCaptureBuffer(CaptureBuffer
);
621 /* Return TRUE or FALSE */
622 return NT_SUCCESS(ApiMessage
.Status
);
628 IntWriteConsoleOutputCode(HANDLE hConsoleOutput
,
633 LPDWORD lpNumberOfCodesWritten
)
636 CONSOLE_API_MESSAGE ApiMessage
;
637 PCSRSS_WRITE_CONSOLE_OUTPUT_CODE WriteConsoleOutputCodeRequest
= &ApiMessage
.Data
.WriteConsoleOutputCodeRequest
;
638 PCSR_CAPTURE_BUFFER CaptureBuffer
;
639 ULONG CodeSize
; //, nChars;
641 // DWORD Written = 0;
643 /* Determine the needed size */
645 CodeSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
646 nChars = min(nLength, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR / CodeSize);
647 SizeBytes = nChars * CodeSize;
652 CodeSize
= sizeof(CHAR
);
656 CodeSize
= sizeof(WCHAR
);
660 CodeSize
= sizeof(WORD
);
664 SetLastError(ERROR_INVALID_PARAMETER
);
667 WriteConsoleOutputCodeRequest
->BufferSize
= nLength
* CodeSize
;
669 /* Allocate a Capture Buffer */
670 CaptureBuffer
= CsrAllocateCaptureBuffer(1, WriteConsoleOutputCodeRequest
->BufferSize
);
671 if (CaptureBuffer
== NULL
)
673 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
674 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
679 /\* Allocate space in the Buffer *\/
680 CsrAllocateMessagePointer(CaptureBuffer,
682 (PVOID*)&WriteConsoleOutputCodeRequest->pCode.pCode);
684 /* Capture the buffer to write */
685 CsrCaptureMessageBuffer(CaptureBuffer
,
687 WriteConsoleOutputCodeRequest
->BufferSize
,
688 (PVOID
*)&WriteConsoleOutputCodeRequest
->pCode
.pCode
);
691 WriteConsoleOutputCodeRequest
->ConsoleHandle
= hConsoleOutput
;
692 WriteConsoleOutputCodeRequest
->CodeType
= CodeType
;
693 WriteConsoleOutputCodeRequest
->Coord
= dwWriteCoord
;
696 ** TODO: HACK: Surely it has to go into CONSRV !!
698 // while (nLength > 0)
702 WriteConsoleOutputCodeRequest
->Length
= nLength
; // (WORD)min(nLength, nChars);
703 // BytesWrite = WriteConsoleOutputCodeRequest->Length * CodeSize;
705 // memcpy(WriteConsoleOutputCodeRequest->pCode.pCode, pCode, BytesWrite);
707 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
709 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepWriteConsoleOutputString
),
710 sizeof(CSRSS_WRITE_CONSOLE_OUTPUT_CODE
));
711 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= ApiMessage
.Status
))
713 CsrFreeCaptureBuffer(CaptureBuffer
);
714 BaseSetLastNTError(Status
);
718 // nLength -= WriteConsoleOutputCodeRequest->NrCharactersWritten;
719 // pCode = (PVOID)((ULONG_PTR)pCode + /*(ULONG_PTR)(*/WriteConsoleOutputCodeRequest->NrCharactersWritten * CodeSize/*)*/);
720 // Written += WriteConsoleOutputCodeRequest->NrCharactersWritten;
722 WriteConsoleOutputCodeRequest
->Coord
= WriteConsoleOutputCodeRequest
->EndCoord
;
725 if (lpNumberOfCodesWritten
!= NULL
)
726 // *lpNumberOfCodesWritten = Written;
727 // *lpNumberOfCodesWritten = WriteConsoleOutputCodeRequest->NrCharactersWritten;
728 *lpNumberOfCodesWritten
= WriteConsoleOutputCodeRequest
->Length
;
730 CsrFreeCaptureBuffer(CaptureBuffer
);
738 IntFillConsoleOutputCode(HANDLE hConsoleOutput
,
743 LPDWORD lpNumberOfCodesWritten
)
746 CONSOLE_API_MESSAGE ApiMessage
;
747 PCSRSS_FILL_OUTPUT FillOutputRequest
= &ApiMessage
.Data
.FillOutputRequest
;
749 FillOutputRequest
->ConsoleHandle
= hConsoleOutput
;
750 FillOutputRequest
->CodeType
= CodeType
;
755 FillOutputRequest
->Code
.AsciiChar
= *(PCHAR
)pCode
;
759 FillOutputRequest
->Code
.UnicodeChar
= *(PWCHAR
)pCode
;
763 FillOutputRequest
->Code
.Attribute
= *(PWORD
)pCode
;
767 SetLastError(ERROR_INVALID_PARAMETER
);
771 FillOutputRequest
->Coord
= dwWriteCoord
;
772 FillOutputRequest
->Length
= nLength
;
774 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
776 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepFillConsoleOutput
),
777 sizeof(CSRSS_FILL_OUTPUT
));
778 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= ApiMessage
.Status
))
780 BaseSetLastNTError(Status
);
784 if (lpNumberOfCodesWritten
)
785 *lpNumberOfCodesWritten
= FillOutputRequest
->Length
;
786 // *lpNumberOfCodesWritten = Request.Data.FillOutputRequest.NrCharactersWritten;
792 /* FUNCTIONS ******************************************************************/
798 /*--------------------------------------------------------------
805 ReadConsoleW(HANDLE hConsoleInput
,
807 DWORD nNumberOfCharsToRead
,
808 LPDWORD lpNumberOfCharsRead
,
809 PCONSOLE_READCONSOLE_CONTROL pInputControl
)
811 return IntReadConsole(hConsoleInput
,
813 nNumberOfCharsToRead
,
820 /*--------------------------------------------------------------
827 ReadConsoleA(HANDLE hConsoleInput
,
829 DWORD nNumberOfCharsToRead
,
830 LPDWORD lpNumberOfCharsRead
,
831 PCONSOLE_READCONSOLE_CONTROL pInputControl
)
833 return IntReadConsole(hConsoleInput
,
835 nNumberOfCharsToRead
,
842 /*--------------------------------------------------------------
849 PeekConsoleInputW(HANDLE hConsoleInput
,
850 PINPUT_RECORD lpBuffer
,
852 LPDWORD lpNumberOfEventsRead
)
854 return IntGetConsoleInput(hConsoleInput
,
858 lpNumberOfEventsRead
,
863 /*--------------------------------------------------------------
870 PeekConsoleInputA(HANDLE hConsoleInput
,
871 PINPUT_RECORD lpBuffer
,
873 LPDWORD lpNumberOfEventsRead
)
875 return IntGetConsoleInput(hConsoleInput
,
879 lpNumberOfEventsRead
,
884 /*--------------------------------------------------------------
891 ReadConsoleInputW(HANDLE hConsoleInput
,
892 PINPUT_RECORD lpBuffer
,
894 LPDWORD lpNumberOfEventsRead
)
896 return IntGetConsoleInput(hConsoleInput
,
900 lpNumberOfEventsRead
,
905 /*--------------------------------------------------------------
912 ReadConsoleInputA(HANDLE hConsoleInput
,
913 PINPUT_RECORD lpBuffer
,
915 LPDWORD lpNumberOfEventsRead
)
917 return IntGetConsoleInput(hConsoleInput
,
921 lpNumberOfEventsRead
,
928 ReadConsoleInputExW(HANDLE hConsole
, LPVOID lpBuffer
, DWORD dwLen
, LPDWORD Unknown1
, DWORD Unknown2
)
937 ReadConsoleInputExA(HANDLE hConsole
, LPVOID lpBuffer
, DWORD dwLen
, LPDWORD Unknown1
, DWORD Unknown2
)
944 /*--------------------------------------------------------------
951 ReadConsoleOutputW(HANDLE hConsoleOutput
,
955 PSMALL_RECT lpReadRegion
)
957 return IntReadConsoleOutput(hConsoleOutput
,
966 /*--------------------------------------------------------------
973 ReadConsoleOutputA(HANDLE hConsoleOutput
,
977 PSMALL_RECT lpReadRegion
)
979 return IntReadConsoleOutput(hConsoleOutput
,
988 /*--------------------------------------------------------------
989 * ReadConsoleOutputCharacterW
995 ReadConsoleOutputCharacterW(HANDLE hConsoleOutput
,
999 LPDWORD lpNumberOfCharsRead
)
1001 return IntReadConsoleOutputCode(hConsoleOutput
,
1006 lpNumberOfCharsRead
);
1010 /*--------------------------------------------------------------
1011 * ReadConsoleOutputCharacterA
1017 ReadConsoleOutputCharacterA(HANDLE hConsoleOutput
,
1021 LPDWORD lpNumberOfCharsRead
)
1023 return IntReadConsoleOutputCode(hConsoleOutput
,
1028 lpNumberOfCharsRead
);
1032 /*--------------------------------------------------------------
1033 * ReadConsoleOutputAttribute
1039 ReadConsoleOutputAttribute(HANDLE hConsoleOutput
,
1043 LPDWORD lpNumberOfAttrsRead
)
1045 return IntReadConsoleOutputCode(hConsoleOutput
,
1050 lpNumberOfAttrsRead
);
1054 /*******************
1056 *******************/
1058 /*--------------------------------------------------------------
1065 WriteConsoleW(HANDLE hConsoleOutput
,
1066 CONST VOID
*lpBuffer
,
1067 DWORD nNumberOfCharsToWrite
,
1068 LPDWORD lpNumberOfCharsWritten
,
1071 return IntWriteConsole(hConsoleOutput
,
1073 nNumberOfCharsToWrite
,
1074 lpNumberOfCharsWritten
,
1080 /*--------------------------------------------------------------
1087 WriteConsoleA(HANDLE hConsoleOutput
,
1088 CONST VOID
*lpBuffer
,
1089 DWORD nNumberOfCharsToWrite
,
1090 LPDWORD lpNumberOfCharsWritten
,
1093 return IntWriteConsole(hConsoleOutput
,
1095 nNumberOfCharsToWrite
,
1096 lpNumberOfCharsWritten
,
1102 /*--------------------------------------------------------------
1103 * WriteConsoleInputW
1109 WriteConsoleInputW(HANDLE hConsoleInput
,
1110 CONST INPUT_RECORD
*lpBuffer
,
1112 LPDWORD lpNumberOfEventsWritten
)
1114 return IntWriteConsoleInput(hConsoleInput
,
1115 (PINPUT_RECORD
)lpBuffer
,
1117 lpNumberOfEventsWritten
,
1122 /*--------------------------------------------------------------
1123 * WriteConsoleInputA
1129 WriteConsoleInputA(HANDLE hConsoleInput
,
1130 CONST INPUT_RECORD
*lpBuffer
,
1132 LPDWORD lpNumberOfEventsWritten
)
1134 return IntWriteConsoleInput(hConsoleInput
,
1135 (PINPUT_RECORD
)lpBuffer
,
1137 lpNumberOfEventsWritten
,
1142 /*--------------------------------------------------------------
1143 * WriteConsoleOutputW
1149 WriteConsoleOutputW(HANDLE hConsoleOutput
,
1150 CONST CHAR_INFO
*lpBuffer
,
1152 COORD dwBufferCoord
,
1153 PSMALL_RECT lpWriteRegion
)
1155 return IntWriteConsoleOutput(hConsoleOutput
,
1164 /*--------------------------------------------------------------
1165 * WriteConsoleOutputA
1171 WriteConsoleOutputA(HANDLE hConsoleOutput
,
1172 CONST CHAR_INFO
*lpBuffer
,
1174 COORD dwBufferCoord
,
1175 PSMALL_RECT lpWriteRegion
)
1177 return IntWriteConsoleOutput(hConsoleOutput
,
1186 /*--------------------------------------------------------------
1187 * WriteConsoleOutputCharacterW
1193 WriteConsoleOutputCharacterW(HANDLE hConsoleOutput
,
1194 LPCWSTR lpCharacter
,
1197 LPDWORD lpNumberOfCharsWritten
)
1199 return IntWriteConsoleOutputCode(hConsoleOutput
,
1204 lpNumberOfCharsWritten
);
1208 /*--------------------------------------------------------------
1209 * WriteConsoleOutputCharacterA
1215 WriteConsoleOutputCharacterA(HANDLE hConsoleOutput
,
1219 LPDWORD lpNumberOfCharsWritten
)
1221 return IntWriteConsoleOutputCode(hConsoleOutput
,
1226 lpNumberOfCharsWritten
);
1230 /*--------------------------------------------------------------
1231 * WriteConsoleOutputAttribute
1237 WriteConsoleOutputAttribute(HANDLE hConsoleOutput
,
1238 CONST WORD
*lpAttribute
,
1241 LPDWORD lpNumberOfAttrsWritten
)
1243 return IntWriteConsoleOutputCode(hConsoleOutput
,
1248 lpNumberOfAttrsWritten
);
1252 /*--------------------------------------------------------------
1253 * FillConsoleOutputCharacterW
1259 FillConsoleOutputCharacterW(HANDLE hConsoleOutput
,
1263 LPDWORD lpNumberOfCharsWritten
)
1265 return IntFillConsoleOutputCode(hConsoleOutput
,
1270 lpNumberOfCharsWritten
);
1274 /*--------------------------------------------------------------
1275 * FillConsoleOutputCharacterA
1281 FillConsoleOutputCharacterA(HANDLE hConsoleOutput
,
1285 LPDWORD lpNumberOfCharsWritten
)
1287 return IntFillConsoleOutputCode(hConsoleOutput
,
1292 lpNumberOfCharsWritten
);
1296 /*--------------------------------------------------------------
1297 * FillConsoleOutputAttribute
1303 FillConsoleOutputAttribute(HANDLE hConsoleOutput
,
1307 LPDWORD lpNumberOfAttrsWritten
)
1309 return IntFillConsoleOutputCode(hConsoleOutput
,
1314 lpNumberOfAttrsWritten
);