ChangeLog: - all driver functions are now properly separated (Alexandre, from this patch on, make checklink is ok) A+
--- winmm_9/driver.c Tue Oct 29 12:05:30 2002 +++ winmm_10/driver.c Tue Oct 29 13:43:02 2002 @@ -25,16 +25,20 @@ #include <string.h> #include "heap.h" #include "windef.h" +#include "wingdi.h" +#include "winuser.h" #include "mmddk.h" #include "winemm.h" -#include "wine/winbase16.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(driver); -static LPWINE_DRIVER lpDrvItemList = NULL; +static LPWINE_DRIVER lpDrvItemList /* = NULL */; -WINE_MMTHREAD* (*pFnGetMMThread16)(HANDLE16 h) /* = NULL */; +WINE_MMTHREAD* (*pFnGetMMThread16)(HANDLE16 h) /* = NULL */; +LPWINE_DRIVER (*pFnOpenDriver16)(LPCSTR,LPCSTR,LPARAM) /* = NULL */; +LRESULT (*pFnCloseDriver16)(HDRVR16,LPARAM,LPARAM) /* = NULL */; +LRESULT (*pFnSendMessage16)(HDRVR16,UINT,LPARAM,LPARAM) /* = NULL */; /************************************************************************** * DRIVER_GetNumberOfModuleRefs [internal] @@ -77,26 +81,23 @@ * DRIVER_SendMessage [internal] */ static LRESULT inline DRIVER_SendMessage(LPWINE_DRIVER lpDrv, UINT msg, - LPARAM lParam1, LPARAM lParam2) + LPARAM lParam1, LPARAM lParam2) { + LRESULT ret = 0; + if (lpDrv->dwFlags & WINE_GDF_16BIT) { - LRESULT ret; - int map = 0; - TRACE("Before sdm16 call hDrv=%04x wMsg=%04x p1=%08lx p2=%08lx\n", - lpDrv->d.d16.hDriver16, msg, lParam1, lParam2); - - if ((map = DRIVER_MapMsg32To16(msg, &lParam1, &lParam2)) >= 0) { - ret = SendDriverMessage16(lpDrv->d.d16.hDriver16, msg, lParam1, lParam2); - if (map == 1) - DRIVER_UnMapMsg32To16(msg, lParam1, lParam2); - } else { - ret = 0; - } - return ret; + /* no need to check mmsystem presence: the driver must have been opened as a 16 bit one, + */ + if (pFnSendMessage16) + ret = pFnSendMessage16(lpDrv->d.d16.hDriver16, msg, lParam1, lParam2); + } else { + TRACE("Before call32 proc=%p drvrID=%08lx hDrv=%08x wMsg=%04x p1=%08lx p2=%08lx\n", + lpDrv->d.d32.lpDrvProc, lpDrv->d.d32.dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2); + ret = lpDrv->d.d32.lpDrvProc(lpDrv->d.d32.dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2); + TRACE("After call32 proc=%p drvrID=%08lx hDrv=%08x wMsg=%04x p1=%08lx p2=%08lx => %08lx\n", + lpDrv->d.d32.lpDrvProc, lpDrv->d.d32.dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2, ret); } - TRACE("Before func32 call proc=%p driverID=%08lx hDrv=%08x wMsg=%04x p1=%08lx p2=%08lx\n", - lpDrv->d.d32.lpDrvProc, lpDrv->d.d32.dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2); - return lpDrv->d.d32.lpDrvProc(lpDrv->d.d32.dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2); + return ret; } /************************************************************************** @@ -275,40 +276,6 @@ } /************************************************************************** - * DRIVER_TryOpenDriver16 [internal] - * - * Tries to load a 16 bit driver whose DLL's (module) name is lpFileName. - */ -static LPWINE_DRIVER DRIVER_TryOpenDriver16(LPCSTR fn, LPCSTR sn, LPARAM lParam2) -{ - LPWINE_DRIVER lpDrv = NULL; - LPCSTR cause = 0; - - TRACE("(%s, %08lX);\n", debugstr_a(sn), lParam2); - - lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER)); - if (lpDrv == NULL) {cause = "OOM"; goto exit;} - - /* FIXME: shall we do some black magic here on sn ? - * drivers32 => drivers - * mci32 => mci - * ... - */ - lpDrv->d.d16.hDriver16 = OpenDriver16(fn, sn, lParam2); - if (lpDrv->d.d16.hDriver16 == 0) {cause = "Not a 16 bit driver"; goto exit;} - lpDrv->dwFlags = WINE_GDF_16BIT; - - if (!DRIVER_AddToList(lpDrv, 0, lParam2)) {cause = "load failed"; goto exit;} - - TRACE("=> %p\n", lpDrv); - return lpDrv; - exit: - HeapFree(GetProcessHeap(), 0, lpDrv); - TRACE("Unable to load 32 bit module %s: %s\n", debugstr_a(fn), cause); - return NULL; -} - -/************************************************************************** * OpenDriverA [WINMM.@] * DrvOpenA [WINMM.@] * (0,1,DRV_LOAD ,0 ,0) @@ -334,8 +301,20 @@ (lpDrv = DRIVER_TryOpenDriver32(libName, lParam2))) goto the_end; - if (!(lpDrv = DRIVER_TryOpenDriver16(lpDriverName, lpSectionName, lParam2))) - TRACE("Failed to open driver %s from system.ini file, section %s\n", debugstr_a(lpDriverName), debugstr_a(lpSectionName)); + /* now we will try a 16 bit driver (and add all the glue to make it work... which + * is located in our mmsystem implementation) + * so ensure, we can load our mmsystem, otherwise just fail + */ + WINMM_CheckForMMSystem(); + if (pFnOpenDriver16 && + (lpDrv = pFnOpenDriver16(lpDriverName, lpSectionName, lParam2))) + { + if (DRIVER_AddToList(lpDrv, 0, lParam2)) goto the_end; + HeapFree(GetProcessHeap(), 0, lpDrv); + } + TRACE("Failed to open driver %s from system.ini file, section %s\n", debugstr_a(lpDriverName), debugstr_a(lpSectionName)); + return 0; + the_end: if (lpDrv) TRACE("=> %08lx\n", (DWORD)lpDrv); return (HDRVR)lpDrv; @@ -369,7 +348,10 @@ if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) { if (lpDrv->dwFlags & WINE_GDF_16BIT) - CloseDriver16(lpDrv->d.d16.hDriver16, lParam1, lParam2); + { + if (pFnCloseDriver16) + pFnCloseDriver16(lpDrv->d.d16.hDriver16, lParam1, lParam2); + } else { DRIVER_SendMessage(lpDrv, DRV_CLOSE, lParam1, lParam2); @@ -463,4 +445,65 @@ default: return 0; } +} + +/************************************************************************** + * DriverCallback [WINMM.@] + */ +BOOL WINAPI DriverCallback(DWORD dwCallBack, UINT uFlags, HDRVR hDev, + UINT wMsg, DWORD dwUser, DWORD dwParam1, + DWORD dwParam2) +{ + TRACE("(%08lX, %04X, %04X, %04X, %08lX, %08lX, %08lX); !\n", + dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2); + + switch (uFlags & DCB_TYPEMASK) { + case DCB_NULL: + TRACE("Null !\n"); + if (dwCallBack) + WARN("uFlags=%04X has null DCB value, but dwCallBack=%08lX is not null !\n", uFlags, dwCallBack); + break; + case DCB_WINDOW: + TRACE("Window(%04lX) handle=%04X!\n", dwCallBack, hDev); + PostMessageA((HWND)dwCallBack, wMsg, (WPARAM)hDev, dwParam1); + break; + case DCB_TASK: /* aka DCB_THREAD */ + TRACE("Task(%04lx) !\n", dwCallBack); + PostThreadMessageA(dwCallBack, wMsg, (WPARAM)hDev, dwParam1); + break; + case DCB_FUNCTION: + TRACE("Function (32 bit) !\n"); + ((LPDRVCALLBACK)dwCallBack)(hDev, wMsg, dwUser, dwParam1, dwParam2); + break; + case DCB_EVENT: + TRACE("Event(%08lx) !\n", dwCallBack); + SetEvent((HANDLE)dwCallBack); + break; + case 6: /* I would dub it DCB_MMTHREADSIGNAL */ + /* this is an undocumented DCB_ value used for mmThreads + * loword of dwCallBack contains the handle of the lpMMThd block + * which dwSignalCount has to be incremented + */ + if (pFnGetMMThread16) + { + WINE_MMTHREAD* lpMMThd = pFnGetMMThread16(LOWORD(dwCallBack)); + + TRACE("mmThread (%04x, %p) !\n", LOWORD(dwCallBack), lpMMThd); + /* same as mmThreadSignal16 */ + InterlockedIncrement(&lpMMThd->dwSignalCount); + SetEvent(lpMMThd->hEvent); + /* some other stuff on lpMMThd->hVxD */ + } + break; +#if 0 + case 4: + /* this is an undocumented DCB_ value for... I don't know */ + break; +#endif + default: + WARN("Unknown callback type %d\n", uFlags & DCB_TYPEMASK); + return FALSE; + } + TRACE("Done\n"); + return TRUE; } --- winmm_9/mmsystem.c Tue Oct 29 14:19:36 2002 +++ winmm_10/mmsystem.c Tue Oct 29 14:20:01 2002 @@ -50,6 +50,9 @@ /* ### stop build ### */ static WINE_MMTHREAD* WINMM_GetmmThread(HANDLE16); +static LPWINE_DRIVER DRIVER_OpenDriver16(LPCSTR, LPCSTR, LPARAM); +static LRESULT DRIVER_CloseDriver16(HDRVR16, LPARAM, LPARAM); +static LRESULT DRIVER_SendMessage16(HDRVR16, UINT, LPARAM, LPARAM); static LRESULT MMIO_Callback16(SEGPTR, LPMMIOINFO, UINT, LPARAM, LPARAM); /* ################################################### @@ -81,11 +84,17 @@ WINMM_IData->hWinMM16Instance = hinstDLL; /* hook in our 16 bit function pointers */ pFnGetMMThread16 = WINMM_GetmmThread; + pFnOpenDriver16 = DRIVER_OpenDriver16; + pFnCloseDriver16 = DRIVER_CloseDriver16; + pFnSendMessage16 = DRIVER_SendMessage16; pFnMmioCallback16 = MMIO_Callback16; break; case DLL_PROCESS_DETACH: WINMM_IData->hWinMM16Instance = 0; pFnGetMMThread16 = NULL; + pFnOpenDriver16 = NULL; + pFnCloseDriver16 = NULL; + pFnSendMessage16 = NULL; pFnMmioCallback16 = NULL; break; case DLL_THREAD_ATTACH: @@ -2183,11 +2192,11 @@ */ /************************************************************************** - * DRIVER_MapMsg32To16 [internal] + * DRIVER_MapMsg32To16 [internal] * * Map a 32 bit driver message to a 16 bit driver message. */ -WINMM_MapType DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lParam2) +static WINMM_MapType DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lParam2) { WINMM_MapType ret = WINMM_MAP_MSGERROR; @@ -2201,63 +2210,63 @@ case DRV_EXITSESSION: case DRV_EXITAPPLICATION: case DRV_POWER: - case DRV_CLOSE: /* should be 0/0 */ - case DRV_OPEN: /* pass through */ - /* lParam1 and lParam2 are not used */ - ret = WINMM_MAP_OK; - break; + case DRV_CLOSE: /* should be 0/0 */ + case DRV_OPEN: /* pass through */ + /* lParam1 and lParam2 are not used */ + ret = WINMM_MAP_OK; + break; case DRV_CONFIGURE: case DRV_INSTALL: - /* lParam1 is a handle to a window (conf) or to a driver (inst) or not used, - * lParam2 is a pointer to DRVCONFIGINFO - */ - if (*lParam2) { + /* lParam1 is a handle to a window (conf) or to a driver (inst) or not used, + * lParam2 is a pointer to DRVCONFIGINFO + */ + if (*lParam2) { LPDRVCONFIGINFO16 dci16 = HeapAlloc( GetProcessHeap(), 0, sizeof(*dci16) ); - LPDRVCONFIGINFO dci32 = (LPDRVCONFIGINFO)(*lParam2); + LPDRVCONFIGINFO dci32 = (LPDRVCONFIGINFO)(*lParam2); - if (dci16) { - LPSTR str1; + if (dci16) { + LPSTR str1; - dci16->dwDCISize = sizeof(DRVCONFIGINFO16); + dci16->dwDCISize = sizeof(DRVCONFIGINFO16); - if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCISectionName)) != NULL) + if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCISectionName)) != NULL) { - dci16->lpszDCISectionName = MapLS( str1 ); - } else { - return WINMM_MAP_NOMEM; - } - if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCIAliasName)) != NULL) + dci16->lpszDCISectionName = MapLS( str1 ); + } else { + return WINMM_MAP_NOMEM; + } + if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCIAliasName)) != NULL) { - dci16->lpszDCIAliasName = MapLS( str1 ); - } else { - return WINMM_MAP_NOMEM; - } - } else { - return WINMM_MAP_NOMEM; - } - *lParam2 = MapLS( dci16 ); - ret = WINMM_MAP_OKMEM; - } else { - ret = WINMM_MAP_OK; - } - break; + dci16->lpszDCIAliasName = MapLS( str1 ); + } else { + return WINMM_MAP_NOMEM; + } + } else { + return WINMM_MAP_NOMEM; + } + *lParam2 = MapLS( dci16 ); + ret = WINMM_MAP_OKMEM; + } else { + ret = WINMM_MAP_OK; + } + break; default: - if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) { - FIXME("Unknown message 0x%04x\n", wMsg); - } - ret = WINMM_MAP_OK; + if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) { + FIXME("Unknown message 0x%04x\n", wMsg); + } + ret = WINMM_MAP_OK; } return ret; } /************************************************************************** - * DRIVER_UnMapMsg32To16 [internal] + * DRIVER_UnMapMsg32To16 [internal] * * UnMap a 32 bit driver message to a 16 bit driver message. */ -WINMM_MapType DRIVER_UnMapMsg32To16(WORD wMsg, DWORD lParam1, DWORD lParam2) +static WINMM_MapType DRIVER_UnMapMsg32To16(WORD wMsg, DWORD lParam1, DWORD lParam2) { - WINMM_MapType ret = WINMM_MAP_MSGERROR; + WINMM_MapType ret = WINMM_MAP_MSGERROR; switch (wMsg) { case DRV_LOAD: @@ -2271,29 +2280,97 @@ case DRV_POWER: case DRV_OPEN: case DRV_CLOSE: - /* lParam1 and lParam2 are not used */ - break; + /* lParam1 and lParam2 are not used */ + break; case DRV_CONFIGURE: case DRV_INSTALL: - /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */ - if (lParam2) { - LPDRVCONFIGINFO16 dci16 = MapSL(lParam2); + /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */ + if (lParam2) { + LPDRVCONFIGINFO16 dci16 = MapSL(lParam2); HeapFree( GetProcessHeap(), 0, MapSL(dci16->lpszDCISectionName) ); HeapFree( GetProcessHeap(), 0, MapSL(dci16->lpszDCIAliasName) ); UnMapLS( lParam2 ); UnMapLS( dci16->lpszDCISectionName ); UnMapLS( dci16->lpszDCIAliasName ); HeapFree( GetProcessHeap(), 0, dci16 ); - } - ret = WINMM_MAP_OK; - break; + } + ret = WINMM_MAP_OK; + break; default: - if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) { - FIXME("Unknown message 0x%04x\n", wMsg); - } - ret = WINMM_MAP_OK; + if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) { + FIXME("Unknown message 0x%04x\n", wMsg); + } + ret = WINMM_MAP_OK; } return ret; +} + +/************************************************************************** + * DRIVER_TryOpenDriver16 [internal] + * + * Tries to load a 16 bit driver whose DLL's (module) name is lpFileName. + */ +static LPWINE_DRIVER DRIVER_OpenDriver16(LPCSTR fn, LPCSTR sn, LPARAM lParam2) +{ + LPWINE_DRIVER lpDrv = NULL; + LPCSTR cause = 0; + + TRACE("(%s, %08lX);\n", debugstr_a(sn), lParam2); + + lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER)); + if (lpDrv == NULL) {cause = "OOM"; goto exit;} + + /* FIXME: shall we do some black magic here on sn ? + * drivers32 => drivers + * mci32 => mci + * ... + */ + lpDrv->d.d16.hDriver16 = OpenDriver16(fn, sn, lParam2); + if (lpDrv->d.d16.hDriver16 == 0) {cause = "Not a 16 bit driver"; goto exit;} + lpDrv->dwFlags = WINE_GDF_16BIT; + + TRACE("=> %p\n", lpDrv); + return lpDrv; + exit: + HeapFree(GetProcessHeap(), 0, lpDrv); + TRACE("Unable to load 16 bit module %s: %s\n", debugstr_a(fn), cause); + return NULL; +} + +/****************************************************************** + * DRIVER_SendMessage16 + * + * + */ +static LRESULT DRIVER_SendMessage16(HDRVR16 hDrv16, UINT msg, + LPARAM lParam1, LPARAM lParam2) +{ + LRESULT ret = 0; + WINMM_MapType map; + + TRACE("Before sdm16 call hDrv=%04x wMsg=%04x p1=%08lx p2=%08lx\n", + hDrv16, msg, lParam1, lParam2); + + switch (map = DRIVER_MapMsg32To16(msg, &lParam1, &lParam2)) { + case WINMM_MAP_OKMEM: + case WINMM_MAP_OK: + ret = SendDriverMessage16(hDrv16, msg, lParam1, lParam2); + if (map == WINMM_MAP_OKMEM) + DRIVER_UnMapMsg32To16(msg, lParam1, lParam2); + default: + break; + } + return ret; +} + +/****************************************************************** + * DRIVER_CloseDriver16 + * + * + */ +static LRESULT DRIVER_CloseDriver16(HDRVR16 hDrv16, LPARAM lParam1, LPARAM lParam2) +{ + return CloseDriver16(hDrv16, lParam1, lParam2); } /************************************************************************** --- winmm_9/playsound.c Sat Oct 26 15:06:40 2002 +++ winmm_10/playsound.c Tue Oct 29 13:42:21 2002 @@ -506,62 +506,3 @@ return 0x030a; } -/************************************************************************** - * DriverCallback [WINMM.@] - */ -BOOL WINAPI DriverCallback(DWORD dwCallBack, UINT uFlags, HDRVR hDev, - UINT wMsg, DWORD dwUser, DWORD dwParam1, - DWORD dwParam2) -{ - TRACE("(%08lX, %04X, %04X, %04X, %08lX, %08lX, %08lX); !\n", - dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2); - - switch (uFlags & DCB_TYPEMASK) { - case DCB_NULL: - TRACE("Null !\n"); - if (dwCallBack) - WARN("uFlags=%04X has null DCB value, but dwCallBack=%08lX is not null !\n", uFlags, dwCallBack); - break; - case DCB_WINDOW: - TRACE("Window(%04lX) handle=%04X!\n", dwCallBack, hDev); - PostMessageA((HWND)dwCallBack, wMsg, (WPARAM)hDev, dwParam1); - break; - case DCB_TASK: /* aka DCB_THREAD */ - TRACE("Task(%04lx) !\n", dwCallBack); - PostThreadMessageA(dwCallBack, wMsg, (WPARAM)hDev, dwParam1); - break; - case DCB_FUNCTION: - TRACE("Function (32 bit) !\n"); - ((LPDRVCALLBACK)dwCallBack)(hDev, wMsg, dwUser, dwParam1, dwParam2); - break; - case DCB_EVENT: - TRACE("Event(%08lx) !\n", dwCallBack); - SetEvent((HANDLE)dwCallBack); - break; - case 6: /* I would dub it DCB_MMTHREADSIGNAL */ - /* this is an undocumented DCB_ value used for mmThreads - * loword of dwCallBack contains the handle of the lpMMThd block - * which dwSignalCount has to be incremented - */ - { - WINE_MMTHREAD* lpMMThd = MapSL( MAKESEGPTR(LOWORD(dwCallBack), 0) ); - - TRACE("mmThread (%04x, %p) !\n", LOWORD(dwCallBack), lpMMThd); - /* same as mmThreadSignal16 */ - InterlockedIncrement(&lpMMThd->dwSignalCount); - SetEvent(lpMMThd->hEvent); - /* some other stuff on lpMMThd->hVxD */ - } - break; -#if 0 - case 4: - /* this is an undocumented DCB_ value for... I don't know */ - break; -#endif - default: - WARN("Unknown callback type %d\n", uFlags & DCB_TYPEMASK); - return FALSE; - } - TRACE("Done\n"); - return TRUE; -} --- winmm_9/winemm.h Tue Oct 29 16:10:12 2002 +++ winmm_10/winemm.h Tue Oct 29 16:09:33 2002 @@ -290,8 +290,6 @@ void TIME_MMTimeStop(void); /* temporary definitions */ -WINMM_MapType DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lParam2); -WINMM_MapType DRIVER_UnMapMsg32To16(WORD wMsg, DWORD lParam1, DWORD lParam2); WINMM_MapType MCI_MapMsg16To32A (WORD uDevType, WORD wMsg, DWORD* lParam); WINMM_MapType MCI_UnMapMsg16To32A(WORD uDevType, WORD wMsg, DWORD lParam); WINMM_MapType MCI_MapMsg32ATo16 (WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD* lParam); @@ -343,6 +341,9 @@ * NULL otherwise */ extern LRESULT (*pFnMmioCallback16)(SEGPTR,LPMMIOINFO,UINT,LPARAM,LPARAM); +extern LPWINE_DRIVER (*pFnOpenDriver16)(LPCSTR,LPCSTR,LPARAM); +extern LRESULT (*pFnCloseDriver16)(HDRVR16,LPARAM,LPARAM); +extern LRESULT (*pFnSendMessage16)(HDRVR16,UINT,LPARAM,LPARAM); extern WINE_MMTHREAD* (*pFnGetMMThread16)(HANDLE16); /* HANDLE16 -> HANDLE conversions */