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 #define PM_BADMSGFLAGS ~((QS_RAWINPUT << 16)|PM_QS_SENDMESSAGE|PM_QS_PAINT|PM_QS_POSTMESSAGE|PM_QS_INPUT|PM_NOYIELD|PM_REMOVE)
26 DOSENDMESSAGE
, *PDOSENDMESSAGE
;
28 /* FUNCTIONS *****************************************************************/
31 IntInitMessageImpl(VOID
)
33 return STATUS_SUCCESS
;
37 IntCleanupMessageImpl(VOID
)
39 return STATUS_SUCCESS
;
42 #define MMS_SIZE_WPARAM -1
43 #define MMS_SIZE_WPARAMWCHAR -2
44 #define MMS_SIZE_LPARAMSZ -3
45 #define MMS_SIZE_SPECIAL -4
46 #define MMS_FLAG_READ 0x01
47 #define MMS_FLAG_WRITE 0x02
48 #define MMS_FLAG_READWRITE (MMS_FLAG_READ | MMS_FLAG_WRITE)
49 typedef struct tagMSGMEMORY
55 MSGMEMORY
, *PMSGMEMORY
;
57 static MSGMEMORY MsgMemory
[] =
59 { WM_CREATE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
60 { WM_DDE_ACK
, sizeof(KMDDELPARAM
), MMS_FLAG_READ
},
61 { WM_DDE_EXECUTE
, MMS_SIZE_WPARAM
, MMS_FLAG_READ
},
62 { WM_GETMINMAXINFO
, sizeof(MINMAXINFO
), MMS_FLAG_READWRITE
},
63 { WM_GETTEXT
, MMS_SIZE_WPARAMWCHAR
, MMS_FLAG_WRITE
},
64 { WM_NCCALCSIZE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
65 { WM_NCCREATE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
66 { WM_SETTEXT
, MMS_SIZE_LPARAMSZ
, MMS_FLAG_READ
},
67 { WM_STYLECHANGED
, sizeof(STYLESTRUCT
), MMS_FLAG_READ
},
68 { WM_STYLECHANGING
, sizeof(STYLESTRUCT
), MMS_FLAG_READWRITE
},
69 { WM_COPYDATA
, MMS_SIZE_SPECIAL
, MMS_FLAG_READ
},
70 { WM_WINDOWPOSCHANGED
, sizeof(WINDOWPOS
), MMS_FLAG_READ
},
71 { WM_WINDOWPOSCHANGING
, sizeof(WINDOWPOS
), MMS_FLAG_READWRITE
},
74 static PMSGMEMORY FASTCALL
75 FindMsgMemory(UINT Msg
)
77 PMSGMEMORY MsgMemoryEntry
;
79 /* See if this message type is present in the table */
80 for (MsgMemoryEntry
= MsgMemory
;
81 MsgMemoryEntry
< MsgMemory
+ sizeof(MsgMemory
) / sizeof(MSGMEMORY
);
84 if (Msg
== MsgMemoryEntry
->Message
)
86 return MsgMemoryEntry
;
94 MsgMemorySize(PMSGMEMORY MsgMemoryEntry
, WPARAM wParam
, LPARAM lParam
)
97 PUNICODE_STRING WindowName
;
98 PUNICODE_STRING ClassName
;
103 if (MMS_SIZE_WPARAM
== MsgMemoryEntry
->Size
)
107 else if (MMS_SIZE_WPARAMWCHAR
== MsgMemoryEntry
->Size
)
109 Size
= (UINT
) (wParam
* sizeof(WCHAR
));
111 else if (MMS_SIZE_LPARAMSZ
== MsgMemoryEntry
->Size
)
113 Size
= (UINT
) ((wcslen((PWSTR
) lParam
) + 1) * sizeof(WCHAR
));
115 else if (MMS_SIZE_SPECIAL
== MsgMemoryEntry
->Size
)
117 switch(MsgMemoryEntry
->Message
)
121 Cs
= (CREATESTRUCTW
*) lParam
;
122 WindowName
= (PUNICODE_STRING
) Cs
->lpszName
;
123 ClassName
= (PUNICODE_STRING
) Cs
->lpszClass
;
124 Size
= sizeof(CREATESTRUCTW
) + WindowName
->Length
+ sizeof(WCHAR
);
125 if (IS_ATOM(ClassName
->Buffer
))
127 Size
+= sizeof(WCHAR
) + sizeof(ATOM
);
131 Size
+= sizeof(WCHAR
) + ClassName
->Length
+ sizeof(WCHAR
);
136 Size
= wParam
? sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
) : sizeof(RECT
);
140 Size
= sizeof(COPYDATASTRUCT
) + ((PCOPYDATASTRUCT
)lParam
)->cbData
;
143 case WM_COPYGLOBALDATA
:
155 Size
= MsgMemoryEntry
->Size
;
158 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
160 DPRINT1("Exception caught in MsgMemorySize()! Status: 0x%x\n", _SEH2_GetExceptionCode());
168 PackParam(LPARAM
*lParamPacked
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, BOOL NonPagedPoolNeeded
)
170 NCCALCSIZE_PARAMS
*UnpackedNcCalcsize
;
171 NCCALCSIZE_PARAMS
*PackedNcCalcsize
;
172 CREATESTRUCTW
*UnpackedCs
;
173 CREATESTRUCTW
*PackedCs
;
174 PLARGE_STRING WindowName
;
175 PUNICODE_STRING ClassName
;
180 *lParamPacked
= lParam
;
182 if (NonPagedPoolNeeded
)
183 PoolType
= NonPagedPool
;
185 PoolType
= PagedPool
;
187 if (WM_NCCALCSIZE
== Msg
&& wParam
)
190 UnpackedNcCalcsize
= (NCCALCSIZE_PARAMS
*) lParam
;
191 PackedNcCalcsize
= ExAllocatePoolWithTag(PoolType
,
192 sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
),
195 if (NULL
== PackedNcCalcsize
)
197 DPRINT1("Not enough memory to pack lParam\n");
198 return STATUS_NO_MEMORY
;
200 RtlCopyMemory(PackedNcCalcsize
, UnpackedNcCalcsize
, sizeof(NCCALCSIZE_PARAMS
));
201 PackedNcCalcsize
->lppos
= (PWINDOWPOS
) (PackedNcCalcsize
+ 1);
202 RtlCopyMemory(PackedNcCalcsize
->lppos
, UnpackedNcCalcsize
->lppos
, sizeof(WINDOWPOS
));
203 *lParamPacked
= (LPARAM
) PackedNcCalcsize
;
205 else if (WM_CREATE
== Msg
|| WM_NCCREATE
== Msg
)
207 UnpackedCs
= (CREATESTRUCTW
*) lParam
;
208 WindowName
= (PLARGE_STRING
) UnpackedCs
->lpszName
;
209 ClassName
= (PUNICODE_STRING
) UnpackedCs
->lpszClass
;
210 Size
= sizeof(CREATESTRUCTW
) + WindowName
->Length
+ sizeof(WCHAR
);
211 if (IS_ATOM(ClassName
->Buffer
))
213 Size
+= sizeof(WCHAR
) + sizeof(ATOM
);
217 Size
+= sizeof(WCHAR
) + ClassName
->Length
+ sizeof(WCHAR
);
219 PackedCs
= ExAllocatePoolWithTag(PoolType
, Size
, TAG_MSG
);
220 if (NULL
== PackedCs
)
222 DPRINT1("Not enough memory to pack lParam\n");
223 return STATUS_NO_MEMORY
;
225 RtlCopyMemory(PackedCs
, UnpackedCs
, sizeof(CREATESTRUCTW
));
226 CsData
= (PCHAR
) (PackedCs
+ 1);
227 PackedCs
->lpszName
= (LPCWSTR
) (CsData
- (PCHAR
) PackedCs
);
228 RtlCopyMemory(CsData
, WindowName
->Buffer
, WindowName
->Length
);
229 CsData
+= WindowName
->Length
;
230 *((WCHAR
*) CsData
) = L
'\0';
231 CsData
+= sizeof(WCHAR
);
232 PackedCs
->lpszClass
= (LPCWSTR
) (CsData
- (PCHAR
) PackedCs
);
233 if (IS_ATOM(ClassName
->Buffer
))
235 *((WCHAR
*) CsData
) = L
'A';
236 CsData
+= sizeof(WCHAR
);
237 *((ATOM
*) CsData
) = (ATOM
)(DWORD_PTR
) ClassName
->Buffer
;
238 CsData
+= sizeof(ATOM
);
242 *((WCHAR
*) CsData
) = L
'S';
243 CsData
+= sizeof(WCHAR
);
244 RtlCopyMemory(CsData
, ClassName
->Buffer
, ClassName
->Length
);
245 CsData
+= ClassName
->Length
;
246 *((WCHAR
*) CsData
) = L
'\0';
247 CsData
+= sizeof(WCHAR
);
249 ASSERT(CsData
== (PCHAR
) PackedCs
+ Size
);
250 *lParamPacked
= (LPARAM
) PackedCs
;
253 else if (PoolType
== NonPagedPool
)
255 PMSGMEMORY MsgMemoryEntry
;
258 MsgMemoryEntry
= FindMsgMemory(Msg
);
260 if ((!MsgMemoryEntry
) || (MsgMemoryEntry
->Size
< 0))
262 /* Keep previous behavior */
263 return STATUS_SUCCESS
;
265 PackedData
= ExAllocatePoolWithTag(NonPagedPool
, MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
), TAG_MSG
);
266 RtlCopyMemory(PackedData
, (PVOID
)lParam
, MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
));
267 *lParamPacked
= (LPARAM
)PackedData
;
270 return STATUS_SUCCESS
;
274 UnpackParam(LPARAM lParamPacked
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, BOOL NonPagedPoolUsed
)
276 NCCALCSIZE_PARAMS
*UnpackedParams
;
277 NCCALCSIZE_PARAMS
*PackedParams
;
278 PWINDOWPOS UnpackedWindowPos
;
280 if (lParamPacked
== lParam
)
282 return STATUS_SUCCESS
;
285 if (WM_NCCALCSIZE
== Msg
&& wParam
)
287 PackedParams
= (NCCALCSIZE_PARAMS
*) lParamPacked
;
288 UnpackedParams
= (NCCALCSIZE_PARAMS
*) lParam
;
289 UnpackedWindowPos
= UnpackedParams
->lppos
;
290 RtlCopyMemory(UnpackedParams
, PackedParams
, sizeof(NCCALCSIZE_PARAMS
));
291 UnpackedParams
->lppos
= UnpackedWindowPos
;
292 RtlCopyMemory(UnpackedWindowPos
, PackedParams
+ 1, sizeof(WINDOWPOS
));
293 ExFreePool((PVOID
) lParamPacked
);
295 return STATUS_SUCCESS
;
297 else if (WM_CREATE
== Msg
|| WM_NCCREATE
== Msg
)
299 ExFreePool((PVOID
) lParamPacked
);
301 return STATUS_SUCCESS
;
303 else if (NonPagedPoolUsed
)
305 PMSGMEMORY MsgMemoryEntry
;
306 MsgMemoryEntry
= FindMsgMemory(Msg
);
307 if (MsgMemoryEntry
->Size
< 0)
309 /* Keep previous behavior */
310 return STATUS_INVALID_PARAMETER
;
313 if (MsgMemory
->Flags
== MMS_FLAG_READWRITE
)
315 //RtlCopyMemory((PVOID)lParam, (PVOID)lParamPacked, MsgMemory->Size);
317 ExFreePool((PVOID
) lParamPacked
);
318 return STATUS_SUCCESS
;
323 return STATUS_INVALID_PARAMETER
;
330 ( PWND Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
332 BOOL SameThread
= FALSE
;
335 if (Window
->head
.pti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
342 co_HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, SameThread
, (LPARAM
)&CWP
);
349 ( PWND Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*uResult
)
351 BOOL SameThread
= FALSE
;
354 if (Window
->head
.pti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
359 CWPR
.wParam
= wParam
;
360 CWPR
.lParam
= lParam
;
361 CWPR
.lResult
= *uResult
;
362 co_HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, SameThread
, (LPARAM
)&CWPR
);
367 IntDispatchMessage(PMSG pMsg
)
369 LARGE_INTEGER TickCount
;
372 PMSGMEMORY MsgMemoryEntry
;
373 INT lParamBufferSize
;
380 Window
= UserGetWindowObject(pMsg
->hwnd
);
381 if (!Window
) return 0;
384 pti
= PsGetCurrentThreadWin32Thread();
386 if (((pMsg
->message
== WM_SYSTIMER
) ||
387 (pMsg
->message
== WM_TIMER
)) &&
390 if (pMsg
->message
== WM_TIMER
)
392 ObReferenceObject(pti
->pEThread
);
393 if (ValidateTimerCallback(pti
,pMsg
->lParam
))
395 KeQueryTickCount(&TickCount
);
396 Time
= MsqCalculateMessageTime(&TickCount
);
397 retval
= co_IntCallWindowProc((WNDPROC
)pMsg
->lParam
,
405 ObDereferenceObject(pti
->pEThread
);
410 PTIMER pTimer
= FindSystemTimer(pMsg
);
411 if (pTimer
&& pTimer
->pfn
)
413 KeQueryTickCount(&TickCount
);
414 Time
= MsqCalculateMessageTime(&TickCount
);
415 pTimer
->pfn(pMsg
->hwnd
, WM_SYSTIMER
, (UINT
)pMsg
->wParam
, Time
);
421 if ( !Window
) return 0;
423 /* See if this message type is present in the table */
424 MsgMemoryEntry
= FindMsgMemory(pMsg
->message
);
425 if ( !MsgMemoryEntry
)
427 lParamBufferSize
= -1;
431 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, pMsg
->wParam
, pMsg
->lParam
);
434 if (! NT_SUCCESS(PackParam(&lParamPacked
, pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
, FALSE
)))
436 DPRINT1("Failed to pack message parameters\n");
439 ObReferenceObject(pti
->pEThread
);
440 retval
= co_IntCallWindowProc( Window
->lpfnWndProc
,
448 if (! NT_SUCCESS(UnpackParam(lParamPacked
, pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
, FALSE
)))
450 DPRINT1("Failed to unpack message parameters\n");
453 if (pMsg
->message
== WM_PAINT
)
455 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
456 HRGN hrgn
= IntSysCreateRectRgn( 0, 0, 0, 0 );
457 co_UserGetUpdateRgn( Window
, hrgn
, TRUE
);
458 REGION_FreeRgnByHandle( hrgn
);
460 ObDereferenceObject(pti
->pEThread
);
465 co_IntSendHitTestMessages(PUSER_MESSAGE_QUEUE ThreadQueue
, LPMSG Msg
)
467 if(!Msg
->hwnd
|| ThreadQueue
->CaptureWindow
)
476 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
481 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
488 case WM_LBUTTONDBLCLK
:
489 case WM_MBUTTONDBLCLK
:
490 case WM_RBUTTONDBLCLK
:
491 case WM_XBUTTONDBLCLK
:
494 PSYSTEM_CURSORINFO CurInfo
;
495 CurInfo
= IntGetSysCursorInfo();
497 wParam
= (WPARAM
)(CurInfo
->ButtonsDown
);
499 co_IntSendMessage(Msg
->hwnd
, WM_MOUSEMOVE
, wParam
, Msg
->lParam
);
500 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
503 case WM_NCLBUTTONDOWN
:
504 case WM_NCMBUTTONDOWN
:
505 case WM_NCRBUTTONDOWN
:
506 case WM_NCXBUTTONDOWN
:
507 case WM_NCLBUTTONDBLCLK
:
508 case WM_NCMBUTTONDBLCLK
:
509 case WM_NCRBUTTONDBLCLK
:
510 case WM_NCXBUTTONDBLCLK
:
512 co_IntSendMessage(Msg
->hwnd
, WM_NCMOUSEMOVE
, (WPARAM
)Msg
->wParam
, Msg
->lParam
);
513 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
520 co_IntActivateWindowMouse(
521 PUSER_MESSAGE_QUEUE ThreadQueue
,
529 ASSERT_REFS_CO(MsgWindow
);
531 if(*HitTest
== (USHORT
)HTTRANSPARENT
)
533 /* eat the message, search again! */
537 Parent
= IntGetParent(MsgWindow
);//fixme: deref retval?
539 /* If no parent window, pass MsgWindows HWND as wParam. Fixes bug #3111 */
540 Result
= co_IntSendMessage(MsgWindow
->head
.h
,
542 (WPARAM
) (Parent
? Parent
->head
.h
: MsgWindow
->head
.h
),
543 (LPARAM
)MAKELONG(*HitTest
, Msg
->message
)
548 case MA_NOACTIVATEANDEAT
:
552 case MA_ACTIVATEANDEAT
:
553 co_IntMouseActivateWindow(MsgWindow
);
557 co_IntMouseActivateWindow(MsgWindow
);
565 co_IntTranslateMouseMessage(
566 PUSER_MESSAGE_QUEUE ThreadQueue
,
572 USER_REFERENCE_ENTRY Ref
, DesktopRef
;
574 if(!(Window
= UserGetWindowObject(Msg
->hwnd
)))
576 /* let's just eat the message?! */
582 UserRefObjectCo(Window
, &Ref
);
584 if ( ThreadQueue
== Window
->head
.pti
->MessageQueue
&&
585 ThreadQueue
->CaptureWindow
!= Window
->head
.h
)
587 /* only send WM_NCHITTEST messages if we're not capturing the window! */
590 *HitTest
= co_IntSendMessage(Window
->head
.h
, WM_NCHITTEST
, 0,
591 MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
));
593 /* else we are going to see this message again, but then with Remove == TRUE */
595 if (*HitTest
== (USHORT
)HTTRANSPARENT
)
598 HWND hDesktop
= IntGetDesktopWindow();
600 if ((DesktopWindow
= UserGetWindowObject(hDesktop
)))
604 UserRefObjectCo(DesktopWindow
, &DesktopRef
);
606 co_WinPosWindowFromPoint(DesktopWindow
, Window
->head
.pti
->MessageQueue
, &Msg
->pt
, &Wnd
);
611 /* post the message to the other window */
612 Msg
->hwnd
= Wnd
->head
.h
;
613 if(!(Wnd
->state
& WNDS_DESTROYED
))
615 MsqPostMessage(Wnd
->head
.pti
->MessageQueue
, Msg
, FALSE
,
616 Msg
->message
== WM_MOUSEMOVE
? QS_MOUSEMOVE
:
620 /* eat the message */
621 UserDereferenceObject(Wnd
);
622 UserDerefObjectCo(DesktopWindow
);
623 UserDerefObjectCo(Window
);
626 UserDereferenceObject(Wnd
);
629 UserDerefObjectCo(DesktopWindow
);
634 if ( gspv
.bMouseClickLock
&&
635 ( (Msg
->message
== WM_LBUTTONUP
) ||
636 (Msg
->message
== WM_LBUTTONDOWN
) ) )
638 if (MsqIsClkLck(Msg
, Remove
))
640 // FIXME: drop the message, hack: use WM_NULL
641 Msg
->message
= WM_NULL
;
645 if (IS_BTN_MESSAGE(Msg
->message
, DOWN
))
647 /* generate double click messages, if necessary */
648 if ((((*HitTest
) != HTCLIENT
) ||
649 (Window
->pcls
->style
& CS_DBLCLKS
)) &&
650 MsqIsDblClk(Msg
, Remove
))
652 Msg
->message
+= WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
;
656 if(Msg
->message
!= WM_MOUSEWHEEL
)
659 if ((*HitTest
) != HTCLIENT
)
661 Msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
662 if ( (Msg
->message
== WM_NCRBUTTONUP
) &&
663 (((*HitTest
) == HTCAPTION
) || ((*HitTest
) == HTSYSMENU
)) )
665 Msg
->message
= WM_CONTEXTMENU
;
666 Msg
->wParam
= (WPARAM
)Window
->head
.h
;
670 Msg
->wParam
= *HitTest
;
672 Msg
->lParam
= MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
);
674 else if ( ThreadQueue
->MoveSize
== NULL
&&
675 ThreadQueue
->MenuOwner
== NULL
)
677 /* NOTE: Msg->pt should remain in screen coordinates. -- FiN */
678 Msg
->lParam
= MAKELONG(
679 Msg
->pt
.x
- (WORD
)Window
->rcClient
.left
,
680 Msg
->pt
.y
- (WORD
)Window
->rcClient
.top
);
684 UserDerefObjectCo(Window
);
688 BOOL
ProcessMouseMessage(MSG
* Msg
, BOOLEAN RemoveMessages
)
690 MOUSEHOOKSTRUCT MHook
;
693 PUSER_MESSAGE_QUEUE ThreadQueue
;
694 USER_REFERENCE_ENTRY Ref
;
695 USHORT HitTest
= HTNOWHERE
;
697 pti
= PsGetCurrentThreadWin32Thread();
698 ThreadQueue
= pti
->MessageQueue
;
702 PWND MsgWindow
= NULL
;
704 /* Mouse message process */
707 ( MsgWindow
= UserGetWindowObject(Msg
->hwnd
) ) &&
708 Msg
->message
>= WM_MOUSEFIRST
&&
709 Msg
->message
<= WM_MOUSELAST
)
713 UserRefObjectCo(MsgWindow
, &Ref
);
715 if ( co_IntTranslateMouseMessage( ThreadQueue
,
719 /* FIXME - check message filter again, if the message doesn't match anymore,
722 UserDerefObjectCo(MsgWindow
);
723 /* eat the message, search again */
727 if(ThreadQueue
->CaptureWindow
== NULL
)
729 co_IntSendHitTestMessages(ThreadQueue
, Msg
);
731 if ( ( Msg
->message
!= WM_MOUSEMOVE
&&
732 Msg
->message
!= WM_NCMOUSEMOVE
) &&
733 IS_BTN_MESSAGE(Msg
->message
, DOWN
) &&
734 co_IntActivateWindowMouse(ThreadQueue
, Msg
, MsgWindow
, &HitTest
) )
736 UserDerefObjectCo(MsgWindow
);
737 /* eat the message, search again */
742 UserDerefObjectCo(MsgWindow
);
746 co_IntSendHitTestMessages(ThreadQueue
, Msg
);
753 Msg
->message
>= WM_MOUSEFIRST
&&
754 Msg
->message
<= WM_MOUSELAST
) &&
755 co_IntTranslateMouseMessage( ThreadQueue
,
759 /* FIXME - check message filter again, if the message doesn't match anymore,
762 /* eat the message, search again */
766 pti
->rpdesk
->htEx
= HitTest
; /* Now set the capture hit. */
768 Event
.message
= Msg
->message
;
769 Event
.time
= Msg
->time
;
770 Event
.hwnd
= Msg
->hwnd
;
771 Event
.paramL
= Msg
->pt
.x
;
772 Event
.paramH
= Msg
->pt
.y
;
773 co_HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&Event
);
777 MHook
.hwnd
= Msg
->hwnd
;
778 MHook
.wHitTestCode
= HitTest
;
779 MHook
.dwExtraInfo
= 0;
780 if (co_HOOK_CallHooks( WH_MOUSE
,
781 RemoveMessages
? HC_ACTION
: HC_NOREMOVE
,
786 MHook
.hwnd
= Msg
->hwnd
;
787 MHook
.wHitTestCode
= HitTest
;
788 MHook
.dwExtraInfo
= 0;
789 co_HOOK_CallHooks( WH_CBT
,
793 DPRINT1("MouseMessage WH_CBT Call Hook return!\n");
800 BOOL
ProcessKeyboardMessage(MSG
* Msg
, BOOLEAN RemoveMessages
)
804 Event
.message
= Msg
->message
;
805 Event
.hwnd
= Msg
->hwnd
;
806 Event
.time
= Msg
->time
;
807 Event
.paramL
= (Msg
->wParam
& 0xFF) | (HIWORD(Msg
->lParam
) << 8);
808 Event
.paramH
= Msg
->lParam
& 0x7FFF;
809 if (HIWORD(Msg
->lParam
) & 0x0100) Event
.paramH
|= 0x8000;
810 co_HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&Event
);
812 if (co_HOOK_CallHooks( WH_KEYBOARD
,
813 RemoveMessages
? HC_ACTION
: HC_NOREMOVE
,
817 /* skip this message */
818 co_HOOK_CallHooks( WH_CBT
,
822 DPRINT1("KeyboardMessage WH_CBT Call Hook return!\n");
828 BOOL
ProcessHardwareMessage(MSG
* Msg
, BOOLEAN RemoveMessages
)
830 if ( IS_MOUSE_MESSAGE(Msg
->message
))
832 if (!ProcessMouseMessage(Msg
, RemoveMessages
))
837 else if ( IS_KBD_MESSAGE(Msg
->message
))
839 if(!ProcessKeyboardMessage(Msg
, RemoveMessages
))
848 * Internal version of PeekMessage() doing all the work
851 co_IntPeekMessage( PUSER_MESSAGE Msg
,
858 LARGE_INTEGER LargeTickCount
;
859 PUSER_MESSAGE_QUEUE ThreadQueue
;
860 PUSER_MESSAGE Message
;
863 pti
= PsGetCurrentThreadWin32Thread();
864 ThreadQueue
= pti
->MessageQueue
;
866 RemoveMessages
= RemoveMsg
& PM_REMOVE
;
870 KeQueryTickCount(&LargeTickCount
);
871 ThreadQueue
->LastMsgRead
= LargeTickCount
.u
.LowPart
;
873 /* Dispatch sent messages here. */
874 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
877 /* Now look for a quit message. */
879 if (ThreadQueue
->QuitPosted
)
881 /* According to the PSDK, WM_QUIT messages are always returned, regardless
882 of the filter specified */
883 Msg
->Msg
.hwnd
= NULL
;
884 Msg
->Msg
.message
= WM_QUIT
;
885 Msg
->Msg
.wParam
= ThreadQueue
->QuitExitCode
;
889 ThreadQueue
->QuitPosted
= FALSE
;
895 /* Now check for normal messages. */
896 if (co_MsqFindMessage( ThreadQueue
,
904 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
907 MsqDestroyMessage(Message
);
912 /* Check for hardware events. */
913 if(co_MsqFindMessage( ThreadQueue
,
921 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
924 MsqDestroyMessage(Message
);
927 if(!ProcessHardwareMessage(&Msg
->Msg
, RemoveMessages
))
933 /* Check for sent messages again. */
934 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
937 /* Check for paint messages. */
938 if( IntGetPaintMessage( Window
,
948 if (PostTimerMessages(Window
))
957 // The WH_GETMESSAGE hook enables an application to monitor messages about to
958 // be returned by the GetMessage or PeekMessage function.
960 co_HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, RemoveMsg
& PM_REMOVE
, (LPARAM
)&Msg
->Msg
);
964 static NTSTATUS FASTCALL
965 CopyMsgToKernelMem(MSG
*KernelModeMsg
, MSG
*UserModeMsg
, PMSGMEMORY MsgMemoryEntry
)
972 *KernelModeMsg
= *UserModeMsg
;
974 /* See if this message type is present in the table */
975 if (NULL
== MsgMemoryEntry
)
977 /* Not present, no copying needed */
978 return STATUS_SUCCESS
;
981 /* Determine required size */
982 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
986 /* Allocate kernel mem */
987 KernelMem
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
988 if (NULL
== KernelMem
)
990 DPRINT1("Not enough memory to copy message to kernel mem\n");
991 return STATUS_NO_MEMORY
;
993 KernelModeMsg
->lParam
= (LPARAM
) KernelMem
;
995 /* Copy data if required */
996 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_READ
))
998 Status
= MmCopyFromCaller(KernelMem
, (PVOID
) UserModeMsg
->lParam
, Size
);
999 if (! NT_SUCCESS(Status
))
1001 DPRINT1("Failed to copy message to kernel: invalid usermode buffer\n");
1002 ExFreePoolWithTag(KernelMem
, TAG_MSG
);
1008 /* Make sure we don't pass any secrets to usermode */
1009 RtlZeroMemory(KernelMem
, Size
);
1014 KernelModeMsg
->lParam
= 0;
1017 return STATUS_SUCCESS
;
1020 static NTSTATUS FASTCALL
1021 CopyMsgToUserMem(MSG
*UserModeMsg
, MSG
*KernelModeMsg
)
1024 PMSGMEMORY MsgMemoryEntry
;
1027 /* See if this message type is present in the table */
1028 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
->message
);
1029 if (NULL
== MsgMemoryEntry
)
1031 /* Not present, no copying needed */
1032 return STATUS_SUCCESS
;
1035 /* Determine required size */
1036 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
1040 /* Copy data if required */
1041 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_WRITE
))
1043 Status
= MmCopyToCaller((PVOID
) UserModeMsg
->lParam
, (PVOID
) KernelModeMsg
->lParam
, Size
);
1044 if (! NT_SUCCESS(Status
))
1046 DPRINT1("Failed to copy message from kernel: invalid usermode buffer\n");
1047 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1052 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1055 return STATUS_SUCCESS
;
1058 static BOOL FASTCALL
1059 co_IntWaitMessage( PWND Window
,
1064 PUSER_MESSAGE_QUEUE ThreadQueue
;
1065 NTSTATUS Status
= STATUS_SUCCESS
;
1068 pti
= PsGetCurrentThreadWin32Thread();
1069 ThreadQueue
= pti
->MessageQueue
;
1073 if ( co_IntPeekMessage( &Msg
,
1081 /* Nothing found. Wait for new messages. */
1082 Status
= co_MsqWaitForNewMessages( ThreadQueue
,
1087 while ( (STATUS_WAIT_0
<= Status
&& Status
<= STATUS_WAIT_63
) ||
1088 STATUS_TIMEOUT
== Status
);
1090 if (!NT_SUCCESS(Status
))
1092 SetLastNtError(Status
);
1093 DPRINT1("Exit co_IntWaitMessage on error!\n");
1100 co_IntGetPeekMessage( PMSG pMsg
,
1111 if ( hWnd
== HWND_TOPMOST
||
1112 hWnd
== HWND_BROADCAST
)
1115 /* Validate input */
1116 if (hWnd
&& hWnd
!= HWND_BOTTOM
)
1118 if (!(Window
= UserGetWindowObject(hWnd
)))
1128 Window
= (PWND
)hWnd
;
1131 if (MsgFilterMax
< MsgFilterMin
)
1139 Present
= co_IntPeekMessage( &Msg
,
1146 RtlCopyMemory( pMsg
, &Msg
.Msg
, sizeof(MSG
));
1149 return (WM_QUIT
!= pMsg
->message
);
1154 if ( bGMSG
&& !co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
) )
1160 if (!(RemoveMsg
& PM_NOYIELD
))
1162 // Yield this thread!
1165 UserEnterExclusive();
1166 // Fall through to fail.
1170 while( bGMSG
&& !Present
);
1176 UserPostThreadMessage( DWORD idThread
,
1183 PTHREADINFO pThread
;
1184 LARGE_INTEGER LargeTickCount
;
1187 DPRINT1("UserPostThreadMessage wParam 0x%x lParam 0x%x\n", wParam
,lParam
);
1189 if (FindMsgMemory(Msg
) != 0)
1191 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1195 Status
= PsLookupThreadByThreadId((HANDLE
)idThread
,&peThread
);
1197 if( Status
== STATUS_SUCCESS
)
1199 pThread
= (PTHREADINFO
)peThread
->Tcb
.Win32Thread
;
1201 !pThread
->MessageQueue
||
1202 (pThread
->TIF_flags
& TIF_INCLEANUP
))
1204 ObDereferenceObject( peThread
);
1208 Message
.hwnd
= NULL
;
1209 Message
.message
= Msg
;
1210 Message
.wParam
= wParam
;
1211 Message
.lParam
= lParam
;
1212 Message
.pt
= gpsi
->ptCursor
;
1214 KeQueryTickCount(&LargeTickCount
);
1215 pThread
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1216 MsqPostMessage(pThread
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1217 ObDereferenceObject( peThread
);
1222 SetLastNtError( Status
);
1228 UserPostMessage( HWND Wnd
,
1235 LARGE_INTEGER LargeTickCount
;
1237 if (FindMsgMemory(Msg
) != 0)
1239 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1244 return UserPostThreadMessage( PtrToInt(PsGetCurrentThreadId()),
1249 if (Wnd
== HWND_BROADCAST
)
1255 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1256 List
= IntWinListChildren(DesktopWindow
);
1260 for (i
= 0; List
[i
]; i
++)
1261 UserPostMessage(List
[i
], Msg
, wParam
, lParam
);
1269 Window
= UserGetWindowObject(Wnd
);
1275 pti
= Window
->head
.pti
;
1276 if ( pti
->TIF_flags
& TIF_INCLEANUP
)
1278 DPRINT1("Attempted to post message to window 0x%x when the thread is in cleanup!\n", Wnd
);
1282 if ( Window
->state
& WNDS_DESTROYED
)
1284 DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd
);
1285 /* FIXME - last error code? */
1291 MsqPostQuitMessage(Window
->head
.pti
->MessageQueue
, wParam
);
1296 Message
.message
= Msg
;
1297 Message
.wParam
= wParam
;
1298 Message
.lParam
= lParam
;
1299 Message
.pt
= gpsi
->ptCursor
;
1300 KeQueryTickCount(&LargeTickCount
);
1301 pti
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1302 MsqPostMessage(Window
->head
.pti
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1310 co_IntSendMessage( HWND hWnd
,
1315 ULONG_PTR Result
= 0;
1316 if(co_IntSendMessageTimeout(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
))
1318 return (LRESULT
)Result
;
1325 co_IntSendMessageTimeoutSingle( HWND hWnd
,
1331 ULONG_PTR
*uResult
)
1335 PMSGMEMORY MsgMemoryEntry
;
1336 INT lParamBufferSize
;
1337 LPARAM lParamPacked
;
1338 PTHREADINFO Win32Thread
;
1339 ULONG_PTR Result
= 0;
1340 DECLARE_RETURN(LRESULT
);
1341 USER_REFERENCE_ENTRY Ref
;
1343 if (!(Window
= UserGetWindowObject(hWnd
)))
1348 UserRefObjectCo(Window
, &Ref
);
1350 Win32Thread
= PsGetCurrentThreadWin32Thread();
1352 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1354 if ( NULL
!= Win32Thread
&&
1355 Window
->head
.pti
->MessageQueue
== Win32Thread
->MessageQueue
)
1357 if (Win32Thread
->TIF_flags
& TIF_INCLEANUP
)
1359 /* Never send messages to exiting threads */
1363 /* See if this message type is present in the table */
1364 MsgMemoryEntry
= FindMsgMemory(Msg
);
1365 if (NULL
== MsgMemoryEntry
)
1367 lParamBufferSize
= -1;
1371 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1374 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
, FALSE
)))
1376 DPRINT1("Failed to pack message parameters\n");
1380 ObReferenceObject(Win32Thread
->pEThread
);
1381 Result
= (ULONG_PTR
)co_IntCallWindowProc( Window
->lpfnWndProc
,
1393 ObDereferenceObject(Win32Thread
->pEThread
);
1395 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1397 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
, FALSE
)))
1399 DPRINT1("Failed to unpack message parameters\n");
1406 if (uFlags
& SMTO_ABORTIFHUNG
&& MsqIsHung(Window
->head
.pti
->MessageQueue
))
1408 /* FIXME - Set a LastError? */
1412 if (Window
->state
& WNDS_DESTROYED
)
1414 /* FIXME - last error? */
1415 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1421 Status
= co_MsqSendMessage( Window
->head
.pti
->MessageQueue
,
1427 (uFlags
& SMTO_BLOCK
),
1431 while ((STATUS_TIMEOUT
== Status
) &&
1432 (uFlags
& SMTO_NOTIMEOUTIFNOTHUNG
) &&
1433 !MsqIsHung(Window
->head
.pti
->MessageQueue
));
1435 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1437 if (STATUS_TIMEOUT
== Status
)
1441 Microsoft Windows 2000: If GetLastError returns zero, then the function
1443 XP+ : If the function fails or times out, the return value is zero.
1444 To get extended error information, call GetLastError. If GetLastError
1445 returns ERROR_TIMEOUT, then the function timed out.
1447 SetLastWin32Error(ERROR_TIMEOUT
);
1450 else if (! NT_SUCCESS(Status
))
1452 SetLastNtError(Status
);
1459 if (Window
) UserDerefObjectCo(Window
);
1464 co_IntSendMessageTimeout( HWND hWnd
,
1470 ULONG_PTR
*uResult
)
1476 if (HWND_BROADCAST
!= hWnd
)
1478 return co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1481 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1482 if (NULL
== DesktopWindow
)
1484 SetLastWin32Error(ERROR_INTERNAL_ERROR
);
1488 Children
= IntWinListChildren(DesktopWindow
);
1489 if (NULL
== Children
)
1494 for (Child
= Children
; NULL
!= *Child
; Child
++)
1496 co_IntSendMessageTimeoutSingle(*Child
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1499 ExFreePool(Children
);
1501 return (LRESULT
) TRUE
;
1504 LRESULT FASTCALL
co_IntSendMessageNoWait(HWND hWnd
,
1509 ULONG_PTR Result
= 0;
1510 co_IntSendMessageWithCallBack(hWnd
,
1521 co_IntSendMessageWithCallBack( HWND hWnd
,
1525 SENDASYNCPROC CompletionCallback
,
1526 ULONG_PTR CompletionCallbackContext
,
1531 PMSGMEMORY MsgMemoryEntry
;
1532 INT lParamBufferSize
;
1533 LPARAM lParamPacked
;
1534 PTHREADINFO Win32Thread
;
1535 DECLARE_RETURN(LRESULT
);
1536 USER_REFERENCE_ENTRY Ref
;
1537 PUSER_SENT_MESSAGE Message
;
1539 if (!(Window
= UserGetWindowObject(hWnd
)))
1544 UserRefObjectCo(Window
, &Ref
);
1546 if (Window
->state
& WNDS_DESTROYED
)
1548 /* FIXME - last error? */
1549 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1553 Win32Thread
= PsGetCurrentThreadWin32Thread();
1555 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1557 if (Win32Thread
== NULL
)
1563 if (Win32Thread
->TIF_flags
& TIF_INCLEANUP
)
1565 /* Never send messages to exiting threads */
1569 /* See if this message type is present in the table */
1570 MsgMemoryEntry
= FindMsgMemory(Msg
);
1571 if (NULL
== MsgMemoryEntry
)
1573 lParamBufferSize
= -1;
1577 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1580 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
, Window
->head
.pti
->MessageQueue
!= Win32Thread
->MessageQueue
)))
1582 DPRINT1("Failed to pack message parameters\n");
1586 /* If this is not a callback and it can be sent now, then send it. */
1587 if ((Window
->head
.pti
->MessageQueue
== Win32Thread
->MessageQueue
) && (CompletionCallback
== NULL
))
1589 ObReferenceObject(Win32Thread
->pEThread
);
1590 Result
= (ULONG_PTR
)co_IntCallWindowProc( Window
->lpfnWndProc
,
1601 ObDereferenceObject(Win32Thread
->pEThread
);
1604 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1606 if ((Window
->head
.pti
->MessageQueue
== Win32Thread
->MessageQueue
) && (CompletionCallback
== NULL
))
1608 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
, FALSE
)))
1610 DPRINT1("Failed to unpack message parameters\n");
1615 if(!(Message
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(USER_SENT_MESSAGE
), TAG_USRMSG
)))
1617 DPRINT1("MsqSendMessage(): Not enough memory to allocate a message");
1618 return STATUS_INSUFFICIENT_RESOURCES
;
1621 Message
->Msg
.hwnd
= hWnd
;
1622 Message
->Msg
.message
= Msg
;
1623 Message
->Msg
.wParam
= wParam
;
1624 Message
->Msg
.lParam
= lParamPacked
;
1625 Message
->CompletionEvent
= NULL
;
1626 Message
->Result
= 0;
1627 Message
->SenderQueue
= NULL
; //Win32Thread->MessageQueue;
1629 IntReferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
1630 Message
->CompletionCallback
= CompletionCallback
;
1631 Message
->CompletionCallbackContext
= CompletionCallbackContext
;
1632 Message
->HookMessage
= MSQ_NORMAL
| MSQ_SENTNOWAIT
;
1633 Message
->HasPackedLParam
= (lParamBufferSize
> 0);
1635 InsertTailList(&Window
->head
.pti
->MessageQueue
->SentMessagesListHead
, &Message
->ListEntry
);
1636 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
1641 if (Window
) UserDerefObjectCo(Window
);
1645 /* This function posts a message if the destination's message queue belongs to
1646 another thread, otherwise it sends the message. It does not support broadcast
1649 co_IntPostOrSendMessage( HWND hWnd
,
1658 if ( hWnd
== HWND_BROADCAST
)
1663 if(!(Window
= UserGetWindowObject(hWnd
)))
1668 pti
= PsGetCurrentThreadWin32Thread();
1670 if ( Window
->head
.pti
->MessageQueue
!= pti
->MessageQueue
&&
1671 FindMsgMemory(Msg
) == 0 )
1673 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1677 if ( !co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
) )
1683 return (LRESULT
)Result
;
1687 co_IntDoSendMessage( HWND hWnd
,
1692 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1695 LRESULT Result
= TRUE
;
1698 NTUSERSENDMESSAGEINFO Info
;
1701 PMSGMEMORY MsgMemoryEntry
;
1703 RtlZeroMemory(&Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1705 /* FIXME: Call hooks. */
1706 if (HWND_BROADCAST
!= hWnd
)
1708 Window
= UserGetWindowObject(hWnd
);
1711 /* Tell usermode to not touch this one */
1712 Info
.HandledByKernel
= TRUE
;
1713 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1718 /* Check for an exiting window. */
1719 if (Window
&& Window
->state
& WNDS_DESTROYED
)
1721 DPRINT1("co_IntDoSendMessage Window Exiting!\n");
1724 /* See if the current thread can handle the message */
1725 pti
= PsGetCurrentThreadWin32Thread();
1727 // This is checked in user mode!!!!!!!
1728 if ( HWND_BROADCAST
!= hWnd
&&
1730 Window
->head
.pti
->MessageQueue
== pti
->MessageQueue
&&
1731 !ISITHOOKED(WH_CALLWNDPROC
) &&
1732 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
1733 ( Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
) )
1735 /* Gather the information usermode needs to call the window proc directly */
1736 Info
.HandledByKernel
= FALSE
;
1738 Status
= MmCopyFromCaller(&(Info
.Ansi
), &(UnsafeInfo
->Ansi
),
1740 if (! NT_SUCCESS(Status
))
1742 Info
.Ansi
= ! Window
->Unicode
;
1745 Info
.Ansi
= !Window
->Unicode
;
1746 Info
.Proc
= Window
->lpfnWndProc
;
1750 /* Must be handled by other thread */
1751 // if (HWND_BROADCAST != hWnd)
1753 // UserDereferenceObject(Window);
1755 Info
.HandledByKernel
= TRUE
;
1756 UserModeMsg
.hwnd
= hWnd
;
1757 UserModeMsg
.message
= Msg
;
1758 UserModeMsg
.wParam
= wParam
;
1759 UserModeMsg
.lParam
= lParam
;
1760 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1762 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1763 if (! NT_SUCCESS(Status
))
1765 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1766 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1767 return (dsm
? 0 : -1);
1772 Result
= co_IntSendMessage( KernelModeMsg
.hwnd
,
1773 KernelModeMsg
.message
,
1774 KernelModeMsg
.wParam
,
1775 KernelModeMsg
.lParam
);
1779 Result
= co_IntSendMessageTimeout( KernelModeMsg
.hwnd
,
1780 KernelModeMsg
.message
,
1781 KernelModeMsg
.wParam
,
1782 KernelModeMsg
.lParam
,
1788 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1789 if (! NT_SUCCESS(Status
))
1791 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1792 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1793 return(dsm
? 0 : -1);
1797 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1798 if (! NT_SUCCESS(Status
))
1800 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1803 return (LRESULT
)Result
;
1808 UserSendNotifyMessage( HWND hWnd
,
1815 if (FindMsgMemory(Msg
) != 0)
1817 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1821 // Basicly the same as IntPostOrSendMessage
1822 if (hWnd
== HWND_BROADCAST
) //Handle Broadcast
1828 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1829 List
= IntWinListChildren(DesktopWindow
);
1833 for (i
= 0; List
[i
]; i
++)
1835 UserSendNotifyMessage(List
[i
], Msg
, wParam
, lParam
);
1846 if ( !(Window
= UserGetWindowObject(hWnd
)) ) return FALSE
;
1848 pti
= PsGetCurrentThreadWin32Thread();
1850 if (Window
->head
.pti
->MessageQueue
!= pti
->MessageQueue
)
1851 { // Send message w/o waiting for it.
1852 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1855 { // Handle message and callback.
1856 Result
= co_IntSendMessageTimeoutSingle( hWnd
,
1870 IntGetQueueStatus(BOOL ClearChanges
)
1873 PUSER_MESSAGE_QUEUE Queue
;
1875 DECLARE_RETURN(DWORD
);
1877 DPRINT("Enter IntGetQueueStatus\n");
1879 pti
= PsGetCurrentThreadWin32Thread();
1880 Queue
= pti
->MessageQueue
;
1882 Result
= MAKELONG(Queue
->QueueBits
, Queue
->ChangedBits
);
1885 Queue
->ChangedBits
= 0;
1891 DPRINT("Leave IntGetQueueStatus, ret=%i\n",_ret_
);
1896 IntInitMessagePumpHook()
1898 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1900 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
++;
1907 IntUninitMessagePumpHook()
1909 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1911 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
<= 0)
1915 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
--;
1921 /** Functions ******************************************************************/
1924 NtUserPostMessage(HWND hWnd
,
1929 DECLARE_RETURN(BOOL
);
1931 DPRINT("Enter NtUserPostMessage\n");
1932 UserEnterExclusive();
1934 RETURN( UserPostMessage(hWnd
, Msg
, wParam
, lParam
));
1937 DPRINT("Leave NtUserPostMessage, ret=%i\n",_ret_
);
1943 NtUserPostThreadMessage(DWORD idThread
,
1948 DECLARE_RETURN(BOOL
);
1950 DPRINT("Enter NtUserPostThreadMessage\n");
1951 UserEnterExclusive();
1953 RETURN( UserPostThreadMessage( idThread
,
1959 DPRINT("Leave NtUserPostThreadMessage, ret=%i\n",_ret_
);
1965 NtUserQuerySendMessage(DWORD Unknown0
)
1973 ////////// API on the way out!
1975 NtUserSendMessageTimeout( HWND hWnd
,
1982 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1986 DECLARE_RETURN(BOOL
);
1988 DPRINT("Enter NtUserSendMessageTimeout\n");
1989 UserEnterExclusive();
1991 dsm
.uFlags
= uFlags
;
1992 dsm
.uTimeout
= uTimeout
;
1993 Result
= co_IntDoSendMessage(hWnd
, Msg
, wParam
, lParam
, &dsm
, UnsafeInfo
);
1994 if(uResult
!= NULL
&& Result
!= 0)
1998 Status
= MmCopyToCaller(uResult
, &dsm
.Result
, sizeof(ULONG_PTR
));
1999 if(!NT_SUCCESS(Status
))
2001 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2008 DPRINT("Leave NtUserSendMessageTimeout, ret=%i\n",_ret_
);
2014 NtUserSendMessage( HWND Wnd
,
2018 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
2020 DECLARE_RETURN(BOOL
);
2022 DPRINT("Enter NtUserSendMessage\n");
2023 UserEnterExclusive();
2025 RETURN(co_IntDoSendMessage(Wnd
, Msg
, wParam
, lParam
, NULL
, UnsafeInfo
));
2028 DPRINT("Leave NtUserSendMessage, ret=%i\n",_ret_
);
2035 NtUserWaitMessage(VOID
)
2037 DECLARE_RETURN(BOOL
);
2039 DPRINT("EnterNtUserWaitMessage\n");
2040 UserEnterExclusive();
2042 RETURN(co_IntWaitMessage(NULL
, 0, 0));
2045 DPRINT("Leave NtUserWaitMessage, ret=%i\n",_ret_
);
2052 NtUserGetMessage( PNTUSERGETMESSAGEINFO UnsafeInfo
,
2057 * FUNCTION: Get a message from the calling thread's message queue.
2059 * UnsafeMsg - Pointer to the structure which receives the returned message.
2060 * Wnd - Window whose messages are to be retrieved.
2061 * MsgFilterMin - Integer value of the lowest message value to be
2063 * MsgFilterMax - Integer value of the highest message value to be
2068 NTUSERGETMESSAGEINFO Info
;
2070 /* FIXME: if initialization is removed, gcc complains that this may be used before initialization. Please review */
2072 PMSGMEMORY MsgMemoryEntry
;
2076 DECLARE_RETURN(BOOL
);
2077 // USER_REFERENCE_ENTRY Ref;
2079 DPRINT("Enter NtUserGetMessage\n");
2080 UserEnterExclusive();
2082 /* Validate input */
2083 if (hWnd
&& !(Window
= UserGetWindowObject(hWnd
)))
2088 // if (Window) UserRefObjectCo(Window, &Ref);
2090 if (MsgFilterMax
< MsgFilterMin
)
2098 GotMessage
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
);
2102 /* See if this message type is present in the table */
2103 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
2104 if (NULL
== MsgMemoryEntry
)
2106 /* Not present, no copying needed */
2107 Info
.LParamSize
= 0;
2111 /* Determine required size */
2112 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
2114 /* Allocate required amount of user-mode memory */
2115 Info
.LParamSize
= Size
;
2117 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
2118 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
2120 if (! NT_SUCCESS(Status
))
2122 SetLastNtError(Status
);
2125 /* Transfer lParam data to user-mode mem */
2126 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
2127 if (! NT_SUCCESS(Status
))
2129 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
2130 &Info
.LParamSize
, MEM_DECOMMIT
);
2131 SetLastNtError(Status
);
2134 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
2136 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
2137 if (! NT_SUCCESS(Status
))
2139 SetLastNtError(Status
);
2143 else if (! co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
))
2148 while (! GotMessage
);
2150 RETURN( WM_QUIT
!= Info
.Msg
.message
);
2153 // if (Window) UserDerefObjectCo(Window);
2155 DPRINT("Leave NtUserGetMessage\n");
2171 DECLARE_RETURN(BOOL
);
2173 DPRINT("Enter NtUserGetMessage\n");
2174 UserEnterExclusive();
2176 if ( (MsgFilterMin
|MsgFilterMax
) & ~WM_MAXIMUM
)
2178 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2182 RtlZeroMemory(&Msg
, sizeof(MSG
));
2184 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
, TRUE
);
2190 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
2191 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
2193 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2195 SetLastNtError(_SEH2_GetExceptionCode());
2203 DPRINT("Leave NtUserGetMessage\n");
2209 NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
2217 NTUSERGETMESSAGEINFO Info
;
2219 PMSGMEMORY MsgMemoryEntry
;
2223 DECLARE_RETURN(BOOL
);
2225 DPRINT("Enter NtUserPeekMessage\n");
2226 UserEnterExclusive();
2228 if (hWnd
== (HWND
)-1 || hWnd
== (HWND
)0x0000FFFF || hWnd
== (HWND
)0xFFFFFFFF)
2231 /* Validate input */
2232 if (hWnd
&& hWnd
!= (HWND
)1)
2234 if (!(Window
= UserGetWindowObject(hWnd
)))
2241 Window
= (PWND
)hWnd
;
2244 if (MsgFilterMax
< MsgFilterMin
)
2250 Present
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
);
2255 /* See if this message type is present in the table */
2256 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
2257 if (NULL
== MsgMemoryEntry
)
2259 /* Not present, no copying needed */
2260 Info
.LParamSize
= 0;
2264 /* Determine required size */
2265 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
2267 /* Allocate required amount of user-mode memory */
2268 Info
.LParamSize
= Size
;
2270 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
2271 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
2272 if (! NT_SUCCESS(Status
))
2274 SetLastNtError(Status
);
2277 /* Transfer lParam data to user-mode mem */
2278 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
2279 if (! NT_SUCCESS(Status
))
2281 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
2282 &Info
.LParamSize
, MEM_RELEASE
);
2283 SetLastNtError(Status
);
2286 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
2288 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
2289 if (! NT_SUCCESS(Status
))
2291 SetLastNtError(Status
);
2299 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2315 DECLARE_RETURN(BOOL
);
2317 DPRINT("Enter NtUserPeekMessage\n");
2318 UserEnterExclusive();
2320 if ( RemoveMsg
& PM_BADMSGFLAGS
)
2322 SetLastWin32Error(ERROR_INVALID_FLAGS
);
2326 RtlZeroMemory(&Msg
, sizeof(MSG
));
2328 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
, FALSE
);
2334 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
2335 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
2337 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2339 SetLastNtError(_SEH2_GetExceptionCode());
2347 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2354 NtUserCallMsgFilter(
2358 BOOL BadChk
= FALSE
, Ret
= FALSE
;
2360 DECLARE_RETURN(BOOL
);
2362 DPRINT("Enter NtUserCallMsgFilter\n");
2363 UserEnterExclusive();
2368 ProbeForRead((PVOID
)lpmsg
,
2371 RtlCopyMemory( &Msg
,
2375 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2384 if (BadChk
) RETURN( FALSE
);
2386 if ( co_HOOK_CallHooks( WH_SYSMSGFILTER
, code
, 0, (LPARAM
)&Msg
))
2392 Ret
= co_HOOK_CallHooks( WH_MSGFILTER
, code
, 0, (LPARAM
)&Msg
);
2397 ProbeForWrite((PVOID
)lpmsg
,
2400 RtlCopyMemory((PVOID
)lpmsg
,
2404 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2409 if (BadChk
) RETURN( FALSE
);
2413 DPRINT("Leave NtUserCallMsgFilter. ret=%i\n", _ret_
);
2419 NtUserDispatchMessage(PMSG UnsafeMsgInfo
)
2425 UserEnterExclusive();
2428 ProbeForRead(UnsafeMsgInfo
, sizeof(MSG
), 1);
2429 RtlCopyMemory(&SafeMsg
, UnsafeMsgInfo
, sizeof(MSG
));
2431 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2433 SetLastNtError(_SEH2_GetExceptionCode());
2438 if (!Hit
) Res
= IntDispatchMessage(&SafeMsg
);
2446 NtUserTranslateMessage(LPMSG lpMsg
,
2451 DECLARE_RETURN(BOOL
);
2453 DPRINT("Enter NtUserTranslateMessage\n");
2454 UserEnterExclusive();
2456 Status
= MmCopyFromCaller(&SafeMsg
, lpMsg
, sizeof(MSG
));
2457 if(!NT_SUCCESS(Status
))
2459 SetLastNtError(Status
);
2463 RETURN( IntTranslateKbdMessage(&SafeMsg
, flags
));
2466 DPRINT("Leave NtUserTranslateMessage: ret=%i\n",_ret_
);
2477 ULONG_PTR ResultInfo
,
2478 DWORD dwType
, // fnID?
2481 LRESULT lResult
= 0;
2483 BOOL BadChk
= FALSE
;
2485 USER_REFERENCE_ENTRY Ref
;
2487 UserEnterExclusive();
2489 /* Validate input */
2490 if (hWnd
&& (hWnd
!= INVALID_HANDLE_VALUE
) && !(Window
= UserGetWindowObject(hWnd
)))
2497 case FNID_DEFWINDOWPROC
:
2498 UserRefObjectCo(Window
, &Ref
);
2499 lResult
= IntDefWindowProc(Window
, Msg
, wParam
, lParam
, Ansi
);
2501 UserDerefObjectCo(Window
);
2503 case FNID_SENDNOTIFYMESSAGE
:
2504 Ret
= UserSendNotifyMessage(hWnd
, Msg
, wParam
, lParam
);
2506 case FNID_BROADCASTSYSTEMMESSAGE
:
2509 DWORD_PTR RetVal
= 0;
2515 ProbeForWrite((PVOID
)ResultInfo
,
2516 sizeof(BROADCASTPARM
),
2518 RtlCopyMemory(&parm
, (PVOID
)ResultInfo
, sizeof(BROADCASTPARM
));
2520 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2530 if ( parm
.recipients
& BSM_ALLDESKTOPS
||
2531 parm
.recipients
== BSM_ALLCOMPONENTS
)
2534 else if (parm
.recipients
& BSM_APPLICATIONS
)
2536 if (parm
.flags
& BSF_QUERY
)
2538 if (parm
.flags
& BSF_FORCEIFHUNG
|| parm
.flags
& BSF_NOHANG
)
2540 co_IntSendMessageTimeout( HWND_BROADCAST
,
2548 else if (parm
.flags
& BSF_NOTIMEOUTIFNOTHUNG
)
2550 co_IntSendMessageTimeout( HWND_BROADCAST
,
2554 SMTO_NOTIMEOUTIFNOTHUNG
,
2560 co_IntSendMessageTimeout( HWND_BROADCAST
,
2570 else if (parm
.flags
& BSF_POSTMESSAGE
)
2572 Ret
= UserPostMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2574 else //Everything else,,,, if ( parm.flags & BSF_SENDNOTIFYMESSAGE)
2576 Ret
= UserSendNotifyMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2581 case FNID_SENDMESSAGECALLBACK
:
2583 PCALL_BACK_INFO CallBackInfo
= (PCALL_BACK_INFO
)ResultInfo
;
2589 if (!co_IntSendMessageWithCallBack(hWnd
, Msg
, wParam
, lParam
,
2590 CallBackInfo
->CallBack
, CallBackInfo
->Context
, &uResult
))
2592 DPRINT1("Callback failure!\n");
2596 // CallNextHook bypass.
2597 case FNID_CALLWNDPROC
:
2598 case FNID_CALLWNDPROCRET
:
2601 PCLIENTINFO ClientInfo
;
2602 PHOOK NextObj
, Hook
;
2604 pti
= GetW32ThreadInfo();
2606 Hook
= pti
->sphkCurrent
;
2610 NextObj
= Hook
->phkNext
;
2611 ClientInfo
= pti
->pClientInfo
;
2614 ClientInfo
->phkCurrent
= NextObj
;
2616 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2622 if (!ClientInfo
|| !NextObj
) break;
2624 NextObj
->phkNext
= IntGetNextHook(NextObj
);
2626 if ( Hook
->HookId
== WH_CALLWNDPROC
)
2631 CWP
.wParam
= wParam
;
2632 CWP
.lParam
= lParam
;
2633 DPRINT("WH_CALLWNDPROC: Hook %x NextHook %x\n", Hook
, NextObj
);
2635 lResult
= co_IntCallHookProc( Hook
->HookId
,
2637 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2648 CWPR
.wParam
= wParam
;
2649 CWPR
.lParam
= lParam
;
2650 CWPR
.lResult
= ClientInfo
->dwHookData
;
2652 lResult
= co_IntCallHookProc( Hook
->HookId
,
2654 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2666 case FNID_DEFWINDOWPROC
:
2667 case FNID_CALLWNDPROC
:
2668 case FNID_CALLWNDPROCRET
:
2673 ProbeForWrite((PVOID
)ResultInfo
, sizeof(LRESULT
), 1);
2674 RtlCopyMemory((PVOID
)ResultInfo
, &lResult
, sizeof(LRESULT
));
2676 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2689 return BadChk
? FALSE
: Ret
;
2692 #define INFINITE 0xFFFFFFFF
2693 #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
2697 NtUserWaitForInputIdle(
2699 IN DWORD dwMilliseconds
,
2703 PPROCESSINFO W32Process
;
2706 LARGE_INTEGER Timeout
;
2707 ULONGLONG StartTime
, Run
, Elapsed
= 0;
2709 UserEnterExclusive();
2711 Status
= ObReferenceObjectByHandle(hProcess
,
2712 PROCESS_QUERY_INFORMATION
,
2718 if (!NT_SUCCESS(Status
))
2721 SetLastNtError(Status
);
2725 W32Process
= (PPROCESSINFO
)Process
->Win32Process
;
2728 ObDereferenceObject(Process
);
2730 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2734 EngCreateEvent((PEVENT
*)&W32Process
->InputIdleEvent
);
2736 Handles
[0] = Process
;
2737 Handles
[1] = W32Process
->InputIdleEvent
;
2741 ObDereferenceObject(Process
);
2743 return STATUS_SUCCESS
; /* no event to wait on */
2746 StartTime
= EngGetTickCount();
2748 Run
= dwMilliseconds
;
2750 DPRINT("WFII: waiting for %p\n", Handles
[1] );
2753 Timeout
.QuadPart
= Run
- Elapsed
;
2755 Status
= KeWaitForMultipleObjects( 2,
2761 dwMilliseconds
== INFINITE
? NULL
: &Timeout
,
2763 UserEnterExclusive();
2765 if (!NT_SUCCESS(Status
))
2767 SetLastNtError(Status
);
2768 Status
= WAIT_FAILED
;
2775 Status
= WAIT_FAILED
;
2781 co_IntPeekMessage( &Msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2785 case STATUS_USER_APC
:
2786 case STATUS_ALERTED
:
2787 case STATUS_TIMEOUT
:
2788 DPRINT1("WFII: timeout\n");
2789 Status
= STATUS_TIMEOUT
;
2793 DPRINT1("WFII: finished\n");
2794 Status
= STATUS_SUCCESS
;
2798 if (dwMilliseconds
!= INFINITE
)
2800 Elapsed
= EngGetTickCount() - StartTime
;
2803 Status
= STATUS_TIMEOUT
;
2810 if (W32Process
->InputIdleEvent
)
2812 EngFreeMem((PVOID
)W32Process
->InputIdleEvent
);
2813 W32Process
->InputIdleEvent
= NULL
;
2815 ObDereferenceObject(Process
);