2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
4 * PURPOSE: Callback to usermode support
5 * FILE: win32ss/user/ntuser/callback.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * Thomas Weidenmueller (w3seek@users.sourceforge.net)
8 * NOTES: Please use the Callback Memory Management functions for
9 * callbacks to make sure, the memory is freed on thread
14 DBG_DEFAULT_CHANNEL(UserCallback
);
17 /* CALLBACK MEMORY MANAGEMENT ************************************************/
19 typedef struct _INT_CALLBACK_HEADER
21 /* List entry in the THREADINFO structure */
24 INT_CALLBACK_HEADER
, *PINT_CALLBACK_HEADER
;
27 IntCbAllocateMemory(ULONG Size
)
29 PINT_CALLBACK_HEADER Mem
;
30 PTHREADINFO W32Thread
;
32 if(!(Mem
= ExAllocatePoolWithTag(PagedPool
, Size
+ sizeof(INT_CALLBACK_HEADER
),
38 W32Thread
= PsGetCurrentThreadWin32Thread();
41 /* Insert the callback memory into the thread's callback list */
43 InsertTailList(&W32Thread
->W32CallbackListHead
, &Mem
->ListEntry
);
49 IntCbFreeMemory(PVOID Data
)
51 PINT_CALLBACK_HEADER Mem
;
52 PTHREADINFO W32Thread
;
56 Mem
= ((PINT_CALLBACK_HEADER
)Data
- 1);
58 W32Thread
= PsGetCurrentThreadWin32Thread();
61 /* Remove the memory block from the thread's callback list */
62 RemoveEntryList(&Mem
->ListEntry
);
65 ExFreePoolWithTag(Mem
, USERTAG_CALLBACK
);
69 IntCleanupThreadCallbacks(PTHREADINFO W32Thread
)
71 PLIST_ENTRY CurrentEntry
;
72 PINT_CALLBACK_HEADER Mem
;
74 while (!IsListEmpty(&W32Thread
->W32CallbackListHead
))
76 CurrentEntry
= RemoveHeadList(&W32Thread
->W32CallbackListHead
);
77 Mem
= CONTAINING_RECORD(CurrentEntry
, INT_CALLBACK_HEADER
,
81 ExFreePoolWithTag(Mem
, USERTAG_CALLBACK
);
86 // Pass the Current Window handle and pointer to the Client Callback.
87 // This will help user space programs speed up read access with the window object.
90 IntSetTebWndCallback (HWND
* hWnd
, PWND
* pWnd
, PVOID
* pActCtx
)
93 PWND Window
= UserGetWindowObject(*hWnd
);
94 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
96 *hWnd
= ClientInfo
->CallbackWnd
.hWnd
;
97 *pWnd
= ClientInfo
->CallbackWnd
.pWnd
;
98 *pActCtx
= ClientInfo
->CallbackWnd
.pActCtx
;
102 ClientInfo
->CallbackWnd
.hWnd
= hWndS
;
103 ClientInfo
->CallbackWnd
.pWnd
= DesktopHeapAddressToUser(Window
);
104 ClientInfo
->CallbackWnd
.pActCtx
= Window
->pActCtx
;
106 else //// What if Dispatching WM_SYS/TIMER with NULL window? Fix AbiWord Crash when sizing.
108 ClientInfo
->CallbackWnd
.hWnd
= hWndS
;
109 ClientInfo
->CallbackWnd
.pWnd
= Window
;
110 ClientInfo
->CallbackWnd
.pActCtx
= 0;
115 IntRestoreTebWndCallback (HWND hWnd
, PWND pWnd
, PVOID pActCtx
)
117 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
119 ClientInfo
->CallbackWnd
.hWnd
= hWnd
;
120 ClientInfo
->CallbackWnd
.pWnd
= pWnd
;
121 ClientInfo
->CallbackWnd
.pActCtx
= pActCtx
;
124 /* FUNCTIONS *****************************************************************/
126 /* Calls ClientLoadLibrary in user32 */
129 co_IntClientLoadLibrary(PUNICODE_STRING pstrLibName
,
130 PUNICODE_STRING pstrInitFunc
,
136 ULONG ArgumentLength
;
137 PCLIENT_LOAD_LIBRARY_ARGUMENTS pArguments
;
140 ULONG_PTR pLibNameBuffer
= 0, pInitFuncBuffer
= 0;
142 /* Do not allow the desktop thread to do callback to user mode */
143 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
145 TRACE("co_IntClientLoadLibrary: %S, %S, %d, %d\n", pstrLibName
->Buffer
, pstrLibName
->Buffer
, Unload
, ApiHook
);
147 /* Calculate the size of the argument */
148 ArgumentLength
= sizeof(CLIENT_LOAD_LIBRARY_ARGUMENTS
);
151 pLibNameBuffer
= ArgumentLength
;
152 ArgumentLength
+= pstrLibName
->Length
+ sizeof(WCHAR
);
156 pInitFuncBuffer
= ArgumentLength
;
157 ArgumentLength
+= pstrInitFunc
->Length
+ sizeof(WCHAR
);
160 /* Allocate the argument */
161 pArguments
= IntCbAllocateMemory(ArgumentLength
);
162 if(pArguments
== NULL
)
167 /* Fill the argument */
168 pArguments
->Unload
= Unload
;
169 pArguments
->ApiHook
= ApiHook
;
172 /* Copy the string to the callback memory */
173 pLibNameBuffer
+= (ULONG_PTR
)pArguments
;
174 pArguments
->strLibraryName
.Buffer
= (PWCHAR
)pLibNameBuffer
;
175 pArguments
->strLibraryName
.MaximumLength
= pstrLibName
->Length
+ sizeof(WCHAR
);
176 RtlCopyUnicodeString(&pArguments
->strLibraryName
, pstrLibName
);
178 /* Fix argument pointer to be relative to the argument */
179 pLibNameBuffer
-= (ULONG_PTR
)pArguments
;
180 pArguments
->strLibraryName
.Buffer
= (PWCHAR
)(pLibNameBuffer
);
184 RtlZeroMemory(&pArguments
->strLibraryName
, sizeof(UNICODE_STRING
));
189 /* Copy the strings to the callback memory */
190 pInitFuncBuffer
+= (ULONG_PTR
)pArguments
;
191 pArguments
->strInitFuncName
.Buffer
= (PWCHAR
)pInitFuncBuffer
;
192 pArguments
->strInitFuncName
.MaximumLength
= pstrInitFunc
->Length
+ sizeof(WCHAR
);
193 RtlCopyUnicodeString(&pArguments
->strInitFuncName
, pstrInitFunc
);
195 /* Fix argument pointers to be relative to the argument */
196 pInitFuncBuffer
-= (ULONG_PTR
)pArguments
;
197 pArguments
->strInitFuncName
.Buffer
= (PWCHAR
)(pInitFuncBuffer
);
201 RtlZeroMemory(&pArguments
->strInitFuncName
, sizeof(UNICODE_STRING
));
204 /* Do the callback */
207 Status
= KeUserModeCallback(USER32_CALLBACK_CLIENTLOADLIBRARY
,
215 /* Free the argument */
216 IntCbFreeMemory(pArguments
);
218 if(!NT_SUCCESS(Status
))
225 /* Probe and copy the usermode result data */
226 ProbeForRead(ResultPointer
, sizeof(HMODULE
), 1);
227 bResult
= *(BOOL
*)ResultPointer
;
229 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
239 co_IntCallSentMessageCallback(SENDASYNCPROC CompletionCallback
,
242 ULONG_PTR CompletionCallbackContext
,
245 SENDASYNCPROC_CALLBACK_ARGUMENTS Arguments
;
246 PVOID ResultPointer
, pActCtx
;
251 /* Do not allow the desktop thread to do callback to user mode */
252 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
254 Arguments
.Callback
= CompletionCallback
;
255 Arguments
.Wnd
= hWnd
;
257 Arguments
.Context
= CompletionCallbackContext
;
258 Arguments
.Result
= Result
;
260 IntSetTebWndCallback (&hWnd
, &pWnd
, &pActCtx
);
264 Status
= KeUserModeCallback(USER32_CALLBACK_SENDASYNCPROC
,
266 sizeof(SENDASYNCPROC_CALLBACK_ARGUMENTS
),
272 IntRestoreTebWndCallback (hWnd
, pWnd
, pActCtx
);
274 if (!NT_SUCCESS(Status
))
282 co_IntCallWindowProc(WNDPROC Proc
,
288 INT lParamBufferSize
)
290 WINDOWPROC_CALLBACK_ARGUMENTS StackArguments
;
291 PWINDOWPROC_CALLBACK_ARGUMENTS Arguments
;
293 PVOID ResultPointer
, pActCtx
;
296 ULONG ArgumentLength
;
299 TRACE("co_IntCallWindowProc(Proc %p, IsAnsiProc: %s, Wnd %p, Message %u, wParam %Iu, lParam %Id, lParamBufferSize %d)\n",
300 Proc
, IsAnsiProc
? "TRUE" : "FALSE", Wnd
, Message
, wParam
, lParam
, lParamBufferSize
);
302 /* Do not allow the desktop thread to do callback to user mode */
303 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
305 if (lParamBufferSize
!= -1)
307 ArgumentLength
= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
) + lParamBufferSize
;
308 Arguments
= IntCbAllocateMemory(ArgumentLength
);
309 if (NULL
== Arguments
)
311 ERR("Unable to allocate buffer for window proc callback\n");
314 RtlMoveMemory((PVOID
) ((char *) Arguments
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)),
315 (PVOID
) lParam
, lParamBufferSize
);
319 Arguments
= &StackArguments
;
320 ArgumentLength
= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
);
322 Arguments
->Proc
= Proc
;
323 Arguments
->IsAnsiProc
= IsAnsiProc
;
324 Arguments
->Wnd
= Wnd
;
325 Arguments
->Msg
= Message
;
326 Arguments
->wParam
= wParam
;
327 Arguments
->lParam
= lParam
;
328 Arguments
->lParamBufferSize
= lParamBufferSize
;
329 ResultPointer
= NULL
;
330 ResultLength
= ArgumentLength
;
332 IntSetTebWndCallback (&Wnd
, &pWnd
, &pActCtx
);
336 Status
= KeUserModeCallback(USER32_CALLBACK_WINDOWPROC
,
341 if (!NT_SUCCESS(Status
))
349 /* Simulate old behaviour: copy into our local buffer */
350 RtlMoveMemory(Arguments
, ResultPointer
, ArgumentLength
);
352 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
354 ERR("Failed to copy result from user mode, Message %u lParam size %d!\n", Message
, lParamBufferSize
);
355 Status
= _SEH2_GetExceptionCode();
361 IntRestoreTebWndCallback (Wnd
, pWnd
, pActCtx
);
363 if (!NT_SUCCESS(Status
))
365 ERR("Call to user mode failed! 0x%08lx\n",Status
);
366 if (lParamBufferSize
!= -1)
368 IntCbFreeMemory(Arguments
);
372 Result
= Arguments
->Result
;
374 if (lParamBufferSize
!= -1)
376 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
377 // Is this message being processed from inside kernel space?
378 BOOL InSendMessage
= (pti
->pcti
->CTI_flags
& CTI_INSENDMESSAGE
);
380 TRACE("Copy lParam Message %u lParam %d!\n", Message
, lParam
);
384 TRACE("Don't copy lParam, Message %u Size %d lParam %d!\n", Message
, lParamBufferSize
, lParam
);
386 // Write back to user/kernel space. Also see g_MsgMemory.
388 case WM_GETMINMAXINFO
:
392 case WM_STYLECHANGING
:
393 case WM_WINDOWPOSCHANGING
:
396 TRACE("Copy lParam, Message %u Size %d lParam %d!\n", Message
, lParamBufferSize
, lParam
);
398 // Copy into kernel space.
399 RtlMoveMemory((PVOID
) lParam
,
400 (PVOID
) ((char *) Arguments
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)),
405 { // Copy into user space.
406 RtlMoveMemory((PVOID
) lParam
,
407 (PVOID
) ((char *) Arguments
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)),
410 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
412 ERR("Failed to copy lParam to user space, Message %u!\n", Message
);
418 IntCbFreeMemory(Arguments
);
425 co_IntLoadSysMenuTemplate()
432 /* Do not allow the desktop thread to do callback to user mode */
433 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
435 ResultPointer
= NULL
;
436 ResultLength
= sizeof(LRESULT
);
440 Status
= KeUserModeCallback(USER32_CALLBACK_LOADSYSMENUTEMPLATE
,
445 if (NT_SUCCESS(Status
))
447 /* Simulate old behaviour: copy into our local buffer */
450 ProbeForRead(ResultPointer
, sizeof(LRESULT
), 1);
451 Result
= *(LRESULT
*)ResultPointer
;
453 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
462 return (HMENU
)Result
;
465 extern HCURSOR gDesktopCursor
;
468 co_IntLoadDefaultCursors(VOID
)
473 BOOL DefaultCursor
= TRUE
;
475 /* Do not allow the desktop thread to do callback to user mode */
476 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
478 ResultPointer
= NULL
;
479 ResultLength
= sizeof(HCURSOR
);
483 Status
= KeUserModeCallback(USER32_CALLBACK_LOADDEFAULTCURSORS
,
491 if (!NT_SUCCESS(Status
))
496 /* HACK: The desktop class doen't have a proper cursor yet, so set it here */
497 gDesktopCursor
= *((HCURSOR
*)ResultPointer
);
503 co_IntCallHookProc(INT HookId
,
511 PUNICODE_STRING ModuleName
)
513 ULONG ArgumentLength
;
514 PVOID Argument
= NULL
;
519 PHOOKPROC_CALLBACK_ARGUMENTS Common
;
520 CBT_CREATEWNDW
*CbtCreateWnd
= NULL
;
522 PHOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS CbtCreatewndExtra
= NULL
;
530 /* Do not allow the desktop thread to do callback to user mode */
531 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
533 pti
= PsGetCurrentThreadWin32Thread();
534 if (pti
->TIF_flags
& TIF_INCLEANUP
)
536 ERR("Thread is in cleanup and trying to call hook %d\n", Code
);
540 ArgumentLength
= sizeof(HOOKPROC_CALLBACK_ARGUMENTS
);
545 TRACE("WH_CBT: Code %d\n", Code
);
549 pWnd
= UserGetWindowObject((HWND
) wParam
);
552 ERR("WH_CBT HCBT_CREATEWND wParam bad hWnd!\n");
555 TRACE("HCBT_CREATEWND AnsiCreator %s, AnsiHook %s\n", pWnd
->state
& WNDS_ANSICREATOR
? "True" : "False", Ansi
? "True" : "False");
556 // Due to KsStudio.exe, just pass the callers original pointers
557 // except class which point to kernel space if not an atom.
558 // Found by, Olaf Siejka
559 CbtCreateWnd
= (CBT_CREATEWNDW
*) lParam
;
560 ArgumentLength
+= sizeof(HOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS
);
564 ArgumentLength
+= sizeof(RECTL
);
567 ArgumentLength
+= sizeof(CBTACTIVATESTRUCT
);
569 case HCBT_CLICKSKIPPED
:
570 ArgumentLength
+= sizeof(MOUSEHOOKSTRUCT
);
573 case HCBT_KEYSKIPPED
:
576 case HCBT_SYSCOMMAND
:
577 /* These types pass through. */
578 case HCBT_DESTROYWND
:
582 ERR("Trying to call unsupported CBT hook %d\n", Code
);
587 ArgumentLength
+= sizeof(KBDLLHOOKSTRUCT
);
590 ArgumentLength
+= sizeof(MSLLHOOKSTRUCT
);
593 ArgumentLength
+= sizeof(MOUSEHOOKSTRUCT
);
597 CWPSTRUCT
* pCWP
= (CWPSTRUCT
*) lParam
;
598 ArgumentLength
+= sizeof(CWPSTRUCT
);
599 lParamSize
= lParamMemorySize(pCWP
->message
, pCWP
->wParam
, pCWP
->lParam
);
600 ArgumentLength
+= lParamSize
;
603 case WH_CALLWNDPROCRET
:
605 CWPRETSTRUCT
* pCWPR
= (CWPRETSTRUCT
*) lParam
;
606 ArgumentLength
+= sizeof(CWPRETSTRUCT
);
607 lParamSize
= lParamMemorySize(pCWPR
->message
, pCWPR
->wParam
, pCWPR
->lParam
);
608 ArgumentLength
+= lParamSize
;
612 case WH_SYSMSGFILTER
:
614 ArgumentLength
+= sizeof(MSG
);
616 case WH_FOREGROUNDIDLE
:
621 ERR("Trying to call unsupported window hook %d\n", HookId
);
625 Argument
= IntCbAllocateMemory(ArgumentLength
);
626 if (NULL
== Argument
)
628 ERR("HookProc callback failed: out of memory\n");
631 Common
= (PHOOKPROC_CALLBACK_ARGUMENTS
) Argument
;
632 Common
->HookId
= HookId
;
634 Common
->wParam
= wParam
;
635 Common
->lParam
= lParam
;
638 Common
->offPfn
= offPfn
;
640 RtlZeroMemory(&Common
->ModuleName
, sizeof(Common
->ModuleName
));
641 RtlCopyMemory(&Common
->ModuleName
, ModuleName
->Buffer
, ModuleName
->Length
);
642 Extra
= (PCHAR
) Common
+ sizeof(HOOKPROC_CALLBACK_ARGUMENTS
);
648 { // Need to remember this is not the first time through! Call Next Hook?
650 CbtCreatewndExtra
= (PHOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS
) Extra
;
651 RtlCopyMemory( &CbtCreatewndExtra
->Cs
, CbtCreateWnd
->lpcs
, sizeof(CREATESTRUCTW
) );
652 CbtCreatewndExtra
->WndInsertAfter
= CbtCreateWnd
->hwndInsertAfter
;
653 CbtCreatewndExtra
->Cs
.lpszClass
= CbtCreateWnd
->lpcs
->lpszClass
;
654 CbtCreatewndExtra
->Cs
.lpszName
= CbtCreateWnd
->lpcs
->lpszName
;
655 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
657 case HCBT_CLICKSKIPPED
:
658 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(MOUSEHOOKSTRUCT
));
659 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
662 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(RECTL
));
663 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
666 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(CBTACTIVATESTRUCT
));
667 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
672 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(KBDLLHOOKSTRUCT
));
673 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
676 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(MSLLHOOKSTRUCT
));
677 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
680 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(MOUSEHOOKSTRUCT
));
681 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
684 /* For CALLWNDPROC and CALLWNDPROCRET, we must be wary of the fact that
685 * lParam could be a pointer to a buffer. This buffer must be exported
686 * to user space too */
687 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(CWPSTRUCT
));
688 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
691 RtlCopyMemory(Extra
+ sizeof(CWPSTRUCT
), (PVOID
)((CWPSTRUCT
*)lParam
)->lParam
, lParamSize
);
692 ((CWPSTRUCT
*)Extra
)->lParam
= (LPARAM
)lParamSize
;
695 case WH_CALLWNDPROCRET
:
696 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(CWPRETSTRUCT
));
697 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
700 RtlCopyMemory(Extra
+ sizeof(CWPRETSTRUCT
), (PVOID
)((CWPRETSTRUCT
*)lParam
)->lParam
, lParamSize
);
701 ((CWPRETSTRUCT
*)Extra
)->lParam
= (LPARAM
)lParamSize
;
705 case WH_SYSMSGFILTER
:
708 RtlCopyMemory(Extra
, (PVOID
) pMsg
, sizeof(MSG
));
709 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
711 case WH_FOREGROUNDIDLE
:
717 ResultPointer
= NULL
;
718 ResultLength
= ArgumentLength
;
722 Status
= KeUserModeCallback(USER32_CALLBACK_HOOKPROC
,
730 if (!NT_SUCCESS(Status
))
732 ERR("Failure to make Callback! Status 0x%x",Status
);
740 /* Simulate old behaviour: copy into our local buffer */
741 RtlMoveMemory(Argument
, ResultPointer
, ArgumentLength
);
742 Result
= Common
->Result
;
744 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
753 ERR("ERROR: Hook %d Code %d ResultPointer 0x%p ResultLength %u\n",HookId
,Code
,ResultPointer
,ResultLength
);
756 /* Support write backs... SEH is in UserCallNextHookEx. */
764 if (CbtCreatewndExtra
)
766 The parameters could have been changed, include the coordinates
767 and dimensions of the window. We copy it back.
769 CbtCreateWnd
->hwndInsertAfter
= CbtCreatewndExtra
->WndInsertAfter
;
770 CbtCreateWnd
->lpcs
->x
= CbtCreatewndExtra
->Cs
.x
;
771 CbtCreateWnd
->lpcs
->y
= CbtCreatewndExtra
->Cs
.y
;
772 CbtCreateWnd
->lpcs
->cx
= CbtCreatewndExtra
->Cs
.cx
;
773 CbtCreateWnd
->lpcs
->cy
= CbtCreatewndExtra
->Cs
.cy
;
779 RtlCopyMemory((PVOID
) lParam
, Extra
, sizeof(RECTL
));
784 // "The GetMsgProc hook procedure can examine or modify the message."
788 RtlCopyMemory((PVOID
) pMsg
, Extra
, sizeof(MSG
));
796 ERR("Exception CallHookProc HookId %d Code %d\n",HookId
,Code
);
798 if (Argument
) IntCbFreeMemory(Argument
);
804 // Events are notifications w/o results.
808 co_IntCallEventProc(HWINEVENTHOOK hook
,
821 PEVENTPROC_CALLBACK_ARGUMENTS Common
;
822 ULONG ArgumentLength
, ResultLength
;
823 PVOID Argument
, ResultPointer
;
825 ArgumentLength
= sizeof(EVENTPROC_CALLBACK_ARGUMENTS
);
827 Argument
= IntCbAllocateMemory(ArgumentLength
);
828 if (NULL
== Argument
)
830 ERR("EventProc callback failed: out of memory\n");
833 Common
= (PEVENTPROC_CALLBACK_ARGUMENTS
) Argument
;
835 Common
->event
= event
;
837 Common
->idObject
= idObject
;
838 Common
->idChild
= idChild
;
839 Common
->dwEventThread
= dwEventThread
;
840 Common
->dwmsEventTime
= dwmsEventTime
;
843 Common
->offPfn
= offPfn
;
845 ResultPointer
= NULL
;
846 ResultLength
= sizeof(LRESULT
);
850 Status
= KeUserModeCallback(USER32_CALLBACK_EVENTPROC
,
858 IntCbFreeMemory(Argument
);
860 if (!NT_SUCCESS(Status
))
869 // Callback Load Menu and results.
873 co_IntCallLoadMenu( HINSTANCE hModule
,
874 PUNICODE_STRING pMenuName
)
878 PLOADMENU_CALLBACK_ARGUMENTS Common
;
879 ULONG ArgumentLength
, ResultLength
;
880 PVOID Argument
, ResultPointer
;
882 ArgumentLength
= sizeof(LOADMENU_CALLBACK_ARGUMENTS
);
884 ArgumentLength
+= pMenuName
->Length
+ sizeof(WCHAR
);
886 Argument
= IntCbAllocateMemory(ArgumentLength
);
887 if (NULL
== Argument
)
889 ERR("LoadMenu callback failed: out of memory\n");
892 Common
= (PLOADMENU_CALLBACK_ARGUMENTS
) Argument
;
894 // Help Intersource check and MenuName is now 4 bytes + so zero it.
895 RtlZeroMemory(Common
, ArgumentLength
);
897 Common
->hModule
= hModule
;
898 if (pMenuName
->Length
)
899 RtlCopyMemory(&Common
->MenuName
, pMenuName
->Buffer
, pMenuName
->Length
);
901 Common
->InterSource
= pMenuName
->Buffer
;
903 ResultPointer
= NULL
;
904 ResultLength
= sizeof(LRESULT
);
908 Status
= KeUserModeCallback(USER32_CALLBACK_LOADMENU
,
916 if (NT_SUCCESS(Status
))
918 Result
= *(LRESULT
*)ResultPointer
;
925 IntCbFreeMemory(Argument
);
927 return (HMENU
)Result
;
932 co_IntClientThreadSetup(VOID
)
935 ULONG ArgumentLength
, ResultLength
;
936 PVOID Argument
, ResultPointer
;
938 /* Do not allow the desktop thread to do callback to user mode */
939 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
941 ArgumentLength
= ResultLength
= 0;
942 Argument
= ResultPointer
= NULL
;
946 Status
= KeUserModeCallback(USER32_CALLBACK_CLIENTTHREADSTARTUP
,
958 co_IntCopyImage(HANDLE hnd
, UINT type
, INT desiredx
, INT desiredy
, UINT flags
)
962 ULONG ArgumentLength
, ResultLength
;
963 PVOID Argument
, ResultPointer
;
964 PCOPYIMAGE_CALLBACK_ARGUMENTS Common
;
966 ArgumentLength
= ResultLength
= 0;
967 Argument
= ResultPointer
= NULL
;
969 ArgumentLength
= sizeof(COPYIMAGE_CALLBACK_ARGUMENTS
);
971 Argument
= IntCbAllocateMemory(ArgumentLength
);
972 if (NULL
== Argument
)
974 ERR("CopyImage callback failed: out of memory\n");
977 Common
= (PCOPYIMAGE_CALLBACK_ARGUMENTS
) Argument
;
979 Common
->hImage
= hnd
;
980 Common
->uType
= type
;
981 Common
->cxDesired
= desiredx
;
982 Common
->cyDesired
= desiredy
;
983 Common
->fuFlags
= flags
;
987 Status
= KeUserModeCallback(USER32_CALLBACK_COPYIMAGE
,
996 if (NT_SUCCESS(Status
))
998 Handle
= *(HANDLE
*)ResultPointer
;
1002 ERR("CopyImage callback failed!\n");
1006 IntCbFreeMemory(Argument
);
1013 co_IntGetCharsetInfo(LCID Locale
, PCHARSETINFO pCs
)
1016 ULONG ArgumentLength
, ResultLength
;
1017 PVOID Argument
, ResultPointer
;
1018 PGET_CHARSET_INFO Common
;
1020 ArgumentLength
= sizeof(GET_CHARSET_INFO
);
1022 Argument
= IntCbAllocateMemory(ArgumentLength
);
1023 if (NULL
== Argument
)
1025 ERR("GetCharsetInfo callback failed: out of memory\n");
1028 Common
= (PGET_CHARSET_INFO
) Argument
;
1030 Common
->Locale
= Locale
;
1032 ResultPointer
= NULL
;
1033 ResultLength
= ArgumentLength
;
1037 Status
= KeUserModeCallback(USER32_CALLBACK_GETCHARSETINFO
,
1043 if (NT_SUCCESS(Status
))
1047 /* Need to copy into our local buffer */
1048 RtlMoveMemory(Argument
, ResultPointer
, ArgumentLength
);
1050 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1052 ERR("Failed to copy result from user mode!\n");
1053 Status
= _SEH2_GetExceptionCode();
1060 RtlCopyMemory(pCs
, &Common
->Cs
, sizeof(CHARSETINFO
));
1062 IntCbFreeMemory(Argument
);
1064 if (!NT_SUCCESS(Status
))
1066 ERR("GetCharsetInfo Failed!!\n");
1074 co_IntSetWndIcons(VOID
)
1077 ULONG ArgumentLength
, ResultLength
;
1078 PVOID Argument
, ResultPointer
;
1079 PSETWNDICONS_CALLBACK_ARGUMENTS Common
;
1081 ResultPointer
= NULL
;
1082 ResultLength
= ArgumentLength
= sizeof(SETWNDICONS_CALLBACK_ARGUMENTS
);
1084 Argument
= IntCbAllocateMemory(ArgumentLength
);
1085 if (NULL
== Argument
)
1087 ERR("Set Window Icons callback failed: out of memory\n");
1090 Common
= (PSETWNDICONS_CALLBACK_ARGUMENTS
) Argument
;
1094 Status
= KeUserModeCallback(USER32_CALLBACK_SETWNDICONS
,
1103 if (!NT_SUCCESS(Status
))
1105 ERR("Set Window Icons callback failed!\n");
1106 IntCbFreeMemory(Argument
);
1110 RtlMoveMemory(Common
, ResultPointer
, ArgumentLength
);
1111 gpsi
->hIconSmWindows
= Common
->hIconSmWindows
;
1112 gpsi
->hIconWindows
= Common
->hIconWindows
;
1114 IntLoadSystenIcons(Common
->hIconSample
, OIC_SAMPLE
);
1115 IntLoadSystenIcons(Common
->hIconHand
, OIC_HAND
);
1116 IntLoadSystenIcons(Common
->hIconQuestion
, OIC_QUES
);
1117 IntLoadSystenIcons(Common
->hIconBang
, OIC_BANG
);
1118 IntLoadSystenIcons(Common
->hIconNote
, OIC_NOTE
);
1119 IntLoadSystenIcons(gpsi
->hIconWindows
, OIC_WINLOGO
);
1120 IntLoadSystenIcons(gpsi
->hIconSmWindows
, OIC_WINLOGO
+1);
1122 ERR("hIconSmWindows %p hIconWindows %p \n",gpsi
->hIconSmWindows
,gpsi
->hIconWindows
);
1124 IntCbFreeMemory(Argument
);
1130 co_IntDeliverUserAPC(VOID
)
1133 PVOID ResultPointer
;
1137 Status
= KeUserModeCallback(USER32_CALLBACK_DELIVERUSERAPC
,
1146 if (!NT_SUCCESS(Status
))
1148 ERR("Delivering User APC callback failed!\n");
1153 co_IntSetupOBM(VOID
)
1156 ULONG ArgumentLength
, ResultLength
;
1157 PVOID Argument
, ResultPointer
;
1158 PSETOBM_CALLBACK_ARGUMENTS Common
;
1160 ResultPointer
= NULL
;
1161 ResultLength
= ArgumentLength
= sizeof(SETOBM_CALLBACK_ARGUMENTS
);
1163 Argument
= IntCbAllocateMemory(ArgumentLength
);
1164 if (NULL
== Argument
)
1166 ERR("Set Window Icons callback failed: out of memory\n");
1169 Common
= (PSETOBM_CALLBACK_ARGUMENTS
) Argument
;
1173 Status
= KeUserModeCallback(USER32_CALLBACK_SETOBM
,
1182 if (!NT_SUCCESS(Status
))
1184 ERR("Set Window Icons callback failed!\n");
1185 IntCbFreeMemory(Argument
);
1189 RtlMoveMemory(Common
, ResultPointer
, ArgumentLength
);
1190 RtlCopyMemory(gpsi
->oembmi
, Common
->oembmi
, sizeof(gpsi
->oembmi
));
1192 IntCbFreeMemory(Argument
);