Merge trunk head (r43756)
[reactos.git] / reactos / dll / win32 / 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #include <string.h>
27 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winnls.h"
33 #include "winreg.h"
34 #include "mmddk.h"
35 #include "winemm.h"
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
38 #include "excpt.h"
39 #include "wine/exception.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(driver);
42
43 static CRITICAL_SECTION mmdriver_lock;
44 static CRITICAL_SECTION_DEBUG mmdriver_lock_debug =
45 {
46 0, 0, &mmdriver_lock,
47 { &mmdriver_lock_debug.ProcessLocksList, &mmdriver_lock_debug.ProcessLocksList },
48 0, 0, { (DWORD_PTR)(__FILE__ ": mmdriver_lock") }
49 };
50 static CRITICAL_SECTION mmdriver_lock = { &mmdriver_lock_debug, -1, 0, 0, 0, 0 };
51
52 static LPWINE_DRIVER lpDrvItemList /* = NULL */;
53 static const WCHAR HKLM_BASE[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
54 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
55
56 static void DRIVER_Dump(const char *comment)
57 {
58 #if 0
59 LPWINE_DRIVER lpDrv;
60
61 TRACE("%s\n", comment);
62
63 EnterCriticalSection( &mmdriver_lock );
64
65 for (lpDrv = lpDrvItemList; lpDrv != NULL; lpDrv = lpDrv->lpNextItem)
66 {
67 TRACE("%p, magic %04lx, id %p, next %p\n", lpDrv, lpDrv->dwMagic, lpDrv->d.d32.dwDriverID, lpDrv->lpNextItem);
68 }
69
70 LeaveCriticalSection( &mmdriver_lock );
71 #endif
72 }
73
74 /**************************************************************************
75 * DRIVER_GetNumberOfModuleRefs [internal]
76 *
77 * Returns the number of open drivers which share the same module.
78 */
79 static unsigned DRIVER_GetNumberOfModuleRefs(HMODULE hModule, WINE_DRIVER** found)
80 {
81 LPWINE_DRIVER lpDrv;
82 unsigned count = 0;
83
84 EnterCriticalSection( &mmdriver_lock );
85
86 if (found) *found = NULL;
87 for (lpDrv = lpDrvItemList; lpDrv; lpDrv = lpDrv->lpNextItem)
88 {
89 if (lpDrv->hModule == hModule)
90 {
91 if (found && !*found) *found = lpDrv;
92 count++;
93 }
94 }
95
96 LeaveCriticalSection( &mmdriver_lock );
97 return count;
98 }
99
100 /**************************************************************************
101 * DRIVER_FindFromHDrvr [internal]
102 *
103 * From a hDrvr being 32 bits, returns the WINE internal structure.
104 */
105 LPWINE_DRIVER DRIVER_FindFromHDrvr(HDRVR hDrvr)
106 {
107 LPWINE_DRIVER d;
108
109 __TRY
110 {
111 d = (LPWINE_DRIVER)hDrvr;
112 if (d && d->dwMagic != WINE_DI_MAGIC) d = NULL;
113 }
114 __EXCEPT_PAGE_FAULT
115 {
116 return NULL;
117 }
118 __ENDTRY;
119
120 if (d) TRACE("%p -> %p, %p\n", hDrvr, d->lpDrvProc, (void *)d->dwDriverID);
121 else TRACE("%p -> NULL\n", hDrvr);
122
123 return d;
124 }
125
126 /**************************************************************************
127 * DRIVER_SendMessage [internal]
128 */
129 static inline LRESULT DRIVER_SendMessage(LPWINE_DRIVER lpDrv, UINT msg,
130 LPARAM lParam1, LPARAM lParam2)
131 {
132 LRESULT ret = 0;
133
134 TRACE("Before call32 proc=%p drvrID=%08lx hDrv=%p wMsg=%04x p1=%08lx p2=%08lx\n",
135 lpDrv->lpDrvProc, lpDrv->dwDriverID, lpDrv, msg, lParam1, lParam2);
136 ret = lpDrv->lpDrvProc(lpDrv->dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2);
137 TRACE("After call32 proc=%p drvrID=%08lx hDrv=%p wMsg=%04x p1=%08lx p2=%08lx => %08lx\n",
138 lpDrv->lpDrvProc, lpDrv->dwDriverID, lpDrv, msg, lParam1, lParam2, ret);
139
140 return ret;
141 }
142
143 /**************************************************************************
144 * SendDriverMessage [WINMM.@]
145 * DrvSendMessage [WINMM.@]
146 */
147 LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT msg, LONG lParam1,
148 LONG lParam2)
149 {
150 LPWINE_DRIVER lpDrv;
151 LRESULT retval = 0;
152
153 TRACE("(%p, %04X, %08lX, %08lX)\n", hDriver, msg, lParam1, lParam2);
154
155 if ((lpDrv = DRIVER_FindFromHDrvr(hDriver)) != NULL) {
156 retval = DRIVER_SendMessage(lpDrv, msg, lParam1, lParam2);
157 } else {
158 WARN("Bad driver handle %p\n", hDriver);
159 }
160 TRACE("retval = %ld\n", retval);
161
162 return retval;
163 }
164
165 /**************************************************************************
166 * DRIVER_RemoveFromList [internal]
167 *
168 * Generates all the logic to handle driver closure / deletion
169 * Removes a driver struct to the list of open drivers.
170 */
171 static BOOL DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv)
172 {
173 /* last of this driver in list ? */
174 if (DRIVER_GetNumberOfModuleRefs(lpDrv->hModule, NULL) == 1) {
175 DRIVER_SendMessage(lpDrv, DRV_DISABLE, 0L, 0L);
176 DRIVER_SendMessage(lpDrv, DRV_FREE, 0L, 0L);
177 }
178
179 EnterCriticalSection( &mmdriver_lock );
180
181 if (lpDrv->lpPrevItem)
182 lpDrv->lpPrevItem->lpNextItem = lpDrv->lpNextItem;
183 else
184 lpDrvItemList = lpDrv->lpNextItem;
185 if (lpDrv->lpNextItem)
186 lpDrv->lpNextItem->lpPrevItem = lpDrv->lpPrevItem;
187 /* trash magic number */
188 lpDrv->dwMagic ^= 0xa5a5a5a5;
189 lpDrv->lpDrvProc = NULL;
190 lpDrv->dwDriverID = 0;
191
192 LeaveCriticalSection( &mmdriver_lock );
193
194 return TRUE;
195 }
196
197 /**************************************************************************
198 * DRIVER_AddToList [internal]
199 *
200 * Adds a driver struct to the list of open drivers.
201 * Generates all the logic to handle driver creation / open.
202 */
203 static BOOL DRIVER_AddToList(LPWINE_DRIVER lpNewDrv, LPARAM lParam1, LPARAM lParam2)
204 {
205 lpNewDrv->dwMagic = WINE_DI_MAGIC;
206 /* First driver to be loaded for this module, need to load correctly the module */
207 /* first of this driver in list ? */
208 if (DRIVER_GetNumberOfModuleRefs(lpNewDrv->hModule, NULL) == 0) {
209 if (DRIVER_SendMessage(lpNewDrv, DRV_LOAD, 0L, 0L) != DRV_SUCCESS) {
210 TRACE("DRV_LOAD failed on driver %p\n", lpNewDrv);
211 return FALSE;
212 }
213 /* returned value is not checked */
214 DRIVER_SendMessage(lpNewDrv, DRV_ENABLE, 0L, 0L);
215 }
216
217 /* Now just open a new instance of a driver on this module */
218 lpNewDrv->dwDriverID = DRIVER_SendMessage(lpNewDrv, DRV_OPEN, lParam1, lParam2);
219
220 if (lpNewDrv->dwDriverID == 0)
221 {
222 TRACE("DRV_OPEN failed on driver %p\n", lpNewDrv);
223 return FALSE;
224 }
225
226 EnterCriticalSection( &mmdriver_lock );
227
228 lpNewDrv->lpNextItem = NULL;
229 if (lpDrvItemList == NULL) {
230 lpDrvItemList = lpNewDrv;
231 lpNewDrv->lpPrevItem = NULL;
232 } else {
233 LPWINE_DRIVER lpDrv = lpDrvItemList; /* find end of list */
234 while (lpDrv->lpNextItem != NULL)
235 lpDrv = lpDrv->lpNextItem;
236
237 lpDrv->lpNextItem = lpNewDrv;
238 lpNewDrv->lpPrevItem = lpDrv;
239 }
240
241 LeaveCriticalSection( &mmdriver_lock );
242 return TRUE;
243 }
244
245 /**************************************************************************
246 * DRIVER_GetLibName [internal]
247 *
248 */
249 BOOL DRIVER_GetLibName(LPCWSTR keyName, LPCWSTR sectName, LPWSTR buf, int sz)
250 {
251 HKEY hKey, hSecKey;
252 DWORD bufLen, lRet;
253 static const WCHAR wszSystemIni[] = {'S','Y','S','T','E','M','.','I','N','I',0};
254 WCHAR wsznull = '\0';
255
256 /* This takes us as far as Windows NT\CurrentVersion */
257 lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, HKLM_BASE, 0, KEY_QUERY_VALUE, &hKey);
258
259 if (lRet == ERROR_SUCCESS)
260 {
261 /* Now we descend into the section name that we were given */
262 lRet = RegOpenKeyExW(hKey, sectName, 0, KEY_QUERY_VALUE, &hSecKey);
263
264 if (lRet == ERROR_SUCCESS)
265 {
266 /* Retrieve the desired value - this is the filename of the lib */
267 bufLen = sz;
268 lRet = RegQueryValueExW(hSecKey, keyName, 0, 0, (void*)buf, &bufLen);
269 RegCloseKey( hSecKey );
270 }
271
272 RegCloseKey( hKey );
273 }
274
275 /* Finish up if we've got what we want from the registry */
276 if (lRet == ERROR_SUCCESS)
277 return TRUE;
278
279 /* default to system.ini if we can't find it in the registry,
280 * to support native installations where system.ini is still used */
281 return GetPrivateProfileStringW(sectName, keyName, &wsznull, buf, sz / sizeof(WCHAR), wszSystemIni);
282 }
283
284 /**************************************************************************
285 * DRIVER_TryOpenDriver32 [internal]
286 *
287 * Tries to load a 32 bit driver whose DLL's (module) name is fn
288 */
289 LPWINE_DRIVER DRIVER_TryOpenDriver32(LPCWSTR fn, LPARAM lParam2)
290 {
291 LPWINE_DRIVER lpDrv = NULL;
292 HMODULE hModule = 0;
293 LPWSTR ptr;
294 LPCSTR cause = 0;
295
296 TRACE("(%s, %08lX);\n", debugstr_w(fn), lParam2);
297
298 if ((ptr = strchrW(fn, ' ')) != NULL)
299 {
300 *ptr++ = '\0';
301
302 while (*ptr == ' ')
303 ptr++;
304
305 if (*ptr == '\0')
306 ptr = NULL;
307 }
308
309 lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
310
311 if (lpDrv == NULL)
312 {
313 cause = "OOM";
314 goto exit;
315 }
316
317 if ((hModule = LoadLibraryW(fn)) == 0)
318 {
319 cause = "Not a 32 bit lib";
320 goto exit;
321 }
322
323 lpDrv->lpDrvProc = (DRIVERPROC)GetProcAddress(hModule, "DriverProc");
324
325 if (lpDrv->lpDrvProc == NULL)
326 {
327 cause = "no DriverProc";
328 goto exit;
329 }
330
331 lpDrv->dwFlags = 0;
332 lpDrv->hModule = hModule;
333 lpDrv->dwDriverID = 0;
334
335 /* Win32 installable drivers must support a two phase opening scheme:
336 * + first open with NULL as lParam2 (session instance),
337 * + then do a second open with the real non null lParam2)
338 */
339 if (DRIVER_GetNumberOfModuleRefs(lpDrv->hModule, NULL) == 0 && lParam2)
340 {
341 LPWINE_DRIVER ret;
342
343 if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, 0L))
344 {
345 cause = "load0 failed";
346 goto exit;
347 }
348 ret = DRIVER_TryOpenDriver32(fn, lParam2);
349 if (!ret)
350 {
351 CloseDriver((HDRVR)lpDrv, 0L, 0L);
352 cause = "load1 failed";
353 goto exit;
354 }
355 return ret;
356 }
357
358 if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, lParam2))
359 {
360 cause = "load failed";
361 goto exit;
362 }
363
364 TRACE("=> %p\n", lpDrv);
365 return lpDrv;
366
367 exit:
368 FreeLibrary(hModule);
369 HeapFree(GetProcessHeap(), 0, lpDrv);
370 TRACE("Unable to load 32 bit module %s: %s\n", debugstr_w(fn), cause);
371 return NULL;
372 }
373
374 /**************************************************************************
375 * OpenDriverA [WINMM.@]
376 * DrvOpenA [WINMM.@]
377 * (0,1,DRV_LOAD ,0 ,0)
378 * (0,1,DRV_ENABLE,0 ,0)
379 * (0,1,DRV_OPEN ,buf[256],0)
380 */
381 HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam)
382 {
383 INT len;
384 LPWSTR dn = NULL;
385 LPWSTR sn = NULL;
386 HDRVR ret = 0;
387
388 if (lpDriverName)
389 {
390 len = MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, NULL, 0 );
391 dn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
392 if (!dn) goto done;
393 MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, dn, len );
394 }
395
396 if (lpSectionName)
397 {
398 len = MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, NULL, 0 );
399 sn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
400 if (!sn) goto done;
401 MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, sn, len );
402 }
403
404 ret = OpenDriver(dn, sn, lParam);
405
406 done:
407 HeapFree(GetProcessHeap(), 0, dn);
408 HeapFree(GetProcessHeap(), 0, sn);
409 return ret;
410 }
411
412 /**************************************************************************
413 * OpenDriver [WINMM.@]
414 * DrvOpen [WINMM.@]
415 */
416 HDRVR WINAPI OpenDriver(LPCWSTR lpDriverName, LPCWSTR lpSectionName, LONG lParam)
417 {
418 LPWINE_DRIVER lpDrv = NULL;
419 WCHAR libName[128];
420 LPCWSTR lsn = lpSectionName;
421
422 TRACE("(%s, %s, 0x%08lx);\n",
423 debugstr_w(lpDriverName), debugstr_w(lpSectionName), lParam);
424
425 /* If no section name is specified, either the caller is intending on
426 opening a driver by filename, or wants to open a user-installable
427 driver that has an entry in the Drivers32 key in the registry */
428 if (lsn == NULL)
429 {
430 /* Default registry key */
431 static const WCHAR wszDrivers32[] = {'D','r','i','v','e','r','s','3','2',0};
432
433 lstrcpynW(libName, lpDriverName, sizeof(libName) / sizeof(WCHAR));
434
435 /* Try and open the driver by filename */
436 if ( (lpDrv = DRIVER_TryOpenDriver32(libName, lParam)) )
437 goto the_end;
438
439 /* If we got here, the file wasn't found. So we assume the caller
440 wanted a driver specified under the Drivers32 registry key */
441 lsn = wszDrivers32;
442 }
443
444 /* Attempt to locate the driver filename in the registry */
445 if ( DRIVER_GetLibName(lpDriverName, lsn, libName, sizeof(libName)) )
446 {
447 /* Now we have the filename, we can try and load it */
448 if ( (lpDrv = DRIVER_TryOpenDriver32(libName, lParam)) )
449 goto the_end;
450 }
451
452 /* now we will try a 16 bit driver (and add all the glue to make it work... which
453 * is located in our mmsystem implementation)
454 * so ensure, we can load our mmsystem, otherwise just fail
455 */
456 WINMM_CheckForMMSystem();
457 #if 0
458 if (pFnOpenDriver16 &&
459 (lpDrv = pFnOpenDriver16(lpDriverName, lpSectionName, lParam)))
460 {
461 if (DRIVER_AddToList(lpDrv, 0, lParam)) goto the_end;
462 HeapFree(GetProcessHeap(), 0, lpDrv);
463 }
464 TRACE("Failed to open driver %s from system.ini file, section %s\n",
465 debugstr_w(lpDriverName), debugstr_w(lpSectionName));
466 #endif
467 return 0;
468
469 the_end:
470 if (lpDrv) TRACE("=> %p\n", lpDrv);
471 return (HDRVR)lpDrv;
472 }
473
474 /**************************************************************************
475 * CloseDriver [WINMM.@]
476 * DrvClose [WINMM.@]
477 */
478 LRESULT WINAPI CloseDriver(HDRVR hDrvr, LONG lParam1, LONG lParam2)
479 {
480 BOOL ret;
481 LPWINE_DRIVER lpDrv;
482
483 TRACE("(%p, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
484
485 DRIVER_Dump("BEFORE:");
486
487 if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL)
488 {
489 LPWINE_DRIVER lpDrv0;
490
491 DRIVER_SendMessage(lpDrv, DRV_CLOSE, lParam1, lParam2);
492
493 DRIVER_RemoveFromList(lpDrv);
494
495 if (lpDrv->dwFlags & WINE_GDF_SESSION)
496 FIXME("WINE_GDF_SESSION: Shouldn't happen (%p)\n", lpDrv);
497 /* if driver has an opened session instance, we have to close it too */
498 if (DRIVER_GetNumberOfModuleRefs(lpDrv->hModule, &lpDrv0) == 1 &&
499 (lpDrv0->dwFlags & WINE_GDF_SESSION))
500 {
501 DRIVER_SendMessage(lpDrv0, DRV_CLOSE, 0, 0);
502 DRIVER_RemoveFromList(lpDrv0);
503 FreeLibrary(lpDrv0->hModule);
504 HeapFree(GetProcessHeap(), 0, lpDrv0);
505 }
506 FreeLibrary(lpDrv->hModule);
507
508 HeapFree(GetProcessHeap(), 0, lpDrv);
509 ret = TRUE;
510 }
511 else
512 {
513 WARN("Failed to close driver\n");
514 ret = FALSE;
515 }
516
517 DRIVER_Dump("AFTER:");
518
519 return ret;
520 }
521
522 /**************************************************************************
523 * GetDriverFlags [WINMM.@]
524 * [in] hDrvr handle to the driver
525 *
526 * Returns:
527 * 0x00000000 if hDrvr is an invalid handle
528 * 0x80000000 if hDrvr is a valid 32 bit driver
529 * 0x90000000 if hDrvr is a valid 16 bit driver
530 *
531 * native WINMM doesn't return those flags
532 * 0x80000000 for a valid 32 bit driver and that's it
533 * (I may have mixed up the two flags :-(
534 */
535 DWORD WINAPI GetDriverFlags(HDRVR hDrvr)
536 {
537 LPWINE_DRIVER lpDrv;
538 DWORD ret = 0;
539
540 TRACE("(%p)\n", hDrvr);
541
542 if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
543 ret = WINE_GDF_EXIST | (lpDrv->dwFlags & WINE_GDF_EXTERNAL_MASK);
544 }
545 return ret;
546 }
547
548 /**************************************************************************
549 * GetDriverModuleHandle [WINMM.@]
550 * DrvGetModuleHandle [WINMM.@]
551 */
552 HMODULE WINAPI GetDriverModuleHandle(HDRVR hDrvr)
553 {
554 LPWINE_DRIVER lpDrv;
555 HMODULE hModule = 0;
556
557 TRACE("(%p);\n", hDrvr);
558
559 if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
560 hModule = lpDrv->hModule;
561 }
562 TRACE("=> %p\n", hModule);
563 return hModule;
564 }
565
566 /**************************************************************************
567 * DefDriverProc [WINMM.@]
568 * DrvDefDriverProc [WINMM.@]
569 */
570 LONG WINAPI DefDriverProc(DWORD dwDriverIdentifier, HDRVR hDrv,
571 UINT Msg, LONG lParam1, LONG lParam2)
572 {
573 switch (Msg) {
574 case DRV_LOAD:
575 case DRV_FREE:
576 case DRV_ENABLE:
577 case DRV_DISABLE:
578 return 1;
579 case DRV_INSTALL:
580 case DRV_REMOVE:
581 return DRV_SUCCESS;
582 default:
583 return 0;
584 }
585 }
586
587 /**************************************************************************
588 * DriverCallback [WINMM.@]
589 */
590 BOOL WINAPI DriverCallback(DWORD_PTR dwCallBack, DWORD uFlags, HDRVR hDev,
591 DWORD wMsg, DWORD_PTR dwUser, DWORD_PTR dwParam1,
592 DWORD_PTR dwParam2)
593 {
594 TRACE("(%08lX, %04X, %p, %04X, %08lX, %08lX, %08lX)\n",
595 dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2);
596
597 switch (uFlags & DCB_TYPEMASK) {
598 case DCB_NULL:
599 TRACE("Null !\n");
600 if (dwCallBack)
601 WARN("uFlags=%04X has null DCB value, but dwCallBack=%08lX is not null !\n", uFlags, dwCallBack);
602 break;
603 case DCB_WINDOW:
604 TRACE("Window(%04lX) handle=%p!\n", dwCallBack, hDev);
605 PostMessageA((HWND)dwCallBack, wMsg, (WPARAM)hDev, dwParam1);
606 break;
607 case DCB_TASK: /* aka DCB_THREAD */
608 TRACE("Task(%04lx) !\n", dwCallBack);
609 PostThreadMessageA(dwCallBack, wMsg, (WPARAM)hDev, dwParam1);
610 break;
611 case DCB_FUNCTION:
612 TRACE("Function (32 bit) !\n");
613 ((LPDRVCALLBACK)dwCallBack)(hDev, wMsg, dwUser, dwParam1, dwParam2);
614 break;
615 case DCB_EVENT:
616 TRACE("Event(%08lx) !\n", dwCallBack);
617 SetEvent((HANDLE)dwCallBack);
618 break;
619 #if 0
620 /* FIXME: for now only usable in mmsystem.dll16
621 * If needed, should be enabled back
622 */
623 case 6: /* I would dub it DCB_MMTHREADSIGNAL */
624 /* this is an undocumented DCB_ value used for mmThreads
625 * loword of dwCallBack contains the handle of the lpMMThd block
626 * which dwSignalCount has to be incremented
627 */
628 if (pFnGetMMThread16)
629 {
630 WINE_MMTHREAD* lpMMThd = pFnGetMMThread16(LOWORD(dwCallBack));
631
632 TRACE("mmThread (%04x, %p) !\n", LOWORD(dwCallBack), lpMMThd);
633 /* same as mmThreadSignal16 */
634 InterlockedIncrement(&lpMMThd->dwSignalCount);
635 SetEvent(lpMMThd->hEvent);
636 /* some other stuff on lpMMThd->hVxD */
637 }
638 break;
639 #endif
640 #if 0
641 case 4:
642 /* this is an undocumented DCB_ value for... I don't know */
643 break;
644 #endif
645 default:
646 WARN("Unknown callback type %d\n", uFlags & DCB_TYPEMASK);
647 return FALSE;
648 }
649 TRACE("Done\n");
650 return TRUE;
651 }
652
653 /******************************************************************
654 * DRIVER_UnloadAll
655 *
656 *
657 */
658 void DRIVER_UnloadAll(void)
659 {
660 LPWINE_DRIVER lpDrv;
661 LPWINE_DRIVER lpNextDrv = NULL;
662 unsigned count = 0;
663
664 restart:
665 EnterCriticalSection( &mmdriver_lock );
666
667 for (lpDrv = lpDrvItemList; lpDrv != NULL; lpDrv = lpNextDrv)
668 {
669 lpNextDrv = lpDrv->lpNextItem;
670
671 /* session instances will be unloaded automatically */
672 if (!(lpDrv->dwFlags & WINE_GDF_SESSION))
673 {
674 LeaveCriticalSection( &mmdriver_lock );
675 CloseDriver((HDRVR)lpDrv, 0, 0);
676 count++;
677 /* restart from the beginning of the list */
678 goto restart;
679 }
680 }
681
682 LeaveCriticalSection( &mmdriver_lock );
683
684 TRACE("Unloaded %u drivers\n", count);
685 }