The Zw... Functions in ntdll.dll are just alternate entry
[wine/multimedia.git] / misc / callback.c
blobe1b9b4c15d24f1c8c726802da3d608de308c542a
1 /*
2 * Function callbacks for the library
4 * Copyright 1997 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include "debug.h"
9 #include "windows.h"
10 #include "callback.h"
11 #include "task.h"
12 #include "syslevel.h"
15 /**********************************************************************
16 * CALLBACK_CallWndProc
18 static LRESULT WINAPI CALLBACK_CallWndProc( WNDPROC16 proc, HWND16 hwnd,
19 UINT16 msg, WPARAM16 wParam,
20 LPARAM lParam )
22 return proc( hwnd, msg, wParam, lParam );
26 /**********************************************************************
27 * CALLBACK_CallRegisterProc
29 static LONG WINAPI CALLBACK_CallRegisterProc( CONTEXT *context, INT32 offset)
31 ERR(relay, "Cannot call a register proc in Winelib\n" );
32 assert( FALSE );
33 return 0;
37 /**********************************************************************
38 * CALLBACK_CallDriverProc
40 static LRESULT WINAPI CALLBACK_CallDriverProc( DRIVERPROC16 proc, DWORD dwId,
41 HDRVR16 hdrvr, UINT16 msg,
42 LPARAM lp1, LPARAM lp2 )
44 return proc( dwId, hdrvr, msg, lp1, lp2 );
48 /**********************************************************************
49 * CALLBACK_CallDriverCallback
51 static LRESULT WINAPI CALLBACK_CallDriverCallback( FARPROC16 proc,
52 HANDLE16 hDev, UINT16 msg,
53 DWORD dwUser, LPARAM lp1,
54 LPARAM lp2 )
56 return proc( hDev, msg, dwUser, lp1, lp2 );
60 /**********************************************************************
61 * CALLBACK_CallTimeFuncProc
63 static LRESULT WINAPI CALLBACK_CallTimeFuncProc( FARPROC16 proc, WORD id,
64 UINT16 msg, DWORD dwUser,
65 LPARAM lp1, LPARAM lp2 )
67 return proc( id, msg, dwUser, lp1, lp2 );
71 /**********************************************************************
72 * CALLBACK_CallWindowsExitProc
74 static INT16 WINAPI CALLBACK_CallWindowsExitProc( FARPROC16 proc, INT16 type)
76 return proc( type );
80 /**********************************************************************
81 * CALLBACK_CallWordBreakProc
83 static INT16 WINAPI CALLBACK_CallWordBreakProc( EDITWORDBREAKPROC16 proc,
84 SEGPTR text, INT16 word,
85 INT16 len, INT16 action )
87 return proc( (LPSTR)text, word, len, action );
91 /**********************************************************************
92 * CALLBACK_CallBootAppProc
94 static void WINAPI CALLBACK_CallBootAppProc( FARPROC16 proc, HANDLE16 module,
95 HFILE16 file )
97 proc( module, file );
101 /**********************************************************************
102 * CALLBACK_CallLoadAppSegProc
104 static WORD WINAPI CALLBACK_CallLoadAppSegProc( FARPROC16 proc,
105 HANDLE16 module, HFILE16 file,
106 WORD seg )
108 return proc( module, file, seg );
112 /**********************************************************************
113 * CALLBACK_CallLocalNotifyFunc
115 static WORD WINAPI CALLBACK_CallLocalNotifyFunc( FARPROC16 proc,
116 WORD wMsg, HLOCAL16 hMem,
117 WORD wArg )
119 return proc( wMsg, hMem, wArg );
123 /**********************************************************************
124 * CALLBACK_CallResourceHandlerProc
126 static HGLOBAL16 WINAPI CALLBACK_CallResourceHandlerProc( FARPROC16 proc,
127 HGLOBAL16 hMemObj,
128 HMODULE16 hModule,
129 HRSRC16 hRsrc )
131 return proc( hMemObj, hModule, hRsrc );
135 /**********************************************************************
136 * CALLBACK_CallASPIPostProc
138 static LRESULT WINAPI CALLBACK_CallASPIPostProc( FARPROC16 proc, SEGPTR ptr )
140 return proc( ptr );
144 /**********************************************************************
145 * CALLBACK_CallWOWCallbackProc
147 static DWORD WINAPI CALLBACK_CallWOWCallbackProc( FARPROC16 proc, DWORD dw )
149 return proc( dw );
152 /**********************************************************************
153 * CALLBACK_CallWOWCallback16Ex
155 * WCB16_MAX_CBARGS (16) is the maximum number of args.
157 * Can call functions using CDECL or PASCAL calling conventions. The CDECL
158 * ones are reversed (not 100% sure about that).
160 static BOOL32 WINAPI CALLBACK_CallWOWCallback16Ex(
161 FARPROC16 proc, DWORD dwFlags, DWORD cbArgs, LPVOID xargs,LPDWORD pdwret
163 LPDWORD args = (LPDWORD)xargs;
164 DWORD ret,i;
166 if (dwFlags == WCB16_CDECL) {
167 /* swap the arguments */
168 args = HeapAlloc(GetProcessHeap(),0,cbArgs*sizeof(DWORD));
169 for (i=0;i<cbArgs;i++)
170 args[i] = ((DWORD*)xargs)[cbArgs-i-1];
172 switch (cbArgs) {
173 case 0: ret = proc();break;
174 case 1: ret = proc(args[0]);break;
175 case 2: ret = proc(args[0],args[1]);break;
176 case 3: ret = proc(args[0],args[1],args[2]);break;
177 case 4: ret = proc(args[0],args[1],args[2],args[3]);break;
178 case 5: ret = proc(args[0],args[1],args[2],args[3],args[4]);break;
179 case 6: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5]);
180 break;
181 case 7: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
182 args[6]
184 break;
185 case 8: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
186 args[6],args[7]
188 break;
189 case 9: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
190 args[6],args[7],args[8]
192 break;
193 case 10:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
194 args[6],args[7],args[8],args[9]
196 break;
197 case 11:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
198 args[6],args[7],args[8],args[9],args[10]
200 break;
201 case 12:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
202 args[6],args[7],args[8],args[9],args[10],args[11]
204 break;
205 case 13:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
206 args[6],args[7],args[8],args[9],args[10],args[11],
207 args[12]
209 break;
210 case 14:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
211 args[6],args[7],args[8],args[9],args[10],args[11],
212 args[12],args[13]
214 break;
215 case 15:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
216 args[6],args[7],args[8],args[9],args[10],args[11],
217 args[12],args[13],args[14]
219 break;
220 case 16:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
221 args[6],args[7],args[8],args[9],args[10],args[11],
222 args[12],args[13],args[14],args[15]
224 break;
225 default:
226 WARN(relay,"(%ld) arguments not supported.\n",cbArgs);
227 if (dwFlags == WCB16_CDECL)
228 HeapFree(GetProcessHeap(),0,args);
229 return FALSE;
231 if (dwFlags == WCB16_CDECL)
232 HeapFree(GetProcessHeap(),0,args);
233 if (pdwret)
234 *pdwret = ret;
235 return TRUE;
238 /**********************************************************************
239 * CALLBACK_CallTaskRescheduleProc
241 static void WINAPI CALLBACK_CallTaskRescheduleProc( void )
243 SYSLEVEL_EnterWin16Lock();
244 TASK_Reschedule();
245 SYSLEVEL_LeaveWin16Lock();
249 /**********************************************************************
250 * CALLBACK_WinelibTable
252 * The callbacks function table for Winelib
254 static const CALLBACKS_TABLE CALLBACK_WinelibTable =
256 CALLBACK_CallRegisterProc, /* CallRegisterShortProc */
257 CALLBACK_CallRegisterProc, /* CallRegisterLongProc */
258 CALLBACK_CallTaskRescheduleProc, /* CallTaskRescheduleProc */
259 NULL, /* CallFrom16WndProc */
260 CALLBACK_CallWndProc, /* CallWndProc */
261 CALLBACK_CallDriverProc, /* CallDriverProc */
262 CALLBACK_CallDriverCallback, /* CallDriverCallback */
263 CALLBACK_CallTimeFuncProc, /* CallTimeFuncProc */
264 CALLBACK_CallWindowsExitProc, /* CallWindowsExitProc */
265 CALLBACK_CallWordBreakProc, /* CallWordBreakProc */
266 CALLBACK_CallBootAppProc, /* CallBootAppProc */
267 CALLBACK_CallLoadAppSegProc, /* CallLoadAppSegProc */
268 CALLBACK_CallLocalNotifyFunc, /* CallLocalNotifyFunc */
269 CALLBACK_CallResourceHandlerProc, /* CallResourceHandlerProc */
270 NULL, /* CallPostAppMessageProc */
271 CALLBACK_CallWOWCallbackProc, /* CallWOWCallbackProc */
272 CALLBACK_CallWOWCallback16Ex, /* CallWOWCallback16Ex */
273 CALLBACK_CallASPIPostProc, /* CallASPIPostProc */
274 /* The graphics driver callbacks are never used in Winelib */
275 NULL, /* CallDrvControlProc */
276 NULL, /* CallDrvEnableProc */
277 NULL, /* CallDrvEnumDFontsProc */
278 NULL, /* CallDrvEnumObjProc */
279 NULL, /* CallDrvOutputProc */
280 NULL, /* CallDrvRealizeProc */
281 NULL, /* CallDrvStretchBltProc */
282 NULL, /* CallDrvExtTextOutProc */
283 NULL, /* CallDrvGetCharWidth */
284 NULL /* CallDrvAbortProc */
287 const CALLBACKS_TABLE *Callbacks = &CALLBACK_WinelibTable;