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
12 #include "wine/winuser16.h"
21 static LPWINE_DRIVER lpDrvItemList = NULL;
24 * - LoadModule count and clean up is not handled correctly (it's not a problem as
25 * long as FreeLibrary is not working correctly)
26 * - msacm has some FIXME related to new code here...
29 /**************************************************************************
30 * LoadStartupDrivers [internal]
32 static void WINE_UNUSED DRIVER_LoadStartupDrivers(void)
38 if (GetPrivateProfileStringA("drivers", NULL, "", str, sizeof(str), "SYSTEM.INI") < 2) {
39 ERR(driver,"Can't find drivers section in system.ini\n");
43 for (ptr = str; lstrlenA(ptr) != 0; ptr += lstrlenA(ptr) + 1) {
44 TRACE(driver, "str='%s'\n", ptr);
45 hDrv = OpenDriver16(ptr, "drivers", 0L);
46 TRACE(driver, "hDrv=%04x\n", hDrv);
48 TRACE(driver, "end of list !\n");
52 /**************************************************************************
53 * DRIVER_GetNumberOfModuleRefs [internal]
55 * Returns the number of open drivers which share the same module.
57 static WORD DRIVER_GetNumberOfModuleRefs(LPWINE_DRIVER lpNewDrv)
60 DWORD type = lpNewDrv->dwFlags & WINE_DI_TYPE_MASK;
63 for (lpDrv = lpDrvItemList; lpDrv; lpDrv = lpDrv->lpNextItem) {
64 if ((lpDrv->dwFlags & WINE_DI_TYPE_MASK) == type) {
67 if (lpDrv->d.d16.hModule == lpNewDrv->d.d16.hModule)
71 if (lpDrv->d.d32.hModule == lpNewDrv->d.d32.hModule)
75 FIXME(driver, "Unsupported driver type: %ld\n", type);
83 /**************************************************************************
84 * DRIVER_FindFromHDrvr16 [internal]
86 * From a hDrvr being 16 bits, returns the WINE internal structure.
88 static LPWINE_DRIVER DRIVER_FindFromHDrvr16(HDRVR16 hDrvr)
92 for (lpDrv = lpDrvItemList; lpDrv; lpDrv = lpDrv->lpNextItem) {
93 if (lpDrv->hDriver16 == hDrvr) {
100 /**************************************************************************
101 * DRIVER_FindFromHDrvr [internal]
103 * From a hDrvr (being 16 or 32 bits), returns the WINE internal structure.
105 static LPWINE_DRIVER DRIVER_FindFromHDrvr(HDRVR hDrvr)
107 if (!IsBadWritePtr((void*)hDrvr, sizeof(DWORD)) &&
108 ((LPWINE_DRIVER)hDrvr)->dwMagic == WINE_DI_MAGIC) {
109 return (LPWINE_DRIVER)hDrvr;
111 return DRIVER_FindFromHDrvr16(hDrvr);
114 int DRIVER_GetType(HDRVR hDrvr)
116 LPWINE_DRIVER lpDrv = DRIVER_FindFromHDrvr(hDrvr);
118 return (lpDrv) ? (lpDrv->dwFlags & WINE_DI_TYPE_MASK) : 0;
121 /**************************************************************************
122 * DRIVER_MapMsg16To32 [internal]
124 * Map a 16 bit driver message to a 32 bit driver message.
125 * 1 : ok, some memory allocated, need to call DRIVER_UnMapMsg16To32
126 * 0 : ok, no memory allocated
127 * -1 : ko, unknown message
128 * -2 : ko, memory problem
130 int DRIVER_MapMsg16To32(WORD wMsg, DWORD* lParam1, DWORD* lParam2)
139 case DRV_QUERYCONFIGURE:
141 case DRV_EXITSESSION:
142 case DRV_EXITAPPLICATION:
144 /* lParam1 and lParam2 are not used */
149 /* lParam1 is a NULL terminated string */
150 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
152 *lParam1 = (DWORD)PTR_SEG_TO_LIN(*lParam1);
153 if (*lParam2 && wMsg == DRV_OPEN) {
154 LPMCI_OPEN_DRIVER_PARMS16 modp16 = PTR_SEG_TO_LIN(*lParam2);
155 char* ptr = HeapAlloc(SystemHeap, 0, sizeof(LPMCI_OPEN_DRIVER_PARMS16) + sizeof(MCI_OPEN_DRIVER_PARMSA));
156 LPMCI_OPEN_DRIVER_PARMSA modp32;
159 *(LPMCI_OPEN_DRIVER_PARMS16*)ptr = modp16;
160 modp32 = (LPMCI_OPEN_DRIVER_PARMSA)(ptr + sizeof(LPMCI_OPEN_DRIVER_PARMSA));
162 modp32->wDeviceID = modp16->wDeviceID;
163 modp32->lpstrParams = PTR_SEG_TO_LIN(modp16->lpstrParams);
167 *lParam2 = (DWORD)modp32;
173 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO */
175 LPDRVCONFIGINFO dci32 = HeapAlloc(SystemHeap, 0, sizeof(DRVCONFIGINFO));
176 LPDRVCONFIGINFO16 dci16 = PTR_SEG_TO_LIN(*lParam2);
179 dci32->dwDCISize = sizeof(DRVCONFIGINFO);
180 dci32->lpszDCISectionName = HEAP_strdupAtoW(SystemHeap, 0, PTR_SEG_TO_LIN(dci16->lpszDCISectionName));
181 dci32->lpszDCIAliasName = HEAP_strdupAtoW(SystemHeap, 0, PTR_SEG_TO_LIN(dci16->lpszDCIAliasName));
182 if (dci32->lpszDCISectionName == NULL || dci32->lpszDCIAliasName == NULL)
187 *lParam2 = (DWORD)dci32;
194 if (wMsg >= 0x800 && wMsg < 0x900) {
195 /* FIXME: another hack to handle MCI messages...
196 * should find a *NICE* way to integrate DRIVER_ and
197 * MCI_ mapping/unmapping functions
201 FIXME(driver, "Unknown message 0x%04x\n", wMsg);
207 /**************************************************************************
208 * DRIVER_MapMsg16To32 [internal]
210 * UnMap a 16 bit driver message to a 32 bit driver message.
213 * -2 : ko, memory problem
215 int DRIVER_UnMapMsg16To32(WORD wMsg, DWORD lParam1, DWORD lParam2)
224 case DRV_QUERYCONFIGURE:
226 case DRV_EXITSESSION:
227 case DRV_EXITAPPLICATION:
229 /* lParam1 and lParam2 are not used */
232 /* lParam1 is a NULL terminated string */
233 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
234 if (lParam2 && wMsg == DRV_OPEN) {
235 LPMCI_OPEN_DRIVER_PARMSA modp32 = (LPMCI_OPEN_DRIVER_PARMSA)lParam2;
236 LPMCI_OPEN_DRIVER_PARMS16 modp16 = *(LPMCI_OPEN_DRIVER_PARMS16*)(lParam2 - sizeof(LPMCI_OPEN_DRIVER_PARMSA));
238 modp16->wCustomCommandTable = modp32->wCustomCommandTable;
239 modp16->wType = modp32->wType;
240 if (!HeapFree(SystemHeap, 0, modp32))
241 FIXME(driver, "bad free line=%d\n", __LINE__);
247 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
249 LPDRVCONFIGINFO dci32 = (LPDRVCONFIGINFO)lParam2;
250 if (!HeapFree(SystemHeap, 0, (LPVOID)dci32->lpszDCISectionName))
251 FIXME(driver, "bad free line=%d\n", __LINE__);
252 if (!HeapFree(SystemHeap, 0, (LPVOID)dci32->lpszDCIAliasName))
253 FIXME(driver, "bad free line=%d\n", __LINE__);
254 if (!HeapFree(SystemHeap, 0, dci32))
255 FIXME(driver, "bad free line=%d\n", __LINE__);
260 if (wMsg >= 0x800 && wMsg < 0x900) {
261 /* FIXME: another hack to handle MCI messages...
262 * should find a *NICE* way to integrate DRIVER_ and
263 * MCI_ mapping/unmapping functions
267 FIXME(driver, "Unknown message 0x%04x\n", wMsg);
273 /**************************************************************************
274 * DRIVER_MapMsg32To16 [internal]
276 * Map a 32 bit driver message to a 16 bit driver message.
277 * 1 : ok, some memory allocated, need to call DRIVER_UnMapMsg32To16
278 * 0 : ok, no memory allocated
279 * -1 : ko, unknown message
280 * -2 : ko, memory problem
282 int DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lParam2)
291 case DRV_QUERYCONFIGURE:
293 case DRV_EXITSESSION:
294 case DRV_EXITAPPLICATION:
296 /* lParam1 and lParam2 are not used */
301 /* lParam1 is a NULL terminated string */
302 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
304 LPSTR str = SEGPTR_STRDUP((LPSTR)*lParam1);
306 *lParam1 = (LPARAM)SEGPTR_GET(str);
314 if (*lParam2 && wMsg == DRV_OPEN) {
315 LPMCI_OPEN_DRIVER_PARMS16 modp16;
316 char* ptr = SEGPTR_ALLOC(sizeof(LPMCI_OPEN_DRIVER_PARMSA) + sizeof(MCI_OPEN_DRIVER_PARMS16));
317 LPMCI_OPEN_DRIVER_PARMSA modp32 = (LPMCI_OPEN_DRIVER_PARMSA)(*lParam2);
320 *(LPMCI_OPEN_DRIVER_PARMSA*)ptr = modp32;
321 modp16 = (LPMCI_OPEN_DRIVER_PARMS16)(ptr + sizeof(LPMCI_OPEN_DRIVER_PARMSA));
323 modp16->wDeviceID = modp32->wDeviceID;
324 modp16->lpstrParams = PTR_SEG_TO_LIN(modp32->lpstrParams);
328 *lParam2 = (DWORD)SEGPTR_GET(modp16);
334 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO */
336 LPDRVCONFIGINFO16 dci16 = (LPDRVCONFIGINFO16)SEGPTR_ALLOC(sizeof(DRVCONFIGINFO16));
337 LPDRVCONFIGINFO dci32 = (LPDRVCONFIGINFO)lParam2;
342 dci16->dwDCISize = sizeof(DRVCONFIGINFO16);
344 if ((str1 = HEAP_strdupWtoA(SystemHeap, 0, dci32->lpszDCISectionName)) != NULL &&
345 (str2 = SEGPTR_STRDUP(str1)) != NULL) {
346 dci16->lpszDCISectionName = (LPSTR)SEGPTR_GET(str2);
347 if (!HeapFree(SystemHeap, 0, str1))
348 FIXME(driver, "bad free line=%d\n", __LINE__);
352 if ((str1 = HEAP_strdupWtoA(SystemHeap, 0, dci32->lpszDCIAliasName)) != NULL &&
353 (str2 = SEGPTR_STRDUP(str1)) != NULL) {
354 dci16->lpszDCIAliasName = (LPSTR)SEGPTR_GET(str2);
355 if (!HeapFree(SystemHeap, 0, str1))
356 FIXME(driver, "bad free line=%d\n", __LINE__);
363 *lParam2 = (LPARAM)SEGPTR_GET(dci16);
370 if (wMsg >= 0x800 && wMsg < 0x900) {
371 /* FIXME: another hack to handle MCI messages...
372 * should find a *NICE* way to integrate DRIVER_ and
373 * MCI_ mapping/unmapping functions
377 FIXME(driver, "Unknown message 0x%04x\n", wMsg);
383 /**************************************************************************
384 * DRIVER_UnMapMsg32To16 [internal]
386 * UnMap a 32 bit driver message to a 16 bit driver message.
389 * -2 : ko, memory problem
391 int DRIVER_UnMapMsg32To16(WORD wMsg, DWORD lParam1, DWORD lParam2)
400 case DRV_QUERYCONFIGURE:
402 case DRV_EXITSESSION:
403 case DRV_EXITAPPLICATION:
405 /* lParam1 and lParam2 are not used */
408 /* lParam1 is a NULL terminated string, lParam2 is unknown => may lead to some problem */
409 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
410 if (lParam1) if (!SEGPTR_FREE(PTR_SEG_TO_LIN(lParam1)))
411 FIXME(driver, "bad free line=%d\n", __LINE__);
413 if (lParam2 && wMsg == DRV_OPEN) {
414 LPMCI_OPEN_DRIVER_PARMS16 modp16 = (LPMCI_OPEN_DRIVER_PARMS16)PTR_SEG_TO_LIN(lParam2);
415 LPMCI_OPEN_DRIVER_PARMSA modp32 = *(LPMCI_OPEN_DRIVER_PARMSA*)((char*)modp16 - sizeof(LPMCI_OPEN_DRIVER_PARMSA));
417 modp32->wCustomCommandTable = modp16->wCustomCommandTable;
418 modp32->wType = modp16->wType;
419 if (!SEGPTR_FREE((char*)modp16 - sizeof(LPMCI_OPEN_DRIVER_PARMSA)))
420 FIXME(driver, "bad free line=%d\n", __LINE__);
426 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
428 LPDRVCONFIGINFO16 dci16 = (LPDRVCONFIGINFO16)PTR_SEG_TO_LIN(lParam2);
430 if (!SEGPTR_FREE(PTR_SEG_TO_LIN(dci16->lpszDCISectionName)))
431 FIXME(driver, "bad free line=%d\n", __LINE__);
432 if (!SEGPTR_FREE(PTR_SEG_TO_LIN(dci16->lpszDCIAliasName)))
433 FIXME(driver, "bad free line=%d\n", __LINE__);
434 if (!SEGPTR_FREE(dci16))
435 FIXME(driver, "bad free line=%d\n", __LINE__);
440 if (wMsg >= 0x800 && wMsg < 0x900) {
441 /* FIXME: another hack to handle MCI messages...
442 * should find a *NICE* way to integrate DRIVER_ and
443 * MCI_ mapping/unmapping functions
447 FIXME(driver, "Unknown message 0x%04x\n", wMsg);
453 /**************************************************************************
454 * SendDriverMessage [USER.251]
456 LRESULT WINAPI SendDriverMessage16(HDRVR16 hDriver, UINT16 msg, LPARAM lParam1,
463 TRACE(driver, "(%04x, %04X, %08lX, %08lX)\n", hDriver, msg, lParam1, lParam2);
465 lpDrv = DRIVER_FindFromHDrvr16(hDriver);
466 if (lpDrv != NULL && lpDrv->hDriver16 == hDriver) {
467 switch (lpDrv->dwFlags & WINE_DI_TYPE_MASK) {
468 case WINE_DI_TYPE_16:
469 TRACE(driver, "Before CallDriverProc proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
470 lpDrv->d.d16.lpDrvProc, lpDrv->dwDriverID, hDriver, msg, lParam1, lParam2);
471 retval = Callbacks->CallDriverProc(lpDrv->d.d16.lpDrvProc, lpDrv->dwDriverID, hDriver,
472 msg, lParam1, lParam2);
474 case WINE_DI_TYPE_32:
475 mapRet = DRIVER_MapMsg16To32(msg, &lParam1, &lParam2);
477 TRACE(driver, "Before func32 call proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
478 lpDrv->d.d32.lpDrvProc, lpDrv->dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2);
479 retval = lpDrv->d.d32.lpDrvProc(lpDrv->dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2);
481 DRIVER_UnMapMsg16To32(msg, lParam1, lParam2);
488 FIXME(driver, "Unknown driver type %08lx\n", lpDrv->dwFlags);
492 WARN(driver, "Bad driver handle %u\n", hDriver);
495 TRACE(driver, "retval = %ld\n", retval);
499 /**************************************************************************
500 * SendDriverMessage [WINMM.19]
502 LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT msg, LPARAM lParam1,
509 TRACE(driver, "(%04x, %04X, %08lX, %08lX)\n", hDriver, msg, lParam1, lParam2);
511 lpDrv = DRIVER_FindFromHDrvr(hDriver);
514 switch (lpDrv->dwFlags & WINE_DI_TYPE_MASK) {
515 case WINE_DI_TYPE_16:
516 mapRet = DRIVER_MapMsg32To16(msg, &lParam1, &lParam2);
518 TRACE(driver, "Before CallDriverProc proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
519 lpDrv->d.d16.lpDrvProc, lpDrv->dwDriverID, lpDrv->hDriver16, msg, lParam1, lParam2);
520 retval = Callbacks->CallDriverProc(lpDrv->d.d16.lpDrvProc, lpDrv->dwDriverID, lpDrv->hDriver16,
521 msg, lParam1, lParam2);
523 DRIVER_UnMapMsg32To16(msg, lParam1, lParam2);
529 case WINE_DI_TYPE_32:
530 TRACE(driver, "Before func32 call proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
531 lpDrv->d.d32.lpDrvProc, lpDrv->dwDriverID, hDriver, msg, lParam1, lParam2);
532 retval = lpDrv->d.d32.lpDrvProc(lpDrv->dwDriverID, hDriver, msg, lParam1, lParam2);
535 FIXME(driver, "Unknown driver type %08lx\n", lpDrv->dwFlags);
539 WARN(driver, "Bad driver handle %u\n", hDriver);
541 TRACE(driver, "retval = %ld\n", retval);
546 /**************************************************************************
547 * DRIVER_RemoveFromList [internal]
549 * Generates all the logic to handle driver closure / deletion
550 * Removes a driver struct to the list of open drivers.
552 static BOOL DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv)
554 lpDrv->dwDriverID = 0;
555 if (DRIVER_GetNumberOfModuleRefs(lpDrv) == 1) {
556 SendDriverMessage((HDRVR)lpDrv, DRV_DISABLE, 0L, 0L);
557 SendDriverMessage((HDRVR)lpDrv, DRV_FREE, 0L, 0L);
559 if (lpDrv->lpPrevItem)
560 lpDrv->lpPrevItem->lpNextItem = lpDrv->lpNextItem;
562 lpDrvItemList = lpDrv->lpNextItem;
563 if (lpDrv->lpNextItem)
564 lpDrv->lpNextItem->lpPrevItem = lpDrv->lpPrevItem;
569 /**************************************************************************
570 * DRIVER_AddToList [internal]
572 * Adds a driver struct to the list of open drivers.
573 * Generates all the logic to handle driver creation / open.
575 static BOOL DRIVER_AddToList(LPWINE_DRIVER lpNewDrv, LPARAM lParam, BOOL bCallFrom32)
577 lpNewDrv->dwMagic = WINE_DI_MAGIC;
578 /* First driver to be loaded for this module, need to load correctly the module */
579 if (DRIVER_GetNumberOfModuleRefs(lpNewDrv) == 0) {
580 if (SendDriverMessage((HDRVR)lpNewDrv, DRV_LOAD, 0L, 0L) != DRV_SUCCESS) {
581 TRACE(driver, "DRV_LOAD failed on driver 0x%08lx\n", (DWORD)lpNewDrv);
584 if (SendDriverMessage((HDRVR)lpNewDrv, DRV_ENABLE, 0L, 0L) != DRV_SUCCESS) {
585 TRACE(driver, "DRV_ENABLE failed on driver 0x%08lx\n", (DWORD)lpNewDrv);
590 lpNewDrv->lpNextItem = NULL;
591 if (lpDrvItemList == NULL) {
592 lpDrvItemList = lpNewDrv;
593 lpNewDrv->lpPrevItem = NULL;
595 LPWINE_DRIVER lpDrv = lpDrvItemList; /* find end of list */
596 while (lpDrv->lpNextItem != NULL)
597 lpDrv = lpDrv->lpNextItem;
599 lpDrv->lpNextItem = lpNewDrv;
600 lpNewDrv->lpPrevItem = lpDrv;
603 /* Now just open a new instance of a driver on this module */
605 lpNewDrv->dwDriverID = SendDriverMessage((HDRVR)lpNewDrv, DRV_OPEN, 0L, lParam);
607 lpNewDrv->dwDriverID = SendDriverMessage16(lpNewDrv->hDriver16, DRV_OPEN, 0L, lParam);
609 if (lpNewDrv->dwDriverID == 0) {
610 TRACE(driver, "DRV_OPEN failed on driver 0x%08lx\n", (DWORD)lpNewDrv);
611 DRIVER_RemoveFromList(lpNewDrv);
618 /**************************************************************************
619 * DRIVER_CreateDrvr16 [internal]
621 * Creates unique ID for 16 bit drivers.
623 static HDRVR16 DRIVER_CreateDrvr16()
625 static WORD DRIVER_hDrvr16Counter = 0;
627 while (DRIVER_FindFromHDrvr16(++DRIVER_hDrvr16Counter));
628 return DRIVER_hDrvr16Counter;
631 /**************************************************************************
632 * DRIVER_RegisterDriver16 [internal]
634 * Creates all the WINE internal representations for a 16 bit driver.
635 * The driver is also open by sending the correct messages.
637 LPWINE_DRIVER DRIVER_RegisterDriver16(LPCSTR lpName, HMODULE16 hModule, DRIVERPROC16 lpProc,
638 LPARAM lParam, BOOL bCallFrom32)
642 lpDrv = HeapAlloc(SystemHeap, 0, sizeof(WINE_DRIVER));
644 lpDrv->dwFlags = WINE_DI_TYPE_16;
645 lpDrv->dwDriverID = 0;
646 lpDrv->hDriver16 = DRIVER_CreateDrvr16();
647 strncpy(lpDrv->szAliasName, lpName, sizeof(lpDrv->szAliasName));
648 lpDrv->d.d16.hModule = hModule;
649 lpDrv->d.d16.lpDrvProc = lpProc;
651 if (!DRIVER_AddToList(lpDrv, lParam, bCallFrom32)) {
652 HeapFree(SystemHeap, 0, lpDrv);
659 /**************************************************************************
660 * DRIVER_RegisterDriver32 [internal]
662 * Creates all the WINE internal representations for a 32 bit driver.
663 * The driver is also open by sending the correct messages.
665 LPWINE_DRIVER DRIVER_RegisterDriver32(LPCSTR lpName, HMODULE hModule, DRIVERPROC lpProc,
666 LPARAM lParam, BOOL bCallFrom32)
670 lpDrv = HeapAlloc(SystemHeap, 0, sizeof(WINE_DRIVER));
672 lpDrv->dwFlags = WINE_DI_TYPE_32;
673 lpDrv->dwDriverID = 0;
674 lpDrv->hDriver16 = DRIVER_CreateDrvr16();
675 strncpy(lpDrv->szAliasName, lpName, sizeof(lpDrv->szAliasName));
676 lpDrv->d.d32.hModule = hModule;
677 lpDrv->d.d32.lpDrvProc = lpProc;
679 if (!DRIVER_AddToList(lpDrv, lParam, bCallFrom32)) {
680 HeapFree(SystemHeap, 0, lpDrv);
687 /**************************************************************************
688 * DRIVER_TryOpenDriver16 [internal]
690 * Tries to load a 16 bit driver whose DLL's (module) name is lpFileName.
692 static HDRVR16 DRIVER_TryOpenDriver16(LPCSTR lpFileName, LPARAM lParam, BOOL bCallFrom32)
694 LPWINE_DRIVER lpDrv = NULL;
699 TRACE(driver,"('%s', %08lX);\n", lpFileName, lParam);
701 if (lstrlenA(lpFileName) < 1)
704 lpSFN = strrchr(lpFileName, '\\');
705 lpSFN = (lpSFN) ? (lpSFN + 1) : lpFileName;
707 if ((hModule = LoadModule16(lpFileName, (LPVOID)-1)) != 0) {
708 if ((lpProc = (DRIVERPROC16)WIN32_GetProcAddress16(hModule, "DRIVERPROC")) != NULL) {
709 lpDrv = DRIVER_RegisterDriver16(lpSFN, hModule, lpProc, lParam, bCallFrom32);
711 TRACE(driver, "No DriverProc found\n");
714 TRACE(driver, "Unable to load 16 bit module (%s)\n", lpFileName);
716 return lpDrv ? lpDrv->hDriver16 : 0;
719 /**************************************************************************
720 * DRIVER_TryOpenDriver32 [internal]
722 * Tries to load a 32 bit driver whose DLL's (module) name is lpFileName.
724 static HDRVR DRIVER_TryOpenDriver32(LPCSTR lpFileName, LPARAM lParam, BOOL bCallFrom32)
726 LPWINE_DRIVER lpDrv = NULL;
731 TRACE(driver,"('%s', %08lX);\n", lpFileName, lParam);
733 if (lstrlenA(lpFileName) < 1)
736 lpSFN = strrchr(lpFileName, '\\');
737 lpSFN = (lpSFN) ? (lpSFN + 1) : lpFileName;
739 if ((hModule = LoadLibraryA(lpFileName)) != 0) {
740 if ((lpProc = GetProcAddress(hModule, "DriverProc")) != NULL) {
741 lpDrv = DRIVER_RegisterDriver32(lpSFN, hModule, lpProc, lParam, bCallFrom32);
743 TRACE(driver, "No DriverProc found\n");
746 TRACE(driver, "Unable to load 32 bit module \"%s\"\n", lpFileName);
748 TRACE(driver, "=> %p\n", lpDrv);
752 /**************************************************************************
753 * OpenDriver16 [USER.252]
755 HDRVR16 WINAPI OpenDriver16(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam)
760 TRACE(driver,"('%s', '%s', %08lX);\n", lpDriverName, lpSectionName, lParam);
762 if (lpSectionName == NULL) {
763 hDriver = DRIVER_TryOpenDriver16(lpDriverName, lParam, FALSE);
765 /* in case hDriver is NULL, search in Drivers32 section */
766 lpSectionName = "Drivers";
769 if (!hDriver && GetPrivateProfileStringA(lpSectionName, lpDriverName, "",
770 drvName, sizeof(drvName), "SYSTEM.INI") > 0) {
771 hDriver = DRIVER_TryOpenDriver16(drvName, lParam, FALSE);
776 /**************************************************************************
777 * OpenDriver32A [WINMM.15]
778 * (0,1,DRV_LOAD ,0 ,0)
779 * (0,1,DRV_ENABLE,0 ,0)
780 * (0,1,DRV_OPEN ,buf[256],0)
782 HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam)
787 TRACE(driver,"('%s', '%s', %08lX);\n", lpDriverName, lpSectionName, lParam);
789 if (lpSectionName == NULL) {
790 strncpy(drvName, lpDriverName, sizeof(drvName));
791 hDriver = DRIVER_TryOpenDriver32(lpDriverName, lParam, TRUE);
793 hDriver = DRIVER_TryOpenDriver16(lpDriverName, lParam, TRUE);
796 if (GetPrivateProfileStringA("Drivers32", lpDriverName, "", drvName,
797 sizeof(drvName), "SYSTEM.INI")) {
798 hDriver = DRIVER_TryOpenDriver32(drvName, lParam, TRUE);
803 if (GetPrivateProfileStringA("Drivers", lpDriverName, "", drvName,
804 sizeof(drvName), "SYSTEM.INI")) {
805 hDriver = DRIVER_TryOpenDriver16(drvName, lParam, TRUE);
810 if (GetPrivateProfileStringA(lpSectionName, lpDriverName, "", drvName,
811 sizeof(drvName), "SYSTEM.INI")) {
812 hDriver = DRIVER_TryOpenDriver32(drvName, lParam, TRUE);
814 hDriver = DRIVER_TryOpenDriver16(drvName, lParam, TRUE);
818 TRACE(driver, "retval='%08x'\n", hDriver);
822 /**************************************************************************
823 * OpenDriver32W [WINMM.15]
825 HDRVR WINAPI OpenDriverW(LPCWSTR lpDriverName, LPCWSTR lpSectionName, LPARAM lParam)
827 LPSTR dn = HEAP_strdupWtoA(GetProcessHeap(), 0, lpDriverName);
828 LPSTR sn = HEAP_strdupWtoA(GetProcessHeap(), 0, lpSectionName);
829 HDRVR ret = OpenDriverA(dn, sn, lParam);
831 if (dn) HeapFree(GetProcessHeap(), 0, dn);
832 if (sn) HeapFree(GetProcessHeap(), 0, sn);
836 /**************************************************************************
837 * CloseDriver [USER.253]
839 LRESULT WINAPI CloseDriver16(HDRVR16 hDrvr, LPARAM lParam1, LPARAM lParam2)
843 TRACE(driver, "(%04x, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
845 lpDrv = DRIVER_FindFromHDrvr16(hDrvr);
847 SendDriverMessage((HDRVR)lpDrv, DRV_CLOSE, lParam1, lParam2);
849 if (DRIVER_RemoveFromList(lpDrv)) {
850 TRACE(driver, "hDrvr=%04x closed !\n", hDrvr);
857 /**************************************************************************
858 * CloseDriver32 [WINMM.4]
860 LRESULT WINAPI CloseDriver(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
864 TRACE(driver, "(%04x, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
866 lpDrv = DRIVER_FindFromHDrvr(hDrvr);
868 SendDriverMessage((HDRVR)lpDrv, DRV_CLOSE, lParam1, lParam2);
870 if (DRIVER_RemoveFromList(lpDrv)) {
871 TRACE(driver, "hDrvr=%08x closed !\n", hDrvr);
878 /**************************************************************************
879 * GetDriverModuleHandle [USER.254]
881 HMODULE16 WINAPI GetDriverModuleHandle16(HDRVR16 hDrvr)
884 HMODULE16 hModule = 0;
886 TRACE(driver, "(%04x);\n", hDrvr);
888 lpDrv = DRIVER_FindFromHDrvr16(hDrvr);
889 if (lpDrv != NULL && lpDrv->hDriver16 == hDrvr &&
890 (lpDrv->dwFlags & WINE_DI_TYPE_MASK) == WINE_DI_TYPE_16) {
891 hModule = lpDrv->d.d16.hModule;
896 /**************************************************************************
897 * GetDriverModuleHandle [USER.254]
899 HMODULE WINAPI GetDriverModuleHandle(HDRVR hDrvr)
904 TRACE(driver, "(%04x);\n", hDrvr);
906 lpDrv = DRIVER_FindFromHDrvr(hDrvr);
907 if (lpDrv != NULL && (lpDrv->dwFlags & WINE_DI_TYPE_MASK) == WINE_DI_TYPE_32) {
908 hModule = lpDrv->d.d32.hModule;
913 /**************************************************************************
914 * DefDriverProc16 [USER.255]
916 LRESULT WINAPI DefDriverProc16(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg,
917 LPARAM lParam1, LPARAM lParam2)
919 TRACE(driver, "devID=0x%08lx hDrv=0x%04x wMsg=%04x lP1=0x%08lx lP2=0x%08lx\n",
920 dwDevID, hDriv, wMsg, lParam1, lParam2);
930 case DRV_QUERYCONFIGURE:
933 MessageBoxA(0, "Driver isn't configurable !", "Wine Driver", MB_OK);
943 /**************************************************************************
944 * GetDriverInfo [USER.256]
946 BOOL16 WINAPI GetDriverInfo16(HDRVR16 hDrvr, LPDRIVERINFOSTRUCT16 lpDrvInfo)
951 TRACE(driver, "(%04x, %p);\n", hDrvr, lpDrvInfo);
953 if (lpDrvInfo == NULL ||
954 lpDrvInfo->length != sizeof(DRIVERINFOSTRUCT16)) return FALSE;
956 lpDrv = DRIVER_FindFromHDrvr16(hDrvr);
957 if (lpDrv != NULL && lpDrv->hDriver16 == hDrvr &&
958 (lpDrv->dwFlags & WINE_DI_TYPE_MASK) == WINE_DI_TYPE_16) {
959 lpDrvInfo->hDriver = lpDrv->hDriver16;
960 lpDrvInfo->hModule = lpDrv->d.d16.hModule;
961 strncpy(lpDrvInfo->szAliasName, lpDrv->szAliasName, sizeof(lpDrvInfo->szAliasName));
968 /**************************************************************************
969 * GetNextDriver [USER.257]
971 HDRVR16 WINAPI GetNextDriver16(HDRVR16 hDrvr, DWORD dwFlags)
976 TRACE(driver, "(%04x, %08lX);\n", hDrvr, dwFlags);
979 if (lpDrvItemList == NULL) {
980 FIXME(driver, "drivers list empty !\n");
981 /* FIXME: code was using DRIVER_LoadStartupDrivers(); before ?
982 * I (EPP) don't quite understand this
984 if (lpDrvItemList == NULL) return 0;
986 lpDrv = lpDrvItemList;
987 if (dwFlags & GND_REVERSE) {
988 while (lpDrv->lpNextItem)
989 lpDrv = lpDrv->lpNextItem;
992 lpDrv = DRIVER_FindFromHDrvr16(hDrvr);
994 if (dwFlags & GND_REVERSE) {
995 lpDrv = (lpDrv->lpPrevItem) ? lpDrv->lpPrevItem : NULL;
997 lpDrv = (lpDrv->lpNextItem) ? lpDrv->lpNextItem : NULL;
1002 hRetDrv = (lpDrv) ? lpDrv->hDriver16 : (HDRVR16)0;
1003 TRACE(driver, "return %04x !\n", hRetDrv);