Index: trunk/src/winmm/WINMM.DEF
===================================================================
--- trunk/src/winmm/WINMM.DEF	(revision 5429)
+++ trunk/src/winmm/WINMM.DEF	(revision 5433)
@@ -1,3 +1,3 @@
-; $Id: WINMM.DEF,v 1.3 2000-12-24 14:58:21 sandervl Exp $
+; $Id: WINMM.DEF,v 1.4 2001-04-02 09:49:08 sandervl Exp $
 
 ;Created by BLAST for IBM's compiler
@@ -13,13 +13,13 @@
      DefDriverProc              = _DefDriverProc@20        @6
      DriverCallback             = _DriverCallback@28       @7
-;    DrvClose                   = _DrvClose@??                @8
-;    DrvDefDriverProc           = _DrvDefDriverProc@??        @9
-     DrvGetModuleHandle         = _DrvGetModuleHandle@4    @10
-;    DrvOpen                    = _DrvOpen@??                 @11
-;    DrvOpenA                   = _DrvOpenA@??                @12
-     DrvSendMessage             = _DrvSendMessage@16       @13
-;    GetDriverFlags             = _GetDriverFlags@??          @14
+     DrvClose                   = _CloseDriver@12          @8
+     DrvDefDriverProc           = _DefDriverProc@20        @9
+     DrvGetModuleHandle         = _GetDriverModuleHandle@4 @10
+     DrvOpen                    = _OpenDriverA@12          @11
+     DrvOpenA                   = _OpenDriverA@12          @12
+     DrvSendMessage             = _SendDriverMessage@16    @13
+     GetDriverFlags             = _GetDriverFlags@4        @14
      GetDriverModuleHandle      = _GetDriverModuleHandle@4 @15
-     OpenDriver                 = _OpenDriver@12           @16
+     OpenDriver                 = _OpenDriverA@12          @16
      OpenDriverA                = _OpenDriverA@12          @17
      PlaySound                  = _PlaySoundA@12           @18
@@ -27,5 +27,4 @@
      SendDriverMessage          = _SendDriverMessage@16    @20
 
-;    SendDriverMessage          = _SendDriverMessage@??      @20
 ; AUX
     auxGetDevCapsA             = _auxGetDevCapsA@12          @21
Index: trunk/src/winmm/driver.c
===================================================================
--- trunk/src/winmm/driver.c	(revision 5433)
+++ trunk/src/winmm/driver.c	(revision 5433)
@@ -0,0 +1,728 @@
+/* -*- tab-width: 8; c-basic-offset: 4 -*- */
+
+/*
+ * WINE Drivers functions
+ *
+ * Copyright 1994 Martin Ayotte
+ * Copyright 1998 Marcus Meissner
+ * Copyright 1999 Eric Pouech
+ */
+
+#include <string.h>
+#ifdef __WIN32OS2__
+#include "winbase.h"
+#include "winerror.h"
+#include "windef.h"
+#include "wingdi.h"
+#include "winuser.h"
+#include <mmddk.h>
+#include <mmsystem.h>
+#include "winemm.h"
+#include <heapstring.h>
+#define inline
+#else
+#include "heap.h"
+#include "windef.h"
+#include "mmddk.h"
+#include "winemm.h"
+#include "wine/winbase16.h"
+#endif
+#include "debugtools.h"
+
+DEFAULT_DEBUG_CHANNEL(driver);
+
+static LPWINE_DRIVER	lpDrvItemList = NULL;
+
+/* TODO list :
+ *	- LoadModule count and clean up is not handled correctly (it's not a 
+ *	  problem as long as FreeLibrary is not working correctly)
+ */
+
+/**************************************************************************
+ *			DRIVER_GetNumberOfModuleRefs		[internal]
+ *
+ * Returns the number of open drivers which share the same module.
+ */
+static	WORD	DRIVER_GetNumberOfModuleRefs(LPWINE_DRIVER lpNewDrv)
+{
+    LPWINE_DRIVER	lpDrv;
+    WORD		count = 0;
+
+    if (lpNewDrv->dwFlags & WINE_GDF_16BIT) ERR("OOOch");
+    for (lpDrv = lpDrvItemList; lpDrv; lpDrv = lpDrv->lpNextItem) {
+	if (!(lpDrv->dwFlags & WINE_GDF_16BIT) &&
+	    lpDrv->d.d32.hModule == lpNewDrv->d.d32.hModule) {
+	    count++;
+	}
+    }
+    return count;
+}
+
+/**************************************************************************
+ *				DRIVER_FindFromHDrvr		[internal]
+ * 
+ * From a hDrvr being 32 bits, returns the WINE internal structure.
+ */
+LPWINE_DRIVER	DRIVER_FindFromHDrvr(HDRVR hDrvr)
+{    
+    LPWINE_DRIVER	d = (LPWINE_DRIVER)hDrvr;
+
+    if (hDrvr && HeapValidate(GetProcessHeap(), 0, d) && d->dwMagic == WINE_DI_MAGIC) {
+	return d;
+    }
+    return NULL;
+}
+
+#ifndef __WIN32OS2__
+/**************************************************************************
+ *				DRIVER_MapMsg32To16		[internal]
+ *
+ * Map a 32 bit driver message to a 16 bit driver message.
+ *  1 : ok, some memory allocated, need to call DRIVER_UnMapMsg32To16
+ *  0 : ok, no memory allocated
+ * -1 : ko, unknown message
+ * -2 : ko, memory problem
+ */
+static int DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lParam2)
+{
+    int	ret = -1;
+    
+    switch (wMsg) {
+    case DRV_LOAD:
+    case DRV_ENABLE:
+    case DRV_DISABLE:
+    case DRV_FREE:
+    case DRV_QUERYCONFIGURE:
+    case DRV_REMOVE:
+    case DRV_EXITSESSION:
+    case DRV_EXITAPPLICATION:	
+    case DRV_POWER:
+    case DRV_CLOSE:	/* should be 0/0 */
+    case DRV_OPEN:	/* pass thru */
+	/* lParam1 and lParam2 are not used */
+	ret = 0;
+	break;
+	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) {
+            LPDRVCONFIGINFO16	dci16 = (LPDRVCONFIGINFO16)SEGPTR_ALLOC(sizeof(DRVCONFIGINFO16));
+            LPDRVCONFIGINFO	dci32 = (LPDRVCONFIGINFO)(*lParam2);
+	    
+	    if (dci16) {
+		LPSTR	str1, str2;
+		
+		dci16->dwDCISize = sizeof(DRVCONFIGINFO16);
+		
+		if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCISectionName)) != NULL &&
+		    (str2 = SEGPTR_STRDUP(str1)) != NULL) {
+		    dci16->lpszDCISectionName = SEGPTR_GET(str2);
+		    if (!HeapFree(GetProcessHeap(), 0, str1))
+			FIXME("bad free line=%d\n", __LINE__);
+		} else {
+		    return -2;
+		}
+		if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCIAliasName)) != NULL &&
+		    (str2 = SEGPTR_STRDUP(str1)) != NULL) {
+		    dci16->lpszDCIAliasName = SEGPTR_GET(str2);
+		    if (!HeapFree(GetProcessHeap(), 0, str1))
+			FIXME("bad free line=%d\n", __LINE__);
+		} else {
+		    return -2;
+		}
+	    } else {
+		return -2;
+	    }
+	    *lParam2 = (LPARAM)SEGPTR_GET(dci16);
+	    ret = 1;
+	} else {
+	    ret = 0;
+	}
+	break;
+    default:
+	if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
+	   FIXME("Unknown message 0x%04x\n", wMsg);
+	}
+	ret = 0;
+    }
+    return ret;
+}
+
+/**************************************************************************
+ *				DRIVER_UnMapMsg32To16		[internal]
+ *
+ * UnMap a 32 bit driver message to a 16 bit driver message.
+ *  0 : ok
+ * -1 : ko
+ * -2 : ko, memory problem
+ */
+static int DRIVER_UnMapMsg32To16(WORD wMsg, DWORD lParam1, DWORD lParam2)
+{
+    int	ret = -1;
+    
+    switch (wMsg) {
+    case DRV_LOAD:
+    case DRV_ENABLE:
+    case DRV_DISABLE:
+    case DRV_FREE:
+    case DRV_QUERYCONFIGURE:
+    case DRV_REMOVE:
+    case DRV_EXITSESSION:
+    case DRV_EXITAPPLICATION:
+    case DRV_POWER:
+    case DRV_OPEN:
+    case DRV_CLOSE:
+	/* 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);
+	    
+	    if (!SEGPTR_FREE(MapSL(dci16->lpszDCISectionName)))
+		FIXME("bad free line=%d\n", __LINE__);
+	    if (!SEGPTR_FREE(MapSL(dci16->lpszDCIAliasName)))
+		FIXME("bad free line=%d\n", __LINE__);
+	    if (!SEGPTR_FREE(dci16))
+		FIXME("bad free line=%d\n", __LINE__);
+	}
+	ret = 0;
+	break;
+    default:
+	if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
+	    FIXME("Unknown message 0x%04x\n", wMsg);
+	}
+	ret = 0;
+    }
+    return ret;
+}
+#endif //#ifndef __WIN32OS2__
+
+/**************************************************************************
+ *				DRIVER_SendMessage		[internal]
+ */
+static LRESULT inline DRIVER_SendMessage(LPWINE_DRIVER lpDrv, UINT msg, 
+					LPARAM lParam1, LPARAM lParam2)
+{
+#ifndef __WIN32OS2__
+    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;
+    }
+#endif
+    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);
+}
+
+/**************************************************************************
+ *				SendDriverMessage		[WINMM.19]
+ */
+LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT msg, LPARAM lParam1,
+				 LPARAM lParam2)
+{
+    LPWINE_DRIVER	lpDrv;
+    LRESULT 		retval = 0;
+    
+    TRACE("(%04x, %04X, %08lX, %08lX)\n", hDriver, msg, lParam1, lParam2);
+    
+    if ((lpDrv = DRIVER_FindFromHDrvr(hDriver)) != NULL) {
+	retval = DRIVER_SendMessage(lpDrv, msg, lParam1, lParam2);
+    } else {
+	WARN("Bad driver handle %u\n", hDriver);
+    }
+    TRACE("retval = %ld\n", retval);
+    
+    return retval;
+}
+
+/**************************************************************************
+ *				DRIVER_RemoveFromList		[internal]
+ *
+ * Generates all the logic to handle driver closure / deletion
+ * Removes a driver struct to the list of open drivers.
+ */
+static	BOOL	DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv)
+{
+    if (!(lpDrv->dwFlags & WINE_GDF_16BIT)) {
+	if (DRIVER_GetNumberOfModuleRefs(lpDrv) == 1) {
+	    DRIVER_SendMessage(lpDrv, DRV_DISABLE, 0L, 0L);
+	    DRIVER_SendMessage(lpDrv, DRV_FREE,    0L, 0L);
+	}
+    }
+    
+    if (lpDrv->lpPrevItem)
+	lpDrv->lpPrevItem->lpNextItem = lpDrv->lpNextItem;
+    else
+	lpDrvItemList = lpDrv->lpNextItem;
+    if (lpDrv->lpNextItem)
+	lpDrv->lpNextItem->lpPrevItem = lpDrv->lpPrevItem;
+
+    return TRUE;
+}
+
+/**************************************************************************
+ *				DRIVER_AddToList		[internal]
+ *
+ * Adds a driver struct to the list of open drivers.
+ * Generates all the logic to handle driver creation / open.
+ */
+static	BOOL	DRIVER_AddToList(LPWINE_DRIVER lpNewDrv, LPARAM lParam1, LPARAM lParam2)
+{
+    lpNewDrv->dwMagic = WINE_DI_MAGIC;
+    /* First driver to be loaded for this module, need to load correctly the module */
+    if (!(lpNewDrv->dwFlags & WINE_GDF_16BIT)) {
+	if (DRIVER_GetNumberOfModuleRefs(lpNewDrv) == 0) {
+	    if (DRIVER_SendMessage(lpNewDrv, DRV_LOAD, 0L, 0L) != DRV_SUCCESS) {
+		TRACE("DRV_LOAD failed on driver 0x%08lx\n", (DWORD)lpNewDrv);
+		return FALSE;
+	    }
+	    /* returned value is not checked */
+	    DRIVER_SendMessage(lpNewDrv, DRV_ENABLE, 0L, 0L);
+	}
+    }
+
+    lpNewDrv->lpNextItem = NULL;
+    if (lpDrvItemList == NULL) {
+	lpDrvItemList = lpNewDrv;
+	lpNewDrv->lpPrevItem = NULL;
+    } else {
+	LPWINE_DRIVER	lpDrv = lpDrvItemList;	/* find end of list */
+	while (lpDrv->lpNextItem != NULL)
+	    lpDrv = lpDrv->lpNextItem;
+	
+	lpDrv->lpNextItem = lpNewDrv;
+	lpNewDrv->lpPrevItem = lpDrv;
+    }
+
+    if (!(lpNewDrv->dwFlags & WINE_GDF_16BIT)) {
+	/* Now just open a new instance of a driver on this module */
+	lpNewDrv->d.d32.dwDriverID = DRIVER_SendMessage(lpNewDrv, DRV_OPEN, lParam1, lParam2);
+
+	if (lpNewDrv->d.d32.dwDriverID == 0) {
+	    TRACE("DRV_OPEN failed on driver 0x%08lx\n", (DWORD)lpNewDrv);
+	    DRIVER_RemoveFromList(lpNewDrv);
+	    return FALSE;
+	}
+    }
+    return TRUE;
+}
+
+/**************************************************************************
+ *				DRIVER_GetLibName		[internal]
+ *
+ */
+BOOL	DRIVER_GetLibName(LPCSTR keyName, LPCSTR sectName, LPSTR buf, int sz)
+{
+    /* should also do some registry diving */
+    return GetPrivateProfileStringA(sectName, keyName, "", buf, sz, "SYSTEM.INI");
+}
+
+/**************************************************************************
+ *				DRIVER_TryOpenDriver32		[internal]
+ *
+ * Tries to load a 32 bit driver whose DLL's (module) name is fn
+ */
+LPWINE_DRIVER	DRIVER_TryOpenDriver32(LPCSTR fn, LPARAM lParam2)
+{
+    LPWINE_DRIVER 	lpDrv = NULL;
+    HMODULE		hModule = 0;
+    LPSTR		ptr;
+    LPCSTR		cause = 0;
+
+    TRACE("('%s', %08lX);\n", fn, lParam2);
+    
+    if ((ptr = strchr(fn, ' ')) != NULL) {
+	*ptr++ = '\0';
+	while (*ptr == ' ') ptr++;
+	if (*ptr == '\0') ptr = NULL;
+    }
+
+    lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
+    if (lpDrv == NULL) {cause = "OOM"; goto exit;}
+
+    if ((hModule = LoadLibraryA(fn)) == 0) {cause = "Not a 32 bit lib"; goto exit;}
+
+    lpDrv->d.d32.lpDrvProc = (DRIVERPROC)GetProcAddress(hModule, "DriverProc");
+    if (lpDrv->d.d32.lpDrvProc == NULL) {cause = "no DriverProc"; goto exit;}
+
+    lpDrv->dwFlags          = 0;
+    lpDrv->d.d32.hModule    = hModule;
+    lpDrv->d.d32.dwDriverID = 0;
+
+    if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, lParam2)) {cause = "load faile"; goto exit;}
+
+    TRACE("=> %p\n", lpDrv);
+    return lpDrv;
+ exit:
+    FreeLibrary(hModule);
+    HeapFree(GetProcessHeap(), 0, lpDrv);
+    TRACE("Unable to load 32 bit module \"%s\": %s\n", fn, cause);
+    return NULL;
+}
+#ifdef __WIN32OS2__
+/**************************************************************************
+ *				DRIVER_OpenDriverA		        [internal]
+ * (0,1,DRV_LOAD  ,0       ,0)
+ * (0,1,DRV_ENABLE,0       ,0)
+ * (0,1,DRV_OPEN  ,buf[256],0)
+ *
+ */
+static	LPWINE_DRIVER	DRIVER_TryOpenDriver16(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam)
+{
+  LPWINE_DRIVER lpDrv = NULL;
+  char 		drvName[128];
+  LPCSTR        cause = 0;
+  
+  TRACE("Entering DRIVER_OpenDriverA: lpDriverName: %s lpSectionName: %s\n",lpDriverName,lpSectionName);
+
+  lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
+  if (lpDrv == NULL) {cause = "OOM"; goto exit;}
+
+  if (lpSectionName == NULL) {
+	lstrcpynA(drvName, lpDriverName, sizeof(drvName));
+	lpDrv = DRIVER_TryOpenDriver32(lpDriverName, lParam);
+	if (!lpDrv) {
+      if (GetPrivateProfileStringA("Drivers32", lpDriverName, "", drvName,
+                                   sizeof(drvName), "SYSTEM.INI")) {
+
+		lpDrv = DRIVER_TryOpenDriver32(drvName, lParam);		
+      }
+	}
+  } else {/* of if (lpSectionName == NULL) */
+    //dprintf(("driver name %x '%s'\n",drvName,drvName));
+    drvName[0]=0;    
+
+	if (GetPrivateProfileStringA(lpSectionName, lpDriverName, "", drvName,
+                                 sizeof(drvName)-1, "SYSTEM.INI")) {
+#if 0
+      dprintf(("driver name %x '%s'\n",drvName,drvName));
+#endif      
+      lpDrv = DRIVER_TryOpenDriver32(drvName, lParam);
+	}/* GetPrivate... */
+  }
+  if (!lpDrv)
+	TRACE("OpenDriverA: Failed to open driver %s from section %s\n", lpDriverName, lpSectionName);
+
+  else 
+	TRACE("OpenDriverA success: Driver handle => %08x\n", lpDrv);
+
+  return lpDrv;
+
+ exit:
+    HeapFree(GetProcessHeap(), 0, lpDrv);
+    TRACE("Unable to load 32 bit module \"%s\": %s\n", lpDriverName, cause);
+    return NULL;
+}
+#else
+/**************************************************************************
+ *				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", 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 faile"; goto exit;}
+
+    TRACE("=> %p\n", lpDrv);
+    return lpDrv;
+ exit:
+    HeapFree(GetProcessHeap(), 0, lpDrv);
+    TRACE("Unable to load 32 bit module \"%s\": %s\n", fn, cause);
+    return NULL;
+}
+#endif //#ifndef __WIN32OS2__
+
+/**************************************************************************
+ *				OpenDriverA		        [WINMM.15]
+ * (0,1,DRV_LOAD  ,0       ,0)
+ * (0,1,DRV_ENABLE,0       ,0)
+ * (0,1,DRV_OPEN  ,buf[256],0)
+ */
+HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam2) 
+{
+    LPWINE_DRIVER	lpDrv = NULL;
+    char 		libName[128];
+    LPCSTR		lsn = lpSectionName;
+
+    TRACE("(%s, %s, 0x%08lx);\n", debugstr_a(lpDriverName), debugstr_a(lpSectionName), lParam2);
+    
+    if (lsn == NULL) {
+	lstrcpynA(libName, lpDriverName, sizeof(libName));
+
+	if ((lpDrv = DRIVER_TryOpenDriver32(libName, lParam2)))
+	    goto the_end;
+	lsn = "Drivers32";
+    }
+    if (DRIVER_GetLibName(lpDriverName, lsn, libName, sizeof(libName)) &&
+	(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", lpDriverName, lpSectionName);
+
+ the_end:
+    if (lpDrv)	TRACE("=> %08lx\n", (DWORD)lpDrv);
+    return (DWORD)lpDrv;
+}
+
+/**************************************************************************
+ *				OpenDriverW		        [WINMM.15]
+ */
+HDRVR WINAPI OpenDriverW(LPCWSTR lpDriverName, LPCWSTR lpSectionName, LPARAM lParam)
+{
+    LPSTR 		dn = HEAP_strdupWtoA(GetProcessHeap(), 0, lpDriverName);
+    LPSTR 		sn = HEAP_strdupWtoA(GetProcessHeap(), 0, lpSectionName);
+    HDRVR		ret = OpenDriverA(dn, sn, lParam);
+    
+    if (dn) HeapFree(GetProcessHeap(), 0, dn);
+    if (sn) HeapFree(GetProcessHeap(), 0, sn);
+    return ret;
+}
+
+/**************************************************************************
+ *			CloseDriver				[WINMM.4]
+ */
+LRESULT WINAPI CloseDriver(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
+{
+    LPWINE_DRIVER	lpDrv;
+
+    TRACE("(%04x, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
+    
+    if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
+#ifndef __WIN32OS2__
+	if (lpDrv->dwFlags & WINE_GDF_16BIT)
+	    CloseDriver16(lpDrv->d.d16.hDriver16, lParam1, lParam2);
+	else
+#endif
+	    DRIVER_SendMessage(lpDrv, DRV_CLOSE, lParam1, lParam2);
+	if (DRIVER_RemoveFromList(lpDrv)) {
+	    HeapFree(GetProcessHeap(), 0, lpDrv);
+	    return TRUE;
+	}
+    }
+    WARN("Failed to close driver\n");
+    return FALSE;
+}
+
+/**************************************************************************
+ *				GetDriverFlags		[WINMM.13]
+ * [in] hDrvr handle to the driver
+ *
+ * Returns:
+ *	0x00000000 if hDrvr is an invalid handle
+ *	0x80000000 if hDrvr is a valid 32 bit driver
+ *	0x90000000 if hDrvr is a valid 16 bit driver
+ *
+ * native WINMM doesn't return those flags
+ *	0x80000000 for a valid 32 bit driver and that's it
+ *	(I may have mixed up the two flags :-(
+ */
+DWORD	WINAPI GetDriverFlags(HDRVR hDrvr)
+{
+    LPWINE_DRIVER 	lpDrv;
+    DWORD		ret = 0;
+
+    TRACE("(%04x)\n", hDrvr);
+
+    if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
+	ret = WINE_GDF_EXIST | lpDrv->dwFlags;
+    }
+    return ret;
+}
+
+/**************************************************************************
+ *				GetDriverModuleHandle	[WINMM.14]
+ */
+HMODULE WINAPI GetDriverModuleHandle(HDRVR hDrvr)
+{
+    LPWINE_DRIVER 	lpDrv;
+    HMODULE		hModule = 0;
+    
+    TRACE("(%04x);\n", hDrvr);
+    
+    if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
+	if (!(lpDrv->dwFlags & WINE_GDF_16BIT))
+	    hModule = lpDrv->d.d32.hModule;
+    }
+    TRACE("=> %04x\n", hModule);
+    return hModule;
+}
+
+#ifndef __WIN32OS2__
+/**************************************************************************
+ * 				DrvOpen	       		[MMSYSTEM.1100]
+ */
+HDRVR16 WINAPI DrvOpen16(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
+{
+    return OpenDriver16(lpDriverName, lpSectionName, lParam);
+}
+
+/**************************************************************************
+ * 				DrvClose       		[MMSYSTEM.1101]
+ */
+LRESULT WINAPI DrvClose16(HDRVR16 hDrv, LPARAM lParam1, LPARAM lParam2)
+{
+    return CloseDriver16(hDrv, lParam1, lParam2);
+}
+
+/**************************************************************************
+ * 				DrvSendMessage		[MMSYSTEM.1102]
+ */
+LRESULT WINAPI DrvSendMessage16(HDRVR16 hDrv, WORD msg, LPARAM lParam1,
+				LPARAM lParam2)
+{
+    return SendDriverMessage16(hDrv, msg, lParam1, lParam2);
+}
+
+/**************************************************************************
+ * 				DrvGetModuleHandle	[MMSYSTEM.1103]
+ */
+HANDLE16 WINAPI DrvGetModuleHandle16(HDRVR16 hDrv)
+{
+    return GetDriverModuleHandle16(hDrv);
+}
+
+/**************************************************************************
+ * 				DrvDefDriverProc	[MMSYSTEM.1104]
+ */
+LRESULT WINAPI DrvDefDriverProc16(DWORD dwDriverID, HDRVR16 hDrv, WORD wMsg, 
+				  DWORD dwParam1, DWORD dwParam2)
+{
+    return DefDriverProc16(dwDriverID, hDrv, wMsg, dwParam1, dwParam2);
+}
+#endif //#ifndef __WIN32OS2__
+
+/**************************************************************************
+ * 				DefDriverProc			  [WINMM.5]
+ */
+LRESULT WINAPI DefDriverProc(DWORD dwDriverIdentifier, HDRVR hDrv,
+			     UINT Msg, LPARAM lParam1, LPARAM lParam2)
+{
+    switch (Msg) {
+    case DRV_LOAD:
+    case DRV_FREE:
+    case DRV_ENABLE:
+    case DRV_DISABLE:
+        return 1;
+    case DRV_INSTALL:
+    case DRV_REMOVE:
+        return DRV_SUCCESS;
+    default:
+        return 0;
+    }
+}
+
+#ifndef __WIN32OS2__
+/**************************************************************************
+ * 				DriverProc			[MMSYSTEM.6]
+ */
+LRESULT WINAPI DriverProc16(DWORD dwDevID, HDRVR16 hDrv, WORD wMsg, 
+			    DWORD dwParam1, DWORD dwParam2)
+{
+    TRACE("dwDevID=%08lx hDrv=%04x wMsg=%04x dwParam1=%08lx dwParam2=%08lx\n",
+	  dwDevID, hDrv, wMsg, dwParam1, dwParam2);
+
+    return DrvDefDriverProc16(dwDevID, hDrv, wMsg, dwParam1, dwParam2);
+}
+#endif //#ifndef __WIN32OS2__
+
+#ifdef __WIN32OS2__
+/**************************************************************************
+ * 				DriverCallback			[MMSYSTEM.31]
+ */
+BOOL WINAPI DriverCallback(DWORD dwCallBack, UINT uFlags, HDRVR hDev, 
+			   UINT wMsg, DWORD dwUser, DWORD dwParam1, 
+			   DWORD dwParam2)
+{
+    TRACE("DriverCallback (%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);
+	if (!IsWindow(dwCallBack))
+	    return FALSE;
+	PostMessageA((HWND)dwCallBack, wMsg, hDev, dwParam1);
+	break;
+    case DCB_TASK: /* aka DCB_THREAD */
+	TRACE("Task(%04lx) !\n", dwCallBack);
+	PostThreadMessageA(dwCallBack, wMsg, 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
+	 */
+	{
+#ifdef __WIN32OS2__
+	    WINE_MMTHREAD*	lpMMThd = (WINE_MMTHREAD*)dwCallBack;
+#else
+	    WINE_MMTHREAD*	lpMMThd = MapSL( MAKESEGPTR(LOWORD(dwCallBack), 0) );
+#endif
+
+	    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;
+}
+#endif
Index: trunk/src/winmm/driver.cpp
===================================================================
--- trunk/src/winmm/driver.cpp	(revision 5429)
+++ 	(revision )
@@ -1,647 +1,0 @@
-/* $Id: driver.cpp,v 1.7 2000-12-03 22:18:17 sandervl Exp $ */
-
-/*
- * Driver multimedia apis
- *
- * Copyright 1994 Martin Ayotte
- * Copyright 1998 Marcus Meissner
- * Copyright 1998 Patrick Haller
- * Copyright 1998/1999 Eric Pouech
- * Copyright 2000 Chris Wohlgemuth
- *
- * Project Odin Software License can be found in LICENSE.TXT
- *
- */
-
-
-/****************************************************************************
- * Includes                                                                 *
- ****************************************************************************/
-
-#include <os2win.h>
-#include <odinwrap.h>
-#include <string.h>
-#include <misc.h>
-#include <unicode.h>
-
-#include "os2timer.h"
-
-#define DBG_LOCALLOG	DBG_driver
-#include "dbglocal.h"
-
-
-/* Who said goofy boy ? */
-#define	WINE_DI_MAGIC	0x900F1B01
-
-typedef struct tagWINE_DRIVER
-{
-    DWORD			dwMagic;
-    char			szAliasName[128];
-    /* as usual LPWINE_DRIVER == hDriver32 */
-    HDRVR16			hDriver16;
-    union {
-       struct {
-	  HMODULE16		hModule;
-	  DRIVERPROC16          lpDrvProc;
-       } d16;
-       struct {
-	  HMODULE		hModule;
-	  DRIVERPROC		lpDrvProc;
-       } d32;
-    } d;
-    DWORD		  	dwDriverID;
-    DWORD			dwFlags;
-    struct tagWINE_DRIVER*	lpPrevItem;
-    struct tagWINE_DRIVER*	lpNextItem;
-} WINE_DRIVER, *LPWINE_DRIVER;
-
-static LPWINE_DRIVER	DRIVER_RegisterDriver32(LPCSTR, HMODULE,   DRIVERPROC,   LPARAM, BOOL);
-
-static LPWINE_DRIVER	lpDrvItemList = NULL;
-
-/* TODO list :
- *	WINE remark: - LoadModule count and clean up is not handled correctly (it's not a 
- *	  problem as long as FreeLibrary is not working correctly)
- *	- shoudln't the allocations be done on a per process basis ?
- */
-
-static HDRVR DRIVER_OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam) ;
-static	LPWINE_DRIVER	DRIVER_FindFromHDrvr(HDRVR hDrvr);
-static BOOL DRIVER_CloseDriver(LPWINE_DRIVER lpDrv, DWORD lParam1, DWORD lParam2);
-
-ODINDEBUGCHANNEL(WINMM-DRIVER)
-
-
-/*****************************************************************************
- *             Sends the specifiedmessage to the installable driver
- * Parameters: HDRVR hDrvr
- *             UINT  msg
- *             LONG  lParam1
- *             LONG  lParam2
- * Variables :
- * @return   : API returncode
- * Remark    :
- * @status   : Completely
- *
- * @author    : Patrick Haller [Tue, 1998/05/05 10:44]
- * @author    : Chris Wohlgemuth [Sun, 2000/11/19]
- *****************************************************************************/
-
-ODINFUNCTION4(LRESULT, SendDriverMessage,
-              HDRVR, hdrvr,
-              UINT, msg,
-              LONG, lParam1,
-              LONG, lParam2)
-{
-    LPWINE_DRIVER	lpDrv;
-    LRESULT 		retval = 0;
-
-    dprintf(("Entering SendDriverMessage (%04x, %04X, %08lX, %08lX)\n", hdrvr, msg, lParam1, lParam2));
-    
-    lpDrv = DRIVER_FindFromHDrvr(hdrvr);
-
-    if (lpDrv != NULL) {
-	if (lpDrv->dwFlags & WINE_GDF_16BIT) {
-#if 0
-      /*We don't use 16 bit */
-      mapRet = DRIVER_MapMsg32To16(msg, &lParam1, &lParam2);
-      if (mapRet >= 0) {
-		TRACE("Before CallDriverProc proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n", 
-		      lpDrv->d.d16.lpDrvProc, lpDrv->dwDriverID, lpDrv->hDriver16, msg, lParam1, lParam2);		  
-		retval = DRIVER_CallTo16_long_lwwll((FARPROC16)lpDrv->d.d16.lpDrvProc, lpDrv->dwDriverID, 
-                                            lpDrv->hDriver16, msg, lParam1, lParam2);
-		if (mapRet >= 1) {
-          DRIVER_UnMapMsg32To16(msg, lParam1, lParam2);
-		}
-      } else {
-		retval = 0;
-      }
-#endif
-	} else {
-
-#if 0
-      dprintf(("Before func32 call proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n", 
-               lpDrv->d.d32.lpDrvProc, lpDrv->dwDriverID, hdrvr, msg, lParam1, lParam2));		  
-#endif
-
-      retval = lpDrv->d.d32.lpDrvProc(lpDrv->dwDriverID, hdrvr, msg, lParam1, lParam2);
-	}
-    } else {
-      dprintf(("Bad driver handle %u\n", hdrvr));
-    }
-
-    dprintf(("(SendDriverMessage) Driver proc returned retval = %ld (0x%lx)\n", retval, retval));
-    
-    return retval;
-}
-
-
-/*****************************************************************************
- *             Opens an instance of an installable driver and initializes
- *             the instance using either the driver's default settings or a
- *             driver-specific value.
- * Parameters: LPCWSTR lpDriverName
- *             LPCWSTR lpSectionName
- *             LONG    lParam
- * Variables :
- * @return   : API returncode
- * Remark    :
- * @status   : Stub
- *
- * @author    : Patrick Haller [Tue, 1998/05/05 10:44]
- *****************************************************************************/
-
-ODINFUNCTION3(HDRVR, OpenDriver,
-              LPCWSTR, lpDriverName,
-              LPCWSTR, lpSectionName,
-              LONG, lParam)
-{
-  dprintf(("WINMM: OpenDriver not implemented.\n"));
-  return 0; /* unsuccessful return */
-}
-
-
-/*****************************************************************************
- *             Opens an instance of an installable driver and initializes
- *             the instance using either the driver's default settings or a
- *             driver-specific value.
- * Parameters: LPCTSTR lpDriverName
- *             LPCTSTR lpSectionName
- *             LONG    lParam
- * Variables :
- * @return   : API returncode
- * Remark    :
- * @status   : Partially tested
- *
- * @author    : Patrick Haller [Tue, 1998/05/05 10:44]
- *****************************************************************************/
-
-ODINFUNCTION3(HDRVR, OpenDriverA,
-              LPCSTR, lpDriverName,
-              LPCSTR, lpSectionName,
-              LONG, lParam)
-{
-  return DRIVER_OpenDriverA(lpDriverName, lpSectionName,  lParam); 
-  //  return 0; /* unsuccessful return */
-}
-
-
-
-/*****************************************************************************
- *             Closes an installable driver.
- * Parameters: HDRVR hDrvr
- *             LONG  lParam1
- *             LONG  lParam2
- * Variables :
- * @return   :
- * Remark    :
- * @status   : Partially tested
- *
- * @author    : Patrick Haller [Tue, 1998/05/05 10:44]
- *****************************************************************************/
-
-ODINFUNCTION3(LRESULT, CloseDriver,
-              HDRVR, hDrvr,
-              LONG, lParam1,
-              LONG, lParam2)
-{
-  return DRIVER_CloseDriver(DRIVER_FindFromHDrvr(hDrvr), lParam1, lParam2);//return 0; /* unsuccessful return */
-}
-
-
-/*****************************************************************************
- *             Provides default processing for anymessages not processed by
- *             an installable driver.
- * Parameters: DWORD dwDriverID
- *             HDRVR hDrvr
- *             UINT  msg
- *             LONG  lParam1
- *             LONG  lParam2
- * Variables :
- * @return   :
- * Remark    :
- * @status   : Partially
- *
- * @author    : Patrick Haller [Tue, 1998/05/05 10:44]
- * @author    : Chris Wohlgemuth [Sun, 2000/11/19]
- *****************************************************************************/
-
-ODINFUNCTION5(LRESULT, DefDriverProc,
-              DWORD, dwDriverID,
-              HDRVR, hDrvr,
-              UINT, msg,
-              LONG, lParam1,
-              LONG, lParam2)
-{
-  switch (msg) {
-  case DRV_LOAD:
-  case DRV_FREE:
-  case DRV_ENABLE:
-  case DRV_DISABLE:
-    // return 1;
-  case DRV_INSTALL:
-  case DRV_REMOVE:
-    //  return DRV_SUCCESS;
-  default:
-    return 0; /* unsuccessful return */
-  }
-
-}
-
-
-/*****************************************************************************
- * Parameters: DWORD dwCallback
- *             DWORD dwFlags
- *             HDRVR hDrvr
- *             DWORD msg
- *             DWORD dwUser
- *             DWORD dwParam1
- *             DWORD dwParam2
- * Variables :
- * @return   :
- * Remark    :
- * @status   : Stub
- *
- * @author    : Patrick Haller [Tue, 1998/05/05 10:44]
- *****************************************************************************/
-
-ODINFUNCTION7(LRESULT, DriverCallback,
-              DWORD, dwCallback,
-              DWORD, dwFlags,
-              HDRVR, hDrvr,
-              DWORD, msg,
-              DWORD, dwUser,
-              DWORD, dwParam1,
-              DWORD, dwParam2)
-{
-  dprintf(("WINMM: DriverCallback not implemented.\n"));
-  return FALSE; /* unsuccessful return */
-}
-
-
-/*****************************************************************************
- * Purpose   : Retrieves the instance handle of the module that contains the
- *             installable driver.
- * Parameters: HDRVR hDriver
- * Variables :
- * @return   :
- * Remark    :
- * @status   : Stub
- *
- * @author    : Patrick Haller [Tue, 1998/05/05 10:44]
- *****************************************************************************/
-
-ODINFUNCTION1(HMODULE, DrvGetModuleHandle,
-              HDRVR, hDriver)
-{
-  dprintf(("WINMM: DrvGetModuleHandle not implemented.\n"));
-  return 0; /* unsuccessful return */
-}
-
-
-/*****************************************************************************
- *             Sends the specified message to the installable driver
- * Parameters: HDRVR hDrvr
- *             UINT  msg
- *             LONG  lParam1
- *             LONG  lParam2
- * Variables :
- * @return   : API returncode
- * Remark    : Ehm, what's the difference to SendDriverMessage() ?
- * @status   : Stub
- *
- * @author    : Patrick Haller [Tue, 1998/05/05 10:44]
- *****************************************************************************/
-
-ODINFUNCTION4(LRESULT, DrvSendMessage,
-              HDRVR, hdrvr,
-              UINT, msg,
-              LONG, lParam1,
-              LONG, lParam2)
-{
-  dprintf(("WINMM: DrvSendMessage not implemented.\n"));
-  return 0; /* unsuccessful return */
-}
-
-
-/*****************************************************************************
- *             Retrieves the instance handle of the module that contains the
- *             installable driver.
- * Parameters: HDRVR hDriver
- * Variables :
- * @return   :
- * Remark    : What's the difference to DrvGetModuleHandle() ?
- * @status   : Completely
- *
- * @author    : Patrick Haller [Tue, 1998/05/05 10:44]
- * @author    : Chris Wohlgemuth [Sun, 2000/11/19]
- *****************************************************************************/
-
-ODINFUNCTION1(HMODULE, GetDriverModuleHandle,
-              HDRVR, hDriver)
-{
-  LPWINE_DRIVER 	lpDrv;
-  HMODULE		hModule = 0;
-  
-#if 0
-  dprintf(("(%04x);\n", hDriver));
-#endif
-
-  lpDrv = DRIVER_FindFromHDrvr(hDriver);
-  if (lpDrv != NULL && !(lpDrv->dwFlags & WINE_GDF_16BIT)) {
-	hModule = lpDrv->d.d32.hModule;
-  
-}
-#if 0
-  dprintf(("=> %d\n", hModule));
-#endif
-  return hModule; //return 0; /* unsuccessful return */
-}
-
-
-
-/**************************************************************************
- *				GetDriverFlags		[WINMM.13]
- * Parameters: HDRVR hDrvr
- * Variables :
- * @return   :	0x00000000 if hDrvr is an invalid handle
- *             	0x80000000 if hDrvr is a valid 32 bit driver
- * Remark    :
- * @status   : Completely
- *
- * @author    : Chris Wohlgemuth [Sun, 2000/11/19] (ported from WINE)
- */
-ODINFUNCTION1(DWORD, GetDriverFlags,
-              HDRVR, hDrvr)
-{
-    LPWINE_DRIVER 	lpDrv;
-    DWORD		ret = 0;
-
-    //TRACE("(%04x)\n", hDrvr);
-
-    if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
-      ret = lpDrv->dwFlags;
-    }
-    return ret;
-}
-
-
-/**************************************************************************/
-/*              Implementation                                            */
-/**************************************************************************/
-
-/**************************************************************************
- *			DRIVER_GetNumberOfModuleRefs		[internal]
- *
- * Returns the number of open drivers which share the same module.
- */
-static	WORD	DRIVER_GetNumberOfModuleRefs(LPWINE_DRIVER lpNewDrv)
-{
-    LPWINE_DRIVER	lpDrv;
-    WORD		count = 0;
-    
-    for (lpDrv = lpDrvItemList; lpDrv; lpDrv = lpDrv->lpNextItem) {
-	if (lpDrv->dwFlags & WINE_GDF_16BIT) {
-	    if (lpDrv->d.d16.hModule == lpNewDrv->d.d16.hModule) {
-		count++;
-	    }
-	} else {
-	    if (lpDrv->d.d32.hModule == lpNewDrv->d.d32.hModule) {
-		count++;
-	    }
-	}
-    }
-    return count;
-}
-
-
-/**************************************************************************
- *				DRIVER_FindFromHDrvr		[internal]
- * 
- * From a hDrvr (being 16 or 32 bits), returns the WINE internal structure.
- */
-static	LPWINE_DRIVER	DRIVER_FindFromHDrvr(HDRVR hDrvr)
-{    
-  if (!IsBadWritePtr((void*)hDrvr, sizeof(WINE_DRIVER)) && 
-      ((LPWINE_DRIVER)hDrvr)->dwMagic == WINE_DI_MAGIC) {
-	return (LPWINE_DRIVER)hDrvr;
-  }
-  return 0;
-}
-
-/**************************************************************************
- *				DRIVER_RemoveFromList		[internal]
- *
- * Generates all the logic to handle driver closure / deletion
- * Removes a driver struct to the list of open drivers.
- *
- */
-static	BOOL	DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv)
-{
-    lpDrv->dwDriverID = 0;
-    if (DRIVER_GetNumberOfModuleRefs(lpDrv) == 1) {
-      SendDriverMessage((HDRVR)lpDrv, DRV_DISABLE, 0L, 0L);
-      SendDriverMessage((HDRVR)lpDrv, DRV_FREE,    0L, 0L);
-    }
-    
-    if (lpDrv->lpPrevItem)
-	lpDrv->lpPrevItem->lpNextItem = lpDrv->lpNextItem;
-    else
-	lpDrvItemList = lpDrv->lpNextItem;
-    if (lpDrv->lpNextItem)
-	lpDrv->lpNextItem->lpPrevItem = lpDrv->lpPrevItem;
-
-    return TRUE;
-}
-
-/**************************************************************************
- *				DRIVER_AddToList		[internal]
- *
- * Adds a driver struct to the list of open drivers.
- * Generates all the logic to handle driver creation / open.
- *
- */
-static	BOOL	DRIVER_AddToList(LPWINE_DRIVER lpNewDrv, LPARAM lParam, BOOL bCallFrom32)
-{
-  lpNewDrv->dwMagic = WINE_DI_MAGIC;
-  /* First driver to be loaded for this module, need to load correctly the module */
-
-  if (DRIVER_GetNumberOfModuleRefs(lpNewDrv) == 0) {
-	if (SendDriverMessage((HDRVR)lpNewDrv, DRV_LOAD, 0L, 0L) != DRV_SUCCESS) {
-      dprintf(("DRV_LOAD failed on driver 0x%08lx\n", (DWORD)lpNewDrv));
-      return FALSE;
-	}
-	if (SendDriverMessage((HDRVR)lpNewDrv, DRV_ENABLE, 0L, 0L) != DRV_SUCCESS) {
-      dprintf(("DRV_ENABLE failed on driver 0x%08lx\n", (DWORD)lpNewDrv));
-      return FALSE;
-	}
-  }
-  
-  lpNewDrv->lpNextItem = NULL;
-  if (lpDrvItemList == NULL) {
-	lpDrvItemList = lpNewDrv;
-	lpNewDrv->lpPrevItem = NULL;
-  } else {
-	LPWINE_DRIVER	lpDrv = lpDrvItemList;	/* find end of list */
-	while (lpDrv->lpNextItem != NULL)
-      lpDrv = lpDrv->lpNextItem;
-	
-	lpDrv->lpNextItem = lpNewDrv;
-	lpNewDrv->lpPrevItem = lpDrv;
-  }
-  /* Now just open a new instance of a driver on this module */
-  
-  lpNewDrv->dwDriverID = SendDriverMessage((HDRVR)lpNewDrv, DRV_OPEN, 0L, lParam);
-  
-  if (lpNewDrv->dwDriverID == 0) {
-	dprintf(("DRV_OPEN failed on driver 0x%08lx\n", (DWORD)lpNewDrv));
-	DRIVER_RemoveFromList(lpNewDrv);
-	return FALSE;
-  }
-    
-  return TRUE;
-}
-
-/**************************************************************************
- *				DRIVER_RegisterDriver32		[internal]
- *
- * Creates all the WINE internal representations for a 32 bit driver.
- * The driver is also open by sending the correct messages.
- *
- */
-static LPWINE_DRIVER DRIVER_RegisterDriver32(LPCSTR lpName, HMODULE hModule, DRIVERPROC lpProc, 
-                                      LPARAM lParam, BOOL bCallFrom32)
-{
-  LPWINE_DRIVER	lpDrv;
-  
-  lpDrv = (LPWINE_DRIVER)HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
-  if (lpDrv != NULL) {
-	lpDrv->dwFlags          = WINE_GDF_EXIST;
-	lpDrv->dwDriverID       = 0;
-    lpDrv->hDriver16        = 0;  /* We don't support 16 bit */
-	lstrcpynA(lpDrv->szAliasName, lpName, sizeof(lpDrv->szAliasName));
-	lpDrv->d.d32.hModule    = hModule;
-	lpDrv->d.d32.lpDrvProc  = lpProc;
-
-	if (!DRIVER_AddToList(lpDrv, lParam, bCallFrom32)) {
-      HeapFree(GetProcessHeap(), 0, lpDrv);
-      lpDrv = NULL;
-	}
-
-  }
-  return lpDrv;
-}
-
-/**************************************************************************
- *				DRIVER_TryOpenDriver32		[internal]
- *
- * Tries to load a 32 bit driver whose DLL's (module) name is lpFileName.
- *
- */
-static	HDRVR	DRIVER_TryOpenDriver32(LPCSTR lpFileName, LPARAM lParam, BOOL bCallFrom32)
-{
-    LPWINE_DRIVER 	lpDrv = NULL;
-    LPCSTR		lpSFN;
-    HMODULE		hModule;
-    DRIVERPROC		lpProc;
-    
-    dprintf(("'Entering DRIVER_TryOpenDriver32: %s', %08lX, %d);\n", lpFileName, lParam, bCallFrom32));
-    
-    if (strlen(lpFileName) < 1) 
-      return 0;
-    
-    lpSFN = strrchr(lpFileName, '\\');
-    lpSFN = (lpSFN) ? (lpSFN + 1) : lpFileName;
-    
-    if ((hModule = LoadLibraryA(lpFileName)) != 0) {
-      if ((lpProc = (DRIVERPROC)GetProcAddress(hModule, "DriverProc")) != NULL) {
-        lpDrv = DRIVER_RegisterDriver32(lpSFN, hModule, lpProc, lParam, bCallFrom32);
-      } else {
-	    FreeLibrary(hModule);
-	    lpDrv = 0;
-	    dprintf(("DRIVER_TryOpenDriver32: No DriverProc found (line %d)\n",__LINE__));
-      }
-    } else {
-      dprintf(("DRIVER_TryOpenDriver32: Unable to load 32 bit module \"%s\" (line %d)\n", lpFileName,__LINE__));
-    }
-
-    dprintf(("(DRIVER_TryOpenDriver32) driver handle => %p\n", lpDrv));
-
-    return (HDRVR)lpDrv;
-}
-
-/**************************************************************************
- *				DRIVER_OpenDriverA		        [internal]
- * (0,1,DRV_LOAD  ,0       ,0)
- * (0,1,DRV_ENABLE,0       ,0)
- * (0,1,DRV_OPEN  ,buf[256],0)
- *
- */
-static HDRVR  DRIVER_OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam) 
-{
-  HDRVR 		hDriver = 0;
-  char 		drvName[128];
-  
-  dprintf(("Entering DRIVER_OpenDriverA: lpDriverName: %s lpSectionName: %s\n",lpDriverName,lpSectionName));
-
-  if (lpSectionName == NULL) {
-	lstrcpynA(drvName, lpDriverName, sizeof(drvName));
-	hDriver = DRIVER_TryOpenDriver32(lpDriverName, lParam, TRUE);
-	if (!hDriver) {
-      if (GetPrivateProfileStringA("Drivers32", lpDriverName, "", drvName,
-                                   sizeof(drvName), "SYSTEM.INI")) {
-
-		hDriver = DRIVER_TryOpenDriver32(drvName, lParam, TRUE);		
-      }
-	}
-  } else {/* of if (lpSectionName == NULL) */
-    //dprintf(("driver name %x '%s'\n",drvName,drvName));
-    drvName[0]=0;    
-
-	if (GetPrivateProfileStringA(lpSectionName, lpDriverName, "", drvName,
-                                 sizeof(drvName)-1, "SYSTEM.INI")) {
-#if 0
-      dprintf(("driver name %x '%s'\n",drvName,drvName));
-#endif      
-      hDriver = DRIVER_TryOpenDriver32(drvName, lParam, TRUE);
-	}/* GetPrivate... */
-  }
-  if (!hDriver)
-	dprintf(("OpenDriverA: Failed to open driver %s from section %s\n", lpDriverName, lpSectionName));
-
-  else 
-	dprintf(("OpenDriverA success: Driver handle => %08x\n", hDriver));
-
-  return hDriver;
-}
-
-/**************************************************************************
- *				DRIVER_CloseDriver		[internal]
- *
- *
- */
-static BOOL DRIVER_CloseDriver(LPWINE_DRIVER lpDrv, DWORD lParam1, DWORD lParam2)
-{
-  if (lpDrv != NULL) {
-	SendDriverMessage((HDRVR)lpDrv, DRV_CLOSE, lParam1, lParam2);
-    
-	if (DRIVER_RemoveFromList(lpDrv)) {
-      HeapFree(GetProcessHeap(), 0, lpDrv);
-      return TRUE;
-	}
-  }
-  dprintf(("Failed to close driver\n"));
-  return FALSE;
-}
-
-
-
-
-
-
-
-
-
-
-
-
Index: trunk/src/winmm/winemm.h
===================================================================
--- trunk/src/winmm/winemm.h	(revision 5433)
+++ trunk/src/winmm/winemm.h	(revision 5433)
@@ -0,0 +1,207 @@
+/* -*- tab-width: 8; c-basic-offset: 4 -*- */
+
+/*****************************************************************************
+ * Copyright 1998, Luiz Otavio L. Zorzella
+ *           1999, Eric Pouech
+ *
+ * File:      winemm.h
+ * Purpose:   multimedia declarations (internal to WINMM & MMSYSTEM DLLs)
+ *
+ *****************************************************************************
+ */
+
+#include "mmddk.h"
+
+#ifdef __WIN32OS2__
+typedef DWORD (* WINAPIMessageProc16)(UINT16 wDevID, UINT16 wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
+typedef DWORD (* WINAPIMessageProc32)(UINT wDevID, UINT wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
+#else
+typedef DWORD WINAPI (*MessageProc16)(UINT16 wDevID, UINT16 wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
+typedef DWORD WINAPI (*MessageProc32)(UINT wDevID, UINT wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
+#endif
+
+/* Who said goofy boy ? */
+#define	WINE_DI_MAGIC	0x900F1B01
+
+typedef struct tagWINE_DRIVER
+{
+    DWORD			dwMagic;
+    /* as usual LPWINE_DRIVER == hDriver32 */
+    DWORD			dwFlags;
+    union {
+	struct {
+	    HMODULE			hModule;
+	    DRIVERPROC			lpDrvProc;
+	    DWORD		  	dwDriverID;
+	} d32;
+	struct {
+	    HDRVR16			hDriver16;
+	} d16;
+    } d;
+    struct tagWINE_DRIVER*	lpPrevItem;
+    struct tagWINE_DRIVER*	lpNextItem;
+} WINE_DRIVER, *LPWINE_DRIVER;
+
+typedef struct tagWINE_MLD {
+/* EPP struct tagWINE_MLD*	lpNext; */		/* not used so far */
+       UINT			uDeviceID;
+       UINT			type;
+       UINT			mmdIndex;		/* index to low-level driver in MMDrvs table */
+       DWORD			dwDriverInstance;	/* this value is driver related, as opposed to
+							 * opendesc.dwInstance which is client (callback) related */
+       WORD			bFrom32;
+       WORD			dwFlags;
+       DWORD			dwCallback;
+       DWORD			dwClientInstance;
+} WINE_MLD, *LPWINE_MLD;
+
+typedef struct  {
+       WINE_MLD			mld;
+} WINE_WAVE, *LPWINE_WAVE;
+
+typedef struct {
+       WINE_MLD			mld;
+       MIDIOPENDESC		mod;			/* FIXME: should be removed */
+} WINE_MIDI, *LPWINE_MIDI;
+
+typedef struct {
+       WINE_MLD			mld;
+} WINE_MIXER, *LPWINE_MIXER;
+
+extern	BOOL		MMDRV_Init(void);
+extern	UINT		MMDRV_GetNum(UINT);
+extern	LPWINE_MLD	MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags, 
+				    DWORD* dwCallback, DWORD* dwInstance, BOOL bFrom32);
+extern	void		MMDRV_Free(HANDLE hndl, LPWINE_MLD mld);
+extern	DWORD		MMDRV_Open(LPWINE_MLD mld, UINT wMsg, DWORD dwParam1, DWORD dwParam2);
+extern	DWORD		MMDRV_Close(LPWINE_MLD mld, UINT wMsg);
+extern	LPWINE_MLD	MMDRV_Get(HANDLE hndl, UINT type, BOOL bCanBeID);
+extern  LPWINE_MLD	MMDRV_GetRelated(HANDLE hndl, UINT srcType, BOOL bSrcCanBeID, UINT dstTyped);
+extern	DWORD		MMDRV_Message(LPWINE_MLD mld, WORD wMsg, DWORD dwParam1, DWORD dwParam2, BOOL bFrom32);
+extern	UINT		MMDRV_PhysicalFeatures(LPWINE_MLD mld, UINT uMsg, DWORD dwParam1, DWORD dwParam2);
+
+#define	MMDRV_AUX		0
+#define	MMDRV_MIXER		1
+#define	MMDRV_MIDIIN		2
+#define	MMDRV_MIDIOUT		3
+#define	MMDRV_WAVEIN		4
+#define	MMDRV_WAVEOUT		5
+#define MMDRV_MAX		6
+
+#define WINE_MMTHREAD_CREATED	0x4153494C	/* "BSIL" */
+#define WINE_MMTHREAD_DELETED	0xDEADDEAD
+
+typedef struct {
+       DWORD			dwSignature;		/* 00 "BSIL" when ok, 0xDEADDEAD when being deleted */
+       DWORD			dwCounter;		/* 04 > 1 when in mmThread functions */
+       HANDLE			hThread;		/* 08 hThread */
+       DWORD                    dwThreadID;     	/* 0C */
+       FARPROC16		fpThread;		/* 10 address of thread proc (segptr or lin depending on dwFlags) */
+       DWORD			dwThreadPmt;    	/* 14 parameter to be passed upon thread creation to fpThread */
+       DWORD                    dwSignalCount;	     	/* 18 counter used for signaling */
+       HANDLE                   hEvent;     		/* 1C event */
+       HANDLE                   hVxD;		     	/* 20 return from OpenVxDHandle */
+       DWORD                    dwStatus;       	/* 24 0x00, 0x10, 0x20, 0x30 */
+       DWORD			dwFlags;		/* 28 dwFlags upon creation */
+       HANDLE16			hTask;          	/* 2C handle to created task */
+} WINE_MMTHREAD;
+
+typedef struct tagWINE_MCIDRIVER {
+        UINT			wDeviceID;
+        UINT			wType;
+	LPSTR			lpstrElementName;
+        LPSTR			lpstrDeviceType;
+        LPSTR			lpstrAlias;
+        HDRVR			hDriver;
+	DRIVERPROC16		driverProc;
+	DWORD			dwPrivate;
+        YIELDPROC		lpfnYieldProc;
+        DWORD	                dwYieldData;
+        BOOL			bIs32;
+        HTASK16			hCreatorTask;
+        UINT			uTypeCmdTable;
+        UINT			uSpecificCmdTable;
+        struct tagWINE_MCIDRIVER*lpNext;
+} WINE_MCIDRIVER, *LPWINE_MCIDRIVER;
+
+#define WINE_TIMER_IS32	0x80
+
+typedef struct tagWINE_TIMERENTRY {
+    UINT			wDelay;
+    UINT			wResol;
+    FARPROC16 			lpFunc;
+    DWORD			dwUser;
+    UINT16			wFlags;
+    UINT16			wTimerID;
+    UINT			uCurTime;
+    struct tagWINE_TIMERENTRY*	lpNext;
+} WINE_TIMERENTRY, *LPWINE_TIMERENTRY;
+
+typedef struct tagWINE_MMIO {
+    MMIOINFO			info;
+    struct IOProcList*		ioProc;
+    BOOL			bTmpIOProc;
+    HANDLE			hMem;
+    SEGPTR			buffer16;
+    struct tagWINE_MMIO*	lpNext;
+    BOOL			bBufferLoaded;
+} WINE_MMIO, *LPWINE_MMIO;
+
+typedef struct tagWINE_MM_IDATA {
+    /* iData reference */
+    DWORD			dwThisProcess;
+    struct tagWINE_MM_IDATA*	lpNextIData;
+    /* winmm part */
+    HANDLE			hWinMM32Instance;
+    HANDLE			hWinMM16Instance;
+    HANDLE			h16Module32;
+    CRITICAL_SECTION		cs;
+    /* mm timer part */
+    HANDLE			hMMTimer;
+    DWORD			mmSysTimeMS;
+    LPWINE_TIMERENTRY 		lpTimerList;
+    int				nSizeLpTimers;
+    LPWINE_TIMERENTRY		lpTimers;
+    /* mci part */
+    LPWINE_MCIDRIVER 		lpMciDrvs;
+    /* low level drivers (unused yet) */
+    /* LPWINE_WAVE		lpWave; */
+    /* LPWINE_MIDI		lpMidi; */
+    /* LPWINE_MIXER		lpMixer; */
+    /* mmio part */
+    LPWINE_MMIO			lpMMIO;
+} WINE_MM_IDATA, *LPWINE_MM_IDATA;
+
+/* function prototypes */
+
+typedef LONG			(*MCIPROC16)(DWORD, HDRVR16, WORD, DWORD, DWORD);
+typedef LONG			(*MCIPROC)(DWORD, HDRVR, DWORD, DWORD, DWORD);
+
+extern LPWINE_DRIVER		DRIVER_FindFromHDrvr(HDRVR hDrvr);
+extern BOOL			DRIVER_GetLibName(LPCSTR keyName, LPCSTR sectName, LPSTR buf, int sz);
+extern LPWINE_DRIVER		DRIVER_TryOpenDriver32(LPCSTR fn, LPARAM lParam2);
+
+extern LPWINE_MCIDRIVER		MCI_GetDriver(UINT16 uDevID);
+extern UINT			MCI_GetDriverFromString(LPCSTR str);
+extern DWORD			MCI_WriteString(LPSTR lpDstStr, DWORD dstSize, LPCSTR lpSrcStr);
+extern const char* 		MCI_MessageToString(UINT16 wMsg);
+
+extern UINT		WINAPI	MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data);
+
+extern LRESULT			MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2, BOOL bIs32);
+
+extern DWORD			MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2, BOOL bFrom32);
+extern DWORD 			MCI_SendCommandFrom32(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2);
+extern DWORD 			MCI_SendCommandFrom16(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2);
+extern DWORD 			MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2, UINT size);
+
+void		CALLBACK	WINE_mmThreadEntryPoint(DWORD _pmt);
+
+void 				MMSYSTEM_MMTIME16to32(LPMMTIME mmt32, const MMTIME16* mmt16);
+void 				MMSYSTEM_MMTIME32to16(LPMMTIME16 mmt16, const MMTIME* mmt32); 
+
+BOOL				MULTIMEDIA_MciInit(void);
+LPWINE_MM_IDATA			MULTIMEDIA_GetIData(void);
+
+LPWINE_MM_IDATA			TIME_MMTimeStart(void);
+void				TIME_MMTimeStop(void);
