2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
5 * FILE: subsys/win32k/ntuser/message.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
11 /* INCLUDES ******************************************************************/
18 BOOLEAN NTAPI
PsGetProcessExitProcessCalled(PEPROCESS Process
);
20 #define PM_BADMSGFLAGS ~((QS_RAWINPUT << 16)|PM_QS_SENDMESSAGE|PM_QS_PAINT|PM_QS_POSTMESSAGE|PM_QS_INPUT|PM_NOYIELD|PM_REMOVE)
28 DOSENDMESSAGE
, *PDOSENDMESSAGE
;
30 /* FUNCTIONS *****************************************************************/
33 IntInitMessageImpl(VOID
)
35 return STATUS_SUCCESS
;
39 IntCleanupMessageImpl(VOID
)
41 return STATUS_SUCCESS
;
44 #define MMS_SIZE_WPARAM -1
45 #define MMS_SIZE_WPARAMWCHAR -2
46 #define MMS_SIZE_LPARAMSZ -3
47 #define MMS_SIZE_SPECIAL -4
48 #define MMS_FLAG_READ 0x01
49 #define MMS_FLAG_WRITE 0x02
50 #define MMS_FLAG_READWRITE (MMS_FLAG_READ | MMS_FLAG_WRITE)
51 typedef struct tagMSGMEMORY
57 MSGMEMORY
, *PMSGMEMORY
;
59 static MSGMEMORY MsgMemory
[] =
61 { WM_CREATE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
62 { WM_DDE_ACK
, sizeof(KMDDELPARAM
), MMS_FLAG_READ
},
63 { WM_DDE_EXECUTE
, MMS_SIZE_WPARAM
, MMS_FLAG_READ
},
64 { WM_GETMINMAXINFO
, sizeof(MINMAXINFO
), MMS_FLAG_READWRITE
},
65 { WM_GETTEXT
, MMS_SIZE_WPARAMWCHAR
, MMS_FLAG_WRITE
},
66 { WM_NCCALCSIZE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
67 { WM_NCCREATE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
68 { WM_SETTEXT
, MMS_SIZE_LPARAMSZ
, MMS_FLAG_READ
},
69 { WM_STYLECHANGED
, sizeof(STYLESTRUCT
), MMS_FLAG_READ
},
70 { WM_STYLECHANGING
, sizeof(STYLESTRUCT
), MMS_FLAG_READWRITE
},
71 { WM_COPYDATA
, MMS_SIZE_SPECIAL
, MMS_FLAG_READ
},
72 { WM_WINDOWPOSCHANGED
, sizeof(WINDOWPOS
), MMS_FLAG_READ
},
73 { WM_WINDOWPOSCHANGING
, sizeof(WINDOWPOS
), MMS_FLAG_READWRITE
},
76 static PMSGMEMORY FASTCALL
77 FindMsgMemory(UINT Msg
)
79 PMSGMEMORY MsgMemoryEntry
;
81 /* See if this message type is present in the table */
82 for (MsgMemoryEntry
= MsgMemory
;
83 MsgMemoryEntry
< MsgMemory
+ sizeof(MsgMemory
) / sizeof(MSGMEMORY
);
86 if (Msg
== MsgMemoryEntry
->Message
)
88 return MsgMemoryEntry
;
96 MsgMemorySize(PMSGMEMORY MsgMemoryEntry
, WPARAM wParam
, LPARAM lParam
)
99 PUNICODE_STRING WindowName
;
100 PUNICODE_STRING ClassName
;
105 if (MMS_SIZE_WPARAM
== MsgMemoryEntry
->Size
)
109 else if (MMS_SIZE_WPARAMWCHAR
== MsgMemoryEntry
->Size
)
111 Size
= (UINT
) (wParam
* sizeof(WCHAR
));
113 else if (MMS_SIZE_LPARAMSZ
== MsgMemoryEntry
->Size
)
115 Size
= (UINT
) ((wcslen((PWSTR
) lParam
) + 1) * sizeof(WCHAR
));
117 else if (MMS_SIZE_SPECIAL
== MsgMemoryEntry
->Size
)
119 switch(MsgMemoryEntry
->Message
)
123 Cs
= (CREATESTRUCTW
*) lParam
;
124 WindowName
= (PUNICODE_STRING
) Cs
->lpszName
;
125 ClassName
= (PUNICODE_STRING
) Cs
->lpszClass
;
126 Size
= sizeof(CREATESTRUCTW
) + WindowName
->Length
+ sizeof(WCHAR
);
127 if (IS_ATOM(ClassName
->Buffer
))
129 Size
+= sizeof(WCHAR
) + sizeof(ATOM
);
133 Size
+= sizeof(WCHAR
) + ClassName
->Length
+ sizeof(WCHAR
);
138 Size
= wParam
? sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
) : sizeof(RECT
);
142 Size
= sizeof(COPYDATASTRUCT
) + ((PCOPYDATASTRUCT
)lParam
)->cbData
;
145 case WM_COPYGLOBALDATA
:
157 Size
= MsgMemoryEntry
->Size
;
160 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
162 DPRINT1("Exception caught in MsgMemorySize()! Status: 0x%x\n", _SEH2_GetExceptionCode());
170 PackParam(LPARAM
*lParamPacked
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, BOOL NonPagedPoolNeeded
)
172 NCCALCSIZE_PARAMS
*UnpackedNcCalcsize
;
173 NCCALCSIZE_PARAMS
*PackedNcCalcsize
;
174 CREATESTRUCTW
*UnpackedCs
;
175 CREATESTRUCTW
*PackedCs
;
176 PLARGE_STRING WindowName
;
177 PUNICODE_STRING ClassName
;
182 *lParamPacked
= lParam
;
184 if (NonPagedPoolNeeded
)
185 PoolType
= NonPagedPool
;
187 PoolType
= PagedPool
;
189 if (WM_NCCALCSIZE
== Msg
&& wParam
)
192 UnpackedNcCalcsize
= (NCCALCSIZE_PARAMS
*) lParam
;
193 PackedNcCalcsize
= ExAllocatePoolWithTag(PoolType
,
194 sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
),
197 if (NULL
== PackedNcCalcsize
)
199 DPRINT1("Not enough memory to pack lParam\n");
200 return STATUS_NO_MEMORY
;
202 RtlCopyMemory(PackedNcCalcsize
, UnpackedNcCalcsize
, sizeof(NCCALCSIZE_PARAMS
));
203 PackedNcCalcsize
->lppos
= (PWINDOWPOS
) (PackedNcCalcsize
+ 1);
204 RtlCopyMemory(PackedNcCalcsize
->lppos
, UnpackedNcCalcsize
->lppos
, sizeof(WINDOWPOS
));
205 *lParamPacked
= (LPARAM
) PackedNcCalcsize
;
207 else if (WM_CREATE
== Msg
|| WM_NCCREATE
== Msg
)
209 UnpackedCs
= (CREATESTRUCTW
*) lParam
;
210 WindowName
= (PLARGE_STRING
) UnpackedCs
->lpszName
;
211 ClassName
= (PUNICODE_STRING
) UnpackedCs
->lpszClass
;
212 Size
= sizeof(CREATESTRUCTW
) + WindowName
->Length
+ sizeof(WCHAR
);
213 if (IS_ATOM(ClassName
->Buffer
))
215 Size
+= sizeof(WCHAR
) + sizeof(ATOM
);
219 Size
+= sizeof(WCHAR
) + ClassName
->Length
+ sizeof(WCHAR
);
221 PackedCs
= ExAllocatePoolWithTag(PoolType
, Size
, TAG_MSG
);
222 if (NULL
== PackedCs
)
224 DPRINT1("Not enough memory to pack lParam\n");
225 return STATUS_NO_MEMORY
;
227 RtlCopyMemory(PackedCs
, UnpackedCs
, sizeof(CREATESTRUCTW
));
228 CsData
= (PCHAR
) (PackedCs
+ 1);
229 PackedCs
->lpszName
= (LPCWSTR
) (CsData
- (PCHAR
) PackedCs
);
230 RtlCopyMemory(CsData
, WindowName
->Buffer
, WindowName
->Length
);
231 CsData
+= WindowName
->Length
;
232 *((WCHAR
*) CsData
) = L
'\0';
233 CsData
+= sizeof(WCHAR
);
234 PackedCs
->lpszClass
= (LPCWSTR
) (CsData
- (PCHAR
) PackedCs
);
235 if (IS_ATOM(ClassName
->Buffer
))
237 *((WCHAR
*) CsData
) = L
'A';
238 CsData
+= sizeof(WCHAR
);
239 *((ATOM
*) CsData
) = (ATOM
)(DWORD_PTR
) ClassName
->Buffer
;
240 CsData
+= sizeof(ATOM
);
244 *((WCHAR
*) CsData
) = L
'S';
245 CsData
+= sizeof(WCHAR
);
246 RtlCopyMemory(CsData
, ClassName
->Buffer
, ClassName
->Length
);
247 CsData
+= ClassName
->Length
;
248 *((WCHAR
*) CsData
) = L
'\0';
249 CsData
+= sizeof(WCHAR
);
251 ASSERT(CsData
== (PCHAR
) PackedCs
+ Size
);
252 *lParamPacked
= (LPARAM
) PackedCs
;
255 else if (PoolType
== NonPagedPool
)
257 PMSGMEMORY MsgMemoryEntry
;
260 MsgMemoryEntry
= FindMsgMemory(Msg
);
262 if ((!MsgMemoryEntry
) || (MsgMemoryEntry
->Size
< 0))
264 /* Keep previous behavior */
265 return STATUS_SUCCESS
;
267 PackedData
= ExAllocatePoolWithTag(NonPagedPool
, MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
), TAG_MSG
);
268 RtlCopyMemory(PackedData
, (PVOID
)lParam
, MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
));
269 *lParamPacked
= (LPARAM
)PackedData
;
272 return STATUS_SUCCESS
;
276 UnpackParam(LPARAM lParamPacked
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, BOOL NonPagedPoolUsed
)
278 NCCALCSIZE_PARAMS
*UnpackedParams
;
279 NCCALCSIZE_PARAMS
*PackedParams
;
280 PWINDOWPOS UnpackedWindowPos
;
282 if (lParamPacked
== lParam
)
284 return STATUS_SUCCESS
;
287 if (WM_NCCALCSIZE
== Msg
&& wParam
)
289 PackedParams
= (NCCALCSIZE_PARAMS
*) lParamPacked
;
290 UnpackedParams
= (NCCALCSIZE_PARAMS
*) lParam
;
291 UnpackedWindowPos
= UnpackedParams
->lppos
;
292 RtlCopyMemory(UnpackedParams
, PackedParams
, sizeof(NCCALCSIZE_PARAMS
));
293 UnpackedParams
->lppos
= UnpackedWindowPos
;
294 RtlCopyMemory(UnpackedWindowPos
, PackedParams
+ 1, sizeof(WINDOWPOS
));
295 ExFreePool((PVOID
) lParamPacked
);
297 return STATUS_SUCCESS
;
299 else if (WM_CREATE
== Msg
|| WM_NCCREATE
== Msg
)
301 ExFreePool((PVOID
) lParamPacked
);
303 return STATUS_SUCCESS
;
305 else if (NonPagedPoolUsed
)
307 PMSGMEMORY MsgMemoryEntry
;
308 MsgMemoryEntry
= FindMsgMemory(Msg
);
309 if (MsgMemoryEntry
->Size
< 0)
311 /* Keep previous behavior */
312 return STATUS_INVALID_PARAMETER
;
315 if (MsgMemory
->Flags
== MMS_FLAG_READWRITE
)
317 //RtlCopyMemory((PVOID)lParam, (PVOID)lParamPacked, MsgMemory->Size);
319 ExFreePool((PVOID
) lParamPacked
);
320 return STATUS_SUCCESS
;
325 return STATUS_INVALID_PARAMETER
;
329 // Wakeup any thread/process waiting on idle input.
334 PPROCESSINFO ppi
= PsGetCurrentProcessWin32Process();
335 PUSER_MESSAGE_QUEUE ForegroundQueue
;
336 PTHREADINFO pti
, ptiForeground
= NULL
;
338 ForegroundQueue
= IntGetFocusMessageQueue();
341 ptiForeground
= ForegroundQueue
->Thread
->Tcb
.Win32Thread
;
343 pti
= PsGetCurrentThreadWin32Thread();
345 if ( pti
&& pti
->pDeskInfo
&& pti
== ptiForeground
)
347 if ( pti
->fsHooks
& HOOKID_TO_FLAG(WH_FOREGROUNDIDLE
) ||
348 pti
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_FOREGROUNDIDLE
) )
350 co_HOOK_CallHooks(WH_FOREGROUNDIDLE
,HC_ACTION
,0,0);
354 DPRINT("IdlePing ppi 0x%x\n",ppi
);
355 if ( ppi
&& ppi
->InputIdleEvent
)
357 DPRINT("InputIdleEvent\n");
358 KeSetEvent( ppi
->InputIdleEvent
, IO_NO_INCREMENT
, FALSE
);
365 PPROCESSINFO ppi
= PsGetCurrentProcessWin32Process();
367 DPRINT("IdlePong ppi 0x%x\n",ppi
);
368 if ( ppi
&& ppi
->InputIdleEvent
)
370 KeClearEvent(ppi
->InputIdleEvent
);
375 IntCallWndProc( PWND Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
377 BOOL SameThread
= FALSE
;
380 if (Window
->head
.pti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
387 co_HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, SameThread
, (LPARAM
)&CWP
);
391 IntCallWndProcRet ( PWND Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*uResult
)
393 BOOL SameThread
= FALSE
;
396 if (Window
->head
.pti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
401 CWPR
.wParam
= wParam
;
402 CWPR
.lParam
= lParam
;
403 CWPR
.lResult
= *uResult
;
404 co_HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, SameThread
, (LPARAM
)&CWPR
);
408 IntDispatchMessage(PMSG pMsg
)
410 LARGE_INTEGER TickCount
;
413 PMSGMEMORY MsgMemoryEntry
;
414 INT lParamBufferSize
;
421 Window
= UserGetWindowObject(pMsg
->hwnd
);
422 if (!Window
) return 0;
425 pti
= PsGetCurrentThreadWin32Thread();
427 if (((pMsg
->message
== WM_SYSTIMER
) ||
428 (pMsg
->message
== WM_TIMER
)) &&
431 if (pMsg
->message
== WM_TIMER
)
433 ObReferenceObject(pti
->pEThread
);
434 if (ValidateTimerCallback(pti
,pMsg
->lParam
))
436 KeQueryTickCount(&TickCount
);
437 Time
= MsqCalculateMessageTime(&TickCount
);
438 retval
= co_IntCallWindowProc((WNDPROC
)pMsg
->lParam
,
446 ObDereferenceObject(pti
->pEThread
);
451 PTIMER pTimer
= FindSystemTimer(pMsg
);
452 if (pTimer
&& pTimer
->pfn
)
454 KeQueryTickCount(&TickCount
);
455 Time
= MsqCalculateMessageTime(&TickCount
);
456 pTimer
->pfn(pMsg
->hwnd
, WM_SYSTIMER
, (UINT
)pMsg
->wParam
, Time
);
462 if ( !Window
) return 0;
464 /* See if this message type is present in the table */
465 MsgMemoryEntry
= FindMsgMemory(pMsg
->message
);
466 if ( !MsgMemoryEntry
)
468 lParamBufferSize
= -1;
472 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, pMsg
->wParam
, pMsg
->lParam
);
475 if (! NT_SUCCESS(PackParam(&lParamPacked
, pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
, FALSE
)))
477 DPRINT1("Failed to pack message parameters\n");
480 ObReferenceObject(pti
->pEThread
);
481 retval
= co_IntCallWindowProc( Window
->lpfnWndProc
,
489 if (! NT_SUCCESS(UnpackParam(lParamPacked
, pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
, FALSE
)))
491 DPRINT1("Failed to unpack message parameters\n");
494 if (pMsg
->message
== WM_PAINT
)
496 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
497 HRGN hrgn
= IntSysCreateRectRgn( 0, 0, 0, 0 );
498 co_UserGetUpdateRgn( Window
, hrgn
, TRUE
);
499 REGION_FreeRgnByHandle( hrgn
);
501 ObDereferenceObject(pti
->pEThread
);
506 * Internal version of PeekMessage() doing all the work
509 co_IntPeekMessage( PMSG Msg
,
516 LARGE_INTEGER LargeTickCount
;
517 PUSER_MESSAGE_QUEUE ThreadQueue
;
520 pti
= PsGetCurrentThreadWin32Thread();
521 ThreadQueue
= pti
->MessageQueue
;
523 RemoveMessages
= RemoveMsg
& PM_REMOVE
;
529 KeQueryTickCount(&LargeTickCount
);
530 ThreadQueue
->LastMsgRead
= LargeTickCount
.u
.LowPart
;
532 /* Dispatch sent messages here. */
533 while (co_MsqDispatchOneSentMessage(ThreadQueue
)) ;
535 /* Now look for a quit message. */
537 if (ThreadQueue
->QuitPosted
)
539 /* According to the PSDK, WM_QUIT messages are always returned, regardless
540 of the filter specified */
542 Msg
->message
= WM_QUIT
;
543 Msg
->wParam
= ThreadQueue
->QuitExitCode
;
547 ThreadQueue
->QuitPosted
= FALSE
;
553 /* Now check for normal messages. */
554 if (MsqPeekMessage( ThreadQueue
,
564 /* Check for hardware events. */
565 if(co_MsqPeekMouseMove(ThreadQueue
,
575 if(co_MsqPeekHardwareMessage(ThreadQueue
,
585 /* Check for sent messages again. */
586 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
589 /* Check for paint messages. */
590 if( IntGetPaintMessage( Window
,
600 if (PostTimerMessages(Window
))
612 static NTSTATUS FASTCALL
613 CopyMsgToKernelMem(MSG
*KernelModeMsg
, MSG
*UserModeMsg
, PMSGMEMORY MsgMemoryEntry
)
620 *KernelModeMsg
= *UserModeMsg
;
622 /* See if this message type is present in the table */
623 if (NULL
== MsgMemoryEntry
)
625 /* Not present, no copying needed */
626 return STATUS_SUCCESS
;
629 /* Determine required size */
630 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
634 /* Allocate kernel mem */
635 KernelMem
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
636 if (NULL
== KernelMem
)
638 DPRINT1("Not enough memory to copy message to kernel mem\n");
639 return STATUS_NO_MEMORY
;
641 KernelModeMsg
->lParam
= (LPARAM
) KernelMem
;
643 /* Copy data if required */
644 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_READ
))
646 Status
= MmCopyFromCaller(KernelMem
, (PVOID
) UserModeMsg
->lParam
, Size
);
647 if (! NT_SUCCESS(Status
))
649 DPRINT1("Failed to copy message to kernel: invalid usermode buffer\n");
650 ExFreePoolWithTag(KernelMem
, TAG_MSG
);
656 /* Make sure we don't pass any secrets to usermode */
657 RtlZeroMemory(KernelMem
, Size
);
662 KernelModeMsg
->lParam
= 0;
665 return STATUS_SUCCESS
;
668 static NTSTATUS FASTCALL
669 CopyMsgToUserMem(MSG
*UserModeMsg
, MSG
*KernelModeMsg
)
672 PMSGMEMORY MsgMemoryEntry
;
675 /* See if this message type is present in the table */
676 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
->message
);
677 if (NULL
== MsgMemoryEntry
)
679 /* Not present, no copying needed */
680 return STATUS_SUCCESS
;
683 /* Determine required size */
684 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
688 /* Copy data if required */
689 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_WRITE
))
691 Status
= MmCopyToCaller((PVOID
) UserModeMsg
->lParam
, (PVOID
) KernelModeMsg
->lParam
, Size
);
692 if (! NT_SUCCESS(Status
))
694 DPRINT1("Failed to copy message from kernel: invalid usermode buffer\n");
695 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
700 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
703 return STATUS_SUCCESS
;
707 co_IntWaitMessage( PWND Window
,
712 PUSER_MESSAGE_QUEUE ThreadQueue
;
713 NTSTATUS Status
= STATUS_SUCCESS
;
716 pti
= PsGetCurrentThreadWin32Thread();
717 ThreadQueue
= pti
->MessageQueue
;
721 if ( co_IntPeekMessage( &Msg
,
730 /* Nothing found. Wait for new messages. */
731 Status
= co_MsqWaitForNewMessages( ThreadQueue
,
736 while ( (STATUS_WAIT_0
<= Status
&& Status
<= STATUS_WAIT_63
) ||
737 STATUS_TIMEOUT
== Status
);
739 if (!NT_SUCCESS(Status
))
741 SetLastNtError(Status
);
742 DPRINT1("Exit co_IntWaitMessage on error!\n");
749 co_IntGetPeekMessage( PMSG pMsg
,
757 BOOL Present
= FALSE
;
759 if ( hWnd
== HWND_TOPMOST
|| hWnd
== HWND_BROADCAST
)
763 if (hWnd
&& hWnd
!= HWND_BOTTOM
)
765 if (!(Window
= UserGetWindowObject(hWnd
)))
778 if (MsgFilterMax
< MsgFilterMin
)
786 Present
= co_IntPeekMessage( pMsg
,
793 // The WH_GETMESSAGE hook enables an application to monitor messages about to
794 // be returned by the GetMessage or PeekMessage function.
796 co_HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, RemoveMsg
& PM_REMOVE
, (LPARAM
)pMsg
);
799 return (WM_QUIT
!= pMsg
->message
);
804 if ( !co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
) )
809 if (!(RemoveMsg
& PM_NOYIELD
))
812 // Yield this thread!
815 UserEnterExclusive();
816 // Fall through to exit.
822 while( bGMSG
&& !Present
);
828 UserPostThreadMessage( DWORD idThread
,
836 LARGE_INTEGER LargeTickCount
;
839 DPRINT1("UserPostThreadMessage wParam 0x%x lParam 0x%x\n", wParam
,lParam
);
841 if (FindMsgMemory(Msg
) != 0)
843 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
847 Status
= PsLookupThreadByThreadId((HANDLE
)idThread
,&peThread
);
849 if( Status
== STATUS_SUCCESS
)
851 pThread
= (PTHREADINFO
)peThread
->Tcb
.Win32Thread
;
853 !pThread
->MessageQueue
||
854 (pThread
->TIF_flags
& TIF_INCLEANUP
))
856 ObDereferenceObject( peThread
);
861 Message
.message
= Msg
;
862 Message
.wParam
= wParam
;
863 Message
.lParam
= lParam
;
864 Message
.pt
= gpsi
->ptCursor
;
866 KeQueryTickCount(&LargeTickCount
);
867 pThread
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
868 MsqPostMessage(pThread
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
869 ObDereferenceObject( peThread
);
874 SetLastNtError( Status
);
880 UserPostMessage( HWND Wnd
,
887 LARGE_INTEGER LargeTickCount
;
889 if (FindMsgMemory(Msg
) != 0)
891 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
897 return UserPostThreadMessage( PtrToInt(PsGetCurrentThreadId()),
902 if (Wnd
== HWND_BROADCAST
)
908 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
909 List
= IntWinListChildren(DesktopWindow
);
913 UserPostMessage(DesktopWindow
->head
.h
, Msg
, wParam
, lParam
);
914 for (i
= 0; List
[i
]; i
++)
916 UserPostMessage(List
[i
], Msg
, wParam
, lParam
);
925 Window
= UserGetWindowObject(Wnd
);
931 pti
= Window
->head
.pti
;
932 if ( pti
->TIF_flags
& TIF_INCLEANUP
)
934 DPRINT1("Attempted to post message to window 0x%x when the thread is in cleanup!\n", Wnd
);
938 if ( Window
->state
& WNDS_DESTROYED
)
940 DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd
);
941 /* FIXME - last error code? */
947 MsqPostQuitMessage(Window
->head
.pti
->MessageQueue
, wParam
);
952 Message
.message
= Msg
;
953 Message
.wParam
= wParam
;
954 Message
.lParam
= lParam
;
955 Message
.pt
= gpsi
->ptCursor
;
956 KeQueryTickCount(&LargeTickCount
);
957 pti
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
958 MsqPostMessage(Window
->head
.pti
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
966 co_IntSendMessage( HWND hWnd
,
971 ULONG_PTR Result
= 0;
972 if(co_IntSendMessageTimeout(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
))
974 return (LRESULT
)Result
;
979 static LRESULT FASTCALL
980 co_IntSendMessageTimeoutSingle( HWND hWnd
,
990 PMSGMEMORY MsgMemoryEntry
;
991 INT lParamBufferSize
;
993 PTHREADINFO Win32Thread
;
994 ULONG_PTR Result
= 0;
995 DECLARE_RETURN(LRESULT
);
996 USER_REFERENCE_ENTRY Ref
;
998 if (!(Window
= UserGetWindowObject(hWnd
)))
1003 UserRefObjectCo(Window
, &Ref
);
1005 Win32Thread
= PsGetCurrentThreadWin32Thread();
1007 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1009 if ( NULL
!= Win32Thread
&&
1010 Window
->head
.pti
->MessageQueue
== Win32Thread
->MessageQueue
)
1012 if (Win32Thread
->TIF_flags
& TIF_INCLEANUP
)
1014 /* Never send messages to exiting threads */
1018 /* See if this message type is present in the table */
1019 MsgMemoryEntry
= FindMsgMemory(Msg
);
1020 if (NULL
== MsgMemoryEntry
)
1022 lParamBufferSize
= -1;
1026 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1029 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
, FALSE
)))
1031 DPRINT1("Failed to pack message parameters\n");
1035 ObReferenceObject(Win32Thread
->pEThread
);
1036 Result
= (ULONG_PTR
)co_IntCallWindowProc( Window
->lpfnWndProc
,
1048 ObDereferenceObject(Win32Thread
->pEThread
);
1050 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1052 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
, FALSE
)))
1054 DPRINT1("Failed to unpack message parameters\n");
1061 if (uFlags
& SMTO_ABORTIFHUNG
&& MsqIsHung(Window
->head
.pti
->MessageQueue
))
1063 /* FIXME - Set a LastError? */
1067 if (Window
->state
& WNDS_DESTROYED
)
1069 /* FIXME - last error? */
1070 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1076 Status
= co_MsqSendMessage( Window
->head
.pti
->MessageQueue
,
1082 (uFlags
& SMTO_BLOCK
),
1086 while ((STATUS_TIMEOUT
== Status
) &&
1087 (uFlags
& SMTO_NOTIMEOUTIFNOTHUNG
) &&
1088 !MsqIsHung(Window
->head
.pti
->MessageQueue
));
1090 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1092 if (STATUS_TIMEOUT
== Status
)
1096 Microsoft Windows 2000: If GetLastError returns zero, then the function
1098 XP+ : If the function fails or times out, the return value is zero.
1099 To get extended error information, call GetLastError. If GetLastError
1100 returns ERROR_TIMEOUT, then the function timed out.
1102 SetLastWin32Error(ERROR_TIMEOUT
);
1105 else if (! NT_SUCCESS(Status
))
1107 SetLastNtError(Status
);
1114 if (Window
) UserDerefObjectCo(Window
);
1119 co_IntSendMessageTimeout( HWND hWnd
,
1125 ULONG_PTR
*uResult
)
1131 if (HWND_BROADCAST
!= hWnd
)
1133 return co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1136 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1137 if (NULL
== DesktopWindow
)
1139 SetLastWin32Error(ERROR_INTERNAL_ERROR
);
1143 /* Send message to the desktop window too! */
1144 co_IntSendMessageTimeoutSingle(DesktopWindow
->head
.h
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1146 Children
= IntWinListChildren(DesktopWindow
);
1147 if (NULL
== Children
)
1152 for (Child
= Children
; NULL
!= *Child
; Child
++)
1154 co_IntSendMessageTimeoutSingle(*Child
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1157 ExFreePool(Children
);
1159 return (LRESULT
) TRUE
;
1163 co_IntSendMessageNoWait(HWND hWnd
,
1168 ULONG_PTR Result
= 0;
1169 co_IntSendMessageWithCallBack(hWnd
,
1180 co_IntSendMessageWithCallBack( HWND hWnd
,
1184 SENDASYNCPROC CompletionCallback
,
1185 ULONG_PTR CompletionCallbackContext
,
1190 PMSGMEMORY MsgMemoryEntry
;
1191 INT lParamBufferSize
;
1192 LPARAM lParamPacked
;
1193 PTHREADINFO Win32Thread
;
1194 DECLARE_RETURN(LRESULT
);
1195 USER_REFERENCE_ENTRY Ref
;
1196 PUSER_SENT_MESSAGE Message
;
1198 if (!(Window
= UserGetWindowObject(hWnd
)))
1203 UserRefObjectCo(Window
, &Ref
);
1205 if (Window
->state
& WNDS_DESTROYED
)
1207 /* FIXME - last error? */
1208 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1212 Win32Thread
= PsGetCurrentThreadWin32Thread();
1214 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1216 if (Win32Thread
== NULL
)
1222 if (Win32Thread
->TIF_flags
& TIF_INCLEANUP
)
1224 /* Never send messages to exiting threads */
1228 /* See if this message type is present in the table */
1229 MsgMemoryEntry
= FindMsgMemory(Msg
);
1230 if (NULL
== MsgMemoryEntry
)
1232 lParamBufferSize
= -1;
1236 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1239 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
, Window
->head
.pti
->MessageQueue
!= Win32Thread
->MessageQueue
)))
1241 DPRINT1("Failed to pack message parameters\n");
1245 /* If this is not a callback and it can be sent now, then send it. */
1246 if ((Window
->head
.pti
->MessageQueue
== Win32Thread
->MessageQueue
) && (CompletionCallback
== NULL
))
1248 ObReferenceObject(Win32Thread
->pEThread
);
1249 Result
= (ULONG_PTR
)co_IntCallWindowProc( Window
->lpfnWndProc
,
1260 ObDereferenceObject(Win32Thread
->pEThread
);
1263 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1265 if ((Window
->head
.pti
->MessageQueue
== Win32Thread
->MessageQueue
) && (CompletionCallback
== NULL
))
1267 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
, FALSE
)))
1269 DPRINT1("Failed to unpack message parameters\n");
1274 if(!(Message
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(USER_SENT_MESSAGE
), TAG_USRMSG
)))
1276 DPRINT1("MsqSendMessage(): Not enough memory to allocate a message");
1277 return STATUS_INSUFFICIENT_RESOURCES
;
1280 Message
->Msg
.hwnd
= hWnd
;
1281 Message
->Msg
.message
= Msg
;
1282 Message
->Msg
.wParam
= wParam
;
1283 Message
->Msg
.lParam
= lParamPacked
;
1284 Message
->CompletionEvent
= NULL
;
1285 Message
->Result
= 0;
1286 Message
->SenderQueue
= NULL
; //Win32Thread->MessageQueue;
1288 IntReferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
1289 Message
->CompletionCallback
= CompletionCallback
;
1290 Message
->CompletionCallbackContext
= CompletionCallbackContext
;
1291 Message
->HookMessage
= MSQ_NORMAL
| MSQ_SENTNOWAIT
;
1292 Message
->HasPackedLParam
= (lParamBufferSize
> 0);
1294 InsertTailList(&Window
->head
.pti
->MessageQueue
->SentMessagesListHead
, &Message
->ListEntry
);
1295 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
1300 if (Window
) UserDerefObjectCo(Window
);
1304 /* This function posts a message if the destination's message queue belongs to
1305 another thread, otherwise it sends the message. It does not support broadcast
1308 co_IntPostOrSendMessage( HWND hWnd
,
1317 if ( hWnd
== HWND_BROADCAST
)
1322 if(!(Window
= UserGetWindowObject(hWnd
)))
1327 pti
= PsGetCurrentThreadWin32Thread();
1329 if ( Window
->head
.pti
->MessageQueue
!= pti
->MessageQueue
&&
1330 FindMsgMemory(Msg
) == 0 )
1332 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1336 if ( !co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
) )
1342 return (LRESULT
)Result
;
1346 co_IntDoSendMessage( HWND hWnd
,
1351 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1354 LRESULT Result
= TRUE
;
1357 NTUSERSENDMESSAGEINFO Info
;
1360 PMSGMEMORY MsgMemoryEntry
;
1362 RtlZeroMemory(&Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1364 /* FIXME: Call hooks. */
1365 if (HWND_BROADCAST
!= hWnd
)
1367 Window
= UserGetWindowObject(hWnd
);
1370 /* Tell usermode to not touch this one */
1371 Info
.HandledByKernel
= TRUE
;
1372 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1377 /* Check for an exiting window. */
1378 if (Window
&& Window
->state
& WNDS_DESTROYED
)
1380 DPRINT1("co_IntDoSendMessage Window Exiting!\n");
1383 /* See if the current thread can handle the message */
1384 pti
= PsGetCurrentThreadWin32Thread();
1386 // This is checked in user mode!!!!!!!
1387 if ( HWND_BROADCAST
!= hWnd
&&
1389 Window
->head
.pti
->MessageQueue
== pti
->MessageQueue
&&
1390 !ISITHOOKED(WH_CALLWNDPROC
) &&
1391 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
1392 ( Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
) )
1394 /* Gather the information usermode needs to call the window proc directly */
1395 Info
.HandledByKernel
= FALSE
;
1397 Status
= MmCopyFromCaller(&(Info
.Ansi
), &(UnsafeInfo
->Ansi
), sizeof(BOOL
));
1398 if (! NT_SUCCESS(Status
))
1400 Info
.Ansi
= ! Window
->Unicode
;
1403 Info
.Ansi
= !Window
->Unicode
;
1404 Info
.Proc
= Window
->lpfnWndProc
;
1408 /* Must be handled by other thread */
1409 // if (HWND_BROADCAST != hWnd)
1411 // UserDereferenceObject(Window);
1413 Info
.HandledByKernel
= TRUE
;
1414 UserModeMsg
.hwnd
= hWnd
;
1415 UserModeMsg
.message
= Msg
;
1416 UserModeMsg
.wParam
= wParam
;
1417 UserModeMsg
.lParam
= lParam
;
1418 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1420 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1421 if (! NT_SUCCESS(Status
))
1423 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1424 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1425 return (dsm
? 0 : -1);
1430 Result
= co_IntSendMessage( KernelModeMsg
.hwnd
,
1431 KernelModeMsg
.message
,
1432 KernelModeMsg
.wParam
,
1433 KernelModeMsg
.lParam
);
1437 Result
= co_IntSendMessageTimeout( KernelModeMsg
.hwnd
,
1438 KernelModeMsg
.message
,
1439 KernelModeMsg
.wParam
,
1440 KernelModeMsg
.lParam
,
1446 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1447 if (! NT_SUCCESS(Status
))
1449 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1450 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1451 return(dsm
? 0 : -1);
1455 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1456 if (! NT_SUCCESS(Status
))
1458 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1461 return (LRESULT
)Result
;
1466 UserSendNotifyMessage( HWND hWnd
,
1473 if (FindMsgMemory(Msg
) != 0)
1475 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1479 // Basicly the same as IntPostOrSendMessage
1480 if (hWnd
== HWND_BROADCAST
) //Handle Broadcast
1486 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1487 List
= IntWinListChildren(DesktopWindow
);
1491 UserSendNotifyMessage(DesktopWindow
->head
.h
, Msg
, wParam
, lParam
);
1492 for (i
= 0; List
[i
]; i
++)
1494 UserSendNotifyMessage(List
[i
], Msg
, wParam
, lParam
);
1505 if ( !(Window
= UserGetWindowObject(hWnd
)) ) return FALSE
;
1507 pti
= PsGetCurrentThreadWin32Thread();
1509 if (Window
->head
.pti
->MessageQueue
!= pti
->MessageQueue
)
1510 { // Send message w/o waiting for it.
1511 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1514 { // Handle message and callback.
1515 Result
= co_IntSendMessageTimeoutSingle( hWnd
,
1529 IntGetQueueStatus(DWORD Changes
)
1532 PUSER_MESSAGE_QUEUE Queue
;
1535 pti
= PsGetCurrentThreadWin32Thread();
1536 Queue
= pti
->MessageQueue
;
1538 Changes
&= (QS_ALLINPUT
|QS_ALLPOSTMESSAGE
|QS_SMRESULT
);
1540 Result
= MAKELONG(Queue
->ChangedBits
& Changes
, Queue
->QueueBits
& Changes
);
1544 pti
->pcti
->fsChangeBits
= Queue
->ChangedBits
;
1545 pti
->pcti
->fsChangeBits
&= ~Changes
;
1548 Queue
->ChangedBits
&= ~Changes
;
1554 IntInitMessagePumpHook()
1556 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
1560 pti
->pcti
->dwcPumpHook
++;
1567 IntUninitMessagePumpHook()
1569 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
1573 if (pti
->pcti
->dwcPumpHook
<= 0)
1577 pti
->pcti
->dwcPumpHook
--;
1583 /** Functions ******************************************************************/
1586 NtUserPostMessage(HWND hWnd
,
1593 UserEnterExclusive();
1595 ret
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1603 NtUserPostThreadMessage(DWORD idThread
,
1610 UserEnterExclusive();
1612 ret
= UserPostThreadMessage( idThread
, Msg
, wParam
, lParam
);
1619 ////////// API on the way out!
1621 NtUserSendMessageTimeout( HWND hWnd
,
1628 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1633 DPRINT("Enter NtUserSendMessageTimeout\n");
1635 dsm
.uFlags
= uFlags
;
1636 dsm
.uTimeout
= uTimeout
;
1638 UserEnterExclusive();
1640 Result
= co_IntDoSendMessage(hWnd
, Msg
, wParam
, lParam
, &dsm
, UnsafeInfo
);
1644 if(uResult
!= NULL
&& Result
!= 0)
1648 ProbeForWrite(uResult
, sizeof(ULONG_PTR
), 1);
1649 RtlCopyMemory(uResult
, &dsm
.Result
, sizeof(ULONG_PTR
));
1651 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1653 SetLastWin32Error(ERROR_INVALID_PARAMETER
);;
1663 NtUserSendMessage( HWND Wnd
,
1667 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1671 UserEnterExclusive();
1673 ret
= co_IntDoSendMessage(Wnd
, Msg
, wParam
, lParam
, NULL
, UnsafeInfo
);
1682 NtUserWaitMessage(VOID
)
1686 UserEnterExclusive();
1688 ret
= co_IntWaitMessage(NULL
, 0, 0);
1697 NtUserGetMessage( PNTUSERGETMESSAGEINFO UnsafeInfo
,
1702 * FUNCTION: Get a message from the calling thread's message queue.
1704 * UnsafeMsg - Pointer to the structure which receives the returned message.
1705 * Wnd - Window whose messages are to be retrieved.
1706 * MsgFilterMin - Integer value of the lowest message value to be
1708 * MsgFilterMax - Integer value of the highest message value to be
1712 NTUSERGETMESSAGEINFO Info
;
1714 PMSGMEMORY MsgMemoryEntry
;
1720 if ( (MsgFilterMin
|MsgFilterMax
) & ~WM_MAXIMUM
)
1722 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1726 UserEnterExclusive();
1728 RtlZeroMemory(&Msg
, sizeof(MSG
));
1730 GotMessage
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
, TRUE
);
1735 /* See if this message type is present in the table */
1736 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
1740 ProbeForWrite(UnsafeInfo
, sizeof(NTUSERGETMESSAGEINFO
), 1);
1741 RtlCopyMemory(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
1743 if (NULL
== MsgMemoryEntry
)
1745 /* Not present, no copying needed */
1746 UnsafeInfo
->LParamSize
= 0;
1750 /* Determine required size */
1751 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
, Info
.Msg
.lParam
);
1753 /* Allocate required amount of user-mode memory */
1754 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(),
1760 if (! NT_SUCCESS(Status
))
1762 SetLastNtError(Status
);
1763 _SEH2_YIELD(return (BOOL
) -1);
1766 /* Transfer lParam data to user-mode mem */
1767 ProbeForWrite(UserMem
, Size
, 1);
1768 RtlCopyMemory(UserMem
, (PVOID
)Info
.Msg
.lParam
, Size
);
1770 UnsafeInfo
->LParamSize
= Size
;
1771 UnsafeInfo
->Msg
.lParam
= (LPARAM
) UserMem
;
1774 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1776 SetLastNtError(_SEH2_GetExceptionCode());
1780 ZwFreeVirtualMemory(NtCurrentProcess(), &UserMem
, &Size
, MEM_RELEASE
);
1783 _SEH2_YIELD(return (BOOL
) -1);
1792 NtUserGetMessageX(PMSG pMsg
,
1800 if ( (MsgFilterMin
|MsgFilterMax
) & ~WM_MAXIMUM
)
1802 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1806 UserEnterExclusive();
1808 RtlZeroMemory(&Msg
, sizeof(MSG
));
1810 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
, TRUE
);
1818 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
1819 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
1821 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1823 SetLastNtError(_SEH2_GetExceptionCode());
1833 NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
1840 NTUSERGETMESSAGEINFO Info
;
1841 PMSGMEMORY MsgMemoryEntry
;
1842 PVOID UserMem
= NULL
;
1847 if ( RemoveMsg
& PM_BADMSGFLAGS
)
1849 SetLastWin32Error(ERROR_INVALID_FLAGS
);
1853 UserEnterExclusive();
1855 RtlZeroMemory(&Msg
, sizeof(MSG
));
1857 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
, FALSE
);
1864 /* See if this message type is present in the table */
1865 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
1869 ProbeForWrite(UnsafeInfo
, sizeof(NTUSERGETMESSAGEINFO
), 1);
1870 RtlCopyMemory(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
1872 if (NULL
== MsgMemoryEntry
)
1874 /* Not present, no copying needed */
1875 UnsafeInfo
->LParamSize
= 0;
1879 /* Determine required size */
1880 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
, Info
.Msg
.lParam
);
1882 /* Allocate required amount of user-mode memory */
1883 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(),
1889 if (! NT_SUCCESS(Status
))
1891 SetLastNtError(Status
);
1892 _SEH2_YIELD(return (BOOL
) -1);
1895 /* Transfer lParam data to user-mode mem */
1896 ProbeForWrite(UserMem
, Size
, 1);
1897 RtlCopyMemory(UserMem
, (PVOID
)Info
.Msg
.lParam
, Size
);
1899 UnsafeInfo
->LParamSize
= Size
;
1900 UnsafeInfo
->Msg
.lParam
= (LPARAM
) UserMem
;
1903 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1905 SetLastNtError(_SEH2_GetExceptionCode());
1910 ZwFreeVirtualMemory(NtCurrentProcess(), &UserMem
, &Size
, MEM_RELEASE
);
1920 NtUserPeekMessageX( PMSG pMsg
,
1929 if ( RemoveMsg
& PM_BADMSGFLAGS
)
1931 SetLastWin32Error(ERROR_INVALID_FLAGS
);
1935 UserEnterExclusive();
1937 RtlZeroMemory(&Msg
, sizeof(MSG
));
1939 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
, FALSE
);
1947 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
1948 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
1950 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1952 SetLastNtError(_SEH2_GetExceptionCode());
1962 NtUserCallMsgFilter( LPMSG lpmsg
, INT code
)
1969 ProbeForRead(lpmsg
, sizeof(MSG
), 1);
1970 RtlCopyMemory( &Msg
, lpmsg
, sizeof(MSG
));
1972 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1974 _SEH2_YIELD(return FALSE
);
1978 UserEnterExclusive();
1980 if ( co_HOOK_CallHooks( WH_SYSMSGFILTER
, code
, 0, (LPARAM
)&Msg
))
1986 Ret
= co_HOOK_CallHooks( WH_MSGFILTER
, code
, 0, (LPARAM
)&Msg
);
1993 ProbeForWrite(lpmsg
, sizeof(MSG
), 1);
1994 RtlCopyMemory(lpmsg
, &Msg
, sizeof(MSG
));
1996 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2006 NtUserDispatchMessage(PMSG UnsafeMsgInfo
)
2013 ProbeForRead(UnsafeMsgInfo
, sizeof(MSG
), 1);
2014 RtlCopyMemory(&SafeMsg
, UnsafeMsgInfo
, sizeof(MSG
));
2016 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2018 SetLastNtError(_SEH2_GetExceptionCode());
2019 _SEH2_YIELD(return FALSE
);
2023 UserEnterExclusive();
2025 Res
= IntDispatchMessage(&SafeMsg
);
2033 NtUserTranslateMessage(LPMSG lpMsg
, UINT flags
)
2040 ProbeForRead(lpMsg
, sizeof(MSG
), 1);
2041 RtlCopyMemory(&SafeMsg
, lpMsg
, sizeof(MSG
));
2043 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2045 SetLastNtError(_SEH2_GetExceptionCode());
2046 _SEH2_YIELD(return FALSE
);
2050 UserEnterExclusive();
2052 Ret
= IntTranslateKbdMessage(&SafeMsg
, flags
);
2060 NtUserMessageCall( HWND hWnd
,
2064 ULONG_PTR ResultInfo
,
2065 DWORD dwType
, // fnID?
2068 LRESULT lResult
= 0;
2071 USER_REFERENCE_ENTRY Ref
;
2073 UserEnterExclusive();
2075 /* Validate input */
2076 if (hWnd
&& (hWnd
!= INVALID_HANDLE_VALUE
))
2078 Window
= UserGetWindowObject(hWnd
);
2088 case FNID_DEFWINDOWPROC
:
2089 if (Window
) UserRefObjectCo(Window
, &Ref
);
2090 lResult
= IntDefWindowProc(Window
, Msg
, wParam
, lParam
, Ansi
);
2092 if (Window
) UserDerefObjectCo(Window
);
2094 case FNID_SENDNOTIFYMESSAGE
:
2095 Ret
= UserSendNotifyMessage(hWnd
, Msg
, wParam
, lParam
);
2097 case FNID_BROADCASTSYSTEMMESSAGE
:
2100 DWORD_PTR RetVal
= 0;
2106 ProbeForWrite((PVOID
)ResultInfo
, sizeof(BROADCASTPARM
), 1);
2107 RtlCopyMemory(&parm
, (PVOID
)ResultInfo
, sizeof(BROADCASTPARM
));
2109 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2119 if ( parm
.recipients
& BSM_ALLDESKTOPS
||
2120 parm
.recipients
== BSM_ALLCOMPONENTS
)
2123 else if (parm
.recipients
& BSM_APPLICATIONS
)
2125 if (parm
.flags
& BSF_QUERY
)
2127 if (parm
.flags
& BSF_FORCEIFHUNG
|| parm
.flags
& BSF_NOHANG
)
2129 co_IntSendMessageTimeout( HWND_BROADCAST
,
2137 else if (parm
.flags
& BSF_NOTIMEOUTIFNOTHUNG
)
2139 co_IntSendMessageTimeout( HWND_BROADCAST
,
2143 SMTO_NOTIMEOUTIFNOTHUNG
,
2149 co_IntSendMessageTimeout( HWND_BROADCAST
,
2159 else if (parm
.flags
& BSF_POSTMESSAGE
)
2161 Ret
= UserPostMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2163 else //Everything else,,,, if ( parm.flags & BSF_SENDNOTIFYMESSAGE)
2165 Ret
= UserSendNotifyMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2170 case FNID_SENDMESSAGECALLBACK
:
2172 PCALL_BACK_INFO CallBackInfo
= (PCALL_BACK_INFO
)ResultInfo
;
2178 if (!co_IntSendMessageWithCallBack(hWnd
, Msg
, wParam
, lParam
,
2179 CallBackInfo
->CallBack
, CallBackInfo
->Context
, &uResult
))
2181 DPRINT1("Callback failure!\n");
2185 // CallNextHook bypass.
2186 case FNID_CALLWNDPROC
:
2187 case FNID_CALLWNDPROCRET
:
2190 PCLIENTINFO ClientInfo
;
2191 PHOOK NextObj
, Hook
;
2193 pti
= GetW32ThreadInfo();
2195 Hook
= pti
->sphkCurrent
;
2199 NextObj
= Hook
->phkNext
;
2200 ClientInfo
= pti
->pClientInfo
;
2203 ClientInfo
->phkCurrent
= NextObj
;
2205 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2211 if (!ClientInfo
|| !NextObj
) break;
2213 NextObj
->phkNext
= IntGetNextHook(NextObj
);
2215 if ( Hook
->HookId
== WH_CALLWNDPROC
)
2220 CWP
.wParam
= wParam
;
2221 CWP
.lParam
= lParam
;
2222 DPRINT("WH_CALLWNDPROC: Hook %x NextHook %x\n", Hook
, NextObj
);
2224 lResult
= co_IntCallHookProc( Hook
->HookId
,
2226 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2237 CWPR
.wParam
= wParam
;
2238 CWPR
.lParam
= lParam
;
2239 CWPR
.lResult
= ClientInfo
->dwHookData
;
2241 lResult
= co_IntCallHookProc( Hook
->HookId
,
2243 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2255 case FNID_DEFWINDOWPROC
:
2256 case FNID_CALLWNDPROC
:
2257 case FNID_CALLWNDPROCRET
:
2262 ProbeForWrite((PVOID
)ResultInfo
, sizeof(LRESULT
), 1);
2263 RtlCopyMemory((PVOID
)ResultInfo
, &lResult
, sizeof(LRESULT
));
2265 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2281 #define INFINITE 0xFFFFFFFF
2282 #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
2286 NtUserWaitForInputIdle( IN HANDLE hProcess
,
2287 IN DWORD dwMilliseconds
,
2291 PPROCESSINFO W32Process
;
2295 LARGE_INTEGER Timeout
;
2297 UserEnterExclusive();
2299 Status
= ObReferenceObjectByHandle(hProcess
,
2300 PROCESS_QUERY_INFORMATION
,
2306 if (!NT_SUCCESS(Status
))
2309 SetLastNtError(Status
);
2313 pti
= PsGetCurrentThreadWin32Thread();
2315 W32Process
= (PPROCESSINFO
)Process
->Win32Process
;
2317 if ( PsGetProcessExitProcessCalled(Process
) ||
2319 pti
->ppi
== W32Process
)
2321 ObDereferenceObject(Process
);
2323 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2327 Handles
[0] = Process
;
2328 Handles
[1] = W32Process
->InputIdleEvent
;
2329 Handles
[2] = pti
->MessageQueue
->NewMessages
; // pEventQueueServer; IntMsqSetWakeMask returns hEventQueueClient
2333 ObDereferenceObject(Process
);
2335 return STATUS_SUCCESS
; /* no event to wait on */
2338 if (dwMilliseconds
!= INFINITE
)
2339 Timeout
.QuadPart
= (LONGLONG
) dwMilliseconds
* (LONGLONG
) -10000;
2341 DPRINT("WFII: ppi 0x%x\n",W32Process
);
2342 DPRINT("WFII: waiting for %p\n", Handles
[1] );
2346 Status
= KeWaitForMultipleObjects( 3,
2352 dwMilliseconds
== INFINITE
? NULL
: &Timeout
,
2354 UserEnterExclusive();
2356 if (!NT_SUCCESS(Status
))
2358 SetLastNtError(Status
);
2359 Status
= WAIT_FAILED
;
2371 co_IntPeekMessage( &Msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2372 DPRINT1("WFII: WAIT 2\n");
2376 case STATUS_TIMEOUT
:
2377 DPRINT1("WFII: timeout\n");
2382 DPRINT1("WFII: finished\n");
2383 Status
= STATUS_SUCCESS
;
2390 ObDereferenceObject(Process
);