[NTUSER] Fix desktop and window station assignment for csrss
[reactos.git] / win32ss / user / winsrv / usersrv / harderror.c
index 6ff336a..e835ed8 100644 (file)
@@ -1012,34 +1012,16 @@ 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)
     {
@@ -1107,6 +1089,7 @@ UserServerHardError(
     UNICODE_STRING TextU, CaptionU;
     WCHAR LocalTextBuffer[256];
     WCHAR LocalCaptionBuffer[256];
+    NTSTATUS Status;
 
     ASSERT(ThreadData->Process != NULL);
 
@@ -1136,6 +1119,16 @@ UserServerHardError(
         // (Message->UnicodeStringParameterMask & 0x3)
     }
 
+    Status = NtUserSetInformationThread(NtCurrentThread(),
+                                        UserThreadUseActiveDesktop,
+                                        NULL,
+                                        0);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to set thread desktop!\n");
+        return;
+    }
+
     /* Re-initialize the hard errors cache */
     UserInitHardErrorsCache();
 
@@ -1187,6 +1180,8 @@ Quit:
     if (CaptionU.Buffer != LocalCaptionBuffer)
         RtlFreeUnicodeString(&CaptionU);
 
+    NtUserSetInformationThread(NtCurrentThread(), UserThreadRestoreDesktop, NULL, 0);
+
     return;
 }