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 /* Do not allow the desktop thread to do callback to user mode */
300 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
302 if (lParamBufferSize
!= -1)
304 ArgumentLength
= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
) + lParamBufferSize
;
305 Arguments
= IntCbAllocateMemory(ArgumentLength
);
306 if (NULL
== Arguments
)
308 ERR("Unable to allocate buffer for window proc callback\n");
311 RtlMoveMemory((PVOID
) ((char *) Arguments
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)),
312 (PVOID
) lParam
, lParamBufferSize
);
316 Arguments
= &StackArguments
;
317 ArgumentLength
= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
);
319 Arguments
->Proc
= Proc
;
320 Arguments
->IsAnsiProc
= IsAnsiProc
;
321 Arguments
->Wnd
= Wnd
;
322 Arguments
->Msg
= Message
;
323 Arguments
->wParam
= wParam
;
324 Arguments
->lParam
= lParam
;
325 Arguments
->lParamBufferSize
= lParamBufferSize
;
326 ResultPointer
= NULL
;
327 ResultLength
= ArgumentLength
;
329 IntSetTebWndCallback (&Wnd
, &pWnd
, &pActCtx
);
333 Status
= KeUserModeCallback(USER32_CALLBACK_WINDOWPROC
,
341 /* Simulate old behaviour: copy into our local buffer */
342 RtlMoveMemory(Arguments
, ResultPointer
, ArgumentLength
);
344 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
346 ERR("Failed to copy result from user mode, Message %d lParam size %d!\n", Message
, lParamBufferSize
);
347 Status
= _SEH2_GetExceptionCode();
353 IntRestoreTebWndCallback (Wnd
, pWnd
, pActCtx
);
355 if (!NT_SUCCESS(Status
))
357 ERR("Call to user mode failed!\n");
358 if (lParamBufferSize
!= -1)
360 IntCbFreeMemory(Arguments
);
364 Result
= Arguments
->Result
;
366 if (lParamBufferSize
!= -1)
368 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
369 // Is this message being processed from inside kernel space?
370 BOOL InSendMessage
= (pti
->pcti
->CTI_flags
& CTI_INSENDMESSAGE
);
372 TRACE("Copy lParam Message %d lParam %d!\n", Message
, lParam
);
376 TRACE("Don't copy lParam, Message %d Size %d lParam %d!\n", Message
, lParamBufferSize
, lParam
);
378 // Write back to user/kernel space. Also see g_MsgMemory.
380 case WM_GETMINMAXINFO
:
384 case WM_STYLECHANGING
:
385 case WM_WINDOWPOSCHANGING
:
388 TRACE("Copy lParam, Message %d Size %d lParam %d!\n", Message
, lParamBufferSize
, lParam
);
390 // Copy into kernel space.
391 RtlMoveMemory((PVOID
) lParam
,
392 (PVOID
) ((char *) Arguments
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)),
397 { // Copy into user space.
398 RtlMoveMemory((PVOID
) lParam
,
399 (PVOID
) ((char *) Arguments
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)),
402 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
404 ERR("Failed to copy lParam to user space, Message %d!\n", Message
);
410 IntCbFreeMemory(Arguments
);
417 co_IntLoadSysMenuTemplate()
424 /* Do not allow the desktop thread to do callback to user mode */
425 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
427 ResultPointer
= NULL
;
428 ResultLength
= sizeof(LRESULT
);
432 Status
= KeUserModeCallback(USER32_CALLBACK_LOADSYSMENUTEMPLATE
,
437 if (NT_SUCCESS(Status
))
439 /* Simulate old behaviour: copy into our local buffer */
442 ProbeForRead(ResultPointer
, sizeof(LRESULT
), 1);
443 Result
= *(LRESULT
*)ResultPointer
;
445 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
454 return (HMENU
)Result
;
457 extern HCURSOR gDesktopCursor
;
460 co_IntLoadDefaultCursors(VOID
)
465 BOOL DefaultCursor
= TRUE
;
467 /* Do not allow the desktop thread to do callback to user mode */
468 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
470 ResultPointer
= NULL
;
471 ResultLength
= sizeof(HCURSOR
);
475 Status
= KeUserModeCallback(USER32_CALLBACK_LOADDEFAULTCURSORS
,
483 /* HACK: The desktop class doen't have a proper cursor yet, so set it here */
484 gDesktopCursor
= *((HCURSOR
*)ResultPointer
);
486 if (!NT_SUCCESS(Status
))
494 co_IntCallHookProc(INT HookId
,
502 PUNICODE_STRING ModuleName
)
504 ULONG ArgumentLength
;
505 PVOID Argument
= NULL
;
510 PHOOKPROC_CALLBACK_ARGUMENTS Common
;
511 CBT_CREATEWNDW
*CbtCreateWnd
= NULL
;
513 PHOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS CbtCreatewndExtra
= NULL
;
521 /* Do not allow the desktop thread to do callback to user mode */
522 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
524 pti
= PsGetCurrentThreadWin32Thread();
525 if (pti
->TIF_flags
& TIF_INCLEANUP
)
527 ERR("Thread is in cleanup and trying to call hook %d\n", Code
);
531 ArgumentLength
= sizeof(HOOKPROC_CALLBACK_ARGUMENTS
);
536 TRACE("WH_CBT: Code %d\n", Code
);
540 pWnd
= UserGetWindowObject((HWND
) wParam
);
543 ERR("WH_CBT HCBT_CREATEWND wParam bad hWnd!\n");
546 TRACE("HCBT_CREATEWND AnsiCreator %s, AnsiHook %s\n", pWnd
->state
& WNDS_ANSICREATOR
? "True" : "False", Ansi
? "True" : "False");
547 // Due to KsStudio.exe, just pass the callers original pointers
548 // except class which point to kernel space if not an atom.
549 // Found by, Olaf Siejka
550 CbtCreateWnd
= (CBT_CREATEWNDW
*) lParam
;
551 ArgumentLength
+= sizeof(HOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS
);
555 ArgumentLength
+= sizeof(RECTL
);
558 ArgumentLength
+= sizeof(CBTACTIVATESTRUCT
);
560 case HCBT_CLICKSKIPPED
:
561 ArgumentLength
+= sizeof(MOUSEHOOKSTRUCT
);
564 case HCBT_KEYSKIPPED
:
567 case HCBT_SYSCOMMAND
:
568 /* These types pass through. */
569 case HCBT_DESTROYWND
:
573 ERR("Trying to call unsupported CBT hook %d\n", Code
);
578 ArgumentLength
+= sizeof(KBDLLHOOKSTRUCT
);
581 ArgumentLength
+= sizeof(MSLLHOOKSTRUCT
);
584 ArgumentLength
+= sizeof(MOUSEHOOKSTRUCT
);
588 CWPSTRUCT
* pCWP
= (CWPSTRUCT
*) lParam
;
589 ArgumentLength
+= sizeof(CWPSTRUCT
);
590 lParamSize
= lParamMemorySize(pCWP
->message
, pCWP
->wParam
, pCWP
->lParam
);
591 ArgumentLength
+= lParamSize
;
594 case WH_CALLWNDPROCRET
:
596 CWPRETSTRUCT
* pCWPR
= (CWPRETSTRUCT
*) lParam
;
597 ArgumentLength
+= sizeof(CWPRETSTRUCT
);
598 lParamSize
= lParamMemorySize(pCWPR
->message
, pCWPR
->wParam
, pCWPR
->lParam
);
599 ArgumentLength
+= lParamSize
;
603 case WH_SYSMSGFILTER
:
605 ArgumentLength
+= sizeof(MSG
);
607 case WH_FOREGROUNDIDLE
:
612 ERR("Trying to call unsupported window hook %d\n", HookId
);
616 Argument
= IntCbAllocateMemory(ArgumentLength
);
617 if (NULL
== Argument
)
619 ERR("HookProc callback failed: out of memory\n");
622 Common
= (PHOOKPROC_CALLBACK_ARGUMENTS
) Argument
;
623 Common
->HookId
= HookId
;
625 Common
->wParam
= wParam
;
626 Common
->lParam
= lParam
;
629 Common
->offPfn
= offPfn
;
631 RtlZeroMemory(&Common
->ModuleName
, sizeof(Common
->ModuleName
));
632 RtlCopyMemory(&Common
->ModuleName
, ModuleName
->Buffer
, ModuleName
->Length
);
633 Extra
= (PCHAR
) Common
+ sizeof(HOOKPROC_CALLBACK_ARGUMENTS
);
639 { // Need to remember this is not the first time through! Call Next Hook?
641 CbtCreatewndExtra
= (PHOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS
) Extra
;
642 RtlCopyMemory( &CbtCreatewndExtra
->Cs
, CbtCreateWnd
->lpcs
, sizeof(CREATESTRUCTW
) );
643 CbtCreatewndExtra
->WndInsertAfter
= CbtCreateWnd
->hwndInsertAfter
;
644 CbtCreatewndExtra
->Cs
.lpszClass
= CbtCreateWnd
->lpcs
->lpszClass
;
645 CbtCreatewndExtra
->Cs
.lpszName
= CbtCreateWnd
->lpcs
->lpszName
;
646 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
648 case HCBT_CLICKSKIPPED
:
649 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(MOUSEHOOKSTRUCT
));
650 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
653 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(RECTL
));
654 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
657 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(CBTACTIVATESTRUCT
));
658 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
663 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(KBDLLHOOKSTRUCT
));
664 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
667 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(MSLLHOOKSTRUCT
));
668 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
671 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(MOUSEHOOKSTRUCT
));
672 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
675 /* For CALLWNDPROC and CALLWNDPROCRET, we must be wary of the fact that
676 * lParam could be a pointer to a buffer. This buffer must be exported
677 * to user space too */
678 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(CWPSTRUCT
));
679 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
682 RtlCopyMemory(Extra
+ sizeof(CWPSTRUCT
), (PVOID
)((CWPSTRUCT
*)lParam
)->lParam
, lParamSize
);
683 ((CWPSTRUCT
*)Extra
)->lParam
= (LPARAM
)lParamSize
;
686 case WH_CALLWNDPROCRET
:
687 RtlCopyMemory(Extra
, (PVOID
) lParam
, sizeof(CWPRETSTRUCT
));
688 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
691 RtlCopyMemory(Extra
+ sizeof(CWPRETSTRUCT
), (PVOID
)((CWPRETSTRUCT
*)lParam
)->lParam
, lParamSize
);
692 ((CWPRETSTRUCT
*)Extra
)->lParam
= (LPARAM
)lParamSize
;
696 case WH_SYSMSGFILTER
:
699 RtlCopyMemory(Extra
, (PVOID
) pMsg
, sizeof(MSG
));
700 Common
->lParam
= (LPARAM
) (Extra
- (PCHAR
) Common
);
702 case WH_FOREGROUNDIDLE
:
708 ResultPointer
= NULL
;
709 ResultLength
= ArgumentLength
;
713 Status
= KeUserModeCallback(USER32_CALLBACK_HOOKPROC
,
725 /* Simulate old behaviour: copy into our local buffer */
726 RtlMoveMemory(Argument
, ResultPointer
, ArgumentLength
);
727 Result
= Common
->Result
;
729 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
738 ERR("ERROR: Hook %d Code %d ResultPointer 0x%p ResultLength %u\n",HookId
,Code
,ResultPointer
,ResultLength
);
741 if (!NT_SUCCESS(Status
))
743 ERR("Failure to make Callback! Status 0x%x",Status
);
746 /* Support write backs... SEH is in UserCallNextHookEx. */
754 if (CbtCreatewndExtra
)
756 The parameters could have been changed, include the coordinates
757 and dimensions of the window. We copy it back.
759 CbtCreateWnd
->hwndInsertAfter
= CbtCreatewndExtra
->WndInsertAfter
;
760 CbtCreateWnd
->lpcs
->x
= CbtCreatewndExtra
->Cs
.x
;
761 CbtCreateWnd
->lpcs
->y
= CbtCreatewndExtra
->Cs
.y
;
762 CbtCreateWnd
->lpcs
->cx
= CbtCreatewndExtra
->Cs
.cx
;
763 CbtCreateWnd
->lpcs
->cy
= CbtCreatewndExtra
->Cs
.cy
;
769 RtlCopyMemory((PVOID
) lParam
, Extra
, sizeof(RECTL
));
774 // "The GetMsgProc hook procedure can examine or modify the message."
778 RtlCopyMemory((PVOID
) pMsg
, Extra
, sizeof(MSG
));
786 ERR("Exception CallHookProc HookId %d Code %d\n",HookId
,Code
);
788 if (Argument
) IntCbFreeMemory(Argument
);
794 // Events are notifications w/o results.
798 co_IntCallEventProc(HWINEVENTHOOK hook
,
809 PEVENTPROC_CALLBACK_ARGUMENTS Common
;
810 ULONG ArgumentLength
, ResultLength
;
811 PVOID Argument
, ResultPointer
;
813 ArgumentLength
= sizeof(EVENTPROC_CALLBACK_ARGUMENTS
);
815 Argument
= IntCbAllocateMemory(ArgumentLength
);
816 if (NULL
== Argument
)
818 ERR("EventProc callback failed: out of memory\n");
821 Common
= (PEVENTPROC_CALLBACK_ARGUMENTS
) Argument
;
823 Common
->event
= event
;
825 Common
->idObject
= idObject
;
826 Common
->idChild
= idChild
;
827 Common
->dwEventThread
= dwEventThread
;
828 Common
->dwmsEventTime
= dwmsEventTime
;
831 ResultPointer
= NULL
;
832 ResultLength
= sizeof(LRESULT
);
836 Status
= KeUserModeCallback(USER32_CALLBACK_EVENTPROC
,
844 IntCbFreeMemory(Argument
);
846 if (!NT_SUCCESS(Status
))
855 // Callback Load Menu and results.
859 co_IntCallLoadMenu( HINSTANCE hModule
,
860 PUNICODE_STRING pMenuName
)
864 PLOADMENU_CALLBACK_ARGUMENTS Common
;
865 ULONG ArgumentLength
, ResultLength
;
866 PVOID Argument
, ResultPointer
;
868 ArgumentLength
= sizeof(LOADMENU_CALLBACK_ARGUMENTS
);
870 ArgumentLength
+= pMenuName
->Length
+ sizeof(WCHAR
);
872 Argument
= IntCbAllocateMemory(ArgumentLength
);
873 if (NULL
== Argument
)
875 ERR("LoadMenu callback failed: out of memory\n");
878 Common
= (PLOADMENU_CALLBACK_ARGUMENTS
) Argument
;
880 // Help Intersource check and MenuName is now 4 bytes + so zero it.
881 RtlZeroMemory(Common
, ArgumentLength
);
883 Common
->hModule
= hModule
;
884 if (pMenuName
->Length
)
885 RtlCopyMemory(&Common
->MenuName
, pMenuName
->Buffer
, pMenuName
->Length
);
887 Common
->InterSource
= pMenuName
->Buffer
;
889 ResultPointer
= NULL
;
890 ResultLength
= sizeof(LRESULT
);
894 Status
= KeUserModeCallback(USER32_CALLBACK_LOADMENU
,
902 Result
= *(LRESULT
*)ResultPointer
;
904 IntCbFreeMemory(Argument
);
906 if (!NT_SUCCESS(Status
))
911 return (HMENU
)Result
;
916 co_IntClientThreadSetup(VOID
)
919 ULONG ArgumentLength
, ResultLength
;
920 PVOID Argument
, ResultPointer
;
922 /* Do not allow the desktop thread to do callback to user mode */
923 ASSERT(PsGetCurrentThreadWin32Thread() != gptiDesktopThread
);
925 ArgumentLength
= ResultLength
= 0;
926 Argument
= ResultPointer
= NULL
;
930 Status
= KeUserModeCallback(USER32_CALLBACK_CLIENTTHREADSTARTUP
,
942 co_IntCopyImage(HANDLE hnd
, UINT type
, INT desiredx
, INT desiredy
, UINT flags
)
946 ULONG ArgumentLength
, ResultLength
;
947 PVOID Argument
, ResultPointer
;
948 PCOPYIMAGE_CALLBACK_ARGUMENTS Common
;
950 ArgumentLength
= ResultLength
= 0;
951 Argument
= ResultPointer
= NULL
;
953 ArgumentLength
= sizeof(COPYIMAGE_CALLBACK_ARGUMENTS
);
955 Argument
= IntCbAllocateMemory(ArgumentLength
);
956 if (NULL
== Argument
)
958 ERR("CopyImage callback failed: out of memory\n");
961 Common
= (PCOPYIMAGE_CALLBACK_ARGUMENTS
) Argument
;
963 Common
->hImage
= hnd
;
964 Common
->uType
= type
;
965 Common
->cxDesired
= desiredx
;
966 Common
->cyDesired
= desiredy
;
967 Common
->fuFlags
= flags
;
971 Status
= KeUserModeCallback(USER32_CALLBACK_COPYIMAGE
,
980 Handle
= *(HANDLE
*)ResultPointer
;
982 IntCbFreeMemory(Argument
);
984 if (!NT_SUCCESS(Status
))
986 ERR("CopyImage callback failed!\n");
995 co_IntGetCharsetInfo(LCID Locale
, PCHARSETINFO pCs
)
998 ULONG ArgumentLength
, ResultLength
;
999 PVOID Argument
, ResultPointer
;
1000 PGET_CHARSET_INFO Common
;
1002 ArgumentLength
= sizeof(GET_CHARSET_INFO
);
1004 Argument
= IntCbAllocateMemory(ArgumentLength
);
1005 if (NULL
== Argument
)
1007 ERR("GetCharsetInfo callback failed: out of memory\n");
1010 Common
= (PGET_CHARSET_INFO
) Argument
;
1012 Common
->Locale
= Locale
;
1014 ResultPointer
= NULL
;
1015 ResultLength
= ArgumentLength
;
1019 Status
= KeUserModeCallback(USER32_CALLBACK_GETCHARSETINFO
,
1027 /* Need to copy into our local buffer */
1028 RtlMoveMemory(Argument
, ResultPointer
, ArgumentLength
);
1030 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1032 ERR("Failed to copy result from user mode!\n");
1033 Status
= _SEH2_GetExceptionCode();
1039 RtlCopyMemory(pCs
, &Common
->Cs
, sizeof(CHARSETINFO
));
1041 IntCbFreeMemory(Argument
);
1043 if (!NT_SUCCESS(Status
))
1045 ERR("GetCharsetInfo Failed!!\n");
1053 co_IntSetWndIcons(VOID
)
1056 ULONG ArgumentLength
, ResultLength
;
1057 PVOID Argument
, ResultPointer
;
1058 PSETWNDICONS_CALLBACK_ARGUMENTS Common
;
1060 ResultPointer
= NULL
;
1061 ResultLength
= ArgumentLength
= sizeof(SETWNDICONS_CALLBACK_ARGUMENTS
);
1063 Argument
= IntCbAllocateMemory(ArgumentLength
);
1064 if (NULL
== Argument
)
1066 ERR("Set Window Icons callback failed: out of memory\n");
1069 Common
= (PSETWNDICONS_CALLBACK_ARGUMENTS
) Argument
;
1073 Status
= KeUserModeCallback(USER32_CALLBACK_SETWNDICONS
,
1082 /* FIXME: Need to setup Registry System Cursor & Icons via Callbacks at init time! */
1083 RtlMoveMemory(Common
, ResultPointer
, ArgumentLength
);
1084 gpsi
->hIconSmWindows
= Common
->hIconSmWindows
;
1085 gpsi
->hIconWindows
= Common
->hIconWindows
;
1087 ERR("hIconSmWindows %p hIconWindows %p \n",gpsi
->hIconSmWindows
,gpsi
->hIconWindows
);
1089 IntCbFreeMemory(Argument
);
1091 if (!NT_SUCCESS(Status
))
1093 ERR("Set Window Icons callback failed!\n");