294 missing WINAPI added.
[wine] / misc / callback.c
1 /*
2  * Function callbacks for the library
3  *
4  * Copyright 1997 Alexandre Julliard
5  */
6
7 #include <assert.h>
8 #include "debug.h"
9 #include "windows.h"
10 #include "callback.h"
11 #include "task.h"
12 #include "syslevel.h"
13
14
15 /**********************************************************************
16  *           CALLBACK_CallWndProc
17  */
18 static LRESULT WINAPI CALLBACK_CallWndProc( WNDPROC16 proc, HWND16 hwnd,
19                                             UINT16 msg, WPARAM16 wParam,
20                                             LPARAM lParam )
21 {
22     return proc( hwnd, msg, wParam, lParam );
23 }
24
25
26 /**********************************************************************
27  *           CALLBACK_CallRegisterProc
28  */
29 static LONG WINAPI CALLBACK_CallRegisterProc( CONTEXT *context, INT32 offset)
30 {
31     ERR(relay, "Cannot call a register proc in Winelib\n" );
32     assert( FALSE );
33     return 0;
34 }
35
36
37 /**********************************************************************
38  *           CALLBACK_CallDriverProc
39  */
40 static LRESULT WINAPI CALLBACK_CallDriverProc( DRIVERPROC16 proc, DWORD dwId,
41                                                HDRVR16 hdrvr, UINT16 msg,
42                                                LPARAM lp1, LPARAM lp2 )
43 {
44     return proc( dwId, hdrvr, msg, lp1, lp2 );
45 }
46
47
48 /**********************************************************************
49  *           CALLBACK_CallDriverCallback
50  */
51 static LRESULT WINAPI CALLBACK_CallDriverCallback( FARPROC16 proc,
52                                                    HANDLE16 hDev, UINT16 msg,
53                                                    DWORD dwUser, LPARAM lp1,
54                                                    LPARAM lp2 )
55 {
56     return proc( hDev, msg, dwUser, lp1, lp2 );
57 }
58
59
60 /**********************************************************************
61  *           CALLBACK_CallTimeFuncProc
62  */
63 static LRESULT WINAPI CALLBACK_CallTimeFuncProc( FARPROC16 proc, WORD id,
64                                                  UINT16 msg, DWORD dwUser,
65                                                  LPARAM lp1, LPARAM lp2 )
66 {
67     return proc( id, msg, dwUser, lp1, lp2 );
68 }
69
70
71 /**********************************************************************
72  *           CALLBACK_CallWindowsExitProc
73  */
74 static INT16 WINAPI CALLBACK_CallWindowsExitProc( FARPROC16 proc, INT16 type)
75 {
76     return proc( type );
77 }
78
79
80 /**********************************************************************
81  *           CALLBACK_CallWordBreakProc
82  */
83 static INT16 WINAPI CALLBACK_CallWordBreakProc( EDITWORDBREAKPROC16 proc,
84                                                 SEGPTR text, INT16 word,
85                                                 INT16 len, INT16 action )
86 {
87     return proc( (LPSTR)text, word, len, action );
88 }
89
90
91 /**********************************************************************
92  *           CALLBACK_CallBootAppProc
93  */
94 static void WINAPI CALLBACK_CallBootAppProc( FARPROC16 proc, HANDLE16 module,
95                                              HFILE16 file )
96 {
97     proc( module, file );
98 }
99
100
101 /**********************************************************************
102  *           CALLBACK_CallLoadAppSegProc
103  */
104 static WORD WINAPI CALLBACK_CallLoadAppSegProc( FARPROC16 proc,
105                                                 HANDLE16 module, HFILE16 file,
106                                                 WORD seg )
107 {
108     return proc( module, file, seg );
109 }
110
111
112 /**********************************************************************
113  *           CALLBACK_CallLocalNotifyFunc
114  */
115 static WORD WINAPI CALLBACK_CallLocalNotifyFunc( FARPROC16 proc,
116                                                  WORD wMsg, HLOCAL16 hMem,
117                                                  WORD wArg )
118 {
119     return proc( wMsg, hMem, wArg );
120 }
121
122
123 /**********************************************************************
124  *           CALLBACK_CallResourceHandlerProc
125  */
126 static HGLOBAL16 WINAPI CALLBACK_CallResourceHandlerProc( FARPROC16 proc,
127                                                           HGLOBAL16 hMemObj, 
128                                                           HMODULE16 hModule,
129                                                           HRSRC16 hRsrc )
130 {
131     return proc( hMemObj, hModule, hRsrc );
132 }
133
134
135 /**********************************************************************
136  *           CALLBACK_CallASPIPostProc
137  */
138 static LRESULT WINAPI CALLBACK_CallASPIPostProc( FARPROC16 proc, SEGPTR ptr )
139 {
140     return proc( ptr );
141 }
142
143
144 /**********************************************************************
145  *           CALLBACK_CallWOWCallbackProc
146  */
147 static DWORD WINAPI CALLBACK_CallWOWCallbackProc( FARPROC16 proc, DWORD dw )
148 {
149     return proc( dw );
150 }
151
152 /**********************************************************************
153  *           CALLBACK_CallWOWCallback16Ex
154  *
155  * WCB16_MAX_CBARGS (16) is the maximum number of args.
156  *
157  * Can call functions using CDECL or PASCAL calling conventions. The CDECL
158  * ones are reversed (not 100% sure about that).
159  */
160 static BOOL32 WINAPI CALLBACK_CallWOWCallback16Ex( 
161         FARPROC16 proc, DWORD dwFlags, DWORD cbArgs, LPVOID xargs,LPDWORD pdwret
162 ) {
163     LPDWORD     args = (LPDWORD)xargs;
164     DWORD       ret,i;
165
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];
171     }
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]
183             );
184             break;
185     case 8: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
186                     args[6],args[7]
187             );
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]
191             );
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]
195             );
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]
199             );
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]
203             );
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]
208             );
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]
213             );
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]
218             );
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]
223             );
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;
230     }
231     if (dwFlags == WCB16_CDECL)
232         HeapFree(GetProcessHeap(),0,args);
233     if (pdwret) 
234         *pdwret = ret;
235     return TRUE;
236 }
237
238 /**********************************************************************
239  *           CALLBACK_CallTaskRescheduleProc
240  */
241 static void WINAPI CALLBACK_CallTaskRescheduleProc( void )
242 {
243     SYSLEVEL_EnterWin16Lock();
244     TASK_Reschedule();
245     SYSLEVEL_LeaveWin16Lock();
246 }
247
248
249 /**********************************************************************
250  *           CALLBACK_WinelibTable
251  *
252  * The callbacks function table for Winelib
253  */
254 static const CALLBACKS_TABLE CALLBACK_WinelibTable =
255 {
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 */
285 };
286
287 const CALLBACKS_TABLE *Callbacks = &CALLBACK_WinelibTable;
288
289