Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Function callbacks for the library |
| 3 | * |
| 4 | * Copyright 1997 Alexandre Julliard |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
Marcus Meissner | 04c3e1d | 1999-02-19 10:37:02 +0000 | [diff] [blame] | 8 | #include "winuser.h" |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 9 | #include "callback.h" |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 10 | #include "task.h" |
Ulrich Weigand | 7df1fbb | 1998-11-01 18:01:53 +0000 | [diff] [blame] | 11 | #include "syslevel.h" |
Ulrich Weigand | e562453 | 1999-03-10 14:06:53 +0000 | [diff] [blame] | 12 | #include "cursoricon.h" |
Ulrich Weigand | 61439d2 | 1998-12-24 15:12:20 +0000 | [diff] [blame] | 13 | #include "queue.h" |
Marcus Meissner | 04c3e1d | 1999-02-19 10:37:02 +0000 | [diff] [blame] | 14 | #include "debug.h" |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 15 | |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 16 | |
| 17 | /********************************************************************** |
| 18 | * CALLBACK_CallWndProc |
| 19 | */ |
| 20 | static LRESULT WINAPI CALLBACK_CallWndProc( WNDPROC16 proc, HWND16 hwnd, |
| 21 | UINT16 msg, WPARAM16 wParam, |
| 22 | LPARAM lParam ) |
| 23 | { |
| 24 | return proc( hwnd, msg, wParam, lParam ); |
| 25 | } |
| 26 | |
| 27 | |
| 28 | /********************************************************************** |
| 29 | * CALLBACK_CallRegisterProc |
| 30 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 31 | static LONG WINAPI CALLBACK_CallRegisterProc( CONTEXT *context, INT offset) |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 32 | { |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 33 | ERR(relay, "Cannot call a register proc in Winelib\n" ); |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 34 | assert( FALSE ); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 35 | return 0; |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | |
| 39 | /********************************************************************** |
| 40 | * CALLBACK_CallDriverProc |
| 41 | */ |
| 42 | static LRESULT WINAPI CALLBACK_CallDriverProc( DRIVERPROC16 proc, DWORD dwId, |
| 43 | HDRVR16 hdrvr, UINT16 msg, |
| 44 | LPARAM lp1, LPARAM lp2 ) |
| 45 | { |
| 46 | return proc( dwId, hdrvr, msg, lp1, lp2 ); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | /********************************************************************** |
| 51 | * CALLBACK_CallDriverCallback |
| 52 | */ |
| 53 | static LRESULT WINAPI CALLBACK_CallDriverCallback( FARPROC16 proc, |
| 54 | HANDLE16 hDev, UINT16 msg, |
| 55 | DWORD dwUser, LPARAM lp1, |
| 56 | LPARAM lp2 ) |
| 57 | { |
| 58 | return proc( hDev, msg, dwUser, lp1, lp2 ); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | /********************************************************************** |
| 63 | * CALLBACK_CallTimeFuncProc |
| 64 | */ |
| 65 | static LRESULT WINAPI CALLBACK_CallTimeFuncProc( FARPROC16 proc, WORD id, |
| 66 | UINT16 msg, DWORD dwUser, |
| 67 | LPARAM lp1, LPARAM lp2 ) |
| 68 | { |
| 69 | return proc( id, msg, dwUser, lp1, lp2 ); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | /********************************************************************** |
| 74 | * CALLBACK_CallWindowsExitProc |
| 75 | */ |
| 76 | static INT16 WINAPI CALLBACK_CallWindowsExitProc( FARPROC16 proc, INT16 type) |
| 77 | { |
| 78 | return proc( type ); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | /********************************************************************** |
| 83 | * CALLBACK_CallWordBreakProc |
| 84 | */ |
| 85 | static INT16 WINAPI CALLBACK_CallWordBreakProc( EDITWORDBREAKPROC16 proc, |
| 86 | SEGPTR text, INT16 word, |
| 87 | INT16 len, INT16 action ) |
| 88 | { |
| 89 | return proc( (LPSTR)text, word, len, action ); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | /********************************************************************** |
| 94 | * CALLBACK_CallBootAppProc |
| 95 | */ |
| 96 | static void WINAPI CALLBACK_CallBootAppProc( FARPROC16 proc, HANDLE16 module, |
| 97 | HFILE16 file ) |
| 98 | { |
| 99 | proc( module, file ); |
| 100 | } |
| 101 | |
| 102 | |
| 103 | /********************************************************************** |
| 104 | * CALLBACK_CallLoadAppSegProc |
| 105 | */ |
| 106 | static WORD WINAPI CALLBACK_CallLoadAppSegProc( FARPROC16 proc, |
| 107 | HANDLE16 module, HFILE16 file, |
| 108 | WORD seg ) |
| 109 | { |
| 110 | return proc( module, file, seg ); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | /********************************************************************** |
Andreas Mohr | a00b49f | 1998-12-07 10:48:09 +0000 | [diff] [blame] | 115 | * CALLBACK_CallLocalNotifyFunc |
| 116 | */ |
| 117 | static WORD WINAPI CALLBACK_CallLocalNotifyFunc( FARPROC16 proc, |
| 118 | WORD wMsg, HLOCAL16 hMem, |
| 119 | WORD wArg ) |
| 120 | { |
| 121 | return proc( wMsg, hMem, wArg ); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | /********************************************************************** |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 126 | * CALLBACK_CallResourceHandlerProc |
| 127 | */ |
| 128 | static HGLOBAL16 WINAPI CALLBACK_CallResourceHandlerProc( FARPROC16 proc, |
| 129 | HGLOBAL16 hMemObj, |
| 130 | HMODULE16 hModule, |
| 131 | HRSRC16 hRsrc ) |
| 132 | { |
| 133 | return proc( hMemObj, hModule, hRsrc ); |
| 134 | } |
| 135 | |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 136 | |
| 137 | /********************************************************************** |
| 138 | * CALLBACK_CallASPIPostProc |
| 139 | */ |
| 140 | static LRESULT WINAPI CALLBACK_CallASPIPostProc( FARPROC16 proc, SEGPTR ptr ) |
| 141 | { |
| 142 | return proc( ptr ); |
| 143 | } |
| 144 | |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 145 | |
| 146 | /********************************************************************** |
| 147 | * CALLBACK_CallWOWCallbackProc |
| 148 | */ |
| 149 | static DWORD WINAPI CALLBACK_CallWOWCallbackProc( FARPROC16 proc, DWORD dw ) |
| 150 | { |
| 151 | return proc( dw ); |
| 152 | } |
| 153 | |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 154 | /********************************************************************** |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 155 | * CALLBACK_CallWOWCallback16Ex |
| 156 | * |
| 157 | * WCB16_MAX_CBARGS (16) is the maximum number of args. |
| 158 | * |
| 159 | * Can call functions using CDECL or PASCAL calling conventions. The CDECL |
| 160 | * ones are reversed (not 100% sure about that). |
| 161 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 162 | static BOOL WINAPI CALLBACK_CallWOWCallback16Ex( |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 163 | FARPROC16 proc, DWORD dwFlags, DWORD cbArgs, LPVOID xargs,LPDWORD pdwret |
| 164 | ) { |
| 165 | LPDWORD args = (LPDWORD)xargs; |
| 166 | DWORD ret,i; |
| 167 | |
| 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]; |
| 173 | } |
| 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] |
| 185 | ); |
| 186 | break; |
| 187 | case 8: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5], |
| 188 | args[6],args[7] |
| 189 | ); |
| 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] |
| 193 | ); |
| 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] |
| 197 | ); |
| 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] |
| 201 | ); |
| 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] |
| 205 | ); |
| 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] |
| 210 | ); |
| 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] |
| 215 | ); |
| 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] |
| 220 | ); |
| 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] |
| 225 | ); |
| 226 | break; |
| 227 | default: |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 228 | WARN(relay,"(%ld) arguments not supported.\n",cbArgs); |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 229 | if (dwFlags == WCB16_CDECL) |
| 230 | HeapFree(GetProcessHeap(),0,args); |
| 231 | return FALSE; |
| 232 | } |
| 233 | if (dwFlags == WCB16_CDECL) |
| 234 | HeapFree(GetProcessHeap(),0,args); |
| 235 | if (pdwret) |
| 236 | *pdwret = ret; |
| 237 | return TRUE; |
| 238 | } |
| 239 | |
| 240 | /********************************************************************** |
Ulrich Weigand | 48241e9 | 1999-03-13 12:54:55 +0000 | [diff] [blame] | 241 | * CALLBACK_CallUTProc |
| 242 | */ |
Ulrich Weigand | b211ec4 | 1999-03-16 10:39:16 +0000 | [diff] [blame] | 243 | static DWORD WINAPI CALLBACK_CallUTProc( FARPROC16 proc, DWORD w1, DWORD w2 ) |
Ulrich Weigand | 48241e9 | 1999-03-13 12:54:55 +0000 | [diff] [blame] | 244 | { |
| 245 | ERR( relay, "Cannot call a UT thunk proc in Winelib\n" ); |
| 246 | assert( FALSE ); |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | /********************************************************************** |
Ulrich Weigand | 7df1fbb | 1998-11-01 18:01:53 +0000 | [diff] [blame] | 251 | * CALLBACK_CallTaskRescheduleProc |
| 252 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 253 | static BOOL WINAPI CALLBACK_CallTaskRescheduleProc( void ) |
Ulrich Weigand | 7df1fbb | 1998-11-01 18:01:53 +0000 | [diff] [blame] | 254 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 255 | BOOL pending; |
Ulrich Weigand | be672fe | 1998-12-24 14:59:53 +0000 | [diff] [blame] | 256 | |
Ulrich Weigand | 7df1fbb | 1998-11-01 18:01:53 +0000 | [diff] [blame] | 257 | SYSLEVEL_EnterWin16Lock(); |
Ulrich Weigand | be672fe | 1998-12-24 14:59:53 +0000 | [diff] [blame] | 258 | pending = TASK_Reschedule(); |
Ulrich Weigand | 7df1fbb | 1998-11-01 18:01:53 +0000 | [diff] [blame] | 259 | SYSLEVEL_LeaveWin16Lock(); |
Ulrich Weigand | be672fe | 1998-12-24 14:59:53 +0000 | [diff] [blame] | 260 | |
| 261 | return pending; |
Ulrich Weigand | 7df1fbb | 1998-11-01 18:01:53 +0000 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | |
| 265 | /********************************************************************** |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 266 | * CALLBACK_WinelibTable |
| 267 | * |
| 268 | * The callbacks function table for Winelib |
| 269 | */ |
| 270 | static const CALLBACKS_TABLE CALLBACK_WinelibTable = |
| 271 | { |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 272 | CALLBACK_CallRegisterProc, /* CallRegisterShortProc */ |
| 273 | CALLBACK_CallRegisterProc, /* CallRegisterLongProc */ |
Ulrich Weigand | 7df1fbb | 1998-11-01 18:01:53 +0000 | [diff] [blame] | 274 | CALLBACK_CallTaskRescheduleProc, /* CallTaskRescheduleProc */ |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 275 | NULL, /* CallFrom16WndProc */ |
| 276 | CALLBACK_CallWndProc, /* CallWndProc */ |
| 277 | CALLBACK_CallDriverProc, /* CallDriverProc */ |
| 278 | CALLBACK_CallDriverCallback, /* CallDriverCallback */ |
| 279 | CALLBACK_CallTimeFuncProc, /* CallTimeFuncProc */ |
| 280 | CALLBACK_CallWindowsExitProc, /* CallWindowsExitProc */ |
| 281 | CALLBACK_CallWordBreakProc, /* CallWordBreakProc */ |
| 282 | CALLBACK_CallBootAppProc, /* CallBootAppProc */ |
| 283 | CALLBACK_CallLoadAppSegProc, /* CallLoadAppSegProc */ |
Andreas Mohr | a00b49f | 1998-12-07 10:48:09 +0000 | [diff] [blame] | 284 | CALLBACK_CallLocalNotifyFunc, /* CallLocalNotifyFunc */ |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 285 | CALLBACK_CallResourceHandlerProc, /* CallResourceHandlerProc */ |
| 286 | CALLBACK_CallWOWCallbackProc, /* CallWOWCallbackProc */ |
| 287 | CALLBACK_CallWOWCallback16Ex, /* CallWOWCallback16Ex */ |
Ulrich Weigand | 48241e9 | 1999-03-13 12:54:55 +0000 | [diff] [blame] | 288 | CALLBACK_CallUTProc, /* CallUTProc */ |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 289 | CALLBACK_CallASPIPostProc, /* CallASPIPostProc */ |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 290 | /* The graphics driver callbacks are never used in Winelib */ |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 291 | NULL, /* CallDrvControlProc */ |
| 292 | NULL, /* CallDrvEnableProc */ |
| 293 | NULL, /* CallDrvEnumDFontsProc */ |
| 294 | NULL, /* CallDrvEnumObjProc */ |
| 295 | NULL, /* CallDrvOutputProc */ |
| 296 | NULL, /* CallDrvRealizeProc */ |
| 297 | NULL, /* CallDrvStretchBltProc */ |
| 298 | NULL, /* CallDrvExtTextOutProc */ |
Huw D M Davies | 980992a | 1998-11-14 18:28:50 +0000 | [diff] [blame] | 299 | NULL, /* CallDrvGetCharWidth */ |
| 300 | NULL /* CallDrvAbortProc */ |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 301 | }; |
| 302 | |
| 303 | const CALLBACKS_TABLE *Callbacks = &CALLBACK_WinelibTable; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 304 | |
| 305 | |
Ulrich Weigand | 61439d2 | 1998-12-24 15:12:20 +0000 | [diff] [blame] | 306 | /********************************************************************** |
| 307 | * CALLOUT_Table |
| 308 | * |
| 309 | * The callout function table for Winelib |
| 310 | */ |
| 311 | |
| 312 | CALLOUT_TABLE Callout = |
| 313 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 314 | PeekMessage16, PeekMessageA, PeekMessageW, |
| 315 | GetMessage16, GetMessageA, GetMessageW, |
| 316 | SendMessage16, SendMessageA, SendMessageW, |
| 317 | PostMessage16, PostMessageA, PostMessageW, |
| 318 | PostAppMessage16, PostThreadMessageA, PostThreadMessageW, |
| 319 | TranslateMessage16, TranslateMessage, |
| 320 | DispatchMessage16, DispatchMessageA, DispatchMessageW, |
| 321 | RedrawWindow16, RedrawWindow, |
| 322 | InitThreadInput16, |
Ulrich Weigand | e562453 | 1999-03-10 14:06:53 +0000 | [diff] [blame] | 323 | UserYield16, |
| 324 | CURSORICON_Destroy |
Ulrich Weigand | 61439d2 | 1998-12-24 15:12:20 +0000 | [diff] [blame] | 325 | }; |
| 326 | |