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

Last change on this file since 6639 was 6639, checked in by bird, 24 years ago

Added Missing $Id:$ keyword.

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