Return proper error code.
[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 / sizeof(WCHAR), 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 = 0;
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) goto done;
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) goto done;
326         MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, sn, len );
327     }
328
329     ret = OpenDriver(dn, sn, lParam);
330
331 done:
332     HeapFree(GetProcessHeap(), 0, dn);
333     HeapFree(GetProcessHeap(), 0, sn);
334     return ret;
335 }
336
337 /**************************************************************************
338  *                              OpenDriver                      [WINMM.@]
339  *                              DrvOpen                         [WINMM.@]
340  */
341 HDRVR WINAPI OpenDriver(LPCWSTR lpDriverName, LPCWSTR lpSectionName, LPARAM lParam)
342 {
343     LPWINE_DRIVER       lpDrv = NULL;
344     WCHAR               libName[128];
345     LPCWSTR             lsn = lpSectionName;
346
347     TRACE("(%s, %s, 0x%08lx);\n", 
348           debugstr_w(lpDriverName), debugstr_w(lpSectionName), lParam);
349
350     if (lsn == NULL) {
351         static const WCHAR wszDrivers32[] = {'D','r','i','v','e','r','s','3','2',0};
352         lstrcpynW(libName, lpDriverName, sizeof(libName) / sizeof(WCHAR));
353
354         if ((lpDrv = DRIVER_TryOpenDriver32(libName, lParam)))
355             goto the_end;
356         lsn = wszDrivers32;
357     }
358     if (DRIVER_GetLibName(lpDriverName, lsn, libName, sizeof(libName)) &&
359         (lpDrv = DRIVER_TryOpenDriver32(libName, lParam)))
360         goto the_end;
361
362     /* now we will try a 16 bit driver (and add all the glue to make it work... which
363      * is located in our mmsystem implementation)
364      * so ensure, we can load our mmsystem, otherwise just fail
365      */
366     WINMM_CheckForMMSystem();
367     if (pFnOpenDriver16 &&
368         (lpDrv = pFnOpenDriver16(lpDriverName, lpSectionName, lParam)))
369     {
370         if (DRIVER_AddToList(lpDrv, 0, lParam)) goto the_end;
371         HeapFree(GetProcessHeap(), 0, lpDrv);
372     }
373     TRACE("Failed to open driver %s from system.ini file, section %s\n", 
374           debugstr_w(lpDriverName), debugstr_w(lpSectionName));
375     return 0;
376
377  the_end:
378     if (lpDrv)  TRACE("=> %08lx\n", (DWORD)lpDrv);
379     return (HDRVR)lpDrv;
380 }
381
382 /**************************************************************************
383  *                      CloseDriver                             [WINMM.@]
384  *                      DrvClose                                [WINMM.@]
385  */
386 LRESULT WINAPI CloseDriver(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
387 {
388     LPWINE_DRIVER       lpDrv;
389
390     TRACE("(%p, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
391
392     if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL)
393     {
394         if (lpDrv->dwFlags & WINE_GDF_16BIT)
395         {
396             if (pFnCloseDriver16)
397                 pFnCloseDriver16(lpDrv->d.d16.hDriver16, lParam1, lParam2);
398         }
399         else
400         {
401             DRIVER_SendMessage(lpDrv, DRV_CLOSE, lParam1, lParam2);
402             lpDrv->d.d32.dwDriverID = 0;
403         }
404         if (DRIVER_RemoveFromList(lpDrv)) {
405             if (!(lpDrv->dwFlags & WINE_GDF_16BIT))
406             {
407                 LPWINE_DRIVER       lpDrv0;
408
409                 /* if driver has an opened session instance, we have to close it too */
410                 if (DRIVER_GetNumberOfModuleRefs(lpDrv->d.d32.hModule, &lpDrv0) == 1)
411                 {
412                     DRIVER_SendMessage(lpDrv0, DRV_CLOSE, 0L, 0L);
413                     lpDrv0->d.d32.dwDriverID = 0;
414                     DRIVER_RemoveFromList(lpDrv0);
415                     FreeLibrary(lpDrv0->d.d32.hModule);
416                     HeapFree(GetProcessHeap(), 0, lpDrv0);
417                 }
418                 FreeLibrary(lpDrv->d.d32.hModule);
419             }
420             HeapFree(GetProcessHeap(), 0, lpDrv);
421             return TRUE;
422         }
423     }
424     WARN("Failed to close driver\n");
425     return FALSE;
426 }
427
428 /**************************************************************************
429  *                              GetDriverFlags          [WINMM.@]
430  * [in] hDrvr handle to the driver
431  *
432  * Returns:
433  *      0x00000000 if hDrvr is an invalid handle
434  *      0x80000000 if hDrvr is a valid 32 bit driver
435  *      0x90000000 if hDrvr is a valid 16 bit driver
436  *
437  * native WINMM doesn't return those flags
438  *      0x80000000 for a valid 32 bit driver and that's it
439  *      (I may have mixed up the two flags :-(
440  */
441 DWORD   WINAPI GetDriverFlags(HDRVR hDrvr)
442 {
443     LPWINE_DRIVER       lpDrv;
444     DWORD               ret = 0;
445
446     TRACE("(%p)\n", hDrvr);
447
448     if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
449         ret = WINE_GDF_EXIST | lpDrv->dwFlags;
450     }
451     return ret;
452 }
453
454 /**************************************************************************
455  *                              GetDriverModuleHandle   [WINMM.@]
456  *                              DrvGetModuleHandle      [WINMM.@]
457  */
458 HMODULE WINAPI GetDriverModuleHandle(HDRVR hDrvr)
459 {
460     LPWINE_DRIVER       lpDrv;
461     HMODULE             hModule = 0;
462
463     TRACE("(%p);\n", hDrvr);
464
465     if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
466         if (!(lpDrv->dwFlags & WINE_GDF_16BIT))
467             hModule = lpDrv->d.d32.hModule;
468     }
469     TRACE("=> %p\n", hModule);
470     return hModule;
471 }
472
473 /**************************************************************************
474  *                              DefDriverProc                     [WINMM.@]
475  *                              DrvDefDriverProc                  [WINMM.@]
476  */
477 LRESULT WINAPI DefDriverProc(DWORD_PTR dwDriverIdentifier, HDRVR hDrv,
478                              UINT Msg, LPARAM lParam1, LPARAM lParam2)
479 {
480     switch (Msg) {
481     case DRV_LOAD:
482     case DRV_FREE:
483     case DRV_ENABLE:
484     case DRV_DISABLE:
485         return 1;
486     case DRV_INSTALL:
487     case DRV_REMOVE:
488         return DRV_SUCCESS;
489     default:
490         return 0;
491     }
492 }
493
494 /**************************************************************************
495  *                              DriverCallback                  [WINMM.@]
496  */
497 BOOL WINAPI DriverCallback(DWORD dwCallBack, UINT uFlags, HDRVR hDev,
498                            UINT wMsg, DWORD dwUser, DWORD dwParam1,
499                            DWORD dwParam2)
500 {
501     TRACE("(%08lX, %04X, %p, %04X, %08lX, %08lX, %08lX); !\n",
502           dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2);
503
504     switch (uFlags & DCB_TYPEMASK) {
505     case DCB_NULL:
506         TRACE("Null !\n");
507         if (dwCallBack)
508             WARN("uFlags=%04X has null DCB value, but dwCallBack=%08lX is not null !\n", uFlags, dwCallBack);
509         break;
510     case DCB_WINDOW:
511         TRACE("Window(%04lX) handle=%p!\n", dwCallBack, hDev);
512         PostMessageA((HWND)dwCallBack, wMsg, (WPARAM)hDev, dwParam1);
513         break;
514     case DCB_TASK: /* aka DCB_THREAD */
515         TRACE("Task(%04lx) !\n", dwCallBack);
516         PostThreadMessageA(dwCallBack, wMsg, (WPARAM)hDev, dwParam1);
517         break;
518     case DCB_FUNCTION:
519         TRACE("Function (32 bit) !\n");
520         ((LPDRVCALLBACK)dwCallBack)(hDev, wMsg, dwUser, dwParam1, dwParam2);
521         break;
522     case DCB_EVENT:
523         TRACE("Event(%08lx) !\n", dwCallBack);
524         SetEvent((HANDLE)dwCallBack);
525         break;
526     case 6: /* I would dub it DCB_MMTHREADSIGNAL */
527         /* this is an undocumented DCB_ value used for mmThreads
528          * loword of dwCallBack contains the handle of the lpMMThd block
529          * which dwSignalCount has to be incremented
530          */     
531         if (pFnGetMMThread16)
532         {
533             WINE_MMTHREAD*      lpMMThd = pFnGetMMThread16(LOWORD(dwCallBack));
534
535             TRACE("mmThread (%04x, %p) !\n", LOWORD(dwCallBack), lpMMThd);
536             /* same as mmThreadSignal16 */
537             InterlockedIncrement(&lpMMThd->dwSignalCount);
538             SetEvent(lpMMThd->hEvent);
539             /* some other stuff on lpMMThd->hVxD */
540         }
541         break;
542 #if 0
543     case 4:
544         /* this is an undocumented DCB_ value for... I don't know */
545         break;
546 #endif
547     default:
548         WARN("Unknown callback type %d\n", uFlags & DCB_TYPEMASK);
549         return FALSE;
550     }
551     TRACE("Done\n");
552     return TRUE;
553 }
554
555 /******************************************************************
556  *              DRIVER_UnloadAll
557  *
558  *
559  */
560 void    DRIVER_UnloadAll(void)
561 {
562     LPWINE_DRIVER       lpDrv;
563     LPWINE_DRIVER       lpNextDrv = NULL;
564     unsigned            count = 0;
565
566     for (lpDrv = lpDrvItemList; lpDrv != NULL; lpDrv = lpNextDrv)
567     {
568         lpNextDrv = lpDrv->lpNextItem;
569         CloseDriver((HDRVR)lpDrv, 0, 0);
570         count++;
571     }
572     TRACE("Unloaded %u drivers\n", count);
573 }