[KERNEL32][CONSRV]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 20 Apr 2014 11:25:38 +0000 (11:25 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 20 Apr 2014 11:25:38 +0000 (11:25 +0000)
Make kernel32 / winsrv console CSR structures Win2k3-compliant.
The aim is to be able to put our kernel32.dll or winsrv.dll on win2k3, and vice-versa.

Part 2/X

CORE-7931

svn path=/trunk/; revision=62833

reactos/dll/win32/kernel32/client/console/console.c
reactos/include/reactos/subsys/win/conmsg.h
reactos/win32ss/user/winsrv/consrv/condrv/coninput.c
reactos/win32ss/user/winsrv/consrv/condrv/console.c
reactos/win32ss/user/winsrv/consrv/condrv/text.c
reactos/win32ss/user/winsrv/consrv/coninput.c
reactos/win32ss/user/winsrv/consrv/conoutput.c
reactos/win32ss/user/winsrv/consrv/console.c
reactos/win32ss/user/winsrv/consrv/handle.c
reactos/win32ss/user/winsrv/consrv/include/conio.h

index e4a3367..e99b1be 100644 (file)
@@ -277,7 +277,6 @@ DuplicateConsoleHandle(HANDLE hConsole,
                        BOOL bInheritHandle,
                        DWORD dwOptions)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_DUPLICATEHANDLE DuplicateHandleRequest = &ApiMessage.Data.DuplicateHandleRequest;
 
@@ -285,26 +284,27 @@ DuplicateConsoleHandle(HANDLE hConsole,
          (!(dwOptions & DUPLICATE_SAME_ACCESS) &&
            (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE))) )
     {
-        SetLastError (ERROR_INVALID_PARAMETER);
+        SetLastError(ERROR_INVALID_PARAMETER);
         return INVALID_HANDLE_VALUE;
     }
 
-    DuplicateHandleRequest->ConsoleHandle = hConsole;
-    DuplicateHandleRequest->Access = dwDesiredAccess;
-    DuplicateHandleRequest->Inheritable = bInheritHandle;
-    DuplicateHandleRequest->Options = dwOptions;
+    DuplicateHandleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    DuplicateHandleRequest->SourceHandle  = hConsole;
+    DuplicateHandleRequest->DesiredAccess = dwDesiredAccess;
+    DuplicateHandleRequest->InheritHandle = bInheritHandle;
+    DuplicateHandleRequest->Options       = dwOptions;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepDuplicateHandle),
-                                 sizeof(CONSOLE_DUPLICATEHANDLE));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepDuplicateHandle),
+                        sizeof(*DuplicateHandleRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return INVALID_HANDLE_VALUE;
     }
 
-    return DuplicateHandleRequest->ConsoleHandle;
+    return DuplicateHandleRequest->TargetHandle;
 }
 
 
@@ -337,6 +337,7 @@ GetConsoleDisplayMode(LPDWORD lpModeFlags)
     }
 
     *lpModeFlags = GetDisplayModeRequest->DisplayMode; // ModeFlags
+
     return TRUE;
 }
 
@@ -407,6 +408,7 @@ GetConsoleHardwareState(HANDLE hConsoleOutput,
 
     *Flags = HardwareStateRequest->Flags;
     *State = HardwareStateRequest->State;
+
     return TRUE;
 }
 
@@ -496,16 +498,15 @@ OpenConsoleW(LPCWSTR wsName,
              BOOL bInheritHandle,
              DWORD dwShareMode)
 {
-    NTSTATUS Status = STATUS_SUCCESS;
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_OPENCONSOLE OpenConsoleRequest = &ApiMessage.Data.OpenConsoleRequest;
     CONSOLE_HANDLE_TYPE HandleType;
 
-    if (wsName && 0 == _wcsicmp(wsName, BaseConInputFileName))
+    if (wsName && (_wcsicmp(wsName, BaseConInputFileName) == 0))
     {
         HandleType = HANDLE_INPUT;
     }
-    else if (wsName && 0 == _wcsicmp(wsName, BaseConOutputFileName))
+    else if (wsName && (_wcsicmp(wsName, BaseConOutputFileName) == 0))
     {
         HandleType = HANDLE_OUTPUT;
     }
@@ -522,22 +523,23 @@ OpenConsoleW(LPCWSTR wsName,
         return INVALID_HANDLE_VALUE;
     }
 
-    OpenConsoleRequest->HandleType = HandleType;
-    OpenConsoleRequest->Access = dwDesiredAccess;
-    OpenConsoleRequest->Inheritable = bInheritHandle;
-    OpenConsoleRequest->ShareMode = dwShareMode;
+    OpenConsoleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    OpenConsoleRequest->HandleType    = HandleType;
+    OpenConsoleRequest->DesiredAccess = dwDesiredAccess;
+    OpenConsoleRequest->InheritHandle = bInheritHandle;
+    OpenConsoleRequest->ShareMode     = dwShareMode;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepOpenConsole),
-                                 sizeof(CONSOLE_OPENCONSOLE));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepOpenConsole),
+                        sizeof(*OpenConsoleRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return INVALID_HANDLE_VALUE;
     }
 
-    return OpenConsoleRequest->ConsoleHandle;
+    return OpenConsoleRequest->Handle;
 }
 
 
@@ -1082,19 +1084,20 @@ WINAPI
 SetConsoleCursorPosition(HANDLE hConsoleOutput,
                          COORD dwCursorPosition)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_SETCURSORPOSITION SetCursorPositionRequest = &ApiMessage.Data.SetCursorPositionRequest;
 
-    ApiMessage.Data.SetCursorPositionRequest.OutputHandle = hConsoleOutput;
-    ApiMessage.Data.SetCursorPositionRequest.Position = dwCursorPosition;
+    SetCursorPositionRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    SetCursorPositionRequest->OutputHandle  = hConsoleOutput;
+    SetCursorPositionRequest->Position      = dwCursorPosition;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursorPosition),
-                                 sizeof(CONSOLE_SETCURSORPOSITION));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursorPosition),
+                        sizeof(*SetCursorPositionRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return FALSE;
     }
 
@@ -1112,7 +1115,6 @@ WINAPI
 GetConsoleMode(HANDLE hConsoleHandle,
                LPDWORD lpMode)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &ApiMessage.Data.ConsoleModeRequest;
 
@@ -1122,19 +1124,51 @@ GetConsoleMode(HANDLE hConsoleHandle,
         return FALSE;
     }
 
-    ConsoleModeRequest->ConsoleHandle = hConsoleHandle;
+    ConsoleModeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    ConsoleModeRequest->Handle        = hConsoleHandle;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetMode),
-                                 sizeof(CONSOLE_GETSETCONSOLEMODE));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetMode),
+                        sizeof(*ConsoleModeRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return FALSE;
     }
 
-    *lpMode = ConsoleModeRequest->ConsoleMode;
+    *lpMode = ConsoleModeRequest->Mode;
+
+    return TRUE;
+}
+
+
+/*--------------------------------------------------------------
+ *     SetConsoleMode
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+SetConsoleMode(HANDLE hConsoleHandle,
+               DWORD dwMode)
+{
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &ApiMessage.Data.ConsoleModeRequest;
+
+    ConsoleModeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    ConsoleModeRequest->Handle        = hConsoleHandle;
+    ConsoleModeRequest->Mode          = dwMode;
+
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetMode),
+                        sizeof(*ConsoleModeRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
+    {
+        BaseSetLastNTError(ApiMessage.Status);
+        return FALSE;
+    }
 
     return TRUE;
 }
@@ -1150,20 +1184,20 @@ WINAPI
 GetNumberOfConsoleInputEvents(HANDLE hConsoleInput,
                               LPDWORD lpNumberOfEvents)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_GETNUMINPUTEVENTS GetNumInputEventsRequest = &ApiMessage.Data.GetNumInputEventsRequest;
 
-    GetNumInputEventsRequest->InputHandle = hConsoleInput;
-    GetNumInputEventsRequest->NumInputEvents = 0;
+    GetNumInputEventsRequest->ConsoleHandle  = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    GetNumInputEventsRequest->InputHandle    = hConsoleInput;
+    GetNumInputEventsRequest->NumberOfEvents = 0;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetNumberOfInputEvents),
-                                 sizeof(CONSOLE_GETNUMINPUTEVENTS));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetNumberOfInputEvents),
+                        sizeof(*GetNumInputEventsRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return FALSE;
     }
 
@@ -1173,7 +1207,7 @@ GetNumberOfConsoleInputEvents(HANDLE hConsoleInput,
         return FALSE;
     }
 
-    *lpNumberOfEvents = GetNumInputEventsRequest->NumInputEvents;
+    *lpNumberOfEvents = GetNumInputEventsRequest->NumberOfEvents;
 
     return TRUE;
 }
@@ -1188,21 +1222,21 @@ COORD
 WINAPI
 GetLargestConsoleWindowSize(HANDLE hConsoleOutput)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest = &ApiMessage.Data.GetLargestWindowSizeRequest;
 
-    GetLargestWindowSizeRequest->OutputHandle = hConsoleOutput;
+    GetLargestWindowSizeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    GetLargestWindowSizeRequest->OutputHandle  = hConsoleOutput;
     GetLargestWindowSizeRequest->Size.X = 0;
     GetLargestWindowSizeRequest->Size.Y = 0;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetLargestWindowSize),
-                                 sizeof(CONSOLE_GETLARGESTWINDOWSIZE));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetLargestWindowSize),
+                        sizeof(*GetLargestWindowSizeRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
     }
 
     DPRINT1("GetLargestConsoleWindowSize, X = %d, Y = %d\n", GetLargestWindowSizeRequest->Size.X, GetLargestWindowSizeRequest->Size.Y);
@@ -1220,8 +1254,8 @@ WINAPI
 GetConsoleCursorInfo(HANDLE hConsoleOutput,
                      PCONSOLE_CURSOR_INFO lpConsoleCursorInfo)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_GETSETCURSORINFO CursorInfoRequest = &ApiMessage.Data.CursorInfoRequest;
 
     if (!lpConsoleCursorInfo)
     {
@@ -1233,63 +1267,49 @@ GetConsoleCursorInfo(HANDLE hConsoleOutput,
         return FALSE;
     }
 
-    ApiMessage.Data.CursorInfoRequest.OutputHandle = hConsoleOutput;
+    CursorInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    CursorInfoRequest->OutputHandle  = hConsoleOutput;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCursorInfo),
-                                 sizeof(CONSOLE_GETSETCURSORINFO));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCursorInfo),
+                        sizeof(*CursorInfoRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return FALSE;
     }
 
-    *lpConsoleCursorInfo = ApiMessage.Data.CursorInfoRequest.Info;
+    *lpConsoleCursorInfo = CursorInfoRequest->Info;
 
     return TRUE;
 }
 
 
 /*--------------------------------------------------------------
- *     GetNumberOfConsoleMouseButtons
- *
- * @unimplemented
- */
-BOOL
-WINAPI
-GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons)
-{
-    DPRINT1("GetNumberOfConsoleMouseButtons(0x%p) UNIMPLEMENTED!\n", lpNumberOfMouseButtons);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
-}
-
-
-/*--------------------------------------------------------------
- *     SetConsoleMode
+ *     SetConsoleCursorInfo
  *
  * @implemented
  */
 BOOL
 WINAPI
-SetConsoleMode(HANDLE hConsoleHandle,
-               DWORD dwMode)
+SetConsoleCursorInfo(HANDLE hConsoleOutput,
+                     CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
-    PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &ApiMessage.Data.ConsoleModeRequest;
+    PCONSOLE_GETSETCURSORINFO CursorInfoRequest = &ApiMessage.Data.CursorInfoRequest;
 
-    ConsoleModeRequest->ConsoleHandle = hConsoleHandle;
-    ConsoleModeRequest->ConsoleMode   = dwMode;
+    CursorInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    CursorInfoRequest->OutputHandle  = hConsoleOutput;
+    CursorInfoRequest->Info          = *lpConsoleCursorInfo;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetMode),
-                                 sizeof(CONSOLE_GETSETCONSOLEMODE));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursorInfo),
+                        sizeof(*CursorInfoRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return FALSE;
     }
 
@@ -1298,54 +1318,42 @@ SetConsoleMode(HANDLE hConsoleHandle,
 
 
 /*--------------------------------------------------------------
- *     SetConsoleActiveScreenBuffer
+ *     GetNumberOfConsoleMouseButtons
  *
- * @implemented
+ * @unimplemented
  */
 BOOL
 WINAPI
-SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
+GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons)
 {
-    NTSTATUS Status;
-    CONSOLE_API_MESSAGE ApiMessage;
-
-    ApiMessage.Data.SetScreenBufferRequest.OutputHandle = hConsoleOutput;
-
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetActiveScreenBuffer),
-                                 sizeof(CONSOLE_SETACTIVESCREENBUFFER));
-    if (!NT_SUCCESS(Status))
-    {
-        BaseSetLastNTError(Status);
-        return FALSE;
-    }
-
-    return TRUE;
+    DPRINT1("GetNumberOfConsoleMouseButtons(0x%p) UNIMPLEMENTED!\n", lpNumberOfMouseButtons);
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return FALSE;
 }
 
 
 /*--------------------------------------------------------------
- *     FlushConsoleInputBuffer
+ *     SetConsoleActiveScreenBuffer
  *
  * @implemented
  */
 BOOL
 WINAPI
-FlushConsoleInputBuffer(HANDLE hConsoleInput)
+SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_SETACTIVESCREENBUFFER SetScreenBufferRequest = &ApiMessage.Data.SetScreenBufferRequest;
 
-    ApiMessage.Data.FlushInputBufferRequest.InputHandle = hConsoleInput;
+    SetScreenBufferRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    SetScreenBufferRequest->OutputHandle  = hConsoleOutput;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepFlushInputBuffer),
-                                 sizeof(CONSOLE_FLUSHINPUTBUFFER));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetActiveScreenBuffer),
+                        sizeof(*SetScreenBufferRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return FALSE;
     }
 
@@ -1354,28 +1362,27 @@ FlushConsoleInputBuffer(HANDLE hConsoleInput)
 
 
 /*--------------------------------------------------------------
- *     SetConsoleScreenBufferSize
+ *     FlushConsoleInputBuffer
  *
  * @implemented
  */
 BOOL
 WINAPI
-SetConsoleScreenBufferSize(HANDLE hConsoleOutput,
-                           COORD dwSize)
+FlushConsoleInputBuffer(HANDLE hConsoleInput)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_FLUSHINPUTBUFFER FlushInputBufferRequest = &ApiMessage.Data.FlushInputBufferRequest;
 
-    ApiMessage.Data.SetScreenBufferSizeRequest.OutputHandle = hConsoleOutput;
-    ApiMessage.Data.SetScreenBufferSizeRequest.Size = dwSize;
+    FlushInputBufferRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    FlushInputBufferRequest->InputHandle   = hConsoleInput;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetScreenBufferSize),
-                                 sizeof(CONSOLE_SETSCREENBUFFERSIZE));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepFlushInputBuffer),
+                        sizeof(*FlushInputBufferRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return FALSE;
     }
 
@@ -1384,28 +1391,29 @@ SetConsoleScreenBufferSize(HANDLE hConsoleOutput,
 
 
 /*--------------------------------------------------------------
- *     SetConsoleCursorInfo
+ *     SetConsoleScreenBufferSize
  *
  * @implemented
  */
 BOOL
 WINAPI
-SetConsoleCursorInfo(HANDLE hConsoleOutput,
-                     CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
+SetConsoleScreenBufferSize(HANDLE hConsoleOutput,
+                           COORD dwSize)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_SETSCREENBUFFERSIZE SetScreenBufferSizeRequest = &ApiMessage.Data.SetScreenBufferSizeRequest;
 
-    ApiMessage.Data.CursorInfoRequest.OutputHandle = hConsoleOutput;
-    ApiMessage.Data.CursorInfoRequest.Info = *lpConsoleCursorInfo;
+    SetScreenBufferSizeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    SetScreenBufferSizeRequest->OutputHandle  = hConsoleOutput;
+    SetScreenBufferSizeRequest->Size          = dwSize;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursorInfo),
-                                 sizeof(CONSOLE_GETSETCURSORINFO));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetScreenBufferSize),
+                        sizeof(*SetScreenBufferSizeRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return FALSE;
     }
 
@@ -1513,7 +1521,6 @@ SetConsoleWindowInfo(HANDLE hConsoleOutput,
                      BOOL bAbsolute,
                      CONST SMALL_RECT *lpConsoleWindow)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_SETWINDOWINFO SetWindowInfoRequest = &ApiMessage.Data.SetWindowInfoRequest;
 
@@ -1523,17 +1530,18 @@ SetConsoleWindowInfo(HANDLE hConsoleOutput,
         return FALSE;
     }
 
-    SetWindowInfoRequest->OutputHandle = hConsoleOutput;
-    SetWindowInfoRequest->Absolute     = bAbsolute;
-    SetWindowInfoRequest->WindowRect   = *lpConsoleWindow;
+    SetWindowInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    SetWindowInfoRequest->OutputHandle  = hConsoleOutput;
+    SetWindowInfoRequest->Absolute      = bAbsolute;
+    SetWindowInfoRequest->WindowRect    = *lpConsoleWindow;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetWindowInfo),
-                                 sizeof(CONSOLE_SETWINDOWINFO));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetWindowInfo),
+                        sizeof(*SetWindowInfoRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return FALSE;
     }
 
@@ -1551,19 +1559,20 @@ WINAPI
 SetConsoleTextAttribute(HANDLE hConsoleOutput,
                         WORD wAttributes)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_SETTEXTATTRIB SetTextAttribRequest = &ApiMessage.Data.SetTextAttribRequest;
 
-    ApiMessage.Data.SetTextAttribRequest.OutputHandle = hConsoleOutput;
-    ApiMessage.Data.SetTextAttribRequest.Attrib = wAttributes;
+    SetTextAttribRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    SetTextAttribRequest->OutputHandle  = hConsoleOutput;
+    SetTextAttribRequest->Attributes    = wAttributes;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetTextAttribute),
-                                 sizeof(CONSOLE_SETTEXTATTRIB));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetTextAttribute),
+                        sizeof(*SetTextAttribRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return FALSE;
     }
 
@@ -1677,8 +1686,8 @@ WINAPI
 GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
                          DWORD dwProcessGroupId)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_GENERATECTRLEVENT GenerateCtrlEventRequest = &ApiMessage.Data.GenerateCtrlEventRequest;
 
     if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
     {
@@ -1686,16 +1695,17 @@ GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
         return FALSE;
     }
 
-    ApiMessage.Data.GenerateCtrlEventRequest.Event = dwCtrlEvent;
-    ApiMessage.Data.GenerateCtrlEventRequest.ProcessGroup = dwProcessGroupId;
+    GenerateCtrlEventRequest->ConsoleHandle  = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    GenerateCtrlEventRequest->CtrlEvent      = dwCtrlEvent;
+    GenerateCtrlEventRequest->ProcessGroupId = dwProcessGroupId;
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 NULL,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGenerateCtrlEvent),
-                                 sizeof(CONSOLE_GENERATECTRLEVENT));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGenerateCtrlEvent),
+                        sizeof(*GenerateCtrlEventRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return FALSE;
     }
 
@@ -1704,16 +1714,18 @@ GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
 
 
 static DWORD
-IntGetConsoleTitle(LPVOID lpConsoleTitle, DWORD nSize, BOOL bUnicode)
+IntGetConsoleTitle(LPVOID lpConsoleTitle, DWORD dwNumChars, BOOLEAN bUnicode)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_GETSETCONSOLETITLE TitleRequest = &ApiMessage.Data.TitleRequest;
     PCSR_CAPTURE_BUFFER CaptureBuffer;
 
-    if (nSize == 0) return 0;
+    if (dwNumChars == 0) return 0;
+
+    TitleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    TitleRequest->Length        = dwNumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
+    TitleRequest->Unicode       = bUnicode;
 
-    TitleRequest->Length = nSize * (bUnicode ? 1 : sizeof(WCHAR));
     CaptureBuffer = CsrAllocateCaptureBuffer(1, TitleRequest->Length);
     if (CaptureBuffer == NULL)
     {
@@ -1726,42 +1738,32 @@ IntGetConsoleTitle(LPVOID lpConsoleTitle, DWORD nSize, BOOL bUnicode)
                               TitleRequest->Length,
                               (PVOID*)&TitleRequest->Title);
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 CaptureBuffer,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetTitle),
-                                 sizeof(CONSOLE_GETSETCONSOLETITLE));
-    if (!NT_SUCCESS(Status))
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        CaptureBuffer,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetTitle),
+                        sizeof(*TitleRequest));
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
         CsrFreeCaptureBuffer(CaptureBuffer);
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return 0;
     }
 
-    if (bUnicode)
-    {
-        if (nSize >= sizeof(WCHAR))
-            wcscpy((LPWSTR)lpConsoleTitle, TitleRequest->Title);
-    }
-    else
+    dwNumChars = TitleRequest->Length / (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
+
+    if (dwNumChars > 0)
     {
-        if (nSize < TitleRequest->Length / sizeof(WCHAR) ||
-            !WideCharToMultiByte(CP_ACP, // ANSI code page
-                                 0, // performance and mapping flags
-                                 TitleRequest->Title, // address of wide-character string
-                                 -1, // number of characters in string
-                                 (LPSTR)lpConsoleTitle, // address of buffer for new string
-                                 nSize, // size of buffer
-                                 NULL, // FAST
-                                 NULL))
-        {
-            /* Yes, if the buffer isn't big enough, it returns 0... Bad API */
-            *(LPSTR)lpConsoleTitle = '\0';
-            TitleRequest->Length = 0;
-        }
+        memcpy(lpConsoleTitle, TitleRequest->Title, TitleRequest->Length);
+
+        if (bUnicode)
+            ((LPWSTR)lpConsoleTitle)[dwNumChars] = L'\0';
+        else
+            ((LPSTR)lpConsoleTitle)[dwNumChars] = '\0';
     }
+
     CsrFreeCaptureBuffer(CaptureBuffer);
 
-    return TitleRequest->Length / sizeof(WCHAR);
+    return dwNumChars;
 }
 
 
@@ -1793,21 +1795,16 @@ GetConsoleTitleA(LPSTR lpConsoleTitle,
 }
 
 
-/*--------------------------------------------------------------
- *    SetConsoleTitleW
- *
- * @implemented
- */
-BOOL
-WINAPI
-SetConsoleTitleW(LPCWSTR lpConsoleTitle)
+static BOOL
+IntSetConsoleTitle(CONST VOID *lpConsoleTitle, DWORD dwNumChars, BOOLEAN bUnicode)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_GETSETCONSOLETITLE TitleRequest = &ApiMessage.Data.TitleRequest;
     PCSR_CAPTURE_BUFFER CaptureBuffer;
 
-    TitleRequest->Length = wcslen(lpConsoleTitle) * sizeof(WCHAR);
+    TitleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    TitleRequest->Length        = dwNumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
+    TitleRequest->Unicode       = bUnicode;
 
     CaptureBuffer = CsrAllocateCaptureBuffer(1, TitleRequest->Length);
     if (CaptureBuffer == NULL)
@@ -1822,22 +1819,34 @@ SetConsoleTitleW(LPCWSTR lpConsoleTitle)
                             TitleRequest->Length,
                             (PVOID*)&TitleRequest->Title);
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 CaptureBuffer,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetTitle),
-                                 sizeof(CONSOLE_GETSETCONSOLETITLE));
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        CaptureBuffer,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetTitle),
+                        sizeof(*TitleRequest));
 
     CsrFreeCaptureBuffer(CaptureBuffer);
 
-    if (!NT_SUCCESS(Status))
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return FALSE;
     }
 
     return TRUE;
 }
 
+/*--------------------------------------------------------------
+ *    SetConsoleTitleW
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+SetConsoleTitleW(LPCWSTR lpConsoleTitle)
+{
+    return IntSetConsoleTitle(lpConsoleTitle, wcslen(lpConsoleTitle), TRUE);
+}
+
 
 /*--------------------------------------------------------------
  *    SetConsoleTitleA
@@ -1848,22 +1857,7 @@ BOOL
 WINAPI
 SetConsoleTitleA(LPCSTR lpConsoleTitle)
 {
-    BOOL   Ret;
-    ULONG  Length = strlen(lpConsoleTitle) + 1;
-    LPWSTR WideTitle = HeapAlloc(GetProcessHeap(), 0, Length * sizeof(WCHAR));
-
-    if (!WideTitle)
-    {
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return FALSE;
-    }
-
-    MultiByteToWideChar(CP_ACP, 0, lpConsoleTitle, -1, WideTitle, Length);
-
-    Ret = SetConsoleTitleW(WideTitle);
-
-    HeapFree(GetProcessHeap(), 0, WideTitle);
-    return Ret;
+    return IntSetConsoleTitle(lpConsoleTitle, strlen(lpConsoleTitle), FALSE);
 }
 
 
@@ -2160,6 +2154,7 @@ GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo)
     }
 
     *lpConsoleSelectionInfo = GetSelectionInfoRequest->Info;
+
     return TRUE;
 }
 
index 04bb3bd..b6481a9 100644 (file)
@@ -274,8 +274,9 @@ typedef struct
 
 typedef struct
 {
+    HANDLE ConsoleHandle;
     HANDLE OutputHandle;
-    COORD Position;
+    COORD  Position;
 } CONSOLE_SETCURSORPOSITION, *PCONSOLE_SETCURSORPOSITION;
 
 typedef struct
@@ -295,20 +296,27 @@ typedef struct
 
 typedef struct
 {
+    HANDLE ConsoleHandle;
     HANDLE OutputHandle;
     CONSOLE_CURSOR_INFO Info;
+/*
+    DWORD   Size;
+    BOOLEAN Visible;
+*/
 } CONSOLE_GETSETCURSORINFO, *PCONSOLE_GETSETCURSORINFO;
 
 typedef struct
 {
+    HANDLE ConsoleHandle;
     HANDLE OutputHandle;
-    WORD Attrib;
+    WORD   Attributes;
 } CONSOLE_SETTEXTATTRIB, *PCONSOLE_SETTEXTATTRIB;
 
 typedef struct
 {
-    HANDLE ConsoleHandle;   /* A valid input or output console handle */
-    DWORD ConsoleMode;
+    HANDLE ConsoleHandle;
+    HANDLE Handle;
+    DWORD  Mode;
 } CONSOLE_GETSETCONSOLEMODE, *PCONSOLE_GETSETCONSOLEMODE;
 
 typedef struct
@@ -358,6 +366,7 @@ typedef struct
 
 typedef struct
 {
+    HANDLE ConsoleHandle;
     HANDLE OutputHandle;  /* Handle to screen buffer to switch to */
 } CONSOLE_SETACTIVESCREENBUFFER, *PCONSOLE_SETACTIVESCREENBUFFER;
 
@@ -378,8 +387,10 @@ typedef struct
 
 typedef struct
 {
-    DWORD Length;
-    PWCHAR Title;
+    HANDLE  ConsoleHandle;
+    DWORD   Length;
+    PVOID   Title;
+    BOOLEAN Unicode;
 } CONSOLE_GETSETCONSOLETITLE, *PCONSOLE_GETSETCONSOLETITLE;
 
 typedef struct
@@ -395,6 +406,7 @@ typedef struct
 
 typedef struct
 {
+    HANDLE ConsoleHandle;
     HANDLE InputHandle;
 } CONSOLE_FLUSHINPUTBUFFER, *PCONSOLE_FLUSHINPUTBUFFER;
 
@@ -527,10 +539,12 @@ typedef struct
 
 typedef struct
 {
-    HANDLE ConsoleHandle;
-    DWORD Access;
-    BOOL Inheritable;
-    DWORD Options;
+    HANDLE  ConsoleHandle;
+    HANDLE  SourceHandle;
+    DWORD   DesiredAccess;
+    BOOLEAN InheritHandle;
+    DWORD   Options;
+    HANDLE  TargetHandle;
 } CONSOLE_DUPLICATEHANDLE, *PCONSOLE_DUPLICATEHANDLE;
 
 /*
@@ -546,14 +560,16 @@ typedef struct
 {
     HANDLE ConsoleHandle;
     CONSOLE_HANDLE_TYPE HandleType;
-    DWORD Access;
-    BOOL Inheritable;
-    DWORD ShareMode;
+    DWORD  DesiredAccess;
+    BOOL   InheritHandle;
+    DWORD  ShareMode;
+    HANDLE Handle;
 } CONSOLE_OPENCONSOLE, *PCONSOLE_OPENCONSOLE;
 
 
 typedef struct
 {
+    HANDLE ConsoleHandle;
     HANDLE OutputHandle;
     COORD  Size;
 } CONSOLE_GETLARGESTWINDOWSIZE, *PCONSOLE_GETLARGESTWINDOWSIZE;
@@ -575,6 +591,7 @@ typedef struct
 
 typedef struct
 {
+    HANDLE ConsoleHandle;
     HANDLE OutputHandle;
     BOOL   Absolute;
     SMALL_RECT WindowRect; // New console window position in the screen-buffer frame (Absolute == TRUE)
@@ -668,20 +685,23 @@ typedef struct
 
 typedef struct
 {
-    DWORD Event;
-    DWORD ProcessGroup;
+    HANDLE ConsoleHandle;
+    DWORD  CtrlEvent;
+    DWORD  ProcessGroupId;
 } CONSOLE_GENERATECTRLEVENT, *PCONSOLE_GENERATECTRLEVENT;
 
 typedef struct
 {
+    HANDLE ConsoleHandle;
     HANDLE InputHandle;
-    DWORD NumInputEvents;
+    DWORD  NumberOfEvents;
 } CONSOLE_GETNUMINPUTEVENTS, *PCONSOLE_GETNUMINPUTEVENTS;
 
 typedef struct
 {
+    HANDLE ConsoleHandle;
     HANDLE OutputHandle;
-    COORD Size;
+    COORD  Size;
 } CONSOLE_SETSCREENBUFFERSIZE, *PCONSOLE_SETSCREENBUFFERSIZE;
 
 typedef struct
index eaf94a8..27c6b36 100644 (file)
@@ -519,24 +519,24 @@ ConDrvFlushConsoleInputBuffer(IN PCONSOLE Console,
 NTSTATUS NTAPI
 ConDrvGetConsoleNumberOfInputEvents(IN PCONSOLE Console,
                                     IN PCONSOLE_INPUT_BUFFER InputBuffer,
-                                    OUT PULONG NumEvents)
+                                    OUT PULONG NumberOfEvents)
 {
     PLIST_ENTRY CurrentInput;
 
-    if (Console == NULL || InputBuffer == NULL || NumEvents == NULL)
+    if (Console == NULL || InputBuffer == NULL || NumberOfEvents == NULL)
         return STATUS_INVALID_PARAMETER;
 
     /* Validity check */
     ASSERT(Console == InputBuffer->Header.Console);
 
-    *NumEvents = 0;
+    *NumberOfEvents = 0;
 
     /* If there are any events ... */
     CurrentInput = InputBuffer->InputEvents.Flink;
     while (CurrentInput != &InputBuffer->InputEvents)
     {
         CurrentInput = CurrentInput->Flink;
-        (*NumEvents)++;
+        (*NumberOfEvents)++;
     }
 
     return STATUS_SUCCESS;
index e756eb5..b4b1111 100644 (file)
@@ -197,7 +197,7 @@ VOID ResetFrontEnd(IN PCONSOLE Console);
 /* PRIVATE FUNCTIONS **********************************************************/
 
 static NTSTATUS
-ConDrvConsoleCtrlEventTimeout(IN ULONG Event,
+ConDrvConsoleCtrlEventTimeout(IN ULONG CtrlEvent,
                               IN PCONSOLE_PROCESS_DATA ProcessData,
                               IN ULONG Timeout)
 {
@@ -215,7 +215,7 @@ ConDrvConsoleCtrlEventTimeout(IN ULONG Event,
             {
                 Thread = CreateRemoteThread(ProcessData->Process->ProcessHandle, NULL, 0,
                                             ProcessData->CtrlDispatcher,
-                                            UlongToPtr(Event), 0, NULL);
+                                            UlongToPtr(CtrlEvent), 0, NULL);
                 if (NULL == Thread)
                 {
                     Status = RtlGetLastNtStatus();
@@ -245,10 +245,10 @@ ConDrvConsoleCtrlEventTimeout(IN ULONG Event,
 }
 
 static NTSTATUS
-ConDrvConsoleCtrlEvent(IN ULONG Event,
+ConDrvConsoleCtrlEvent(IN ULONG CtrlEvent,
                        IN PCONSOLE_PROCESS_DATA ProcessData)
 {
-    return ConDrvConsoleCtrlEventTimeout(Event, ProcessData, 0);
+    return ConDrvConsoleCtrlEventTimeout(CtrlEvent, ProcessData, 0);
 }
 
 VOID FASTCALL
@@ -879,7 +879,8 @@ ConDrvSetConsoleMode(IN PCONSOLE Console,
                      IN PCONSOLE_IO_OBJECT Object,
                      IN ULONG ConsoleMode)
 {
-#define CONSOLE_VALID_CONTROL_MODES ( ENABLE_EXTENDED_FLAGS   | ENABLE_INSERT_MODE  | ENABLE_QUICK_EDIT_MODE )
+#define CONSOLE_VALID_CONTROL_MODES ( ENABLE_EXTENDED_FLAGS   | \
+                                      ENABLE_INSERT_MODE      | ENABLE_QUICK_EDIT_MODE )
 #define CONSOLE_VALID_INPUT_MODES   ( ENABLE_PROCESSED_INPUT  | ENABLE_LINE_INPUT   | \
                                       ENABLE_ECHO_INPUT       | ENABLE_WINDOW_INPUT | \
                                       ENABLE_MOUSE_INPUT )
@@ -956,39 +957,80 @@ Quit:
 
 NTSTATUS NTAPI
 ConDrvGetConsoleTitle(IN PCONSOLE Console,
-                      IN OUT PWCHAR Title,
+                      IN BOOLEAN Unicode,
+                      IN OUT PVOID TitleBuffer,
                       IN OUT PULONG BufLength)
 {
     ULONG Length;
 
-    if (Console == NULL || Title == NULL || BufLength == NULL)
+    if (Console == NULL || TitleBuffer == NULL || BufLength == NULL)
         return STATUS_INVALID_PARAMETER;
 
     /* Copy title of the console to the user title buffer */
-    if (*BufLength >= sizeof(WCHAR))
+    if (Unicode)
     {
-        Length = min(*BufLength - sizeof(WCHAR), Console->Title.Length);
-        RtlCopyMemory(Title, Console->Title.Buffer, Length);
-        Title[Length / sizeof(WCHAR)] = L'\0';
+        if (*BufLength >= sizeof(WCHAR))
+        {
+            Length = min(*BufLength - sizeof(WCHAR), Console->Title.Length);
+            RtlCopyMemory(TitleBuffer, Console->Title.Buffer, Length);
+            ((PWCHAR)TitleBuffer)[Length / sizeof(WCHAR)] = L'\0';
+            *BufLength = Length;
+        }
+        else
+        {
+            *BufLength = Console->Title.Length;
+        }
+    }
+    else
+    {
+        if (*BufLength >= sizeof(CHAR))
+        {
+            Length = min(*BufLength - sizeof(CHAR), Console->Title.Length / sizeof(WCHAR));
+            Length = WideCharToMultiByte(Console->CodePage, 0,
+                                         Console->Title.Buffer, Length,
+                                         TitleBuffer, Length,
+                                         NULL, NULL);
+            ((PCHAR)TitleBuffer)[Length] = '\0';
+            *BufLength = Length;
+        }
+        else
+        {
+            *BufLength = Console->Title.Length / sizeof(WCHAR);
+        }
     }
-
-    *BufLength = Console->Title.Length;
 
     return STATUS_SUCCESS;
 }
 
 NTSTATUS NTAPI
 ConDrvSetConsoleTitle(IN PCONSOLE Console,
-                      IN PWCHAR Title,
+                      IN BOOLEAN Unicode,
+                      IN PVOID TitleBuffer,
                       IN ULONG BufLength)
 {
     PWCHAR Buffer;
+    ULONG  Length;
 
-    if (Console == NULL || Title == NULL)
+    if (Console == NULL || TitleBuffer == NULL)
         return STATUS_INVALID_PARAMETER;
 
+    if (Unicode)
+    {
+        /* Length is in bytes */
+        Length = BufLength;
+    }
+    else
+    {
+        /* Use the console input CP for the conversion */
+        Length = MultiByteToWideChar(Console->CodePage, 0,
+                                     TitleBuffer, BufLength,
+                                     NULL, 0);
+        /* The returned Length was in number of wchars, convert it in bytes */
+        Length *= sizeof(WCHAR);
+    }
+
     /* Allocate a new buffer to hold the new title (NULL-terminated) */
-    Buffer = ConsoleAllocHeap(0, BufLength + sizeof(WCHAR));
+    Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY, Length + sizeof(WCHAR));
     if (!Buffer) return STATUS_NO_MEMORY;
 
     /* Free the old title */
@@ -996,9 +1038,22 @@ ConDrvSetConsoleTitle(IN PCONSOLE Console,
 
     /* Copy title to console */
     Console->Title.Buffer = Buffer;
-    Console->Title.Length = BufLength;
+    Console->Title.Length = Length;
     Console->Title.MaximumLength = Console->Title.Length + sizeof(WCHAR);
-    RtlCopyMemory(Console->Title.Buffer, Title, Console->Title.Length);
+
+    if (Unicode)
+    {
+        RtlCopyMemory(Console->Title.Buffer, TitleBuffer, Console->Title.Length);
+    }
+    else
+    {
+        MultiByteToWideChar(Console->CodePage, 0,
+                            TitleBuffer, BufLength,
+                            Console->Title.Buffer,
+                            Console->Title.Length / sizeof(WCHAR));
+    }
+
+    /* NULL-terminate */
     Console->Title.Buffer[Console->Title.Length / sizeof(WCHAR)] = L'\0';
 
     // TermChangeTitle(Console);
@@ -1066,7 +1121,7 @@ ConDrvGetConsoleProcessList(IN PCONSOLE Console,
 NTSTATUS NTAPI
 ConDrvConsoleProcessCtrlEvent(IN PCONSOLE Console,
                               IN ULONG ProcessGroupId,
-                              IN ULONG Event)
+                              IN ULONG CtrlEvent)
 {
     NTSTATUS Status = STATUS_SUCCESS;
     PLIST_ENTRY current_entry;
@@ -1094,7 +1149,7 @@ ConDrvConsoleProcessCtrlEvent(IN PCONSOLE Console,
          */
         if (ProcessGroupId == 0 || current->Process->ProcessGroupId == ProcessGroupId)
         {
-            Status = ConDrvConsoleCtrlEvent(Event, current);
+            Status = ConDrvConsoleCtrlEvent(CtrlEvent, current);
         }
     }
 
index fe99b38..da6459d 100644 (file)
@@ -1259,7 +1259,7 @@ ConDrvGetConsoleScreenBufferInfo(IN  PCONSOLE Console,
 NTSTATUS NTAPI
 ConDrvSetConsoleTextAttribute(IN PCONSOLE Console,
                               IN PTEXTMODE_SCREEN_BUFFER Buffer,
-                              IN WORD Attribute)
+                              IN WORD Attributes)
 {
     if (Console == NULL || Buffer == NULL)
         return STATUS_INVALID_PARAMETER;
@@ -1267,7 +1267,7 @@ ConDrvSetConsoleTextAttribute(IN PCONSOLE Console,
     /* Validity check */
     ASSERT(Console == Buffer->Header.Console);
 
-    Buffer->ScreenDefaultAttrib = Attribute;
+    Buffer->ScreenDefaultAttrib = Attributes;
     return STATUS_SUCCESS;
 }
 
index d0b01e2..97e1ee5 100644 (file)
@@ -444,7 +444,7 @@ CSR_API(SrvFlushConsoleInputBuffer)
 NTSTATUS NTAPI
 ConDrvGetConsoleNumberOfInputEvents(IN PCONSOLE Console,
                                     IN PCONSOLE_INPUT_BUFFER InputBuffer,
-                                    OUT PULONG NumEvents);
+                                    OUT PULONG NumberOfEvents);
 CSR_API(SrvGetConsoleNumberOfInputEvents)
 {
     NTSTATUS Status;
@@ -460,7 +460,7 @@ CSR_API(SrvGetConsoleNumberOfInputEvents)
 
     Status = ConDrvGetConsoleNumberOfInputEvents(InputBuffer->Header.Console,
                                                  InputBuffer,
-                                                 &GetNumInputEventsRequest->NumInputEvents);
+                                                 &GetNumInputEventsRequest->NumberOfEvents);
 
     ConSrvReleaseInputBuffer(InputBuffer, TRUE);
     return Status;
index fe04b8b..9c01dd4 100644 (file)
@@ -720,7 +720,7 @@ CSR_API(SrvGetConsoleScreenBufferInfo)
 NTSTATUS NTAPI
 ConDrvSetConsoleTextAttribute(IN PCONSOLE Console,
                               IN PTEXTMODE_SCREEN_BUFFER Buffer,
-                              IN WORD Attribute);
+                              IN WORD Attributes);
 CSR_API(SrvSetConsoleTextAttribute)
 {
     NTSTATUS Status;
@@ -736,7 +736,7 @@ CSR_API(SrvSetConsoleTextAttribute)
 
     Status = ConDrvSetConsoleTextAttribute(Buffer->Header.Console,
                                            Buffer,
-                                           SetTextAttribRequest->Attrib);
+                                           SetTextAttribRequest->Attributes);
 
     ConSrvReleaseScreenBuffer(Buffer, TRUE);
     return Status;
index 8cc401a..8ecd567 100644 (file)
@@ -439,12 +439,12 @@ CSR_API(SrvGetConsoleMode)
     PCONSOLE_IO_OBJECT Object;
 
     Status = ConSrvGetObject(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
-                             ConsoleModeRequest->ConsoleHandle,
+                             ConsoleModeRequest->Handle,
                              &Object, NULL, GENERIC_READ, TRUE, 0);
     if (!NT_SUCCESS(Status)) return Status;
 
     Status = ConDrvGetConsoleMode(Object->Console, Object,
-                                  &ConsoleModeRequest->ConsoleMode);
+                                  &ConsoleModeRequest->Mode);
 
     ConSrvReleaseObject(Object, TRUE);
     return Status;
@@ -461,12 +461,12 @@ CSR_API(SrvSetConsoleMode)
     PCONSOLE_IO_OBJECT Object;
 
     Status = ConSrvGetObject(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
-                             ConsoleModeRequest->ConsoleHandle,
+                             ConsoleModeRequest->Handle,
                              &Object, NULL, GENERIC_WRITE, TRUE, 0);
     if (!NT_SUCCESS(Status)) return Status;
 
     Status = ConDrvSetConsoleMode(Object->Console, Object,
-                                  ConsoleModeRequest->ConsoleMode);
+                                  ConsoleModeRequest->Mode);
 
     ConSrvReleaseObject(Object, TRUE);
     return Status;
@@ -474,7 +474,8 @@ CSR_API(SrvSetConsoleMode)
 
 NTSTATUS NTAPI
 ConDrvGetConsoleTitle(IN PCONSOLE Console,
-                      IN OUT PWCHAR Title,
+                      IN BOOLEAN Unicode,
+                      IN OUT PVOID TitleBuffer,
                       IN OUT PULONG BufLength);
 CSR_API(SrvGetConsoleTitle)
 {
@@ -498,6 +499,7 @@ CSR_API(SrvGetConsoleTitle)
     }
 
     Status = ConDrvGetConsoleTitle(Console,
+                                   TitleRequest->Unicode,
                                    TitleRequest->Title,
                                    &TitleRequest->Length);
 
@@ -507,7 +509,8 @@ CSR_API(SrvGetConsoleTitle)
 
 NTSTATUS NTAPI
 ConDrvSetConsoleTitle(IN PCONSOLE Console,
-                      IN PWCHAR Title,
+                      IN BOOLEAN Unicode,
+                      IN PVOID TitleBuffer,
                       IN ULONG BufLength);
 CSR_API(SrvSetConsoleTitle)
 {
@@ -531,9 +534,9 @@ CSR_API(SrvSetConsoleTitle)
     }
 
     Status = ConDrvSetConsoleTitle(Console,
+                                   TitleRequest->Unicode,
                                    TitleRequest->Title,
                                    TitleRequest->Length);
-
     if (NT_SUCCESS(Status)) TermChangeTitle(Console);
 
     ConSrvReleaseConsole(Console, TRUE);
@@ -629,8 +632,8 @@ CSR_API(SrvGenerateConsoleCtrlEvent)
     if (!NT_SUCCESS(Status)) return Status;
 
     Status = ConDrvConsoleProcessCtrlEvent(Console,
-                                           GenerateCtrlEventRequest->ProcessGroup,
-                                           GenerateCtrlEventRequest->Event);
+                                           GenerateCtrlEventRequest->ProcessGroupId,
+                                           GenerateCtrlEventRequest->CtrlEvent);
 
     ConSrvReleaseConsole(Console, TRUE);
     return Status;
index 9f268d2..6ad1cdf 100644 (file)
@@ -688,11 +688,11 @@ CSR_API(SrvOpenConsole)
     PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
     PCONSOLE Console;
 
-    DWORD DesiredAccess = OpenConsoleRequest->Access;
+    DWORD DesiredAccess = OpenConsoleRequest->DesiredAccess;
     DWORD ShareMode = OpenConsoleRequest->ShareMode;
     PCONSOLE_IO_OBJECT Object;
 
-    OpenConsoleRequest->ConsoleHandle = INVALID_HANDLE_VALUE;
+    OpenConsoleRequest->Handle = INVALID_HANDLE_VALUE;
 
     Status = ConSrvGetConsole(ProcessData, &Console, TRUE);
     if (!NT_SUCCESS(Status))
@@ -726,10 +726,10 @@ CSR_API(SrvOpenConsole)
     else
     {
         Status = ConSrvInsertObject(ProcessData,
-                                    &OpenConsoleRequest->ConsoleHandle,
+                                    &OpenConsoleRequest->Handle,
                                     Object,
                                     DesiredAccess,
-                                    OpenConsoleRequest->Inheritable,
+                                    OpenConsoleRequest->InheritHandle,
                                     ShareMode);
     }
 
@@ -746,11 +746,13 @@ CSR_API(SrvDuplicateHandle)
     PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
     PCONSOLE Console;
 
-    HANDLE ConsoleHandle = DuplicateHandleRequest->ConsoleHandle;
-    ULONG Index = HandleToULong(ConsoleHandle) >> 2;
+    HANDLE SourceHandle = DuplicateHandleRequest->SourceHandle;
+    ULONG Index = HandleToULong(SourceHandle) >> 2;
     PCONSOLE_IO_HANDLE Entry;
     DWORD DesiredAccess;
 
+    DuplicateHandleRequest->TargetHandle = INVALID_HANDLE_VALUE;
+
     Status = ConSrvGetConsole(ProcessData, &Console, TRUE);
     if (!NT_SUCCESS(Status))
     {
@@ -763,11 +765,11 @@ CSR_API(SrvDuplicateHandle)
     // ASSERT( (ProcessData->HandleTable == NULL && ProcessData->HandleTableSize == 0) ||
     //         (ProcessData->HandleTable != NULL && ProcessData->HandleTableSize != 0) );
 
-    if ( /** !IsConsoleHandle(ConsoleHandle)    || **/
+    if ( /** !IsConsoleHandle(SourceHandle)   || **/
         Index >= ProcessData->HandleTableSize ||
         (Entry = &ProcessData->HandleTable[Index])->Object == NULL)
     {
-        DPRINT1("Couldn't duplicate invalid handle %p\n", ConsoleHandle);
+        DPRINT1("Couldn't duplicate invalid handle 0x%p\n", SourceHandle);
         Status = STATUS_INVALID_HANDLE;
         goto Quit;
     }
@@ -778,12 +780,12 @@ CSR_API(SrvDuplicateHandle)
     }
     else
     {
-        DesiredAccess = DuplicateHandleRequest->Access;
+        DesiredAccess = DuplicateHandleRequest->DesiredAccess;
         /* Make sure the source handle has all the desired flags */
         if ((Entry->Access & DesiredAccess) == 0)
         {
-            DPRINT1("Handle %p only has access %X; requested %X\n",
-                    ConsoleHandle, Entry->Access, DesiredAccess);
+            DPRINT1("Handle 0x%p only has access %X; requested %X\n",
+                    SourceHandle, Entry->Access, DesiredAccess);
             Status = STATUS_INVALID_PARAMETER;
             goto Quit;
         }
@@ -791,10 +793,10 @@ CSR_API(SrvDuplicateHandle)
 
     /* Insert the new handle inside the process handles table */
     Status = ConSrvInsertObject(ProcessData,
-                                &DuplicateHandleRequest->ConsoleHandle, // Use the new handle value!
+                                &DuplicateHandleRequest->TargetHandle,
                                 Entry->Object,
                                 DesiredAccess,
-                                DuplicateHandleRequest->Inheritable,
+                                DuplicateHandleRequest->InheritHandle,
                                 Entry->ShareMode);
     if (NT_SUCCESS(Status) &&
         (DuplicateHandleRequest->Options & DUPLICATE_CLOSE_SOURCE))
index a60e95f..30a70ea 100644 (file)
@@ -344,7 +344,7 @@ VOID FASTCALL ConioUnpause(PCONSOLE Console, UINT Flags);
 NTSTATUS NTAPI
 ConDrvConsoleProcessCtrlEvent(IN PCONSOLE Console,
                               IN ULONG ProcessGroupId,
-                              IN ULONG Event);
+                              IN ULONG CtrlEvent);
 
 /* coninput.c */
 VOID NTAPI ConioProcessKey(PCONSOLE Console, MSG* msg);