Reverse the order for deleting the items in resetcontent to correctly
[wine] / dlls / winmm / driver.c
1 /*
2  * WINE Drivers functions
3  *
4  * Copyright 1994 Martin Ayotte
5  * Copyright 1998 Marcus Meissner
6  * Copyright 1999 Eric Pouech
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include <string.h>
24 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "winreg.h"
31 #include "mmddk.h"
32 #include "winemm.h"
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(driver);
37
38 static LPWINE_DRIVER   lpDrvItemList  /* = NULL */;
39 static const WCHAR HKLM_BASE[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
40                                   'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
41
42 WINE_MMTHREAD*  (*pFnGetMMThread16)(UINT16 h) /* = NULL */;
43 LPWINE_DRIVER   (*pFnOpenDriver16)(LPCWSTR,LPCWSTR,LPARAM) /* = NULL */;
44 LRESULT         (*pFnCloseDriver16)(UINT16,LPARAM,LPARAM) /* = NULL */;
45 LRESULT         (*pFnSendMessage16)(UINT16,UINT,LPARAM,LPARAM) /* = NULL */;
46
47 /**************************************************************************
48  *                      DRIVER_GetNumberOfModuleRefs            [internal]
49  *
50  * Returns the number of open drivers which share the same module.
51  */
52 static  unsigned DRIVER_GetNumberOfModuleRefs(HMODULE hModule, WINE_DRIVER** found)
53 {
54     LPWINE_DRIVER       lpDrv;
55     unsigned            count = 0;
56
57     if (found) *found = NULL;
58     for (lpDrv = lpDrvItemList; lpDrv; lpDrv = lpDrv->lpNextItem)
59     {
60         if (!(lpDrv->dwFlags & WINE_GDF_16BIT) && lpDrv->d.d32.hModule == hModule)
61         {
62             if (found && !*found) *found = lpDrv;
63             count++;
64         }
65     }
66     return count;
67 }
68
69 /**************************************************************************
70  *                              DRIVER_FindFromHDrvr            [internal]
71  *
72  * From a hDrvr being 32 bits, returns the WINE internal structure.
73  */
74 LPWINE_DRIVER   DRIVER_FindFromHDrvr(HDRVR hDrvr)
75 {
76     LPWINE_DRIVER       d = (LPWINE_DRIVER)hDrvr;
77
78     if (hDrvr && HeapValidate(GetProcessHeap(), 0, d) && d->dwMagic == WINE_DI_MAGIC) {
79         return d;
80     }
81     return NULL;
82 }
83
84 /**************************************************************************
85  *                              DRIVER_SendMessage              [internal]
86  */
87 static LRESULT inline DRIVER_SendMessage(LPWINE_DRIVER lpDrv, UINT msg,
88                                          LPARAM lParam1, LPARAM lParam2)
89 {
90     LRESULT             ret = 0;
91
92     if (lpDrv->dwFlags & WINE_GDF_16BIT) {
93         /* no need to check mmsystem presence: the driver must have been opened as a 16 bit one,
94          */
95         if (pFnSendMessage16)
96             ret = pFnSendMessage16(lpDrv->d.d16.hDriver16, msg, lParam1, lParam2);
97     } else {
98         TRACE("Before call32 proc=%p drvrID=%08lx hDrv=%p wMsg=%04x p1=%08lx p2=%08lx\n", 
99               lpDrv->d.d32.lpDrvProc, lpDrv->d.d32.dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2);
100         ret = lpDrv->d.d32.lpDrvProc(lpDrv->d.d32.dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2);
101         TRACE("After  call32 proc=%p drvrID=%08lx hDrv=%p wMsg=%04x p1=%08lx p2=%08lx => %08lx\n", 
102               lpDrv->d.d32.lpDrvProc, lpDrv->d.d32.dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2, ret);
103     }
104     return ret;
105 }
106
107 /**************************************************************************
108  *                              SendDriverMessage               [WINMM.@]
109  *                              DrvSendMessage                  [WINMM.@]
110  */
111 LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT msg, LPARAM lParam1,
112                                  LPARAM lParam2)
113 {
114     LPWINE_DRIVER       lpDrv;
115     LRESULT             retval = 0;
116
117     TRACE("(%p, %04X, %08lX, %08lX)\n", hDriver, msg, lParam1, lParam2);
118
119     if ((lpDrv = DRIVER_FindFromHDrvr(hDriver)) != NULL) {
120         retval = DRIVER_SendMessage(lpDrv, msg, lParam1, lParam2);
121     } else {
122         WARN("Bad driver handle %p\n", hDriver);
123     }
124     TRACE("retval = %ld\n", retval);
125
126     return retval;
127 }
128
129 /**************************************************************************
130  *                              DRIVER_RemoveFromList           [internal]
131  *
132  * Generates all the logic to handle driver closure / deletion
133  * Removes a driver struct to the list of open drivers.
134  */
135 static  BOOL    DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv)
136 {
137     if (!(lpDrv->dwFlags & WINE_GDF_16BIT)) {
138         /* last of this driver in list ? */
139         if (DRIVER_GetNumberOfModuleRefs(lpDrv->d.d32.hModule, NULL) == 1) {
140             DRIVER_SendMessage(lpDrv, DRV_DISABLE, 0L, 0L);
141             DRIVER_SendMessage(lpDrv, DRV_FREE,    0L, 0L);
142         }
143     }
144
145     if (lpDrv->lpPrevItem)
146         lpDrv->lpPrevItem->lpNextItem = lpDrv->lpNextItem;
147     else
148         lpDrvItemList = lpDrv->lpNextItem;
149     if (lpDrv->lpNextItem)
150         lpDrv->lpNextItem->lpPrevItem = lpDrv->lpPrevItem;
151     /* trash magic number */
152     lpDrv->dwMagic ^= 0xa5a5a5a5;
153
154     return TRUE;
155 }
156
157 /**************************************************************************
158  *                              DRIVER_AddToList                [internal]
159  *
160  * Adds a driver struct to the list of open drivers.
161  * Generates all the logic to handle driver creation / open.
162  */
163 static  BOOL    DRIVER_AddToList(LPWINE_DRIVER lpNewDrv, LPARAM lParam1, LPARAM lParam2)
164 {
165     lpNewDrv->dwMagic = WINE_DI_MAGIC;
166     /* First driver to be loaded for this module, need to load correctly the module */
167     if (!(lpNewDrv->dwFlags & WINE_GDF_16BIT)) {
168         /* first of this driver in list ? */
169         if (DRIVER_GetNumberOfModuleRefs(lpNewDrv->d.d32.hModule, NULL) == 0) {
170             if (DRIVER_SendMessage(lpNewDrv, DRV_LOAD, 0L, 0L) != DRV_SUCCESS) {
171                 TRACE("DRV_LOAD failed on driver 0x%08lx\n", (DWORD)lpNewDrv);
172                 return FALSE;
173             }
174             /* returned value is not checked */
175             DRIVER_SendMessage(lpNewDrv, DRV_ENABLE, 0L, 0L);
176         }
177     }
178
179     lpNewDrv->lpNextItem = NULL;
180     if (lpDrvItemList == NULL) {
181         lpDrvItemList = lpNewDrv;
182         lpNewDrv->lpPrevItem = NULL;
183     } else {
184         LPWINE_DRIVER   lpDrv = lpDrvItemList;  /* find end of list */
185         while (lpDrv->lpNextItem != NULL)
186             lpDrv = lpDrv->lpNextItem;
187
188         lpDrv->lpNextItem = lpNewDrv;
189         lpNewDrv->lpPrevItem = lpDrv;
190     }
191
192     if (!(lpNewDrv->dwFlags & WINE_GDF_16BIT)) {
193         /* Now just open a new instance of a driver on this module */
194         lpNewDrv->d.d32.dwDriverID = DRIVER_SendMessage(lpNewDrv, DRV_OPEN, lParam1, lParam2);
195
196         if (lpNewDrv->d.d32.dwDriverID == 0) {
197             TRACE("DRV_OPEN failed on driver 0x%08lx\n", (DWORD)lpNewDrv);
198             DRIVER_RemoveFromList(lpNewDrv);
199             return FALSE;
200         }
201     }
202     return TRUE;
203 }
204
205 /**************************************************************************
206  *                              DRIVER_GetLibName               [internal]
207  *
208  */
209 BOOL    DRIVER_GetLibName(LPCWSTR keyName, LPCWSTR sectName, LPWSTR buf, int sz)
210 {
211     HKEY        hKey, hSecKey;
212     DWORD       bufLen, lRet;
213     static const WCHAR wszSystemIni[] = {'S','Y','S','T','E','M','.','I','N','I',0};
214     WCHAR       wsznull = '\0';
215
216     lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, HKLM_BASE, 0, KEY_QUERY_VALUE, &hKey);
217     if (lRet == ERROR_SUCCESS) {
218         lRet = RegOpenKeyExW(hKey, sectName, 0, KEY_QUERY_VALUE, &hSecKey);
219         if (lRet == ERROR_SUCCESS) {
220             bufLen = sz;
221             lRet = RegQueryValueExW(hSecKey, keyName, 0, 0, (void*)buf, &bufLen);
222             RegCloseKey( hSecKey );
223         }
224         RegCloseKey( hKey );
225     }
226     if (lRet == ERROR_SUCCESS) return TRUE;
227     /* default to system.ini if we can't find it in the registry,
228      * to support native installations where system.ini is still used */
229     return GetPrivateProfileStringW(sectName, keyName, &wsznull, buf, sz, wszSystemIni);
230 }
231
232 /**************************************************************************
233  *                              DRIVER_TryOpenDriver32          [internal]
234  *
235  * Tries to load a 32 bit driver whose DLL's (module) name is fn
236  */
237 LPWINE_DRIVER   DRIVER_TryOpenDriver32(LPCWSTR fn, LPARAM lParam2)
238 {
239     LPWINE_DRIVER       lpDrv = NULL;
240     HMODULE             hModule = 0;
241     LPWSTR              ptr;
242     LPCSTR              cause = 0;
243
244     TRACE("(%s, %08lX);\n", debugstr_w(fn), lParam2);
245
246     if ((ptr = strchrW(fn, ' ')) != NULL) {
247         *ptr++ = '\0';
248         while (*ptr == ' ') ptr++;
249         if (*ptr == '\0') ptr = NULL;
250     }
251
252     lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
253     if (lpDrv == NULL) {cause = "OOM"; goto exit;}
254
255     if ((hModule = LoadLibraryW(fn)) == 0) {cause = "Not a 32 bit lib"; goto exit;}
256
257     lpDrv->d.d32.lpDrvProc = (DRIVERPROC)GetProcAddress(hModule, "DriverProc");
258     if (lpDrv->d.d32.lpDrvProc == NULL) {cause = "no DriverProc"; goto exit;}
259
260     lpDrv->dwFlags          = 0;
261     lpDrv->d.d32.hModule    = hModule;
262     lpDrv->d.d32.dwDriverID = 0;
263
264     /* Win32 installable drivers must support a two phase opening scheme:
265      * + first open with NULL as lParam2 (session instance),
266      * + then do a second open with the real non null lParam2)
267      */
268     if (DRIVER_GetNumberOfModuleRefs(lpDrv->d.d32.hModule, NULL) == 0 && lParam2)
269     {
270         LPWINE_DRIVER   ret;
271
272         if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, 0L))
273         {
274             cause = "load0 failed";
275             goto exit;
276         }
277         ret = DRIVER_TryOpenDriver32(fn, lParam2);
278         if (!ret)
279         {
280             CloseDriver((HDRVR)lpDrv, 0L, 0L);
281             cause = "load1 failed";
282             goto exit;
283         }
284         return ret;
285     }
286
287     if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, lParam2))
288     {cause = "load failed"; goto exit;}
289
290     TRACE("=> %p\n", lpDrv);
291     return lpDrv;
292  exit:
293     FreeLibrary(hModule);
294     HeapFree(GetProcessHeap(), 0, lpDrv);
295     TRACE("Unable to load 32 bit module %s: %s\n", debugstr_w(fn), cause);
296     return NULL;
297 }
298
299 /**************************************************************************
300  *                              OpenDriverA                     [WINMM.@]
301  *                              DrvOpenA                        [WINMM.@]
302  * (0,1,DRV_LOAD  ,0       ,0)
303  * (0,1,DRV_ENABLE,0       ,0)
304  * (0,1,DRV_OPEN  ,buf[256],0)
305  */
306 HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam)
307 {
308     INT                 len;
309     LPWSTR              dn = NULL;
310     LPWSTR              sn = NULL;
311     HDRVR               ret;
312
313     if (lpDriverName)
314     {
315         len = MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, NULL, 0 );
316         dn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
317         if (!dn) return 0;
318         MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, dn, len );
319     }
320
321     if (lpSectionName)
322     {
323         len = MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, NULL, 0 );
324         sn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
325         if (!sn) return 0;
326         MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, sn, len );
327     }
328
329     ret = OpenDriver(dn, sn, lParam);
330
331     if (dn) HeapFree(GetProcessHeap(), 0, dn);
332     if (sn) HeapFree(GetProcessHeap(), 0, sn);
333     return ret;
334 }
335
336 /**************************************************************************
337  *                              OpenDriver                      [WINMM.@]
338  *                              DrvOpen                         [WINMM.@]
339  */
340 HDRVR WINAPI OpenDriver(LPCWSTR lpDriverName, LPCWSTR lpSectionName, LPARAM lParam)
341 {
342     LPWINE_DRIVER       lpDrv = NULL;
343     WCHAR               libName[128];
344     LPCWSTR             lsn = lpSectionName;
345
346     TRACE("(%s, %s, 0x%08lx);\n", 
347           debugstr_w(lpDriverName), debugstr_w(lpSectionName), lParam);
348
349     if (lsn == NULL) {
350         static const WCHAR wszDrivers32[] = {'D','r','i','v','e','r','s','3','2',0};
351         lstrcpynW(libName, lpDriverName, sizeof(libName) / sizeof(WCHAR));
352
353         if ((lpDrv = DRIVER_TryOpenDriver32(libName, lParam)))
354             goto the_end;
355         lsn = wszDrivers32;
356     }
357     if (DRIVER_GetLibName(lpDriverName, lsn, libName, sizeof(libName)) &&
358         (lpDrv = DRIVER_TryOpenDriver32(libName, lParam)))
359         goto the_end;
360
361     /* now we will try a 16 bit driver (and add all the glue to make it work... which
362      * is located in our mmsystem implementation)
363      * so ensure, we can load our mmsystem, otherwise just fail
364      */
365     WINMM_CheckForMMSystem();
366     if (pFnOpenDriver16 &&
367         (lpDrv = pFnOpenDriver16(lpDriverName, lpSectionName, lParam)))
368     {
369         if (DRIVER_AddToList(lpDrv, 0, lParam)) goto the_end;
370         HeapFree(GetProcessHeap(), 0, lpDrv);
371     }
372     TRACE("Failed to open driver %s from system.ini file, section %s\n", 
373           debugstr_w(lpDriverName), debugstr_w(lpSectionName));
374     return 0;
375
376  the_end:
377     if (lpDrv)  TRACE("=> %08lx\n", (DWORD)lpDrv);
378     return (HDRVR)lpDrv;
379 }
380
381 /**************************************************************************
382  *                      CloseDriver                             [WINMM.@]
383  *                      DrvClose                                [WINMM.@]
384  */
385 LRESULT WINAPI CloseDriver(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
386 {
387     LPWINE_DRIVER       lpDrv;
388
389     TRACE("(%p, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
390
391     if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL)
392     {
393         if (lpDrv->dwFlags & WINE_GDF_16BIT)
394         {
395             if (pFnCloseDriver16)
396                 pFnCloseDriver16(lpDrv->d.d16.hDriver16, lParam1, lParam2);
397         }
398         else
399         {
400             DRIVER_SendMessage(lpDrv, DRV_CLOSE, lParam1, lParam2);
401             lpDrv->d.d32.dwDriverID = 0;
402         }
403         if (DRIVER_RemoveFromList(lpDrv)) {
404             if (!(lpDrv->dwFlags & WINE_GDF_16BIT))
405             {
406                 LPWINE_DRIVER       lpDrv0;
407
408                 /* if driver has an opened session instance, we have to close it too */
409                 if (DRIVER_GetNumberOfModuleRefs(lpDrv->d.d32.hModule, &lpDrv0) == 1)
410                 {
411                     DRIVER_SendMessage(lpDrv0, DRV_CLOSE, 0L, 0L);
412                     lpDrv0->d.d32.dwDriverID = 0;
413                     DRIVER_RemoveFromList(lpDrv0);
414                     FreeLibrary(lpDrv0->d.d32.hModule);
415                     HeapFree(GetProcessHeap(), 0, lpDrv0);
416                 }
417                 FreeLibrary(lpDrv->d.d32.hModule);
418             }
419             HeapFree(GetProcessHeap(), 0, lpDrv);
420             return TRUE;
421         }
422     }
423     WARN("Failed to close driver\n");
424     return FALSE;
425 }
426
427 /**************************************************************************
428  *                              GetDriverFlags          [WINMM.@]
429  * [in] hDrvr handle to the driver
430  *
431  * Returns:
432  *      0x00000000 if hDrvr is an invalid handle
433  *      0x80000000 if hDrvr is a valid 32 bit driver
434  *      0x90000000 if hDrvr is a valid 16 bit driver
435  *
436  * native WINMM doesn't return those flags
437  *      0x80000000 for a valid 32 bit driver and that's it
438  *      (I may have mixed up the two flags :-(
439  */
440 DWORD   WINAPI GetDriverFlags(HDRVR hDrvr)
441 {
442     LPWINE_DRIVER       lpDrv;
443     DWORD               ret = 0;
444
445     TRACE("(%p)\n", hDrvr);
446
447     if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
448         ret = WINE_GDF_EXIST | lpDrv->dwFlags;
449     }
450     return ret;
451 }
452
453 /**************************************************************************
454  *                              GetDriverModuleHandle   [WINMM.@]
455  *                              DrvGetModuleHandle      [WINMM.@]
456  */
457 HMODULE WINAPI GetDriverModuleHandle(HDRVR hDrvr)
458 {
459     LPWINE_DRIVER       lpDrv;
460     HMODULE             hModule = 0;
461
462     TRACE("(%p);\n", hDrvr);
463
464     if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
465         if (!(lpDrv->dwFlags & WINE_GDF_16BIT))
466             hModule = lpDrv->d.d32.hModule;
467     }
468     TRACE("=> %p\n", hModule);
469     return hModule;
470 }
471
472 /**************************************************************************
473  *                              DefDriverProc                     [WINMM.@]
474  *                              DrvDefDriverProc                  [WINMM.@]
475  */
476 LRESULT WINAPI DefDriverProc(DWORD_PTR dwDriverIdentifier, HDRVR hDrv,
477                              UINT Msg, LPARAM lParam1, LPARAM lParam2)
478 {
479     switch (Msg) {
480     case DRV_LOAD:
481     case DRV_FREE:
482     case DRV_ENABLE:
483     case DRV_DISABLE:
484         return 1;
485     case DRV_INSTALL:
486     case DRV_REMOVE:
487         return DRV_SUCCESS;
488     default:
489         return 0;
490     }
491 }
492
493 /**************************************************************************
494  *                              DriverCallback                  [WINMM.@]
495  */
496 BOOL WINAPI DriverCallback(DWORD dwCallBack, UINT uFlags, HDRVR hDev,
497                            UINT wMsg, DWORD dwUser, DWORD dwParam1,
498                            DWORD dwParam2)
499 {
500     TRACE("(%08lX, %04X, %p, %04X, %08lX, %08lX, %08lX); !\n",
501           dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2);
502
503     switch (uFlags & DCB_TYPEMASK) {
504     case DCB_NULL:
505         TRACE("Null !\n");
506         if (dwCallBack)
507             WARN("uFlags=%04X has null DCB value, but dwCallBack=%08lX is not null !\n", uFlags, dwCallBack);
508         break;
509     case DCB_WINDOW:
510         TRACE("Window(%04lX) handle=%p!\n", dwCallBack, hDev);
511         PostMessageA((HWND)dwCallBack, wMsg, (WPARAM)hDev, dwParam1);
512         break;
513     case DCB_TASK: /* aka DCB_THREAD */
514         TRACE("Task(%04lx) !\n", dwCallBack);
515         PostThreadMessageA(dwCallBack, wMsg, (WPARAM)hDev, dwParam1);
516         break;
517     case DCB_FUNCTION:
518         TRACE("Function (32 bit) !\n");
519         ((LPDRVCALLBACK)dwCallBack)(hDev, wMsg, dwUser, dwParam1, dwParam2);
520         break;
521     case DCB_EVENT:
522         TRACE("Event(%08lx) !\n", dwCallBack);
523         SetEvent((HANDLE)dwCallBack);
524         break;
525     case 6: /* I would dub it DCB_MMTHREADSIGNAL */
526         /* this is an undocumented DCB_ value used for mmThreads
527          * loword of dwCallBack contains the handle of the lpMMThd block
528          * which dwSignalCount has to be incremented
529          */     
530         if (pFnGetMMThread16)
531         {
532             WINE_MMTHREAD*      lpMMThd = pFnGetMMThread16(LOWORD(dwCallBack));
533
534             TRACE("mmThread (%04x, %p) !\n", LOWORD(dwCallBack), lpMMThd);
535             /* same as mmThreadSignal16 */
536             InterlockedIncrement(&lpMMThd->dwSignalCount);
537             SetEvent(lpMMThd->hEvent);
538             /* some other stuff on lpMMThd->hVxD */
539         }
540         break;
541 #if 0
542     case 4:
543         /* this is an undocumented DCB_ value for... I don't know */
544         break;
545 #endif
546     default:
547         WARN("Unknown callback type %d\n", uFlags & DCB_TYPEMASK);
548         return FALSE;
549     }
550     TRACE("Done\n");
551     return TRUE;
552 }
553
554 /******************************************************************
555  *              DRIVER_UnloadAll
556  *
557  *
558  */
559 void    DRIVER_UnloadAll(void)
560 {
561     LPWINE_DRIVER       lpDrv;
562     LPWINE_DRIVER       lpNextDrv = NULL;
563     unsigned            count = 0;
564
565     for (lpDrv = lpDrvItemList; lpDrv != NULL; lpDrv = lpNextDrv)
566     {
567         lpNextDrv = lpDrv->lpNextItem;
568         CloseDriver((HDRVR)lpDrv, 0, 0);
569         count++;
570     }
571     TRACE("Unloaded %u drivers\n", count);
572 }