source: trunk/src/winmm/driver.c

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

restored old version

File size: 21.0 KB
RevLine 
[5433]1/* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
[6712]3/*
[5433]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
[6712]34static LPWINE_DRIVER lpDrvItemList = NULL;
[5433]35
36/* TODO list :
[6712]37 * - LoadModule count and clean up is not handled correctly (it's not a
38 * problem as long as FreeLibrary is not working correctly)
[5433]39 */
40
41/**************************************************************************
[6712]42 * DRIVER_GetNumberOfModuleRefs [internal]
[5433]43 *
44 * Returns the number of open drivers which share the same module.
45 */
[6712]46static WORD DRIVER_GetNumberOfModuleRefs(LPWINE_DRIVER lpNewDrv)
[5433]47{
[6712]48 LPWINE_DRIVER lpDrv;
49 WORD count = 0;
[5433]50
51 if (lpNewDrv->dwFlags & WINE_GDF_16BIT) ERR("OOOch");
52 for (lpDrv = lpDrvItemList; lpDrv; lpDrv = lpDrv->lpNextItem) {
[6712]53 if (!(lpDrv->dwFlags & WINE_GDF_16BIT) &&
54 lpDrv->d.d32.hModule == lpNewDrv->d.d32.hModule) {
55 count++;
56 }
[5433]57 }
58 return count;
59}
60
61/**************************************************************************
[6712]62 * DRIVER_FindFromHDrvr [internal]
63 *
[5433]64 * From a hDrvr being 32 bits, returns the WINE internal structure.
65 */
[6712]66LPWINE_DRIVER DRIVER_FindFromHDrvr(HDRVR hDrvr)
67{
68 LPWINE_DRIVER d = (LPWINE_DRIVER)hDrvr;
[5433]69
70 if (hDrvr && HeapValidate(GetProcessHeap(), 0, d) && d->dwMagic == WINE_DI_MAGIC) {
[6712]71 return d;
[5433]72 }
73 return NULL;
74}
75
76#ifndef __WIN32OS2__
77/**************************************************************************
[6712]78 * DRIVER_MapMsg32To16 [internal]
[5433]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{
[6712]88 int ret = -1;
89
[5433]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:
[6712]98 case DRV_EXITAPPLICATION:
[5433]99 case DRV_POWER:
[6712]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;
[5433]106 case DRV_CONFIGURE:
107 case DRV_INSTALL:
[6712]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;
[5433]145 default:
[6712]146 if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
147 FIXME("Unknown message 0x%04x\n", wMsg);
148 }
149 ret = 0;
[5433]150 }
151 return ret;
152}
153
154/**************************************************************************
[6712]155 * DRIVER_UnMapMsg32To16 [internal]
[5433]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{
[6712]164 int ret = -1;
165
[5433]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:
[6712]178 /* lParam1 and lParam2 are not used */
179 break;
180 case DRV_CONFIGURE:
[5433]181 case DRV_INSTALL:
[6712]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;
[5433]195 default:
[6712]196 if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
197 FIXME("Unknown message 0x%04x\n", wMsg);
198 }
199 ret = 0;
[5433]200 }
201 return ret;
202}
203#endif //#ifndef __WIN32OS2__
204
205/**************************************************************************
[6712]206 * DRIVER_SendMessage [internal]
[5433]207 */
[6712]208static LRESULT inline DRIVER_SendMessage(LPWINE_DRIVER lpDrv, UINT msg,
209 LPARAM lParam1, LPARAM lParam2)
[5433]210{
211#ifndef __WIN32OS2__
212 if (lpDrv->dwFlags & WINE_GDF_16BIT) {
[6712]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);
[5433]217
[6712]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;
[5433]226 }
227#endif
[6712]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);
[5433]230 return lpDrv->d.d32.lpDrvProc(lpDrv->d.d32.dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2);
231}
232
233/**************************************************************************
[6712]234 * SendDriverMessage [WINMM.19]
[5433]235 */
236LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT msg, LPARAM lParam1,
[6712]237 LPARAM lParam2)
[5433]238{
[6712]239 LPWINE_DRIVER lpDrv;
240 LRESULT retval = 0;
241
[5433]242 TRACE("(%04x, %04X, %08lX, %08lX)\n", hDriver, msg, lParam1, lParam2);
[6712]243
[5433]244 if ((lpDrv = DRIVER_FindFromHDrvr(hDriver)) != NULL) {
[6712]245 retval = DRIVER_SendMessage(lpDrv, msg, lParam1, lParam2);
[5433]246 } else {
[6712]247 WARN("Bad driver handle %u\n", hDriver);
[5433]248 }
249 TRACE("retval = %ld\n", retval);
[6712]250
[5433]251 return retval;
252}
253
254/**************************************************************************
[6712]255 * DRIVER_RemoveFromList [internal]
[5433]256 *
257 * Generates all the logic to handle driver closure / deletion
258 * Removes a driver struct to the list of open drivers.
259 */
[6712]260static BOOL DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv)
[5433]261{
262 if (!(lpDrv->dwFlags & WINE_GDF_16BIT)) {
[6712]263 if (DRIVER_GetNumberOfModuleRefs(lpDrv) == 1) {
264 DRIVER_SendMessage(lpDrv, DRV_DISABLE, 0L, 0L);
265 DRIVER_SendMessage(lpDrv, DRV_FREE, 0L, 0L);
266 }
[5433]267 }
[6712]268
[5433]269 if (lpDrv->lpPrevItem)
[6712]270 lpDrv->lpPrevItem->lpNextItem = lpDrv->lpNextItem;
[5433]271 else
[6712]272 lpDrvItemList = lpDrv->lpNextItem;
[5433]273 if (lpDrv->lpNextItem)
[6712]274 lpDrv->lpNextItem->lpPrevItem = lpDrv->lpPrevItem;
[5433]275
276 return TRUE;
277}
278
279/**************************************************************************
[6712]280 * DRIVER_AddToList [internal]
[5433]281 *
282 * Adds a driver struct to the list of open drivers.
283 * Generates all the logic to handle driver creation / open.
284 */
[6712]285static BOOL DRIVER_AddToList(LPWINE_DRIVER lpNewDrv, LPARAM lParam1, LPARAM lParam2)
[5433]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)) {
[6712]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 }
[5433]298 }
299
300 lpNewDrv->lpNextItem = NULL;
301 if (lpDrvItemList == NULL) {
[6712]302 lpDrvItemList = lpNewDrv;
303 lpNewDrv->lpPrevItem = NULL;
[5433]304 } else {
[6712]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;
[5433]311 }
312
313 if (!(lpNewDrv->dwFlags & WINE_GDF_16BIT)) {
[6712]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);
[5433]316
[6712]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 }
[5433]322 }
323 return TRUE;
324}
325
326/**************************************************************************
[6712]327 * DRIVER_GetLibName [internal]
[5433]328 *
329 */
[6712]330BOOL DRIVER_GetLibName(LPCSTR keyName, LPCSTR sectName, LPSTR buf, int sz)
[5433]331{
332 /* should also do some registry diving */
333 return GetPrivateProfileStringA(sectName, keyName, "", buf, sz, "SYSTEM.INI");
334}
335
336/**************************************************************************
[6712]337 * DRIVER_TryOpenDriver32 [internal]
[5433]338 *
339 * Tries to load a 32 bit driver whose DLL's (module) name is fn
340 */
[6712]341LPWINE_DRIVER DRIVER_TryOpenDriver32(LPCSTR fn, LPARAM lParam2)
[5433]342{
[6712]343 LPWINE_DRIVER lpDrv = NULL;
344 HMODULE hModule = 0;
345 LPSTR ptr;
346 LPCSTR cause = 0;
[5433]347
348 TRACE("('%s', %08lX);\n", fn, lParam2);
[6712]349
[5433]350 if ((ptr = strchr(fn, ' ')) != NULL) {
[6712]351 *ptr++ = '\0';
352 while (*ptr == ' ') ptr++;
353 if (*ptr == '\0') ptr = NULL;
[5433]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/**************************************************************************
[6712]380 * DRIVER_OpenDriverA [internal]
[5433]381 * (0,1,DRV_LOAD ,0 ,0)
382 * (0,1,DRV_ENABLE,0 ,0)
383 * (0,1,DRV_OPEN ,buf[256],0)
384 *
385 */
[6712]386static LPWINE_DRIVER DRIVER_TryOpenDriver16(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam)
[5433]387{
388 LPWINE_DRIVER lpDrv = NULL;
[6712]389 char drvName[128];
[5433]390 LPCSTR cause = 0;
[6712]391
[5433]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) {
[6712]398 lstrcpynA(drvName, lpDriverName, sizeof(drvName));
399 lpDrv = DRIVER_TryOpenDriver32(lpDriverName, lParam);
400 if (!lpDrv) {
[5433]401 if (GetPrivateProfileStringA("Drivers32", lpDriverName, "", drvName,
402 sizeof(drvName), "SYSTEM.INI")) {
403
[6712]404 lpDrv = DRIVER_TryOpenDriver32(drvName, lParam);
[5433]405 }
[6712]406 }
[5433]407 } else {/* of if (lpSectionName == NULL) */
408 //dprintf(("driver name %x '%s'\n",drvName,drvName));
[6712]409 drvName[0]=0;
[5433]410
[6712]411 if (GetPrivateProfileStringA(lpSectionName, lpDriverName, "", drvName,
[5433]412 sizeof(drvName)-1, "SYSTEM.INI")) {
413#if 0
414 dprintf(("driver name %x '%s'\n",drvName,drvName));
[6712]415#endif
[5433]416 lpDrv = DRIVER_TryOpenDriver32(drvName, lParam);
[6712]417 }/* GetPrivate... */
[5433]418 }
419 if (!lpDrv)
[6712]420 TRACE("OpenDriverA: Failed to open driver %s from section %s\n", lpDriverName, lpSectionName);
[5433]421
[6712]422 else
423 TRACE("OpenDriverA success: Driver handle => %08x\n", lpDrv);
[5433]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/**************************************************************************
[6712]434 * DRIVER_TryOpenDriver16 [internal]
[5433]435 *
436 * Tries to load a 16 bit driver whose DLL's (module) name is lpFileName.
437 */
[6712]438static LPWINE_DRIVER DRIVER_TryOpenDriver16(LPCSTR fn, LPCSTR sn, LPARAM lParam2)
[5433]439{
[6712]440 LPWINE_DRIVER lpDrv = NULL;
441 LPCSTR cause = 0;
[5433]442
443 TRACE("('%s', %08lX);\n", sn, lParam2);
[6712]444
[5433]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 ?
[6712]449 * drivers32 => drivers
450 * mci32 => mci
[5433]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/**************************************************************************
[6712]469 * OpenDriverA [WINMM.15]
[5433]470 * (0,1,DRV_LOAD ,0 ,0)
471 * (0,1,DRV_ENABLE,0 ,0)
472 * (0,1,DRV_OPEN ,buf[256],0)
473 */
[6712]474HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam2)
[5433]475{
[6712]476 LPWINE_DRIVER lpDrv = NULL;
477 char libName[128];
478 LPCSTR lsn = lpSectionName;
[5433]479
480 TRACE("(%s, %s, 0x%08lx);\n", debugstr_a(lpDriverName), debugstr_a(lpSectionName), lParam2);
[6712]481
[5433]482 if (lsn == NULL) {
[6712]483 lstrcpynA(libName, lpDriverName, sizeof(libName));
[5433]484
[6712]485 if ((lpDrv = DRIVER_TryOpenDriver32(libName, lParam2)))
486 goto the_end;
487 lsn = "Drivers32";
[5433]488 }
489 if (DRIVER_GetLibName(lpDriverName, lsn, libName, sizeof(libName)) &&
[6712]490 (lpDrv = DRIVER_TryOpenDriver32(libName, lParam2)))
491 goto the_end;
[5433]492
493 if (!(lpDrv = DRIVER_TryOpenDriver16(lpDriverName, lpSectionName, lParam2)))
[6712]494 TRACE("Failed to open driver %s from system.ini file, section %s\n", lpDriverName, lpSectionName);
[5433]495
496 the_end:
[6712]497 if (lpDrv) TRACE("=> %08lx\n", (DWORD)lpDrv);
[5433]498 return (DWORD)lpDrv;
499}
500
501/**************************************************************************
[6712]502 * OpenDriverW [WINMM.15]
[5433]503 */
504HDRVR WINAPI OpenDriverW(LPCWSTR lpDriverName, LPCWSTR lpSectionName, LPARAM lParam)
505{
[6712]506 LPSTR dn = HEAP_strdupWtoA(GetProcessHeap(), 0, lpDriverName);
507 LPSTR sn = HEAP_strdupWtoA(GetProcessHeap(), 0, lpSectionName);
508 HDRVR ret = OpenDriverA(dn, sn, lParam);
509
[5433]510 if (dn) HeapFree(GetProcessHeap(), 0, dn);
511 if (sn) HeapFree(GetProcessHeap(), 0, sn);
512 return ret;
513}
514
515/**************************************************************************
[6712]516 * CloseDriver [WINMM.4]
[5433]517 */
518LRESULT WINAPI CloseDriver(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
519{
[6712]520 LPWINE_DRIVER lpDrv;
[5433]521
522 TRACE("(%04x, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
[6712]523
[5433]524 if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
525#ifndef __WIN32OS2__
[6712]526 if (lpDrv->dwFlags & WINE_GDF_16BIT)
527 CloseDriver16(lpDrv->d.d16.hDriver16, lParam1, lParam2);
528 else
[5433]529#endif
[6712]530 DRIVER_SendMessage(lpDrv, DRV_CLOSE, lParam1, lParam2);
531 if (DRIVER_RemoveFromList(lpDrv)) {
532 HeapFree(GetProcessHeap(), 0, lpDrv);
533 return TRUE;
534 }
[5433]535 }
536 WARN("Failed to close driver\n");
537 return FALSE;
538}
539
540/**************************************************************************
[6712]541 * GetDriverFlags [WINMM.13]
[5433]542 * [in] hDrvr handle to the driver
543 *
544 * Returns:
[6712]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
[5433]548 *
549 * native WINMM doesn't return those flags
[6712]550 * 0x80000000 for a valid 32 bit driver and that's it
551 * (I may have mixed up the two flags :-(
[5433]552 */
[6712]553DWORD WINAPI GetDriverFlags(HDRVR hDrvr)
[5433]554{
[6712]555 LPWINE_DRIVER lpDrv;
556 DWORD ret = 0;
[5433]557
558 TRACE("(%04x)\n", hDrvr);
559
560 if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
[6712]561 ret = WINE_GDF_EXIST | lpDrv->dwFlags;
[5433]562 }
563 return ret;
564}
565
566/**************************************************************************
[6712]567 * GetDriverModuleHandle [WINMM.14]
[5433]568 */
569HMODULE WINAPI GetDriverModuleHandle(HDRVR hDrvr)
570{
[6712]571 LPWINE_DRIVER lpDrv;
572 HMODULE hModule = 0;
573
[5433]574 TRACE("(%04x);\n", hDrvr);
[6712]575
[5433]576 if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
[6712]577 if (!(lpDrv->dwFlags & WINE_GDF_16BIT))
578 hModule = lpDrv->d.d32.hModule;
[5433]579 }
580 TRACE("=> %04x\n", hModule);
581 return hModule;
582}
583
584#ifndef __WIN32OS2__
585/**************************************************************************
[6712]586 * DrvOpen [MMSYSTEM.1100]
[5433]587 */
588HDRVR16 WINAPI DrvOpen16(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
589{
590 return OpenDriver16(lpDriverName, lpSectionName, lParam);
591}
592
593/**************************************************************************
[6712]594 * DrvClose [MMSYSTEM.1101]
[5433]595 */
596LRESULT WINAPI DrvClose16(HDRVR16 hDrv, LPARAM lParam1, LPARAM lParam2)
597{
598 return CloseDriver16(hDrv, lParam1, lParam2);
599}
600
601/**************************************************************************
[6712]602 * DrvSendMessage [MMSYSTEM.1102]
[5433]603 */
604LRESULT WINAPI DrvSendMessage16(HDRVR16 hDrv, WORD msg, LPARAM lParam1,
[6712]605 LPARAM lParam2)
[5433]606{
607 return SendDriverMessage16(hDrv, msg, lParam1, lParam2);
608}
609
610/**************************************************************************
[6712]611 * DrvGetModuleHandle [MMSYSTEM.1103]
[5433]612 */
613HANDLE16 WINAPI DrvGetModuleHandle16(HDRVR16 hDrv)
614{
615 return GetDriverModuleHandle16(hDrv);
616}
617
618/**************************************************************************
[6712]619 * DrvDefDriverProc [MMSYSTEM.1104]
[5433]620 */
[6712]621LRESULT WINAPI DrvDefDriverProc16(DWORD dwDriverID, HDRVR16 hDrv, WORD wMsg,
622 DWORD dwParam1, DWORD dwParam2)
[5433]623{
624 return DefDriverProc16(dwDriverID, hDrv, wMsg, dwParam1, dwParam2);
625}
626#endif //#ifndef __WIN32OS2__
627
628/**************************************************************************
[6712]629 * DefDriverProc [WINMM.5]
[5433]630 */
631LRESULT WINAPI DefDriverProc(DWORD dwDriverIdentifier, HDRVR hDrv,
[6712]632 UINT Msg, LPARAM lParam1, LPARAM lParam2)
[5433]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/**************************************************************************
[6712]650 * DriverProc [MMSYSTEM.6]
[5433]651 */
[6712]652LRESULT WINAPI DriverProc16(DWORD dwDevID, HDRVR16 hDrv, WORD wMsg,
653 DWORD dwParam1, DWORD dwParam2)
[5433]654{
655 TRACE("dwDevID=%08lx hDrv=%04x wMsg=%04x dwParam1=%08lx dwParam2=%08lx\n",
[6712]656 dwDevID, hDrv, wMsg, dwParam1, dwParam2);
[5433]657
658 return DrvDefDriverProc16(dwDevID, hDrv, wMsg, dwParam1, dwParam2);
659}
660#endif //#ifndef __WIN32OS2__
661
662#ifdef __WIN32OS2__
663/**************************************************************************
[6712]664 * DriverCallback [MMSYSTEM.31]
[5433]665 */
[6712]666BOOL WINAPI DriverCallback(DWORD dwCallBack, UINT uFlags, HDRVR hDev,
667 UINT wMsg, DWORD dwUser, DWORD dwParam1,
668 DWORD dwParam2)
[5433]669{
670 TRACE("DriverCallback (%08lX, %04X, %04X, %04X, %08lX, %08lX, %08lX); !\n",
[6712]671 dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2);
[5433]672
673 switch (uFlags & DCB_TYPEMASK) {
674 case DCB_NULL:
[6712]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;
[5433]679 case DCB_WINDOW:
[6712]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;
[5433]685 case DCB_TASK: /* aka DCB_THREAD */
[6712]686 TRACE("Task(%04lx) !\n", dwCallBack);
687 PostThreadMessageA(dwCallBack, wMsg, hDev, dwParam1);
688 break;
[5433]689 case DCB_FUNCTION:
[6712]690 TRACE("Function (32 bit) !\n");
691 ((LPDRVCALLBACK)dwCallBack)(hDev, wMsg, dwUser, dwParam1, dwParam2);
692 break;
[5433]693 case DCB_EVENT:
[6712]694 TRACE("Event(%08lx) !\n", dwCallBack);
695 SetEvent((HANDLE)dwCallBack);
696 break;
[5433]697 case 6: /* I would dub it DCB_MMTHREADSIGNAL */
[6712]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 {
[5433]703#ifdef __WIN32OS2__
[6712]704 WINE_MMTHREAD* lpMMThd = (WINE_MMTHREAD*)dwCallBack;
[5433]705#else
[6712]706 WINE_MMTHREAD* lpMMThd = MapSL( MAKESEGPTR(LOWORD(dwCallBack), 0) );
[5433]707#endif
708
[6712]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;
[5433]716#if 0
717 case 4:
[6712]718 /* this is an undocumented DCB_ value for... I don't know */
719 break;
[5433]720#endif
721 default:
[6712]722 WARN("Unknown callback type %d\n", uFlags & DCB_TYPEMASK);
723 return FALSE;
[5433]724 }
725 TRACE("Done\n");
726 return TRUE;
727}
728#endif
Note: See TracBrowser for help on using the repository browser.