Sync to trunk (r44371)
[reactos.git] / reactos / subsystems / win32 / win32k / ntuser / message.c
index 10342d1..f3644c0 100644 (file)
@@ -335,6 +335,9 @@ IntDispatchMessage(PMSG pMsg)
   LARGE_INTEGER TickCount;
   LONG Time;
   LRESULT retval;
+  PMSGMEMORY MsgMemoryEntry;
+  INT lParamBufferSize;
+  LPARAM lParamPacked;
   PWINDOW_OBJECT Window = NULL;
 
   if (pMsg->hwnd)
@@ -376,9 +379,37 @@ IntDispatchMessage(PMSG pMsg)
      }
   }
   // Need a window!
-  if (!Window) return 0;
+  if ( !Window || !Window->Wnd ) return 0;
 
-  retval = co_IntPostOrSendMessage(pMsg->hwnd, pMsg->message, pMsg->wParam, pMsg->lParam);
+  /* See if this message type is present in the table */
+  MsgMemoryEntry = FindMsgMemory(pMsg->message);
+  if ( !MsgMemoryEntry )
+  {
+     lParamBufferSize = -1;
+  }
+  else
+  {
+     lParamBufferSize = MsgMemorySize(MsgMemoryEntry, pMsg->wParam, pMsg->lParam);
+  }
+
+  if (! NT_SUCCESS(PackParam(&lParamPacked, pMsg->message, pMsg->wParam, pMsg->lParam)))
+  {
+     DPRINT1("Failed to pack message parameters\n");
+     return 0;
+  }
+
+  retval = co_IntCallWindowProc( Window->Wnd->lpfnWndProc,
+                                !Window->Wnd->Unicode,
+                                 pMsg->hwnd,
+                                 pMsg->message,
+                                 pMsg->wParam,
+                                 lParamPacked,
+                                 lParamBufferSize);
+
+  if (! NT_SUCCESS(UnpackParam(lParamPacked, pMsg->message, pMsg->wParam, pMsg->lParam)))
+  {
+     DPRINT1("Failed to unpack message parameters\n");
+  }
 
   if (pMsg->message == WM_PAINT)
   {
@@ -482,7 +513,7 @@ NtUserDispatchMessage(PMSG UnsafeMsgInfo)
 
 BOOL APIENTRY
 NtUserTranslateMessage(LPMSG lpMsg,
-                       HKL dwhkl)
+                       UINT Flags)
 {
    NTSTATUS Status;
    MSG SafeMsg;
@@ -498,7 +529,7 @@ NtUserTranslateMessage(LPMSG lpMsg,
       RETURN( FALSE);
    }
 
-   RETURN( IntTranslateKbdMessage(&SafeMsg, dwhkl));
+   RETURN( IntTranslateKbdMessage(&SafeMsg, Flags));
 
 CLEANUP:
    DPRINT("Leave NtUserTranslateMessage: ret=%i\n",_ret_);
@@ -1324,7 +1355,7 @@ UserPostThreadMessage( DWORD idThread,
    if( Status == STATUS_SUCCESS )
    {
       pThread = (PTHREADINFO)peThread->Tcb.Win32Thread;
-      if( !pThread || !pThread->MessageQueue )
+      if( !pThread || !pThread->MessageQueue || (pThread->TIF_flags & TIF_INCLEANUP))
       {
          ObDereferenceObject( peThread );
          return FALSE;
@@ -1370,7 +1401,6 @@ UserPostMessage(HWND Wnd,
                                     wParam,
                                     lParam);
 
-   pti = PsGetCurrentThreadWin32Thread();
    if (Wnd == HWND_BROADCAST)
    {
       HWND *List;
@@ -1392,10 +1422,18 @@ UserPostMessage(HWND Wnd,
       PWINDOW_OBJECT Window;
 
       Window = UserGetWindowObject(Wnd);
-      if (NULL == Window)
+      if ( !Window || !Window->Wnd )
       {
          return FALSE;
       }
+
+      pti = Window->Wnd->head.pti;
+      if ( pti->TIF_flags & TIF_INCLEANUP )
+      {
+         DPRINT1("Attempted to post message to window 0x%x when the thread is in cleanup!\n", Wnd);
+         return FALSE;
+      }
+
       if(Window->Status & WINDOWSTATUS_DESTROYING)
       {
          DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd);
@@ -1761,6 +1799,9 @@ co_IntDoSendMessage(HWND hWnd,
       Info.Ansi = !Window->Wnd->Unicode;
       Info.Proc = Window->Wnd->lpfnWndProc;
 
+      // Make the call from here if CALLWNDPROC or CALLWNDPROCRET are hooked
+      // or just do it in User32!
+
       IntCallWndProcRet( Window, hWnd, Msg, wParam, lParam, &Result);
    }
    else