[WIN32K:NTUSER] Add a temporary winsta/desktop-connection hack for CSRSS/USERSRV...
[reactos.git] / win32ss / user / winsrv / usersrv / harderror.c
index 85ef9fe..6ff336a 100644 (file)
@@ -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)
     {