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
17 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(driver)
22 static LPWINE_DRIVER lpDrvItemList = NULL;
25 * - LoadModule count and clean up is not handled correctly (it's not a problem as
26 * long as FreeLibrary is not working correctly)
27 * - msacm has some FIXME related to new code here...
30 /**************************************************************************
31 * LoadStartupDrivers [internal]
33 static void WINE_UNUSED DRIVER_LoadStartupDrivers(void)
37 if (GetPrivateProfileStringA("drivers", NULL, "", str, sizeof(str), "SYSTEM.INI") < 2) {
38 ERR("Can't find drivers section in system.ini\n");
43 for (ptr = str; lstrlenA(ptr) != 0; ptr += lstrlenA(ptr) + 1) {
44 TRACE("str='%s'\n", ptr);
45 hDrv = OpenDriver16(ptr, "drivers", 0L);
46 TRACE("hDrv=%04x\n", hDrv);
48 TRACE("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("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(WINE_DRIVER)) &&
108 ((LPWINE_DRIVER)hDrvr)->dwMagic == WINE_DI_MAGIC) {
109 return (LPWINE_DRIVER)hDrvr;
111 return DRIVER_FindFromHDrvr16(hDrvr);
114 /**************************************************************************
115 * DRIVER_GetType [internal]
117 * From a hDrvr (being 16 or 32 bits), returns the WINE internal structure.
119 int DRIVER_GetType(HDRVR hDrvr)
121 LPWINE_DRIVER lpDrv = DRIVER_FindFromHDrvr(hDrvr);
123 return (lpDrv) ? (lpDrv->dwFlags & WINE_DI_TYPE_MASK) : 0;
126 /**************************************************************************
127 * DRIVER_MapMsg16To32 [internal]
129 * Map a 16 bit driver message to a 32 bit driver message.
130 * 1 : ok, some memory allocated, need to call DRIVER_UnMapMsg16To32
131 * 0 : ok, no memory allocated
132 * -1 : ko, unknown message
133 * -2 : ko, memory problem
135 static int DRIVER_MapMsg16To32(WORD wMsg, DWORD* lParam1, DWORD* lParam2)
144 case DRV_QUERYCONFIGURE:
146 case DRV_EXITSESSION:
147 case DRV_EXITAPPLICATION:
149 /* lParam1 and lParam2 are not used */
154 /* lParam1 is a NULL terminated string */
155 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
157 *lParam1 = (DWORD)PTR_SEG_TO_LIN(*lParam1);
158 if (*lParam2 && wMsg == DRV_OPEN) {
159 LPMCI_OPEN_DRIVER_PARMS16 modp16 = PTR_SEG_TO_LIN(*lParam2);
160 char* ptr = HeapAlloc(SystemHeap, 0, sizeof(LPMCI_OPEN_DRIVER_PARMS16) + sizeof(MCI_OPEN_DRIVER_PARMSA));
161 LPMCI_OPEN_DRIVER_PARMSA modp32;
164 *(LPMCI_OPEN_DRIVER_PARMS16*)ptr = modp16;
165 modp32 = (LPMCI_OPEN_DRIVER_PARMSA)(ptr + sizeof(LPMCI_OPEN_DRIVER_PARMSA));
167 modp32->wDeviceID = modp16->wDeviceID;
168 modp32->lpstrParams = PTR_SEG_TO_LIN(modp16->lpstrParams);
172 *lParam2 = (DWORD)modp32;
178 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO */
180 LPDRVCONFIGINFO dci32 = HeapAlloc(SystemHeap, 0, sizeof(DRVCONFIGINFO));
181 LPDRVCONFIGINFO16 dci16 = PTR_SEG_TO_LIN(*lParam2);
184 dci32->dwDCISize = sizeof(DRVCONFIGINFO);
185 dci32->lpszDCISectionName = HEAP_strdupAtoW(SystemHeap, 0, PTR_SEG_TO_LIN(dci16->lpszDCISectionName));
186 dci32->lpszDCIAliasName = HEAP_strdupAtoW(SystemHeap, 0, PTR_SEG_TO_LIN(dci16->lpszDCIAliasName));
187 if (dci32->lpszDCISectionName == NULL || dci32->lpszDCIAliasName == NULL)
192 *lParam2 = (DWORD)dci32;
199 if (wMsg >= 0x800 && wMsg < 0x900) {
200 /* FIXME: another hack to handle MCI messages...
201 * should find a *NICE* way to integrate DRIVER_ and
202 * MCI_ mapping/unmapping functions
206 FIXME("Unknown message 0x%04x\n", wMsg);
212 /**************************************************************************
213 * DRIVER_MapMsg16To32 [internal]
215 * UnMap a 16 bit driver message to a 32 bit driver message.
218 * -2 : ko, memory problem
220 static int DRIVER_UnMapMsg16To32(WORD wMsg, DWORD lParam1, DWORD lParam2)
229 case DRV_QUERYCONFIGURE:
231 case DRV_EXITSESSION:
232 case DRV_EXITAPPLICATION:
234 /* lParam1 and lParam2 are not used */
237 /* lParam1 is a NULL terminated string */
238 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
239 if (lParam2 && wMsg == DRV_OPEN) {
240 LPMCI_OPEN_DRIVER_PARMSA modp32 = (LPMCI_OPEN_DRIVER_PARMSA)lParam2;
241 LPMCI_OPEN_DRIVER_PARMS16 modp16 = *(LPMCI_OPEN_DRIVER_PARMS16*)(lParam2 - sizeof(LPMCI_OPEN_DRIVER_PARMSA));
243 modp16->wCustomCommandTable = modp32->wCustomCommandTable;
244 modp16->wType = modp32->wType;
245 if (!HeapFree(SystemHeap, 0, modp32))
246 FIXME("bad free line=%d\n", __LINE__);
252 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
254 LPDRVCONFIGINFO dci32 = (LPDRVCONFIGINFO)lParam2;
255 if (!HeapFree(SystemHeap, 0, (LPVOID)dci32->lpszDCISectionName))
256 FIXME("bad free line=%d\n", __LINE__);
257 if (!HeapFree(SystemHeap, 0, (LPVOID)dci32->lpszDCIAliasName))
258 FIXME("bad free line=%d\n", __LINE__);
259 if (!HeapFree(SystemHeap, 0, dci32))
260 FIXME("bad free line=%d\n", __LINE__);
265 if (wMsg >= 0x800 && wMsg < 0x900) {
266 /* FIXME: another hack to handle MCI messages...
267 * should find a *NICE* way to integrate DRIVER_ and
268 * MCI_ mapping/unmapping functions
272 FIXME("Unknown message 0x%04x\n", wMsg);
278 /**************************************************************************
279 * DRIVER_MapMsg32To16 [internal]
281 * Map a 32 bit driver message to a 16 bit driver message.
282 * 1 : ok, some memory allocated, need to call DRIVER_UnMapMsg32To16
283 * 0 : ok, no memory allocated
284 * -1 : ko, unknown message
285 * -2 : ko, memory problem
287 static int DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lParam2)
296 case DRV_QUERYCONFIGURE:
298 case DRV_EXITSESSION:
299 case DRV_EXITAPPLICATION:
301 /* lParam1 and lParam2 are not used */
306 /* lParam1 is a NULL terminated string */
307 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
309 LPSTR str = SEGPTR_STRDUP((LPSTR)*lParam1);
311 *lParam1 = (LPARAM)SEGPTR_GET(str);
319 if (*lParam2 && wMsg == DRV_OPEN) {
320 LPMCI_OPEN_DRIVER_PARMS16 modp16;
321 char* ptr = SEGPTR_ALLOC(sizeof(LPMCI_OPEN_DRIVER_PARMSA) + sizeof(MCI_OPEN_DRIVER_PARMS16));
322 LPMCI_OPEN_DRIVER_PARMSA modp32 = (LPMCI_OPEN_DRIVER_PARMSA)(*lParam2);
325 *(LPMCI_OPEN_DRIVER_PARMSA*)ptr = modp32;
326 modp16 = (LPMCI_OPEN_DRIVER_PARMS16)(ptr + sizeof(LPMCI_OPEN_DRIVER_PARMSA));
328 modp16->wDeviceID = modp32->wDeviceID;
329 modp16->lpstrParams = PTR_SEG_TO_LIN(modp32->lpstrParams);
333 *lParam2 = (DWORD)SEGPTR_GET(modp16);
339 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO */
341 LPDRVCONFIGINFO16 dci16 = (LPDRVCONFIGINFO16)SEGPTR_ALLOC(sizeof(DRVCONFIGINFO16));
342 LPDRVCONFIGINFO dci32 = (LPDRVCONFIGINFO)(*lParam2);
347 dci16->dwDCISize = sizeof(DRVCONFIGINFO16);
349 if ((str1 = HEAP_strdupWtoA(SystemHeap, 0, dci32->lpszDCISectionName)) != NULL &&
350 (str2 = SEGPTR_STRDUP(str1)) != NULL) {
351 dci16->lpszDCISectionName = (LPSTR)SEGPTR_GET(str2);
352 if (!HeapFree(SystemHeap, 0, str1))
353 FIXME("bad free line=%d\n", __LINE__);
357 if ((str1 = HEAP_strdupWtoA(SystemHeap, 0, dci32->lpszDCIAliasName)) != NULL &&
358 (str2 = SEGPTR_STRDUP(str1)) != NULL) {
359 dci16->lpszDCIAliasName = (LPSTR)SEGPTR_GET(str2);
360 if (!HeapFree(SystemHeap, 0, str1))
361 FIXME("bad free line=%d\n", __LINE__);
368 *lParam2 = (LPARAM)SEGPTR_GET(dci16);
375 if (wMsg >= 0x800 && wMsg < 0x900) {
376 /* FIXME: another hack to handle MCI messages...
377 * should find a *NICE* way to integrate DRIVER_ and
378 * MCI_ mapping/unmapping functions
382 FIXME("Unknown message 0x%04x\n", wMsg);
388 /**************************************************************************
389 * DRIVER_UnMapMsg32To16 [internal]
391 * UnMap a 32 bit driver message to a 16 bit driver message.
394 * -2 : ko, memory problem
396 static int DRIVER_UnMapMsg32To16(WORD wMsg, DWORD lParam1, DWORD lParam2)
405 case DRV_QUERYCONFIGURE:
407 case DRV_EXITSESSION:
408 case DRV_EXITAPPLICATION:
410 /* lParam1 and lParam2 are not used */
413 /* lParam1 is a NULL terminated string, lParam2 is unknown => may lead to some problem */
414 /* lParam2 is a pointer to an MCI_OPEN_DRIVER_PARMS for an MCI device */
415 if (lParam1) if (!SEGPTR_FREE(PTR_SEG_TO_LIN(lParam1)))
416 FIXME("bad free line=%d\n", __LINE__);
418 if (lParam2 && wMsg == DRV_OPEN) {
419 LPMCI_OPEN_DRIVER_PARMS16 modp16 = (LPMCI_OPEN_DRIVER_PARMS16)PTR_SEG_TO_LIN(lParam2);
420 LPMCI_OPEN_DRIVER_PARMSA modp32 = *(LPMCI_OPEN_DRIVER_PARMSA*)((char*)modp16 - sizeof(LPMCI_OPEN_DRIVER_PARMSA));
422 modp32->wCustomCommandTable = modp16->wCustomCommandTable;
423 modp32->wType = modp16->wType;
424 if (!SEGPTR_FREE((char*)modp16 - sizeof(LPMCI_OPEN_DRIVER_PARMSA)))
425 FIXME("bad free line=%d\n", __LINE__);
431 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
433 LPDRVCONFIGINFO16 dci16 = (LPDRVCONFIGINFO16)PTR_SEG_TO_LIN(lParam2);
435 if (!SEGPTR_FREE(PTR_SEG_TO_LIN(dci16->lpszDCISectionName)))
436 FIXME("bad free line=%d\n", __LINE__);
437 if (!SEGPTR_FREE(PTR_SEG_TO_LIN(dci16->lpszDCIAliasName)))
438 FIXME("bad free line=%d\n", __LINE__);
439 if (!SEGPTR_FREE(dci16))
440 FIXME("bad free line=%d\n", __LINE__);
445 if (wMsg >= 0x800 && wMsg < 0x900) {
446 /* FIXME: another hack to handle MCI messages...
447 * should find a *NICE* way to integrate DRIVER_ and
448 * MCI_ mapping/unmapping functions
452 FIXME("Unknown message 0x%04x\n", wMsg);
458 /**************************************************************************
459 * SendDriverMessage [USER.251]
461 LRESULT WINAPI SendDriverMessage16(HDRVR16 hDriver, UINT16 msg, LPARAM lParam1,
468 TRACE("(%04x, %04X, %08lX, %08lX)\n", hDriver, msg, lParam1, lParam2);
470 lpDrv = DRIVER_FindFromHDrvr16(hDriver);
471 if (lpDrv != NULL && lpDrv->hDriver16 == hDriver) {
472 switch (lpDrv->dwFlags & WINE_DI_TYPE_MASK) {
473 case WINE_DI_TYPE_16:
474 TRACE("Before CallDriverProc proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
475 lpDrv->d.d16.lpDrvProc, lpDrv->dwDriverID, hDriver, msg, lParam1, lParam2);
476 retval = Callbacks->CallDriverProc(lpDrv->d.d16.lpDrvProc, lpDrv->dwDriverID, hDriver,
477 msg, lParam1, lParam2);
479 case WINE_DI_TYPE_32:
480 mapRet = DRIVER_MapMsg16To32(msg, &lParam1, &lParam2);
482 TRACE("Before func32 call proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
483 lpDrv->d.d32.lpDrvProc, lpDrv->dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2);
484 retval = lpDrv->d.d32.lpDrvProc(lpDrv->dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2);
486 DRIVER_UnMapMsg16To32(msg, lParam1, lParam2);
493 FIXME("Unknown driver type %08lx\n", lpDrv->dwFlags);
497 WARN("Bad driver handle %u\n", hDriver);
500 TRACE("retval = %ld\n", retval);
504 /**************************************************************************
505 * SendDriverMessage [WINMM.19]
507 LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT msg, LPARAM lParam1,
514 TRACE("(%04x, %04X, %08lX, %08lX)\n", hDriver, msg, lParam1, lParam2);
516 lpDrv = DRIVER_FindFromHDrvr(hDriver);
519 switch (lpDrv->dwFlags & WINE_DI_TYPE_MASK) {
520 case WINE_DI_TYPE_16:
521 mapRet = DRIVER_MapMsg32To16(msg, &lParam1, &lParam2);
523 TRACE("Before CallDriverProc proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
524 lpDrv->d.d16.lpDrvProc, lpDrv->dwDriverID, lpDrv->hDriver16, msg, lParam1, lParam2);
525 retval = Callbacks->CallDriverProc(lpDrv->d.d16.lpDrvProc, lpDrv->dwDriverID, lpDrv->hDriver16,
526 msg, lParam1, lParam2);
528 DRIVER_UnMapMsg32To16(msg, lParam1, lParam2);
534 case WINE_DI_TYPE_32:
535 TRACE("Before func32 call proc=%p driverID=%08lx hDrv=%u wMsg=%04x p1=%08lx p2=%08lx\n",
536 lpDrv->d.d32.lpDrvProc, lpDrv->dwDriverID, hDriver, msg, lParam1, lParam2);
537 retval = lpDrv->d.d32.lpDrvProc(lpDrv->dwDriverID, hDriver, msg, lParam1, lParam2);
540 FIXME("Unknown driver type %08lx\n", lpDrv->dwFlags);
544 WARN("Bad driver handle %u\n", hDriver);
546 TRACE("retval = %ld\n", retval);
551 /**************************************************************************
552 * DRIVER_RemoveFromList [internal]
554 * Generates all the logic to handle driver closure / deletion
555 * Removes a driver struct to the list of open drivers.
557 static BOOL DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv)
559 lpDrv->dwDriverID = 0;
560 if (DRIVER_GetNumberOfModuleRefs(lpDrv) == 1) {
561 SendDriverMessage((HDRVR)lpDrv, DRV_DISABLE, 0L, 0L);
562 SendDriverMessage((HDRVR)lpDrv, DRV_FREE, 0L, 0L);
565 if (lpDrv->lpPrevItem)
566 lpDrv->lpPrevItem->lpNextItem = lpDrv->lpNextItem;
568 lpDrvItemList = lpDrv->lpNextItem;
569 if (lpDrv->lpNextItem)
570 lpDrv->lpNextItem->lpPrevItem = lpDrv->lpPrevItem;
575 /**************************************************************************
576 * DRIVER_AddToList [internal]
578 * Adds a driver struct to the list of open drivers.
579 * Generates all the logic to handle driver creation / open.
581 static BOOL DRIVER_AddToList(LPWINE_DRIVER lpNewDrv, LPARAM lParam, BOOL bCallFrom32)
583 lpNewDrv->dwMagic = WINE_DI_MAGIC;
584 /* First driver to be loaded for this module, need to load correctly the module */
585 if (DRIVER_GetNumberOfModuleRefs(lpNewDrv) == 0) {
586 if (SendDriverMessage((HDRVR)lpNewDrv, DRV_LOAD, 0L, 0L) != DRV_SUCCESS) {
587 TRACE("DRV_LOAD failed on driver 0x%08lx\n", (DWORD)lpNewDrv);
590 if (SendDriverMessage((HDRVR)lpNewDrv, DRV_ENABLE, 0L, 0L) != DRV_SUCCESS) {
591 TRACE("DRV_ENABLE failed on driver 0x%08lx\n", (DWORD)lpNewDrv);
596 lpNewDrv->lpNextItem = NULL;
597 if (lpDrvItemList == NULL) {
598 lpDrvItemList = lpNewDrv;
599 lpNewDrv->lpPrevItem = NULL;
601 LPWINE_DRIVER lpDrv = lpDrvItemList; /* find end of list */
602 while (lpDrv->lpNextItem != NULL)
603 lpDrv = lpDrv->lpNextItem;
605 lpDrv->lpNextItem = lpNewDrv;
606 lpNewDrv->lpPrevItem = lpDrv;
609 /* Now just open a new instance of a driver on this module */
611 lpNewDrv->dwDriverID = SendDriverMessage((HDRVR)lpNewDrv, DRV_OPEN, 0L, lParam);
613 lpNewDrv->dwDriverID = SendDriverMessage16(lpNewDrv->hDriver16, DRV_OPEN, 0L, lParam);
615 if (lpNewDrv->dwDriverID == 0) {
616 TRACE("DRV_OPEN failed on driver 0x%08lx\n", (DWORD)lpNewDrv);
617 DRIVER_RemoveFromList(lpNewDrv);
624 /**************************************************************************
625 * DRIVER_CreateDrvr16 [internal]
627 * Creates unique ID for 16 bit drivers.
629 static HDRVR16 DRIVER_CreateDrvr16()
631 static WORD DRIVER_hDrvr16Counter = 0;
633 while (DRIVER_FindFromHDrvr16(++DRIVER_hDrvr16Counter));
634 return DRIVER_hDrvr16Counter;
637 /**************************************************************************
638 * DRIVER_CloseDriver [internal]
641 BOOL DRIVER_CloseDriver(LPWINE_DRIVER lpDrv, DWORD lParam1, DWORD lParam2)
644 SendDriverMessage((HDRVR)lpDrv, DRV_CLOSE, lParam1, lParam2);
646 if (DRIVER_RemoveFromList(lpDrv)) {
647 HeapFree(SystemHeap, 0, lpDrv);
651 WARN("Failed to close driver\n");
655 /**************************************************************************
656 * DRIVER_RegisterDriver16 [internal]
658 * Creates all the WINE internal representations for a 16 bit driver.
659 * The driver is also open by sending the correct messages.
661 LPWINE_DRIVER DRIVER_RegisterDriver16(LPCSTR lpName, HMODULE16 hModule, DRIVERPROC16 lpProc,
662 LPARAM lParam, BOOL bCallFrom32)
666 lpDrv = HeapAlloc(SystemHeap, 0, sizeof(WINE_DRIVER));
668 lpDrv->dwFlags = WINE_DI_TYPE_16;
669 lpDrv->dwDriverID = 0;
670 lpDrv->hDriver16 = DRIVER_CreateDrvr16();
671 strncpy(lpDrv->szAliasName, lpName, sizeof(lpDrv->szAliasName));
672 lpDrv->d.d16.hModule = hModule;
673 lpDrv->d.d16.lpDrvProc = lpProc;
675 if (!DRIVER_AddToList(lpDrv, lParam, bCallFrom32)) {
676 HeapFree(SystemHeap, 0, lpDrv);
683 /**************************************************************************
684 * DRIVER_RegisterDriver32 [internal]
686 * Creates all the WINE internal representations for a 32 bit driver.
687 * The driver is also open by sending the correct messages.
689 LPWINE_DRIVER DRIVER_RegisterDriver32(LPCSTR lpName, HMODULE hModule, DRIVERPROC lpProc,
690 LPARAM lParam, BOOL bCallFrom32)
694 lpDrv = HeapAlloc(SystemHeap, 0, sizeof(WINE_DRIVER));
696 lpDrv->dwFlags = WINE_DI_TYPE_32;
697 lpDrv->dwDriverID = 0;
698 lpDrv->hDriver16 = DRIVER_CreateDrvr16();
699 strncpy(lpDrv->szAliasName, lpName, sizeof(lpDrv->szAliasName));
700 lpDrv->d.d32.hModule = hModule;
701 lpDrv->d.d32.lpDrvProc = lpProc;
703 if (!DRIVER_AddToList(lpDrv, lParam, bCallFrom32)) {
704 HeapFree(SystemHeap, 0, lpDrv);
711 /**************************************************************************
712 * DRIVER_TryOpenDriver16 [internal]
714 * Tries to load a 16 bit driver whose DLL's (module) name is lpFileName.
716 static HDRVR16 DRIVER_TryOpenDriver16(LPCSTR lpFileName, LPARAM lParam, BOOL bCallFrom32)
718 LPWINE_DRIVER lpDrv = NULL;
723 TRACE("('%s', %08lX, %d);\n", lpFileName, lParam, bCallFrom32);
725 if (lstrlenA(lpFileName) < 1)
728 lpSFN = strrchr(lpFileName, '\\');
729 lpSFN = (lpSFN) ? (lpSFN + 1) : lpFileName;
731 if ((hModule = LoadModule16(lpFileName, (LPVOID)-1)) >= 32) {
732 if ((lpProc = (DRIVERPROC16)WIN32_GetProcAddress16(hModule, "DRIVERPROC")) != NULL) {
733 lpDrv = DRIVER_RegisterDriver16(lpSFN, hModule, lpProc, lParam, bCallFrom32);
735 FreeLibrary16(hModule);
736 TRACE("No DriverProc found\n");
740 TRACE("Unable to load 16 bit module (%s): %d\n", lpFileName, hModule);
742 return lpDrv ? lpDrv->hDriver16 : 0;
745 /**************************************************************************
746 * DRIVER_TryOpenDriver32 [internal]
748 * Tries to load a 32 bit driver whose DLL's (module) name is lpFileName.
750 static HDRVR DRIVER_TryOpenDriver32(LPCSTR lpFileName, LPARAM lParam, BOOL bCallFrom32)
752 LPWINE_DRIVER lpDrv = NULL;
757 TRACE("('%s', %08lX, %d);\n", lpFileName, lParam, bCallFrom32);
759 if (lstrlenA(lpFileName) < 1)
762 lpSFN = strrchr(lpFileName, '\\');
763 lpSFN = (lpSFN) ? (lpSFN + 1) : lpFileName;
765 if ((hModule = LoadLibraryA(lpFileName)) != 0) {
766 if ((lpProc = GetProcAddress(hModule, "DriverProc")) != NULL) {
767 lpDrv = DRIVER_RegisterDriver32(lpSFN, hModule, lpProc, lParam, bCallFrom32);
769 FreeLibrary(hModule);
771 TRACE("No DriverProc found\n");
774 TRACE("Unable to load 32 bit module \"%s\"\n", lpFileName);
776 TRACE("=> %p\n", lpDrv);
780 /**************************************************************************
781 * OpenDriver16 [USER.252]
783 HDRVR16 WINAPI OpenDriver16(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam)
788 TRACE("('%s', '%s', %08lX);\n", lpDriverName, lpSectionName, lParam);
790 if (lpSectionName == NULL) {
791 hDriver = DRIVER_TryOpenDriver16(lpDriverName, lParam, FALSE);
793 hDriver = DRIVER_TryOpenDriver32(lpDriverName, lParam, FALSE);
796 /* in case hDriver is NULL, search in Drivers32 section */
797 lpSectionName = "Drivers";
800 if (!hDriver && GetPrivateProfileStringA(lpSectionName, lpDriverName, "",
801 drvName, sizeof(drvName), "SYSTEM.INI") > 0) {
802 hDriver = DRIVER_TryOpenDriver16(drvName, lParam, FALSE);
807 /**************************************************************************
808 * OpenDriverA [WINMM.15]
809 * (0,1,DRV_LOAD ,0 ,0)
810 * (0,1,DRV_ENABLE,0 ,0)
811 * (0,1,DRV_OPEN ,buf[256],0)
813 HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam)
818 TRACE("('%s', '%s', %08lX);\n", lpDriverName, lpSectionName, lParam);
820 if (lpSectionName == NULL) {
821 strncpy(drvName, lpDriverName, sizeof(drvName));
822 hDriver = DRIVER_TryOpenDriver32(lpDriverName, lParam, TRUE);
824 hDriver = DRIVER_TryOpenDriver16(lpDriverName, lParam, TRUE);
827 if (GetPrivateProfileStringA("Drivers32", lpDriverName, "", drvName,
828 sizeof(drvName), "SYSTEM.INI")) {
829 hDriver = DRIVER_TryOpenDriver32(drvName, lParam, TRUE);
834 if (GetPrivateProfileStringA("Drivers", lpDriverName, "", drvName,
835 sizeof(drvName), "SYSTEM.INI")) {
836 hDriver = DRIVER_TryOpenDriver16(drvName, lParam, TRUE);
841 if (GetPrivateProfileStringA(lpSectionName, lpDriverName, "", drvName,
842 sizeof(drvName), "SYSTEM.INI")) {
843 hDriver = DRIVER_TryOpenDriver32(drvName, lParam, TRUE);
845 hDriver = DRIVER_TryOpenDriver16(drvName, lParam, TRUE);
849 TRACE("retval='%08x'\n", hDriver);
853 /**************************************************************************
854 * OpenDriverW [WINMM.15]
856 HDRVR WINAPI OpenDriverW(LPCWSTR lpDriverName, LPCWSTR lpSectionName, LPARAM lParam)
858 LPSTR dn = HEAP_strdupWtoA(GetProcessHeap(), 0, lpDriverName);
859 LPSTR sn = HEAP_strdupWtoA(GetProcessHeap(), 0, lpSectionName);
860 HDRVR ret = OpenDriverA(dn, sn, lParam);
862 if (dn) HeapFree(GetProcessHeap(), 0, dn);
863 if (sn) HeapFree(GetProcessHeap(), 0, sn);
867 /**************************************************************************
868 * CloseDriver16 [USER.253]
870 LRESULT WINAPI CloseDriver16(HDRVR16 hDrvr, LPARAM lParam1, LPARAM lParam2)
872 TRACE("(%04x, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
874 return DRIVER_CloseDriver(DRIVER_FindFromHDrvr16(hDrvr), lParam1, lParam2);
877 /**************************************************************************
878 * CloseDriver [WINMM.4]
880 LRESULT WINAPI CloseDriver(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
882 TRACE("(%04x, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
884 return DRIVER_CloseDriver(DRIVER_FindFromHDrvr(hDrvr), lParam1, lParam2);
887 /**************************************************************************
888 * GetDriverModuleHandle [USER.254]
890 HMODULE16 WINAPI GetDriverModuleHandle16(HDRVR16 hDrvr)
893 HMODULE16 hModule = 0;
895 TRACE("(%04x);\n", hDrvr);
897 lpDrv = DRIVER_FindFromHDrvr16(hDrvr);
898 if (lpDrv != NULL && lpDrv->hDriver16 == hDrvr &&
899 (lpDrv->dwFlags & WINE_DI_TYPE_MASK) == WINE_DI_TYPE_16) {
900 hModule = lpDrv->d.d16.hModule;
902 TRACE("=> %d\n", hModule);
906 /**************************************************************************
907 * GetDriverFlags [WINMM.13]
909 DWORD WINAPI GetDriverFlags(HDRVR hDrvr)
911 FIXME("(%04x); stub!\n", hDrvr);
915 /**************************************************************************
916 * GetDriverModuleHandle [WINMM.14]
918 HMODULE WINAPI GetDriverModuleHandle(HDRVR hDrvr)
923 TRACE("(%04x);\n", hDrvr);
925 lpDrv = DRIVER_FindFromHDrvr(hDrvr);
926 if (lpDrv != NULL && (lpDrv->dwFlags & WINE_DI_TYPE_MASK) == WINE_DI_TYPE_32) {
927 hModule = lpDrv->d.d32.hModule;
929 TRACE("=> %d\n", hModule);
933 /**************************************************************************
934 * DefDriverProc16 [USER.255]
936 LRESULT WINAPI DefDriverProc16(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg,
937 LPARAM lParam1, LPARAM lParam2)
939 TRACE("devID=0x%08lx hDrv=0x%04x wMsg=%04x lP1=0x%08lx lP2=0x%08lx\n",
940 dwDevID, hDriv, wMsg, lParam1, lParam2);
950 case DRV_QUERYCONFIGURE:
953 MessageBoxA(0, "Driver isn't configurable !", "Wine Driver", MB_OK);
963 /**************************************************************************
964 * GetDriverInfo [USER.256]
966 BOOL16 WINAPI GetDriverInfo16(HDRVR16 hDrvr, LPDRIVERINFOSTRUCT16 lpDrvInfo)
971 TRACE("(%04x, %p);\n", hDrvr, lpDrvInfo);
973 if (lpDrvInfo == NULL || lpDrvInfo->length != sizeof(DRIVERINFOSTRUCT16))
976 lpDrv = DRIVER_FindFromHDrvr16(hDrvr);
977 if (lpDrv != NULL && lpDrv->hDriver16 == hDrvr &&
978 (lpDrv->dwFlags & WINE_DI_TYPE_MASK) == WINE_DI_TYPE_16) {
979 lpDrvInfo->hDriver = lpDrv->hDriver16;
980 lpDrvInfo->hModule = lpDrv->d.d16.hModule;
981 strncpy(lpDrvInfo->szAliasName, lpDrv->szAliasName, sizeof(lpDrvInfo->szAliasName));
988 /**************************************************************************
989 * GetNextDriver [USER.257]
991 HDRVR16 WINAPI GetNextDriver16(HDRVR16 hDrvr, DWORD dwFlags)
996 TRACE("(%04x, %08lX);\n", hDrvr, dwFlags);
999 if (lpDrvItemList == NULL) {
1000 FIXME("drivers list empty !\n");
1001 /* FIXME: code was using DRIVER_LoadStartupDrivers(); before ?
1002 * I (EPP) don't quite understand this
1004 if (lpDrvItemList == NULL)
1007 lpDrv = lpDrvItemList;
1008 if (dwFlags & GND_REVERSE) {
1009 while (lpDrv->lpNextItem)
1010 lpDrv = lpDrv->lpNextItem;
1013 lpDrv = DRIVER_FindFromHDrvr16(hDrvr);
1014 if (lpDrv != NULL) {
1015 if (dwFlags & GND_REVERSE) {
1016 lpDrv = (lpDrv->lpPrevItem) ? lpDrv->lpPrevItem : NULL;
1018 lpDrv = (lpDrv->lpNextItem) ? lpDrv->lpNextItem : NULL;
1023 hRetDrv = (lpDrv) ? lpDrv->hDriver16 : (HDRVR16)0;
1024 TRACE("return %04x !\n", hRetDrv);