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