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) || (wMsg >= 0x4000 && wMsg < 0x4100 )) {
224 /* FIXME: another hack to handle MCI and ICM 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) || (wMsg >= 0x4000 && wMsg < 0x4100 )) {
290 /* FIXME: another hack to handle MCI and ICM 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) || (wMsg >= 0x4000 && wMsg < 0x4100 )) {
400 /* FIXME: another hack to handle MCI and ICM 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) || (wMsg >= 0x4000 && wMsg < 0x4100 )) {
470 /* FIXME: another hack to handle MCI and ICM 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;
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 system.ini file, 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, 0x%08lx);\n", debugstr_a(lpDriverName), debugstr_a(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);