[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.
This commit is contained in:
Hermès Bélusca-Maïto 2019-04-28 02:40:20 +02:00
parent 2da24f7274
commit d70848b8b7
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
8 changed files with 75 additions and 8 deletions

View file

@ -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

View file

@ -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);

View file

@ -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;

View file

@ -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,

View file

@ -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,

View file

@ -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);

View file

@ -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) \

View file

@ -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;
Status = GetThreadConsoleDesktop(GetThreadConsoleDesktopRequest->ThreadId,
&GetThreadConsoleDesktopRequest->ConsoleDesktop);
if (!NT_SUCCESS(Status))
{
DPRINT1("GetThreadConsoleDesktop(%lu) failed with Status 0x%08x\n",
GetThreadConsoleDesktopRequest->ThreadId, Status);
}
/* Return nothing for the moment... */
GetThreadConsoleDesktopRequest->ConsoleDesktop = NULL;
/* Always succeeds */
/* Windows-compatibility: Always return success since User32 relies on this! */
return STATUS_SUCCESS;
}