2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
4 * PURPOSE: Callback to usermode support
5 * FILE: subsystems/win32/win32k/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
,
344 /* Simulate old behaviour: copy into our local buffer */
345 RtlMoveMemory(Arguments
, ResultPointer
, ArgumentLength
);
347 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
349 ERR("Failed to copy result from user mode, Message %d lParam size %d!\n", Message
, lParamBufferSize
);
350 Status
= _SEH2_GetExceptionCode();
356 IntRestoreTebWndCallback (Wnd
, pWnd
, pActCtx
);
358 if (!NT_SUCCESS(Status
))
360 ERR("Call to user mode failed!\n");
361 if (lParamBufferSize
!= -1)
363 IntCbFreeMemory(Arguments
);
367 Result
= Arguments
->Result
;
369 if (lParamBufferSize
!= -1)
371 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
372 // Is this message being processed from inside kernel space?
373 BOOL InSendMessage
= (pti
->pcti
->CTI_flags
& CTI_INSENDMESSAGE
);
375 TRACE("Copy lParam Message %d lParam %d!\n", Message
, lParam
);
379 TRACE("Don't copy lParam, Message %d Size %d lParam %d!\n", Message
, lParamBufferSize
, lParam
);
381 // Write back to user/kernel space. Also see g_MsgMemory.
383 case WM_GETMINMAXINFO
:
387 case WM_STYLECHANGING
:
388 case WM_WINDOWPOSCHANGING
:
391 TRACE("Copy lParam, Message %d Size %d lParam %d!\n", Message
, lParamBufferSize
, lParam
);
393 // Copy into kernel space.
394 RtlMoveMemory((PVOID
) lParam
,
395 (PVOID
) ((char *) Arguments
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)),
400 { // Copy into user space.
401 RtlMoveMemory((PVOID
) lParam
,
402 (PVOID
) ((char *) Arguments
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)),
405 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
407 ERR("Failed to copy lParam to user space, Message %d!\n", Message
);
413 IntCbFreeMemory(Arguments
);
420 co_IntLoadSysMenuTemplate()
427 /* Do not allow the desktop thread to do callback to user mode */
428 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
430 ResultPointer
= NULL
;
431 ResultLength
= sizeof(LRESULT
);
435 Status
= KeUserModeCallback(USER32_CALLBACK_LOADSYSMENUTEMPLATE
,
440 if (NT_SUCCESS(Status
))
442 /* Simulate old behaviour: copy into our local buffer */
445 ProbeForRead(ResultPointer
, sizeof(LRESULT
), 1);
446 Result
= *(LRESULT
*)ResultPointer
;
448 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
457 return (HMENU
)Result
;
460 extern HCURSOR gDesktopCursor
;
463 co_IntLoadDefaultCursors(VOID
)
468 BOOL DefaultCursor
= TRUE
;
470 /* Do not allow the desktop thread to do callback to user mode */
471 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
473 ResultPointer
= NULL
;
474 ResultLength
= sizeof(HCURSOR
);
478 Status
= KeUserModeCallback(USER32_CALLBACK_LOADDEFAULTCURSORS
,
486 /* HACK: The desktop class doen't have a proper cursor yet, so set it here */
487 gDesktopCursor
= *((HCURSOR
*)ResultPointer
);
489 if (!NT_SUCCESS(Status
))
497 co_IntCallHookProc(INT HookId
,
505 PUNICODE_STRING ModuleName
)
507 ULONG ArgumentLength
;
508 PVOID Argument
= NULL
;
513 PHOOKPROC_CALLBACK_ARGUMENTS Common
;
514 CBT_CREATEWNDW
*CbtCreateWnd
= NULL
;
516 PHOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS CbtCreatewndExtra
= NULL
;
524 /* Do not allow the desktop thread to do callback to user mode */
525 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
527 pti
= PsGetCurrentThreadWin32Thread();
528 if (pti
->TIF_flags
& TIF_INCLEANUP
)
530 ERR("Thread is in cleanup and trying to call hook %d\n", Code
);
534 ArgumentLength
= sizeof(HOOKPROC_CALLBACK_ARGUMENTS
);
539 TRACE("WH_CBT: Code %d\n", Code
);
543 pWnd
= UserGetWindowObject((HWND
) wParam
);
546 ERR("WH_CBT HCBT_CREATEWND wParam bad hWnd!\n");
549 TRACE("HCBT_CREATEWND AnsiCreator %s, AnsiHook %s\n", pWnd
->state
& WNDS_ANSICREATOR
? "True" : "False", Ansi
? "True" : "False");
550 // Due to KsStudio.exe, just pass the callers original pointers
551 // except class which point to kernel space if not an atom.
552 // Found by, Olaf Siejka
553 CbtCreateWnd
= (CBT_CREATEWNDW
*) lParam
;
554 ArgumentLength
+= sizeof(HOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS
);
558 ArgumentLength
+= sizeof(RECTL
);
561 ArgumentLength
+= sizeof(CBTACTIVATESTRUCT
);
563 case HCBT_CLICKSKIPPED
:
564 ArgumentLength
+= sizeof(MOUSEHOOKSTRUCT
);
567 case HCBT_KEYSKIPPED
:
570 case HCBT_SYSCOMMAND
:
571 /* These types pass through. */
572 case HCBT_DESTROYWND
:
576 ERR("Trying to call unsupported CBT hook %d\n", Code
);
581 ArgumentLength
+= sizeof(KBDLLHOOKSTRUCT
);
584 ArgumentLength
+= sizeof(MSLLHOOKSTRUCT
);
587 ArgumentLength
+= sizeof(MOUSEHOOKSTRUCT
);
591 CWPSTRUCT
* pCWP
= (CWPSTRUCT
*) lParam
;
592 ArgumentLength
+= sizeof(CWPSTRUCT
);
593 lParamSize
= lParamMemorySize(pCWP
->message
, pCWP
->wParam
, pCWP
->lParam
);
594 ArgumentLength
+= lParamSize
;
597 case WH_CALLWNDPROCRET
:
599 CWPRETSTRUCT
* pCWPR
= (CWPRETSTRUCT
*) lParam
;
600 ArgumentLength
+= sizeof(CWPRETSTRUCT
);
601 lParamSize
= lParamMemorySize(pCWPR
->message
, pCWPR
->wParam
, pCWPR
->lParam
);
602 ArgumentLength
+= lParamSize
;
606 case WH_SYSMSGFILTER
:
608 ArgumentLength
+= sizeof(MSG
);
610 case WH_FOREGROUNDIDLE
:
615 ERR("Trying to call unsupported window hook %d\n", HookId
);
619 Argument
= IntCbAllocateMemory(ArgumentLength
);
620 if (NULL
== Argument
)
622 ERR("HookProc callback failed: out of memory\n");
625 Common
= (PHOOKPROC_CALLBACK_ARGUMENTS
) Argument
;
626 Common
->HookId
= HookId
;
628 Common
->wParam
= wParam
;
629 Common
->lParam
= lParam
;
632 Common
->offPfn
= offPfn
;
634 RtlZeroMemory(&Common
->ModuleName
, sizeof(Common
->ModuleName
));
635 RtlCopyMemory(&Common
->ModuleName
, ModuleName
->Buffer
, ModuleName
->Length
);
636 Extra
= (PCHAR
) Common
+ sizeof(HOOKPROC_CALLBACK_ARGUMENTS
);
642 { // Need to remember this is not the first time through! Call Next Hook?
644 CbtCreatewndExtra
= (PHOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS
) Extra
;
645 RtlCopyMemory( &CbtCreatewndExtra
->Cs
, CbtCreateWnd
->lpcs
, sizeof(CREATESTRUCTW
) );
646 CbtCreatewndExtra
->WndInsertAfter
= CbtCreateWnd
->hwndInsertAfter
;
647 CbtCreatewndExtra
->Cs
.lpszClass
= CbtCreateWnd
->lpcs
->lpszClass
;
648 CbtCreatewndExtra
->Cs
.lpszName
= CbtCreateWnd
->lpcs
->lpszName
;
649 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
651 case HCBT_CLICKSKIPPED
:
652 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(MOUSEHOOKSTRUCT
));
653 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
656 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(RECTL
));
657 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
660 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(CBTACTIVATESTRUCT
));
661 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
666 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(KBDLLHOOKSTRUCT
));
667 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
670 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(MSLLHOOKSTRUCT
));
671 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
674 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(MOUSEHOOKSTRUCT
));
675 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
678 /* For CALLWNDPROC and CALLWNDPROCRET, we must be wary of the fact that
679 * lParam could be a pointer to a buffer. This buffer must be exported
680 * to user space too */
681 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(CWPSTRUCT
));
682 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
685 RtlCopyMemory(Extra
+ sizeof(CWPSTRUCT
), (PVOID
)((CWPSTRUCT
*)lParam
)->lParam
, lParamSize
);
686 ((CWPSTRUCT
*)Extra
)->lParam
= (LPARAM
)lParamSize
;
689 case WH_CALLWNDPROCRET
:
690 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(CWPRETSTRUCT
));
691 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
694 RtlCopyMemory(Extra
+ sizeof(CWPRETSTRUCT
), (PVOID
)((CWPRETSTRUCT
*)lParam
)->lParam
, lParamSize
);
695 ((CWPRETSTRUCT
*)Extra
)->lParam
= (LPARAM
)lParamSize
;
699 case WH_SYSMSGFILTER
:
702 RtlCopyMemory(Extra
, (PVOID
) pMsg
, sizeof(MSG
));
703 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
705 case WH_FOREGROUNDIDLE
:
711 ResultPointer
= NULL
;
712 ResultLength
= ArgumentLength
;
716 Status
= KeUserModeCallback(USER32_CALLBACK_HOOKPROC
,
728 /* Simulate old behaviour: copy into our local buffer */
729 RtlMoveMemory(Argument
, ResultPointer
, ArgumentLength
);
730 Result
= Common
->Result
;
732 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
741 ERR("ERROR: Hook %d Code %d ResultPointer 0x%p ResultLength %u\n",HookId
,Code
,ResultPointer
,ResultLength
);
744 if (!NT_SUCCESS(Status
))
746 ERR("Failure to make Callback! Status 0x%x",Status
);
749 /* Support write backs... SEH is in UserCallNextHookEx. */
757 if (CbtCreatewndExtra
)
759 The parameters could have been changed, include the coordinates
760 and dimensions of the window. We copy it back.
762 CbtCreateWnd
->hwndInsertAfter
= CbtCreatewndExtra
->WndInsertAfter
;
763 CbtCreateWnd
->lpcs
->x
= CbtCreatewndExtra
->Cs
.x
;
764 CbtCreateWnd
->lpcs
->y
= CbtCreatewndExtra
->Cs
.y
;
765 CbtCreateWnd
->lpcs
->cx
= CbtCreatewndExtra
->Cs
.cx
;
766 CbtCreateWnd
->lpcs
->cy
= CbtCreatewndExtra
->Cs
.cy
;
772 RtlCopyMemory((PVOID
) lParam
, Extra
, sizeof(RECTL
));
777 // "The GetMsgProc hook procedure can examine or modify the message."
781 RtlCopyMemory((PVOID
) pMsg
, Extra
, sizeof(MSG
));
789 ERR("Exception CallHookProc HookId %d Code %d\n",HookId
,Code
);
791 if (Argument
) IntCbFreeMemory(Argument
);
797 // Events are notifications w/o results.
801 co_IntCallEventProc(HWINEVENTHOOK hook
,
812 PEVENTPROC_CALLBACK_ARGUMENTS Common
;
813 ULONG ArgumentLength
, ResultLength
;
814 PVOID Argument
, ResultPointer
;
816 ArgumentLength
= sizeof(EVENTPROC_CALLBACK_ARGUMENTS
);
818 Argument
= IntCbAllocateMemory(ArgumentLength
);
819 if (NULL
== Argument
)
821 ERR("EventProc callback failed: out of memory\n");
824 Common
= (PEVENTPROC_CALLBACK_ARGUMENTS
) Argument
;
826 Common
->event
= event
;
828 Common
->idObject
= idObject
;
829 Common
->idChild
= idChild
;
830 Common
->dwEventThread
= dwEventThread
;
831 Common
->dwmsEventTime
= dwmsEventTime
;
834 ResultPointer
= NULL
;
835 ResultLength
= sizeof(LRESULT
);
839 Status
= KeUserModeCallback(USER32_CALLBACK_EVENTPROC
,
847 IntCbFreeMemory(Argument
);
849 if (!NT_SUCCESS(Status
))
858 // Callback Load Menu and results.
862 co_IntCallLoadMenu( HINSTANCE hModule
,
863 PUNICODE_STRING pMenuName
)
867 PLOADMENU_CALLBACK_ARGUMENTS Common
;
868 ULONG ArgumentLength
, ResultLength
;
869 PVOID Argument
, ResultPointer
;
871 ArgumentLength
= sizeof(LOADMENU_CALLBACK_ARGUMENTS
);
873 ArgumentLength
+= pMenuName
->Length
+ sizeof(WCHAR
);
875 Argument
= IntCbAllocateMemory(ArgumentLength
);
876 if (NULL
== Argument
)
878 ERR("LoadMenu callback failed: out of memory\n");
881 Common
= (PLOADMENU_CALLBACK_ARGUMENTS
) Argument
;
883 // Help Intersource check and MenuName is now 4 bytes + so zero it.
884 RtlZeroMemory(Common
, ArgumentLength
);
886 Common
->hModule
= hModule
;
887 if (pMenuName
->Length
)
888 RtlCopyMemory(&Common
->MenuName
, pMenuName
->Buffer
, pMenuName
->Length
);
890 Common
->InterSource
= pMenuName
->Buffer
;
892 ResultPointer
= NULL
;
893 ResultLength
= sizeof(LRESULT
);
897 Status
= KeUserModeCallback(USER32_CALLBACK_LOADMENU
,
905 Result
= *(LRESULT
*)ResultPointer
;
907 IntCbFreeMemory(Argument
);
909 if (!NT_SUCCESS(Status
))
914 return (HMENU
)Result
;
919 co_IntClientThreadSetup(VOID
)
922 ULONG ArgumentLength
, ResultLength
;
923 PVOID Argument
, ResultPointer
;
925 /* Do not allow the desktop thread to do callback to user mode */
926 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
928 ArgumentLength
= ResultLength
= 0;
929 Argument
= ResultPointer
= NULL
;
933 Status
= KeUserModeCallback(USER32_CALLBACK_CLIENTTHREADSTARTUP
,
945 co_IntCopyImage(HANDLE hnd
, UINT type
, INT desiredx
, INT desiredy
, UINT flags
)
949 ULONG ArgumentLength
, ResultLength
;
950 PVOID Argument
, ResultPointer
;
951 PCOPYIMAGE_CALLBACK_ARGUMENTS Common
;
953 ArgumentLength
= ResultLength
= 0;
954 Argument
= ResultPointer
= NULL
;
956 ArgumentLength
= sizeof(COPYIMAGE_CALLBACK_ARGUMENTS
);
958 Argument
= IntCbAllocateMemory(ArgumentLength
);
959 if (NULL
== Argument
)
961 ERR("CopyImage callback failed: out of memory\n");
964 Common
= (PCOPYIMAGE_CALLBACK_ARGUMENTS
) Argument
;
966 Common
->hImage
= hnd
;
967 Common
->uType
= type
;
968 Common
->cxDesired
= desiredx
;
969 Common
->cyDesired
= desiredy
;
970 Common
->fuFlags
= flags
;
974 Status
= KeUserModeCallback(USER32_CALLBACK_COPYIMAGE
,
983 Handle
= *(HANDLE
*)ResultPointer
;
985 IntCbFreeMemory(Argument
);
987 if (!NT_SUCCESS(Status
))
989 ERR("CopyImage callback failed!\n");
998 co_IntGetCharsetInfo(LCID Locale
, PCHARSETINFO pCs
)
1001 ULONG ArgumentLength
, ResultLength
;
1002 PVOID Argument
, ResultPointer
;
1003 PGET_CHARSET_INFO Common
;
1005 ArgumentLength
= sizeof(GET_CHARSET_INFO
);
1007 Argument
= IntCbAllocateMemory(ArgumentLength
);
1008 if (NULL
== Argument
)
1010 ERR("GetCharsetInfo callback failed: out of memory\n");
1013 Common
= (PGET_CHARSET_INFO
) Argument
;
1015 Common
->Locale
= Locale
;
1017 ResultPointer
= NULL
;
1018 ResultLength
= ArgumentLength
;
1022 Status
= KeUserModeCallback(USER32_CALLBACK_GETCHARSETINFO
,
1030 /* Need to copy into our local buffer */
1031 RtlMoveMemory(Argument
, ResultPointer
, ArgumentLength
);
1033 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1035 ERR("Failed to copy result from user mode!\n");
1036 Status
= _SEH2_GetExceptionCode();
1042 RtlCopyMemory(pCs
, &Common
->Cs
, sizeof(CHARSETINFO
));
1044 IntCbFreeMemory(Argument
);
1046 if (!NT_SUCCESS(Status
))
1048 ERR("GetCharsetInfo Failed!!\n");
1056 co_IntSetWndIcons(VOID
)
1059 ULONG ArgumentLength
, ResultLength
;
1060 PVOID Argument
, ResultPointer
;
1061 PSETWNDICONS_CALLBACK_ARGUMENTS Common
;
1063 ResultPointer
= NULL
;
1064 ResultLength
= ArgumentLength
= sizeof(SETWNDICONS_CALLBACK_ARGUMENTS
);
1066 Argument
= IntCbAllocateMemory(ArgumentLength
);
1067 if (NULL
== Argument
)
1069 ERR("Set Window Icons callback failed: out of memory\n");
1072 Common
= (PSETWNDICONS_CALLBACK_ARGUMENTS
) Argument
;
1076 Status
= KeUserModeCallback(USER32_CALLBACK_SETWNDICONS
,
1085 /* FIXME: Need to setup Registry System Cursor & Icons via Callbacks at init time! */
1086 RtlMoveMemory(Common
, ResultPointer
, ArgumentLength
);
1087 gpsi
->hIconSmWindows
= Common
->hIconSmWindows
;
1088 gpsi
->hIconWindows
= Common
->hIconWindows
;
1090 ERR("hIconSmWindows %p hIconWindows %p \n",gpsi
->hIconSmWindows
,gpsi
->hIconWindows
);
1092 IntCbFreeMemory(Argument
);
1094 if (!NT_SUCCESS(Status
))
1096 ERR("Set Window Icons callback failed!\n");