Implement a Default Console Handler for Console Apps.
[reactos.git] / reactos / lib / kernel32 / misc / console.c
1 /* $Id: console.c,v 1.63 2003/08/09 04:13:24 jimtabor Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/misc/console.c
6 * PURPOSE: Win32 server console functions
7 * PROGRAMMER: James Tabor
8 * <jimtabor@adsl-64-217-116-74.dsl.hstntx.swbell.net>
9 * UPDATE HISTORY:
10 * 199901?? ?? Created
11 * 19990204 EA SetConsoleTitleA
12 * 19990306 EA Stubs
13 */
14
15 /* INCLUDES ******************************************************************/
16
17 #include <k32.h>
18
19 #define NDEBUG
20 #include <kernel32/kernel32.h>
21
22 /* GLOBALS *******************************************************************/
23
24 static BOOL IgnoreCtrlEvents = FALSE;
25 static ULONG NrCtrlHandlers = 0;
26 static PHANDLER_ROUTINE* CtrlHandlers = NULL;
27
28 /* Default Console Handler *****************************************************************/
29
30 BOOL WINAPI DefaultConsoleHandler(DWORD Event)
31 {
32 UINT ExitCode;
33 switch(Event)
34 {
35 case CTRL_C_EVENT:
36 DPRINT("Ctrl-C Event\n");
37 // ExitProcess((UINT)&ExitCode);
38 break;
39
40 case CTRL_BREAK_EVENT:
41 DPRINT("Ctrl-Break Event\n");
42 // ExitProcess((UINT&ExitCode);
43 break;
44
45 case CTRL_SHUTDOWN_EVENT:
46 DPRINT("Ctrl Shutdown Event\n");
47 break;
48
49 case CTRL_CLOSE_EVENT:
50 DPRINT("Ctrl Close Event\n");
51 break;
52
53 case CTRL_LOGOFF_EVENT:
54 DPRINT("Ctrl Logoff Event\n");
55 break;
56 }
57 return TRUE;
58 }
59
60 /* FUNCTIONS *****************************************************************/
61
62 /*
63 * @unimplemented
64 */
65 BOOL STDCALL
66 AddConsoleAliasA (LPSTR Source,
67 LPSTR Target,
68 LPSTR ExeName)
69 {
70 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
71 return FALSE;
72 }
73
74
75 /*
76 * @unimplemented
77 */
78 BOOL STDCALL
79 AddConsoleAliasW (LPWSTR Source,
80 LPWSTR Target,
81 LPWSTR ExeName)
82 {
83 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
84 return FALSE;
85 }
86
87
88 /*
89 * @unimplemented
90 */
91 BOOL STDCALL
92 ConsoleMenuControl (HANDLE hConsole,
93 DWORD Unknown1,
94 DWORD Unknown2)
95 /*
96 * Undocumented
97 */
98 {
99 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
100 return FALSE;
101 }
102
103
104 /*
105 * @implemented
106 */
107 HANDLE STDCALL
108 DuplicateConsoleHandle (HANDLE hConsole,
109 DWORD dwDesiredAccess,
110 BOOL bInheritHandle,
111 DWORD dwOptions)
112 {
113 CSRSS_API_REQUEST Request;
114 CSRSS_API_REPLY Reply;
115 NTSTATUS Status;
116
117 if (IsConsoleHandle (hConsole) == FALSE)
118 {
119 SetLastError (ERROR_INVALID_PARAMETER);
120 return INVALID_HANDLE_VALUE;
121 }
122
123 Request.Type = CSRSS_DUPLICATE_HANDLE;
124 Request.Data.DuplicateHandleRequest.Handle = hConsole;
125 Request.Data.DuplicateHandleRequest.ProcessId = GetCurrentProcessId();
126 Status = CsrClientCallServer(&Request,
127 &Reply,
128 sizeof(CSRSS_API_REQUEST),
129 sizeof(CSRSS_API_REPLY));
130 if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status=Reply.Status))
131 {
132 SetLastErrorByStatus(Status);
133 return INVALID_HANDLE_VALUE;
134 }
135 return Reply.Data.DuplicateHandleReply.Handle;
136 }
137
138
139 /*
140 * @unimplemented
141 */
142 DWORD STDCALL
143 ExpungeConsoleCommandHistoryW (DWORD Unknown0)
144 /*
145 * Undocumented
146 */
147 {
148 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
149 return 0;
150 }
151
152
153 /*
154 * @unimplemented
155 */
156 DWORD STDCALL
157 ExpungeConsoleCommandHistoryA (DWORD Unknown0)
158 /*
159 * Undocumented
160 */
161 {
162 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
163 return 0;
164 }
165
166
167 /*
168 * @unimplemented
169 */
170 DWORD STDCALL
171 GetConsoleAliasW (DWORD Unknown0,
172 DWORD Unknown1,
173 DWORD Unknown2,
174 DWORD Unknown3)
175 /*
176 * Undocumented
177 */
178 {
179 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
180 return 0;
181 }
182
183
184 /*
185 * @unimplemented
186 */
187 DWORD STDCALL
188 GetConsoleAliasA (DWORD Unknown0,
189 DWORD Unknown1,
190 DWORD Unknown2,
191 DWORD Unknown3)
192 /*
193 * Undocumented
194 */
195 {
196 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
197 return 0;
198 }
199
200
201 /*
202 * @unimplemented
203 */
204 DWORD STDCALL
205 GetConsoleAliasExesW (DWORD Unknown0,
206 DWORD Unknown1)
207 /*
208 * Undocumented
209 */
210 {
211 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
212 return 0;
213 }
214
215
216 /*
217 * @unimplemented
218 */
219 DWORD STDCALL
220 GetConsoleAliasExesA (DWORD Unknown0,
221 DWORD Unknown1)
222 /*
223 * Undocumented
224 */
225 {
226 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
227 return 0;
228 }
229
230
231 /*
232 * @unimplemented
233 */
234 DWORD STDCALL
235 GetConsoleAliasExesLengthA (VOID)
236 /*
237 * Undocumented
238 */
239 {
240 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
241 return 0;
242 }
243
244
245 /*
246 * @unimplemented
247 */
248 DWORD STDCALL
249 GetConsoleAliasExesLengthW (VOID)
250 /*
251 * Undocumented
252 */
253 {
254 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
255 return 0;
256 }
257
258
259 /*
260 * @unimplemented
261 */
262 DWORD STDCALL
263 GetConsoleAliasesW (DWORD Unknown0,
264 DWORD Unknown1,
265 DWORD Unknown2)
266 /*
267 * Undocumented
268 */
269 {
270 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
271 return 0;
272 }
273
274
275 /*
276 * @unimplemented
277 */
278 DWORD STDCALL
279 GetConsoleAliasesA (DWORD Unknown0,
280 DWORD Unknown1,
281 DWORD Unknown2)
282 /*
283 * Undocumented
284 */
285 {
286 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
287 return 0;
288 }
289
290
291 /*
292 * @unimplemented
293 */
294 DWORD STDCALL
295 GetConsoleAliasesLengthW (DWORD Unknown0)
296 /*
297 * Undocumented
298 */
299 {
300 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
301 return 0;
302 }
303
304
305 /*
306 * @unimplemented
307 */
308 DWORD STDCALL
309 GetConsoleAliasesLengthA (DWORD Unknown0)
310 /*
311 * Undocumented
312 */
313 {
314 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
315 return 0;
316 }
317
318
319 /*
320 * @unimplemented
321 */
322 DWORD STDCALL
323 GetConsoleCommandHistoryW (DWORD Unknown0,
324 DWORD Unknown1,
325 DWORD Unknown2)
326 /*
327 * Undocumented
328 */
329 {
330 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
331 return 0;
332 }
333
334
335 /*
336 * @unimplemented
337 */
338 DWORD STDCALL
339 GetConsoleCommandHistoryA (DWORD Unknown0,
340 DWORD Unknown1,
341 DWORD Unknown2)
342 /*
343 * Undocumented
344 */
345 {
346 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
347 return 0;
348 }
349
350
351 /*
352 * @unimplemented
353 */
354 DWORD STDCALL
355 GetConsoleCommandHistoryLengthW (DWORD Unknown0)
356 /*
357 * Undocumented
358 */
359 {
360 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
361 return 0;
362 }
363
364
365 /*
366 * @unimplemented
367 */
368 DWORD STDCALL
369 GetConsoleCommandHistoryLengthA (DWORD Unknown0)
370 /*
371 * Undocumented
372 */
373 {
374 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
375 return 0;
376 }
377
378 /*
379 * @unimplemented
380 */
381 DWORD STDCALL
382 GetConsoleDisplayMode (LPDWORD lpdwMode)
383 /*
384 * FUNCTION: Get the console display mode
385 * ARGUMENTS:
386 * lpdwMode - Address of variable that receives the current value
387 * of display mode
388 * STATUS: Undocumented
389 */
390 {
391 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
392 return 0;
393 }
394
395
396 /*
397 * @unimplemented
398 */
399 DWORD STDCALL
400 GetConsoleFontInfo (DWORD Unknown0,
401 DWORD Unknown1,
402 DWORD Unknown2,
403 DWORD Unknown3)
404 /*
405 * Undocumented
406 */
407 {
408 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
409 return 0;
410 }
411
412
413 /*
414 * @unimplemented
415 */
416 DWORD STDCALL
417 GetConsoleFontSize(HANDLE hConsoleOutput,
418 DWORD nFont)
419 {
420 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
421 return 0;
422 }
423
424
425 /*
426 * @implemented
427 */
428 DWORD STDCALL
429 GetConsoleHardwareState (HANDLE hConsole,
430 DWORD Flags,
431 PDWORD State)
432 /*
433 * Undocumented
434 */
435 {
436 CSRSS_API_REQUEST Request;
437 CSRSS_API_REPLY Reply;
438 NTSTATUS Status;
439
440 Request.Type = CSRSS_SETGET_CONSOLE_HW_STATE;
441 Request.Data.ConsoleHardwareStateRequest.ConsoleHandle = hConsole;
442 Request.Data.ConsoleHardwareStateRequest.SetGet = CONSOLE_HARDWARE_STATE_GET;
443
444 Status = CsrClientCallServer(& Request,
445 & Reply,
446 sizeof(CSRSS_API_REQUEST),
447 sizeof(CSRSS_API_REPLY));
448 if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
449 {
450 SetLastErrorByStatus(Status);
451 return FALSE;
452 }
453 *State = Reply.Data.ConsoleHardwareStateReply.State;
454 return TRUE;
455 }
456
457
458 /*
459 * @unimplemented
460 */
461 DWORD STDCALL
462 GetConsoleInputWaitHandle (VOID)
463 /*
464 * Undocumented
465 */
466 {
467 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
468 return FALSE;
469 }
470
471
472 /*
473 * @unimplemented
474 */
475 DWORD STDCALL
476 GetCurrentConsoleFont(HANDLE hConsoleOutput,
477 BOOL bMaximumWindow,
478 PCONSOLE_FONT_INFO lpConsoleCurrentFont)
479 {
480 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
481 return 0;
482 }
483
484
485 /*
486 * @unimplemented
487 */
488 ULONG STDCALL
489 GetNumberOfConsoleFonts (VOID)
490 /*
491 * Undocumented
492 */
493 {
494 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
495 return 1; /* FIXME: call csrss.exe */
496 }
497
498
499 /*
500 * @unimplemented
501 */
502 DWORD STDCALL
503 InvalidateConsoleDIBits (DWORD Unknown0,
504 DWORD Unknown1)
505 /*
506 * Undocumented
507 */
508 {
509 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
510 return 0;
511 }
512
513
514 /*
515 * @unimplemented
516 */
517 HANDLE STDCALL
518 OpenConsoleW (LPWSTR wsName,
519 DWORD dwDesiredAccess,
520 BOOL bInheritHandle,
521 DWORD dwCreationDistribution)
522 /*
523 * Undocumented
524 */
525 {
526 CSRSS_API_REQUEST Request;
527 CSRSS_API_REPLY Reply;
528 PHANDLE phConsole = NULL;
529 NTSTATUS Status = STATUS_SUCCESS;
530
531
532 if(0 == _wcsicmp(wsName, L"CONIN$"))
533 {
534 Request.Type = CSRSS_GET_INPUT_HANDLE;
535 phConsole = & Reply.Data.GetInputHandleReply.InputHandle;
536 }
537 else if (0 == _wcsicmp(wsName, L"CONOUT$"))
538 {
539 Request.Type = CSRSS_GET_OUTPUT_HANDLE;
540 phConsole = & Reply.Data.GetOutputHandleReply.OutputHandle;
541 }
542 else
543 {
544 SetLastError(ERROR_INVALID_PARAMETER);
545 return(INVALID_HANDLE_VALUE);
546 }
547 if ((GENERIC_READ|GENERIC_WRITE) != dwDesiredAccess)
548 {
549 SetLastError(ERROR_INVALID_PARAMETER);
550 return(INVALID_HANDLE_VALUE);
551 }
552 if (OPEN_EXISTING != dwCreationDistribution)
553 {
554 SetLastError(ERROR_INVALID_PARAMETER);
555 return(INVALID_HANDLE_VALUE);
556 }
557 Status = CsrClientCallServer(& Request,
558 & Reply,
559 sizeof(CSRSS_API_REQUEST),
560 sizeof(CSRSS_API_REPLY));
561 if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
562 {
563 SetLastErrorByStatus(Status);
564 return INVALID_HANDLE_VALUE;
565 }
566 return(*phConsole);
567 }
568
569
570 /*
571 * @unimplemented
572 */
573 WINBOOL STDCALL
574 SetConsoleCommandHistoryMode (DWORD dwMode)
575 /*
576 * Undocumented
577 */
578 {
579 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
580 return FALSE;
581 }
582
583
584 /*
585 * @unimplemented
586 */
587 WINBOOL STDCALL
588 SetConsoleCursor (DWORD Unknown0,
589 DWORD Unknown1)
590 /*
591 * Undocumented
592 */
593 {
594 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
595 return FALSE;
596 }
597
598
599 /*
600 * @unimplemented
601 */
602 WINBOOL STDCALL
603 SetConsoleDisplayMode (HANDLE hOut,
604 DWORD dwNewMode,
605 LPDWORD lpdwOldMode)
606 /*
607 * FUNCTION: Set the console display mode.
608 * ARGUMENTS:
609 * hOut - Standard output handle.
610 * dwNewMode - New mode.
611 * lpdwOldMode - Address of a variable that receives the old mode.
612 */
613 {
614 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
615 return FALSE;
616 }
617
618
619 /*
620 * @unimplemented
621 */
622 WINBOOL STDCALL
623 SetConsoleFont (DWORD Unknown0,
624 DWORD Unknown1)
625 /*
626 * Undocumented
627 */
628 {
629 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
630 return FALSE;
631 }
632
633
634 /*
635 * @implemented
636 */
637 WINBOOL STDCALL
638 SetConsoleHardwareState (HANDLE hConsole,
639 DWORD Flags,
640 DWORD State)
641 /*
642 * Undocumented
643 */
644 {
645 CSRSS_API_REQUEST Request;
646 CSRSS_API_REPLY Reply;
647 NTSTATUS Status;
648
649 Request.Type = CSRSS_SETGET_CONSOLE_HW_STATE;
650 Request.Data.ConsoleHardwareStateRequest.ConsoleHandle = hConsole;
651 Request.Data.ConsoleHardwareStateRequest.SetGet = CONSOLE_HARDWARE_STATE_SET;
652 Request.Data.ConsoleHardwareStateRequest.State = State;
653
654 Status = CsrClientCallServer(& Request,
655 & Reply,
656 sizeof(CSRSS_API_REQUEST),
657 sizeof(CSRSS_API_REPLY));
658 if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
659 {
660 SetLastErrorByStatus(Status);
661 return FALSE;
662 }
663 return TRUE;
664 }
665
666
667 /*
668 * @unimplemented
669 */
670 WINBOOL STDCALL
671 SetConsoleKeyShortcuts (DWORD Unknown0,
672 DWORD Unknown1,
673 DWORD Unknown2,
674 DWORD Unknown3)
675 /*
676 * Undocumented
677 */
678 {
679 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
680 return FALSE;
681 }
682
683
684 /*
685 * @unimplemented
686 */
687 WINBOOL STDCALL
688 SetConsoleMaximumWindowSize (DWORD Unknown0,
689 DWORD Unknown1)
690 /*
691 * Undocumented
692 */
693 {
694 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
695 return FALSE;
696 }
697
698
699 /*
700 * @unimplemented
701 */
702 WINBOOL STDCALL
703 SetConsoleMenuClose (DWORD Unknown0)
704 /*
705 * Undocumented
706 */
707 {
708 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
709 return FALSE;
710 }
711
712
713 /*
714 * @unimplemented
715 */
716 WINBOOL STDCALL
717 SetConsoleNumberOfCommandsA (DWORD Unknown0,
718 DWORD Unknown1)
719 /*
720 * Undocumented
721 */
722 {
723 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
724 return FALSE;
725 }
726
727
728 /*
729 * @unimplemented
730 */
731 WINBOOL STDCALL
732 SetConsoleNumberOfCommandsW (DWORD Unknown0,
733 DWORD Unknown1)
734 /*
735 * Undocumented
736 */
737 {
738 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
739 return FALSE;
740 }
741
742
743 /*
744 * @unimplemented
745 */
746 WINBOOL STDCALL
747 SetConsolePalette (DWORD Unknown0,
748 DWORD Unknown1,
749 DWORD Unknown2)
750 /*
751 * Undocumented
752 */
753 {
754 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
755 return FALSE;
756 }
757
758
759 /*
760 * @unimplemented
761 */
762 WINBOOL STDCALL
763 SetLastConsoleEventActive (VOID)
764 /*
765 * Undocumented
766 */
767 {
768 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
769 return FALSE;
770 }
771
772
773 /*
774 * @unimplemented
775 */
776 DWORD STDCALL
777 ShowConsoleCursor (DWORD Unknown0,
778 DWORD Unknown1)
779 /*
780 * Undocumented
781 */
782 {
783 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
784 return 0;
785 }
786
787
788 /*
789 * FUNCTION: Checks whether the given handle is a valid console handle.
790 * ARGUMENTS:
791 * Handle - Handle to be checked
792 * RETURNS:
793 * TRUE: Handle is a valid console handle
794 * FALSE: Handle is not a valid console handle.
795 * STATUS: Officially undocumented
796 *
797 * @implemented
798 */
799 BOOL STDCALL
800 VerifyConsoleIoHandle(HANDLE Handle)
801 {
802 CSRSS_API_REQUEST Request;
803 CSRSS_API_REPLY Reply;
804 NTSTATUS Status;
805
806 Request.Type = CSRSS_VERIFY_HANDLE;
807 Request.Data.VerifyHandleRequest.Handle = Handle;
808 Status = CsrClientCallServer(&Request,
809 &Reply,
810 sizeof(CSRSS_API_REQUEST),
811 sizeof(CSRSS_API_REPLY));
812 if (!NT_SUCCESS(Status))
813 {
814 SetLastErrorByStatus(Status);
815 return FALSE;
816 }
817
818 return (BOOL)NT_SUCCESS(Reply.Status);
819 }
820
821
822 /*
823 * @unimplemented
824 */
825 DWORD STDCALL
826 WriteConsoleInputVDMA (DWORD Unknown0,
827 DWORD Unknown1,
828 DWORD Unknown2,
829 DWORD Unknown3)
830 {
831 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
832 return 0;
833 }
834
835
836 /*
837 * @unimplemented
838 */
839 DWORD STDCALL
840 WriteConsoleInputVDMW (DWORD Unknown0,
841 DWORD Unknown1,
842 DWORD Unknown2,
843 DWORD Unknown3)
844 {
845 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
846 return 0;
847 }
848
849
850 /*
851 * @implemented
852 */
853 WINBOOL STDCALL
854 CloseConsoleHandle(HANDLE Handle)
855 /*
856 * Undocumented
857 */
858 {
859 CSRSS_API_REQUEST Request;
860 CSRSS_API_REPLY Reply;
861 NTSTATUS Status;
862
863 if (IsConsoleHandle (Handle) == FALSE)
864 {
865 SetLastError (ERROR_INVALID_PARAMETER);
866 return FALSE;
867 }
868
869 Request.Type = CSRSS_CLOSE_HANDLE;
870 Request.Data.CloseHandleRequest.Handle = Handle;
871 Status = CsrClientCallServer(&Request,
872 &Reply,
873 sizeof(CSRSS_API_REQUEST),
874 sizeof(CSRSS_API_REPLY));
875 if (!NT_SUCCESS(Status))
876 {
877 SetLastErrorByStatus(Status);
878 return FALSE;
879 }
880
881 return TRUE;
882 }
883
884
885 /*
886 * @implemented
887 */
888 BOOLEAN STDCALL
889 IsConsoleHandle(HANDLE Handle)
890 {
891 if ((((ULONG)Handle) & 0x10000003) == 0x3)
892 {
893 return(TRUE);
894 }
895 return(FALSE);
896 }
897
898
899 /*
900 * @implemented
901 */
902 HANDLE STDCALL
903 GetStdHandle(DWORD nStdHandle)
904 /*
905 * FUNCTION: Get a handle for the standard input, standard output
906 * and a standard error device.
907 * ARGUMENTS:
908 * nStdHandle - Specifies the device for which to return the handle.
909 * RETURNS: If the function succeeds, the return value is the handle
910 * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
911 */
912 {
913 PRTL_USER_PROCESS_PARAMETERS Ppb;
914
915 Ppb = NtCurrentPeb()->ProcessParameters;
916 switch (nStdHandle)
917 {
918 case STD_INPUT_HANDLE:
919 return Ppb->hStdInput;
920
921 case STD_OUTPUT_HANDLE:
922 return Ppb->hStdOutput;
923
924 case STD_ERROR_HANDLE:
925 return Ppb->hStdError;
926 }
927
928 SetLastError (ERROR_INVALID_PARAMETER);
929 return INVALID_HANDLE_VALUE;
930 }
931
932
933 /*
934 * @implemented
935 */
936 WINBASEAPI BOOL WINAPI
937 SetStdHandle(DWORD nStdHandle,
938 HANDLE hHandle)
939 /*
940 * FUNCTION: Set the handle for the standard input, standard output or
941 * the standard error device.
942 * ARGUMENTS:
943 * nStdHandle - Specifies the handle to be set.
944 * hHandle - The handle to set.
945 * RETURNS: TRUE if the function succeeds, FALSE otherwise.
946 */
947 {
948 PRTL_USER_PROCESS_PARAMETERS Ppb;
949
950 Ppb = NtCurrentPeb()->ProcessParameters;
951
952 /* More checking needed? */
953 if (hHandle == INVALID_HANDLE_VALUE)
954 {
955 SetLastError (ERROR_INVALID_HANDLE);
956 return FALSE;
957 }
958
959 SetLastError(ERROR_SUCCESS); /* OK */
960
961 switch (nStdHandle)
962 {
963 case STD_INPUT_HANDLE:
964 Ppb->hStdInput = hHandle;
965 return TRUE;
966
967 case STD_OUTPUT_HANDLE:
968 Ppb->hStdOutput = hHandle;
969 return TRUE;
970
971 case STD_ERROR_HANDLE:
972 Ppb->hStdError = hHandle;
973 return TRUE;
974 }
975
976 SetLastError (ERROR_INVALID_PARAMETER);
977 return FALSE;
978 }
979
980
981 /*--------------------------------------------------------------
982 * WriteConsoleA
983 *
984 * @implemented
985 */
986 WINBOOL STDCALL
987 WriteConsoleA(HANDLE hConsoleOutput,
988 CONST VOID *lpBuffer,
989 DWORD nNumberOfCharsToWrite,
990 LPDWORD lpNumberOfCharsWritten,
991 LPVOID lpReserved)
992 {
993 PCSRSS_API_REQUEST Request;
994 CSRSS_API_REPLY Reply;
995 NTSTATUS Status;
996 USHORT Size;
997 ULONG MessageSize;
998
999 Request = RtlAllocateHeap(GetProcessHeap(),
1000 HEAP_ZERO_MEMORY,
1001 sizeof(CSRSS_API_REQUEST) +
1002 CSRSS_MAX_WRITE_CONSOLE_REQUEST);
1003 if (Request == NULL)
1004 {
1005 SetLastError(ERROR_OUTOFMEMORY);
1006 return(FALSE);
1007 }
1008
1009 Request->Type = CSRSS_WRITE_CONSOLE;
1010 Request->Data.WriteConsoleRequest.ConsoleHandle = hConsoleOutput;
1011 if (lpNumberOfCharsWritten != NULL)
1012 *lpNumberOfCharsWritten = nNumberOfCharsToWrite;
1013 while (nNumberOfCharsToWrite)
1014 {
1015 if (nNumberOfCharsToWrite > CSRSS_MAX_WRITE_CONSOLE_REQUEST)
1016 {
1017 Size = CSRSS_MAX_WRITE_CONSOLE_REQUEST;
1018 }
1019 else
1020 {
1021 Size = nNumberOfCharsToWrite;
1022 }
1023 Request->Data.WriteConsoleRequest.NrCharactersToWrite = Size;
1024
1025 memcpy(Request->Data.WriteConsoleRequest.Buffer, lpBuffer, Size);
1026
1027 MessageSize = CSRSS_REQUEST_HEADER_SIZE +
1028 sizeof(CSRSS_WRITE_CONSOLE_REQUEST) + Size;
1029 Status = CsrClientCallServer(Request,
1030 &Reply,
1031 MessageSize,
1032 sizeof(CSRSS_API_REPLY));
1033
1034 if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
1035 {
1036 RtlFreeHeap(GetProcessHeap(), 0, Request);
1037 SetLastErrorByStatus(Status);
1038 return(FALSE);
1039 }
1040 nNumberOfCharsToWrite -= Size;
1041 lpBuffer += Size;
1042 }
1043
1044 RtlFreeHeap(GetProcessHeap(), 0, Request);
1045
1046 return TRUE;
1047 }
1048
1049
1050 /*--------------------------------------------------------------
1051 * ReadConsoleA
1052 *
1053 * @implemented
1054 */
1055 WINBOOL STDCALL ReadConsoleA(HANDLE hConsoleInput,
1056 LPVOID lpBuffer,
1057 DWORD nNumberOfCharsToRead,
1058 LPDWORD lpNumberOfCharsRead,
1059 LPVOID lpReserved)
1060 {
1061 CSRSS_API_REQUEST Request;
1062 PCSRSS_API_REPLY Reply;
1063 NTSTATUS Status;
1064 ULONG CharsRead = 0;
1065
1066 Reply = RtlAllocateHeap(GetProcessHeap(),
1067 HEAP_ZERO_MEMORY,
1068 sizeof(CSRSS_API_REPLY) + nNumberOfCharsToRead);
1069 if (Reply == NULL)
1070 {
1071 SetLastError(ERROR_OUTOFMEMORY);
1072 return(FALSE);
1073 }
1074
1075 Request.Type = CSRSS_READ_CONSOLE;
1076 Request.Data.ReadConsoleRequest.ConsoleHandle = hConsoleInput;
1077 Request.Data.ReadConsoleRequest.NrCharactersToRead = nNumberOfCharsToRead > CSRSS_MAX_READ_CONSOLE_REQUEST ? CSRSS_MAX_READ_CONSOLE_REQUEST : nNumberOfCharsToRead;
1078 Request.Data.ReadConsoleRequest.nCharsCanBeDeleted = 0;
1079 Status = CsrClientCallServer(&Request,
1080 Reply,
1081 sizeof(CSRSS_API_REQUEST),
1082 sizeof(CSRSS_API_REPLY) +
1083 Request.Data.ReadConsoleRequest.NrCharactersToRead);
1084 if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply->Status ))
1085 {
1086 DbgPrint( "CSR returned error in ReadConsole\n" );
1087 SetLastErrorByStatus ( Status );
1088 RtlFreeHeap( GetProcessHeap(), 0, Reply );
1089 return(FALSE);
1090 }
1091 if( Reply->Status == STATUS_NOTIFY_CLEANUP )
1092 Reply->Status = STATUS_PENDING; // ignore backspace because we have no chars to backspace
1093 /* There may not be any chars or lines to read yet, so wait */
1094 while( Reply->Status == STATUS_PENDING )
1095 {
1096 /* some chars may have been returned, but not a whole line yet, so recompute buffer and try again */
1097 nNumberOfCharsToRead -= Reply->Data.ReadConsoleReply.NrCharactersRead;
1098 /* don't overflow caller's buffer, even if you still don't have a complete line */
1099 if( !nNumberOfCharsToRead )
1100 break;
1101 Request.Data.ReadConsoleRequest.NrCharactersToRead = nNumberOfCharsToRead > CSRSS_MAX_READ_CONSOLE_REQUEST ? CSRSS_MAX_READ_CONSOLE_REQUEST : nNumberOfCharsToRead;
1102 /* copy any chars already read to buffer */
1103 memcpy( lpBuffer + CharsRead, Reply->Data.ReadConsoleReply.Buffer, Reply->Data.ReadConsoleReply.NrCharactersRead );
1104 CharsRead += Reply->Data.ReadConsoleReply.NrCharactersRead;
1105 /* wait for csrss to signal there is more data to read, but not if we got STATUS_NOTIFY_CLEANUP for backspace */
1106 Status = NtWaitForSingleObject( Reply->Data.ReadConsoleReply.EventHandle, FALSE, 0 );
1107 if( !NT_SUCCESS( Status ) )
1108 {
1109 DbgPrint( "Wait for console input failed!\n" );
1110 RtlFreeHeap( GetProcessHeap(), 0, Reply );
1111 return FALSE;
1112 }
1113 Request.Data.ReadConsoleRequest.nCharsCanBeDeleted = CharsRead;
1114 Status = CsrClientCallServer( &Request, Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) + Request.Data.ReadConsoleRequest.NrCharactersToRead );
1115 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply->Status ) )
1116 {
1117 SetLastErrorByStatus ( Status );
1118 RtlFreeHeap( GetProcessHeap(), 0, Reply );
1119 return FALSE;
1120 }
1121 if( Reply->Status == STATUS_NOTIFY_CLEANUP )
1122 {
1123 // delete last char
1124 if( CharsRead )
1125 {
1126 CharsRead--;
1127 nNumberOfCharsToRead++;
1128 }
1129 Reply->Status = STATUS_PENDING; // retry
1130 }
1131 }
1132 /* copy data to buffer, count total returned, and return */
1133 memcpy( lpBuffer + CharsRead, Reply->Data.ReadConsoleReply.Buffer, Reply->Data.ReadConsoleReply.NrCharactersRead );
1134 CharsRead += Reply->Data.ReadConsoleReply.NrCharactersRead;
1135 if (lpNumberOfCharsRead != NULL)
1136 *lpNumberOfCharsRead = CharsRead;
1137 RtlFreeHeap(GetProcessHeap(),
1138 0,
1139 Reply);
1140
1141 return(TRUE);
1142 }
1143
1144
1145 /*--------------------------------------------------------------
1146 * AllocConsole
1147 *
1148 * @implemented
1149 */
1150 WINBOOL STDCALL AllocConsole(VOID)
1151 {
1152 CSRSS_API_REQUEST Request;
1153 CSRSS_API_REPLY Reply;
1154 NTSTATUS Status;
1155 HANDLE hStdError;
1156
1157 Request.Type = CSRSS_ALLOC_CONSOLE;
1158 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
1159 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
1160 {
1161 SetLastErrorByStatus ( Status );
1162 return FALSE;
1163 }
1164 SetStdHandle( STD_INPUT_HANDLE, Reply.Data.AllocConsoleReply.InputHandle );
1165 SetStdHandle( STD_OUTPUT_HANDLE, Reply.Data.AllocConsoleReply.OutputHandle );
1166 hStdError = DuplicateConsoleHandle(Reply.Data.AllocConsoleReply.OutputHandle,
1167 0,
1168 TRUE,
1169 DUPLICATE_SAME_ACCESS);
1170 SetStdHandle( STD_ERROR_HANDLE, hStdError );
1171 return TRUE;
1172 }
1173
1174
1175 /*--------------------------------------------------------------
1176 * FreeConsole
1177 *
1178 * @unimplemented
1179 */
1180 WINBOOL STDCALL FreeConsole(VOID)
1181 {
1182 DbgPrint("FreeConsole() is unimplemented\n");
1183 return FALSE;
1184 }
1185
1186
1187 /*--------------------------------------------------------------
1188 * GetConsoleScreenBufferInfo
1189 *
1190 * @implemented
1191 */
1192 WINBOOL
1193 STDCALL
1194 GetConsoleScreenBufferInfo(
1195 HANDLE hConsoleOutput,
1196 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
1197 )
1198 {
1199 CSRSS_API_REQUEST Request;
1200 CSRSS_API_REPLY Reply;
1201 NTSTATUS Status;
1202
1203 Request.Type = CSRSS_SCREEN_BUFFER_INFO;
1204 Request.Data.ScreenBufferInfoRequest.ConsoleHandle = hConsoleOutput;
1205 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
1206 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
1207 {
1208 SetLastErrorByStatus ( Status );
1209 return FALSE;
1210 }
1211 *lpConsoleScreenBufferInfo = Reply.Data.ScreenBufferInfoReply.Info;
1212 return TRUE;
1213 }
1214
1215
1216 /*--------------------------------------------------------------
1217 * SetConsoleCursorPosition
1218 *
1219 * @implemented
1220 */
1221 WINBOOL
1222 STDCALL
1223 SetConsoleCursorPosition(
1224 HANDLE hConsoleOutput,
1225 COORD dwCursorPosition
1226 )
1227 {
1228 CSRSS_API_REQUEST Request;
1229 CSRSS_API_REPLY Reply;
1230 NTSTATUS Status;
1231
1232 Request.Type = CSRSS_SET_CURSOR;
1233 Request.Data.SetCursorRequest.ConsoleHandle = hConsoleOutput;
1234 Request.Data.SetCursorRequest.Position = dwCursorPosition;
1235 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
1236 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
1237 {
1238 SetLastErrorByStatus ( Status );
1239 return FALSE;
1240 }
1241 return TRUE;
1242 }
1243
1244
1245 /*--------------------------------------------------------------
1246 * FillConsoleOutputCharacterA
1247 *
1248 * @implemented
1249 */
1250 WINBOOL STDCALL
1251 FillConsoleOutputCharacterA(
1252 HANDLE hConsoleOutput,
1253 CHAR cCharacter,
1254 DWORD nLength,
1255 COORD dwWriteCoord,
1256 LPDWORD lpNumberOfCharsWritten
1257 )
1258 {
1259 CSRSS_API_REQUEST Request;
1260 CSRSS_API_REPLY Reply;
1261 NTSTATUS Status;
1262
1263 Request.Type = CSRSS_FILL_OUTPUT;
1264 Request.Data.FillOutputRequest.ConsoleHandle = hConsoleOutput;
1265 Request.Data.FillOutputRequest.Char = cCharacter;
1266 Request.Data.FillOutputRequest.Position = dwWriteCoord;
1267 Request.Data.FillOutputRequest.Length = nLength;
1268 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
1269 if ( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
1270 {
1271 SetLastErrorByStatus(Status);
1272 return(FALSE);
1273 }
1274 if (lpNumberOfCharsWritten != NULL)
1275 *lpNumberOfCharsWritten = nLength;
1276 return(TRUE);
1277 }
1278
1279
1280 /*--------------------------------------------------------------
1281 * FillConsoleOutputCharacterW
1282 *
1283 * @unimplemented
1284 */
1285 WINBOOL
1286 STDCALL
1287 FillConsoleOutputCharacterW(
1288 HANDLE hConsoleOutput,
1289 WCHAR cCharacter,
1290 DWORD nLength,
1291 COORD dwWriteCoord,
1292 LPDWORD lpNumberOfCharsWritten
1293 )
1294 {
1295 /* TO DO */
1296 return FALSE;
1297 }
1298
1299
1300 /*--------------------------------------------------------------
1301 * PeekConsoleInputA
1302 *
1303 * @implemented
1304 */
1305 WINBASEAPI
1306 BOOL
1307 WINAPI
1308 PeekConsoleInputA(
1309 HANDLE hConsoleInput,
1310 PINPUT_RECORD lpBuffer,
1311 DWORD nLength,
1312 LPDWORD lpNumberOfEventsRead
1313 )
1314 {
1315 PCSRSS_API_REQUEST Request;
1316 CSRSS_API_REPLY Reply;
1317 NTSTATUS Status;
1318 PVOID BufferBase;
1319 PVOID BufferTargetBase;
1320 DWORD Size;
1321
1322 if(lpBuffer == NULL)
1323 {
1324 SetLastError(ERROR_INVALID_PARAMETER);
1325 return FALSE;
1326 }
1327
1328 Size = nLength * sizeof(INPUT_RECORD);
1329
1330 Status = CsrCaptureParameterBuffer((PVOID)lpBuffer, Size, &BufferBase, &BufferTargetBase);
1331 if(!NT_SUCCESS(Status))
1332 {
1333 SetLastErrorByStatus(Status);
1334 return FALSE;
1335 }
1336
1337 Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CSRSS_API_REQUEST));
1338 if(Request == NULL)
1339 {
1340 CsrReleaseParameterBuffer(BufferBase);
1341 SetLastError(ERROR_OUTOFMEMORY);
1342 return FALSE;
1343 }
1344
1345 Request->Type = CSRSS_PEEK_CONSOLE_INPUT;
1346 Request->Data.PeekConsoleInputRequest.ConsoleHandle = hConsoleInput;
1347 Request->Data.PeekConsoleInputRequest.Length = nLength;
1348 Request->Data.PeekConsoleInputRequest.InputRecord = (INPUT_RECORD*)BufferTargetBase;
1349
1350 Status = CsrClientCallServer(Request, &Reply, sizeof(CSRSS_API_REQUEST), sizeof(CSRSS_API_REPLY));
1351
1352 if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
1353 {
1354 RtlFreeHeap(GetProcessHeap(), 0, Request);
1355 CsrReleaseParameterBuffer(BufferBase);
1356 return FALSE;
1357 }
1358
1359 memcpy(lpBuffer, BufferBase, sizeof(INPUT_RECORD) * Reply.Data.PeekConsoleInputReply.Length);
1360
1361 if(lpNumberOfEventsRead != NULL)
1362 *lpNumberOfEventsRead = Reply.Data.PeekConsoleInputReply.Length;
1363
1364 RtlFreeHeap(GetProcessHeap(), 0, Request);
1365 CsrReleaseParameterBuffer(BufferBase);
1366
1367 return TRUE;
1368 }
1369
1370
1371 /*--------------------------------------------------------------
1372 * PeekConsoleInputW
1373 *
1374 * @unimplemented
1375 */
1376 WINBASEAPI
1377 BOOL
1378 WINAPI
1379 PeekConsoleInputW(
1380 HANDLE hConsoleInput,
1381 PINPUT_RECORD lpBuffer,
1382 DWORD nLength,
1383 LPDWORD lpNumberOfEventsRead
1384 )
1385 {
1386 /* TO DO */
1387 return FALSE;
1388 }
1389
1390
1391 /*--------------------------------------------------------------
1392 * ReadConsoleInputA
1393 *
1394 * @implemented
1395 */
1396 WINBASEAPI BOOL WINAPI
1397 ReadConsoleInputA(HANDLE hConsoleInput,
1398 PINPUT_RECORD lpBuffer,
1399 DWORD nLength,
1400 LPDWORD lpNumberOfEventsRead)
1401 {
1402 CSRSS_API_REQUEST Request;
1403 CSRSS_API_REPLY Reply;
1404 DWORD NumEventsRead;
1405 NTSTATUS Status;
1406
1407 Request.Type = CSRSS_READ_INPUT;
1408 Request.Data.ReadInputRequest.ConsoleHandle = hConsoleInput;
1409 Status = CsrClientCallServer(&Request, &Reply, sizeof(CSRSS_API_REQUEST),
1410 sizeof(CSRSS_API_REPLY));
1411 if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
1412 {
1413 SetLastErrorByStatus(Status);
1414 return(FALSE);
1415 }
1416
1417 while (Status == STATUS_PENDING)
1418 {
1419 Status = NtWaitForSingleObject(Reply.Data.ReadInputReply.Event, FALSE,
1420 0);
1421 if(!NT_SUCCESS(Status))
1422 {
1423 SetLastErrorByStatus(Status);
1424 return FALSE;
1425 }
1426
1427 Request.Type = CSRSS_READ_INPUT;
1428 Request.Data.ReadInputRequest.ConsoleHandle = hConsoleInput;
1429 Status = CsrClientCallServer(&Request, &Reply, sizeof(CSRSS_API_REQUEST),
1430 sizeof(CSRSS_API_REPLY));
1431 if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
1432 {
1433 SetLastErrorByStatus(Status);
1434 return(FALSE);
1435 }
1436 }
1437
1438 NumEventsRead = 0;
1439 *lpBuffer = Reply.Data.ReadInputReply.Input;
1440 lpBuffer++;
1441 NumEventsRead++;
1442
1443 while ((NumEventsRead < nLength) && (Reply.Data.ReadInputReply.MoreEvents))
1444 {
1445 Status = CsrClientCallServer(&Request, &Reply, sizeof(CSRSS_API_REQUEST),
1446 sizeof(CSRSS_API_REPLY));
1447 if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
1448 {
1449 SetLastErrorByStatus(Status);
1450 return(FALSE);
1451 }
1452
1453 if (Status == STATUS_PENDING)
1454 {
1455 break;
1456 }
1457
1458 *lpBuffer = Reply.Data.ReadInputReply.Input;
1459 lpBuffer++;
1460 NumEventsRead++;
1461
1462 }
1463 *lpNumberOfEventsRead = NumEventsRead;
1464
1465 return TRUE;
1466 }
1467
1468
1469 /*--------------------------------------------------------------
1470 * ReadConsoleInputW
1471 *
1472 * @unimplemented
1473 */
1474 WINBASEAPI
1475 BOOL
1476 WINAPI
1477 ReadConsoleInputW(
1478 HANDLE hConsoleInput,
1479 PINPUT_RECORD lpBuffer,
1480 DWORD nLength,
1481 LPDWORD lpNumberOfEventsRead
1482 )
1483 {
1484 /* TO DO */
1485 return FALSE;
1486 }
1487
1488
1489 /*--------------------------------------------------------------
1490 * WriteConsoleInputA
1491 *
1492 * @implemented
1493 */
1494 WINBASEAPI
1495 BOOL
1496 WINAPI
1497 WriteConsoleInputA(
1498 HANDLE hConsoleInput,
1499 CONST INPUT_RECORD *lpBuffer,
1500 DWORD nLength,
1501 LPDWORD lpNumberOfEventsWritten
1502 )
1503 {
1504 PCSRSS_API_REQUEST Request;
1505 CSRSS_API_REPLY Reply;
1506 PVOID BufferBase, BufferTargetBase;
1507 NTSTATUS Status;
1508 DWORD Size;
1509
1510 if(lpBuffer == NULL)
1511 {
1512 SetLastError(ERROR_INVALID_PARAMETER);
1513 return FALSE;
1514 }
1515
1516 Size = nLength * sizeof(INPUT_RECORD);
1517
1518 Status = CsrCaptureParameterBuffer((PVOID)lpBuffer, Size, &BufferBase, &BufferTargetBase);
1519 if(!NT_SUCCESS(Status))
1520 {
1521 SetLastErrorByStatus(Status);
1522 return FALSE;
1523 }
1524
1525 Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CSRSS_API_REQUEST));
1526 if(Request == NULL)
1527 {
1528 SetLastError(ERROR_OUTOFMEMORY);
1529 CsrReleaseParameterBuffer(BufferBase);
1530 return FALSE;
1531 }
1532
1533 Request->Type = CSRSS_WRITE_CONSOLE_INPUT;
1534 Request->Data.WriteConsoleInputRequest.ConsoleHandle = hConsoleInput;
1535 Request->Data.WriteConsoleInputRequest.Length = nLength;
1536 Request->Data.WriteConsoleInputRequest.InputRecord = (PINPUT_RECORD)BufferTargetBase;
1537
1538 Status = CsrClientCallServer(Request, &Reply, sizeof(CSRSS_API_REQUEST), sizeof(CSRSS_API_REPLY));
1539 if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
1540 {
1541 RtlFreeHeap(GetProcessHeap(), 0, Request);
1542 CsrReleaseParameterBuffer(BufferBase);
1543 return FALSE;
1544 }
1545
1546 if(lpNumberOfEventsWritten != NULL)
1547 *lpNumberOfEventsWritten = Reply.Data.WriteConsoleInputReply.Length;
1548
1549 RtlFreeHeap(GetProcessHeap(), 0, Request);
1550 CsrReleaseParameterBuffer(BufferBase);
1551
1552 return TRUE;
1553 }
1554
1555
1556 /*--------------------------------------------------------------
1557 * WriteConsoleInputW
1558 *
1559 * @unimplemented
1560 */
1561 WINBASEAPI
1562 BOOL
1563 WINAPI
1564 WriteConsoleInputW(
1565 HANDLE hConsoleInput,
1566 CONST INPUT_RECORD *lpBuffer,
1567 DWORD nLength,
1568 LPDWORD lpNumberOfEventsWritten
1569 )
1570 {
1571 /* TO DO */
1572 return FALSE;
1573 }
1574
1575
1576 /*--------------------------------------------------------------
1577 * ReadConsoleOutputA
1578 *
1579 * @implemented
1580 */
1581 WINBASEAPI
1582 BOOL
1583 WINAPI
1584 ReadConsoleOutputA(
1585 HANDLE hConsoleOutput,
1586 PCHAR_INFO lpBuffer,
1587 COORD dwBufferSize,
1588 COORD dwBufferCoord,
1589 PSMALL_RECT lpReadRegion
1590 )
1591 {
1592 PCSRSS_API_REQUEST Request;
1593 CSRSS_API_REPLY Reply;
1594 PVOID BufferBase;
1595 PVOID BufferTargetBase;
1596 NTSTATUS Status;
1597 DWORD Size, SizeX, SizeY;
1598
1599 if(lpBuffer == NULL)
1600 {
1601 SetLastError(ERROR_INVALID_PARAMETER);
1602 return FALSE;
1603 }
1604
1605 Size = dwBufferSize.X * dwBufferSize.Y * sizeof(CHAR_INFO);
1606
1607 Status = CsrCaptureParameterBuffer((PVOID)lpBuffer, Size, &BufferBase, &BufferTargetBase);
1608 if(!NT_SUCCESS(Status))
1609 {
1610 SetLastErrorByStatus(Status);
1611 return FALSE;
1612 }
1613
1614 Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CSRSS_API_REQUEST));
1615 if(Request == NULL)
1616 {
1617 SetLastError(ERROR_OUTOFMEMORY);
1618 CsrReleaseParameterBuffer(BufferBase);
1619 return FALSE;
1620 }
1621
1622 Request->Type = CSRSS_READ_CONSOLE_OUTPUT;
1623 Request->Data.ReadConsoleOutputRequest.ConsoleHandle = hConsoleOutput;
1624 Request->Data.ReadConsoleOutputRequest.BufferSize = dwBufferSize;
1625 Request->Data.ReadConsoleOutputRequest.BufferCoord = dwBufferCoord;
1626 Request->Data.ReadConsoleOutputRequest.ReadRegion = *lpReadRegion;
1627 Request->Data.ReadConsoleOutputRequest.CharInfo = (PCHAR_INFO)BufferTargetBase;
1628
1629 Status = CsrClientCallServer(Request, &Reply, sizeof(CSRSS_API_REQUEST), sizeof(CSRSS_API_REPLY));
1630 if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
1631 {
1632 SetLastErrorByStatus(Status);
1633 RtlFreeHeap(GetProcessHeap(), 0, Request);
1634 CsrReleaseParameterBuffer(BufferBase);
1635 return FALSE;
1636 }
1637
1638 SizeX = Reply.Data.ReadConsoleOutputReply.ReadRegion.Right - Reply.Data.ReadConsoleOutputReply.ReadRegion.Left + 1;
1639 SizeY = Reply.Data.ReadConsoleOutputReply.ReadRegion.Bottom - Reply.Data.ReadConsoleOutputReply.ReadRegion.Top + 1;
1640
1641 memcpy(lpBuffer, BufferBase, sizeof(CHAR_INFO) * SizeX * SizeY);
1642 *lpReadRegion = Reply.Data.ReadConsoleOutputReply.ReadRegion;
1643
1644 RtlFreeHeap(GetProcessHeap(), 0, Request);
1645 CsrReleaseParameterBuffer(BufferBase);
1646
1647 return TRUE;
1648 }
1649
1650
1651 /*--------------------------------------------------------------
1652 * ReadConsoleOutputW
1653 *
1654 * @unimplemented
1655 */
1656 WINBASEAPI
1657 BOOL
1658 WINAPI
1659 ReadConsoleOutputW(
1660 HANDLE hConsoleOutput,
1661 PCHAR_INFO lpBuffer,
1662 COORD dwBufferSize,
1663 COORD dwBufferCoord,
1664 PSMALL_RECT lpReadRegion
1665 )
1666 {
1667 /* TO DO */
1668 return FALSE;
1669 }
1670
1671 /*--------------------------------------------------------------
1672 * WriteConsoleOutputA
1673 *
1674 * @implemented
1675 */
1676 WINBASEAPI BOOL WINAPI
1677 WriteConsoleOutputA(HANDLE hConsoleOutput,
1678 CONST CHAR_INFO *lpBuffer,
1679 COORD dwBufferSize,
1680 COORD dwBufferCoord,
1681 PSMALL_RECT lpWriteRegion)
1682 {
1683 PCSRSS_API_REQUEST Request;
1684 CSRSS_API_REPLY Reply;
1685 NTSTATUS Status;
1686 ULONG Size;
1687 BOOLEAN Result;
1688 ULONG i, j;
1689 PVOID BufferBase;
1690 PVOID BufferTargetBase;
1691
1692 Size = dwBufferSize.Y * dwBufferSize.X * sizeof(CHAR_INFO);
1693
1694 Status = CsrCaptureParameterBuffer((PVOID)lpBuffer,
1695 Size,
1696 &BufferBase,
1697 &BufferTargetBase);
1698 if (!NT_SUCCESS(Status))
1699 {
1700 SetLastErrorByStatus(Status);
1701 return(FALSE);
1702 }
1703
1704 Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY,
1705 sizeof(CSRSS_API_REQUEST));
1706 if (Request == NULL)
1707 {
1708 CsrReleaseParameterBuffer(BufferBase);
1709 SetLastError(ERROR_OUTOFMEMORY);
1710 return FALSE;
1711 }
1712 Request->Type = CSRSS_WRITE_CONSOLE_OUTPUT;
1713 Request->Data.WriteConsoleOutputRequest.ConsoleHandle = hConsoleOutput;
1714 Request->Data.WriteConsoleOutputRequest.BufferSize = dwBufferSize;
1715 Request->Data.WriteConsoleOutputRequest.BufferCoord = dwBufferCoord;
1716 Request->Data.WriteConsoleOutputRequest.WriteRegion = *lpWriteRegion;
1717 Request->Data.WriteConsoleOutputRequest.CharInfo =
1718 (CHAR_INFO*)BufferTargetBase;
1719
1720 Status = CsrClientCallServer(Request, &Reply,
1721 sizeof(CSRSS_API_REQUEST),
1722 sizeof(CSRSS_API_REPLY));
1723 if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
1724 {
1725 CsrReleaseParameterBuffer(BufferBase);
1726 RtlFreeHeap(GetProcessHeap(), 0, Request);
1727 SetLastErrorByStatus(Status);
1728 return FALSE;
1729 }
1730
1731 *lpWriteRegion = Reply.Data.WriteConsoleOutputReply.WriteRegion;
1732 RtlFreeHeap(GetProcessHeap(), 0, Request);
1733 CsrReleaseParameterBuffer(BufferBase);
1734 return(TRUE);
1735 }
1736
1737
1738 /*--------------------------------------------------------------
1739 * WriteConsoleOutputW
1740 *
1741 * @unimplemented
1742 */
1743 WINBASEAPI
1744 BOOL
1745 WINAPI
1746 WriteConsoleOutputW(
1747 HANDLE hConsoleOutput,
1748 CONST CHAR_INFO *lpBuffer,
1749 COORD dwBufferSize,
1750 COORD dwBufferCoord,
1751 PSMALL_RECT lpWriteRegion
1752 )
1753 {
1754 /* TO DO */
1755 return FALSE;
1756 }
1757
1758
1759 /*--------------------------------------------------------------
1760 * ReadConsoleOutputCharacterA
1761 *
1762 * @implemented
1763 */
1764 WINBASEAPI
1765 BOOL
1766 WINAPI
1767 ReadConsoleOutputCharacterA(
1768 HANDLE hConsoleOutput,
1769 LPSTR lpCharacter,
1770 DWORD nLength,
1771 COORD dwReadCoord,
1772 LPDWORD lpNumberOfCharsRead
1773 )
1774 {
1775 CSRSS_API_REQUEST Request;
1776 PCSRSS_API_REPLY Reply;
1777 NTSTATUS Status;
1778 DWORD Size;
1779
1780 Reply = RtlAllocateHeap(GetProcessHeap(),
1781 HEAP_ZERO_MEMORY,
1782 sizeof(CSRSS_API_REPLY) + CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR);
1783 if (Reply == NULL)
1784 {
1785 SetLastError(ERROR_OUTOFMEMORY);
1786 return(FALSE);
1787 }
1788
1789 if (lpNumberOfCharsRead != NULL)
1790 *lpNumberOfCharsRead = nLength;
1791
1792 Request.Type = CSRSS_READ_CONSOLE_OUTPUT_CHAR;
1793 Request.Data.ReadConsoleOutputCharRequest.ConsoleHandle = hConsoleOutput;
1794 Request.Data.ReadConsoleOutputCharRequest.ReadCoord = dwReadCoord;
1795
1796 while (nLength != 0)
1797 {
1798 if (nLength > CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR)
1799 Size = CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR;
1800 else
1801 Size = nLength;
1802
1803 Request.Data.ReadConsoleOutputCharRequest.NumCharsToRead = Size;
1804
1805 Status = CsrClientCallServer(&Request,
1806 Reply,
1807 sizeof(CSRSS_API_REQUEST),
1808 sizeof(CSRSS_API_REPLY) + Size);
1809 if (!NT_SUCCESS(Status) || !NT_SUCCESS(Reply->Status))
1810 {
1811 RtlFreeHeap(GetProcessHeap(), 0, Reply);
1812 SetLastErrorByStatus(Status);
1813 return(FALSE);
1814 }
1815
1816 memcpy(lpCharacter, &Reply->Data.ReadConsoleOutputCharReply.String[0], Size);
1817 lpCharacter += Size;
1818 nLength -= Size;
1819 Request.Data.ReadConsoleOutputCharRequest.ReadCoord = Reply->Data.ReadConsoleOutputCharReply.EndCoord;
1820 }
1821
1822 RtlFreeHeap(GetProcessHeap(), 0, Reply);
1823
1824 return(TRUE);
1825 }
1826
1827
1828 /*--------------------------------------------------------------
1829 * ReadConsoleOutputCharacterW
1830 *
1831 * @unimplemented
1832 */
1833 WINBASEAPI
1834 BOOL
1835 WINAPI
1836 ReadConsoleOutputCharacterW(
1837 HANDLE hConsoleOutput,
1838 LPWSTR lpCharacter,
1839 DWORD nLength,
1840 COORD dwReadCoord,
1841 LPDWORD lpNumberOfCharsRead
1842 )
1843 {
1844 /* TO DO */
1845 return FALSE;
1846 }
1847
1848
1849 /*--------------------------------------------------------------
1850 * ReadConsoleOutputAttribute
1851 *
1852 * @implemented
1853 */
1854 WINBASEAPI
1855 BOOL
1856 WINAPI
1857 ReadConsoleOutputAttribute(
1858 HANDLE hConsoleOutput,
1859 LPWORD lpAttribute,
1860 DWORD nLength,
1861 COORD dwReadCoord,
1862 LPDWORD lpNumberOfAttrsRead
1863 )
1864 {
1865 CSRSS_API_REQUEST Request;
1866 PCSRSS_API_REPLY Reply;
1867 NTSTATUS Status;
1868 DWORD Size, i;
1869
1870 Reply = RtlAllocateHeap(GetProcessHeap(),
1871 HEAP_ZERO_MEMORY,
1872 sizeof(CSRSS_API_REPLY) + CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB);
1873 if (Reply == NULL)
1874 {
1875 SetLastError(ERROR_OUTOFMEMORY);
1876 return(FALSE);
1877 }
1878
1879 if (lpNumberOfAttrsRead != NULL)
1880 *lpNumberOfAttrsRead = nLength;
1881
1882 Request.Type = CSRSS_READ_CONSOLE_OUTPUT_ATTRIB;
1883 Request.Data.ReadConsoleOutputAttribRequest.ConsoleHandle = hConsoleOutput;
1884 Request.Data.ReadConsoleOutputAttribRequest.ReadCoord = dwReadCoord;
1885
1886 while (nLength != 0)
1887 {
1888 if (nLength > CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB)
1889 Size = CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB;
1890 else
1891 Size = nLength;
1892
1893 Request.Data.ReadConsoleOutputAttribRequest.NumAttrsToRead = Size;
1894
1895 Status = CsrClientCallServer(&Request,
1896 Reply,
1897 sizeof(CSRSS_API_REQUEST),
1898 sizeof(CSRSS_API_REPLY) + Size);
1899 if (!NT_SUCCESS(Status) || !NT_SUCCESS(Reply->Status))
1900 {
1901 RtlFreeHeap(GetProcessHeap(), 0, Reply);
1902 SetLastErrorByStatus(Status);
1903 return(FALSE);
1904 }
1905
1906 // Convert CHARs to WORDs
1907 for(i = 0; i < Size; ++i)
1908 *lpAttribute++ = Reply->Data.ReadConsoleOutputAttribReply.String[i];
1909
1910 nLength -= Size;
1911 Request.Data.ReadConsoleOutputAttribRequest.ReadCoord = Reply->Data.ReadConsoleOutputAttribReply.EndCoord;
1912 }
1913
1914 RtlFreeHeap(GetProcessHeap(), 0, Reply);
1915
1916 return(TRUE);
1917 }
1918
1919
1920 /*--------------------------------------------------------------
1921 * WriteConsoleOutputCharacterA
1922 *
1923 * @implemented
1924 */
1925 WINBASEAPI BOOL WINAPI
1926 WriteConsoleOutputCharacterA(HANDLE hConsoleOutput,
1927 LPCSTR lpCharacter,
1928 DWORD nLength,
1929 COORD dwWriteCoord,
1930 LPDWORD lpNumberOfCharsWritten)
1931 {
1932 PCSRSS_API_REQUEST Request;
1933 CSRSS_API_REPLY Reply;
1934 NTSTATUS Status;
1935 WORD Size;
1936
1937 Request = RtlAllocateHeap(GetProcessHeap(),
1938 HEAP_ZERO_MEMORY,
1939 sizeof(CSRSS_API_REQUEST) + CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR);
1940 if( !Request )
1941 {
1942 SetLastError( ERROR_OUTOFMEMORY );
1943 return FALSE;
1944 }
1945 Request->Type = CSRSS_WRITE_CONSOLE_OUTPUT_CHAR;
1946 Request->Data.WriteConsoleOutputCharRequest.ConsoleHandle = hConsoleOutput;
1947 Request->Data.WriteConsoleOutputCharRequest.Coord = dwWriteCoord;
1948 if( lpNumberOfCharsWritten )
1949 *lpNumberOfCharsWritten = nLength;
1950 while( nLength )
1951 {
1952 Size = nLength > CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR ? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR : nLength;
1953 Request->Data.WriteConsoleOutputCharRequest.Length = Size;
1954 memcpy( &Request->Data.WriteConsoleOutputCharRequest.String[0],
1955 lpCharacter,
1956 Size );
1957 Status = CsrClientCallServer( Request, &Reply, sizeof( CSRSS_API_REQUEST ) + Size, sizeof( CSRSS_API_REPLY ) );
1958 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
1959 {
1960 RtlFreeHeap( GetProcessHeap(), 0, Request );
1961 SetLastErrorByStatus ( Status );
1962 return FALSE;
1963 }
1964 nLength -= Size;
1965 lpCharacter += Size;
1966 Request->Data.WriteConsoleOutputCharRequest.Coord = Reply.Data.WriteConsoleOutputCharReply.EndCoord;
1967 }
1968
1969 RtlFreeHeap( GetProcessHeap(), 0, Request );
1970 return TRUE;
1971 }
1972
1973
1974 /*--------------------------------------------------------------
1975 * WriteConsoleOutputCharacterW
1976 *
1977 * @implemented
1978 */
1979 WINBASEAPI BOOL WINAPI
1980 WriteConsoleOutputCharacterW(HANDLE hConsoleOutput,
1981 LPCWSTR lpCharacter,
1982 DWORD nLength,
1983 COORD dwWriteCoord,
1984 LPDWORD lpNumberOfCharsWritten)
1985 {
1986 PCSRSS_API_REQUEST Request;
1987 CSRSS_API_REPLY Reply;
1988 NTSTATUS Status;
1989 WORD Size;
1990
1991 Request = RtlAllocateHeap(GetProcessHeap(),
1992 HEAP_ZERO_MEMORY,
1993 sizeof(CSRSS_API_REQUEST) + CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR);
1994 if( !Request )
1995 {
1996 SetLastError( ERROR_OUTOFMEMORY );
1997 return FALSE;
1998 }
1999 Request->Type = CSRSS_WRITE_CONSOLE_OUTPUT_CHAR;
2000 Request->Data.WriteConsoleOutputCharRequest.ConsoleHandle = hConsoleOutput;
2001 Request->Data.WriteConsoleOutputCharRequest.Coord = dwWriteCoord;
2002 if( lpNumberOfCharsWritten )
2003 *lpNumberOfCharsWritten = nLength;
2004 while( nLength )
2005 {
2006 Size = nLength > CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR ? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR : nLength;
2007 Request->Data.WriteConsoleOutputCharRequest.Length = Size;
2008 Status = RtlUnicodeToOemN (&Request->Data.WriteConsoleOutputCharRequest.String[0],
2009 Size,
2010 NULL,
2011 (PWCHAR)lpCharacter,
2012 Size * sizeof(WCHAR));
2013 if (!NT_SUCCESS(Status))
2014 {
2015 RtlFreeHeap (GetProcessHeap(), 0, Request);
2016 SetLastErrorByStatus (Status);
2017 return FALSE;
2018 }
2019
2020 Status = CsrClientCallServer( Request, &Reply, sizeof( CSRSS_API_REQUEST ) + Size, sizeof( CSRSS_API_REPLY ) );
2021 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
2022 {
2023 RtlFreeHeap( GetProcessHeap(), 0, Request );
2024 SetLastErrorByStatus ( Status );
2025 return FALSE;
2026 }
2027 nLength -= Size;
2028 lpCharacter += Size;
2029 Request->Data.WriteConsoleOutputCharRequest.Coord = Reply.Data.WriteConsoleOutputCharReply.EndCoord;
2030 }
2031
2032 RtlFreeHeap( GetProcessHeap(), 0, Request );
2033 return TRUE;
2034 }
2035
2036
2037 /*--------------------------------------------------------------
2038 * WriteConsoleOutputAttribute
2039 *
2040 * @implemented
2041 */
2042 WINBASEAPI
2043 BOOL
2044 WINAPI
2045 WriteConsoleOutputAttribute(
2046 HANDLE hConsoleOutput,
2047 CONST WORD *lpAttribute,
2048 DWORD nLength,
2049 COORD dwWriteCoord,
2050 LPDWORD lpNumberOfAttrsWritten
2051 )
2052 {
2053 PCSRSS_API_REQUEST Request;
2054 CSRSS_API_REPLY Reply;
2055 NTSTATUS Status;
2056 WORD Size;
2057 int c;
2058
2059 Request = RtlAllocateHeap(GetProcessHeap(),
2060 HEAP_ZERO_MEMORY,
2061 sizeof(CSRSS_API_REQUEST) + CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB);
2062 if( !Request )
2063 {
2064 SetLastError( ERROR_OUTOFMEMORY );
2065 return FALSE;
2066 }
2067 Request->Type = CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB;
2068 Request->Data.WriteConsoleOutputAttribRequest.ConsoleHandle = hConsoleOutput;
2069 Request->Data.WriteConsoleOutputAttribRequest.Coord = dwWriteCoord;
2070 if( lpNumberOfAttrsWritten )
2071 *lpNumberOfAttrsWritten = nLength;
2072 while( nLength )
2073 {
2074 Size = nLength > CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB ? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB : nLength;
2075 Request->Data.WriteConsoleOutputAttribRequest.Length = Size;
2076 for( c = 0; c < ( Size * 2 ); c++ )
2077 Request->Data.WriteConsoleOutputAttribRequest.String[c] = (char)lpAttribute[c];
2078 Status = CsrClientCallServer( Request, &Reply, sizeof( CSRSS_API_REQUEST ) + (Size * 2), sizeof( CSRSS_API_REPLY ) );
2079 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
2080 {
2081 RtlFreeHeap( GetProcessHeap(), 0, Request );
2082 SetLastErrorByStatus ( Status );
2083 return FALSE;
2084 }
2085 nLength -= Size;
2086 lpAttribute += Size;
2087 Request->Data.WriteConsoleOutputAttribRequest.Coord = Reply.Data.WriteConsoleOutputAttribReply.EndCoord;
2088 }
2089
2090 RtlFreeHeap( GetProcessHeap(), 0, Request );
2091 return TRUE;
2092 }
2093
2094
2095 /*--------------------------------------------------------------
2096 * FillConsoleOutputAttribute
2097 *
2098 * @implemented
2099 */
2100 WINBASEAPI
2101 BOOL
2102 WINAPI
2103 FillConsoleOutputAttribute(
2104 HANDLE hConsoleOutput,
2105 WORD wAttribute,
2106 DWORD nLength,
2107 COORD dwWriteCoord,
2108 LPDWORD lpNumberOfAttrsWritten
2109 )
2110 {
2111 CSRSS_API_REQUEST Request;
2112 CSRSS_API_REPLY Reply;
2113 NTSTATUS Status;
2114
2115 Request.Type = CSRSS_FILL_OUTPUT_ATTRIB;
2116 Request.Data.FillOutputAttribRequest.ConsoleHandle = hConsoleOutput;
2117 Request.Data.FillOutputAttribRequest.Attribute = wAttribute;
2118 Request.Data.FillOutputAttribRequest.Coord = dwWriteCoord;
2119 Request.Data.FillOutputAttribRequest.Length = nLength;
2120 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
2121 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
2122 {
2123 SetLastErrorByStatus ( Status );
2124 return FALSE;
2125 }
2126 if( lpNumberOfAttrsWritten )
2127 *lpNumberOfAttrsWritten = nLength;
2128 return TRUE;
2129 }
2130
2131
2132 /*--------------------------------------------------------------
2133 * GetConsoleMode
2134 *
2135 * @implemented
2136 */
2137 WINBASEAPI
2138 BOOL
2139 WINAPI
2140 GetConsoleMode(
2141 HANDLE hConsoleHandle,
2142 LPDWORD lpMode
2143 )
2144 {
2145 CSRSS_API_REQUEST Request;
2146 CSRSS_API_REPLY Reply;
2147 NTSTATUS Status;
2148
2149 Request.Type = CSRSS_GET_MODE;
2150 Request.Data.GetConsoleModeRequest.ConsoleHandle = hConsoleHandle;
2151 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
2152 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
2153 {
2154 SetLastErrorByStatus ( Status );
2155 return FALSE;
2156 }
2157 *lpMode = Reply.Data.GetConsoleModeReply.ConsoleMode;
2158 return TRUE;
2159 }
2160
2161
2162 /*--------------------------------------------------------------
2163 * GetNumberOfConsoleInputEvents
2164 *
2165 * @implemented
2166 */
2167 WINBASEAPI
2168 BOOL
2169 WINAPI
2170 GetNumberOfConsoleInputEvents(
2171 HANDLE hConsoleInput,
2172 LPDWORD lpNumberOfEvents
2173 )
2174 {
2175 CSRSS_API_REQUEST Request;
2176 CSRSS_API_REPLY Reply;
2177 NTSTATUS Status;
2178
2179 if(lpNumberOfEvents == NULL)
2180 {
2181 SetLastError(ERROR_INVALID_PARAMETER);
2182 return FALSE;
2183 }
2184
2185 Request.Type = CSRSS_GET_NUM_INPUT_EVENTS;
2186 Request.Data.GetNumInputEventsRequest.ConsoleHandle = hConsoleInput;
2187 Status = CsrClientCallServer(&Request, &Reply, sizeof(CSRSS_API_REQUEST), sizeof(CSRSS_API_REPLY));
2188 if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
2189 {
2190 SetLastErrorByStatus(Status);
2191 return FALSE;
2192 }
2193
2194 *lpNumberOfEvents = Reply.Data.GetNumInputEventsReply.NumInputEvents;
2195
2196 return TRUE;
2197 }
2198
2199
2200 /*--------------------------------------------------------------
2201 * GetLargestConsoleWindowSize
2202 *
2203 * @unimplemented
2204 */
2205 WINBASEAPI
2206 COORD
2207 WINAPI
2208 GetLargestConsoleWindowSize(
2209 HANDLE hConsoleOutput
2210 )
2211 {
2212 #if 1 /* FIXME: */
2213 COORD Coord = {80,25};
2214
2215 /* TO DO */
2216 return Coord;
2217 #endif
2218 }
2219
2220
2221 /*--------------------------------------------------------------
2222 * GetConsoleCursorInfo
2223 *
2224 * @implemented
2225 */
2226 WINBASEAPI
2227 BOOL
2228 WINAPI
2229 GetConsoleCursorInfo(
2230 HANDLE hConsoleOutput,
2231 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
2232 )
2233 {
2234 CSRSS_API_REQUEST Request;
2235 CSRSS_API_REPLY Reply;
2236 NTSTATUS Status;
2237
2238 Request.Type = CSRSS_GET_CURSOR_INFO;
2239 Request.Data.GetCursorInfoRequest.ConsoleHandle = hConsoleOutput;
2240 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
2241
2242 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
2243 {
2244 SetLastErrorByStatus ( Status );
2245 return FALSE;
2246 }
2247 *lpConsoleCursorInfo = Reply.Data.GetCursorInfoReply.Info;
2248 return TRUE;
2249 }
2250
2251
2252 /*--------------------------------------------------------------
2253 * GetNumberOfConsoleMouseButtons
2254 *
2255 * @unimplemented
2256 */
2257 WINBASEAPI
2258 BOOL
2259 WINAPI
2260 GetNumberOfConsoleMouseButtons(
2261 LPDWORD lpNumberOfMouseButtons
2262 )
2263 {
2264 /* TO DO */
2265 return FALSE;
2266 }
2267
2268
2269 /*--------------------------------------------------------------
2270 * SetConsoleMode
2271 *
2272 * @implemented
2273 */
2274 WINBASEAPI
2275 BOOL
2276 WINAPI
2277 SetConsoleMode(
2278 HANDLE hConsoleHandle,
2279 DWORD dwMode
2280 )
2281 {
2282 CSRSS_API_REQUEST Request;
2283 CSRSS_API_REPLY Reply;
2284 NTSTATUS Status;
2285
2286 Request.Type = CSRSS_SET_MODE;
2287 Request.Data.SetConsoleModeRequest.ConsoleHandle = hConsoleHandle;
2288 Request.Data.SetConsoleModeRequest.Mode = dwMode;
2289 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
2290 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
2291 {
2292 SetLastErrorByStatus ( Status );
2293 return FALSE;
2294 }
2295 return TRUE;
2296 }
2297
2298
2299 /*--------------------------------------------------------------
2300 * SetConsoleActiveScreenBuffer
2301 *
2302 * @implemented
2303 */
2304 WINBASEAPI
2305 BOOL
2306 WINAPI
2307 SetConsoleActiveScreenBuffer(
2308 HANDLE hConsoleOutput
2309 )
2310 {
2311 CSRSS_API_REQUEST Request;
2312 CSRSS_API_REPLY Reply;
2313 NTSTATUS Status;
2314
2315 Request.Type = CSRSS_SET_SCREEN_BUFFER;
2316 Request.Data.SetActiveScreenBufferRequest.OutputHandle = hConsoleOutput;
2317 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
2318 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
2319 {
2320 SetLastErrorByStatus ( Status );
2321 return FALSE;
2322 }
2323 return TRUE;
2324 }
2325
2326
2327 /*--------------------------------------------------------------
2328 * FlushConsoleInputBuffer
2329 *
2330 * @implemented
2331 */
2332 WINBASEAPI
2333 BOOL
2334 WINAPI
2335 FlushConsoleInputBuffer(
2336 HANDLE hConsoleInput
2337 )
2338 {
2339 CSRSS_API_REQUEST Request;
2340 CSRSS_API_REPLY Reply;
2341 NTSTATUS Status;
2342
2343 Request.Type = CSRSS_FLUSH_INPUT_BUFFER;
2344 Request.Data.FlushInputBufferRequest.ConsoleInput = hConsoleInput;
2345 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
2346 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
2347 {
2348 SetLastErrorByStatus ( Status );
2349 return FALSE;
2350 }
2351 return TRUE;
2352 }
2353
2354
2355 /*--------------------------------------------------------------
2356 * SetConsoleScreenBufferSize
2357 *
2358 * @unimplemented
2359 */
2360 WINBASEAPI
2361 BOOL
2362 WINAPI
2363 SetConsoleScreenBufferSize(
2364 HANDLE hConsoleOutput,
2365 COORD dwSize
2366 )
2367 {
2368 /* TO DO */
2369 return FALSE;
2370 }
2371
2372 /*--------------------------------------------------------------
2373 * SetConsoleCursorInfo
2374 *
2375 * @implemented
2376 */
2377 WINBASEAPI
2378 BOOL
2379 WINAPI
2380 SetConsoleCursorInfo(
2381 HANDLE hConsoleOutput,
2382 CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo
2383 )
2384 {
2385 CSRSS_API_REQUEST Request;
2386 CSRSS_API_REPLY Reply;
2387 NTSTATUS Status;
2388
2389 Request.Type = CSRSS_SET_CURSOR_INFO;
2390 Request.Data.SetCursorInfoRequest.ConsoleHandle = hConsoleOutput;
2391 Request.Data.SetCursorInfoRequest.Info = *lpConsoleCursorInfo;
2392 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
2393
2394 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
2395 {
2396 SetLastErrorByStatus ( Status );
2397 return FALSE;
2398 }
2399 return TRUE;
2400 }
2401
2402
2403 /*--------------------------------------------------------------
2404 * ScrollConsoleScreenBufferA
2405 *
2406 * @implemented
2407 */
2408 WINBASEAPI
2409 BOOL
2410 WINAPI
2411 ScrollConsoleScreenBufferA(
2412 HANDLE hConsoleOutput,
2413 CONST SMALL_RECT *lpScrollRectangle,
2414 CONST SMALL_RECT *lpClipRectangle,
2415 COORD dwDestinationOrigin,
2416 CONST CHAR_INFO *lpFill
2417 )
2418 {
2419 CSRSS_API_REQUEST Request;
2420 CSRSS_API_REPLY Reply;
2421 NTSTATUS Status;
2422
2423 Request.Type = CSRSS_SCROLL_CONSOLE_SCREEN_BUFFER;
2424 Request.Data.ScrollConsoleScreenBufferRequest.ConsoleHandle = hConsoleOutput;
2425 Request.Data.ScrollConsoleScreenBufferRequest.ScrollRectangle = *lpScrollRectangle;
2426
2427 if (lpClipRectangle != NULL)
2428 {
2429 Request.Data.ScrollConsoleScreenBufferRequest.UseClipRectangle = TRUE;
2430 Request.Data.ScrollConsoleScreenBufferRequest.ClipRectangle = *lpClipRectangle;
2431 }
2432 else
2433 {
2434 Request.Data.ScrollConsoleScreenBufferRequest.UseClipRectangle = FALSE;
2435 }
2436
2437 Request.Data.ScrollConsoleScreenBufferRequest.DestinationOrigin = dwDestinationOrigin;
2438 Request.Data.ScrollConsoleScreenBufferRequest.Fill = *lpFill;
2439 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
2440
2441 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
2442 {
2443 SetLastErrorByStatus ( Status );
2444 return FALSE;
2445 }
2446 return TRUE;
2447 }
2448
2449
2450 /*--------------------------------------------------------------
2451 * ScrollConsoleScreenBufferW
2452 *
2453 * @unimplemented
2454 */
2455 WINBASEAPI
2456 BOOL
2457 WINAPI
2458 ScrollConsoleScreenBufferW(
2459 HANDLE hConsoleOutput,
2460 CONST SMALL_RECT *lpScrollRectangle,
2461 CONST SMALL_RECT *lpClipRectangle,
2462 COORD dwDestinationOrigin,
2463 CONST CHAR_INFO *lpFill
2464 )
2465 {
2466 /* TO DO */
2467 return FALSE;
2468 }
2469
2470
2471 /*--------------------------------------------------------------
2472 * SetConsoleWindowInfo
2473 *
2474 * @unimplemented
2475 */
2476 WINBASEAPI
2477 BOOL
2478 WINAPI
2479 SetConsoleWindowInfo(
2480 HANDLE hConsoleOutput,
2481 BOOL bAbsolute,
2482 CONST SMALL_RECT *lpConsoleWindow
2483 )
2484 {
2485 /* TO DO */
2486 return FALSE;
2487 }
2488
2489
2490 /*--------------------------------------------------------------
2491 * SetConsoleTextAttribute
2492 *
2493 * @implemented
2494 */
2495 WINBASEAPI
2496 BOOL
2497 WINAPI
2498 SetConsoleTextAttribute(
2499 HANDLE hConsoleOutput,
2500 WORD wAttributes
2501 )
2502 {
2503 CSRSS_API_REQUEST Request;
2504 CSRSS_API_REPLY Reply;
2505 NTSTATUS Status;
2506
2507 Request.Type = CSRSS_SET_ATTRIB;
2508 Request.Data.SetAttribRequest.ConsoleHandle = hConsoleOutput;
2509 Request.Data.SetAttribRequest.Attrib = wAttributes;
2510 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
2511 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
2512 {
2513 SetLastErrorByStatus ( Status );
2514 return FALSE;
2515 }
2516 return TRUE;
2517 }
2518
2519
2520 BOOL STATIC
2521 AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine)
2522 {
2523 if (HandlerRoutine == NULL)
2524 {
2525 IgnoreCtrlEvents = TRUE;
2526 return(TRUE);
2527 }
2528 else
2529 {
2530 NrCtrlHandlers++;
2531 CtrlHandlers =
2532 RtlReAllocateHeap(RtlGetProcessHeap(),
2533 HEAP_ZERO_MEMORY,
2534 (PVOID)CtrlHandlers,
2535 NrCtrlHandlers * sizeof(PHANDLER_ROUTINE));
2536 if (CtrlHandlers == NULL)
2537 {
2538 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2539 return(FALSE);
2540 }
2541 CtrlHandlers[NrCtrlHandlers - 1] = HandlerRoutine;
2542 return(TRUE);
2543 }
2544 }
2545
2546
2547 BOOL STATIC
2548 RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine)
2549 {
2550 ULONG i;
2551
2552 if (HandlerRoutine == NULL)
2553 {
2554 IgnoreCtrlEvents = FALSE;
2555 return(TRUE);
2556 }
2557 else
2558 {
2559 for (i = 0; i < NrCtrlHandlers; i++)
2560 {
2561 if ( ((void*)(CtrlHandlers[i])) == (void*)HandlerRoutine)
2562 {
2563 CtrlHandlers[i] = CtrlHandlers[NrCtrlHandlers - 1];
2564 NrCtrlHandlers--;
2565 CtrlHandlers =
2566 RtlReAllocateHeap(RtlGetProcessHeap(),
2567 HEAP_ZERO_MEMORY,
2568 (PVOID)CtrlHandlers,
2569 NrCtrlHandlers * sizeof(PHANDLER_ROUTINE));
2570 return(TRUE);
2571 }
2572 }
2573 }
2574 return(FALSE);
2575 }
2576
2577
2578 /*
2579 * @implemented
2580 */
2581 WINBASEAPI BOOL WINAPI
2582 SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine,
2583 BOOL Add)
2584 {
2585 BOOLEAN Ret;
2586
2587 RtlEnterCriticalSection(&DllLock);
2588 if (Add)
2589 {
2590 Ret = AddConsoleCtrlHandler(HandlerRoutine);
2591 }
2592 else
2593 {
2594 Ret = RemoveConsoleCtrlHandler(HandlerRoutine);
2595 }
2596 RtlLeaveCriticalSection(&DllLock);
2597 return(Ret);
2598 }
2599
2600
2601 /*--------------------------------------------------------------
2602 * GenerateConsoleCtrlEvent
2603 *
2604 * @unimplemented
2605 */
2606 WINBASEAPI BOOL WINAPI
2607 GenerateConsoleCtrlEvent(
2608 DWORD dwCtrlEvent,
2609 DWORD dwProcessGroupId
2610 )
2611 {
2612 /* TO DO */
2613 return FALSE;
2614 }
2615
2616
2617 /*--------------------------------------------------------------
2618 * GetConsoleTitleW
2619 *
2620 * @implemented
2621 */
2622 WINBASEAPI
2623 DWORD
2624 WINAPI
2625 GetConsoleTitleW(
2626 LPWSTR lpConsoleTitle,
2627 DWORD nSize
2628 )
2629 {
2630 CSRSS_API_REQUEST Request;
2631 PCSRSS_API_REPLY Reply;
2632 NTSTATUS Status;
2633 HANDLE hConsole;
2634
2635 hConsole = CreateFileW(L"CONIN$", GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2636 if (hConsole == INVALID_HANDLE_VALUE)
2637 {
2638 return 0;
2639 }
2640
2641 Reply = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CSRSS_API_REPLY) + CSRSS_MAX_TITLE_LENGTH * sizeof(WCHAR));
2642 if(Reply == NULL)
2643 {
2644 CloseHandle(hConsole);
2645 SetLastError(ERROR_OUTOFMEMORY);
2646 return 0;
2647 }
2648
2649 Request.Type = CSRSS_GET_TITLE;
2650 Request.Data.GetTitleRequest.ConsoleHandle = hConsole;
2651
2652 Status = CsrClientCallServer(&Request, Reply, sizeof(CSRSS_API_REQUEST), sizeof(CSRSS_API_REPLY) + CSRSS_MAX_TITLE_LENGTH * sizeof(WCHAR));
2653 CloseHandle(hConsole);
2654 if(!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = Reply->Status)))
2655 {
2656 SetLastErrorByStatus(Status);
2657 RtlFreeHeap(GetProcessHeap(), 0, Reply);
2658 return 0;
2659 }
2660
2661 if(nSize * sizeof(WCHAR) < Reply->Data.GetTitleReply.Length)
2662 {
2663 wcsncpy(lpConsoleTitle, Reply->Data.GetTitleReply.Title, nSize - 1);
2664 lpConsoleTitle[nSize--] = L'\0';
2665 }
2666 else
2667 {
2668 nSize = Reply->Data.GetTitleReply.Length / sizeof (WCHAR);
2669 wcscpy(lpConsoleTitle, Reply->Data.GetTitleReply.Title);
2670 lpConsoleTitle[nSize] = L'\0';
2671 }
2672
2673 RtlFreeHeap(GetProcessHeap(), 0, Reply);
2674 return nSize;
2675 }
2676
2677
2678 /*--------------------------------------------------------------
2679 * GetConsoleTitleA
2680 *
2681 * 19990306 EA
2682 *
2683 * @implemented
2684 */
2685 WINBASEAPI
2686 DWORD
2687 WINAPI
2688 GetConsoleTitleA(
2689 LPSTR lpConsoleTitle,
2690 DWORD nSize
2691 )
2692 {
2693 wchar_t WideTitle [CSRSS_MAX_TITLE_LENGTH];
2694 DWORD nWideTitle = sizeof WideTitle;
2695 DWORD nWritten;
2696
2697 if (!lpConsoleTitle || !nSize) return 0;
2698 nWideTitle = GetConsoleTitleW( (LPWSTR) WideTitle, nWideTitle );
2699 if (!nWideTitle) return 0;
2700
2701 if ( (nWritten = WideCharToMultiByte(
2702 CP_ACP, // ANSI code page
2703 0, // performance and mapping flags
2704 (LPWSTR) WideTitle, // address of wide-character string
2705 nWideTitle, // number of characters in string
2706 lpConsoleTitle, // address of buffer for new string
2707 nSize, // size of buffer
2708 NULL, // FAST
2709 NULL // FAST
2710 )))
2711 {
2712 lpConsoleTitle[nWritten] = '\0';
2713 return nWritten;
2714 }
2715
2716 return 0;
2717 }
2718
2719
2720 /*--------------------------------------------------------------
2721 * SetConsoleTitleW
2722 *
2723 * @implemented
2724 */
2725 WINBASEAPI
2726 BOOL
2727 WINAPI
2728 SetConsoleTitleW(
2729 LPCWSTR lpConsoleTitle
2730 )
2731 {
2732 PCSRSS_API_REQUEST Request;
2733 CSRSS_API_REPLY Reply;
2734 NTSTATUS Status;
2735 unsigned int c;
2736 HANDLE hConsole;
2737
2738 hConsole = CreateFileW(L"CONIN$", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2739 if (hConsole == INVALID_HANDLE_VALUE)
2740 {
2741 return FALSE;
2742 }
2743
2744 Request = RtlAllocateHeap(GetProcessHeap(),
2745 HEAP_ZERO_MEMORY,
2746 sizeof(CSRSS_API_REQUEST) + CSRSS_MAX_SET_TITLE_REQUEST);
2747 if (Request == NULL)
2748 {
2749 CloseHandle(hConsole);
2750 SetLastError(ERROR_OUTOFMEMORY);
2751 return(FALSE);
2752 }
2753
2754 Request->Type = CSRSS_SET_TITLE;
2755 Request->Data.SetTitleRequest.Console = hConsole;
2756
2757 for( c = 0; lpConsoleTitle[c] && c < CSRSS_MAX_TITLE_LENGTH; c++ )
2758 Request->Data.SetTitleRequest.Title[c] = lpConsoleTitle[c];
2759 // add null
2760 Request->Data.SetTitleRequest.Title[c] = 0;
2761 Request->Data.SetTitleRequest.Length = c;
2762 Status = CsrClientCallServer(Request,
2763 &Reply,
2764 sizeof(CSRSS_API_REQUEST) +
2765 c * sizeof(WCHAR),
2766 sizeof(CSRSS_API_REPLY));
2767 CloseHandle(hConsole);
2768 if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) )
2769 {
2770 RtlFreeHeap( GetProcessHeap(), 0, Request );
2771 SetLastErrorByStatus (Status);
2772 return(FALSE);
2773 }
2774 RtlFreeHeap( GetProcessHeap(), 0, Request );
2775 return TRUE;
2776 }
2777
2778
2779 /*--------------------------------------------------------------
2780 * SetConsoleTitleA
2781 *
2782 * 19990204 EA Added
2783 *
2784 * @implemented
2785 */
2786 WINBASEAPI
2787 BOOL
2788 WINAPI
2789 SetConsoleTitleA(
2790 LPCSTR lpConsoleTitle
2791 )
2792 {
2793 PCSRSS_API_REQUEST Request;
2794 CSRSS_API_REPLY Reply;
2795 NTSTATUS Status;
2796 unsigned int c;
2797 HANDLE hConsole;
2798
2799 hConsole = CreateFileW(L"CONIN$", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2800 if (hConsole == INVALID_HANDLE_VALUE)
2801 {
2802 return FALSE;
2803 }
2804
2805 Request = RtlAllocateHeap(GetProcessHeap(),
2806 HEAP_ZERO_MEMORY,
2807 sizeof(CSRSS_API_REQUEST) + CSRSS_MAX_SET_TITLE_REQUEST);
2808 if (Request == NULL)
2809 {
2810 CloseHandle(hConsole);
2811 SetLastError(ERROR_OUTOFMEMORY);
2812 return(FALSE);
2813 }
2814
2815 Request->Type = CSRSS_SET_TITLE;
2816 Request->Data.SetTitleRequest.Console = hConsole;
2817
2818 for( c = 0; lpConsoleTitle[c] && c < CSRSS_MAX_TITLE_LENGTH; c++ )
2819 Request->Data.SetTitleRequest.Title[c] = lpConsoleTitle[c];
2820 // add null
2821 Request->Data.SetTitleRequest.Title[c] = 0;
2822 Request->Data.SetTitleRequest.Length = c;
2823 Status = CsrClientCallServer(Request,
2824 &Reply,
2825 sizeof(CSRSS_API_REQUEST) +
2826 c * sizeof(WCHAR),
2827 sizeof(CSRSS_API_REPLY));
2828 CloseHandle(hConsole);
2829 if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) )
2830 {
2831 RtlFreeHeap( GetProcessHeap(), 0, Request );
2832 SetLastErrorByStatus (Status);
2833 return(FALSE);
2834 }
2835 RtlFreeHeap( GetProcessHeap(), 0, Request );
2836 return TRUE;
2837 }
2838
2839
2840 /*--------------------------------------------------------------
2841 * ReadConsoleW
2842 *
2843 * @unimplemented
2844 */
2845 WINBASEAPI
2846 BOOL
2847 WINAPI
2848 ReadConsoleW(
2849 HANDLE hConsoleInput,
2850 LPVOID lpBuffer,
2851 DWORD nNumberOfCharsToRead,
2852 LPDWORD lpNumberOfCharsRead,
2853 LPVOID lpReserved
2854 )
2855 {
2856 /* --- TO DO --- */
2857 return FALSE;
2858 }
2859
2860
2861 /*--------------------------------------------------------------
2862 * WriteConsoleW
2863 *
2864 * @unimplemented
2865 */
2866 WINBASEAPI
2867 BOOL
2868 WINAPI
2869 WriteConsoleW(
2870 HANDLE hConsoleOutput,
2871 CONST VOID *lpBuffer,
2872 DWORD nNumberOfCharsToWrite,
2873 LPDWORD lpNumberOfCharsWritten,
2874 LPVOID lpReserved
2875 )
2876 {
2877 #if 0
2878 PCSRSS_API_REQUEST Request;
2879 CSRSS_API_REPLY Reply;
2880 NTSTATUS Status;
2881
2882 Request = RtlAllocateHeap(GetProcessHeap(),
2883 HEAP_ZERO_MEMORY,
2884 sizeof(CSRSS_API_REQUEST) + nNumberOfCharsToWrite * sizeof(WCHAR));
2885 if (Request == NULL)
2886 {
2887 SetLastError(ERROR_OUTOFMEMORY);
2888 return(FALSE);
2889 }
2890
2891 Request->Type = CSRSS_WRITE_CONSOLE;
2892 Request->Data.WriteConsoleRequest.ConsoleHandle = hConsoleOutput;
2893 Request->Data.WriteConsoleRequest.NrCharactersToWrite =
2894 nNumberOfCharsToWrite;
2895 // DbgPrint("nNumberOfCharsToWrite %d\n", nNumberOfCharsToWrite);
2896 // DbgPrint("Buffer %s\n", Request->Data.WriteConsoleRequest.Buffer);
2897 memcpy(Request->Data.WriteConsoleRequest.Buffer,
2898 lpBuffer,
2899 nNumberOfCharsToWrite * sizeof(WCHAR));
2900
2901 Status = CsrClientCallServer(Request,
2902 &Reply,
2903 sizeof(CSRSS_API_REQUEST) + nNumberOfCharsToWrite,
2904 sizeof(CSRSS_API_REPLY));
2905
2906 RtlFreeHeap(GetProcessHeap(),
2907 0,
2908 Request);
2909
2910 if (!NT_SUCCESS(Status))
2911 {
2912 return(FALSE);
2913 }
2914
2915 if (lpNumberOfCharsWritten != NULL)
2916 {
2917 *lpNumberOfCharsWritten =
2918 Reply.Data.WriteConsoleReply.NrCharactersWritten;
2919 }
2920
2921 return(TRUE);
2922 #endif
2923 return(FALSE);
2924 }
2925
2926
2927 /*--------------------------------------------------------------
2928 * CreateConsoleScreenBuffer
2929 *
2930 * @implemented
2931 */
2932 WINBASEAPI
2933 HANDLE
2934 WINAPI
2935 CreateConsoleScreenBuffer(
2936 DWORD dwDesiredAccess,
2937 DWORD dwShareMode,
2938 CONST SECURITY_ATTRIBUTES *lpSecurityAttributes,
2939 DWORD dwFlags,
2940 LPVOID lpScreenBufferData
2941 )
2942 {
2943 // FIXME: don't ignore access, share mode, and security
2944 CSRSS_API_REQUEST Request;
2945 CSRSS_API_REPLY Reply;
2946 NTSTATUS Status;
2947
2948 Request.Type = CSRSS_CREATE_SCREEN_BUFFER;
2949 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
2950 if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
2951 {
2952 SetLastErrorByStatus ( Status );
2953 return FALSE;
2954 }
2955 return Reply.Data.CreateScreenBufferReply.OutputHandle;
2956 }
2957
2958
2959 /*--------------------------------------------------------------
2960 * GetConsoleCP
2961 *
2962 * @unimplemented
2963 */
2964 WINBASEAPI
2965 UINT
2966 WINAPI
2967 GetConsoleCP( VOID )
2968 {
2969 /* --- TO DO --- */
2970 return CP_OEMCP; /* FIXME */
2971 }
2972
2973
2974 /*--------------------------------------------------------------
2975 * SetConsoleCP
2976 *
2977 * @unimplemented
2978 */
2979 WINBASEAPI
2980 BOOL
2981 WINAPI
2982 SetConsoleCP(
2983 UINT wCodePageID
2984 )
2985 {
2986 /* --- TO DO --- */
2987 return FALSE;
2988 }
2989
2990
2991 /*--------------------------------------------------------------
2992 * GetConsoleOutputCP
2993 *
2994 * @unimplemented
2995 */
2996 WINBASEAPI
2997 UINT
2998 WINAPI
2999 GetConsoleOutputCP( VOID )
3000 {
3001 /* --- TO DO --- */
3002 return 0; /* FIXME */
3003 }
3004
3005
3006 /*--------------------------------------------------------------
3007 * SetConsoleOutputCP
3008 *
3009 * @unimplemented
3010 */
3011 WINBASEAPI
3012 BOOL
3013 WINAPI
3014 SetConsoleOutputCP(
3015 UINT wCodePageID
3016 )
3017 {
3018 /* --- TO DO --- */
3019 return FALSE;
3020 }
3021
3022
3023 /*--------------------------------------------------------------
3024 * GetConsoleProcessList
3025 *
3026 * @unimplemented
3027 */
3028 DWORD STDCALL
3029 GetConsoleProcessList(LPDWORD lpdwProcessList,
3030 DWORD dwProcessCount)
3031 {
3032 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3033 return 0;
3034 }
3035
3036
3037
3038 /*--------------------------------------------------------------
3039 * GetConsoleSelectionInfo
3040 *
3041 * @unimplemented
3042 */
3043 BOOL STDCALL
3044 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo)
3045 {
3046 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3047 return FALSE;
3048 }
3049
3050
3051
3052 /*--------------------------------------------------------------
3053 * AttachConsole
3054 *
3055 * @unimplemented
3056 */
3057 BOOL STDCALL
3058 AttachConsole(DWORD dwProcessId)
3059 {
3060 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3061 return FALSE;
3062 }
3063
3064 /*--------------------------------------------------------------
3065 * GetConsoleWindow/0
3066 *
3067 * @implemented
3068 */
3069 HWND STDCALL
3070 GetConsoleWindow (VOID)
3071 {
3072 CSRSS_API_REQUEST Request;
3073 CSRSS_API_REPLY Reply;
3074 NTSTATUS Status;
3075
3076 Request.Data.ConsoleWindowRequest.ConsoleHandle =
3077 OpenConsoleW (L"CONOUT$", (GENERIC_READ|GENERIC_WRITE), FALSE, OPEN_EXISTING);
3078 if (INVALID_HANDLE_VALUE == Request.Data.ConsoleWindowRequest.ConsoleHandle)
3079 {
3080 return (HWND) NULL;
3081 }
3082 Request.Type = CSRSS_GET_CONSOLE_WINDOW;
3083 Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
3084 if (!NT_SUCCESS(Status ) || !NT_SUCCESS(Status = Reply.Status))
3085 {
3086 SetLastErrorByStatus (Status);
3087 return (HWND) NULL;
3088 }
3089 return Reply.Data.ConsoleWindowReply.WindowHandle;
3090 }
3091
3092 /* EOF */