From 6f778a79f4f0e0c229d7dc7917a5fb5195dabd35 Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Sun, 20 Jun 2010 08:08:04 +0200 Subject: [PATCH] mmsystem.drv: Always map parameters for all callback kinds. --- dlls/mmsystem.dll16/message16.c | 68 +++++++++++++++++++++++---------- dlls/mmsystem.dll16/mmsystem.c | 61 ++++++++++++----------------- dlls/mmsystem.dll16/winemm16.h | 2 +- 3 files changed, 73 insertions(+), 58 deletions(-) diff --git a/dlls/mmsystem.dll16/message16.c b/dlls/mmsystem.dll16/message16.c index ce25b9cd714..6a4dc0e13e8 100644 --- a/dlls/mmsystem.dll16/message16.c +++ b/dlls/mmsystem.dll16/message16.c @@ -25,6 +25,7 @@ #include "wine/winbase16.h" #include "windef.h" #include "winbase.h" +#include "winuser.h" #include "wownt32.h" #include "winemm16.h" #include "digitalv.h" @@ -796,9 +797,10 @@ static struct mmsystdrv_thunk BYTE pushl_this; /* pushl this (this very thunk) */ struct mmsystdrv_thunk* this; BYTE pushl_eax; /* pushl %eax */ - BYTE jmp; /* ljmp MMDRV_Callback1632 */ - DWORD callback; - DWORD pfn16; /* 16bit callback function */ + BYTE jmp; /* ljmp MMDRV_Callback3216 */ + DWORD callback3216; + DWORD callback; /* callback value (function, window, event...) */ + DWORD flags; /* flags to control callback value (CALLBACK_???) */ void* hMmdrv; /* Handle to 32bit mmdrv object */ enum MMSYSTEM_DriverType kind; } *MMSYSTDRV_Thunks; @@ -834,25 +836,48 @@ static LRESULT CALLBACK MMSYSTDRV_Callback3216(struct mmsystdrv_thunk* thunk, HD MMSYSTEM_DriversType[thunk->kind].mapcb(wMsg, &dwUser, &dwParam1, &dwParam2); - /* 16 bit func, call it */ - TRACE("Function (16 bit) %x!\n", thunk->pfn16); + switch (thunk->flags & CALLBACK_TYPEMASK) { + case CALLBACK_NULL: + TRACE("Null !\n"); + break; + case CALLBACK_WINDOW: + TRACE("Window(%04X) handle=%p!\n", thunk->callback, hDev); + PostMessageA((HWND)thunk->callback, wMsg, (WPARAM)hDev, dwParam1); + break; + case CALLBACK_TASK: /* aka CALLBACK_THREAD */ + TRACE("Task(%04x) !\n", thunk->callback); + PostThreadMessageA(thunk->callback, wMsg, (WPARAM)hDev, dwParam1); + break; + case CALLBACK_FUNCTION: + /* 16 bit func, call it */ + TRACE("Function (16 bit) %x!\n", thunk->callback); - args[7] = HDRVR_16(hDev); - args[6] = wMsg; - args[5] = HIWORD(dwUser); - args[4] = LOWORD(dwUser); - args[3] = HIWORD(dwParam1); - args[2] = LOWORD(dwParam1); - args[1] = HIWORD(dwParam2); - args[0] = LOWORD(dwParam2); - return WOWCallback16Ex(thunk->pfn16, WCB16_PASCAL, sizeof(args), args, NULL); + args[7] = HDRVR_16(hDev); + args[6] = wMsg; + args[5] = HIWORD(dwUser); + args[4] = LOWORD(dwUser); + args[3] = HIWORD(dwParam1); + args[2] = LOWORD(dwParam1); + args[1] = HIWORD(dwParam2); + args[0] = LOWORD(dwParam2); + return WOWCallback16Ex(thunk->callback, WCB16_PASCAL, sizeof(args), args, NULL); + case CALLBACK_EVENT: + TRACE("Event(%08x) !\n", thunk->callback); + SetEvent((HANDLE)thunk->callback); + break; + default: + WARN("Unknown callback type %lx\n", thunk->flags & CALLBACK_TYPEMASK); + return FALSE; + } + TRACE("Done\n"); + return TRUE; } /****************************************************************** * MMSYSTDRV_AddThunk * */ -struct mmsystdrv_thunk* MMSYSTDRV_AddThunk(DWORD pfn16, enum MMSYSTEM_DriverType kind) +struct mmsystdrv_thunk* MMSYSTDRV_AddThunk(DWORD callback, DWORD flags, enum MMSYSTEM_DriverType kind) { struct mmsystdrv_thunk* thunk; @@ -873,17 +898,19 @@ struct mmsystdrv_thunk* MMSYSTDRV_AddThunk(DWORD pfn16, enum MMSYSTEM_Driv thunk->this = thunk; thunk->pushl_eax = 0x50; /* pushl %eax */ thunk->jmp = 0xe9; /* jmp MMDRV_Callback3216 */ - thunk->callback = (char *)MMSYSTDRV_Callback3216 - (char *)(&thunk->callback + 1); - thunk->pfn16 = 0; + thunk->callback3216 = (char *)MMSYSTDRV_Callback3216 - (char *)(&thunk->callback3216 + 1); + thunk->callback = 0; + thunk->flags = CALLBACK_NULL; thunk->hMmdrv = NULL; thunk->kind = MMSYSTDRV_MAX; } } for (thunk = MMSYSTDRV_Thunks; thunk < &MMSYSTDRV_Thunks[MMSYSTDRV_MAX_THUNKS]; thunk++) { - if (thunk->pfn16 == 0 && thunk->hMmdrv == NULL) + if (thunk->callback == 0 && thunk->hMmdrv == NULL) { - thunk->pfn16 = pfn16; + thunk->callback = callback; + thunk->flags = flags; thunk->hMmdrv = NULL; thunk->kind = kind; LeaveCriticalSection(&mmdrv_cs); @@ -930,7 +957,8 @@ void MMSYSTDRV_SetHandle(struct mmsystdrv_thunk* thunk, void* h) */ void MMSYSTDRV_DeleteThunk(struct mmsystdrv_thunk* thunk) { - thunk->pfn16 = 0; + thunk->callback = 0; + thunk->flags = CALLBACK_NULL; thunk->hMmdrv = NULL; thunk->kind = MMSYSTDRV_MAX; } diff --git a/dlls/mmsystem.dll16/mmsystem.c b/dlls/mmsystem.dll16/mmsystem.c index 66311bb71cc..e9f2b3a5a5d 100644 --- a/dlls/mmsystem.dll16/mmsystem.c +++ b/dlls/mmsystem.dll16/mmsystem.c @@ -400,16 +400,13 @@ UINT16 WINAPI mixerOpen16(LPHMIXER16 lphmix, UINT16 uDeviceID, DWORD dwCallback, UINT ret; struct mmsystdrv_thunk* thunk; - if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_MIXER))) + if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, fdwOpen, MMSYSTDRV_MIXER))) { return MMSYSERR_NOMEM; } - if ((fdwOpen & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION) - { - dwCallback = (DWORD)thunk; - } - - ret = mixerOpen(&hmix, uDeviceID, dwCallback, dwInstance, fdwOpen); + if ((fdwOpen & CALLBACK_TYPEMASK) != CALLBACK_NULL) + fdwOpen = (fdwOpen & ~CALLBACK_TYPEMASK) | CALLBACK_FUNCTION; + ret = mixerOpen(&hmix, uDeviceID, (DWORD)thunk, dwInstance, fdwOpen); if (ret == MMSYSERR_NOERROR) { if (lphmix) *lphmix = HMIXER_16(hmix); @@ -747,15 +744,13 @@ UINT16 WINAPI midiOutOpen16(HMIDIOUT16* lphMidiOut, UINT16 uDeviceID, UINT ret; struct mmsystdrv_thunk* thunk; - if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_MIDIOUT))) + if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, dwFlags, MMSYSTDRV_MIDIOUT))) { return MMSYSERR_NOMEM; } - if ((dwFlags & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION) - { - dwCallback = (DWORD)thunk; - } - ret = midiOutOpen(&hmo, uDeviceID, dwCallback, dwInstance, dwFlags); + if ((dwFlags & CALLBACK_TYPEMASK) != CALLBACK_NULL) + dwFlags = (dwFlags & ~CALLBACK_TYPEMASK) | CALLBACK_FUNCTION; + ret = midiOutOpen(&hmo, uDeviceID, (DWORD)thunk, dwInstance, dwFlags); if (ret == MMSYSERR_NOERROR) { if (lphMidiOut != NULL) *lphMidiOut = HMIDIOUT_16(hmo); @@ -953,15 +948,13 @@ UINT16 WINAPI midiInOpen16(HMIDIIN16* lphMidiIn, UINT16 uDeviceID, UINT ret; struct mmsystdrv_thunk* thunk; - if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_MIDIIN))) + if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, dwFlags, MMSYSTDRV_MIDIIN))) { return MMSYSERR_NOMEM; } - if ((dwFlags & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION) - { - dwCallback = (DWORD)thunk; - } - ret = midiInOpen(&hmid, uDeviceID, dwCallback, dwInstance, dwFlags); + if ((dwFlags & CALLBACK_TYPEMASK) != CALLBACK_NULL) + dwFlags = (dwFlags & ~CALLBACK_TYPEMASK) | CALLBACK_FUNCTION; + ret = midiInOpen(&hmid, uDeviceID, (DWORD)thunk, dwInstance, dwFlags); if (ret == MMSYSERR_NOERROR) { if (lphMidiIn) *lphMidiIn = HMIDIIN_16(hmid); @@ -1116,15 +1109,13 @@ MMRESULT16 WINAPI midiStreamOpen16(HMIDISTRM16* phMidiStrm, LPUINT16 devid, return MMSYSERR_INVALPARAM; devid32 = *devid; - if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_MIDIOUT))) + if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, fdwOpen, MMSYSTDRV_MIDIOUT))) { return MMSYSERR_NOMEM; } - if ((fdwOpen & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION) - { - dwCallback = (DWORD)thunk; - } - ret = midiStreamOpen(&hMidiStrm32, &devid32, cMidi, dwCallback, dwInstance, fdwOpen); + if ((fdwOpen & CALLBACK_TYPEMASK) != CALLBACK_NULL) + fdwOpen = (fdwOpen & ~CALLBACK_TYPEMASK) | CALLBACK_FUNCTION; + ret = midiStreamOpen(&hMidiStrm32, &devid32, cMidi, (DWORD)thunk, dwInstance, fdwOpen); if (ret == MMSYSERR_NOERROR) { *phMidiStrm = HMIDISTRM_16(hMidiStrm32); @@ -1252,21 +1243,19 @@ UINT16 WINAPI waveOutOpen16(HWAVEOUT16* lphWaveOut, UINT16 uDeviceID, UINT ret; struct mmsystdrv_thunk* thunk; - if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_WAVEOUT))) + if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, dwFlags, MMSYSTDRV_WAVEOUT))) { return MMSYSERR_NOMEM; } - if ((dwFlags & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION) - { - dwCallback = (DWORD)thunk; - } + if ((dwFlags & CALLBACK_TYPEMASK) != CALLBACK_NULL) + dwFlags = (dwFlags & ~CALLBACK_TYPEMASK) | CALLBACK_FUNCTION; /* since layout of WAVEFORMATEX is the same for 16/32 bits, we directly * call the 32 bit version * however, we need to promote correctly the wave mapper id * (0xFFFFFFFF and not 0x0000FFFF) */ ret = waveOutOpen(&hWaveOut, (uDeviceID == (UINT16)-1) ? (UINT)-1 : uDeviceID, - lpFormat, dwCallback, dwInstance, dwFlags); + lpFormat, (DWORD)thunk, dwInstance, dwFlags); if (ret == MMSYSERR_NOERROR) { @@ -1547,21 +1536,19 @@ UINT16 WINAPI waveInOpen16(HWAVEIN16* lphWaveIn, UINT16 uDeviceID, UINT ret; struct mmsystdrv_thunk* thunk; - if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_WAVEIN))) + if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, dwFlags, MMSYSTDRV_WAVEIN))) { return MMSYSERR_NOMEM; } - if ((dwFlags & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION) - { - dwCallback = (DWORD)thunk; - } + if ((dwFlags & CALLBACK_TYPEMASK) != CALLBACK_NULL) + dwFlags = (dwFlags & ~CALLBACK_TYPEMASK) | CALLBACK_FUNCTION; /* since layout of WAVEFORMATEX is the same for 16/32 bits, we directly * call the 32 bit version * however, we need to promote correctly the wave mapper id * (0xFFFFFFFF and not 0x0000FFFF) */ ret = waveInOpen(&hWaveIn, (uDeviceID == (UINT16)-1) ? (UINT)-1 : uDeviceID, - lpFormat, dwCallback, dwInstance, dwFlags); + lpFormat, (DWORD)thunk, dwInstance, dwFlags); if (ret == MMSYSERR_NOERROR) { diff --git a/dlls/mmsystem.dll16/winemm16.h b/dlls/mmsystem.dll16/winemm16.h index e8cad537d8e..e76ee34fbc4 100644 --- a/dlls/mmsystem.dll16/winemm16.h +++ b/dlls/mmsystem.dll16/winemm16.h @@ -73,7 +73,7 @@ enum MMSYSTEM_DriverType MMSYSTDRV_MAX }; -extern struct mmsystdrv_thunk* MMSYSTDRV_AddThunk(DWORD pfn16, enum MMSYSTEM_DriverType kind); +extern struct mmsystdrv_thunk* MMSYSTDRV_AddThunk(DWORD callback, DWORD flags, enum MMSYSTEM_DriverType kind); extern void MMSYSTDRV_DeleteThunk(struct mmsystdrv_thunk* thunk); extern void MMSYSTDRV_SetHandle(struct mmsystdrv_thunk* thunk, void* h); extern void MMSYSTDRV_CloseHandle(void* h);