https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3270979327444f7870057a0917cddd1072ea108f

commit 3270979327444f7870057a0917cddd1072ea108f
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Sun Jul 22 23:11:00 2018 +0200
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Sun Aug 19 22:18:40 2018 +0200

    [WIN32K:NTUSER] Add a temporary winsta/desktop-connection hack for 
CSRSS/USERSRV (connection to WinSta0).
    
    Normally CSRSS must not be connected to any winsta or desktop by default. 
It should manually connect
    to a winsta/desktop only when it has to do some GUI operations, and then 
disconnect afterwards.
    
    [USERSRV] Temporarily hackfix the harderror dialog display to the current 
input desktop.
---
 win32ss/user/ntuser/main.c              |  7 ++++++-
 win32ss/user/winsrv/usersrv/harderror.c | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/win32ss/user/ntuser/main.c b/win32ss/user/ntuser/main.c
index 21fba73d1d..73d39d3bd5 100644
--- a/win32ss/user/ntuser/main.c
+++ b/win32ss/user/ntuser/main.c
@@ -577,7 +577,8 @@ InitThreadCallback(PETHREAD Thread)
      */
     // if (ptiCurrent->ppi->hdeskStartup == NULL && InputWindowStation != NULL)
     /* Last things to do only if we are not a SYSTEM or CSRSS thread */
-    if (!(ptiCurrent->TIF_flags & (TIF_SYSTEMTHREAD | TIF_CSRSSTHREAD)) &&
+    // HACK Part #1: Temporarily disabled to have our current USERSRV running, 
but normally this is its duty to connect itself to the required desktop!
+    if (// !(ptiCurrent->TIF_flags & (TIF_SYSTEMTHREAD | TIF_CSRSSTHREAD)) &&
         /**/ptiCurrent->ppi->hdeskStartup == NULL &&/**/
         InputWindowStation != NULL)
     {
@@ -586,6 +587,10 @@ InitThreadCallback(PETHREAD Thread)
         UNICODE_STRING DesktopPath;
         PDESKTOP pdesk;
 
+        // HACK Part #2: We force USERSRV to connect to WinSta0 by setting the 
STARTF_INHERITDESKTOP flag.
+        if (ptiCurrent->TIF_flags & (TIF_SYSTEMTHREAD | TIF_CSRSSTHREAD))
+            ProcessParams->WindowFlags |= STARTF_INHERITDESKTOP;
+
         /*
          * Inherit the thread desktop and process window station (if not yet 
inherited)
          * from the process startup info structure. See documentation of 
CreateProcess().
diff --git a/win32ss/user/winsrv/usersrv/harderror.c 
b/win32ss/user/winsrv/usersrv/harderror.c
index 85ef9fe23d..6ff336aff5 100644
--- a/win32ss/user/winsrv/usersrv/harderror.c
+++ b/win32ss/user/winsrv/usersrv/harderror.c
@@ -1012,16 +1012,34 @@ UserpMessageBox(
     IN ULONG Timeout)
 {
     ULONG MessageBoxResponse;
+    HDESK hDesk, hOldDesk;
 
     DPRINT("Text = '%S', Caption = '%S', Type = 0x%lx\n",
            TextStringU->Buffer, CaptionStringU->Buffer, Type);
 
+    // TEMPORARY HACK to fix desktop assignment for harderror message boxes.
+    hDesk = OpenInputDesktop(0, FALSE, GENERIC_WRITE);
+    if (!hDesk)
+        return ResponseNotHandled;
+
+    /* Assign the desktop to this thread */
+    hOldDesk = GetThreadDesktop(GetCurrentThreadId());
+    if (!SetThreadDesktop(hDesk))
+    {
+        CloseDesktop(hDesk);
+        return ResponseNotHandled;
+    }
+
     /* Display a message box */
     MessageBoxResponse = MessageBoxTimeoutW(NULL,
                                             TextStringU->Buffer,
                                             CaptionStringU->Buffer,
                                             Type, 0, Timeout);
 
+    /* Restore the original desktop */
+    SetThreadDesktop(hOldDesk);
+    CloseDesktop(hDesk);
+
     /* Return response value */
     switch (MessageBoxResponse)
     {

Reply via email to