source: trunk/src/winmm/driver.c@ 10367

Last change on this file since 10367 was 6712, checked in by sandervl, 24 years ago

restored old version

File size: 21.0 KB
Line 
1/* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
3/*
4 * WINE Drivers functions
5 *
6 * Copyright 1994 Martin Ayotte
7 * Copyright 1998 Marcus Meissner
8 * Copyright 1999 Eric Pouech
9 */
10
11#include <string.h>
12#ifdef __WIN32OS2__
13#include "winbase.h"
14#include "winerror.h"
15#include "windef.h"
16#include "wingdi.h"
17#include "winuser.h"
18#include <mmddk.h>
19#include <mmsystem.h>
20#include "winemm.h"
21#include <heapstring.h>
22#define inline
23#else
24#include "heap.h"
25#include "windef.h"
26#include "mmddk.h"
27#include "winemm.h"
28#include "wine/winbase16.h"
29#endif
30#include "debugtools.h"
31
32DEFAULT_DEBUG_CHANNEL(driver);
33
34static LPWINE_DRIVER lpDrvItemList = NULL;
35
36/* TODO list :
37 * - LoadModule count and clean up is not handled correctly (it's not a
38 * problem as long as FreeLibrary is not working correctly)
39 */
40
41/**************************************************************************
42 * DRIVER_GetNumberOfModuleRefs [internal]
43 *
44 * Returns the number of open drivers which share the same module.
45 */
46static WORD DRIVER_GetNumberOfModuleRefs(LPWINE_DRIVER lpNewDrv)
47{
48 LPWINE_DRIVER lpDrv;
49 WORD count = 0;
50
51 if (lpNewDrv->dwFlags & WINE_GDF_16BIT) ERR("OOOch");
52 for (lpDrv = lpDrvItemList; lpDrv; lpDrv = lpDrv->lpNextItem) {
53 if (!(lpDrv->dwFlags & WINE_GDF_16BIT) &&
54 lpDrv->d.d32.hModule == lpNewDrv->d.d32.hModule) {
55 count++;
56 }
57 }
58 return count;
59}
60
61/**************************************************************************
62 * DRIVER_FindFromHDrvr [internal]
63 *
64 * From a hDrvr being 32 bits, returns the WINE internal structure.
65 */
66LPWINE_DRIVER DRIVER_FindFromHDrvr(HDRVR hDrvr)
67{
68 LPWINE_DRIVER d = (LPWINE_DRIVER)hDrvr;
69
70 if (hDrvr && HeapValidate(GetProcessHeap(), 0, d) && d->dwMagic == WINE_DI_MAGIC) {
71 return d;
72 }
73 return NULL;
74}
75
76#ifndef __WIN32OS2__
77/**************************************************************************
78 * DRIVER_MapMsg32To16 [internal]
79 *
80 * Map a 32 bit driver message to a 16 bit driver message.
81 * 1 : ok, some memory allocated, need to call DRIVER_UnMapMsg32To16
82 * 0 : ok, no memory allocated
83 * -1 : ko, unknown message
84 * -2 : ko, memory problem
85 */
86static int DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lParam2)
87{
88 int ret = -1;
89
90 switch (wMsg) {
91 case DRV_LOAD:
92 case DRV_ENABLE:
93 case DRV_DISABLE:
94 case DRV_FREE:
95 case DRV_QUERYCONFIGURE:
96 case DRV_REMOVE:
97 case DRV_EXITSESSION:
98 case DRV_EXITAPPLICATION:
99 case DRV_POWER:
100 case DRV_CLOSE: /* should be 0/0 */
101 case DRV_OPEN: /* pass thru */
102 /* lParam1 and lParam2 are not used */
103 ret = 0;
104 break;
105 break;
106 case DRV_CONFIGURE:
107 case DRV_INSTALL:
108 /* lParam1 is a handle to a window (conf) or to a driver (inst) or not used,
109 * lParam2 is a pointer to DRVCONFIGINFO
110 */
111 if (*lParam2) {
112 LPDRVCONFIGINFO16 dci16 = (LPDRVCONFIGINFO16)SEGPTR_ALLOC(sizeof(DRVCONFIGINFO16));
113 LPDRVCONFIGINFO dci32 = (LPDRVCONFIGINFO)(*lParam2);
114
115 if (dci16) {
116 LPSTR str1, str2;
117
118 dci16->dwDCISize = sizeof(DRVCONFIGINFO16);
119
120 if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCISectionName)) != NULL &&
121 (str2 = SEGPTR_STRDUP(str1)) != NULL) {
122 dci16->lpszDCISectionName = SEGPTR_GET(str2);
123 if (!HeapFree(GetProcessHeap(), 0, str1))
124 FIXME("bad free line=%d\n", __LINE__);
125 } else {
126 return -2;
127 }
128 if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCIAliasName)) != NULL &&
129 (str2 = SEGPTR_STRDUP(str1)) != NULL) {
130 dci16->lpszDCIAliasName = SEGPTR_GET(str2);
131 if (!HeapFree(GetProcessHeap(), 0, str1))
132 FIXME("bad free line=%d\n", __LINE__);
133 } else {
134 return -2;
135 }
136 } else {
137 return -2;
138 }
139 *lParam2 = (LPARAM)SEGPTR_GET(dci16);
140 ret = 1;
141 } else {
142 ret = 0;
143 }
144 break;
145 default:
146 if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
147 FIXME("Unknown message 0x%04x\n", wMsg);
148 }
149 ret = 0;
150 }
151 return ret;
152}
153
154/**************************************************************************
155 * DRIVER_UnMapMsg32To16 [internal]
156 *
157 * UnMap a 32 bit driver message to a 16 bit driver message.
158 * 0 : ok
159 * -1 : ko
160 * -2 : ko, memory problem
161 */
162static int DRIVER_UnMapMsg32To16(WORD wMsg, DWORD lParam1, DWORD lParam2)
163{
164 int ret = -1;
165
166 switch (wMsg) {
167 case DRV_LOAD:
168 case DRV_ENABLE:
169 case DRV_DISABLE:
170 case DRV_FREE:
171 case DRV_QUERYCONFIGURE:
172 case DRV_REMOVE:
173 case DRV_EXITSESSION:
174 case DRV_EXITAPPLICATION:
175 case DRV_POWER:
176 case DRV_OPEN:
177 case DRV_CLOSE:
178 /* lParam1 and lParam2 are not used */
179 break;
180 case DRV_CONFIGURE:
181 case DRV_INSTALL:
182 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
183 if (lParam2) {
184 LPDRVCONFIGINFO16 dci16 = MapSL(lParam2);
185
186 if (!SEGPTR_FREE(MapSL(dci16->lpszDCISectionName)))
187 FIXME("bad free line=%d\n", __LINE__);
188 if (!SEGPTR_FREE(MapSL(dci16->lpszDCIAliasName)))
189 FIXME("bad free line=%d\n", __LINE__);
190 if (!SEGPTR_FREE(dci16))
191 FIXME("bad free line=%d\n", __LINE__);
192 }
193 ret = 0;
194 break;
195 default:
196 if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
197 FIXME("Unknown message 0x%04x\n", wMsg);
198 }
199 ret = 0;
200 }
201 return ret;
202}
203#endif //#ifndef __WIN32OS2__
204
205/**************************************************************************
206 * DRIVER_SendMessage [internal]
207 */
208static LRESULT inline DRIVER_SendMessage(LPWINE_DRIVER lpDrv, UINT msg,
209 LPARAM lParam1, LPARAM lParam2)
210{
211#ifndef __WIN32OS2__
212 if (lpDrv->dwFlags & WINE_GDF_16BIT) {
213 LRESULT ret;
214 int map = 0;
215 TRACE("Before sdm16 call hDrv=%04x wMsg=%04x p1=%08lx p2=%08lx\n",
216 lpDrv->d.d16.hDriver16, msg, lParam1, lParam2);
217
218 if ((map = DRIVER_MapMsg32To16(msg, &lParam1, &lParam2)) >= 0) {
219 ret = SendDriverMessage16(lpDrv->d.d16.hDriver16, msg, lParam1, lParam2);
220 if (map == 1)
221 DRIVER_UnMapMsg32To16(msg, lParam1, lParam2);
222 } else {
223 ret = 0;
224 }
225 return ret;
226 }
227#endif
228 TRACE("Before func32 call proc=%p driverID=%08lx hDrv=%08x wMsg=%04x p1=%08lx p2=%08lx\n",
229 lpDrv->d.d32.lpDrvProc, lpDrv->d.d32.dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2);
230 return lpDrv->d.d32.lpDrvProc(lpDrv->d.d32.dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2);
231}
232
233/**************************************************************************
234 * SendDriverMessage [WINMM.19]
235 */
236LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT msg, LPARAM lParam1,
237 LPARAM lParam2)
238{
239 LPWINE_DRIVER lpDrv;
240 LRESULT retval = 0;
241
242 TRACE("(%04x, %04X, %08lX, %08lX)\n", hDriver, msg, lParam1, lParam2);
243
244 if ((lpDrv = DRIVER_FindFromHDrvr(hDriver)) != NULL) {
245 retval = DRIVER_SendMessage(lpDrv, msg, lParam1, lParam2);
246 } else {
247 WARN("Bad driver handle %u\n", hDriver);
248 }
249 TRACE("retval = %ld\n", retval);
250
251 return retval;
252}
253
254/**************************************************************************
255 * DRIVER_RemoveFromList [internal]
256 *
257 * Generates all the logic to handle driver closure / deletion
258 * Removes a driver struct to the list of open drivers.
259 */
260static BOOL DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv)
261{
262 if (!(lpDrv->dwFlags & WINE_GDF_16BIT)) {
263 if (DRIVER_GetNumberOfModuleRefs(lpDrv) == 1) {
264 DRIVER_SendMessage(lpDrv, DRV_DISABLE, 0L, 0L);
265 DRIVER_SendMessage(lpDrv, DRV_FREE, 0L, 0L);
266 }
267 }
268
269 if (lpDrv->lpPrevItem)
270 lpDrv->lpPrevItem->lpNextItem = lpDrv->lpNextItem;
271 else
272 lpDrvItemList = lpDrv->lpNextItem;
273 if (lpDrv->lpNextItem)
274 lpDrv->lpNextItem->lpPrevItem = lpDrv->lpPrevItem;
275
276 return TRUE;
277}
278
279/**************************************************************************
280 * DRIVER_AddToList [internal]
281 *
282 * Adds a driver struct to the list of open drivers.
283 * Generates all the logic to handle driver creation / open.
284 */
285static BOOL DRIVER_AddToList(LPWINE_DRIVER lpNewDrv, LPARAM lParam1, LPARAM lParam2)
286{
287 lpNewDrv->dwMagic = WINE_DI_MAGIC;
288 /* First driver to be loaded for this module, need to load correctly the module */
289 if (!(lpNewDrv->dwFlags & WINE_GDF_16BIT)) {
290 if (DRIVER_GetNumberOfModuleRefs(lpNewDrv) == 0) {
291 if (DRIVER_SendMessage(lpNewDrv, DRV_LOAD, 0L, 0L) != DRV_SUCCESS) {
292 TRACE("DRV_LOAD failed on driver 0x%08lx\n", (DWORD)lpNewDrv);
293 return FALSE;
294 }
295 /* returned value is not checked */
296 DRIVER_SendMessage(lpNewDrv, DRV_ENABLE, 0L, 0L);
297 }
298 }
299
300 lpNewDrv->lpNextItem = NULL;
301 if (lpDrvItemList == NULL) {
302 lpDrvItemList = lpNewDrv;
303 lpNewDrv->lpPrevItem = NULL;
304 } else {
305 LPWINE_DRIVER lpDrv = lpDrvItemList; /* find end of list */
306 while (lpDrv->lpNextItem != NULL)
307 lpDrv = lpDrv->lpNextItem;
308
309 lpDrv->lpNextItem = lpNewDrv;
310 lpNewDrv->lpPrevItem = lpDrv;
311 }
312
313 if (!(lpNewDrv->dwFlags & WINE_GDF_16BIT)) {
314 /* Now just open a new instance of a driver on this module */
315 lpNewDrv->d.d32.dwDriverID = DRIVER_SendMessage(lpNewDrv, DRV_OPEN, lParam1, lParam2);
316
317 if (lpNewDrv->d.d32.dwDriverID == 0) {
318 TRACE("DRV_OPEN failed on driver 0x%08lx\n", (DWORD)lpNewDrv);
319 DRIVER_RemoveFromList(lpNewDrv);
320 return FALSE;
321 }
322 }
323 return TRUE;
324}
325
326/**************************************************************************
327 * DRIVER_GetLibName [internal]
328 *
329 */
330BOOL DRIVER_GetLibName(LPCSTR keyName, LPCSTR sectName, LPSTR buf, int sz)
331{
332 /* should also do some registry diving */
333 return GetPrivateProfileStringA(sectName, keyName, "", buf, sz, "SYSTEM.INI");
334}
335
336/**************************************************************************
337 * DRIVER_TryOpenDriver32 [internal]
338 *
339 * Tries to load a 32 bit driver whose DLL's (module) name is fn
340 */
341LPWINE_DRIVER DRIVER_TryOpenDriver32(LPCSTR fn, LPARAM lParam2)
342{
343 LPWINE_DRIVER lpDrv = NULL;
344 HMODULE hModule = 0;
345 LPSTR ptr;
346 LPCSTR cause = 0;
347
348 TRACE("('%s', %08lX);\n", fn, lParam2);
349
350 if ((ptr = strchr(fn, ' ')) != NULL) {
351 *ptr++ = '\0';
352 while (*ptr == ' ') ptr++;
353 if (*ptr == '\0') ptr = NULL;
354 }
355
356 lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
357 if (lpDrv == NULL) {cause = "OOM"; goto exit;}
358
359 if ((hModule = LoadLibraryA(fn)) == 0) {cause = "Not a 32 bit lib"; goto exit;}
360
361 lpDrv->d.d32.lpDrvProc = (DRIVERPROC)GetProcAddress(hModule, "DriverProc");
362 if (lpDrv->d.d32.lpDrvProc == NULL) {cause = "no DriverProc"; goto exit;}
363
364 lpDrv->dwFlags = 0;
365 lpDrv->d.d32.hModule = hModule;
366 lpDrv->d.d32.dwDriverID = 0;
367
368 if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, lParam2)) {cause = "load faile"; goto exit;}
369
370 TRACE("=> %p\n", lpDrv);
371 return lpDrv;
372 exit:
373 FreeLibrary(hModule);
374 HeapFree(GetProcessHeap(), 0, lpDrv);
375 TRACE("Unable to load 32 bit module \"%s\": %s\n", fn, cause);
376 return NULL;
377}
378#ifdef __WIN32OS2__
379/**************************************************************************
380 * DRIVER_OpenDriverA [internal]
381 * (0,1,DRV_LOAD ,0 ,0)
382 * (0,1,DRV_ENABLE,0 ,0)
383 * (0,1,DRV_OPEN ,buf[256],0)
384 *
385 */
386static LPWINE_DRIVER DRIVER_TryOpenDriver16(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam)
387{
388 LPWINE_DRIVER lpDrv = NULL;
389 char drvName[128];
390 LPCSTR cause = 0;
391
392 TRACE("Entering DRIVER_OpenDriverA: lpDriverName: %s lpSectionName: %s\n",lpDriverName,lpSectionName);
393
394 lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
395 if (lpDrv == NULL) {cause = "OOM"; goto exit;}
396
397 if (lpSectionName == NULL) {
398 lstrcpynA(drvName, lpDriverName, sizeof(drvName));
399 lpDrv = DRIVER_TryOpenDriver32(lpDriverName, lParam);
400 if (!lpDrv) {
401 if (GetPrivateProfileStringA("Drivers32", lpDriverName, "", drvName,
402 sizeof(drvName), "SYSTEM.INI")) {
403
404 lpDrv = DRIVER_TryOpenDriver32(drvName, lParam);
405 }
406 }
407 } else {/* of if (lpSectionName == NULL) */
408 //dprintf(("driver name %x '%s'\n",drvName,drvName));
409 drvName[0]=0;
410
411 if (GetPrivateProfileStringA(lpSectionName, lpDriverName, "", drvName,
412 sizeof(drvName)-1, "SYSTEM.INI")) {
413#if 0
414 dprintf(("driver name %x '%s'\n",drvName,drvName));
415#endif
416 lpDrv = DRIVER_TryOpenDriver32(drvName, lParam);
417 }/* GetPrivate... */
418 }
419 if (!lpDrv)
420 TRACE("OpenDriverA: Failed to open driver %s from section %s\n", lpDriverName, lpSectionName);
421
422 else
423 TRACE("OpenDriverA success: Driver handle => %08x\n", lpDrv);
424
425 return lpDrv;
426
427 exit:
428 HeapFree(GetProcessHeap(), 0, lpDrv);
429 TRACE("Unable to load 32 bit module \"%s\": %s\n", lpDriverName, cause);
430 return NULL;
431}
432#else
433/**************************************************************************
434 * DRIVER_TryOpenDriver16 [internal]
435 *
436 * Tries to load a 16 bit driver whose DLL's (module) name is lpFileName.
437 */
438static LPWINE_DRIVER DRIVER_TryOpenDriver16(LPCSTR fn, LPCSTR sn, LPARAM lParam2)
439{
440 LPWINE_DRIVER lpDrv = NULL;
441 LPCSTR cause = 0;
442
443 TRACE("('%s', %08lX);\n", sn, lParam2);
444
445 lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
446 if (lpDrv == NULL) {cause = "OOM"; goto exit;}
447
448 /* FIXME: shall we do some black magic here on sn ?
449 * drivers32 => drivers
450 * mci32 => mci
451 * ...
452 */
453 lpDrv->d.d16.hDriver16 = OpenDriver16(fn, sn, lParam2);
454 if (lpDrv->d.d16.hDriver16 == 0) {cause = "Not a 16 bit driver"; goto exit;}
455 lpDrv->dwFlags = WINE_GDF_16BIT;
456
457 if (!DRIVER_AddToList(lpDrv, 0, lParam2)) {cause = "load faile"; goto exit;}
458
459 TRACE("=> %p\n", lpDrv);
460 return lpDrv;
461 exit:
462 HeapFree(GetProcessHeap(), 0, lpDrv);
463 TRACE("Unable to load 32 bit module \"%s\": %s\n", fn, cause);
464 return NULL;
465}
466#endif //#ifndef __WIN32OS2__
467
468/**************************************************************************
469 * OpenDriverA [WINMM.15]
470 * (0,1,DRV_LOAD ,0 ,0)
471 * (0,1,DRV_ENABLE,0 ,0)
472 * (0,1,DRV_OPEN ,buf[256],0)
473 */
474HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam2)
475{
476 LPWINE_DRIVER lpDrv = NULL;
477 char libName[128];
478 LPCSTR lsn = lpSectionName;
479
480 TRACE("(%s, %s, 0x%08lx);\n", debugstr_a(lpDriverName), debugstr_a(lpSectionName), lParam2);
481
482 if (lsn == NULL) {
483 lstrcpynA(libName, lpDriverName, sizeof(libName));
484
485 if ((lpDrv = DRIVER_TryOpenDriver32(libName, lParam2)))
486 goto the_end;
487 lsn = "Drivers32";
488 }
489 if (DRIVER_GetLibName(lpDriverName, lsn, libName, sizeof(libName)) &&
490 (lpDrv = DRIVER_TryOpenDriver32(libName, lParam2)))
491 goto the_end;
492
493 if (!(lpDrv = DRIVER_TryOpenDriver16(lpDriverName, lpSectionName, lParam2)))
494 TRACE("Failed to open driver %s from system.ini file, section %s\n", lpDriverName, lpSectionName);
495
496 the_end:
497 if (lpDrv) TRACE("=> %08lx\n", (DWORD)lpDrv);
498 return (DWORD)lpDrv;
499}
500
501/**************************************************************************
502 * OpenDriverW [WINMM.15]
503 */
504HDRVR WINAPI OpenDriverW(LPCWSTR lpDriverName, LPCWSTR lpSectionName, LPARAM lParam)
505{
506 LPSTR dn = HEAP_strdupWtoA(GetProcessHeap(), 0, lpDriverName);
507 LPSTR sn = HEAP_strdupWtoA(GetProcessHeap(), 0, lpSectionName);
508 HDRVR ret = OpenDriverA(dn, sn, lParam);
509
510 if (dn) HeapFree(GetProcessHeap(), 0, dn);
511 if (sn) HeapFree(GetProcessHeap(), 0, sn);
512 return ret;
513}
514
515/**************************************************************************
516 * CloseDriver [WINMM.4]
517 */
518LRESULT WINAPI CloseDriver(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
519{
520 LPWINE_DRIVER lpDrv;
521
522 TRACE("(%04x, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
523
524 if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
525#ifndef __WIN32OS2__
526 if (lpDrv->dwFlags & WINE_GDF_16BIT)
527 CloseDriver16(lpDrv->d.d16.hDriver16, lParam1, lParam2);
528 else
529#endif
530 DRIVER_SendMessage(lpDrv, DRV_CLOSE, lParam1, lParam2);
531 if (DRIVER_RemoveFromList(lpDrv)) {
532 HeapFree(GetProcessHeap(), 0, lpDrv);
533 return TRUE;
534 }
535 }
536 WARN("Failed to close driver\n");
537 return FALSE;
538}
539
540/**************************************************************************
541 * GetDriverFlags [WINMM.13]
542 * [in] hDrvr handle to the driver
543 *
544 * Returns:
545 * 0x00000000 if hDrvr is an invalid handle
546 * 0x80000000 if hDrvr is a valid 32 bit driver
547 * 0x90000000 if hDrvr is a valid 16 bit driver
548 *
549 * native WINMM doesn't return those flags
550 * 0x80000000 for a valid 32 bit driver and that's it
551 * (I may have mixed up the two flags :-(
552 */
553DWORD WINAPI GetDriverFlags(HDRVR hDrvr)
554{
555 LPWINE_DRIVER lpDrv;
556 DWORD ret = 0;
557
558 TRACE("(%04x)\n", hDrvr);
559
560 if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
561 ret = WINE_GDF_EXIST | lpDrv->dwFlags;
562 }
563 return ret;
564}
565
566/**************************************************************************
567 * GetDriverModuleHandle [WINMM.14]
568 */
569HMODULE WINAPI GetDriverModuleHandle(HDRVR hDrvr)
570{
571 LPWINE_DRIVER lpDrv;
572 HMODULE hModule = 0;
573
574 TRACE("(%04x);\n", hDrvr);
575
576 if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
577 if (!(lpDrv->dwFlags & WINE_GDF_16BIT))
578 hModule = lpDrv->d.d32.hModule;
579 }
580 TRACE("=> %04x\n", hModule);
581 return hModule;
582}
583
584#ifndef __WIN32OS2__
585/**************************************************************************
586 * DrvOpen [MMSYSTEM.1100]
587 */
588HDRVR16 WINAPI DrvOpen16(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
589{
590 return OpenDriver16(lpDriverName, lpSectionName, lParam);
591}
592
593/**************************************************************************
594 * DrvClose [MMSYSTEM.1101]
595 */
596LRESULT WINAPI DrvClose16(HDRVR16 hDrv, LPARAM lParam1, LPARAM lParam2)
597{
598 return CloseDriver16(hDrv, lParam1, lParam2);
599}
600
601/**************************************************************************
602 * DrvSendMessage [MMSYSTEM.1102]
603 */
604LRESULT WINAPI DrvSendMessage16(HDRVR16 hDrv, WORD msg, LPARAM lParam1,
605 LPARAM lParam2)
606{
607 return SendDriverMessage16(hDrv, msg, lParam1, lParam2);
608}
609
610/**************************************************************************
611 * DrvGetModuleHandle [MMSYSTEM.1103]
612 */
613HANDLE16 WINAPI DrvGetModuleHandle16(HDRVR16 hDrv)
614{
615 return GetDriverModuleHandle16(hDrv);
616}
617
618/**************************************************************************
619 * DrvDefDriverProc [MMSYSTEM.1104]
620 */
621LRESULT WINAPI DrvDefDriverProc16(DWORD dwDriverID, HDRVR16 hDrv, WORD wMsg,
622 DWORD dwParam1, DWORD dwParam2)
623{
624 return DefDriverProc16(dwDriverID, hDrv, wMsg, dwParam1, dwParam2);
625}
626#endif //#ifndef __WIN32OS2__
627
628/**************************************************************************
629 * DefDriverProc [WINMM.5]
630 */
631LRESULT WINAPI DefDriverProc(DWORD dwDriverIdentifier, HDRVR hDrv,
632 UINT Msg, LPARAM lParam1, LPARAM lParam2)
633{
634 switch (Msg) {
635 case DRV_LOAD:
636 case DRV_FREE:
637 case DRV_ENABLE:
638 case DRV_DISABLE:
639 return 1;
640 case DRV_INSTALL:
641 case DRV_REMOVE:
642 return DRV_SUCCESS;
643 default:
644 return 0;
645 }
646}
647
648#ifndef __WIN32OS2__
649/**************************************************************************
650 * DriverProc [MMSYSTEM.6]
651 */
652LRESULT WINAPI DriverProc16(DWORD dwDevID, HDRVR16 hDrv, WORD wMsg,
653 DWORD dwParam1, DWORD dwParam2)
654{
655 TRACE("dwDevID=%08lx hDrv=%04x wMsg=%04x dwParam1=%08lx dwParam2=%08lx\n",
656 dwDevID, hDrv, wMsg, dwParam1, dwParam2);
657
658 return DrvDefDriverProc16(dwDevID, hDrv, wMsg, dwParam1, dwParam2);
659}
660#endif //#ifndef __WIN32OS2__
661
662#ifdef __WIN32OS2__
663/**************************************************************************
664 * DriverCallback [MMSYSTEM.31]
665 */
666BOOL WINAPI DriverCallback(DWORD dwCallBack, UINT uFlags, HDRVR hDev,
667 UINT wMsg, DWORD dwUser, DWORD dwParam1,
668 DWORD dwParam2)
669{
670 TRACE("DriverCallback (%08lX, %04X, %04X, %04X, %08lX, %08lX, %08lX); !\n",
671 dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2);
672
673 switch (uFlags & DCB_TYPEMASK) {
674 case DCB_NULL:
675 TRACE("Null !\n");
676 if (dwCallBack)
677 WARN("uFlags=%04X has null DCB value, but dwCallBack=%08lX is not null !\n", uFlags, dwCallBack);
678 break;
679 case DCB_WINDOW:
680 TRACE("Window(%04lX) handle=%04X!\n", dwCallBack, hDev);
681 if (!IsWindow(dwCallBack))
682 return FALSE;
683 PostMessageA((HWND)dwCallBack, wMsg, hDev, dwParam1);
684 break;
685 case DCB_TASK: /* aka DCB_THREAD */
686 TRACE("Task(%04lx) !\n", dwCallBack);
687 PostThreadMessageA(dwCallBack, wMsg, hDev, dwParam1);
688 break;
689 case DCB_FUNCTION:
690 TRACE("Function (32 bit) !\n");
691 ((LPDRVCALLBACK)dwCallBack)(hDev, wMsg, dwUser, dwParam1, dwParam2);
692 break;
693 case DCB_EVENT:
694 TRACE("Event(%08lx) !\n", dwCallBack);
695 SetEvent((HANDLE)dwCallBack);
696 break;
697 case 6: /* I would dub it DCB_MMTHREADSIGNAL */
698 /* this is an undocumented DCB_ value used for mmThreads
699 * loword of dwCallBack contains the handle of the lpMMThd block
700 * which dwSignalCount has to be incremented
701 */
702 {
703#ifdef __WIN32OS2__
704 WINE_MMTHREAD* lpMMThd = (WINE_MMTHREAD*)dwCallBack;
705#else
706 WINE_MMTHREAD* lpMMThd = MapSL( MAKESEGPTR(LOWORD(dwCallBack), 0) );
707#endif
708
709 TRACE("mmThread (%04x, %p) !\n", LOWORD(dwCallBack), lpMMThd);
710 /* same as mmThreadSignal16 */
711 InterlockedIncrement(&lpMMThd->dwSignalCount);
712 SetEvent(lpMMThd->hEvent);
713 /* some other stuff on lpMMThd->hVxD */
714 }
715 break;
716#if 0
717 case 4:
718 /* this is an undocumented DCB_ value for... I don't know */
719 break;
720#endif
721 default:
722 WARN("Unknown callback type %d\n", uFlags & DCB_TYPEMASK);
723 return FALSE;
724 }
725 TRACE("Done\n");
726 return TRUE;
727}
728#endif
Note: See TracBrowser for help on using the repository browser.