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
14 #include "wine/winbase16.h"
21 #include "debugtools.h"
23 DEFAULT_DEBUG_CHANNEL(driver
);
25 /* The following definitions are WINE internals */
26 /* FIXME: This is a WINE internal struct and should be moved in include/wine directory
27 * Please note that WINE shares 16 and 32 bit drivers on a single list...
28 * Basically, we maintain an external double view on drivers, so that a 16 bit drivers
29 * can be loaded/used... by 32 functions transparently
32 /* Who said goofy boy ? */
33 #define WINE_DI_MAGIC 0x900F1B01
35 typedef struct tagWINE_DRIVER
38 char szAliasName
[128];
39 /* as usual LPWINE_DRIVER == hDriver32 */
44 DRIVERPROC16 lpDrvProc
;
53 struct tagWINE_DRIVER
* lpPrevItem
;
54 struct tagWINE_DRIVER
* lpNextItem
;
55 } WINE_DRIVER
, *LPWINE_DRIVER
;
57 LPWINE_DRIVER
DRIVER_RegisterDriver16(LPCSTR
, HMODULE16
, DRIVERPROC16
, LPARAM
, BOOL
);
58 LPWINE_DRIVER
DRIVER_RegisterDriver32(LPCSTR
, HMODULE
, DRIVERPROC
, LPARAM
, BOOL
);
60 static LPWINE_DRIVER lpDrvItemList
= NULL
;
63 * - LoadModule count and clean up is not handled correctly (it's not a
64 * problem as long as FreeLibrary is not working correctly)
65 * - shoudln't the allocations be done on a per process basis ?
66 * - split 16/32 bit functions between DLLs as windows do (16 bit in USER, 32 bit in WINMM)
69 /* ### start build ### */
70 extern LONG CALLBACK
DRIVER_CallTo16_long_lwwll(FARPROC16
,LONG
,WORD
,WORD
,LONG
,LONG
);
71 /* ### stop build ### */
73 /**************************************************************************
74 * LoadStartupDrivers [internal]
76 static void WINE_UNUSED
DRIVER_LoadStartupDrivers(void)
80 if (GetPrivateProfileStringA("drivers", NULL
, "", str
, sizeof(str
), "SYSTEM.INI") < 2) {
81 ERR("Can't find drivers section in system.ini\n");
86 for (ptr
= str
; lstrlenA(ptr
) != 0; ptr
+= lstrlenA(ptr
) + 1) {
87 TRACE("str='%s'\n", ptr
);
88 hDrv
= OpenDriver16(ptr
, "drivers", 0L);
89 TRACE("hDrv=%04x\n", hDrv
);
91 TRACE("end of list !\n");
95 /**************************************************************************
96 * DRIVER_GetNumberOfModuleRefs [internal]
98 * Returns the number of open drivers which share the same module.
100 static WORD
DRIVER_GetNumberOfModuleRefs(LPWINE_DRIVER lpNewDrv
)
105 for (lpDrv
= lpDrvItemList
; lpDrv
; lpDrv
= lpDrv
->lpNextItem
) {
106 if (lpDrv
->dwFlags
& WINE_GDF_16BIT
) {
107 if (lpDrv
->d
.d16
.hModule
== lpNewDrv
->d
.d16
.hModule
) {
111 if (lpDrv
->d
.d32
.hModule
== lpNewDrv
->d
.d32
.hModule
) {
119 /**************************************************************************
120 * DRIVER_FindFromHDrvr16 [internal]
122 * From a hDrvr being 16 bits, returns the WINE internal structure.
124 static LPWINE_DRIVER
DRIVER_FindFromHDrvr16(HDRVR16 hDrvr
)
128 for (lpDrv
= lpDrvItemList
; lpDrv
; lpDrv
= lpDrv
->lpNextItem
) {
129 if (lpDrv
->hDriver16
== hDrvr
) {
136 /**************************************************************************
137 * DRIVER_FindFromHDrvr [internal]
139 * From a hDrvr (being 16 or 32 bits), returns the WINE internal structure.
141 static LPWINE_DRIVER
DRIVER_FindFromHDrvr(HDRVR hDrvr
)
143 if (!IsBadWritePtr((void*)hDrvr
, sizeof(WINE_DRIVER
)) &&
144 ((LPWINE_DRIVER
)hDrvr
)->dwMagic
== WINE_DI_MAGIC
) {
145 return (LPWINE_DRIVER
)hDrvr
;
147 return DRIVER_FindFromHDrvr16(hDrvr
);
150 /**************************************************************************
151 * DRIVER_MapMsg16To32 [internal]
153 * Map a 16 bit driver message to a 32 bit driver message.
154 * 1 : ok, some memory allocated, need to call DRIVER_UnMapMsg16To32
155 * 0 : ok, no memory allocated
156 * -1 : ko, unknown message
157 * -2 : ko, memory problem
159 static int DRIVER_MapMsg16To32(WORD wMsg
, DWORD
* lParam1
, DWORD
* lParam2
)
168 case DRV_QUERYCONFIGURE
:
170 case DRV_EXITSESSION
:
171 case DRV_EXITAPPLICATION
:
173 /* lParam1 and lParam2 are not used */
178 /* lParam1 is a NULL terminated string */
179 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
181 *lParam1
= (DWORD
)PTR_SEG_TO_LIN(*lParam1
);
182 if (*lParam2
&& wMsg
== DRV_OPEN
) {
183 LPMCI_OPEN_DRIVER_PARMS16 modp16
= PTR_SEG_TO_LIN(*lParam2
);
184 char* ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPMCI_OPEN_DRIVER_PARMS16
) + sizeof(MCI_OPEN_DRIVER_PARMSA
));
185 LPMCI_OPEN_DRIVER_PARMSA modp32
;
188 *(LPMCI_OPEN_DRIVER_PARMS16
*)ptr
= modp16
;
189 modp32
= (LPMCI_OPEN_DRIVER_PARMSA
)(ptr
+ sizeof(LPMCI_OPEN_DRIVER_PARMSA
));
191 modp32
->wDeviceID
= modp16
->wDeviceID
;
192 modp32
->lpstrParams
= PTR_SEG_TO_LIN(modp16
->lpstrParams
);
196 *lParam2
= (DWORD
)modp32
;
202 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO */
204 LPDRVCONFIGINFO dci32
= HeapAlloc(GetProcessHeap(), 0, sizeof(DRVCONFIGINFO
));
205 LPDRVCONFIGINFO16 dci16
= PTR_SEG_TO_LIN(*lParam2
);
208 dci32
->dwDCISize
= sizeof(DRVCONFIGINFO
);
209 dci32
->lpszDCISectionName
= HEAP_strdupAtoW(GetProcessHeap(), 0, PTR_SEG_TO_LIN(dci16
->lpszDCISectionName
));
210 dci32
->lpszDCIAliasName
= HEAP_strdupAtoW(GetProcessHeap(), 0, PTR_SEG_TO_LIN(dci16
->lpszDCIAliasName
));
211 if (dci32
->lpszDCISectionName
== NULL
|| dci32
->lpszDCIAliasName
== NULL
)
216 *lParam2
= (DWORD
)dci32
;
223 if (wMsg
>= 0x800 && wMsg
< 0x900) {
224 /* FIXME: another hack to handle MCI messages...
225 * should find a *NICE* way to integrate DRIVER_ and
226 * MCI_ mapping/unmapping functions
230 FIXME("Unknown message 0x%04x\n", wMsg
);
236 /**************************************************************************
237 * DRIVER_MapMsg16To32 [internal]
239 * UnMap a 16 bit driver message to a 32 bit driver message.
242 * -2 : ko, memory problem
244 static int DRIVER_UnMapMsg16To32(WORD wMsg
, DWORD lParam1
, DWORD lParam2
)
253 case DRV_QUERYCONFIGURE
:
255 case DRV_EXITSESSION
:
256 case DRV_EXITAPPLICATION
:
258 /* lParam1 and lParam2 are not used */
261 /* lParam1 is a NULL terminated string */
262 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
263 if (lParam2
&& wMsg
== DRV_OPEN
) {
264 LPMCI_OPEN_DRIVER_PARMSA modp32
= (LPMCI_OPEN_DRIVER_PARMSA
)lParam2
;
265 LPMCI_OPEN_DRIVER_PARMS16 modp16
= *(LPMCI_OPEN_DRIVER_PARMS16
*)(lParam2
- sizeof(LPMCI_OPEN_DRIVER_PARMSA
));
267 modp16
->wCustomCommandTable
= modp32
->wCustomCommandTable
;
268 modp16
->wType
= modp32
->wType
;
269 if (!HeapFree(GetProcessHeap(), 0, modp32
))
270 FIXME("bad free line=%d\n", __LINE__
);
276 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
278 LPDRVCONFIGINFO dci32
= (LPDRVCONFIGINFO
)lParam2
;
279 if (!HeapFree(GetProcessHeap(), 0, (LPVOID
)dci32
->lpszDCISectionName
))
280 FIXME("bad free line=%d\n", __LINE__
);
281 if (!HeapFree(GetProcessHeap(), 0, (LPVOID
)dci32
->lpszDCIAliasName
))
282 FIXME("bad free line=%d\n", __LINE__
);
283 if (!HeapFree(GetProcessHeap(), 0, dci32
))
284 FIXME("bad free line=%d\n", __LINE__
);
289 if (wMsg
>= 0x800 && wMsg
< 0x900) {
290 /* FIXME: another hack to handle MCI messages...
291 * should find a *NICE* way to integrate DRIVER_ and
292 * MCI_ mapping/unmapping functions
296 FIXME("Unknown message 0x%04x\n", wMsg
);
302 /**************************************************************************
303 * DRIVER_MapMsg32To16 [internal]
305 * Map a 32 bit driver message to a 16 bit driver message.
306 * 1 : ok, some memory allocated, need to call DRIVER_UnMapMsg32To16
307 * 0 : ok, no memory allocated
308 * -1 : ko, unknown message
309 * -2 : ko, memory problem
311 static int DRIVER_MapMsg32To16(WORD wMsg
, DWORD
* lParam1
, DWORD
* lParam2
)
320 case DRV_QUERYCONFIGURE
:
322 case DRV_EXITSESSION
:
323 case DRV_EXITAPPLICATION
:
325 /* lParam1 and lParam2 are not used */
330 /* lParam1 is a NULL terminated string */
331 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
333 LPSTR str
= SEGPTR_STRDUP((LPSTR
)*lParam1
);
335 *lParam1
= (LPARAM
)SEGPTR_GET(str
);
343 if (*lParam2
&& wMsg
== DRV_OPEN
) {
344 LPMCI_OPEN_DRIVER_PARMS16 modp16
;
345 char* ptr
= SEGPTR_ALLOC(sizeof(LPMCI_OPEN_DRIVER_PARMSA
) + sizeof(MCI_OPEN_DRIVER_PARMS16
));
346 LPMCI_OPEN_DRIVER_PARMSA modp32
= (LPMCI_OPEN_DRIVER_PARMSA
)(*lParam2
);
349 *(LPMCI_OPEN_DRIVER_PARMSA
*)ptr
= modp32
;
350 modp16
= (LPMCI_OPEN_DRIVER_PARMS16
)(ptr
+ sizeof(LPMCI_OPEN_DRIVER_PARMSA
));
352 modp16
->wDeviceID
= modp32
->wDeviceID
;
353 modp16
->lpstrParams
= PTR_SEG_TO_LIN(modp32
->lpstrParams
);
357 *lParam2
= (DWORD
)SEGPTR_GET(modp16
);
363 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO */
365 LPDRVCONFIGINFO16 dci16
= (LPDRVCONFIGINFO16
)SEGPTR_ALLOC(sizeof(DRVCONFIGINFO16
));
366 LPDRVCONFIGINFO dci32
= (LPDRVCONFIGINFO
)(*lParam2
);
371 dci16
->dwDCISize
= sizeof(DRVCONFIGINFO16
);
373 if ((str1
= HEAP_strdupWtoA(GetProcessHeap(), 0, dci32
->lpszDCISectionName
)) != NULL
&&
374 (str2
= SEGPTR_STRDUP(str1
)) != NULL
) {
375 dci16
->lpszDCISectionName
= (LPSTR
)SEGPTR_GET(str2
);
376 if (!HeapFree(GetProcessHeap(), 0, str1
))
377 FIXME("bad free line=%d\n", __LINE__
);
381 if ((str1
= HEAP_strdupWtoA(GetProcessHeap(), 0, dci32
->lpszDCIAliasName
)) != NULL
&&
382 (str2
= SEGPTR_STRDUP(str1
)) != NULL
) {
383 dci16
->lpszDCIAliasName
= (LPSTR
)SEGPTR_GET(str2
);
384 if (!HeapFree(GetProcessHeap(), 0, str1
))
385 FIXME("bad free line=%d\n", __LINE__
);
392 *lParam2
= (LPARAM
)SEGPTR_GET(dci16
);
399 if (wMsg
>= 0x800 && wMsg
< 0x900) {
400 /* FIXME: another hack to handle MCI messages...
401 * should find a *NICE* way to integrate DRIVER_ and
402 * MCI_ mapping/unmapping functions
406 FIXME("Unknown message 0x%04x\n", wMsg
);
412 /**************************************************************************
413 * DRIVER_UnMapMsg32To16 [internal]
415 * UnMap a 32 bit driver message to a 16 bit driver message.
418 * -2 : ko, memory problem
420 static int DRIVER_UnMapMsg32To16(WORD wMsg
, DWORD lParam1
, DWORD lParam2
)
429 case DRV_QUERYCONFIGURE
:
431 case DRV_EXITSESSION
:
432 case DRV_EXITAPPLICATION
:
434 /* lParam1 and lParam2 are not used */
437 /* lParam1 is a NULL terminated string, lParam2 is unknown => may lead to some problem */
438 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
439 if (lParam1
) if (!SEGPTR_FREE(PTR_SEG_TO_LIN(lParam1
)))
440 FIXME("bad free line=%d\n", __LINE__
);
442 if (lParam2
&& wMsg
== DRV_OPEN
) {
443 LPMCI_OPEN_DRIVER_PARMS16 modp16
= (LPMCI_OPEN_DRIVER_PARMS16
)PTR_SEG_TO_LIN(lParam2
);
444 LPMCI_OPEN_DRIVER_PARMSA modp32
= *(LPMCI_OPEN_DRIVER_PARMSA
*)((char*)modp16
- sizeof(LPMCI_OPEN_DRIVER_PARMSA
));
446 modp32
->wCustomCommandTable
= modp16
->wCustomCommandTable
;
447 modp32
->wType
= modp16
->wType
;
448 if (!SEGPTR_FREE((char*)modp16
- sizeof(LPMCI_OPEN_DRIVER_PARMSA
)))
449 FIXME("bad free line=%d\n", __LINE__
);
455 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
457 LPDRVCONFIGINFO16 dci16
= (LPDRVCONFIGINFO16
)PTR_SEG_TO_LIN(lParam2
);
459 if (!SEGPTR_FREE(PTR_SEG_TO_LIN(dci16
->lpszDCISectionName
)))
460 FIXME("bad free line=%d\n", __LINE__
);
461 if (!SEGPTR_FREE(PTR_SEG_TO_LIN(dci16
->lpszDCIAliasName
)))
462 FIXME("bad free line=%d\n", __LINE__
);
463 if (!SEGPTR_FREE(dci16
))
464 FIXME("bad free line=%d\n", __LINE__
);
469 if (wMsg
>= 0x800 && wMsg
< 0x900) {
470 /* FIXME: another hack to handle MCI messages...
471 * should find a *NICE* way to integrate DRIVER_ and
472 * MCI_ mapping/unmapping functions
476 FIXME("Unknown message 0x%04x\n", wMsg
);
482 /**************************************************************************
483 * SendDriverMessage [USER.251]
485 LRESULT WINAPI
SendDriverMessage16(HDRVR16 hDriver
, UINT16 msg
, LPARAM lParam1
,
492 TRACE("(%04x, %04X, %08lX, %08lX)\n", hDriver
, msg
, lParam1
, lParam2
);
494 lpDrv
= DRIVER_FindFromHDrvr16(hDriver
);
495 if (lpDrv
!= NULL
&& lpDrv
->hDriver16
== hDriver
) {
496 if (lpDrv
->dwFlags
& WINE_GDF_16BIT
) {
497 TRACE("Before CallDriverProc proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
498 lpDrv
->d
.d16
.lpDrvProc
, lpDrv
->dwDriverID
, hDriver
, msg
, lParam1
, lParam2
);
499 retval
= DRIVER_CallTo16_long_lwwll((FARPROC16
)lpDrv
->d
.d16
.lpDrvProc
, lpDrv
->dwDriverID
,
500 hDriver
, msg
, lParam1
, lParam2
);
502 mapRet
= DRIVER_MapMsg16To32(msg
, &lParam1
, &lParam2
);
504 TRACE("Before func32 call proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
505 lpDrv
->d
.d32
.lpDrvProc
, lpDrv
->dwDriverID
, (HDRVR
)lpDrv
, msg
, lParam1
, lParam2
);
506 retval
= lpDrv
->d
.d32
.lpDrvProc(lpDrv
->dwDriverID
, (HDRVR
)lpDrv
, msg
, lParam1
, lParam2
);
508 DRIVER_UnMapMsg16To32(msg
, lParam1
, lParam2
);
515 WARN("Bad driver handle %u\n", hDriver
);
518 TRACE("retval = %ld\n", retval
);
522 /**************************************************************************
523 * SendDriverMessage [WINMM.19]
525 LRESULT WINAPI
SendDriverMessage(HDRVR hDriver
, UINT msg
, LPARAM lParam1
,
532 TRACE("(%04x, %04X, %08lX, %08lX)\n", hDriver
, msg
, lParam1
, lParam2
);
534 lpDrv
= DRIVER_FindFromHDrvr(hDriver
);
537 if (lpDrv
->dwFlags
& WINE_GDF_16BIT
) {
538 mapRet
= DRIVER_MapMsg32To16(msg
, &lParam1
, &lParam2
);
540 TRACE("Before CallDriverProc proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
541 lpDrv
->d
.d16
.lpDrvProc
, lpDrv
->dwDriverID
, lpDrv
->hDriver16
, msg
, lParam1
, lParam2
);
542 retval
= DRIVER_CallTo16_long_lwwll((FARPROC16
)lpDrv
->d
.d16
.lpDrvProc
, lpDrv
->dwDriverID
,
543 lpDrv
->hDriver16
, msg
, lParam1
, lParam2
);
545 DRIVER_UnMapMsg32To16(msg
, lParam1
, lParam2
);
551 TRACE("Before func32 call proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
552 lpDrv
->d
.d32
.lpDrvProc
, lpDrv
->dwDriverID
, hDriver
, msg
, lParam1
, lParam2
);
553 retval
= lpDrv
->d
.d32
.lpDrvProc(lpDrv
->dwDriverID
, hDriver
, msg
, lParam1
, lParam2
);
556 WARN("Bad driver handle %u\n", hDriver
);
558 TRACE("retval = %ld\n", retval
);
563 /**************************************************************************
564 * DRIVER_RemoveFromList [internal]
566 * Generates all the logic to handle driver closure / deletion
567 * Removes a driver struct to the list of open drivers.
569 static BOOL
DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv
)
571 lpDrv
->dwDriverID
= 0;
572 if (DRIVER_GetNumberOfModuleRefs(lpDrv
) == 1) {
573 SendDriverMessage((HDRVR
)lpDrv
, DRV_DISABLE
, 0L, 0L);
574 SendDriverMessage((HDRVR
)lpDrv
, DRV_FREE
, 0L, 0L);
577 if (lpDrv
->lpPrevItem
)
578 lpDrv
->lpPrevItem
->lpNextItem
= lpDrv
->lpNextItem
;
580 lpDrvItemList
= lpDrv
->lpNextItem
;
581 if (lpDrv
->lpNextItem
)
582 lpDrv
->lpNextItem
->lpPrevItem
= lpDrv
->lpPrevItem
;
587 /**************************************************************************
588 * DRIVER_AddToList [internal]
590 * Adds a driver struct to the list of open drivers.
591 * Generates all the logic to handle driver creation / open.
593 static BOOL
DRIVER_AddToList(LPWINE_DRIVER lpNewDrv
, LPARAM lParam
, BOOL bCallFrom32
)
595 lpNewDrv
->dwMagic
= WINE_DI_MAGIC
;
596 /* First driver to be loaded for this module, need to load correctly the module */
597 if (DRIVER_GetNumberOfModuleRefs(lpNewDrv
) == 0) {
598 if (SendDriverMessage((HDRVR
)lpNewDrv
, DRV_LOAD
, 0L, 0L) != DRV_SUCCESS
) {
599 TRACE("DRV_LOAD failed on driver 0x%08lx\n", (DWORD
)lpNewDrv
);
602 if (SendDriverMessage((HDRVR
)lpNewDrv
, DRV_ENABLE
, 0L, 0L) != DRV_SUCCESS
) {
603 TRACE("DRV_ENABLE failed on driver 0x%08lx\n", (DWORD
)lpNewDrv
);
608 lpNewDrv
->lpNextItem
= NULL
;
609 if (lpDrvItemList
== NULL
) {
610 lpDrvItemList
= lpNewDrv
;
611 lpNewDrv
->lpPrevItem
= NULL
;
613 LPWINE_DRIVER lpDrv
= lpDrvItemList
; /* find end of list */
614 while (lpDrv
->lpNextItem
!= NULL
)
615 lpDrv
= lpDrv
->lpNextItem
;
617 lpDrv
->lpNextItem
= lpNewDrv
;
618 lpNewDrv
->lpPrevItem
= lpDrv
;
621 /* Now just open a new instance of a driver on this module */
623 lpNewDrv
->dwDriverID
= SendDriverMessage((HDRVR
)lpNewDrv
, DRV_OPEN
, 0L, lParam
);
625 lpNewDrv
->dwDriverID
= SendDriverMessage16(lpNewDrv
->hDriver16
, DRV_OPEN
, 0L, lParam
);
627 if (lpNewDrv
->dwDriverID
== 0) {
628 TRACE("DRV_OPEN failed on driver 0x%08lx\n", (DWORD
)lpNewDrv
);
629 DRIVER_RemoveFromList(lpNewDrv
);
636 /**************************************************************************
637 * DRIVER_CreateDrvr16 [internal]
639 * Creates unique ID for 16 bit drivers.
641 static HDRVR16
DRIVER_CreateDrvr16()
643 static WORD DRIVER_hDrvr16Counter
= 0;
645 while (DRIVER_FindFromHDrvr16(++DRIVER_hDrvr16Counter
));
646 return DRIVER_hDrvr16Counter
;
649 /**************************************************************************
650 * DRIVER_CloseDriver [internal]
653 BOOL
DRIVER_CloseDriver(LPWINE_DRIVER lpDrv
, DWORD lParam1
, DWORD lParam2
)
656 SendDriverMessage((HDRVR
)lpDrv
, DRV_CLOSE
, lParam1
, lParam2
);
658 if (DRIVER_RemoveFromList(lpDrv
)) {
659 HeapFree(GetProcessHeap(), 0, lpDrv
);
663 WARN("Failed to close driver\n");
667 /**************************************************************************
668 * DRIVER_RegisterDriver16 [internal]
670 * Creates all the WINE internal representations for a 16 bit driver.
671 * The driver is also open by sending the correct messages.
673 LPWINE_DRIVER
DRIVER_RegisterDriver16(LPCSTR lpName
, HMODULE16 hModule
, DRIVERPROC16 lpProc
,
674 LPARAM lParam
, BOOL bCallFrom32
)
678 lpDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER
));
680 lpDrv
->dwFlags
= WINE_GDF_EXIST
|WINE_GDF_16BIT
;
681 lpDrv
->dwDriverID
= 0;
682 lpDrv
->hDriver16
= DRIVER_CreateDrvr16();
683 lstrcpynA(lpDrv
->szAliasName
, lpName
, sizeof(lpDrv
->szAliasName
));
684 lpDrv
->d
.d16
.hModule
= hModule
;
685 lpDrv
->d
.d16
.lpDrvProc
= lpProc
;
687 if (!DRIVER_AddToList(lpDrv
, lParam
, bCallFrom32
)) {
688 HeapFree(GetProcessHeap(), 0, lpDrv
);
695 /**************************************************************************
696 * DRIVER_RegisterDriver32 [internal]
698 * Creates all the WINE internal representations for a 32 bit driver.
699 * The driver is also open by sending the correct messages.
701 LPWINE_DRIVER
DRIVER_RegisterDriver32(LPCSTR lpName
, HMODULE hModule
, DRIVERPROC lpProc
,
702 LPARAM lParam
, BOOL bCallFrom32
)
706 lpDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER
));
708 lpDrv
->dwFlags
= WINE_GDF_EXIST
;
709 lpDrv
->dwDriverID
= 0;
710 lpDrv
->hDriver16
= DRIVER_CreateDrvr16();
711 lstrcpynA(lpDrv
->szAliasName
, lpName
, sizeof(lpDrv
->szAliasName
));
712 lpDrv
->d
.d32
.hModule
= hModule
;
713 lpDrv
->d
.d32
.lpDrvProc
= lpProc
;
715 if (!DRIVER_AddToList(lpDrv
, lParam
, bCallFrom32
)) {
716 HeapFree(GetProcessHeap(), 0, lpDrv
);
723 /**************************************************************************
724 * DRIVER_TryOpenDriver16 [internal]
726 * Tries to load a 16 bit driver whose DLL's (module) name is lpFileName.
728 static HDRVR16
DRIVER_TryOpenDriver16(LPCSTR lpFileName
, LPARAM lParam
, BOOL bCallFrom32
)
730 LPWINE_DRIVER lpDrv
= NULL
;
735 TRACE("('%s', %08lX, %d);\n", lpFileName
, lParam
, bCallFrom32
);
737 if (lstrlenA(lpFileName
) < 1)
740 lpSFN
= strrchr(lpFileName
, '\\');
741 lpSFN
= (lpSFN
) ? (lpSFN
+ 1) : lpFileName
;
743 if ((hModule
= LoadModule16(lpFileName
, (LPVOID
)-1)) >= 32) {
744 if ((lpProc
= (DRIVERPROC16
)WIN32_GetProcAddress16(hModule
, "DRIVERPROC")) != NULL
) {
745 lpDrv
= DRIVER_RegisterDriver16(lpSFN
, hModule
, lpProc
, lParam
, bCallFrom32
);
747 FreeLibrary16(hModule
);
748 TRACE("No DriverProc found\n");
752 TRACE("Unable to load 16 bit module (%s): %d\n", lpFileName
, hModule
);
754 return lpDrv
? lpDrv
->hDriver16
: 0;
757 /**************************************************************************
758 * DRIVER_TryOpenDriver32 [internal]
760 * Tries to load a 32 bit driver whose DLL's (module) name is lpFileName.
762 static HDRVR
DRIVER_TryOpenDriver32(LPCSTR lpFileName
, LPARAM lParam
, BOOL bCallFrom32
)
764 LPWINE_DRIVER lpDrv
= NULL
;
769 TRACE("('%s', %08lX, %d);\n", lpFileName
, lParam
, bCallFrom32
);
771 if (lstrlenA(lpFileName
) < 1)
774 lpSFN
= strrchr(lpFileName
, '\\');
775 lpSFN
= (lpSFN
) ? (lpSFN
+ 1) : lpFileName
;
777 if ((hModule
= LoadLibraryA(lpFileName
)) != 0) {
778 if ((lpProc
= GetProcAddress(hModule
, "DriverProc")) != NULL
) {
779 lpDrv
= DRIVER_RegisterDriver32(lpSFN
, hModule
, lpProc
, lParam
, bCallFrom32
);
781 FreeLibrary(hModule
);
783 TRACE("No DriverProc found\n");
786 TRACE("Unable to load 32 bit module \"%s\"\n", lpFileName
);
788 TRACE("=> %p\n", lpDrv
);
792 /**************************************************************************
793 * OpenDriver16 [USER.252]
795 HDRVR16 WINAPI
OpenDriver16(LPCSTR lpDriverName
, LPCSTR lpSectionName
, LPARAM lParam
)
800 TRACE("('%s', '%s', %08lX);\n", lpDriverName
, lpSectionName
, lParam
);
802 if (lpSectionName
== NULL
) {
803 hDriver
= DRIVER_TryOpenDriver16(lpDriverName
, lParam
, FALSE
);
805 hDriver
= DRIVER_TryOpenDriver32(lpDriverName
, lParam
, FALSE
);
808 /* in case hDriver is NULL, search in Drivers32 section */
809 lpSectionName
= "Drivers";
812 if (!hDriver
&& GetPrivateProfileStringA(lpSectionName
, lpDriverName
, "",
813 drvName
, sizeof(drvName
), "SYSTEM.INI") > 0) {
814 hDriver
= DRIVER_TryOpenDriver16(drvName
, lParam
, FALSE
);
817 ERR("Failed to open driver %s from system.ini file, section %s\n", lpDriverName
, lpSectionName
);
819 TRACE("=> %08x\n", hDriver
);
823 /**************************************************************************
824 * OpenDriverA [WINMM.15]
825 * (0,1,DRV_LOAD ,0 ,0)
826 * (0,1,DRV_ENABLE,0 ,0)
827 * (0,1,DRV_OPEN ,buf[256],0)
829 HDRVR WINAPI
OpenDriverA(LPCSTR lpDriverName
, LPCSTR lpSectionName
, LPARAM lParam
)
834 TRACE("(%s, %s, 0x%08lx);\n", debugstr_a(lpDriverName
), debugstr_a(lpSectionName
), lParam
);
836 if (lpSectionName
== NULL
) {
837 lstrcpynA(drvName
, lpDriverName
, sizeof(drvName
));
838 hDriver
= DRIVER_TryOpenDriver32(lpDriverName
, lParam
, TRUE
);
840 hDriver
= DRIVER_TryOpenDriver16(lpDriverName
, lParam
, TRUE
);
843 if (GetPrivateProfileStringA("Drivers32", lpDriverName
, "", drvName
,
844 sizeof(drvName
), "SYSTEM.INI")) {
845 hDriver
= DRIVER_TryOpenDriver32(drvName
, lParam
, TRUE
);
850 if (GetPrivateProfileStringA("Drivers", lpDriverName
, "", drvName
,
851 sizeof(drvName
), "SYSTEM.INI")) {
852 hDriver
= DRIVER_TryOpenDriver16(drvName
, lParam
, TRUE
);
857 if (GetPrivateProfileStringA(lpSectionName
, lpDriverName
, "", drvName
,
858 sizeof(drvName
), "SYSTEM.INI")) {
859 hDriver
= DRIVER_TryOpenDriver32(drvName
, lParam
, TRUE
);
861 hDriver
= DRIVER_TryOpenDriver16(drvName
, lParam
, TRUE
);
866 ERR("Failed to open driver %s from section %s\n", lpDriverName
, lpSectionName
);
868 TRACE("=> %08x\n", hDriver
);
872 /**************************************************************************
873 * OpenDriverW [WINMM.15]
875 HDRVR WINAPI
OpenDriverW(LPCWSTR lpDriverName
, LPCWSTR lpSectionName
, LPARAM lParam
)
877 LPSTR dn
= HEAP_strdupWtoA(GetProcessHeap(), 0, lpDriverName
);
878 LPSTR sn
= HEAP_strdupWtoA(GetProcessHeap(), 0, lpSectionName
);
879 HDRVR ret
= OpenDriverA(dn
, sn
, lParam
);
881 if (dn
) HeapFree(GetProcessHeap(), 0, dn
);
882 if (sn
) HeapFree(GetProcessHeap(), 0, sn
);
886 /**************************************************************************
887 * CloseDriver16 [USER.253]
889 LRESULT WINAPI
CloseDriver16(HDRVR16 hDrvr
, LPARAM lParam1
, LPARAM lParam2
)
891 TRACE("(%04x, %08lX, %08lX);\n", hDrvr
, lParam1
, lParam2
);
893 return DRIVER_CloseDriver(DRIVER_FindFromHDrvr16(hDrvr
), lParam1
, lParam2
);
896 /**************************************************************************
897 * CloseDriver [WINMM.4]
899 LRESULT WINAPI
CloseDriver(HDRVR hDrvr
, LPARAM lParam1
, LPARAM lParam2
)
901 TRACE("(%04x, %08lX, %08lX);\n", hDrvr
, lParam1
, lParam2
);
903 return DRIVER_CloseDriver(DRIVER_FindFromHDrvr(hDrvr
), lParam1
, lParam2
);
906 /**************************************************************************
907 * GetDriverModuleHandle [USER.254]
909 HMODULE16 WINAPI
GetDriverModuleHandle16(HDRVR16 hDrvr
)
912 HMODULE16 hModule
= 0;
914 TRACE("(%04x);\n", hDrvr
);
916 lpDrv
= DRIVER_FindFromHDrvr16(hDrvr
);
917 if (lpDrv
!= NULL
&& lpDrv
->hDriver16
== hDrvr
&& (lpDrv
->dwFlags
& WINE_GDF_16BIT
)) {
918 hModule
= lpDrv
->d
.d16
.hModule
;
920 TRACE("=> %d\n", hModule
);
924 /**************************************************************************
925 * GetDriverFlags [WINMM.13]
926 * [in] hDrvr handle to the driver
929 * 0x00000000 if hDrvr is an invalid handle
930 * 0x80000000 if hDrvr is a valid 32 bit driver
931 * 0x90000000 if hDrvr is a valid 16 bit driver
933 DWORD WINAPI
GetDriverFlags(HDRVR hDrvr
)
938 TRACE("(%04x)\n", hDrvr
);
940 if ((lpDrv
= DRIVER_FindFromHDrvr(hDrvr
)) != NULL
) {
941 ret
= lpDrv
->dwFlags
;
946 /**************************************************************************
947 * GetDriverModuleHandle [WINMM.14]
949 HMODULE WINAPI
GetDriverModuleHandle(HDRVR hDrvr
)
954 TRACE("(%04x);\n", hDrvr
);
956 lpDrv
= DRIVER_FindFromHDrvr(hDrvr
);
957 if (lpDrv
!= NULL
&& !(lpDrv
->dwFlags
& WINE_GDF_16BIT
)) {
958 hModule
= lpDrv
->d
.d32
.hModule
;
960 TRACE("=> %d\n", hModule
);
964 /**************************************************************************
965 * DefDriverProc16 [USER.255]
967 LRESULT WINAPI
DefDriverProc16(DWORD dwDevID
, HDRVR16 hDriv
, UINT16 wMsg
,
968 LPARAM lParam1
, LPARAM lParam2
)
970 TRACE("devID=0x%08lx hDrv=0x%04x wMsg=%04x lP1=0x%08lx lP2=0x%08lx\n",
971 dwDevID
, hDriv
, wMsg
, lParam1
, lParam2
);
981 case DRV_QUERYCONFIGURE
:
984 MessageBoxA(0, "Driver isn't configurable !", "Wine Driver", MB_OK
);
994 /**************************************************************************
995 * GetDriverInfo [USER.256]
997 BOOL16 WINAPI
GetDriverInfo16(HDRVR16 hDrvr
, LPDRIVERINFOSTRUCT16 lpDrvInfo
)
1002 TRACE("(%04x, %p);\n", hDrvr
, lpDrvInfo
);
1004 if (lpDrvInfo
== NULL
|| lpDrvInfo
->length
!= sizeof(DRIVERINFOSTRUCT16
))
1007 lpDrv
= DRIVER_FindFromHDrvr16(hDrvr
);
1008 if (lpDrv
!= NULL
&& lpDrv
->hDriver16
== hDrvr
&&
1009 (lpDrv
->dwFlags
& WINE_GDF_16BIT
)) {
1010 lpDrvInfo
->hDriver
= lpDrv
->hDriver16
;
1011 lpDrvInfo
->hModule
= lpDrv
->d
.d16
.hModule
;
1012 lstrcpynA(lpDrvInfo
->szAliasName
, lpDrv
->szAliasName
, sizeof(lpDrvInfo
->szAliasName
));
1019 /**************************************************************************
1020 * GetNextDriver [USER.257]
1022 HDRVR16 WINAPI
GetNextDriver16(HDRVR16 hDrvr
, DWORD dwFlags
)
1024 HDRVR16 hRetDrv
= 0;
1025 LPWINE_DRIVER lpDrv
;
1027 TRACE("(%04x, %08lX);\n", hDrvr
, dwFlags
);
1030 if (lpDrvItemList
== NULL
) {
1031 FIXME("drivers list empty !\n");
1032 /* FIXME: code was using DRIVER_LoadStartupDrivers(); before ?
1033 * I (EPP) don't quite understand this
1035 if (lpDrvItemList
== NULL
)
1038 lpDrv
= lpDrvItemList
;
1039 if (dwFlags
& GND_REVERSE
) {
1040 while (lpDrv
->lpNextItem
)
1041 lpDrv
= lpDrv
->lpNextItem
;
1044 lpDrv
= DRIVER_FindFromHDrvr16(hDrvr
);
1045 if (lpDrv
!= NULL
) {
1046 if (dwFlags
& GND_REVERSE
) {
1047 lpDrv
= (lpDrv
->lpPrevItem
) ? lpDrv
->lpPrevItem
: NULL
;
1049 lpDrv
= (lpDrv
->lpNextItem
) ? lpDrv
->lpNextItem
: NULL
;
1054 hRetDrv
= (lpDrv
) ? lpDrv
->hDriver16
: (HDRVR16
)0;
1055 TRACE("return %04x !\n", hRetDrv
);