1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * WINE Drivers functions
6 * Copyright 1994 Martin Ayotte
7 * Copyright 1998 Marcus Meissner
8 * Copyright 1999 Eric Pouech
20 #include "debugtools.h"
22 DEFAULT_DEBUG_CHANNEL(driver
)
24 /* The following definitions are WINE internals */
25 /* FIXME: This is a WINE internal struct and should be moved in include/wine directory
26 * Please note that WINE shares 16 and 32 bit drivers on a single list...
27 * Basically, we maintain an external double view on drivers, so that a 16 bit drivers
28 * can be loaded/used... by 32 functions transparently
31 /* Who said goofy boy ? */
32 #define WINE_DI_MAGIC 0x900F1B01
34 typedef struct tagWINE_DRIVER
37 char szAliasName
[128];
38 /* as usual LPWINE_DRIVER == hDriver32 */
43 DRIVERPROC16 lpDrvProc
;
52 struct tagWINE_DRIVER
* lpPrevItem
;
53 struct tagWINE_DRIVER
* lpNextItem
;
54 } WINE_DRIVER
, *LPWINE_DRIVER
;
56 LPWINE_DRIVER
DRIVER_RegisterDriver16(LPCSTR
, HMODULE16
, DRIVERPROC16
, LPARAM
, BOOL
);
57 LPWINE_DRIVER
DRIVER_RegisterDriver32(LPCSTR
, HMODULE
, DRIVERPROC
, LPARAM
, BOOL
);
59 static LPWINE_DRIVER lpDrvItemList
= NULL
;
62 * - LoadModule count and clean up is not handled correctly (it's not a
63 * problem as long as FreeLibrary is not working correctly)
64 * - shoudln't the allocations be done on a per process basis ?
65 * - split 16/32 bit functions between DLLs as windows do (16 bit in USER, 32 bit in WINMM)
68 /* ### start build ### */
69 extern LONG CALLBACK
DRIVER_CallTo16_long_lwwll(FARPROC16
,LONG
,WORD
,WORD
,LONG
,LONG
);
70 /* ### stop build ### */
72 /**************************************************************************
73 * LoadStartupDrivers [internal]
75 static void WINE_UNUSED
DRIVER_LoadStartupDrivers(void)
79 if (GetPrivateProfileStringA("drivers", NULL
, "", str
, sizeof(str
), "SYSTEM.INI") < 2) {
80 ERR("Can't find drivers section in system.ini\n");
85 for (ptr
= str
; lstrlenA(ptr
) != 0; ptr
+= lstrlenA(ptr
) + 1) {
86 TRACE("str='%s'\n", ptr
);
87 hDrv
= OpenDriver16(ptr
, "drivers", 0L);
88 TRACE("hDrv=%04x\n", hDrv
);
90 TRACE("end of list !\n");
94 /**************************************************************************
95 * DRIVER_GetNumberOfModuleRefs [internal]
97 * Returns the number of open drivers which share the same module.
99 static WORD
DRIVER_GetNumberOfModuleRefs(LPWINE_DRIVER lpNewDrv
)
104 for (lpDrv
= lpDrvItemList
; lpDrv
; lpDrv
= lpDrv
->lpNextItem
) {
105 if (lpDrv
->dwFlags
& WINE_GDF_16BIT
) {
106 if (lpDrv
->d
.d16
.hModule
== lpNewDrv
->d
.d16
.hModule
) {
110 if (lpDrv
->d
.d32
.hModule
== lpNewDrv
->d
.d32
.hModule
) {
118 /**************************************************************************
119 * DRIVER_FindFromHDrvr16 [internal]
121 * From a hDrvr being 16 bits, returns the WINE internal structure.
123 static LPWINE_DRIVER
DRIVER_FindFromHDrvr16(HDRVR16 hDrvr
)
127 for (lpDrv
= lpDrvItemList
; lpDrv
; lpDrv
= lpDrv
->lpNextItem
) {
128 if (lpDrv
->hDriver16
== hDrvr
) {
135 /**************************************************************************
136 * DRIVER_FindFromHDrvr [internal]
138 * From a hDrvr (being 16 or 32 bits), returns the WINE internal structure.
140 static LPWINE_DRIVER
DRIVER_FindFromHDrvr(HDRVR hDrvr
)
142 if (!IsBadWritePtr((void*)hDrvr
, sizeof(WINE_DRIVER
)) &&
143 ((LPWINE_DRIVER
)hDrvr
)->dwMagic
== WINE_DI_MAGIC
) {
144 return (LPWINE_DRIVER
)hDrvr
;
146 return DRIVER_FindFromHDrvr16(hDrvr
);
149 /**************************************************************************
150 * DRIVER_MapMsg16To32 [internal]
152 * Map a 16 bit driver message to a 32 bit driver message.
153 * 1 : ok, some memory allocated, need to call DRIVER_UnMapMsg16To32
154 * 0 : ok, no memory allocated
155 * -1 : ko, unknown message
156 * -2 : ko, memory problem
158 static int DRIVER_MapMsg16To32(WORD wMsg
, DWORD
* lParam1
, DWORD
* lParam2
)
167 case DRV_QUERYCONFIGURE
:
169 case DRV_EXITSESSION
:
170 case DRV_EXITAPPLICATION
:
172 /* lParam1 and lParam2 are not used */
177 /* lParam1 is a NULL terminated string */
178 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
180 *lParam1
= (DWORD
)PTR_SEG_TO_LIN(*lParam1
);
181 if (*lParam2
&& wMsg
== DRV_OPEN
) {
182 LPMCI_OPEN_DRIVER_PARMS16 modp16
= PTR_SEG_TO_LIN(*lParam2
);
183 char* ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPMCI_OPEN_DRIVER_PARMS16
) + sizeof(MCI_OPEN_DRIVER_PARMSA
));
184 LPMCI_OPEN_DRIVER_PARMSA modp32
;
187 *(LPMCI_OPEN_DRIVER_PARMS16
*)ptr
= modp16
;
188 modp32
= (LPMCI_OPEN_DRIVER_PARMSA
)(ptr
+ sizeof(LPMCI_OPEN_DRIVER_PARMSA
));
190 modp32
->wDeviceID
= modp16
->wDeviceID
;
191 modp32
->lpstrParams
= PTR_SEG_TO_LIN(modp16
->lpstrParams
);
195 *lParam2
= (DWORD
)modp32
;
201 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO */
203 LPDRVCONFIGINFO dci32
= HeapAlloc(GetProcessHeap(), 0, sizeof(DRVCONFIGINFO
));
204 LPDRVCONFIGINFO16 dci16
= PTR_SEG_TO_LIN(*lParam2
);
207 dci32
->dwDCISize
= sizeof(DRVCONFIGINFO
);
208 dci32
->lpszDCISectionName
= HEAP_strdupAtoW(GetProcessHeap(), 0, PTR_SEG_TO_LIN(dci16
->lpszDCISectionName
));
209 dci32
->lpszDCIAliasName
= HEAP_strdupAtoW(GetProcessHeap(), 0, PTR_SEG_TO_LIN(dci16
->lpszDCIAliasName
));
210 if (dci32
->lpszDCISectionName
== NULL
|| dci32
->lpszDCIAliasName
== NULL
)
215 *lParam2
= (DWORD
)dci32
;
222 if (wMsg
>= 0x800 && wMsg
< 0x900) {
223 /* FIXME: another hack to handle MCI messages...
224 * should find a *NICE* way to integrate DRIVER_ and
225 * MCI_ mapping/unmapping functions
229 FIXME("Unknown message 0x%04x\n", wMsg
);
235 /**************************************************************************
236 * DRIVER_MapMsg16To32 [internal]
238 * UnMap a 16 bit driver message to a 32 bit driver message.
241 * -2 : ko, memory problem
243 static int DRIVER_UnMapMsg16To32(WORD wMsg
, DWORD lParam1
, DWORD lParam2
)
252 case DRV_QUERYCONFIGURE
:
254 case DRV_EXITSESSION
:
255 case DRV_EXITAPPLICATION
:
257 /* lParam1 and lParam2 are not used */
260 /* lParam1 is a NULL terminated string */
261 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
262 if (lParam2
&& wMsg
== DRV_OPEN
) {
263 LPMCI_OPEN_DRIVER_PARMSA modp32
= (LPMCI_OPEN_DRIVER_PARMSA
)lParam2
;
264 LPMCI_OPEN_DRIVER_PARMS16 modp16
= *(LPMCI_OPEN_DRIVER_PARMS16
*)(lParam2
- sizeof(LPMCI_OPEN_DRIVER_PARMSA
));
266 modp16
->wCustomCommandTable
= modp32
->wCustomCommandTable
;
267 modp16
->wType
= modp32
->wType
;
268 if (!HeapFree(GetProcessHeap(), 0, modp32
))
269 FIXME("bad free line=%d\n", __LINE__
);
275 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
277 LPDRVCONFIGINFO dci32
= (LPDRVCONFIGINFO
)lParam2
;
278 if (!HeapFree(GetProcessHeap(), 0, (LPVOID
)dci32
->lpszDCISectionName
))
279 FIXME("bad free line=%d\n", __LINE__
);
280 if (!HeapFree(GetProcessHeap(), 0, (LPVOID
)dci32
->lpszDCIAliasName
))
281 FIXME("bad free line=%d\n", __LINE__
);
282 if (!HeapFree(GetProcessHeap(), 0, dci32
))
283 FIXME("bad free line=%d\n", __LINE__
);
288 if (wMsg
>= 0x800 && wMsg
< 0x900) {
289 /* FIXME: another hack to handle MCI messages...
290 * should find a *NICE* way to integrate DRIVER_ and
291 * MCI_ mapping/unmapping functions
295 FIXME("Unknown message 0x%04x\n", wMsg
);
301 /**************************************************************************
302 * DRIVER_MapMsg32To16 [internal]
304 * Map a 32 bit driver message to a 16 bit driver message.
305 * 1 : ok, some memory allocated, need to call DRIVER_UnMapMsg32To16
306 * 0 : ok, no memory allocated
307 * -1 : ko, unknown message
308 * -2 : ko, memory problem
310 static int DRIVER_MapMsg32To16(WORD wMsg
, DWORD
* lParam1
, DWORD
* lParam2
)
319 case DRV_QUERYCONFIGURE
:
321 case DRV_EXITSESSION
:
322 case DRV_EXITAPPLICATION
:
324 /* lParam1 and lParam2 are not used */
329 /* lParam1 is a NULL terminated string */
330 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
332 LPSTR str
= SEGPTR_STRDUP((LPSTR
)*lParam1
);
334 *lParam1
= (LPARAM
)SEGPTR_GET(str
);
342 if (*lParam2
&& wMsg
== DRV_OPEN
) {
343 LPMCI_OPEN_DRIVER_PARMS16 modp16
;
344 char* ptr
= SEGPTR_ALLOC(sizeof(LPMCI_OPEN_DRIVER_PARMSA
) + sizeof(MCI_OPEN_DRIVER_PARMS16
));
345 LPMCI_OPEN_DRIVER_PARMSA modp32
= (LPMCI_OPEN_DRIVER_PARMSA
)(*lParam2
);
348 *(LPMCI_OPEN_DRIVER_PARMSA
*)ptr
= modp32
;
349 modp16
= (LPMCI_OPEN_DRIVER_PARMS16
)(ptr
+ sizeof(LPMCI_OPEN_DRIVER_PARMSA
));
351 modp16
->wDeviceID
= modp32
->wDeviceID
;
352 modp16
->lpstrParams
= PTR_SEG_TO_LIN(modp32
->lpstrParams
);
356 *lParam2
= (DWORD
)SEGPTR_GET(modp16
);
362 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO */
364 LPDRVCONFIGINFO16 dci16
= (LPDRVCONFIGINFO16
)SEGPTR_ALLOC(sizeof(DRVCONFIGINFO16
));
365 LPDRVCONFIGINFO dci32
= (LPDRVCONFIGINFO
)(*lParam2
);
370 dci16
->dwDCISize
= sizeof(DRVCONFIGINFO16
);
372 if ((str1
= HEAP_strdupWtoA(GetProcessHeap(), 0, dci32
->lpszDCISectionName
)) != NULL
&&
373 (str2
= SEGPTR_STRDUP(str1
)) != NULL
) {
374 dci16
->lpszDCISectionName
= (LPSTR
)SEGPTR_GET(str2
);
375 if (!HeapFree(GetProcessHeap(), 0, str1
))
376 FIXME("bad free line=%d\n", __LINE__
);
380 if ((str1
= HEAP_strdupWtoA(GetProcessHeap(), 0, dci32
->lpszDCIAliasName
)) != NULL
&&
381 (str2
= SEGPTR_STRDUP(str1
)) != NULL
) {
382 dci16
->lpszDCIAliasName
= (LPSTR
)SEGPTR_GET(str2
);
383 if (!HeapFree(GetProcessHeap(), 0, str1
))
384 FIXME("bad free line=%d\n", __LINE__
);
391 *lParam2
= (LPARAM
)SEGPTR_GET(dci16
);
398 if (wMsg
>= 0x800 && wMsg
< 0x900) {
399 /* FIXME: another hack to handle MCI messages...
400 * should find a *NICE* way to integrate DRIVER_ and
401 * MCI_ mapping/unmapping functions
405 FIXME("Unknown message 0x%04x\n", wMsg
);
411 /**************************************************************************
412 * DRIVER_UnMapMsg32To16 [internal]
414 * UnMap a 32 bit driver message to a 16 bit driver message.
417 * -2 : ko, memory problem
419 static int DRIVER_UnMapMsg32To16(WORD wMsg
, DWORD lParam1
, DWORD lParam2
)
428 case DRV_QUERYCONFIGURE
:
430 case DRV_EXITSESSION
:
431 case DRV_EXITAPPLICATION
:
433 /* lParam1 and lParam2 are not used */
436 /* lParam1 is a NULL terminated string, lParam2 is unknown => may lead to some problem */
437 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
438 if (lParam1
) if (!SEGPTR_FREE(PTR_SEG_TO_LIN(lParam1
)))
439 FIXME("bad free line=%d\n", __LINE__
);
441 if (lParam2
&& wMsg
== DRV_OPEN
) {
442 LPMCI_OPEN_DRIVER_PARMS16 modp16
= (LPMCI_OPEN_DRIVER_PARMS16
)PTR_SEG_TO_LIN(lParam2
);
443 LPMCI_OPEN_DRIVER_PARMSA modp32
= *(LPMCI_OPEN_DRIVER_PARMSA
*)((char*)modp16
- sizeof(LPMCI_OPEN_DRIVER_PARMSA
));
445 modp32
->wCustomCommandTable
= modp16
->wCustomCommandTable
;
446 modp32
->wType
= modp16
->wType
;
447 if (!SEGPTR_FREE((char*)modp16
- sizeof(LPMCI_OPEN_DRIVER_PARMSA
)))
448 FIXME("bad free line=%d\n", __LINE__
);
454 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
456 LPDRVCONFIGINFO16 dci16
= (LPDRVCONFIGINFO16
)PTR_SEG_TO_LIN(lParam2
);
458 if (!SEGPTR_FREE(PTR_SEG_TO_LIN(dci16
->lpszDCISectionName
)))
459 FIXME("bad free line=%d\n", __LINE__
);
460 if (!SEGPTR_FREE(PTR_SEG_TO_LIN(dci16
->lpszDCIAliasName
)))
461 FIXME("bad free line=%d\n", __LINE__
);
462 if (!SEGPTR_FREE(dci16
))
463 FIXME("bad free line=%d\n", __LINE__
);
468 if (wMsg
>= 0x800 && wMsg
< 0x900) {
469 /* FIXME: another hack to handle MCI messages...
470 * should find a *NICE* way to integrate DRIVER_ and
471 * MCI_ mapping/unmapping functions
475 FIXME("Unknown message 0x%04x\n", wMsg
);
481 /**************************************************************************
482 * SendDriverMessage [USER.251]
484 LRESULT WINAPI
SendDriverMessage16(HDRVR16 hDriver
, UINT16 msg
, LPARAM lParam1
,
491 TRACE("(%04x, %04X, %08lX, %08lX)\n", hDriver
, msg
, lParam1
, lParam2
);
493 lpDrv
= DRIVER_FindFromHDrvr16(hDriver
);
494 if (lpDrv
!= NULL
&& lpDrv
->hDriver16
== hDriver
) {
495 if (lpDrv
->dwFlags
& WINE_GDF_16BIT
) {
496 TRACE("Before CallDriverProc proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
497 lpDrv
->d
.d16
.lpDrvProc
, lpDrv
->dwDriverID
, hDriver
, msg
, lParam1
, lParam2
);
498 retval
= DRIVER_CallTo16_long_lwwll((FARPROC16
)lpDrv
->d
.d16
.lpDrvProc
, lpDrv
->dwDriverID
,
499 hDriver
, msg
, lParam1
, lParam2
);
501 mapRet
= DRIVER_MapMsg16To32(msg
, &lParam1
, &lParam2
);
503 TRACE("Before func32 call proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
504 lpDrv
->d
.d32
.lpDrvProc
, lpDrv
->dwDriverID
, (HDRVR
)lpDrv
, msg
, lParam1
, lParam2
);
505 retval
= lpDrv
->d
.d32
.lpDrvProc(lpDrv
->dwDriverID
, (HDRVR
)lpDrv
, msg
, lParam1
, lParam2
);
507 DRIVER_UnMapMsg16To32(msg
, lParam1
, lParam2
);
514 WARN("Bad driver handle %u\n", hDriver
);
517 TRACE("retval = %ld\n", retval
);
521 /**************************************************************************
522 * SendDriverMessage [WINMM.19]
524 LRESULT WINAPI
SendDriverMessage(HDRVR hDriver
, UINT msg
, LPARAM lParam1
,
531 TRACE("(%04x, %04X, %08lX, %08lX)\n", hDriver
, msg
, lParam1
, lParam2
);
533 lpDrv
= DRIVER_FindFromHDrvr(hDriver
);
536 if (lpDrv
->dwFlags
& WINE_GDF_16BIT
) {
537 mapRet
= DRIVER_MapMsg32To16(msg
, &lParam1
, &lParam2
);
539 TRACE("Before CallDriverProc proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
540 lpDrv
->d
.d16
.lpDrvProc
, lpDrv
->dwDriverID
, lpDrv
->hDriver16
, msg
, lParam1
, lParam2
);
541 retval
= DRIVER_CallTo16_long_lwwll((FARPROC16
)lpDrv
->d
.d16
.lpDrvProc
, lpDrv
->dwDriverID
,
542 lpDrv
->hDriver16
, msg
, lParam1
, lParam2
);
544 DRIVER_UnMapMsg32To16(msg
, lParam1
, lParam2
);
550 TRACE("Before func32 call proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
551 lpDrv
->d
.d32
.lpDrvProc
, lpDrv
->dwDriverID
, hDriver
, msg
, lParam1
, lParam2
);
552 retval
= lpDrv
->d
.d32
.lpDrvProc(lpDrv
->dwDriverID
, hDriver
, msg
, lParam1
, lParam2
);
555 WARN("Bad driver handle %u\n", hDriver
);
557 TRACE("retval = %ld\n", retval
);
562 /**************************************************************************
563 * DRIVER_RemoveFromList [internal]
565 * Generates all the logic to handle driver closure / deletion
566 * Removes a driver struct to the list of open drivers.
568 static BOOL
DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv
)
570 lpDrv
->dwDriverID
= 0;
571 if (DRIVER_GetNumberOfModuleRefs(lpDrv
) == 1) {
572 SendDriverMessage((HDRVR
)lpDrv
, DRV_DISABLE
, 0L, 0L);
573 SendDriverMessage((HDRVR
)lpDrv
, DRV_FREE
, 0L, 0L);
576 if (lpDrv
->lpPrevItem
)
577 lpDrv
->lpPrevItem
->lpNextItem
= lpDrv
->lpNextItem
;
579 lpDrvItemList
= lpDrv
->lpNextItem
;
580 if (lpDrv
->lpNextItem
)
581 lpDrv
->lpNextItem
->lpPrevItem
= lpDrv
->lpPrevItem
;
586 /**************************************************************************
587 * DRIVER_AddToList [internal]
589 * Adds a driver struct to the list of open drivers.
590 * Generates all the logic to handle driver creation / open.
592 static BOOL
DRIVER_AddToList(LPWINE_DRIVER lpNewDrv
, LPARAM lParam
, BOOL bCallFrom32
)
594 lpNewDrv
->dwMagic
= WINE_DI_MAGIC
;
595 /* First driver to be loaded for this module, need to load correctly the module */
596 if (DRIVER_GetNumberOfModuleRefs(lpNewDrv
) == 0) {
597 if (SendDriverMessage((HDRVR
)lpNewDrv
, DRV_LOAD
, 0L, 0L) != DRV_SUCCESS
) {
598 TRACE("DRV_LOAD failed on driver 0x%08lx\n", (DWORD
)lpNewDrv
);
601 if (SendDriverMessage((HDRVR
)lpNewDrv
, DRV_ENABLE
, 0L, 0L) != DRV_SUCCESS
) {
602 TRACE("DRV_ENABLE failed on driver 0x%08lx\n", (DWORD
)lpNewDrv
);
607 lpNewDrv
->lpNextItem
= NULL
;
608 if (lpDrvItemList
== NULL
) {
609 lpDrvItemList
= lpNewDrv
;
610 lpNewDrv
->lpPrevItem
= NULL
;
612 LPWINE_DRIVER lpDrv
= lpDrvItemList
; /* find end of list */
613 while (lpDrv
->lpNextItem
!= NULL
)
614 lpDrv
= lpDrv
->lpNextItem
;
616 lpDrv
->lpNextItem
= lpNewDrv
;
617 lpNewDrv
->lpPrevItem
= lpDrv
;
620 /* Now just open a new instance of a driver on this module */
622 lpNewDrv
->dwDriverID
= SendDriverMessage((HDRVR
)lpNewDrv
, DRV_OPEN
, 0L, lParam
);
624 lpNewDrv
->dwDriverID
= SendDriverMessage16(lpNewDrv
->hDriver16
, DRV_OPEN
, 0L, lParam
);
626 if (lpNewDrv
->dwDriverID
== 0) {
627 TRACE("DRV_OPEN failed on driver 0x%08lx\n", (DWORD
)lpNewDrv
);
628 DRIVER_RemoveFromList(lpNewDrv
);
635 /**************************************************************************
636 * DRIVER_CreateDrvr16 [internal]
638 * Creates unique ID for 16 bit drivers.
640 static HDRVR16
DRIVER_CreateDrvr16()
642 static WORD DRIVER_hDrvr16Counter
= 0;
644 while (DRIVER_FindFromHDrvr16(++DRIVER_hDrvr16Counter
));
645 return DRIVER_hDrvr16Counter
;
648 /**************************************************************************
649 * DRIVER_CloseDriver [internal]
652 BOOL
DRIVER_CloseDriver(LPWINE_DRIVER lpDrv
, DWORD lParam1
, DWORD lParam2
)
655 SendDriverMessage((HDRVR
)lpDrv
, DRV_CLOSE
, lParam1
, lParam2
);
657 if (DRIVER_RemoveFromList(lpDrv
)) {
658 HeapFree(GetProcessHeap(), 0, lpDrv
);
662 WARN("Failed to close driver\n");
666 /**************************************************************************
667 * DRIVER_RegisterDriver16 [internal]
669 * Creates all the WINE internal representations for a 16 bit driver.
670 * The driver is also open by sending the correct messages.
672 LPWINE_DRIVER
DRIVER_RegisterDriver16(LPCSTR lpName
, HMODULE16 hModule
, DRIVERPROC16 lpProc
,
673 LPARAM lParam
, BOOL bCallFrom32
)
677 lpDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER
));
679 lpDrv
->dwFlags
= WINE_GDF_EXIST
|WINE_GDF_16BIT
;
680 lpDrv
->dwDriverID
= 0;
681 lpDrv
->hDriver16
= DRIVER_CreateDrvr16();
682 lstrcpynA(lpDrv
->szAliasName
, lpName
, sizeof(lpDrv
->szAliasName
));
683 lpDrv
->d
.d16
.hModule
= hModule
;
684 lpDrv
->d
.d16
.lpDrvProc
= lpProc
;
686 if (!DRIVER_AddToList(lpDrv
, lParam
, bCallFrom32
)) {
687 HeapFree(GetProcessHeap(), 0, lpDrv
);
694 /**************************************************************************
695 * DRIVER_RegisterDriver32 [internal]
697 * Creates all the WINE internal representations for a 32 bit driver.
698 * The driver is also open by sending the correct messages.
700 LPWINE_DRIVER
DRIVER_RegisterDriver32(LPCSTR lpName
, HMODULE hModule
, DRIVERPROC lpProc
,
701 LPARAM lParam
, BOOL bCallFrom32
)
705 lpDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER
));
707 lpDrv
->dwFlags
= WINE_GDF_EXIST
;
708 lpDrv
->dwDriverID
= 0;
709 lpDrv
->hDriver16
= DRIVER_CreateDrvr16();
710 lstrcpynA(lpDrv
->szAliasName
, lpName
, sizeof(lpDrv
->szAliasName
));
711 lpDrv
->d
.d32
.hModule
= hModule
;
712 lpDrv
->d
.d32
.lpDrvProc
= lpProc
;
714 if (!DRIVER_AddToList(lpDrv
, lParam
, bCallFrom32
)) {
715 HeapFree(GetProcessHeap(), 0, lpDrv
);
722 /**************************************************************************
723 * DRIVER_TryOpenDriver16 [internal]
725 * Tries to load a 16 bit driver whose DLL's (module) name is lpFileName.
727 static HDRVR16
DRIVER_TryOpenDriver16(LPCSTR lpFileName
, LPARAM lParam
, BOOL bCallFrom32
)
729 LPWINE_DRIVER lpDrv
= NULL
;
734 TRACE("('%s', %08lX, %d);\n", lpFileName
, lParam
, bCallFrom32
);
736 if (lstrlenA(lpFileName
) < 1)
739 lpSFN
= strrchr(lpFileName
, '\\');
740 lpSFN
= (lpSFN
) ? (lpSFN
+ 1) : lpFileName
;
742 if ((hModule
= LoadModule16(lpFileName
, (LPVOID
)-1)) >= 32) {
743 if ((lpProc
= (DRIVERPROC16
)WIN32_GetProcAddress16(hModule
, "DRIVERPROC")) != NULL
) {
744 lpDrv
= DRIVER_RegisterDriver16(lpSFN
, hModule
, lpProc
, lParam
, bCallFrom32
);
746 FreeLibrary16(hModule
);
747 TRACE("No DriverProc found\n");
751 TRACE("Unable to load 16 bit module (%s): %d\n", lpFileName
, hModule
);
753 return lpDrv
? lpDrv
->hDriver16
: 0;
756 /**************************************************************************
757 * DRIVER_TryOpenDriver32 [internal]
759 * Tries to load a 32 bit driver whose DLL's (module) name is lpFileName.
761 static HDRVR
DRIVER_TryOpenDriver32(LPCSTR lpFileName
, LPARAM lParam
, BOOL bCallFrom32
)
763 LPWINE_DRIVER lpDrv
= NULL
;
768 TRACE("('%s', %08lX, %d);\n", lpFileName
, lParam
, bCallFrom32
);
770 if (lstrlenA(lpFileName
) < 1)
773 lpSFN
= strrchr(lpFileName
, '\\');
774 lpSFN
= (lpSFN
) ? (lpSFN
+ 1) : lpFileName
;
776 if ((hModule
= LoadLibraryA(lpFileName
)) != 0) {
777 if ((lpProc
= GetProcAddress(hModule
, "DriverProc")) != NULL
) {
778 lpDrv
= DRIVER_RegisterDriver32(lpSFN
, hModule
, lpProc
, lParam
, bCallFrom32
);
780 FreeLibrary(hModule
);
782 TRACE("No DriverProc found\n");
785 TRACE("Unable to load 32 bit module \"%s\"\n", lpFileName
);
787 TRACE("=> %p\n", lpDrv
);
791 /**************************************************************************
792 * OpenDriver16 [USER.252]
794 HDRVR16 WINAPI
OpenDriver16(LPCSTR lpDriverName
, LPCSTR lpSectionName
, LPARAM lParam
)
799 TRACE("('%s', '%s', %08lX);\n", lpDriverName
, lpSectionName
, lParam
);
801 if (lpSectionName
== NULL
) {
802 hDriver
= DRIVER_TryOpenDriver16(lpDriverName
, lParam
, FALSE
);
804 hDriver
= DRIVER_TryOpenDriver32(lpDriverName
, lParam
, FALSE
);
807 /* in case hDriver is NULL, search in Drivers32 section */
808 lpSectionName
= "Drivers";
811 if (!hDriver
&& GetPrivateProfileStringA(lpSectionName
, lpDriverName
, "",
812 drvName
, sizeof(drvName
), "SYSTEM.INI") > 0) {
813 hDriver
= DRIVER_TryOpenDriver16(drvName
, lParam
, FALSE
);
816 ERR("Failed to open driver %s from section %s\n", lpDriverName
, lpSectionName
);
818 TRACE("=> %08x\n", hDriver
);
822 /**************************************************************************
823 * OpenDriverA [WINMM.15]
824 * (0,1,DRV_LOAD ,0 ,0)
825 * (0,1,DRV_ENABLE,0 ,0)
826 * (0,1,DRV_OPEN ,buf[256],0)
828 HDRVR WINAPI
OpenDriverA(LPCSTR lpDriverName
, LPCSTR lpSectionName
, LPARAM lParam
)
833 TRACE("('%s', '%s', %08lX);\n", lpDriverName
, lpSectionName
, lParam
);
835 if (lpSectionName
== NULL
) {
836 lstrcpynA(drvName
, lpDriverName
, sizeof(drvName
));
837 hDriver
= DRIVER_TryOpenDriver32(lpDriverName
, lParam
, TRUE
);
839 hDriver
= DRIVER_TryOpenDriver16(lpDriverName
, lParam
, TRUE
);
842 if (GetPrivateProfileStringA("Drivers32", lpDriverName
, "", drvName
,
843 sizeof(drvName
), "SYSTEM.INI")) {
844 hDriver
= DRIVER_TryOpenDriver32(drvName
, lParam
, TRUE
);
849 if (GetPrivateProfileStringA("Drivers", lpDriverName
, "", drvName
,
850 sizeof(drvName
), "SYSTEM.INI")) {
851 hDriver
= DRIVER_TryOpenDriver16(drvName
, lParam
, TRUE
);
856 if (GetPrivateProfileStringA(lpSectionName
, lpDriverName
, "", drvName
,
857 sizeof(drvName
), "SYSTEM.INI")) {
858 hDriver
= DRIVER_TryOpenDriver32(drvName
, lParam
, TRUE
);
860 hDriver
= DRIVER_TryOpenDriver16(drvName
, lParam
, TRUE
);
865 ERR("Failed to open driver %s from section %s\n", lpDriverName
, lpSectionName
);
867 TRACE("=> %08x\n", hDriver
);
871 /**************************************************************************
872 * OpenDriverW [WINMM.15]
874 HDRVR WINAPI
OpenDriverW(LPCWSTR lpDriverName
, LPCWSTR lpSectionName
, LPARAM lParam
)
876 LPSTR dn
= HEAP_strdupWtoA(GetProcessHeap(), 0, lpDriverName
);
877 LPSTR sn
= HEAP_strdupWtoA(GetProcessHeap(), 0, lpSectionName
);
878 HDRVR ret
= OpenDriverA(dn
, sn
, lParam
);
880 if (dn
) HeapFree(GetProcessHeap(), 0, dn
);
881 if (sn
) HeapFree(GetProcessHeap(), 0, sn
);
885 /**************************************************************************
886 * CloseDriver16 [USER.253]
888 LRESULT WINAPI
CloseDriver16(HDRVR16 hDrvr
, LPARAM lParam1
, LPARAM lParam2
)
890 TRACE("(%04x, %08lX, %08lX);\n", hDrvr
, lParam1
, lParam2
);
892 return DRIVER_CloseDriver(DRIVER_FindFromHDrvr16(hDrvr
), lParam1
, lParam2
);
895 /**************************************************************************
896 * CloseDriver [WINMM.4]
898 LRESULT WINAPI
CloseDriver(HDRVR hDrvr
, LPARAM lParam1
, LPARAM lParam2
)
900 TRACE("(%04x, %08lX, %08lX);\n", hDrvr
, lParam1
, lParam2
);
902 return DRIVER_CloseDriver(DRIVER_FindFromHDrvr(hDrvr
), lParam1
, lParam2
);
905 /**************************************************************************
906 * GetDriverModuleHandle [USER.254]
908 HMODULE16 WINAPI
GetDriverModuleHandle16(HDRVR16 hDrvr
)
911 HMODULE16 hModule
= 0;
913 TRACE("(%04x);\n", hDrvr
);
915 lpDrv
= DRIVER_FindFromHDrvr16(hDrvr
);
916 if (lpDrv
!= NULL
&& lpDrv
->hDriver16
== hDrvr
&& (lpDrv
->dwFlags
& WINE_GDF_16BIT
)) {
917 hModule
= lpDrv
->d
.d16
.hModule
;
919 TRACE("=> %d\n", hModule
);
923 /**************************************************************************
924 * GetDriverFlags [WINMM.13]
925 * [in] hDrvr handle to the driver
928 * 0x00000000 if hDrvr is an invalid handle
929 * 0x80000000 if hDrvr is a valid 32 bit driver
930 * 0x90000000 if hDrvr is a valid 16 bit driver
932 DWORD WINAPI
GetDriverFlags(HDRVR hDrvr
)
937 TRACE("(%04x)\n", hDrvr
);
939 if ((lpDrv
= DRIVER_FindFromHDrvr(hDrvr
)) != NULL
) {
940 ret
= lpDrv
->dwFlags
;
945 /**************************************************************************
946 * GetDriverModuleHandle [WINMM.14]
948 HMODULE WINAPI
GetDriverModuleHandle(HDRVR hDrvr
)
953 TRACE("(%04x);\n", hDrvr
);
955 lpDrv
= DRIVER_FindFromHDrvr(hDrvr
);
956 if (lpDrv
!= NULL
&& !(lpDrv
->dwFlags
& WINE_GDF_16BIT
)) {
957 hModule
= lpDrv
->d
.d32
.hModule
;
959 TRACE("=> %d\n", hModule
);
963 /**************************************************************************
964 * DefDriverProc16 [USER.255]
966 LRESULT WINAPI
DefDriverProc16(DWORD dwDevID
, HDRVR16 hDriv
, UINT16 wMsg
,
967 LPARAM lParam1
, LPARAM lParam2
)
969 TRACE("devID=0x%08lx hDrv=0x%04x wMsg=%04x lP1=0x%08lx lP2=0x%08lx\n",
970 dwDevID
, hDriv
, wMsg
, lParam1
, lParam2
);
980 case DRV_QUERYCONFIGURE
:
983 MessageBoxA(0, "Driver isn't configurable !", "Wine Driver", MB_OK
);
993 /**************************************************************************
994 * GetDriverInfo [USER.256]
996 BOOL16 WINAPI
GetDriverInfo16(HDRVR16 hDrvr
, LPDRIVERINFOSTRUCT16 lpDrvInfo
)
1001 TRACE("(%04x, %p);\n", hDrvr
, lpDrvInfo
);
1003 if (lpDrvInfo
== NULL
|| lpDrvInfo
->length
!= sizeof(DRIVERINFOSTRUCT16
))
1006 lpDrv
= DRIVER_FindFromHDrvr16(hDrvr
);
1007 if (lpDrv
!= NULL
&& lpDrv
->hDriver16
== hDrvr
&&
1008 (lpDrv
->dwFlags
& WINE_GDF_16BIT
)) {
1009 lpDrvInfo
->hDriver
= lpDrv
->hDriver16
;
1010 lpDrvInfo
->hModule
= lpDrv
->d
.d16
.hModule
;
1011 lstrcpynA(lpDrvInfo
->szAliasName
, lpDrv
->szAliasName
, sizeof(lpDrvInfo
->szAliasName
));
1018 /**************************************************************************
1019 * GetNextDriver [USER.257]
1021 HDRVR16 WINAPI
GetNextDriver16(HDRVR16 hDrvr
, DWORD dwFlags
)
1023 HDRVR16 hRetDrv
= 0;
1024 LPWINE_DRIVER lpDrv
;
1026 TRACE("(%04x, %08lX);\n", hDrvr
, dwFlags
);
1029 if (lpDrvItemList
== NULL
) {
1030 FIXME("drivers list empty !\n");
1031 /* FIXME: code was using DRIVER_LoadStartupDrivers(); before ?
1032 * I (EPP) don't quite understand this
1034 if (lpDrvItemList
== NULL
)
1037 lpDrv
= lpDrvItemList
;
1038 if (dwFlags
& GND_REVERSE
) {
1039 while (lpDrv
->lpNextItem
)
1040 lpDrv
= lpDrv
->lpNextItem
;
1043 lpDrv
= DRIVER_FindFromHDrvr16(hDrvr
);
1044 if (lpDrv
!= NULL
) {
1045 if (dwFlags
& GND_REVERSE
) {
1046 lpDrv
= (lpDrv
->lpPrevItem
) ? lpDrv
->lpPrevItem
: NULL
;
1048 lpDrv
= (lpDrv
->lpNextItem
) ? lpDrv
->lpNextItem
: NULL
;
1053 hRetDrv
= (lpDrv
) ? lpDrv
->hDriver16
: (HDRVR16
)0;
1054 TRACE("return %04x !\n", hRetDrv
);