Removed direct access to the WND struct.
[wine/dcerpc.git] / misc / callback.c
blobbd882482d074dd56784e5aeb25d9287dfb2b6c32
1 /*
2 * Function callbacks for the library
4 * Copyright 1997 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include "winuser.h"
9 #include "callback.h"
10 #include "task.h"
11 #include "syslevel.h"
12 #include "cursoricon.h"
13 #include "queue.h"
14 #include "debug.h"
17 /**********************************************************************
18 * CALLBACK_CallWndProc
20 static LRESULT WINAPI CALLBACK_CallWndProc( WNDPROC16 proc, HWND16 hwnd,
21 UINT16 msg, WPARAM16 wParam,
22 LPARAM lParam )
24 return proc( hwnd, msg, wParam, lParam );
28 /**********************************************************************
29 * CALLBACK_CallRegisterProc
31 static LONG WINAPI CALLBACK_CallRegisterProc( CONTEXT *context, INT offset)
33 ERR(relay, "Cannot call a register proc in Winelib\n" );
34 assert( FALSE );
35 return 0;
39 /**********************************************************************
40 * CALLBACK_CallDriverProc
42 static LRESULT WINAPI CALLBACK_CallDriverProc( DRIVERPROC16 proc, DWORD dwId,
43 HDRVR16 hdrvr, UINT16 msg,
44 LPARAM lp1, LPARAM lp2 )
46 return proc( dwId, hdrvr, msg, lp1, lp2 );
50 /**********************************************************************
51 * CALLBACK_CallDriverCallback
53 static LRESULT WINAPI CALLBACK_CallDriverCallback( FARPROC16 proc,
54 HANDLE16 hDev, UINT16 msg,
55 DWORD dwUser, LPARAM lp1,
56 LPARAM lp2 )
58 return proc( hDev, msg, dwUser, lp1, lp2 );
62 /**********************************************************************
63 * CALLBACK_CallTimeFuncProc
65 static LRESULT WINAPI CALLBACK_CallTimeFuncProc( FARPROC16 proc, WORD id,
66 UINT16 msg, DWORD dwUser,
67 LPARAM lp1, LPARAM lp2 )
69 return proc( id, msg, dwUser, lp1, lp2 );
73 /**********************************************************************
74 * CALLBACK_CallWindowsExitProc
76 static INT16 WINAPI CALLBACK_CallWindowsExitProc( FARPROC16 proc, INT16 type)
78 return proc( type );
82 /**********************************************************************
83 * CALLBACK_CallWordBreakProc
85 static INT16 WINAPI CALLBACK_CallWordBreakProc( EDITWORDBREAKPROC16 proc,
86 SEGPTR text, INT16 word,
87 INT16 len, INT16 action )
89 return proc( (LPSTR)text, word, len, action );
93 /**********************************************************************
94 * CALLBACK_CallBootAppProc
96 static void WINAPI CALLBACK_CallBootAppProc( FARPROC16 proc, HANDLE16 module,
97 HFILE16 file )
99 proc( module, file );
103 /**********************************************************************
104 * CALLBACK_CallLoadAppSegProc
106 static WORD WINAPI CALLBACK_CallLoadAppSegProc( FARPROC16 proc,
107 HANDLE16 module, HFILE16 file,
108 WORD seg )
110 return proc( module, file, seg );
114 /**********************************************************************
115 * CALLBACK_CallLocalNotifyFunc
117 static WORD WINAPI CALLBACK_CallLocalNotifyFunc( FARPROC16 proc,
118 WORD wMsg, HLOCAL16 hMem,
119 WORD wArg )
121 return proc( wMsg, hMem, wArg );
125 /**********************************************************************
126 * CALLBACK_CallResourceHandlerProc
128 static HGLOBAL16 WINAPI CALLBACK_CallResourceHandlerProc( FARPROC16 proc,
129 HGLOBAL16 hMemObj,
130 HMODULE16 hModule,
131 HRSRC16 hRsrc )
133 return proc( hMemObj, hModule, hRsrc );
137 /**********************************************************************
138 * CALLBACK_CallASPIPostProc
140 static LRESULT WINAPI CALLBACK_CallASPIPostProc( FARPROC16 proc, SEGPTR ptr )
142 return proc( ptr );
146 /**********************************************************************
147 * CALLBACK_CallWOWCallbackProc
149 static DWORD WINAPI CALLBACK_CallWOWCallbackProc( FARPROC16 proc, DWORD dw )
151 return proc( dw );
154 /**********************************************************************
155 * CALLBACK_CallWOWCallback16Ex
157 * WCB16_MAX_CBARGS (16) is the maximum number of args.
159 * Can call functions using CDECL or PASCAL calling conventions. The CDECL
160 * ones are reversed (not 100% sure about that).
162 static BOOL WINAPI CALLBACK_CallWOWCallback16Ex(
163 FARPROC16 proc, DWORD dwFlags, DWORD cbArgs, LPVOID xargs,LPDWORD pdwret
165 LPDWORD args = (LPDWORD)xargs;
166 DWORD ret,i;
168 if (dwFlags == WCB16_CDECL) {
169 /* swap the arguments */
170 args = HeapAlloc(GetProcessHeap(),0,cbArgs*sizeof(DWORD));
171 for (i=0;i<cbArgs;i++)
172 args[i] = ((DWORD*)xargs)[cbArgs-i-1];
174 switch (cbArgs) {
175 case 0: ret = proc();break;
176 case 1: ret = proc(args[0]);break;
177 case 2: ret = proc(args[0],args[1]);break;
178 case 3: ret = proc(args[0],args[1],args[2]);break;
179 case 4: ret = proc(args[0],args[1],args[2],args[3]);break;
180 case 5: ret = proc(args[0],args[1],args[2],args[3],args[4]);break;
181 case 6: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5]);
182 break;
183 case 7: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
184 args[6]
186 break;
187 case 8: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
188 args[6],args[7]
190 break;
191 case 9: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
192 args[6],args[7],args[8]
194 break;
195 case 10:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
196 args[6],args[7],args[8],args[9]
198 break;
199 case 11:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
200 args[6],args[7],args[8],args[9],args[10]
202 break;
203 case 12:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
204 args[6],args[7],args[8],args[9],args[10],args[11]
206 break;
207 case 13:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
208 args[6],args[7],args[8],args[9],args[10],args[11],
209 args[12]
211 break;
212 case 14:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
213 args[6],args[7],args[8],args[9],args[10],args[11],
214 args[12],args[13]
216 break;
217 case 15:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
218 args[6],args[7],args[8],args[9],args[10],args[11],
219 args[12],args[13],args[14]
221 break;
222 case 16:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
223 args[6],args[7],args[8],args[9],args[10],args[11],
224 args[12],args[13],args[14],args[15]
226 break;
227 default:
228 WARN(relay,"(%ld) arguments not supported.\n",cbArgs);
229 if (dwFlags == WCB16_CDECL)
230 HeapFree(GetProcessHeap(),0,args);
231 return FALSE;
233 if (dwFlags == WCB16_CDECL)
234 HeapFree(GetProcessHeap(),0,args);
235 if (pdwret)
236 *pdwret = ret;
237 return TRUE;
240 /**********************************************************************
241 * CALLBACK_CallTaskRescheduleProc
243 static BOOL WINAPI CALLBACK_CallTaskRescheduleProc( void )
245 BOOL pending;
247 SYSLEVEL_EnterWin16Lock();
248 pending = TASK_Reschedule();
249 SYSLEVEL_LeaveWin16Lock();
251 return pending;
255 /**********************************************************************
256 * CALLBACK_WinelibTable
258 * The callbacks function table for Winelib
260 static const CALLBACKS_TABLE CALLBACK_WinelibTable =
262 CALLBACK_CallRegisterProc, /* CallRegisterShortProc */
263 CALLBACK_CallRegisterProc, /* CallRegisterLongProc */
264 CALLBACK_CallTaskRescheduleProc, /* CallTaskRescheduleProc */
265 NULL, /* CallFrom16WndProc */
266 CALLBACK_CallWndProc, /* CallWndProc */
267 CALLBACK_CallDriverProc, /* CallDriverProc */
268 CALLBACK_CallDriverCallback, /* CallDriverCallback */
269 CALLBACK_CallTimeFuncProc, /* CallTimeFuncProc */
270 CALLBACK_CallWindowsExitProc, /* CallWindowsExitProc */
271 CALLBACK_CallWordBreakProc, /* CallWordBreakProc */
272 CALLBACK_CallBootAppProc, /* CallBootAppProc */
273 CALLBACK_CallLoadAppSegProc, /* CallLoadAppSegProc */
274 CALLBACK_CallLocalNotifyFunc, /* CallLocalNotifyFunc */
275 CALLBACK_CallResourceHandlerProc, /* CallResourceHandlerProc */
276 CALLBACK_CallWOWCallbackProc, /* CallWOWCallbackProc */
277 CALLBACK_CallWOWCallback16Ex, /* CallWOWCallback16Ex */
278 CALLBACK_CallASPIPostProc, /* CallASPIPostProc */
279 /* The graphics driver callbacks are never used in Winelib */
280 NULL, /* CallDrvControlProc */
281 NULL, /* CallDrvEnableProc */
282 NULL, /* CallDrvEnumDFontsProc */
283 NULL, /* CallDrvEnumObjProc */
284 NULL, /* CallDrvOutputProc */
285 NULL, /* CallDrvRealizeProc */
286 NULL, /* CallDrvStretchBltProc */
287 NULL, /* CallDrvExtTextOutProc */
288 NULL, /* CallDrvGetCharWidth */
289 NULL /* CallDrvAbortProc */
292 const CALLBACKS_TABLE *Callbacks = &CALLBACK_WinelibTable;
295 /**********************************************************************
296 * CALLOUT_Table
298 * The callout function table for Winelib
301 CALLOUT_TABLE Callout =
303 PeekMessage16, PeekMessageA, PeekMessageW,
304 GetMessage16, GetMessageA, GetMessageW,
305 SendMessage16, SendMessageA, SendMessageW,
306 PostMessage16, PostMessageA, PostMessageW,
307 PostAppMessage16, PostThreadMessageA, PostThreadMessageW,
308 TranslateMessage16, TranslateMessage,
309 DispatchMessage16, DispatchMessageA, DispatchMessageW,
310 RedrawWindow16, RedrawWindow,
311 InitThreadInput16,
312 UserYield16,
313 CURSORICON_Destroy