ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

driver.c
Go to the documentation of this file.
00001 /*
00002  * WINE Drivers functions
00003  *
00004  * Copyright 1994 Martin Ayotte
00005  * Copyright 1998 Marcus Meissner
00006  * Copyright 1999 Eric Pouech
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00021  */
00022 
00023 #include "config.h"
00024 #include "wine/port.h"
00025 
00026 #include <string.h>
00027 #include <stdarg.h>
00028 #include "windef.h"
00029 #include "winbase.h"
00030 #include "wingdi.h"
00031 #include "winuser.h"
00032 #include "winnls.h"
00033 #include "winreg.h"
00034 #include "mmddk.h"
00035 #include "winemm.h"
00036 #include "wine/debug.h"
00037 #include "wine/unicode.h"
00038 #include "excpt.h"
00039 #include "wine/exception.h"
00040 
00041 WINE_DEFAULT_DEBUG_CHANNEL(driver);
00042 
00043 static CRITICAL_SECTION mmdriver_lock;
00044 static CRITICAL_SECTION_DEBUG mmdriver_lock_debug =
00045 {
00046     0, 0, &mmdriver_lock,
00047     { &mmdriver_lock_debug.ProcessLocksList, &mmdriver_lock_debug.ProcessLocksList },
00048       0, 0, { (DWORD_PTR)(__FILE__ ": mmdriver_lock") }
00049 };
00050 static CRITICAL_SECTION mmdriver_lock = { &mmdriver_lock_debug, -1, 0, 0, 0, 0 };
00051 
00052 static LPWINE_DRIVER   lpDrvItemList  /* = NULL */;
00053 static const WCHAR HKLM_BASE[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
00054                                   'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
00055 
00056 static void DRIVER_Dump(const char *comment)
00057 {
00058 #if 0
00059     LPWINE_DRIVER   lpDrv;
00060 
00061     TRACE("%s\n", comment);
00062 
00063     EnterCriticalSection( &mmdriver_lock );
00064 
00065     for (lpDrv = lpDrvItemList; lpDrv != NULL; lpDrv = lpDrv->lpNextItem)
00066     {
00067         TRACE("%p, magic %04lx, id %p, next %p\n", lpDrv, lpDrv->dwMagic, lpDrv->d.d32.dwDriverID, lpDrv->lpNextItem);
00068     }
00069 
00070     LeaveCriticalSection( &mmdriver_lock );
00071 #endif
00072 }
00073 
00074 /**************************************************************************
00075  *          DRIVER_GetNumberOfModuleRefs        [internal]
00076  *
00077  * Returns the number of open drivers which share the same module.
00078  */
00079 static  unsigned DRIVER_GetNumberOfModuleRefs(HMODULE hModule, WINE_DRIVER** found)
00080 {
00081     LPWINE_DRIVER   lpDrv;
00082     unsigned        count = 0;
00083 
00084     EnterCriticalSection( &mmdriver_lock );
00085 
00086     if (found) *found = NULL;
00087     for (lpDrv = lpDrvItemList; lpDrv; lpDrv = lpDrv->lpNextItem)
00088     {
00089     if (lpDrv->hModule == hModule)
00090         {
00091             if (found && !*found) *found = lpDrv;
00092         count++;
00093     }
00094     }
00095 
00096     LeaveCriticalSection( &mmdriver_lock );
00097     return count;
00098 }
00099 
00100 /**************************************************************************
00101  *              DRIVER_FindFromHDrvr        [internal]
00102  *
00103  * From a hDrvr being 32 bits, returns the WINE internal structure.
00104  */
00105 LPWINE_DRIVER   DRIVER_FindFromHDrvr(HDRVR hDrvr)
00106 {
00107     LPWINE_DRIVER d;
00108 
00109     __TRY
00110     {
00111         d = (LPWINE_DRIVER)hDrvr;
00112         if (d && d->dwMagic != WINE_DI_MAGIC) d = NULL;
00113     }
00114     __EXCEPT_PAGE_FAULT
00115     {
00116         return NULL;
00117     }
00118     __ENDTRY;
00119 
00120     if (d) TRACE("%p -> %p, %p\n", hDrvr, d->lpDrvProc, (void *)d->dwDriverID);
00121     else TRACE("%p -> NULL\n", hDrvr);
00122 
00123     return d;
00124 }
00125 
00126 /**************************************************************************
00127  *              DRIVER_SendMessage      [internal]
00128  */
00129 static inline LRESULT DRIVER_SendMessage(LPWINE_DRIVER lpDrv, UINT msg,
00130                                          LPARAM lParam1, LPARAM lParam2)
00131 {
00132     LRESULT     ret = 0;
00133 
00134     TRACE("Before call32 proc=%p drvrID=%08lx hDrv=%p wMsg=%04x p1=%08lx p2=%08lx\n",
00135           lpDrv->lpDrvProc, lpDrv->dwDriverID, lpDrv, msg, lParam1, lParam2);
00136     ret = lpDrv->lpDrvProc(lpDrv->dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2);
00137     TRACE("After  call32 proc=%p drvrID=%08lx hDrv=%p wMsg=%04x p1=%08lx p2=%08lx => %08lx\n",
00138           lpDrv->lpDrvProc, lpDrv->dwDriverID, lpDrv, msg, lParam1, lParam2, ret);
00139 
00140     return ret;
00141 }
00142 
00143 /**************************************************************************
00144  *              SendDriverMessage       [WINMM.@]
00145  *              DrvSendMessage          [WINMM.@]
00146  */
00147 LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT msg, LPARAM lParam1,
00148                  LPARAM lParam2)
00149 {
00150     LPWINE_DRIVER   lpDrv;
00151     LRESULT         retval = 0;
00152 
00153     TRACE("(%p, %04X, %08lX, %08lX)\n", hDriver, msg, lParam1, lParam2);
00154 
00155     if ((lpDrv = DRIVER_FindFromHDrvr(hDriver)) != NULL) {
00156     retval = DRIVER_SendMessage(lpDrv, msg, lParam1, lParam2);
00157     } else {
00158     WARN("Bad driver handle %p\n", hDriver);
00159     }
00160     TRACE("retval = %ld\n", retval);
00161 
00162     return retval;
00163 }
00164 
00165 /**************************************************************************
00166  *              DRIVER_RemoveFromList       [internal]
00167  *
00168  * Generates all the logic to handle driver closure / deletion
00169  * Removes a driver struct to the list of open drivers.
00170  */
00171 static  BOOL    DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv)
00172 {
00173     /* last of this driver in list ? */
00174     if (DRIVER_GetNumberOfModuleRefs(lpDrv->hModule, NULL) == 1) {
00175         DRIVER_SendMessage(lpDrv, DRV_DISABLE, 0L, 0L);
00176         DRIVER_SendMessage(lpDrv, DRV_FREE,    0L, 0L);
00177     }
00178 
00179     EnterCriticalSection( &mmdriver_lock );
00180 
00181     if (lpDrv->lpPrevItem)
00182     lpDrv->lpPrevItem->lpNextItem = lpDrv->lpNextItem;
00183     else
00184     lpDrvItemList = lpDrv->lpNextItem;
00185     if (lpDrv->lpNextItem)
00186     lpDrv->lpNextItem->lpPrevItem = lpDrv->lpPrevItem;
00187     /* trash magic number */
00188     lpDrv->dwMagic ^= 0xa5a5a5a5;
00189     lpDrv->lpDrvProc = NULL;
00190     lpDrv->dwDriverID = 0;
00191 
00192     LeaveCriticalSection( &mmdriver_lock );
00193 
00194     return TRUE;
00195 }
00196 
00197 /**************************************************************************
00198  *              DRIVER_AddToList        [internal]
00199  *
00200  * Adds a driver struct to the list of open drivers.
00201  * Generates all the logic to handle driver creation / open.
00202  */
00203 static  BOOL    DRIVER_AddToList(LPWINE_DRIVER lpNewDrv, LPARAM lParam1, LPARAM lParam2)
00204 {
00205     lpNewDrv->dwMagic = WINE_DI_MAGIC;
00206     /* First driver to be loaded for this module, need to load correctly the module */
00207     /* first of this driver in list ? */
00208     if (DRIVER_GetNumberOfModuleRefs(lpNewDrv->hModule, NULL) == 0) {
00209         if (DRIVER_SendMessage(lpNewDrv, DRV_LOAD, 0L, 0L) != DRV_SUCCESS) {
00210             TRACE("DRV_LOAD failed on driver %p\n", lpNewDrv);
00211             return FALSE;
00212         }
00213         /* returned value is not checked */
00214         DRIVER_SendMessage(lpNewDrv, DRV_ENABLE, 0L, 0L);
00215     }
00216 
00217     /* Now just open a new instance of a driver on this module */
00218     lpNewDrv->dwDriverID = DRIVER_SendMessage(lpNewDrv, DRV_OPEN, lParam1, lParam2);
00219 
00220     if (lpNewDrv->dwDriverID == 0)
00221     {
00222         TRACE("DRV_OPEN failed on driver %p\n", lpNewDrv);
00223         return FALSE;
00224     }
00225 
00226     EnterCriticalSection( &mmdriver_lock );
00227 
00228     lpNewDrv->lpNextItem = NULL;
00229     if (lpDrvItemList == NULL) {
00230     lpDrvItemList = lpNewDrv;
00231     lpNewDrv->lpPrevItem = NULL;
00232     } else {
00233     LPWINE_DRIVER   lpDrv = lpDrvItemList;  /* find end of list */
00234     while (lpDrv->lpNextItem != NULL)
00235         lpDrv = lpDrv->lpNextItem;
00236 
00237     lpDrv->lpNextItem = lpNewDrv;
00238     lpNewDrv->lpPrevItem = lpDrv;
00239     }
00240 
00241     LeaveCriticalSection( &mmdriver_lock );
00242     return TRUE;
00243 }
00244 
00245 /**************************************************************************
00246  *              DRIVER_GetLibName       [internal]
00247  *
00248  */
00249 BOOL    DRIVER_GetLibName(LPCWSTR keyName, LPCWSTR sectName, LPWSTR buf, int sz)
00250 {
00251     HKEY    hKey, hSecKey;
00252     DWORD   bufLen, lRet;
00253     static const WCHAR wszSystemIni[] = {'S','Y','S','T','E','M','.','I','N','I',0};
00254     WCHAR       wsznull = '\0';
00255 
00256     /* This takes us as far as Windows NT\CurrentVersion */
00257     lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, HKLM_BASE, 0, KEY_QUERY_VALUE, &hKey);
00258 
00259     if (lRet == ERROR_SUCCESS)
00260     {
00261         /* Now we descend into the section name that we were given */
00262         lRet = RegOpenKeyExW(hKey, sectName, 0, KEY_QUERY_VALUE, &hSecKey);
00263 
00264         if (lRet == ERROR_SUCCESS)
00265         {
00266             /* Retrieve the desired value - this is the filename of the lib */
00267             bufLen = sz;
00268             lRet = RegQueryValueExW(hSecKey, keyName, 0, 0, (void*)buf, &bufLen);
00269             RegCloseKey( hSecKey );
00270         }
00271 
00272         RegCloseKey( hKey );
00273     }
00274 
00275     /* Finish up if we've got what we want from the registry */
00276     if (lRet == ERROR_SUCCESS)
00277         return TRUE;
00278 
00279     /* default to system.ini if we can't find it in the registry,
00280      * to support native installations where system.ini is still used */
00281     return GetPrivateProfileStringW(sectName, keyName, &wsznull, buf, sz / sizeof(WCHAR), wszSystemIni);
00282 }
00283 
00284 /**************************************************************************
00285  *              DRIVER_TryOpenDriver32      [internal]
00286  *
00287  * Tries to load a 32 bit driver whose DLL's (module) name is fn
00288  */
00289 LPWINE_DRIVER   DRIVER_TryOpenDriver32(LPCWSTR fn, LPARAM lParam2)
00290 {
00291     LPWINE_DRIVER   lpDrv = NULL;
00292     HMODULE     hModule = 0;
00293     LPWSTR      ptr;
00294     LPCSTR      cause = 0;
00295 
00296     TRACE("(%s, %08lX);\n", debugstr_w(fn), lParam2);
00297 
00298     if ((ptr = strchrW(fn, ' ')) != NULL)
00299     {
00300         *ptr++ = '\0';
00301 
00302         while (*ptr == ' ')
00303             ptr++;
00304 
00305         if (*ptr == '\0')
00306             ptr = NULL;
00307     }
00308 
00309     lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
00310 
00311     if (lpDrv == NULL)
00312     {
00313         cause = "OOM";
00314         goto exit;
00315     }
00316 
00317     if ((hModule = LoadLibraryW(fn)) == 0)
00318     {
00319         cause = "Not a 32 bit lib";
00320         goto exit;
00321     }
00322 
00323     lpDrv->lpDrvProc = (DRIVERPROC)GetProcAddress(hModule, "DriverProc");
00324 
00325     if (lpDrv->lpDrvProc == NULL)
00326     {
00327         cause = "no DriverProc";
00328         goto exit;
00329     }
00330 
00331     lpDrv->dwFlags          = 0;
00332     lpDrv->hModule    = hModule;
00333     lpDrv->dwDriverID = 0;
00334 
00335     /* Win32 installable drivers must support a two phase opening scheme:
00336      * + first open with NULL as lParam2 (session instance),
00337      * + then do a second open with the real non null lParam2)
00338      */
00339     if (DRIVER_GetNumberOfModuleRefs(lpDrv->hModule, NULL) == 0 && lParam2)
00340     {
00341         LPWINE_DRIVER   ret;
00342 
00343         if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, 0L))
00344         {
00345             cause = "load0 failed";
00346             goto exit;
00347         }
00348         ret = DRIVER_TryOpenDriver32(fn, lParam2);
00349         if (!ret)
00350         {
00351             CloseDriver((HDRVR)lpDrv, 0L, 0L);
00352             cause = "load1 failed";
00353             goto exit;
00354         }
00355         return ret;
00356     }
00357 
00358     if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, lParam2))
00359     {
00360         cause = "load failed";
00361         goto exit;
00362     }
00363 
00364     TRACE("=> %p\n", lpDrv);
00365     return lpDrv;
00366 
00367  exit:
00368     FreeLibrary(hModule);
00369     HeapFree(GetProcessHeap(), 0, lpDrv);
00370     TRACE("Unable to load 32 bit module %s: %s\n", debugstr_w(fn), cause);
00371     return NULL;
00372 }
00373 
00374 /**************************************************************************
00375  *              OpenDriverA             [WINMM.@]
00376  *              DrvOpenA            [WINMM.@]
00377  * (0,1,DRV_LOAD  ,0       ,0)
00378  * (0,1,DRV_ENABLE,0       ,0)
00379  * (0,1,DRV_OPEN  ,buf[256],0)
00380  */
00381 HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam)
00382 {
00383     INT                 len;
00384     LPWSTR      dn = NULL;
00385     LPWSTR      sn = NULL;
00386     HDRVR       ret = 0;
00387 
00388     if (lpDriverName)
00389     {
00390         len = MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, NULL, 0 );
00391         dn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
00392         if (!dn) goto done;
00393         MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, dn, len );
00394     }
00395 
00396     if (lpSectionName)
00397     {
00398         len = MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, NULL, 0 );
00399         sn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
00400         if (!sn) goto done;
00401         MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, sn, len );
00402     }
00403 
00404     ret = OpenDriver(dn, sn, lParam);
00405 
00406 done:
00407     HeapFree(GetProcessHeap(), 0, dn);
00408     HeapFree(GetProcessHeap(), 0, sn);
00409     return ret;
00410 }
00411 
00412 /**************************************************************************
00413  *              OpenDriver              [WINMM.@]
00414  *              DrvOpen             [WINMM.@]
00415  */
00416 HDRVR WINAPI OpenDriver(LPCWSTR lpDriverName, LPCWSTR lpSectionName, LPARAM lParam)
00417 {
00418     LPWINE_DRIVER   lpDrv = NULL;
00419     WCHAR       libName[128];
00420     LPCWSTR     lsn = lpSectionName;
00421 
00422     TRACE("(%s, %s, 0x%08lx);\n", 
00423           debugstr_w(lpDriverName), debugstr_w(lpSectionName), lParam);
00424 
00425     /* If no section name is specified, either the caller is intending on
00426        opening a driver by filename, or wants to open a user-installable
00427        driver that has an entry in the Drivers32 key in the registry */
00428     if (lsn == NULL)
00429     {
00430         /* Default registry key */
00431         static const WCHAR wszDrivers32[] = {'D','r','i','v','e','r','s','3','2',0};
00432 
00433         lstrcpynW(libName, lpDriverName, sizeof(libName) / sizeof(WCHAR));
00434 
00435         /* Try and open the driver by filename */
00436         if ( (lpDrv = DRIVER_TryOpenDriver32(libName, lParam)) )
00437             goto the_end;
00438 
00439         /* If we got here, the file wasn't found. So we assume the caller
00440            wanted a driver specified under the Drivers32 registry key */
00441         lsn = wszDrivers32;
00442     }
00443 
00444     /* Attempt to locate the driver filename in the registry */
00445     if ( DRIVER_GetLibName(lpDriverName, lsn, libName, sizeof(libName)) )
00446     {
00447         /* Now we have the filename, we can try and load it */
00448         if ( (lpDrv = DRIVER_TryOpenDriver32(libName, lParam)) )
00449             goto the_end;
00450     }
00451 
00452     /* now we will try a 16 bit driver (and add all the glue to make it work... which
00453      * is located in our mmsystem implementation)
00454      * so ensure, we can load our mmsystem, otherwise just fail
00455      */
00456     WINMM_CheckForMMSystem();
00457 #if 0
00458     if (pFnOpenDriver16 &&
00459         (lpDrv = pFnOpenDriver16(lpDriverName, lpSectionName, lParam)))
00460     {
00461         if (DRIVER_AddToList(lpDrv, 0, lParam)) goto the_end;
00462         HeapFree(GetProcessHeap(), 0, lpDrv);
00463     }
00464     TRACE("Failed to open driver %s from system.ini file, section %s\n", 
00465           debugstr_w(lpDriverName), debugstr_w(lpSectionName));
00466 #endif
00467     return 0;
00468 
00469  the_end:
00470     if (lpDrv)  TRACE("=> %p\n", lpDrv);
00471     return (HDRVR)lpDrv;
00472 }
00473 
00474 /**************************************************************************
00475  *          CloseDriver             [WINMM.@]
00476  *          DrvClose                [WINMM.@]
00477  */
00478 LRESULT WINAPI CloseDriver(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
00479 {
00480     BOOL ret;
00481     LPWINE_DRIVER   lpDrv;
00482 
00483     TRACE("(%p, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
00484 
00485     DRIVER_Dump("BEFORE:");
00486 
00487     if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL)
00488     {
00489         LPWINE_DRIVER lpDrv0;
00490 
00491         DRIVER_SendMessage(lpDrv, DRV_CLOSE, lParam1, lParam2);
00492 
00493         DRIVER_RemoveFromList(lpDrv);
00494 
00495         if (lpDrv->dwFlags & WINE_GDF_SESSION)
00496             FIXME("WINE_GDF_SESSION: Shouldn't happen (%p)\n", lpDrv);
00497         /* if driver has an opened session instance, we have to close it too */
00498         if (DRIVER_GetNumberOfModuleRefs(lpDrv->hModule, &lpDrv0) == 1 &&
00499             (lpDrv0->dwFlags & WINE_GDF_SESSION))
00500         {
00501             DRIVER_SendMessage(lpDrv0, DRV_CLOSE, 0, 0);
00502             DRIVER_RemoveFromList(lpDrv0);
00503             FreeLibrary(lpDrv0->hModule);
00504             HeapFree(GetProcessHeap(), 0, lpDrv0);
00505         }
00506         FreeLibrary(lpDrv->hModule);
00507 
00508         HeapFree(GetProcessHeap(), 0, lpDrv);
00509         ret = TRUE;
00510     }
00511     else
00512     {
00513         WARN("Failed to close driver\n");
00514         ret = FALSE;
00515     }
00516 
00517     DRIVER_Dump("AFTER:");
00518 
00519     return ret;
00520 }
00521 
00522 /**************************************************************************
00523  *              GetDriverFlags      [WINMM.@]
00524  * [in] hDrvr handle to the driver
00525  *
00526  * Returns:
00527  *  0x00000000 if hDrvr is an invalid handle
00528  *  0x80000000 if hDrvr is a valid 32 bit driver
00529  *  0x90000000 if hDrvr is a valid 16 bit driver
00530  *
00531  * native WINMM doesn't return those flags
00532  *  0x80000000 for a valid 32 bit driver and that's it
00533  *  (I may have mixed up the two flags :-(
00534  */
00535 DWORD   WINAPI GetDriverFlags(HDRVR hDrvr)
00536 {
00537     LPWINE_DRIVER   lpDrv;
00538     DWORD       ret = 0;
00539 
00540     TRACE("(%p)\n", hDrvr);
00541 
00542     if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
00543     ret = WINE_GDF_EXIST | (lpDrv->dwFlags & WINE_GDF_EXTERNAL_MASK);
00544     }
00545     return ret;
00546 }
00547 
00548 /**************************************************************************
00549  *              GetDriverModuleHandle   [WINMM.@]
00550  *              DrvGetModuleHandle  [WINMM.@]
00551  */
00552 HMODULE WINAPI GetDriverModuleHandle(HDRVR hDrvr)
00553 {
00554     LPWINE_DRIVER   lpDrv;
00555     HMODULE     hModule = 0;
00556 
00557     TRACE("(%p);\n", hDrvr);
00558 
00559     if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
00560         hModule = lpDrv->hModule;
00561     }
00562     TRACE("=> %p\n", hModule);
00563     return hModule;
00564 }
00565 
00566 /**************************************************************************
00567  *              DefDriverProc             [WINMM.@]
00568  *              DrvDefDriverProc          [WINMM.@]
00569  */
00570 LRESULT WINAPI DefDriverProc(DWORD_PTR dwDriverIdentifier, HDRVR hDrv,
00571                  UINT Msg, LPARAM lParam1, LPARAM lParam2)
00572 {
00573     switch (Msg) {
00574     case DRV_LOAD:
00575     case DRV_FREE:
00576     case DRV_ENABLE:
00577     case DRV_DISABLE:
00578         return 1;
00579     case DRV_INSTALL:
00580     case DRV_REMOVE:
00581         return DRV_SUCCESS;
00582     default:
00583         return 0;
00584     }
00585 }
00586 
00587 /**************************************************************************
00588  *              DriverCallback          [WINMM.@]
00589  */
00590 BOOL WINAPI DriverCallback(DWORD_PTR dwCallBack, DWORD uFlags, HDRVR hDev,
00591                DWORD wMsg, DWORD_PTR dwUser, DWORD_PTR dwParam1,
00592                DWORD_PTR dwParam2)
00593 {
00594     TRACE("(%08lX, %04X, %p, %04X, %08lX, %08lX, %08lX)\n",
00595       dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2);
00596 
00597     switch (uFlags & DCB_TYPEMASK) {
00598     case DCB_NULL:
00599     TRACE("Null !\n");
00600     if (dwCallBack)
00601         WARN("uFlags=%04X has null DCB value, but dwCallBack=%08lX is not null !\n", uFlags, dwCallBack);
00602     break;
00603     case DCB_WINDOW:
00604     TRACE("Window(%04lX) handle=%p!\n", dwCallBack, hDev);
00605     PostMessageA((HWND)dwCallBack, wMsg, (WPARAM)hDev, dwParam1);
00606     break;
00607     case DCB_TASK: /* aka DCB_THREAD */
00608     TRACE("Task(%04lx) !\n", dwCallBack);
00609     PostThreadMessageA(dwCallBack, wMsg, (WPARAM)hDev, dwParam1);
00610     break;
00611     case DCB_FUNCTION:
00612     TRACE("Function (32 bit) !\n");
00613     ((LPDRVCALLBACK)dwCallBack)(hDev, wMsg, dwUser, dwParam1, dwParam2);
00614     break;
00615     case DCB_EVENT:
00616     TRACE("Event(%08lx) !\n", dwCallBack);
00617     SetEvent((HANDLE)dwCallBack);
00618     break;
00619 #if 0
00620         /* FIXME: for now only usable in mmsystem.dll16
00621          * If needed, should be enabled back
00622          */
00623     case 6: /* I would dub it DCB_MMTHREADSIGNAL */
00624     /* this is an undocumented DCB_ value used for mmThreads
00625      * loword of dwCallBack contains the handle of the lpMMThd block
00626      * which dwSignalCount has to be incremented
00627      */     
00628         if (pFnGetMMThread16)
00629     {
00630         WINE_MMTHREAD*  lpMMThd = pFnGetMMThread16(LOWORD(dwCallBack));
00631 
00632         TRACE("mmThread (%04x, %p) !\n", LOWORD(dwCallBack), lpMMThd);
00633         /* same as mmThreadSignal16 */
00634         InterlockedIncrement(&lpMMThd->dwSignalCount);
00635         SetEvent(lpMMThd->hEvent);
00636         /* some other stuff on lpMMThd->hVxD */
00637     }
00638     break;
00639 #endif
00640 #if 0
00641     case 4:
00642     /* this is an undocumented DCB_ value for... I don't know */
00643     break;
00644 #endif
00645     default:
00646     WARN("Unknown callback type %d\n", uFlags & DCB_TYPEMASK);
00647     return FALSE;
00648     }
00649     TRACE("Done\n");
00650     return TRUE;
00651 }
00652 
00653 /******************************************************************
00654  *      DRIVER_UnloadAll
00655  *
00656  *
00657  */
00658 void    DRIVER_UnloadAll(void)
00659 {
00660     LPWINE_DRIVER   lpDrv;
00661     LPWINE_DRIVER   lpNextDrv = NULL;
00662     unsigned            count = 0;
00663 
00664 restart:
00665     EnterCriticalSection( &mmdriver_lock );
00666 
00667     for (lpDrv = lpDrvItemList; lpDrv != NULL; lpDrv = lpNextDrv)
00668     {
00669         lpNextDrv = lpDrv->lpNextItem;
00670 
00671         /* session instances will be unloaded automatically */
00672         if (!(lpDrv->dwFlags & WINE_GDF_SESSION))
00673         {
00674             LeaveCriticalSection( &mmdriver_lock );
00675             CloseDriver((HDRVR)lpDrv, 0, 0);
00676             count++;
00677             /* restart from the beginning of the list */
00678             goto restart;
00679         }
00680     }
00681 
00682     LeaveCriticalSection( &mmdriver_lock );
00683 
00684     TRACE("Unloaded %u drivers\n", count);
00685 }

Generated on Sun May 27 2012 04:18:51 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.