[KERNEL32]
[reactos.git] / dll / win32 / kernel32 / client / console / console.c
index d83de74..f6aaea0 100644 (file)
@@ -15,7 +15,7 @@
 
 #include <k32.h>
 
-// #define NDEBUG
+#define NDEBUG
 #include <debug.h>
 
 extern RTL_CRITICAL_SECTION ConsoleLock;
@@ -66,16 +66,16 @@ DefaultConsoleCtrlHandler(DWORD Event)
     return TRUE;
 }
 
-__declspec(noreturn)
-VOID
-CALLBACK
-ConsoleControlDispatcher(DWORD CodeAndFlag)
+DWORD
+WINAPI
+ConsoleControlDispatcher(IN LPVOID lpThreadParameter)
 {
     DWORD nExitCode = 0;
+    DWORD CodeAndFlag = PtrToUlong(lpThreadParameter);
     DWORD nCode = CodeAndFlag & MAXLONG;
     UINT i;
     EXCEPTION_RECORD erException;
-    
+
     DPRINT("Console Dispatcher Active: %lx %lx\n", CodeAndFlag, nCode);
     SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
 
@@ -92,7 +92,7 @@ ConsoleControlDispatcher(DWORD CodeAndFlag)
                 erException.ExceptionRecord = NULL;
                 erException.ExceptionAddress = DefaultConsoleCtrlHandler;
                 erException.NumberParameters = 0;
-                
+
                 _SEH2_TRY
                 {
                     RtlRaiseException(&erException);
@@ -100,7 +100,7 @@ ConsoleControlDispatcher(DWORD CodeAndFlag)
                 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
                 {
                     RtlEnterCriticalSection(&ConsoleLock);
-                    
+
                     if ((nCode != CTRL_C_EVENT) ||
                         (NtCurrentPeb()->ProcessParameters->ConsoleFlags != 1))
                     {
@@ -109,14 +109,13 @@ ConsoleControlDispatcher(DWORD CodeAndFlag)
                             if (CtrlHandlers[i - 1](nCode)) break;
                         }
                     }
-                    
+
                     RtlLeaveCriticalSection(&ConsoleLock);
                 }
                 _SEH2_END;
-                
+
                 ExitThread(0);
             }
-            
             break;
         }
 
@@ -124,25 +123,22 @@ ConsoleControlDispatcher(DWORD CodeAndFlag)
         case CTRL_LOGOFF_EVENT:
         case CTRL_SHUTDOWN_EVENT:
             break;
-            
+
         case 3:
-        
             ExitThread(0);
             break;
-        
+
         case 4:
-        
             ExitProcess(CONTROL_C_EXIT);
             break;
 
         default:
-        
             ASSERT(FALSE);
             break;
     }
-    
+
     ASSERT(ConsoleInitialized);
-    
+
     RtlEnterCriticalSection(&ConsoleLock);
     nExitCode = 0;
     if ((nCode != CTRL_C_EVENT) || (NtCurrentPeb()->ProcessParameters->ConsoleFlags != 1))
@@ -172,140 +168,14 @@ ConsoleControlDispatcher(DWORD CodeAndFlag)
             }
         }
     }
-    
+
     RtlLeaveCriticalSection(&ConsoleLock);
     ExitThread(nExitCode);
+    return STATUS_SUCCESS;
 }
 
-/* Get the size needed to copy a string to a capture buffer, including alignment */
-static ULONG
-IntStringSize(LPCVOID String,
-              BOOL Unicode)
-{
-    ULONG Size = (Unicode ? wcslen(String) : strlen(String)) * sizeof(WCHAR);
-    return (Size + 3) & -4;
-}
-
-/* Copy a string to a capture buffer */
-static VOID
-IntCaptureMessageString(PCSR_CAPTURE_BUFFER CaptureBuffer,
-                        LPCVOID String,
-                        BOOL Unicode,
-                        PUNICODE_STRING RequestString)
-{
-    ULONG Size;
-    if (Unicode)
-    {
-        Size = wcslen(String) * sizeof(WCHAR);
-        CsrCaptureMessageBuffer(CaptureBuffer, (PVOID)String, Size, (PVOID *)&RequestString->Buffer);
-    }
-    else
-    {
-        Size = strlen(String);
-        CsrAllocateMessagePointer(CaptureBuffer, Size * sizeof(WCHAR), (PVOID *)&RequestString->Buffer);
-        Size = MultiByteToWideChar(CP_ACP, 0, String, Size, RequestString->Buffer, Size * sizeof(WCHAR))
-               * sizeof(WCHAR);
-    }
-    RequestString->Length = RequestString->MaximumLength = Size;
-}
-
-/* FUNCTIONS *****************************************************************/
-
-/*
- * @implemented
- */
-BOOL
-WINAPI
-AddConsoleAliasA(LPCSTR lpSource,
-                 LPCSTR lpTarget,
-                 LPCSTR lpExeName)
-{
-    LPWSTR lpSourceW = NULL;
-    LPWSTR lpTargetW = NULL;
-    LPWSTR lpExeNameW = NULL;
-    BOOL bRetVal;
-
-    if (lpSource)
-        BasepAnsiStringToHeapUnicodeString(lpSource, (LPWSTR*) &lpSourceW);
-    if (lpTarget)
-        BasepAnsiStringToHeapUnicodeString(lpTarget, (LPWSTR*) &lpTargetW);
-    if (lpExeName)
-        BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*) &lpExeNameW);
-
-    bRetVal = AddConsoleAliasW(lpSourceW, lpTargetW, lpExeNameW);
-
-    /* Clean up */
-    if (lpSourceW)
-        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpSourceW);
-    if (lpTargetW)
-        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpTargetW);
-    if (lpExeNameW)
-        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpExeNameW);
-
-    return bRetVal;
-}
-
-
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-AddConsoleAliasW(LPCWSTR lpSource,
-                 LPCWSTR lpTarget,
-                 LPCWSTR lpExeName)
-{
-    PCSR_API_MESSAGE Request;
-    NTSTATUS Status;
-    ULONG SourceLength;
-    ULONG TargetLength = 0;
-    ULONG ExeLength;
-    ULONG Size;
-    ULONG RequestLength;
-    WCHAR * Ptr;
-
-    DPRINT("AddConsoleAliasW enterd with lpSource %S lpTarget %S lpExeName %S\n", lpSource, lpTarget, lpExeName);
-
-    ExeLength = wcslen(lpExeName) + 1;
-    SourceLength = wcslen(lpSource)+ 1;
-    if (lpTarget)
-        TargetLength = wcslen(lpTarget) + 1;
-
-    Size = (ExeLength + SourceLength + TargetLength) * sizeof(WCHAR);
-    RequestLength = sizeof(CSR_API_MESSAGE) + Size;
-
-    Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, RequestLength);
-    Ptr = (WCHAR*)(((ULONG_PTR)Request) + sizeof(CSR_API_MESSAGE));
-
-    wcscpy(Ptr, lpSource);
-    Request->Data.AddConsoleAlias.SourceLength = SourceLength;
-    Ptr = (WCHAR*)(((ULONG_PTR)Request) + sizeof(CSR_API_MESSAGE) + SourceLength * sizeof(WCHAR));
-
-    wcscpy(Ptr, lpExeName);
-    Request->Data.AddConsoleAlias.ExeLength = ExeLength;
-    Ptr = (WCHAR*)(((ULONG_PTR)Request) + sizeof(CSR_API_MESSAGE) + (ExeLength + SourceLength)* sizeof(WCHAR));
-
-    if (lpTarget) /* target can be optional */
-        wcscpy(Ptr, lpTarget);
-
-    Request->Data.AddConsoleAlias.TargetLength = TargetLength;
-
-    Status = CsrClientCallServer(Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, ADD_CONSOLE_ALIAS),
-                                 RequestLength);
-
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status))
-    {
-        BaseSetLastNTError(Status);
-        RtlFreeHeap(GetProcessHeap(), 0, Request);
-        return FALSE;
-    }
-
-    RtlFreeHeap(GetProcessHeap(), 0, Request);
-    return TRUE;
-}
 
+/* FUNCTIONS ******************************************************************/
 
 /*
  * @unimplemented (Undocumented)
@@ -332,2695 +202,718 @@ DuplicateConsoleHandle(HANDLE hConsole,
                        BOOL bInheritHandle,
                        DWORD dwOptions)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_DUPLICATE_HANDLE DuplicateHandleRequest = &ApiMessage.Data.DuplicateHandleRequest;
 
-    if (dwOptions & ~(DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)
-        || (!(dwOptions & DUPLICATE_SAME_ACCESS)
-        && dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE)))
+    if ( (dwOptions & ~(DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) ||
+         (!(dwOptions & DUPLICATE_SAME_ACCESS) &&
+           (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE))) )
     {
         SetLastError (ERROR_INVALID_PARAMETER);
         return INVALID_HANDLE_VALUE;
     }
 
-    Request.Data.DuplicateHandleRequest.Handle = hConsole;
-    Request.Data.DuplicateHandleRequest.Access = dwDesiredAccess;
-    Request.Data.DuplicateHandleRequest.Inheritable = bInheritHandle;
-    Request.Data.DuplicateHandleRequest.Options = dwOptions;
+    DuplicateHandleRequest->Handle = hConsole;
+    DuplicateHandleRequest->Access = dwDesiredAccess;
+    DuplicateHandleRequest->Inheritable = bInheritHandle;
+    DuplicateHandleRequest->Options = dwOptions;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_NATIVE, DUPLICATE_HANDLE),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status=Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepDuplicateHandle),
+                                 sizeof(CSRSS_DUPLICATE_HANDLE));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return INVALID_HANDLE_VALUE;
     }
 
-    return Request.Data.DuplicateHandleRequest.Handle;
+    return DuplicateHandleRequest->Handle;
 }
 
 
-static BOOL
-IntExpungeConsoleCommandHistory(LPCVOID lpExeName, BOOL bUnicode)
+/*
+ * @unimplemented
+ */
+INT
+WINAPI
+GetConsoleDisplayMode(LPDWORD lpdwMode)
+     /*
+      * FUNCTION: Get the console display mode
+      * ARGUMENTS:
+      *      lpdwMode - Address of variable that receives the current value
+      *                 of display mode
+      * STATUS: Undocumented
+      */
 {
-    CSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
-    NTSTATUS Status;
-
-    if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName))
-    {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return FALSE;
-    }
-
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
-    if (!CaptureBuffer)
-    {
-        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return FALSE;
-    }
-
-    IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
-                            &Request.Data.ExpungeCommandHistory.ExeName);
-
-    Status = CsrClientCallServer(&Request,
-                                 CaptureBuffer,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, EXPUNGE_COMMAND_HISTORY),
-                                 sizeof(CSR_API_MESSAGE));
-
-    CsrFreeCaptureBuffer(CaptureBuffer);
-
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return FALSE;
-    }
-
-    return TRUE;
+    DPRINT1("GetConsoleDisplayMode(0x%x) UNIMPLEMENTED!\n", lpdwMode);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return 0;
 }
 
+
 /*
- * @implemented (Undocumented)
+ * @unimplemented (Undocumented)
  */
-BOOL
+DWORD
 WINAPI
-ExpungeConsoleCommandHistoryW(LPCWSTR lpExeName)
+GetConsoleFontInfo(DWORD Unknown0,
+                   DWORD Unknown1,
+                   DWORD Unknown2,
+                   DWORD Unknown3)
 {
-    return IntExpungeConsoleCommandHistory(lpExeName, TRUE);
+    DPRINT1("GetConsoleFontInfo(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return 0;
 }
 
+
 /*
- * @implemented (Undocumented)
+ * @unimplemented
  */
-BOOL
+COORD
 WINAPI
-ExpungeConsoleCommandHistoryA(LPCSTR lpExeName)
+GetConsoleFontSize(HANDLE hConsoleOutput,
+                   DWORD nFont)
 {
-    return IntExpungeConsoleCommandHistory(lpExeName, FALSE);
+    COORD Empty = {0, 0};
+    DPRINT1("GetConsoleFontSize(0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput, nFont);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return Empty;
 }
 
 
 /*
- * @implemented
+ * @implemented (Undocumented)
  */
 DWORD
 WINAPI
-GetConsoleAliasW(LPWSTR lpSource,
-                 LPWSTR lpTargetBuffer,
-                 DWORD TargetBufferLength,
-                 LPWSTR lpExeName)
+GetConsoleHardwareState(HANDLE hConsole,
+                        DWORD Flags,
+                        PDWORD State)
 {
-    PCSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
     NTSTATUS Status;
-    ULONG Size;
-    ULONG ExeLength;
-    ULONG SourceLength;
-    ULONG RequestLength;
-    WCHAR * Ptr;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_CONSOLE_HW_STATE ConsoleHardwareStateRequest = &ApiMessage.Data.ConsoleHardwareStateRequest;
 
-    DPRINT("GetConsoleAliasW entered lpSource %S lpExeName %S\n", lpSource, lpExeName);
+    ConsoleHardwareStateRequest->ConsoleHandle = hConsole;
 
-    if (lpTargetBuffer == NULL)
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetHardwareState),
+                                 sizeof(CSRSS_CONSOLE_HW_STATE));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return 0;
+        BaseSetLastNTError(Status);
+        return FALSE;
     }
 
-    ExeLength = wcslen(lpExeName) + 1;
-    SourceLength = wcslen(lpSource) + 1;
+    *State = ConsoleHardwareStateRequest->State;
+    return TRUE;
+}
 
-    Size = (ExeLength + SourceLength) * sizeof(WCHAR);
 
-    RequestLength = Size + sizeof(CSR_API_MESSAGE);
-    Request = RtlAllocateHeap(GetProcessHeap(), 0, RequestLength);
-    if (Request == NULL)
-    {
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return 0;
-    }
+/*
+ * @implemented (Undocumented)
+ */
+HANDLE
+WINAPI
+GetConsoleInputWaitHandle(VOID)
+{
+    CSR_API_MESSAGE Request;
+    NTSTATUS Status;
 
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, TargetBufferLength);
-    if (!CaptureBuffer)
+    Status = CsrClientCallServer(&Request,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_INPUT_WAIT_HANDLE),
+                                 sizeof(CSR_API_MESSAGE));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
     {
-        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
-        RtlFreeHeap(GetProcessHeap(), 0, Request);
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        BaseSetLastNTError(Status);
         return 0;
     }
 
-    Request->Data.GetConsoleAlias.TargetBuffer = NULL;
-
-    CsrCaptureMessageBuffer(CaptureBuffer,
-                            NULL,
-                            TargetBufferLength,
-                            (PVOID*)&Request->Data.GetConsoleAlias.TargetBuffer);
-
-    Request->Data.GetConsoleAlias.TargetBufferLength = TargetBufferLength;
-
-    Ptr = (LPWSTR)((ULONG_PTR)Request + sizeof(CSR_API_MESSAGE));
-    wcscpy(Ptr, lpSource);
-    Ptr += SourceLength;
-    wcscpy(Ptr, lpExeName);
-
-    Request->Data.GetConsoleAlias.ExeLength = ExeLength;
-    Request->Data.GetConsoleAlias.SourceLength = SourceLength;
+    return Request.Data.GetConsoleInputWaitHandle.InputWaitHandle;
+}
 
-    Status = CsrClientCallServer(Request,
-                                 CaptureBuffer,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CONSOLE_ALIAS),
-                                 sizeof(CSR_API_MESSAGE) + Size);
 
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status))
-    {
-        RtlFreeHeap(GetProcessHeap(), 0, Request);
-        CsrFreeCaptureBuffer(CaptureBuffer);
-        BaseSetLastNTError(Status);
-        return 0;
-    }
+/*
+ * @unimplemented
+ */
+INT
+WINAPI
+GetCurrentConsoleFont(HANDLE hConsoleOutput,
+                      BOOL bMaximumWindow,
+                      PCONSOLE_FONT_INFO lpConsoleCurrentFont)
+{
+    DPRINT1("GetCurrentConsoleFont(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput, bMaximumWindow, lpConsoleCurrentFont);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return 0;
+}
 
-    wcscpy(lpTargetBuffer, Request->Data.GetConsoleAlias.TargetBuffer);
-    RtlFreeHeap(GetProcessHeap(), 0, Request);
-    CsrFreeCaptureBuffer(CaptureBuffer);
 
-    return Request->Data.GetConsoleAlias.BytesWritten;
+/*
+ * @unimplemented (Undocumented)
+ */
+ULONG
+WINAPI
+GetNumberOfConsoleFonts(VOID)
+{
+    DPRINT1("GetNumberOfConsoleFonts() UNIMPLEMENTED!\n");
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return 1;
 }
 
 
 /*
- * @implemented
+ * @unimplemented (Undocumented)
  */
 DWORD
 WINAPI
-GetConsoleAliasA(LPSTR lpSource,
-                 LPSTR lpTargetBuffer,
-                 DWORD TargetBufferLength,
-                 LPSTR lpExeName)
+InvalidateConsoleDIBits(DWORD Unknown0,
+                        DWORD Unknown1)
 {
-    LPWSTR lpwSource;
-    LPWSTR lpwExeName;
-    LPWSTR lpwTargetBuffer;
-    UINT dwSourceSize;
-    UINT dwExeNameSize;
-    UINT dwResult;
+    DPRINT1("InvalidateConsoleDIBits(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return 0;
+}
 
-    DPRINT("GetConsoleAliasA entered\n");
 
-    if (lpTargetBuffer == NULL)
+/*
+ * @unimplemented (Undocumented)
+ */
+HANDLE
+WINAPI
+OpenConsoleW(LPCWSTR wsName,
+             DWORD dwDesiredAccess,
+             BOOL bInheritHandle,
+             DWORD dwShareMode)
+{
+    NTSTATUS Status = STATUS_SUCCESS;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_OPEN_CONSOLE OpenConsoleRequest = &ApiMessage.Data.OpenConsoleRequest;
+    HANDLE_TYPE HandleType;
+
+    if (wsName && 0 == _wcsicmp(wsName, L"CONIN$"))
     {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return 0;
+        HandleType = HANDLE_INPUT;
     }
-
-    dwSourceSize = (strlen(lpSource)+1) * sizeof(WCHAR);
-    lpwSource = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSourceSize);
-    if (lpwSource == NULL)
+    else if (wsName && 0 == _wcsicmp(wsName, L"CONOUT$"))
     {
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return 0;
+        HandleType = HANDLE_OUTPUT;
     }
-    MultiByteToWideChar(CP_ACP, 0, lpSource, -1, lpwSource, dwSourceSize);
-
-    dwExeNameSize = (strlen(lpExeName)+1) * sizeof(WCHAR);
-    lpwExeName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwExeNameSize);
-    if (lpwExeName == NULL)
+    else
     {
-        HeapFree(GetProcessHeap(), 0, lpwSource);
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return 0;
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return INVALID_HANDLE_VALUE;
     }
-    MultiByteToWideChar(CP_ACP, 0, lpExeName, -1, lpwExeName, dwExeNameSize);
 
-    lpwTargetBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, TargetBufferLength * sizeof(WCHAR));
-    if (lpwTargetBuffer == NULL)
+    if (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE))
     {
-        HeapFree(GetProcessHeap(), 0, lpwSource);
-        HeapFree(GetProcessHeap(), 0, lpwExeName);
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return 0;
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return INVALID_HANDLE_VALUE;
     }
 
-    dwResult = GetConsoleAliasW(lpwSource, lpwTargetBuffer, TargetBufferLength * sizeof(WCHAR), lpwExeName);
-
-    HeapFree(GetProcessHeap(), 0, lpwSource);
-    HeapFree(GetProcessHeap(), 0, lpwExeName);
+    if (dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE))
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return INVALID_HANDLE_VALUE;
+    }
 
-    if (dwResult)
-        dwResult = WideCharToMultiByte(CP_ACP, 0, lpwTargetBuffer, dwResult / sizeof(WCHAR), lpTargetBuffer, TargetBufferLength, NULL, NULL);
+    OpenConsoleRequest->HandleType = HandleType;
+    OpenConsoleRequest->Access = dwDesiredAccess;
+    OpenConsoleRequest->Inheritable = bInheritHandle;
+    OpenConsoleRequest->ShareMode = dwShareMode;
 
-    HeapFree(GetProcessHeap(), 0, lpwTargetBuffer);
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepOpenConsole),
+                                 sizeof(CSRSS_OPEN_CONSOLE));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
+    {
+        BaseSetLastNTError(Status);
+        return INVALID_HANDLE_VALUE;
+    }
 
-    return dwResult;
+    return OpenConsoleRequest->Handle;
 }
 
 
 /*
- * @implemented
+ * @unimplemented (Undocumented)
  */
-DWORD
+BOOL
 WINAPI
-GetConsoleAliasExesW(LPWSTR lpExeNameBuffer,
-                     DWORD ExeNameBufferLength)
+SetConsoleCursor(DWORD Unknown0,
+                 DWORD Unknown1)
 {
-    CSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
-    NTSTATUS Status;
-
-    DPRINT("GetConsoleAliasExesW entered\n");
-
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, ExeNameBufferLength);
-    if (!CaptureBuffer)
-    {
-        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return 0;
-    }
-
-    CsrAllocateMessagePointer(CaptureBuffer,
-                              ExeNameBufferLength,
-                              (PVOID*)&Request.Data.GetConsoleAliasesExes.ExeNames);
-    Request.Data.GetConsoleAliasesExes.Length = ExeNameBufferLength;
-
-    Status = CsrClientCallServer(&Request,
-                                 CaptureBuffer,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CONSOLE_ALIASES_EXES),
-                                 sizeof(CSR_API_MESSAGE));
-
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        CsrFreeCaptureBuffer(CaptureBuffer);
-        return 0;
-    }
-
-    memcpy(lpExeNameBuffer,
-           Request.Data.GetConsoleAliasesExes.ExeNames,
-           Request.Data.GetConsoleAliasesExes.BytesWritten);
-
-    CsrFreeCaptureBuffer(CaptureBuffer);
-    return Request.Data.GetConsoleAliasesExes.BytesWritten;
+    DPRINT1("SetConsoleCursor(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return FALSE;
 }
 
 
 /*
- * @implemented
+ * @unimplemented
  */
-DWORD
+BOOL
 WINAPI
-GetConsoleAliasExesA(LPSTR lpExeNameBuffer,
-                     DWORD ExeNameBufferLength)
+SetConsoleDisplayMode(HANDLE hOut,
+                      DWORD dwNewMode,
+                      PCOORD lpdwOldMode)
+     /*
+      * FUNCTION: Set the console display mode.
+      * ARGUMENTS:
+      *       hOut - Standard output handle.
+      *       dwNewMode - New mode.
+      *       lpdwOldMode - Address of a variable that receives the old mode.
+      */
 {
-    LPWSTR lpwExeNameBuffer;
-    DWORD dwResult;
-
-    DPRINT("GetConsoleAliasExesA entered\n");
-
-    lpwExeNameBuffer = HeapAlloc(GetProcessHeap(), 0, ExeNameBufferLength * sizeof(WCHAR));
-
-    dwResult = GetConsoleAliasExesW(lpwExeNameBuffer, ExeNameBufferLength * sizeof(WCHAR));
+    DPRINT1("SetConsoleDisplayMode(0x%x, 0x%x, 0x%p) UNIMPLEMENTED!\n", hOut, dwNewMode, lpdwOldMode);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return FALSE;
+}
 
-    if (dwResult)
-        dwResult = WideCharToMultiByte(CP_ACP, 0, lpwExeNameBuffer, dwResult / sizeof(WCHAR), lpExeNameBuffer, ExeNameBufferLength, NULL, NULL);
 
-    HeapFree(GetProcessHeap(), 0, lpwExeNameBuffer);
-    return dwResult;
+/*
+ * @unimplemented (Undocumented)
+ */
+BOOL
+WINAPI
+SetConsoleFont(DWORD Unknown0,
+               DWORD Unknown1)
+{
+    DPRINT1("SetConsoleFont(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return FALSE;
 }
 
+
 /*
- * @implemented
+ * @implemented (Undocumented)
  */
-DWORD
+BOOL
 WINAPI
-GetConsoleAliasExesLengthW(VOID)
+SetConsoleHardwareState(HANDLE hConsole,
+                        DWORD Flags,
+                        DWORD State)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_CONSOLE_HW_STATE ConsoleHardwareStateRequest = &ApiMessage.Data.ConsoleHardwareStateRequest;
 
-    DPRINT("GetConsoleAliasExesLengthW entered\n");
-
-    Request.Data.GetConsoleAliasesExesLength.Length = 0;
+    ConsoleHardwareStateRequest->ConsoleHandle = hConsole;
+    ConsoleHardwareStateRequest->State = State;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CONSOLE_ALIASES_EXES_LENGTH),
-                                 sizeof(CSR_API_MESSAGE));
-
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetHardwareState),
+                                 sizeof(CSRSS_CONSOLE_HW_STATE));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
-        return 0;
+        return FALSE;
     }
 
-    return Request.Data.GetConsoleAliasesExesLength.Length;
+    return TRUE;
 }
 
+
 /*
- * @implemented
+ * @unimplemented (Undocumented)
  */
-DWORD
+BOOL
 WINAPI
-GetConsoleAliasExesLengthA(VOID)
+SetConsoleKeyShortcuts(DWORD Unknown0,
+                       DWORD Unknown1,
+                       DWORD Unknown2,
+                       DWORD Unknown3)
 {
-    DWORD dwLength;
-
-    DPRINT("GetConsoleAliasExesLengthA entered\n");
-
-    dwLength = GetConsoleAliasExesLengthW();
-
-    if (dwLength)
-        dwLength /= sizeof(WCHAR);
-
-    return dwLength;
+    DPRINT1("SetConsoleKeyShortcuts(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return FALSE;
 }
 
 
 /*
- * @implemented
+ * @unimplemented (Undocumented)
  */
-DWORD
+BOOL
 WINAPI
-GetConsoleAliasesW(LPWSTR AliasBuffer,
-                   DWORD AliasBufferLength,
-                   LPWSTR ExeName)
+SetConsoleMaximumWindowSize(DWORD Unknown0,
+                            DWORD Unknown1)
 {
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status;
-    DWORD dwLength;
-
-    DPRINT("GetConsoleAliasesW entered\n");
-
-    dwLength = GetConsoleAliasesLengthW(ExeName);
-    if (!dwLength || dwLength > AliasBufferLength)
-        return 0;
-
-    Request.Data.GetAllConsoleAlias.AliasBuffer = AliasBuffer;
-    Request.Data.GetAllConsoleAlias.AliasBufferLength = AliasBufferLength;
-    Request.Data.GetAllConsoleAlias.lpExeName = ExeName;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_ALL_CONSOLE_ALIASES),
-                                 sizeof(CSR_API_MESSAGE));
-
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return 0;
-    }
-
-    return Request.Data.GetAllConsoleAlias.BytesWritten / sizeof(WCHAR);
+    DPRINT1("SetConsoleMaximumWindowSize(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return FALSE;
 }
 
 
 /*
- * @implemented
+ * @unimplemented (Undocumented)
  */
-DWORD
+BOOL
 WINAPI
-GetConsoleAliasesA(LPSTR AliasBuffer,
-                   DWORD AliasBufferLength,
-                   LPSTR ExeName)
+SetConsoleMenuClose(DWORD Unknown0)
 {
-    DWORD dwRetVal = 0;
-    LPWSTR lpwExeName = NULL;
-    LPWSTR lpwAliasBuffer;
-
-    DPRINT("GetConsoleAliasesA entered\n");
-
-    if (ExeName)
-        BasepAnsiStringToHeapUnicodeString(ExeName, (LPWSTR*) &lpwExeName);
-
-    lpwAliasBuffer = HeapAlloc(GetProcessHeap(), 0, AliasBufferLength * sizeof(WCHAR));
-
-    dwRetVal = GetConsoleAliasesW(lpwAliasBuffer, AliasBufferLength, lpwExeName);
-
-    if (lpwExeName)
-        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpwExeName);
-
-    if (dwRetVal)
-        dwRetVal = WideCharToMultiByte(CP_ACP, 0, lpwAliasBuffer, dwRetVal, AliasBuffer, AliasBufferLength, NULL, NULL);
-
-    HeapFree(GetProcessHeap(), 0, lpwAliasBuffer);
-    return dwRetVal;
+    DPRINT1("SetConsoleMenuClose(0x%x) UNIMPLEMENTED!\n", Unknown0);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return FALSE;
 }
 
 
 /*
- * @implemented
+ * @unimplemented (Undocumented)
  */
-DWORD
+BOOL
 WINAPI
-GetConsoleAliasesLengthW(LPWSTR lpExeName)
+SetConsolePalette(DWORD Unknown0,
+                  DWORD Unknown1,
+                  DWORD Unknown2)
 {
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status;
-
-    DPRINT("GetConsoleAliasesLengthW entered\n");
-
-    Request.Data.GetAllConsoleAliasesLength.lpExeName = lpExeName;
-    Request.Data.GetAllConsoleAliasesLength.Length = 0;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_ALL_CONSOLE_ALIASES_LENGTH),
-                                 sizeof(CSR_API_MESSAGE));
-
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return 0;
-    }
-
-    return Request.Data.GetAllConsoleAliasesLength.Length;
+    DPRINT1("SetConsolePalette(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return FALSE;
 }
 
-
 /*
- * @implemented
+ * @unimplemented (Undocumented)
  */
 DWORD
 WINAPI
-GetConsoleAliasesLengthA(LPSTR lpExeName)
+ShowConsoleCursor(DWORD Unknown0,
+                  DWORD Unknown1)
 {
-    DWORD dwRetVal = 0;
-    LPWSTR lpExeNameW = NULL;
-
-    if (lpExeName)
-        BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*) &lpExeNameW);
-
-    dwRetVal = GetConsoleAliasesLengthW(lpExeNameW);
-    if (dwRetVal)
-        dwRetVal /= sizeof(WCHAR);
-
-    /* Clean up */
-    if (lpExeNameW)
-        RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpExeNameW);
-
-    return dwRetVal;
+    DPRINT1("ShowConsoleCursor(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return 0;
 }
 
 
-static DWORD
-IntGetConsoleCommandHistory(LPVOID lpHistory, DWORD cbHistory, LPCVOID lpExeName, BOOL bUnicode)
+/*
+ * FUNCTION: Checks whether the given handle is a valid console handle.
+ *
+ * ARGUMENTS:
+ *      Handle - Handle to be checked
+ *
+ * RETURNS:
+ *      TRUE: Handle is a valid console handle
+ *      FALSE: Handle is not a valid console handle.
+ *
+ * STATUS: Officially undocumented
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+VerifyConsoleIoHandle(HANDLE Handle)
 {
-    CSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
     NTSTATUS Status;
-    DWORD HistoryLength = cbHistory * (bUnicode ? 1 : sizeof(WCHAR));
-
-    if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName))
-    {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return 0;
-    }
-
-    CaptureBuffer = CsrAllocateCaptureBuffer(2, IntStringSize(lpExeName, bUnicode) +
-                                                HistoryLength);
-    if (!CaptureBuffer)
-    {
-        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return 0;
-    }
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
-                            &Request.Data.GetCommandHistory.ExeName);
-    Request.Data.GetCommandHistory.Length = HistoryLength;
-    CsrAllocateMessagePointer(CaptureBuffer, HistoryLength,
-                              (PVOID*)&Request.Data.GetCommandHistory.History);
+    ApiMessage.Data.VerifyHandleRequest.Handle = Handle;
 
-    Status = CsrClientCallServer(&Request,
-                                 CaptureBuffer,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_COMMAND_HISTORY),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepVerifyIoHandle),
+                                 sizeof(CSRSS_VERIFY_HANDLE));
+    if (!NT_SUCCESS(Status))
     {
-        CsrFreeCaptureBuffer(CaptureBuffer);
         BaseSetLastNTError(Status);
-        return 0;
-    }
-
-    if (bUnicode)
-    {
-        memcpy(lpHistory,
-               Request.Data.GetCommandHistory.History,
-               Request.Data.GetCommandHistory.Length);
-    }
-    else
-    {
-        WideCharToMultiByte(CP_ACP, 0,
-                            Request.Data.GetCommandHistory.History,
-                            Request.Data.GetCommandHistory.Length / sizeof(WCHAR),
-                            lpHistory,
-                            cbHistory,
-                            NULL, NULL);
+        return FALSE;
     }
 
-    CsrFreeCaptureBuffer(CaptureBuffer);
-    return Request.Data.GetCommandHistory.Length;
+    return (BOOL)NT_SUCCESS(ApiMessage.Status);
 }
 
+
 /*
- * @implemented (Undocumented)
+ * @unimplemented
  */
 DWORD
 WINAPI
-GetConsoleCommandHistoryW(LPWSTR lpHistory,
-                          DWORD cbHistory,
-                          LPCWSTR lpExeName)
+WriteConsoleInputVDMA(DWORD Unknown0,
+                      DWORD Unknown1,
+                      DWORD Unknown2,
+                      DWORD Unknown3)
 {
-    return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, TRUE);
+    DPRINT1("WriteConsoleInputVDMA(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return 0;
 }
 
+
 /*
- * @implemented (Undocumented)
+ * @unimplemented
  */
 DWORD
 WINAPI
-GetConsoleCommandHistoryA(LPSTR lpHistory,
-                          DWORD cbHistory,
-                          LPCSTR lpExeName)
+WriteConsoleInputVDMW(DWORD Unknown0,
+                      DWORD Unknown1,
+                      DWORD Unknown2,
+                      DWORD Unknown3)
 {
-    return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, FALSE);
-}
-
-
-static DWORD
-IntGetConsoleCommandHistoryLength(LPCVOID lpExeName, BOOL bUnicode)
-{
-    CSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
-    NTSTATUS Status;
-
-    if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName))
-    {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return 0;
-    }
-
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
-    if (!CaptureBuffer)
-    {
-        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return 0;
-    }
-
-    IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
-                            &Request.Data.GetCommandHistoryLength.ExeName);
-
-    Status = CsrClientCallServer(&Request,
-                                 CaptureBuffer,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_COMMAND_HISTORY_LENGTH),
-                                 sizeof(CSR_API_MESSAGE));
-
-    CsrFreeCaptureBuffer(CaptureBuffer);
-
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return 0;
-    }
-
-    return Request.Data.GetCommandHistoryLength.Length;
-}
-
-/*
- * @implemented (Undocumented)
- */
-DWORD
-WINAPI
-GetConsoleCommandHistoryLengthW(LPCWSTR lpExeName)
-{
-    return IntGetConsoleCommandHistoryLength(lpExeName, TRUE);
-}
-
-/*
- * @implemented (Undocumented)
- */
-DWORD
-WINAPI
-GetConsoleCommandHistoryLengthA(LPCSTR lpExeName)
-{
-    return IntGetConsoleCommandHistoryLength(lpExeName, FALSE) / sizeof(WCHAR);
-}
-
-
-/*
- * @unimplemented
- */
-INT
-WINAPI
-GetConsoleDisplayMode(LPDWORD lpdwMode)
-     /*
-      * FUNCTION: Get the console display mode
-      * ARGUMENTS:
-      *      lpdwMode - Address of variable that receives the current value
-      *                 of display mode
-      * STATUS: Undocumented
-      */
-{
-    DPRINT1("GetConsoleDisplayMode(0x%x) UNIMPLEMENTED!\n", lpdwMode);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return 0;
-}
-
-
-/*
- * @unimplemented (Undocumented)
- */
-DWORD
-WINAPI
-GetConsoleFontInfo(DWORD Unknown0,
-                   DWORD Unknown1,
-                   DWORD Unknown2,
-                   DWORD Unknown3)
-{
-    DPRINT1("GetConsoleFontInfo(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return 0;
-}
-
-
-/*
- * @unimplemented
- */
-COORD
-WINAPI
-GetConsoleFontSize(HANDLE hConsoleOutput,
-                   DWORD nFont)
-{
-    COORD Empty = {0, 0};
-    DPRINT1("GetConsoleFontSize(0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput, nFont);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return Empty;
-}
-
-
-/*
- * @implemented (Undocumented)
- */
-DWORD
-WINAPI
-GetConsoleHardwareState(HANDLE hConsole,
-                        DWORD Flags,
-                        PDWORD State)
-{
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status;
-
-    Request.Data.ConsoleHardwareStateRequest.ConsoleHandle = hConsole;
-    Request.Data.ConsoleHardwareStateRequest.SetGet = CONSOLE_HARDWARE_STATE_GET;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SETGET_CONSOLE_HW_STATE),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return FALSE;
-    }
-
-    *State = Request.Data.ConsoleHardwareStateRequest.State;
-    return TRUE;
+    DPRINT1("WriteConsoleInputVDMW(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return 0;
 }
 
 
 /*
  * @implemented (Undocumented)
- */
-HANDLE
-WINAPI
-GetConsoleInputWaitHandle(VOID)
-{
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_INPUT_WAIT_HANDLE),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return 0;
-    }
-
-    return Request.Data.GetConsoleInputWaitHandle.InputWaitHandle;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-WINAPI
-GetCurrentConsoleFont(HANDLE hConsoleOutput,
-                      BOOL bMaximumWindow,
-                      PCONSOLE_FONT_INFO lpConsoleCurrentFont)
-{
-    DPRINT1("GetCurrentConsoleFont(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput, bMaximumWindow, lpConsoleCurrentFont);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return 0;
-}
-
-
-/*
- * @unimplemented (Undocumented)
- */
-ULONG
-WINAPI
-GetNumberOfConsoleFonts(VOID)
-{
-    DPRINT1("GetNumberOfConsoleFonts() UNIMPLEMENTED!\n");
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return 1; /* FIXME: call csrss.exe */
-}
-
-
-/*
- * @unimplemented (Undocumented)
- */
-DWORD
-WINAPI
-InvalidateConsoleDIBits(DWORD Unknown0,
-                        DWORD Unknown1)
-{
-    DPRINT1("InvalidateConsoleDIBits(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return 0;
-}
-
-
-/*
- * @unimplemented (Undocumented)
- */
-HANDLE
-WINAPI
-OpenConsoleW(LPCWSTR wsName,
-             DWORD dwDesiredAccess,
-             BOOL bInheritHandle,
-             DWORD dwShareMode)
-{
-    CSR_API_MESSAGE Request;
-    ULONG CsrRequest;
-    NTSTATUS Status = STATUS_SUCCESS;
-
-    if (wsName && 0 == _wcsicmp(wsName, L"CONIN$"))
-    {
-        CsrRequest = CSR_CREATE_API_NUMBER(CSR_NATIVE, GET_INPUT_HANDLE);
-    }
-    else if (wsName && 0 == _wcsicmp(wsName, L"CONOUT$"))
-    {
-        CsrRequest = CSR_CREATE_API_NUMBER(CSR_NATIVE, GET_OUTPUT_HANDLE);
-    }
-    else
-    {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return(INVALID_HANDLE_VALUE);
-    }
-
-    if (dwDesiredAccess & ~(GENERIC_READ|GENERIC_WRITE))
-    {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return(INVALID_HANDLE_VALUE);
-    }
-
-    if (dwShareMode & ~(FILE_SHARE_READ|FILE_SHARE_WRITE))
-    {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return(INVALID_HANDLE_VALUE);
-    }
-
-    /* Structures for GET_INPUT_HANDLE and GET_OUTPUT_HANDLE requests are identical */
-    Request.Data.GetInputHandleRequest.Access = dwDesiredAccess;
-    Request.Data.GetInputHandleRequest.Inheritable = bInheritHandle;
-    Request.Data.GetInputHandleRequest.ShareMode = dwShareMode;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CsrRequest,
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return INVALID_HANDLE_VALUE;
-    }
-
-    return Request.Data.GetInputHandleRequest.Handle;
-}
-
-
-/*
- * @unimplemented (Undocumented)
- */
-BOOL
-WINAPI
-SetConsoleCursor(DWORD Unknown0,
-                 DWORD Unknown1)
-{
-    DPRINT1("SetConsoleCursor(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-SetConsoleDisplayMode(HANDLE hOut,
-                      DWORD dwNewMode,
-                      PCOORD lpdwOldMode)
-     /*
-      * FUNCTION: Set the console display mode.
-      * ARGUMENTS:
-      *       hOut - Standard output handle.
-      *       dwNewMode - New mode.
-      *       lpdwOldMode - Address of a variable that receives the old mode.
-      */
-{
-    DPRINT1("SetConsoleDisplayMode(0x%x, 0x%x, 0x%p) UNIMPLEMENTED!\n", hOut, dwNewMode, lpdwOldMode);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
-}
-
-
-/*
- * @unimplemented (Undocumented)
- */
-BOOL
-WINAPI
-SetConsoleFont(DWORD Unknown0,
-               DWORD Unknown1)
-{
-    DPRINT1("SetConsoleFont(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
-}
-
-
-/*
- * @implemented (Undocumented)
- */
-BOOL
-WINAPI
-SetConsoleHardwareState(HANDLE hConsole,
-                        DWORD Flags,
-                        DWORD State)
-{
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status;
-
-    Request.Data.ConsoleHardwareStateRequest.ConsoleHandle = hConsole;
-    Request.Data.ConsoleHardwareStateRequest.SetGet = CONSOLE_HARDWARE_STATE_SET;
-    Request.Data.ConsoleHardwareStateRequest.State = State;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SETGET_CONSOLE_HW_STATE),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-
-/*
- * @unimplemented (Undocumented)
- */
-BOOL
-WINAPI
-SetConsoleKeyShortcuts(DWORD Unknown0,
-                       DWORD Unknown1,
-                       DWORD Unknown2,
-                       DWORD Unknown3)
-{
-    DPRINT1("SetConsoleKeyShortcuts(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
-}
-
-
-/*
- * @unimplemented (Undocumented)
- */
-BOOL
-WINAPI
-SetConsoleMaximumWindowSize(DWORD Unknown0,
-                            DWORD Unknown1)
-{
-    DPRINT1("SetConsoleMaximumWindowSize(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
-}
-
-
-/*
- * @unimplemented (Undocumented)
- */
-BOOL
-WINAPI
-SetConsoleMenuClose(DWORD Unknown0)
-{
-    DPRINT1("SetConsoleMenuClose(0x%x) UNIMPLEMENTED!\n", Unknown0);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
-}
-
-
-static BOOL
-IntSetConsoleNumberOfCommands(DWORD dwNumCommands,
-                              LPCVOID lpExeName,
-                              BOOL bUnicode)
-{
-    CSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
-    NTSTATUS Status;
-
-    if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName))
-    {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return FALSE;
-    }
-
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
-    if (!CaptureBuffer)
-    {
-        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return FALSE;
-    }
-
-    IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
-                            &Request.Data.SetHistoryNumberCommands.ExeName);
-    Request.Data.SetHistoryNumberCommands.NumCommands = dwNumCommands;
-
-    Status = CsrClientCallServer(&Request,
-                                 CaptureBuffer,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_HISTORY_NUMBER_COMMANDS),
-                                 sizeof(CSR_API_MESSAGE));
-
-    CsrFreeCaptureBuffer(CaptureBuffer);
-
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-/*
- * @implemented (Undocumented)
- */
-BOOL
-WINAPI
-SetConsoleNumberOfCommandsA(DWORD dwNumCommands,
-                            LPCWSTR lpExeName)
-{
-    return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, FALSE);
-}
-
-/*
- * @implemented (Undocumented)
- */
-BOOL
-WINAPI
-SetConsoleNumberOfCommandsW(DWORD dwNumCommands,
-                            LPCSTR lpExeName)
-{
-    return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, TRUE);
-}
-
-
-/*
- * @unimplemented (Undocumented)
- */
-BOOL
-WINAPI
-SetConsolePalette(DWORD Unknown0,
-                  DWORD Unknown1,
-                  DWORD Unknown2)
-{
-    DPRINT1("SetConsolePalette(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
-}
-
-/*
- * @unimplemented (Undocumented)
- */
-DWORD
-WINAPI
-ShowConsoleCursor(DWORD Unknown0,
-                  DWORD Unknown1)
-{
-    DPRINT1("ShowConsoleCursor(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return 0;
-}
-
-
-/*
- * FUNCTION: Checks whether the given handle is a valid console handle.
- * ARGUMENTS:
- *      Handle - Handle to be checked
- * RETURNS:
- *      TRUE: Handle is a valid console handle
- *      FALSE: Handle is not a valid console handle.
- * STATUS: Officially undocumented
- *
- * @implemented
- */
-BOOL
-WINAPI
-VerifyConsoleIoHandle(HANDLE Handle)
-{
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status;
-
-    Request.Data.VerifyHandleRequest.Handle = Handle;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_NATIVE, VERIFY_HANDLE),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status))
-    {
-        BaseSetLastNTError(Status);
-        return FALSE;
-    }
-
-    return (BOOL)NT_SUCCESS(Request.Status);
-}
-
-
-/*
- * @unimplemented
- */
-DWORD
-WINAPI
-WriteConsoleInputVDMA(DWORD Unknown0,
-                      DWORD Unknown1,
-                      DWORD Unknown2,
-                      DWORD Unknown3)
-{
-    DPRINT1("WriteConsoleInputVDMA(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return 0;
-}
-
-
-/*
- * @unimplemented
- */
-DWORD
-WINAPI
-WriteConsoleInputVDMW(DWORD Unknown0,
-                      DWORD Unknown1,
-                      DWORD Unknown2,
-                      DWORD Unknown3)
-{
-    DPRINT1("WriteConsoleInputVDMW(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return 0;
-}
-
-
-/*
- * @implemented (Undocumented)
- */
-BOOL
-WINAPI
-CloseConsoleHandle(HANDLE Handle)
-{
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status;
-
-    Request.Data.CloseHandleRequest.Handle = Handle;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_NATIVE, CLOSE_HANDLE),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status))
-    {
-        BaseSetLastNTError(Status);
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-/*
- * @implemented
- */
-HANDLE
-WINAPI
-GetStdHandle(DWORD nStdHandle)
-     /*
-      * FUNCTION: Get a handle for the standard input, standard output
-      * and a standard error device.
-      * ARGUMENTS:
-      *       nStdHandle - Specifies the device for which to return the handle.
-      * RETURNS: If the function succeeds, the return value is the handle
-      * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
-      */
-{
-    PRTL_USER_PROCESS_PARAMETERS Ppb;
-
-    Ppb = NtCurrentPeb()->ProcessParameters;
-    switch (nStdHandle)
-    {
-        case STD_INPUT_HANDLE:
-            return Ppb->StandardInput;
-
-        case STD_OUTPUT_HANDLE:
-            return Ppb->StandardOutput;
-
-        case STD_ERROR_HANDLE:
-            return Ppb->StandardError;
-    }
-
-    SetLastError (ERROR_INVALID_PARAMETER);
-    return INVALID_HANDLE_VALUE;
-}
-
-
-/*
- * @implemented
- */
-BOOL
-WINAPI
-SetStdHandle(DWORD nStdHandle,
-             HANDLE hHandle)
-     /*
-      * FUNCTION: Set the handle for the standard input, standard output or
-      * the standard error device.
-      * ARGUMENTS:
-      *        nStdHandle - Specifies the handle to be set.
-      *        hHandle - The handle to set.
-      * RETURNS: TRUE if the function succeeds, FALSE otherwise.
-      */
-{
-    PRTL_USER_PROCESS_PARAMETERS Ppb;
-
-    /* no need to check if hHandle == INVALID_HANDLE_VALUE */
-
-    Ppb = NtCurrentPeb()->ProcessParameters;
-
-    switch (nStdHandle)
-    {
-        case STD_INPUT_HANDLE:
-            Ppb->StandardInput = hHandle;
-            return TRUE;
-
-        case STD_OUTPUT_HANDLE:
-            Ppb->StandardOutput = hHandle;
-            return TRUE;
-
-        case STD_ERROR_HANDLE:
-            Ppb->StandardError = hHandle;
-            return TRUE;
-    }
-
-    /* windows for whatever reason sets the last error to ERROR_INVALID_HANDLE here */
-    SetLastError(ERROR_INVALID_HANDLE);
-    return FALSE;
-}
-
-
-static
-BOOL
-IntWriteConsole(HANDLE hConsoleOutput,
-                PVOID lpBuffer,
-                DWORD nNumberOfCharsToWrite,
-                LPDWORD lpNumberOfCharsWritten,
-                LPVOID lpReserved,
-                BOOL bUnicode)
-{
-    PCSR_API_MESSAGE Request;
-    ULONG CsrRequest;
-    NTSTATUS Status;
-    USHORT nChars;
-    ULONG SizeBytes, CharSize;
-    DWORD Written = 0;
-
-    CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
-    Request = RtlAllocateHeap(RtlGetProcessHeap(),
-                              0,
-                              max(sizeof(CSR_API_MESSAGE),
-                              CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE) + min(nNumberOfCharsToWrite,
-                              CSRSS_MAX_WRITE_CONSOLE / CharSize) * CharSize));
-    if (Request == NULL)
-    {
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return FALSE;
-    }
-
-    CsrRequest = CSR_CREATE_API_NUMBER(CSR_CONSOLE, WRITE_CONSOLE);
-
-    while (nNumberOfCharsToWrite > 0)
-    {
-        Request->Data.WriteConsoleRequest.ConsoleHandle = hConsoleOutput;
-        Request->Data.WriteConsoleRequest.Unicode = bUnicode;
-
-        nChars = (USHORT)min(nNumberOfCharsToWrite, CSRSS_MAX_WRITE_CONSOLE / CharSize);
-        Request->Data.WriteConsoleRequest.NrCharactersToWrite = nChars;
-
-        SizeBytes = nChars * CharSize;
-
-        memcpy(Request->Data.WriteConsoleRequest.Buffer, lpBuffer, SizeBytes);
-
-        Status = CsrClientCallServer(Request,
-                                     NULL,
-                                     CsrRequest,
-                                     max(sizeof(CSR_API_MESSAGE),
-                                     CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE) + SizeBytes));
-
-        if (Status == STATUS_PENDING)
-        {
-            WaitForSingleObject(Request->Data.WriteConsoleRequest.UnpauseEvent, INFINITE);
-            CloseHandle(Request->Data.WriteConsoleRequest.UnpauseEvent);
-            continue;
-        }
-        if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status))
-        {
-            RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
-            BaseSetLastNTError(Status);
-            return FALSE;
-        }
-
-        nNumberOfCharsToWrite -= nChars;
-        lpBuffer = (PVOID)((ULONG_PTR)lpBuffer + (ULONG_PTR)SizeBytes);
-        Written += Request->Data.WriteConsoleRequest.NrCharactersWritten;
-    }
-
-    if (lpNumberOfCharsWritten != NULL)
-    {
-        *lpNumberOfCharsWritten = Written;
-    }
-    RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
-
-    return TRUE;
-}
-
-
-/*--------------------------------------------------------------
- *    WriteConsoleA
- *
- * @implemented
- */
-BOOL
-WINAPI
-WriteConsoleA(HANDLE hConsoleOutput,
-              CONST VOID *lpBuffer,
-              DWORD nNumberOfCharsToWrite,
-              LPDWORD lpNumberOfCharsWritten,
-              LPVOID lpReserved)
-{
-    return IntWriteConsole(hConsoleOutput,
-                           (PVOID)lpBuffer,
-                           nNumberOfCharsToWrite,
-                           lpNumberOfCharsWritten,
-                           lpReserved,
-                           FALSE);
-}
-
-
-/*--------------------------------------------------------------
- *    WriteConsoleW
- *
- * @implemented
- */
-BOOL
-WINAPI
-WriteConsoleW(HANDLE hConsoleOutput,
-              CONST VOID *lpBuffer,
-              DWORD nNumberOfCharsToWrite,
-              LPDWORD lpNumberOfCharsWritten,
-              LPVOID lpReserved)
-{
-    return IntWriteConsole(hConsoleOutput,
-                           (PVOID)lpBuffer,
-                           nNumberOfCharsToWrite,
-                           lpNumberOfCharsWritten,
-                           lpReserved,
-                           TRUE);
-}
-
-
-static
-BOOL
-IntReadConsole(HANDLE hConsoleInput,
-               PVOID lpBuffer,
-               DWORD nNumberOfCharsToRead,
-               LPDWORD lpNumberOfCharsRead,
-               PCONSOLE_READCONSOLE_CONTROL pInputControl,
-               BOOL bUnicode)
-{
-    CSR_API_MESSAGE Request;
-    ULONG CsrRequest;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
-    NTSTATUS Status = STATUS_SUCCESS;
-    ULONG CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
-
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, nNumberOfCharsToRead * CharSize);
-    if (CaptureBuffer == NULL)
-    {
-        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return FALSE;
-    }
-
-    CsrAllocateMessagePointer(CaptureBuffer,
-                              nNumberOfCharsToRead * CharSize,
-                              &Request.Data.ReadConsoleRequest.Buffer);
-
-    Request.Data.ReadConsoleRequest.ConsoleHandle = hConsoleInput;
-    Request.Data.ReadConsoleRequest.Unicode = bUnicode;
-    Request.Data.ReadConsoleRequest.NrCharactersToRead = (WORD)nNumberOfCharsToRead;
-    Request.Data.ReadConsoleRequest.NrCharactersRead = 0;
-    Request.Data.ReadConsoleRequest.CtrlWakeupMask = 0;
-    if (pInputControl && pInputControl->nLength == sizeof(CONSOLE_READCONSOLE_CONTROL))
-    {
-        Request.Data.ReadConsoleRequest.NrCharactersRead = pInputControl->nInitialChars;
-        memcpy(Request.Data.ReadConsoleRequest.Buffer,
-               lpBuffer,
-               pInputControl->nInitialChars * sizeof(WCHAR));
-        Request.Data.ReadConsoleRequest.CtrlWakeupMask = pInputControl->dwCtrlWakeupMask;
-    }
-
-    CsrRequest = CSR_CREATE_API_NUMBER(CSR_CONSOLE, READ_CONSOLE);
-
-    do
-    {
-        if (Status == STATUS_PENDING)
-        {
-            Status = NtWaitForSingleObject(Request.Data.ReadConsoleRequest.EventHandle,
-                                           FALSE,
-                                           0);
-            if (!NT_SUCCESS(Status))
-            {
-                DPRINT1("Wait for console input failed!\n");
-                break;
-            }
-        }
-
-        Status = CsrClientCallServer(&Request,
-                                     CaptureBuffer,
-                                     CsrRequest,
-                                     sizeof(CSR_API_MESSAGE));
-        if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-        {
-            DPRINT1("CSR returned error in ReadConsole\n");
-            CsrFreeCaptureBuffer(CaptureBuffer);
-            BaseSetLastNTError(Status);
-            return FALSE;
-        }
-    }
-    while (Status == STATUS_PENDING);
-
-    memcpy(lpBuffer,
-           Request.Data.ReadConsoleRequest.Buffer,
-           Request.Data.ReadConsoleRequest.NrCharactersRead * CharSize);
-
-    if (lpNumberOfCharsRead != NULL)
-        *lpNumberOfCharsRead = Request.Data.ReadConsoleRequest.NrCharactersRead;
-
-    if (pInputControl && pInputControl->nLength == sizeof(CONSOLE_READCONSOLE_CONTROL))
-        pInputControl->dwControlKeyState = Request.Data.ReadConsoleRequest.ControlKeyState;
-
-    CsrFreeCaptureBuffer(CaptureBuffer);
-
-    return TRUE;
-}
-
-
-/*--------------------------------------------------------------
- *    ReadConsoleA
- *
- * @implemented
- */
-BOOL
-WINAPI
-ReadConsoleA(HANDLE hConsoleInput,
-             LPVOID lpBuffer,
-             DWORD nNumberOfCharsToRead,
-             LPDWORD lpNumberOfCharsRead,
-             PCONSOLE_READCONSOLE_CONTROL pInputControl)
-{
-    return IntReadConsole(hConsoleInput,
-                          lpBuffer,
-                          nNumberOfCharsToRead,
-                          lpNumberOfCharsRead,
-                          NULL,
-                          FALSE);
-}
-
-
-/*--------------------------------------------------------------
- *    ReadConsoleW
- *
- * @implemented
- */
-BOOL
-WINAPI
-ReadConsoleW(HANDLE hConsoleInput,
-             LPVOID lpBuffer,
-             DWORD nNumberOfCharsToRead,
-             LPDWORD lpNumberOfCharsRead,
-             PCONSOLE_READCONSOLE_CONTROL pInputControl)
-{
-    return IntReadConsole(hConsoleInput,
-                          lpBuffer,
-                          nNumberOfCharsToRead,
-                          lpNumberOfCharsRead,
-                          pInputControl,
-                          TRUE);
-}
-
-
-/*--------------------------------------------------------------
- *    AllocConsole
- *
- * @implemented
- */
-BOOL
-WINAPI
-AllocConsole(VOID)
-{
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status;
-    HANDLE hStdError;
-    STARTUPINFO si;
-
-    if (NtCurrentPeb()->ProcessParameters->ConsoleHandle)
-    {
-        DPRINT("AllocConsole: Allocate duplicate console to the same Process\n");
-        BaseSetLastNTError (STATUS_OBJECT_NAME_EXISTS);
-        return FALSE;
-    }
-
-    GetStartupInfo(&si);
-
-    Request.Data.AllocConsoleRequest.CtrlDispatcher = ConsoleControlDispatcher;
-    Request.Data.AllocConsoleRequest.ConsoleNeeded = TRUE;
-    Request.Data.AllocConsoleRequest.ShowCmd = si.wShowWindow;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, ALLOC_CONSOLE),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return FALSE;
-    }
-
-    NtCurrentPeb()->ProcessParameters->ConsoleHandle = Request.Data.AllocConsoleRequest.Console;
-
-    SetStdHandle(STD_INPUT_HANDLE, Request.Data.AllocConsoleRequest.InputHandle);
-    SetStdHandle(STD_OUTPUT_HANDLE, Request.Data.AllocConsoleRequest.OutputHandle);
-
-    hStdError = DuplicateConsoleHandle(Request.Data.AllocConsoleRequest.OutputHandle,
-                                       0,
-                                       TRUE,
-                                       DUPLICATE_SAME_ACCESS);
-
-    SetStdHandle(STD_ERROR_HANDLE, hStdError);
-    return TRUE;
-}
-
-
-/*--------------------------------------------------------------
- *    FreeConsole
- *
- * @implemented
- */
-BOOL
-WINAPI
-FreeConsole(VOID)
-{
-    // AG: I'm not sure if this is correct (what happens to std handles?)
-    // but I just tried to reverse what AllocConsole() does...
-
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, FREE_CONSOLE),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return FALSE;
-    }
-
-    NtCurrentPeb()->ProcessParameters->ConsoleHandle = NULL;
-    return TRUE;
-}
-
-
-/*--------------------------------------------------------------
- *    GetConsoleScreenBufferInfo
- *
- * @implemented
- */
-BOOL
-WINAPI
-GetConsoleScreenBufferInfo(HANDLE hConsoleOutput,
-                           PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
-{
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status;
-
-    Request.Data.ScreenBufferInfoRequest.ConsoleHandle = hConsoleOutput;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SCREEN_BUFFER_INFO),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return FALSE;
-    }
-    *lpConsoleScreenBufferInfo = Request.Data.ScreenBufferInfoRequest.Info;
-    return TRUE;
-}
-
-
-/*--------------------------------------------------------------
- *    SetConsoleCursorPosition
- *
- * @implemented
- */
-BOOL
-WINAPI
-SetConsoleCursorPosition(HANDLE hConsoleOutput,
-                         COORD dwCursorPosition)
-{
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status;
-
-    Request.Data.SetCursorRequest.ConsoleHandle = hConsoleOutput;
-    Request.Data.SetCursorRequest.Position = dwCursorPosition;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_CURSOR),
-                                 sizeof(CSR_API_MESSAGE));
-    if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-
-static
-BOOL
-IntFillConsoleOutputCharacter(HANDLE hConsoleOutput,
-                              PVOID cCharacter,
-                              DWORD nLength,
-                              COORD dwWriteCoord,
-                              LPDWORD lpNumberOfCharsWritten,
-                              BOOL bUnicode)
-{
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status;
-
-    Request.Data.FillOutputRequest.ConsoleHandle = hConsoleOutput;
-    Request.Data.FillOutputRequest.Unicode = bUnicode;
-
-    if(bUnicode)
-        Request.Data.FillOutputRequest.Char.UnicodeChar = *((WCHAR*)cCharacter);
-    else
-        Request.Data.FillOutputRequest.Char.AsciiChar = *((CHAR*)cCharacter);
-
-    Request.Data.FillOutputRequest.Position = dwWriteCoord;
-    Request.Data.FillOutputRequest.Length = (WORD)nLength;
-
-    Status = CsrClientCallServer(&Request,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, FILL_OUTPUT),
-                                 sizeof(CSR_API_MESSAGE));
-
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-    {
-        BaseSetLastNTError(Status);
-        return FALSE;
-    }
-
-    if(lpNumberOfCharsWritten != NULL)
-    {
-        *lpNumberOfCharsWritten = Request.Data.FillOutputRequest.NrCharactersWritten;
-    }
-
-    return TRUE;
-}
-
-/*--------------------------------------------------------------
- *    FillConsoleOutputCharacterA
- *
- * @implemented
- */
-BOOL
-WINAPI
-FillConsoleOutputCharacterA(HANDLE hConsoleOutput,
-                            CHAR cCharacter,
-                            DWORD nLength,
-                            COORD dwWriteCoord,
-                            LPDWORD lpNumberOfCharsWritten)
-{
-    return IntFillConsoleOutputCharacter(hConsoleOutput,
-                                         &cCharacter,
-                                         nLength,
-                                         dwWriteCoord,
-                                         lpNumberOfCharsWritten,
-                                         FALSE);
-}
-
-
-/*--------------------------------------------------------------
- *    FillConsoleOutputCharacterW
- *
- * @implemented
- */
-BOOL
-WINAPI
-FillConsoleOutputCharacterW(HANDLE hConsoleOutput,
-                            WCHAR cCharacter,
-                            DWORD nLength,
-                            COORD dwWriteCoord,
-                            LPDWORD lpNumberOfCharsWritten)
-{
-    return IntFillConsoleOutputCharacter(hConsoleOutput,
-                                         &cCharacter,
-                                         nLength,
-                                         dwWriteCoord,
-                                         lpNumberOfCharsWritten,
-                                         TRUE);
-}
-
-
-static
-BOOL
-IntPeekConsoleInput(HANDLE hConsoleInput,
-                    PINPUT_RECORD lpBuffer,
-                    DWORD nLength,
-                    LPDWORD lpNumberOfEventsRead,
-                    BOOL bUnicode)
-{
-    CSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
-    ULONG Size;
-
-    if (lpBuffer == NULL)
-    {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return FALSE;
-    }
-
-    Size = nLength * sizeof(INPUT_RECORD);
-
-    /* Allocate a Capture Buffer */
-    DPRINT("IntPeekConsoleInput: %lx %p\n", Size, lpNumberOfEventsRead);
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, Size);
-    if (CaptureBuffer == NULL)
-    {
-        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return FALSE;
-    }
-
-    /* Allocate space in the Buffer */
-    CsrCaptureMessageBuffer(CaptureBuffer,
-                            NULL,
-                            Size,
-                            (PVOID*)&Request.Data.PeekConsoleInputRequest.InputRecord);
-
-    /* Set up the data to send to the Console Server */
-    Request.Data.PeekConsoleInputRequest.ConsoleHandle = hConsoleInput;
-    Request.Data.PeekConsoleInputRequest.Unicode = bUnicode;
-    Request.Data.PeekConsoleInputRequest.Length = nLength;
-
-    /* Call the server */
-    CsrClientCallServer(&Request,
-                        CaptureBuffer,
-                        CSR_CREATE_API_NUMBER(CSR_CONSOLE, PEEK_CONSOLE_INPUT),
-                        sizeof(CSR_API_MESSAGE));
-    DPRINT("Server returned: %x\n", Request.Status);
-
-    /* Check for success*/
-    if (NT_SUCCESS(Request.Status))
-    {
-        /* Return the number of events read */
-        DPRINT("Events read: %lx\n", Request.Data.PeekConsoleInputRequest.Length);
-        *lpNumberOfEventsRead = Request.Data.PeekConsoleInputRequest.Length;
-
-        /* Copy into the buffer */
-        DPRINT("Copying to buffer\n");
-        RtlCopyMemory(lpBuffer,
-                      Request.Data.PeekConsoleInputRequest.InputRecord,
-                      sizeof(INPUT_RECORD) * *lpNumberOfEventsRead);
-    }
-    else
-    {
-        /* Error out */
-       *lpNumberOfEventsRead = 0;
-       BaseSetLastNTError(Request.Status);
-    }
-
-    /* Release the capture buffer */
-    CsrFreeCaptureBuffer(CaptureBuffer);
-
-    /* Return TRUE or FALSE */
-    return NT_SUCCESS(Request.Status);
-}
-
-/*--------------------------------------------------------------
- *     PeekConsoleInputA
- *
- * @implemented
- */
-BOOL
-WINAPI
-PeekConsoleInputA(HANDLE hConsoleInput,
-                  PINPUT_RECORD lpBuffer,
-                  DWORD nLength,
-                  LPDWORD lpNumberOfEventsRead)
-{
-    return IntPeekConsoleInput(hConsoleInput,
-                               lpBuffer,
-                               nLength,
-                               lpNumberOfEventsRead,
-                               FALSE);
-}
-
-
-/*--------------------------------------------------------------
- *     PeekConsoleInputW
- *
- * @implemented
- */
-BOOL
-WINAPI
-PeekConsoleInputW(HANDLE hConsoleInput,
-                  PINPUT_RECORD lpBuffer,
-                  DWORD nLength,
-                  LPDWORD lpNumberOfEventsRead)
-{
-    return IntPeekConsoleInput(hConsoleInput,
-                               lpBuffer, nLength,
-                               lpNumberOfEventsRead,
-                               TRUE);
-}
-
-
-static
-BOOL
-IntReadConsoleInput(HANDLE hConsoleInput,
-                    PINPUT_RECORD lpBuffer,
-                    DWORD nLength,
-                    LPDWORD lpNumberOfEventsRead,
-                    BOOL bUnicode)
-{
-    CSR_API_MESSAGE Request;
-    ULONG CsrRequest;
-    ULONG Read;
-    NTSTATUS Status;
-
-    CsrRequest = CSR_CREATE_API_NUMBER(CSR_CONSOLE, READ_INPUT);
-    Read = 0;
-
-    while (nLength > 0)
-    {
-        Request.Data.ReadInputRequest.ConsoleHandle = hConsoleInput;
-        Request.Data.ReadInputRequest.Unicode = bUnicode;
-
-        Status = CsrClientCallServer(&Request,
-                                     NULL,
-                                     CsrRequest,
-                                     sizeof(CSR_API_MESSAGE));
-        if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
-        {
-            if (Read == 0)
-            {
-                /* we couldn't read a single record, fail */
-                BaseSetLastNTError(Status);
-                return FALSE;
-            }
-            else
-            {
-                /* FIXME - fail gracefully in case we already read at least one record? */
-                break;
-            }
-        }
-        else if (Status == STATUS_PENDING)
-        {
-            if (Read == 0)
-            {
-                Status = NtWaitForSingleObject(Request.Data.ReadInputRequest.Event, FALSE, 0);
-                if (!NT_SUCCESS(Status))
-                {
-                    BaseSetLastNTError(Status);
-                    break;
-                }
-            }
-            else
-            {
-                /* nothing more to read (waiting for more input??), let's just bail */
-                break;
-            }
-        }
-        else
-        {
-            lpBuffer[Read++] = Request.Data.ReadInputRequest.Input;
-            nLength--;
-
-            if (!Request.Data.ReadInputRequest.MoreEvents)
-            {
-                /* nothing more to read, bail */
-                break;
-            }
-        }
-    }
-
-    if (lpNumberOfEventsRead != NULL)
-    {
-        *lpNumberOfEventsRead = Read;
-    }
-
-    return (Read > 0);
-}
-
-
-/*--------------------------------------------------------------
- *     ReadConsoleInputA
- *
- * @implemented
- */
-BOOL
-WINAPI
-ReadConsoleInputA(HANDLE hConsoleInput,
-                  PINPUT_RECORD lpBuffer,
-                  DWORD nLength,
-                  LPDWORD lpNumberOfEventsRead)
-{
-    return IntReadConsoleInput(hConsoleInput,
-                               lpBuffer,
-                               nLength,
-                               lpNumberOfEventsRead,
-                               FALSE);
-}
-
-
-/*--------------------------------------------------------------
- *     ReadConsoleInputW
- *
- * @implemented
- */
-BOOL
-WINAPI
-ReadConsoleInputW(HANDLE hConsoleInput,
-                  PINPUT_RECORD lpBuffer,
-                  DWORD nLength,
-                  LPDWORD lpNumberOfEventsRead)
-{
-    return IntReadConsoleInput(hConsoleInput,
-                               lpBuffer,
-                               nLength,
-                               lpNumberOfEventsRead,
-                               TRUE);
-}
-
-
-static
-BOOL
-IntWriteConsoleInput(HANDLE hConsoleInput,
-                     PINPUT_RECORD lpBuffer,
-                     DWORD nLength,
-                     LPDWORD lpNumberOfEventsWritten,
-                     BOOL bUnicode)
-{
-    CSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
-    DWORD Size;
-
-    if (lpBuffer == NULL)
-    {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return FALSE;
-    }
-
-    Size = nLength * sizeof(INPUT_RECORD);
-
-    /* Allocate a Capture Buffer */
-    DPRINT("IntWriteConsoleInput: %lx %p\n", Size, lpNumberOfEventsWritten);
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, Size);
-    if (CaptureBuffer == NULL)
-    {
-        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return FALSE;
-    }
-
-    /* Allocate space in the Buffer */
-    CsrCaptureMessageBuffer(CaptureBuffer,
-                            lpBuffer,
-                            Size,
-                            (PVOID*)&Request.Data.WriteConsoleInputRequest.InputRecord);
-
-    /* Set up the data to send to the Console Server */
-    Request.Data.WriteConsoleInputRequest.ConsoleHandle = hConsoleInput;
-    Request.Data.WriteConsoleInputRequest.Unicode = bUnicode;
-    Request.Data.WriteConsoleInputRequest.Length = nLength;
-
-    /* Call the server */
-    CsrClientCallServer(&Request,
-                        CaptureBuffer,
-                        CSR_CREATE_API_NUMBER(CSR_CONSOLE, WRITE_CONSOLE_INPUT),
-                        sizeof(CSR_API_MESSAGE));
-    DPRINT("Server returned: %x\n", Request.Status);
-
-    /* Check for success*/
-    if (NT_SUCCESS(Request.Status))
-    {
-        /* Return the number of events read */
-        DPRINT("Events read: %lx\n", Request.Data.WriteConsoleInputRequest.Length);
-        *lpNumberOfEventsWritten = Request.Data.WriteConsoleInputRequest.Length;
-    }
-    else
-    {
-        /* Error out */
-        *lpNumberOfEventsWritten = 0;
-        BaseSetLastNTError(Request.Status);
-    }
-
-    /* Release the capture buffer */
-    CsrFreeCaptureBuffer(CaptureBuffer);
-
-    /* Return TRUE or FALSE */
-    return NT_SUCCESS(Request.Status);
-}
-
-
-/*--------------------------------------------------------------
- *     WriteConsoleInputA
- *
- * @implemented
- */
-BOOL
-WINAPI
-WriteConsoleInputA(HANDLE hConsoleInput,
-                   CONST INPUT_RECORD *lpBuffer,
-                   DWORD nLength,
-                   LPDWORD lpNumberOfEventsWritten)
-{
-    return IntWriteConsoleInput(hConsoleInput,
-                                (PINPUT_RECORD)lpBuffer,
-                                nLength,
-                                lpNumberOfEventsWritten,
-                                FALSE);
-}
-
-
-/*--------------------------------------------------------------
- *     WriteConsoleInputW
- *
- * @implemented
- */
-BOOL
-WINAPI
-WriteConsoleInputW(HANDLE hConsoleInput,
-                   CONST INPUT_RECORD *lpBuffer,
-                   DWORD nLength,
-                   LPDWORD lpNumberOfEventsWritten)
-{
-    return IntWriteConsoleInput(hConsoleInput,
-                                (PINPUT_RECORD)lpBuffer,
-                                nLength,
-                                lpNumberOfEventsWritten,
-                                TRUE);
-}
-
-
-static
-BOOL
-IntReadConsoleOutput(HANDLE hConsoleOutput,
-                     PCHAR_INFO lpBuffer,
-                     COORD dwBufferSize,
-                     COORD dwBufferCoord,
-                     PSMALL_RECT lpReadRegion,
-                     BOOL bUnicode)
-{
-    CSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
-    DWORD Size, SizeX, SizeY;
-
-    if (lpBuffer == NULL)
-    {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return FALSE;
-    }
-
-    Size = dwBufferSize.X * dwBufferSize.Y * sizeof(CHAR_INFO);
-
-    /* Allocate a Capture Buffer */
-    DPRINT("IntReadConsoleOutput: %lx %p\n", Size, lpReadRegion);
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, Size);
-    if (CaptureBuffer == NULL)
-    {
-        DPRINT1("CsrAllocateCaptureBuffer failed with size 0x%x!\n", Size);
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return FALSE;
-    }
-
-    /* Allocate space in the Buffer */
-    CsrCaptureMessageBuffer(CaptureBuffer,
-                            NULL,
-                            Size,
-                            (PVOID*)&Request.Data.ReadConsoleOutputRequest.CharInfo);
-
-    /* Set up the data to send to the Console Server */
-    Request.Data.ReadConsoleOutputRequest.ConsoleHandle = hConsoleOutput;
-    Request.Data.ReadConsoleOutputRequest.Unicode = bUnicode;
-    Request.Data.ReadConsoleOutputRequest.BufferSize = dwBufferSize;
-    Request.Data.ReadConsoleOutputRequest.BufferCoord = dwBufferCoord;
-    Request.Data.ReadConsoleOutputRequest.ReadRegion = *lpReadRegion;
-
-    /* Call the server */
-    CsrClientCallServer(&Request,
-                        CaptureBuffer,
-                        CSR_CREATE_API_NUMBER(CSR_CONSOLE, READ_CONSOLE_OUTPUT),
-                        sizeof(CSR_API_MESSAGE));
-    DPRINT("Server returned: %x\n", Request.Status);
-
-    /* Check for success*/
-    if (NT_SUCCESS(Request.Status))
-    {
-        /* Copy into the buffer */
-        DPRINT("Copying to buffer\n");
-        SizeX = Request.Data.ReadConsoleOutputRequest.ReadRegion.Right -
-                Request.Data.ReadConsoleOutputRequest.ReadRegion.Left + 1;
-        SizeY = Request.Data.ReadConsoleOutputRequest.ReadRegion.Bottom -
-                Request.Data.ReadConsoleOutputRequest.ReadRegion.Top + 1;
-        RtlCopyMemory(lpBuffer,
-                      Request.Data.ReadConsoleOutputRequest.CharInfo,
-                      sizeof(CHAR_INFO) * SizeX * SizeY);
-    }
-    else
-    {
-        /* Error out */
-        BaseSetLastNTError(Request.Status);
-    }
-
-    /* Return the read region */
-    DPRINT("read region: %lx\n", Request.Data.ReadConsoleOutputRequest.ReadRegion);
-    *lpReadRegion = Request.Data.ReadConsoleOutputRequest.ReadRegion;
-
-    /* Release the capture buffer */
-    CsrFreeCaptureBuffer(CaptureBuffer);
-
-    /* Return TRUE or FALSE */
-    return NT_SUCCESS(Request.Status);
-}
-
-/*--------------------------------------------------------------
- *     ReadConsoleOutputA
- *
- * @implemented
- */
-BOOL
-WINAPI
-ReadConsoleOutputA(HANDLE hConsoleOutput,
-                   PCHAR_INFO lpBuffer,
-                   COORD dwBufferSize,
-                   COORD dwBufferCoord,
-                   PSMALL_RECT lpReadRegion)
-{
-    return IntReadConsoleOutput(hConsoleOutput,
-                                lpBuffer,
-                                dwBufferSize,
-                                dwBufferCoord,
-                                lpReadRegion,
-                                FALSE);
-}
-
-
-/*--------------------------------------------------------------
- *     ReadConsoleOutputW
- *
- * @implemented
- */
-BOOL
-WINAPI
-ReadConsoleOutputW(HANDLE hConsoleOutput,
-                   PCHAR_INFO lpBuffer,
-                   COORD dwBufferSize,
-                   COORD dwBufferCoord,
-                   PSMALL_RECT lpReadRegion)
-{
-    return IntReadConsoleOutput(hConsoleOutput,
-                                lpBuffer,
-                                dwBufferSize,
-                                dwBufferCoord,
-                                lpReadRegion,
-                                TRUE);
-}
-
-
-static
-BOOL
-IntWriteConsoleOutput(HANDLE hConsoleOutput,
-                      CONST CHAR_INFO *lpBuffer,
-                      COORD dwBufferSize,
-                      COORD dwBufferCoord,
-                      PSMALL_RECT lpWriteRegion,
-                      BOOL bUnicode)
-{
-    CSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
-    ULONG Size;
-
-    Size = dwBufferSize.Y * dwBufferSize.X * sizeof(CHAR_INFO);
-
-    /* Allocate a Capture Buffer */
-    DPRINT("IntWriteConsoleOutput: %lx %p\n", Size, lpWriteRegion);
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, Size);
-    if (CaptureBuffer == NULL)
-    {
-        DPRINT1("CsrAllocateCaptureBuffer failed!\n");
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return FALSE;
-    }
-
-    /* Allocate space in the Buffer */
-    CsrCaptureMessageBuffer(CaptureBuffer,
-                            NULL,
-                            Size,
-                            (PVOID*)&Request.Data.WriteConsoleOutputRequest.CharInfo);
-
-    /* Copy from the buffer */
-    RtlCopyMemory(Request.Data.WriteConsoleOutputRequest.CharInfo, lpBuffer, Size);
-
-    /* Set up the data to send to the Console Server */
-    Request.Data.WriteConsoleOutputRequest.ConsoleHandle = hConsoleOutput;
-    Request.Data.WriteConsoleOutputRequest.Unicode = bUnicode;
-    Request.Data.WriteConsoleOutputRequest.BufferSize = dwBufferSize;
-    Request.Data.WriteConsoleOutputRequest.BufferCoord = dwBufferCoord;
-    Request.Data.WriteConsoleOutputRequest.WriteRegion = *lpWriteRegion;
-
-    /* Call the server */
-    CsrClientCallServer(&Request,
-                        CaptureBuffer,
-                        CSR_CREATE_API_NUMBER(CSR_CONSOLE, WRITE_CONSOLE_OUTPUT),
-                        sizeof(CSR_API_MESSAGE));
-    DPRINT("Server returned: %x\n", Request.Status);
-
-    /* Check for success*/
-    if (!NT_SUCCESS(Request.Status))
-    {
-        /* Error out */
-        BaseSetLastNTError(Request.Status);
-    }
-
-    /* Return the read region */
-    DPRINT("read region: %lx\n", Request.Data.WriteConsoleOutputRequest.WriteRegion);
-    *lpWriteRegion = Request.Data.WriteConsoleOutputRequest.WriteRegion;
-
-    /* Release the capture buffer */
-    CsrFreeCaptureBuffer(CaptureBuffer);
-
-    /* Return TRUE or FALSE */
-    return NT_SUCCESS(Request.Status);
-}
-
-/*--------------------------------------------------------------
- *     WriteConsoleOutputA
- *
- * @implemented
- */
-BOOL
-WINAPI
-WriteConsoleOutputA(HANDLE hConsoleOutput,
-                    CONST CHAR_INFO *lpBuffer,
-                    COORD dwBufferSize,
-                    COORD dwBufferCoord,
-                    PSMALL_RECT lpWriteRegion)
-{
-    return IntWriteConsoleOutput(hConsoleOutput,
-                                 lpBuffer,
-                                 dwBufferSize,
-                                 dwBufferCoord,
-                                 lpWriteRegion,
-                                 FALSE);
-}
-
-
-/*--------------------------------------------------------------
- *     WriteConsoleOutputW
- *
- * @implemented
- */
-BOOL
-WINAPI
-WriteConsoleOutputW(HANDLE hConsoleOutput,
-                    CONST CHAR_INFO *lpBuffer,
-                    COORD dwBufferSize,
-                    COORD dwBufferCoord,
-                    PSMALL_RECT lpWriteRegion)
-{
-    return IntWriteConsoleOutput(hConsoleOutput,
-                                 lpBuffer,
-                                 dwBufferSize,
-                                 dwBufferCoord,
-                                 lpWriteRegion,
-                                 TRUE);
-}
-
-
-static
-BOOL
-IntReadConsoleOutputCharacter(HANDLE hConsoleOutput,
-                              PVOID lpCharacter,
-                              DWORD nLength,
-                              COORD dwReadCoord,
-                              LPDWORD lpNumberOfCharsRead,
-                              BOOL bUnicode)
-{
-    PCSR_API_MESSAGE Request;
-    ULONG CsrRequest;
-    NTSTATUS Status;
-    ULONG SizeBytes, CharSize;
-    DWORD CharsRead = 0;
-
-    CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
-
-    nLength = min(nLength, CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR / CharSize);
-    SizeBytes = nLength * CharSize;
-
-    Request = RtlAllocateHeap(RtlGetProcessHeap(), 0,
-                              max(sizeof(CSR_API_MESSAGE),
-                              CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR) + SizeBytes));
-    if (Request == NULL)
-    {
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return FALSE;
-    }
-
-    CsrRequest = CSR_CREATE_API_NUMBER(CSR_CONSOLE, READ_CONSOLE_OUTPUT_CHAR);
-    Request->Data.ReadConsoleOutputCharRequest.ReadCoord = dwReadCoord;
-
-    while (nLength > 0)
-    {
-        DWORD BytesRead;
-
-        Request->Data.ReadConsoleOutputCharRequest.ConsoleHandle = hConsoleOutput;
-        Request->Data.ReadConsoleOutputCharRequest.Unicode = bUnicode;
-        Request->Data.ReadConsoleOutputCharRequest.NumCharsToRead = nLength;
-        SizeBytes = Request->Data.ReadConsoleOutputCharRequest.NumCharsToRead * CharSize;
-
-        Status = CsrClientCallServer(Request,
-                                     NULL,
-                                     CsrRequest,
-                                     max(sizeof(CSR_API_MESSAGE),
-                                     CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR) + SizeBytes));
-        if (!NT_SUCCESS(Status) || !NT_SUCCESS(Request->Status))
-        {
-            RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
-            BaseSetLastNTError(Status);
-            break;
-        }
-
-        BytesRead = Request->Data.ReadConsoleOutputCharRequest.CharsRead * CharSize;
-        memcpy(lpCharacter, Request->Data.ReadConsoleOutputCharRequest.String, BytesRead);
-        lpCharacter = (PVOID)((ULONG_PTR)lpCharacter + (ULONG_PTR)BytesRead);
-        CharsRead += Request->Data.ReadConsoleOutputCharRequest.CharsRead;
-        nLength -= Request->Data.ReadConsoleOutputCharRequest.CharsRead;
+ */
+BOOL
+WINAPI
+CloseConsoleHandle(HANDLE Handle)
+{
+    NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-        Request->Data.ReadConsoleOutputCharRequest.ReadCoord = Request->Data.ReadConsoleOutputCharRequest.EndCoord;
-    }
+    ApiMessage.Data.CloseHandleRequest.Handle = Handle;
 
-    if (lpNumberOfCharsRead != NULL)
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepCloseHandle),
+                                 sizeof(CSRSS_CLOSE_HANDLE));
+    if (!NT_SUCCESS(Status))
     {
-        *lpNumberOfCharsRead = CharsRead;
+        BaseSetLastNTError(Status);
+        return FALSE;
     }
 
-    RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
-
     return TRUE;
 }
 
 
-/*--------------------------------------------------------------
- *     ReadConsoleOutputCharacterA
- *
+/*
  * @implemented
  */
-BOOL
+HANDLE
 WINAPI
-ReadConsoleOutputCharacterA(HANDLE hConsoleOutput,
-                            LPSTR lpCharacter,
-                            DWORD nLength,
-                            COORD dwReadCoord,
-                            LPDWORD lpNumberOfCharsRead)
-{
-    return IntReadConsoleOutputCharacter(hConsoleOutput,
-                                         (PVOID)lpCharacter,
-                                         nLength,
-                                         dwReadCoord,
-                                         lpNumberOfCharsRead,
-                                         FALSE);
-}
-
-
-/*--------------------------------------------------------------
- *      ReadConsoleOutputCharacterW
+GetStdHandle(DWORD nStdHandle)
+/*
+ * FUNCTION: Get a handle for the standard input, standard output
+ * and a standard error device.
  *
- * @implemented
+ * ARGUMENTS:
+ *       nStdHandle - Specifies the device for which to return the handle.
+ *
+ * RETURNS: If the function succeeds, the return value is the handle
+ * of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
  */
-BOOL
-WINAPI
-ReadConsoleOutputCharacterW(HANDLE hConsoleOutput,
-                            LPWSTR lpCharacter,
-                            DWORD nLength,
-                            COORD dwReadCoord,
-                            LPDWORD lpNumberOfCharsRead)
 {
-    return IntReadConsoleOutputCharacter(hConsoleOutput,
-                                         (PVOID)lpCharacter,
-                                         nLength,
-                                         dwReadCoord,
-                                         lpNumberOfCharsRead,
-                                         TRUE);
+    PRTL_USER_PROCESS_PARAMETERS Ppb;
+
+    Ppb = NtCurrentPeb()->ProcessParameters;
+    switch (nStdHandle)
+    {
+        case STD_INPUT_HANDLE:
+            return Ppb->StandardInput;
+
+        case STD_OUTPUT_HANDLE:
+            return Ppb->StandardOutput;
+
+        case STD_ERROR_HANDLE:
+            return Ppb->StandardError;
+    }
+
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return INVALID_HANDLE_VALUE;
 }
 
 
-/*--------------------------------------------------------------
- *     ReadConsoleOutputAttribute
- *
+/*
  * @implemented
  */
 BOOL
 WINAPI
-ReadConsoleOutputAttribute(HANDLE hConsoleOutput,
-                           LPWORD lpAttribute,
-                           DWORD nLength,
-                           COORD dwReadCoord,
-                           LPDWORD lpNumberOfAttrsRead)
+SetStdHandle(DWORD nStdHandle,
+             HANDLE hHandle)
+/*
+ * FUNCTION: Set the handle for the standard input, standard output or
+ * the standard error device.
+ *
+ * ARGUMENTS:
+ *        nStdHandle - Specifies the handle to be set.
+ *        hHandle - The handle to set.
+ *
+ * RETURNS: TRUE if the function succeeds, FALSE otherwise.
+ */
 {
-    PCSR_API_MESSAGE Request;
-    ULONG CsrRequest;
-    NTSTATUS Status;
-    DWORD Size;
-
-    if (lpNumberOfAttrsRead != NULL)
-        *lpNumberOfAttrsRead = nLength;
+    PRTL_USER_PROCESS_PARAMETERS Ppb;
 
-    Request = RtlAllocateHeap(RtlGetProcessHeap(),
-                              0,
-                              max(sizeof(CSR_API_MESSAGE),
-                              CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB)
-                                  + min (nLength, CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB / sizeof(WORD)) * sizeof(WORD)));
-    if (Request == NULL)
-    {
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return FALSE;
-    }
+    /* no need to check if hHandle == INVALID_HANDLE_VALUE */
 
-    CsrRequest = CSR_CREATE_API_NUMBER(CSR_CONSOLE, READ_CONSOLE_OUTPUT_ATTRIB);
+    Ppb = NtCurrentPeb()->ProcessParameters;
 
-    while (nLength != 0)
+    switch (nStdHandle)
     {
-        Request->Data.ReadConsoleOutputAttribRequest.ConsoleHandle = hConsoleOutput;
-        Request->Data.ReadConsoleOutputAttribRequest.ReadCoord = dwReadCoord;
-
-        if (nLength > CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB / sizeof(WORD))
-            Size = CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB / sizeof(WCHAR);
-        else
-            Size = nLength;
-
-        Request->Data.ReadConsoleOutputAttribRequest.NumAttrsToRead = Size;
+        case STD_INPUT_HANDLE:
+            Ppb->StandardInput = hHandle;
+            return TRUE;
 
-        Status = CsrClientCallServer(Request,
-                                     NULL,
-                                     CsrRequest,
-                                     max(sizeof(CSR_API_MESSAGE),
-                                     CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB) + Size * sizeof(WORD)));
-        if (!NT_SUCCESS(Status) || !NT_SUCCESS(Request->Status))
-        {
-            RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
-            BaseSetLastNTError(Status);
-            return FALSE;
-        }
+        case STD_OUTPUT_HANDLE:
+            Ppb->StandardOutput = hHandle;
+            return TRUE;
 
-        memcpy(lpAttribute, Request->Data.ReadConsoleOutputAttribRequest.Attribute, Size * sizeof(WORD));
-        lpAttribute += Size;
-        nLength -= Size;
-        Request->Data.ReadConsoleOutputAttribRequest.ReadCoord = Request->Data.ReadConsoleOutputAttribRequest.EndCoord;
+        case STD_ERROR_HANDLE:
+            Ppb->StandardError = hHandle;
+            return TRUE;
     }
 
-    RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
-
-    return TRUE;
+    /* windows for whatever reason sets the last error to ERROR_INVALID_HANDLE here */
+    SetLastError(ERROR_INVALID_HANDLE);
+    return FALSE;
 }
 
 
-static
+/*--------------------------------------------------------------
+ *    AllocConsole
+ *
+ * @implemented
+ */
 BOOL
-IntWriteConsoleOutputCharacter(HANDLE hConsoleOutput,
-                               PVOID lpCharacter,
-                               DWORD nLength,
-                               COORD dwWriteCoord,
-                               LPDWORD lpNumberOfCharsWritten,
-                               BOOL bUnicode)
+WINAPI
+AllocConsole(VOID)
 {
-    PCSR_API_MESSAGE Request;
-    ULONG CsrRequest;
     NTSTATUS Status;
-    ULONG CharSize, nChars;
-    //ULONG SizeBytes;
-    DWORD Written = 0;
-
-    CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
-
-    nChars = min(nLength, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR / CharSize);
-    //SizeBytes = nChars * CharSize;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_ALLOC_CONSOLE AllocConsoleRequest = &ApiMessage.Data.AllocConsoleRequest;
+    HANDLE hStdError;
+    STARTUPINFO si;
 
-    Request = RtlAllocateHeap(RtlGetProcessHeap(), 0,
-                              max(sizeof(CSR_API_MESSAGE),
-                              CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR)
-                                + min (nChars, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR / CharSize) * CharSize));
-    if (Request == NULL)
+    if (NtCurrentPeb()->ProcessParameters->ConsoleHandle)
     {
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        DPRINT("AllocConsole: Allocate duplicate console to the same Process\n");
+        BaseSetLastNTError (STATUS_OBJECT_NAME_EXISTS);
         return FALSE;
     }
 
-    CsrRequest = CSR_CREATE_API_NUMBER(CSR_CONSOLE, WRITE_CONSOLE_OUTPUT_CHAR);
-    Request->Data.WriteConsoleOutputCharRequest.Coord = dwWriteCoord;
-
-    while (nLength > 0)
-    {
-        DWORD BytesWrite;
-
-        Request->Data.WriteConsoleOutputCharRequest.ConsoleHandle = hConsoleOutput;
-        Request->Data.WriteConsoleOutputCharRequest.Unicode = bUnicode;
-        Request->Data.WriteConsoleOutputCharRequest.Length = (WORD)min(nLength, nChars);
-        BytesWrite = Request->Data.WriteConsoleOutputCharRequest.Length * CharSize;
-
-        memcpy(Request->Data.WriteConsoleOutputCharRequest.String, lpCharacter, BytesWrite);
-
-        Status = CsrClientCallServer(Request,
-                                     NULL,
-                                     CsrRequest,
-                                     max(sizeof(CSR_API_MESSAGE),
-                                     CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR) + BytesWrite));
-
-        if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status))
-        {
-            RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
-            BaseSetLastNTError(Status);
-            return FALSE;
-        }
-
-        nLength -= Request->Data.WriteConsoleOutputCharRequest.NrCharactersWritten;
-        lpCharacter = (PVOID)((ULONG_PTR)lpCharacter + (ULONG_PTR)(Request->Data.WriteConsoleOutputCharRequest.NrCharactersWritten * CharSize));
-        Written += Request->Data.WriteConsoleOutputCharRequest.NrCharactersWritten;
+    GetStartupInfo(&si);
 
-        Request->Data.WriteConsoleOutputCharRequest.Coord = Request->Data.WriteConsoleOutputCharRequest.EndCoord;
-    }
+    AllocConsoleRequest->CtrlDispatcher = ConsoleControlDispatcher;
+    AllocConsoleRequest->ConsoleNeeded = TRUE;
+    AllocConsoleRequest->ShowCmd = si.wShowWindow;
 
-    if (lpNumberOfCharsWritten != NULL)
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepAlloc),
+                                 sizeof(CSRSS_ALLOC_CONSOLE));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
-        *lpNumberOfCharsWritten = Written;
+        BaseSetLastNTError(Status);
+        return FALSE;
     }
 
-    RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
+    NtCurrentPeb()->ProcessParameters->ConsoleHandle = AllocConsoleRequest->Console;
+
+    SetStdHandle(STD_INPUT_HANDLE, AllocConsoleRequest->InputHandle);
+    SetStdHandle(STD_OUTPUT_HANDLE, AllocConsoleRequest->OutputHandle);
+
+    hStdError = DuplicateConsoleHandle(AllocConsoleRequest->OutputHandle,
+                                       0,
+                                       TRUE,
+                                       DUPLICATE_SAME_ACCESS);
 
+    SetStdHandle(STD_ERROR_HANDLE, hStdError);
     return TRUE;
 }
 
 
 /*--------------------------------------------------------------
- *     WriteConsoleOutputCharacterA
+ *    FreeConsole
  *
  * @implemented
  */
 BOOL
 WINAPI
-WriteConsoleOutputCharacterA(HANDLE hConsoleOutput,
-                             LPCSTR lpCharacter,
-                             DWORD nLength,
-                             COORD dwWriteCoord,
-                             LPDWORD lpNumberOfCharsWritten)
+FreeConsole(VOID)
 {
-    return IntWriteConsoleOutputCharacter(hConsoleOutput,
-                                          (PVOID)lpCharacter,
-                                          nLength,
-                                          dwWriteCoord,
-                                          lpNumberOfCharsWritten,
-                                          FALSE);
-}
+    // AG: I'm not sure if this is correct (what happens to std handles?)
+    // but I just tried to reverse what AllocConsole() does...
 
+    NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-/*--------------------------------------------------------------
- *     WriteConsoleOutputCharacterW
- *
- * @implemented
- */
-BOOL
-WINAPI
-WriteConsoleOutputCharacterW(HANDLE hConsoleOutput,
-                             LPCWSTR lpCharacter,
-                             DWORD nLength,
-                             COORD dwWriteCoord,
-                             LPDWORD lpNumberOfCharsWritten)
-{
-    return IntWriteConsoleOutputCharacter(hConsoleOutput,
-                                          (PVOID)lpCharacter,
-                                          nLength,
-                                          dwWriteCoord,
-                                          lpNumberOfCharsWritten,
-                                          TRUE);
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepFree),
+                                 sizeof(CSRSS_FREE_CONSOLE));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
+    {
+        BaseSetLastNTError(Status);
+        return FALSE;
+    }
+
+    NtCurrentPeb()->ProcessParameters->ConsoleHandle = NULL;
+    return TRUE;
 }
 
 
 /*--------------------------------------------------------------
- *     WriteConsoleOutputAttribute
+ *    GetConsoleScreenBufferInfo
  *
  * @implemented
  */
 BOOL
 WINAPI
-WriteConsoleOutputAttribute(HANDLE hConsoleOutput,
-                            CONST WORD *lpAttribute,
-                            DWORD nLength,
-                            COORD dwWriteCoord,
-                            LPDWORD lpNumberOfAttrsWritten)
+GetConsoleScreenBufferInfo(HANDLE hConsoleOutput,
+                           PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
 {
-    PCSR_API_MESSAGE Request;
-    ULONG CsrRequest;
     NTSTATUS Status;
-    WORD Size;
-
-    Request = RtlAllocateHeap(RtlGetProcessHeap(),
-                              0,
-                              max(sizeof(CSR_API_MESSAGE),
-                              CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB)
-                                + min(nLength, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB / sizeof(WORD)) * sizeof(WORD)));
-    if (Request == NULL)
+    CONSOLE_API_MESSAGE ApiMessage;
+
+    if (lpConsoleScreenBufferInfo == NULL)
     {
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        SetLastError(ERROR_INVALID_PARAMETER);
         return FALSE;
     }
 
-    CsrRequest = CSR_CREATE_API_NUMBER(CSR_CONSOLE, WRITE_CONSOLE_OUTPUT_ATTRIB);
-    Request->Data.WriteConsoleOutputAttribRequest.Coord = dwWriteCoord;
+    ApiMessage.Data.ScreenBufferInfoRequest.ConsoleHandle = hConsoleOutput;
 
-    if (lpNumberOfAttrsWritten)
-        *lpNumberOfAttrsWritten = nLength;
-    while (nLength)
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetScreenBufferInfo),
+                                 sizeof(CSRSS_SCREEN_BUFFER_INFO));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
-        Size = (WORD)min(nLength, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB / sizeof(WORD));
-        Request->Data.WriteConsoleOutputAttribRequest.ConsoleHandle = hConsoleOutput;
-        Request->Data.WriteConsoleOutputAttribRequest.Length = Size;
-        memcpy(Request->Data.WriteConsoleOutputAttribRequest.Attribute, lpAttribute, Size * sizeof(WORD));
-
-        Status = CsrClientCallServer(Request,
-                                     NULL,
-                                     CsrRequest,
-                                     max(sizeof(CSR_API_MESSAGE),
-                                     CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB) + Size * sizeof(WORD)));
-
-        if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status))
-        {
-            RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
-            BaseSetLastNTError (Status);
-            return FALSE;
-        }
-        nLength -= Size;
-        lpAttribute += Size;
-        Request->Data.WriteConsoleOutputAttribRequest.Coord = Request->Data.WriteConsoleOutputAttribRequest.EndCoord;
+        BaseSetLastNTError(Status);
+        return FALSE;
     }
 
-    RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
+    *lpConsoleScreenBufferInfo = ApiMessage.Data.ScreenBufferInfoRequest.Info;
 
     return TRUE;
 }
 
 
 /*--------------------------------------------------------------
- *     FillConsoleOutputAttribute
+ *    SetConsoleCursorPosition
  *
  * @implemented
  */
 BOOL
 WINAPI
-FillConsoleOutputAttribute(HANDLE hConsoleOutput,
-                           WORD wAttribute,
-                           DWORD nLength,
-                           COORD dwWriteCoord,
-                           LPDWORD lpNumberOfAttrsWritten)
+SetConsoleCursorPosition(HANDLE hConsoleOutput,
+                         COORD dwCursorPosition)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    Request.Data.FillOutputAttribRequest.ConsoleHandle = hConsoleOutput;
-    Request.Data.FillOutputAttribRequest.Attribute = (CHAR)wAttribute;
-    Request.Data.FillOutputAttribRequest.Coord = dwWriteCoord;
-    Request.Data.FillOutputAttribRequest.Length = (WORD)nLength;
+    ApiMessage.Data.SetCursorPositionRequest.ConsoleHandle = hConsoleOutput;
+    ApiMessage.Data.SetCursorPositionRequest.Position = dwCursorPosition;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, FILL_OUTPUT_ATTRIB),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursorPosition),
+                                 sizeof(CSRSS_SET_CURSOR_POSITION));
+    if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
-        BaseSetLastNTError ( Status );
+        BaseSetLastNTError(Status);
         return FALSE;
     }
 
-    if (lpNumberOfAttrsWritten)
-        *lpNumberOfAttrsWritten = nLength;
-
     return TRUE;
 }
 
@@ -3035,22 +928,23 @@ WINAPI
 GetConsoleMode(HANDLE hConsoleHandle,
                LPDWORD lpMode)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_CONSOLE_MODE ConsoleModeRequest = &ApiMessage.Data.ConsoleModeRequest;
 
-    Request.Data.GetConsoleModeRequest.ConsoleHandle = hConsoleHandle;
+    ConsoleModeRequest->ConsoleHandle = hConsoleHandle;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CONSOLE_MODE),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetMode),
+                                 sizeof(CSRSS_CONSOLE_MODE));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return FALSE;
     }
 
-    *lpMode = Request.Data.GetConsoleModeRequest.ConsoleMode;
+    *lpMode = ConsoleModeRequest->ConsoleMode;
 
     return TRUE;
 }
@@ -3066,8 +960,8 @@ WINAPI
 GetNumberOfConsoleInputEvents(HANDLE hConsoleInput,
                               LPDWORD lpNumberOfEvents)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
     if (lpNumberOfEvents == NULL)
     {
@@ -3075,19 +969,19 @@ GetNumberOfConsoleInputEvents(HANDLE hConsoleInput,
         return FALSE;
     }
 
-    Request.Data.GetNumInputEventsRequest.ConsoleHandle = hConsoleInput;
+    ApiMessage.Data.GetNumInputEventsRequest.ConsoleHandle = hConsoleInput;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_NUM_INPUT_EVENTS),
-                                 sizeof(CSR_API_MESSAGE));
-    if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetNumberOfInputEvents),
+                                 sizeof(CSRSS_GET_NUM_INPUT_EVENTS));
+    if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return FALSE;
     }
 
-    *lpNumberOfEvents = Request.Data.GetNumInputEventsRequest.NumInputEvents;
+    *lpNumberOfEvents = ApiMessage.Data.GetNumInputEventsRequest.NumInputEvents;
 
     return TRUE;
 }
@@ -3119,8 +1013,8 @@ WINAPI
 GetConsoleCursorInfo(HANDLE hConsoleOutput,
                      PCONSOLE_CURSOR_INFO lpConsoleCursorInfo)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
     if (!lpConsoleCursorInfo)
     {
@@ -3132,19 +1026,19 @@ GetConsoleCursorInfo(HANDLE hConsoleOutput,
         return FALSE;
     }
 
-    Request.Data.GetCursorInfoRequest.ConsoleHandle = hConsoleOutput;
+    ApiMessage.Data.CursorInfoRequest.ConsoleHandle = hConsoleOutput;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CURSOR_INFO),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCursorInfo),
+                                 sizeof(CSRSS_CURSOR_INFO));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return FALSE;
     }
 
-    *lpConsoleCursorInfo = Request.Data.GetCursorInfoRequest.Info;
+    *lpConsoleCursorInfo = ApiMessage.Data.CursorInfoRequest.Info;
 
     return TRUE;
 }
@@ -3175,17 +1069,18 @@ WINAPI
 SetConsoleMode(HANDLE hConsoleHandle,
                DWORD dwMode)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_CONSOLE_MODE ConsoleModeRequest = &ApiMessage.Data.ConsoleModeRequest;
 
-    Request.Data.SetConsoleModeRequest.ConsoleHandle = hConsoleHandle;
-    Request.Data.SetConsoleModeRequest.Mode = dwMode;
+    ConsoleModeRequest->ConsoleHandle = hConsoleHandle;
+    ConsoleModeRequest->ConsoleMode = dwMode;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_CONSOLE_MODE),
-                                 sizeof(CSR_API_MESSAGE));
-    if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetMode),
+                                 sizeof(CSRSS_CONSOLE_MODE));
+    if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return FALSE;
@@ -3204,16 +1099,16 @@ BOOL
 WINAPI
 SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    Request.Data.SetScreenBufferRequest.OutputHandle = hConsoleOutput;
+    ApiMessage.Data.SetScreenBufferRequest.OutputHandle = hConsoleOutput;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_SCREEN_BUFFER),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetActiveScreenBuffer),
+                                 sizeof(CSRSS_SET_SCREEN_BUFFER));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return FALSE;
@@ -3232,16 +1127,16 @@ BOOL
 WINAPI
 FlushConsoleInputBuffer(HANDLE hConsoleInput)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    Request.Data.FlushInputBufferRequest.ConsoleInput = hConsoleInput;
+    ApiMessage.Data.FlushInputBufferRequest.ConsoleInput = hConsoleInput;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, FLUSH_INPUT_BUFFER),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepFlushInputBuffer),
+                                 sizeof(CSRSS_FLUSH_INPUT_BUFFER));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return FALSE;
@@ -3261,17 +1156,17 @@ WINAPI
 SetConsoleScreenBufferSize(HANDLE hConsoleOutput,
                            COORD dwSize)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    Request.Data.SetScreenBufferSize.OutputHandle = hConsoleOutput;
-    Request.Data.SetScreenBufferSize.Size = dwSize;
+    ApiMessage.Data.SetScreenBufferSize.OutputHandle = hConsoleOutput;
+    ApiMessage.Data.SetScreenBufferSize.Size = dwSize;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_SCREEN_BUFFER_SIZE),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetScreenBufferSize),
+                                 sizeof(CSRSS_SET_SCREEN_BUFFER_SIZE));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return FALSE;
@@ -3280,6 +1175,7 @@ SetConsoleScreenBufferSize(HANDLE hConsoleOutput,
     return TRUE;
 }
 
+
 /*--------------------------------------------------------------
  *     SetConsoleCursorInfo
  *
@@ -3290,17 +1186,17 @@ WINAPI
 SetConsoleCursorInfo(HANDLE hConsoleOutput,
                      CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    Request.Data.SetCursorInfoRequest.ConsoleHandle = hConsoleOutput;
-    Request.Data.SetCursorInfoRequest.Info = *lpConsoleCursorInfo;
+    ApiMessage.Data.CursorInfoRequest.ConsoleHandle = hConsoleOutput;
+    ApiMessage.Data.CursorInfoRequest.Info = *lpConsoleCursorInfo;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_CURSOR_INFO),
-                                 sizeof(CSR_API_MESSAGE));
-    if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursorInfo),
+                                 sizeof(CSRSS_CURSOR_INFO));
+    if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return FALSE;
@@ -3319,32 +1215,33 @@ IntScrollConsoleScreenBuffer(HANDLE hConsoleOutput,
                              const CHAR_INFO *lpFill,
                              BOOL bUnicode)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_SCROLL_CONSOLE_SCREEN_BUFFER ScrollConsoleScreenBufferRequest = &ApiMessage.Data.ScrollConsoleScreenBufferRequest;
 
-    Request.Data.ScrollConsoleScreenBufferRequest.ConsoleHandle = hConsoleOutput;
-    Request.Data.ScrollConsoleScreenBufferRequest.Unicode = bUnicode;
-    Request.Data.ScrollConsoleScreenBufferRequest.ScrollRectangle = *lpScrollRectangle;
+    ScrollConsoleScreenBufferRequest->ConsoleHandle = hConsoleOutput;
+    ScrollConsoleScreenBufferRequest->Unicode = bUnicode;
+    ScrollConsoleScreenBufferRequest->ScrollRectangle = *lpScrollRectangle;
 
     if (lpClipRectangle != NULL)
     {
-        Request.Data.ScrollConsoleScreenBufferRequest.UseClipRectangle = TRUE;
-        Request.Data.ScrollConsoleScreenBufferRequest.ClipRectangle = *lpClipRectangle;
+        ScrollConsoleScreenBufferRequest->UseClipRectangle = TRUE;
+        ScrollConsoleScreenBufferRequest->ClipRectangle = *lpClipRectangle;
     }
     else
     {
-        Request.Data.ScrollConsoleScreenBufferRequest.UseClipRectangle = FALSE;
+        ScrollConsoleScreenBufferRequest->UseClipRectangle = FALSE;
     }
 
-    Request.Data.ScrollConsoleScreenBufferRequest.DestinationOrigin = dwDestinationOrigin;
-    Request.Data.ScrollConsoleScreenBufferRequest.Fill = *lpFill;
+    ScrollConsoleScreenBufferRequest->DestinationOrigin = dwDestinationOrigin;
+    ScrollConsoleScreenBufferRequest->Fill = *lpFill;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SCROLL_CONSOLE_SCREEN_BUFFER),
-                                 sizeof(CSR_API_MESSAGE));
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepScrollScreenBuffer),
+                                 sizeof(CSRSS_SCROLL_CONSOLE_SCREEN_BUFFER));
 
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return FALSE;
@@ -3425,17 +1322,17 @@ WINAPI
 SetConsoleTextAttribute(HANDLE hConsoleOutput,
                         WORD wAttributes)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    Request.Data.SetAttribRequest.ConsoleHandle = hConsoleOutput;
-    Request.Data.SetAttribRequest.Attrib = wAttributes;
+    ApiMessage.Data.SetAttribRequest.ConsoleHandle = hConsoleOutput;
+    ApiMessage.Data.SetAttribRequest.Attrib = wAttributes;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_ATTRIB),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetTextAttribute),
+                                 sizeof(CSRSS_SET_ATTRIB));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return FALSE;
@@ -3654,8 +1551,6 @@ GetConsoleTitleW(LPWSTR lpConsoleTitle,
 /*--------------------------------------------------------------
  *     GetConsoleTitleA
  *
- *     19990306 EA
- *
  * @implemented
  */
 DWORD
@@ -3715,8 +1610,6 @@ SetConsoleTitleW(LPCWSTR lpConsoleTitle)
 /*--------------------------------------------------------------
  *    SetConsoleTitleA
  *
- *     19990204 EA    Added
- *
  * @implemented
  */
 BOOL
@@ -3751,32 +1644,33 @@ CreateConsoleScreenBuffer(DWORD dwDesiredAccess,
                           DWORD dwFlags,
                           LPVOID lpScreenBufferData)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    if (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE)
-        || dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE)
-        || dwFlags != CONSOLE_TEXTMODE_BUFFER)
+    if ( (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE))    ||
+         (dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE))  ||
+         (dwFlags != CONSOLE_TEXTMODE_BUFFER) )
     {
         SetLastError(ERROR_INVALID_PARAMETER);
         return INVALID_HANDLE_VALUE;
     }
 
-    Request.Data.CreateScreenBufferRequest.Access = dwDesiredAccess;
-    Request.Data.CreateScreenBufferRequest.ShareMode = dwShareMode;
-    Request.Data.CreateScreenBufferRequest.Inheritable =
-        lpSecurityAttributes ? lpSecurityAttributes->bInheritHandle : FALSE;
+    ApiMessage.Data.CreateScreenBufferRequest.Access = dwDesiredAccess;
+    ApiMessage.Data.CreateScreenBufferRequest.ShareMode = dwShareMode;
+    ApiMessage.Data.CreateScreenBufferRequest.Inheritable =
+        (lpSecurityAttributes ? lpSecurityAttributes->bInheritHandle : FALSE);
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, CREATE_SCREEN_BUFFER),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepCreateScreenBuffer),
+                                 sizeof(CSRSS_CREATE_SCREEN_BUFFER));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return INVALID_HANDLE_VALUE;
     }
-    return Request.Data.CreateScreenBufferRequest.OutputHandle;
+
+    return ApiMessage.Data.CreateScreenBufferRequest.OutputHandle;
 }
 
 
@@ -3943,7 +1837,6 @@ GetConsoleProcessList(LPDWORD lpdwProcessList,
 }
 
 
-
 /*--------------------------------------------------------------
  *     GetConsoleSelectionInfo
  *
@@ -3953,23 +1846,30 @@ BOOL
 WINAPI
 GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo)
 {
-    CSR_API_MESSAGE Request;
-    NTSTATUS Status = CsrClientCallServer(&Request,
-                                          NULL,
-                                          CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CONSOLE_SELECTION_INFO),
-                                          sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+    NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+
+    if (lpConsoleSelectionInfo == NULL)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetSelectionInfo),
+                                 sizeof(CSRSS_GET_CONSOLE_SELECTION_INFO));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return FALSE;
     }
 
-    *lpConsoleSelectionInfo = Request.Data.GetConsoleSelectionInfo.Info;
+    *lpConsoleSelectionInfo = ApiMessage.Data.GetConsoleSelectionInfo.Info;
     return TRUE;
 }
 
 
-
 /*--------------------------------------------------------------
  *     AttachConsole
  *
@@ -3983,6 +1883,7 @@ AttachConsole(DWORD dwProcessId)
     return TRUE;
 }
 
+
 /*--------------------------------------------------------------
  *     GetConsoleWindow
  *
@@ -3992,20 +1893,20 @@ HWND
 WINAPI
 GetConsoleWindow(VOID)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CONSOLE_WINDOW),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status ) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetConsoleWindow),
+                                 sizeof(CSRSS_GET_CONSOLE_WINDOW));
+    if (!NT_SUCCESS(Status ) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return (HWND) NULL;
     }
 
-    return Request.Data.GetConsoleWindowRequest.WindowHandle;
+    return ApiMessage.Data.GetConsoleWindowRequest.WindowHandle;
 }
 
 
@@ -4018,16 +1919,16 @@ BOOL
 WINAPI
 SetConsoleIcon(HICON hicon)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    Request.Data.SetConsoleIconRequest.WindowIcon = hicon;
+    ApiMessage.Data.SetConsoleIconRequest.WindowIcon = hicon;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_CONSOLE_ICON),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetIcon),
+                                 sizeof(CSRSS_SET_CONSOLE_ICON));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
         return FALSE;
@@ -4233,23 +2134,6 @@ GetConsoleNlsMode(HANDLE hConsole, LPDWORD lpMode)
     return FALSE;
 }
 
-
-BOOL
-WINAPI
-ReadConsoleInputExA(HANDLE hConsole, LPVOID lpBuffer, DWORD dwLen, LPDWORD Unknown1, DWORD Unknown2)
-{
-    STUB;
-    return FALSE;
-}
-
-BOOL
-WINAPI
-ReadConsoleInputExW(HANDLE hConsole, LPVOID lpBuffer, DWORD dwLen, LPDWORD Unknown1, DWORD Unknown2)
-{
-    STUB;
-    return FALSE;
-}
-
 BOOL
 WINAPI
 RegisterConsoleIME(HWND hWnd, LPDWORD ThreadId)
@@ -4336,16 +2220,4 @@ SetLastConsoleEventActive(VOID)
     return FALSE;
 }
 
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-SetConsoleCommandHistoryMode(IN DWORD dwMode)
-{
-    STUB;
-    return FALSE;
-}
-
-
 /* EOF */