https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d70848b8b7d1a7e8dd8fd…
commit d70848b8b7d1a7e8dd8fd7c6ae10b38d8a9c0f53
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Apr 28 02:40:20 2019 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Apr 28 02:50:38 2019 +0200
[WINSRV] Implement SrvGetThreadConsoleDesktop(). CORE-13470
It retrieves the handle to the desktop assigned to the specified
thread belonging to a console application, which is going to be
where the input thread of this console is.
---
sdk/include/reactos/subsys/win/winmsg.h | 2 +-
win32ss/user/winsrv/consrv/api.h | 8 +++++
win32ss/user/winsrv/consrv/frontendctl.c | 36 ++++++++++++++++++++++
win32ss/user/winsrv/consrv/frontends/gui/guiterm.c | 8 +++++
win32ss/user/winsrv/consrv/frontends/tui/tuiterm.c | 8 +++++
win32ss/user/winsrv/consrv/include/conio_winsrv.h | 1 +
win32ss/user/winsrv/consrv/include/term.h | 2 ++
win32ss/user/winsrv/usersrv/init.c | 18 ++++++-----
8 files changed, 75 insertions(+), 8 deletions(-)
diff --git a/sdk/include/reactos/subsys/win/winmsg.h
b/sdk/include/reactos/subsys/win/winmsg.h
index 6134538cad..e445331eba 100644
--- a/sdk/include/reactos/subsys/win/winmsg.h
+++ b/sdk/include/reactos/subsys/win/winmsg.h
@@ -68,7 +68,7 @@ typedef struct _USER_LOGON
typedef struct _USER_GET_THREAD_CONSOLE_DESKTOP
{
ULONG_PTR ThreadId;
- HANDLE ConsoleDesktop;
+ HDESK ConsoleDesktop;
} USER_GET_THREAD_CONSOLE_DESKTOP, *PUSER_GET_THREAD_CONSOLE_DESKTOP;
typedef struct _USER_REGISTER_SERVICES_PROCESS
diff --git a/win32ss/user/winsrv/consrv/api.h b/win32ss/user/winsrv/consrv/api.h
index c9e62d46c9..45aca668c2 100644
--- a/win32ss/user/winsrv/consrv/api.h
+++ b/win32ss/user/winsrv/consrv/api.h
@@ -78,6 +78,14 @@ CSR_API(SrvShowConsoleCursor);
CSR_API(SrvSetConsoleCursor);
CSR_API(SrvConsoleMenuControl);
CSR_API(SrvSetConsoleMenuClose);
+
+/* Used by USERSRV!SrvGetThreadConsoleDesktop() */
+NTSTATUS
+NTAPI
+GetThreadConsoleDesktop(
+ IN ULONG_PTR ThreadId,
+ OUT HDESK* ConsoleDesktop);
+
CSR_API(SrvGetConsoleWindow);
CSR_API(SrvSetConsoleIcon);
CSR_API(SrvGetConsoleSelectionInfo);
diff --git a/win32ss/user/winsrv/consrv/frontendctl.c
b/win32ss/user/winsrv/consrv/frontendctl.c
index 9ea1fe9961..18ef2edd51 100644
--- a/win32ss/user/winsrv/consrv/frontendctl.c
+++ b/win32ss/user/winsrv/consrv/frontendctl.c
@@ -275,6 +275,42 @@ CSR_API(SrvSetConsoleMenuClose)
return (Success ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
}
+/* Used by USERSRV!SrvGetThreadConsoleDesktop() */
+NTSTATUS
+NTAPI
+GetThreadConsoleDesktop(
+ IN ULONG_PTR ThreadId,
+ OUT HDESK* ConsoleDesktop)
+{
+ NTSTATUS Status;
+ PCSR_THREAD CsrThread;
+ PCONSRV_CONSOLE Console;
+
+ /* No console desktop handle by default */
+ *ConsoleDesktop = NULL;
+
+ /* Retrieve and lock the thread */
+ Status = CsrLockThreadByClientId(ULongToHandle(ThreadId), &CsrThread);
+ if (!NT_SUCCESS(Status))
+ return Status;
+
+ ASSERT(CsrThread->Process);
+
+ /* Retrieve the console to which the process is attached, and unlock the thread */
+ Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrThread->Process),
+ &Console, TRUE);
+ CsrUnlockThread(CsrThread);
+
+ if (!NT_SUCCESS(Status))
+ return Status;
+
+ /* Retrieve the console desktop handle, and release the console */
+ *ConsoleDesktop = TermGetThreadConsoleDesktop(Console);
+ ConSrvReleaseConsole(Console, TRUE);
+
+ return STATUS_SUCCESS;
+}
+
CSR_API(SrvGetConsoleWindow)
{
NTSTATUS Status;
diff --git a/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
b/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
index 1468363517..2b2e9d4f27 100644
--- a/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
+++ b/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
@@ -911,6 +911,13 @@ GuiChangeIcon(IN OUT PFRONTEND This,
return TRUE;
}
+static HDESK NTAPI
+GuiGetThreadConsoleDesktop(IN OUT PFRONTEND This)
+{
+ PGUI_CONSOLE_DATA GuiData = This->Context;
+ return GuiData->Desktop;
+}
+
static HWND NTAPI
GuiGetConsoleWindowHandle(IN OUT PFRONTEND This)
{
@@ -1148,6 +1155,7 @@ static FRONTEND_VTBL GuiVtbl =
GuiRefreshInternalInfo,
GuiChangeTitle,
GuiChangeIcon,
+ GuiGetThreadConsoleDesktop,
GuiGetConsoleWindowHandle,
GuiGetLargestConsoleWindowSize,
GuiGetSelectionInfo,
diff --git a/win32ss/user/winsrv/consrv/frontends/tui/tuiterm.c
b/win32ss/user/winsrv/consrv/frontends/tui/tuiterm.c
index e1e96d6e55..e66203ad7b 100644
--- a/win32ss/user/winsrv/consrv/frontends/tui/tuiterm.c
+++ b/win32ss/user/winsrv/consrv/frontends/tui/tuiterm.c
@@ -831,6 +831,13 @@ TuiChangeIcon(IN OUT PFRONTEND This,
return TRUE;
}
+static HDESK NTAPI
+TuiGetThreadConsoleDesktop(IN OUT PFRONTEND This)
+{
+ // PTUI_CONSOLE_DATA TuiData = This->Context;
+ return NULL;
+}
+
static HWND NTAPI
TuiGetConsoleWindowHandle(IN OUT PFRONTEND This)
{
@@ -920,6 +927,7 @@ static FRONTEND_VTBL TuiVtbl =
TuiRefreshInternalInfo,
TuiChangeTitle,
TuiChangeIcon,
+ TuiGetThreadConsoleDesktop,
TuiGetConsoleWindowHandle,
TuiGetLargestConsoleWindowSize,
TuiGetSelectionInfo,
diff --git a/win32ss/user/winsrv/consrv/include/conio_winsrv.h
b/win32ss/user/winsrv/consrv/include/conio_winsrv.h
index 9398065bc0..79e0c04277 100644
--- a/win32ss/user/winsrv/consrv/include/conio_winsrv.h
+++ b/win32ss/user/winsrv/consrv/include/conio_winsrv.h
@@ -89,6 +89,7 @@ typedef struct _FRONTEND_VTBL
VOID (NTAPI *ChangeTitle)(IN OUT PFRONTEND This);
BOOL (NTAPI *ChangeIcon)(IN OUT PFRONTEND This,
HICON IconHandle);
+ HDESK (NTAPI *GetThreadConsoleDesktop)(IN OUT PFRONTEND This);
HWND (NTAPI *GetConsoleWindowHandle)(IN OUT PFRONTEND This);
VOID (NTAPI *GetLargestConsoleWindowSize)(IN OUT PFRONTEND This,
PCOORD pSize);
diff --git a/win32ss/user/winsrv/consrv/include/term.h
b/win32ss/user/winsrv/consrv/include/term.h
index a672499acf..2766ec8906 100644
--- a/win32ss/user/winsrv/consrv/include/term.h
+++ b/win32ss/user/winsrv/consrv/include/term.h
@@ -47,6 +47,8 @@
(Console)->FrontEndIFace.Vtbl->ChangeTitle(&(Console)->FrontEndIFace)
#define TermChangeIcon(Console, IconHandle) \
(Console)->FrontEndIFace.Vtbl->ChangeIcon(&(Console)->FrontEndIFace,
(IconHandle))
+#define TermGetThreadConsoleDesktop(Console) \
+
(Console)->FrontEndIFace.Vtbl->GetThreadConsoleDesktop(&(Console)->FrontEndIFace)
#define TermGetConsoleWindowHandle(Console) \
(Console)->FrontEndIFace.Vtbl->GetConsoleWindowHandle(&(Console)->FrontEndIFace)
#define TermGetSelectionInfo(Console, pSelectionInfo) \
diff --git a/win32ss/user/winsrv/usersrv/init.c b/win32ss/user/winsrv/usersrv/init.c
index 2e65099915..f3c5be8a4d 100644
--- a/win32ss/user/winsrv/usersrv/init.c
+++ b/win32ss/user/winsrv/usersrv/init.c
@@ -10,8 +10,8 @@
/* INCLUDES *******************************************************************/
#include "usersrv.h"
-
-#include "api.h"
+#include "api.h" // USERSRV Public server APIs definitions
+#include "../consrv/api.h" // CONSRV Public server APIs definitions
#define NDEBUG
#include <debug.h>
@@ -138,14 +138,18 @@ CSR_API(SrvActivateDebugger)
CSR_API(SrvGetThreadConsoleDesktop)
{
+ NTSTATUS Status;
PUSER_GET_THREAD_CONSOLE_DESKTOP GetThreadConsoleDesktopRequest =
&((PUSER_API_MESSAGE)ApiMessage)->Data.GetThreadConsoleDesktopRequest;
- UNIMPLEMENTED_ONCE;
-
- /* Return nothing for the moment... */
- GetThreadConsoleDesktopRequest->ConsoleDesktop = NULL;
+ Status = GetThreadConsoleDesktop(GetThreadConsoleDesktopRequest->ThreadId,
+
&GetThreadConsoleDesktopRequest->ConsoleDesktop);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("GetThreadConsoleDesktop(%lu) failed with Status 0x%08x\n",
+ GetThreadConsoleDesktopRequest->ThreadId, Status);
+ }
- /* Always succeeds */
+ /* Windows-compatibility: Always return success since User32 relies on this! */
return STATUS_SUCCESS;
}