Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 1 | /* -*- tab-width: 8; c-basic-offset: 4 -*- */ |
| 2 | |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 3 | /* |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 4 | * WINE Drivers functions |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 5 | * |
| 6 | * Copyright 1994 Martin Ayotte |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 7 | * Copyright 1998 Marcus Meissner |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 8 | * Copyright 1999,2000 Eric Pouech |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 9 | */ |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 10 | |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 11 | #include <string.h> |
Alexandre Julliard | 1922c72 | 2001-07-25 00:43:29 +0000 | [diff] [blame] | 12 | |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 13 | #include "windef.h" |
Alexandre Julliard | 680919c | 2000-05-07 18:39:28 +0000 | [diff] [blame] | 14 | #include "wine/winbase16.h" |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 15 | #include "wingdi.h" |
Eric Pouech | 95aa1c3 | 2000-01-04 00:26:50 +0000 | [diff] [blame] | 16 | #include "winuser.h" |
Eric Pouech | 37c0217 | 1999-09-05 16:44:38 +0000 | [diff] [blame] | 17 | #include "mmddk.h" |
| 18 | #include "debugtools.h" |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 19 | |
Alexandre Julliard | 680919c | 2000-05-07 18:39:28 +0000 | [diff] [blame] | 20 | DEFAULT_DEBUG_CHANNEL(driver); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 21 | |
Eric Pouech | 4f81c3e | 2000-01-15 22:29:32 +0000 | [diff] [blame] | 22 | typedef struct tagWINE_DRIVER |
| 23 | { |
Eric Pouech | 4f81c3e | 2000-01-15 22:29:32 +0000 | [diff] [blame] | 24 | char szAliasName[128]; |
| 25 | /* as usual LPWINE_DRIVER == hDriver32 */ |
| 26 | HDRVR16 hDriver16; |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 27 | HMODULE16 hModule16; |
| 28 | DRIVERPROC16 lpDrvProc; |
Eric Pouech | 4f81c3e | 2000-01-15 22:29:32 +0000 | [diff] [blame] | 29 | DWORD dwDriverID; |
Eric Pouech | 4f81c3e | 2000-01-15 22:29:32 +0000 | [diff] [blame] | 30 | struct tagWINE_DRIVER* lpPrevItem; |
| 31 | struct tagWINE_DRIVER* lpNextItem; |
| 32 | } WINE_DRIVER, *LPWINE_DRIVER; |
| 33 | |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 34 | static LPWINE_DRIVER lpDrvItemList = NULL; |
| 35 | |
| 36 | /* TODO list : |
Eric Pouech | 95aa1c3 | 2000-01-04 00:26:50 +0000 | [diff] [blame] | 37 | * - LoadModule count and clean up is not handled correctly (it's not a |
| 38 | * problem as long as FreeLibrary is not working correctly) |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 39 | */ |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 40 | |
Eric Pouech | 95aa1c3 | 2000-01-04 00:26:50 +0000 | [diff] [blame] | 41 | /* ### start build ### */ |
| 42 | extern LONG CALLBACK DRIVER_CallTo16_long_lwwll(FARPROC16,LONG,WORD,WORD,LONG,LONG); |
| 43 | /* ### stop build ### */ |
| 44 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 45 | /************************************************************************** |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 46 | * LoadStartupDrivers [internal] |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 47 | */ |
Marcus Meissner | de43ef4 | 1999-02-28 19:56:59 +0000 | [diff] [blame] | 48 | static void WINE_UNUSED DRIVER_LoadStartupDrivers(void) |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 49 | { |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 50 | char str[256]; |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 51 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 52 | if (GetPrivateProfileStringA("drivers", NULL, "", str, sizeof(str), "SYSTEM.INI") < 2) { |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 53 | ERR("Can't find drivers section in system.ini\n"); |
Eric Pouech | bd1a0a6 | 1999-04-10 16:50:24 +0000 | [diff] [blame] | 54 | } else { |
| 55 | HDRVR16 hDrv; |
| 56 | LPSTR ptr; |
| 57 | |
Alexandre Julliard | cb10fda | 2000-08-06 02:41:16 +0000 | [diff] [blame] | 58 | for (ptr = str; *ptr; ptr += strlen(ptr) + 1) { |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 59 | TRACE("str='%s'\n", ptr); |
Eric Pouech | bd1a0a6 | 1999-04-10 16:50:24 +0000 | [diff] [blame] | 60 | hDrv = OpenDriver16(ptr, "drivers", 0L); |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 61 | TRACE("hDrv=%04x\n", hDrv); |
Eric Pouech | bd1a0a6 | 1999-04-10 16:50:24 +0000 | [diff] [blame] | 62 | } |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 63 | TRACE("end of list !\n"); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 64 | } |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 67 | /************************************************************************** |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 68 | * DRIVER_GetNumberOfModuleRefs [internal] |
| 69 | * |
| 70 | * Returns the number of open drivers which share the same module. |
| 71 | */ |
| 72 | static WORD DRIVER_GetNumberOfModuleRefs(LPWINE_DRIVER lpNewDrv) |
| 73 | { |
| 74 | LPWINE_DRIVER lpDrv; |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 75 | WORD count = 0; |
| 76 | |
| 77 | for (lpDrv = lpDrvItemList; lpDrv; lpDrv = lpDrv->lpNextItem) { |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 78 | if (lpDrv->hModule16 == lpNewDrv->hModule16) { |
| 79 | count++; |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | return count; |
| 83 | } |
| 84 | |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 85 | /************************************************************************** |
| 86 | * DRIVER_FindFromHDrvr16 [internal] |
| 87 | * |
| 88 | * From a hDrvr being 16 bits, returns the WINE internal structure. |
| 89 | */ |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 90 | static LPWINE_DRIVER DRIVER_FindFromHDrvr16(HDRVR16 hDrvr) |
| 91 | { |
| 92 | LPWINE_DRIVER lpDrv; |
| 93 | |
| 94 | for (lpDrv = lpDrvItemList; lpDrv; lpDrv = lpDrv->lpNextItem) { |
| 95 | if (lpDrv->hDriver16 == hDrvr) { |
Eric Pouech | bd1a0a6 | 1999-04-10 16:50:24 +0000 | [diff] [blame] | 96 | break; |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
Eric Pouech | bd1a0a6 | 1999-04-10 16:50:24 +0000 | [diff] [blame] | 99 | return lpDrv; |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /************************************************************************** |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 103 | * DRIVER_SendMessage [internal] |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 104 | */ |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 105 | static LRESULT inline DRIVER_SendMessage(LPWINE_DRIVER lpDrv, UINT16 msg, |
| 106 | LPARAM lParam1, LPARAM lParam2) |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 107 | { |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 108 | TRACE("Before CallDriverProc proc=%p driverID=%08lx wMsg=%04x p1=%08lx p2=%08lx\n", |
| 109 | lpDrv->lpDrvProc, lpDrv->dwDriverID, msg, lParam1, lParam2); |
| 110 | return DRIVER_CallTo16_long_lwwll((FARPROC16)lpDrv->lpDrvProc, lpDrv->dwDriverID, |
| 111 | lpDrv->hDriver16, msg, lParam1, lParam2); |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 115 | * SendDriverMessage (USER.251) |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 116 | * SendDriverMessage16 (USER32.@) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 117 | */ |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 118 | LRESULT WINAPI SendDriverMessage16(HDRVR16 hDriver, UINT16 msg, LPARAM lParam1, |
| 119 | LPARAM lParam2) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 120 | { |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 121 | LPWINE_DRIVER lpDrv; |
| 122 | LRESULT retval = 0; |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 123 | |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 124 | TRACE("(%04x, %04X, %08lX, %08lX)\n", hDriver, msg, lParam1, lParam2); |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 125 | |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 126 | if ((lpDrv = DRIVER_FindFromHDrvr16(hDriver)) != NULL) { |
| 127 | retval = DRIVER_SendMessage(lpDrv, msg, lParam1, lParam2); |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 128 | } else { |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 129 | WARN("Bad driver handle %u\n", hDriver); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 130 | } |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 131 | |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 132 | TRACE("retval = %ld\n", retval); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 133 | return retval; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /************************************************************************** |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 137 | * DRIVER_RemoveFromList [internal] |
| 138 | * |
| 139 | * Generates all the logic to handle driver closure / deletion |
| 140 | * Removes a driver struct to the list of open drivers. |
| 141 | */ |
| 142 | static BOOL DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv) |
| 143 | { |
| 144 | lpDrv->dwDriverID = 0; |
| 145 | if (DRIVER_GetNumberOfModuleRefs(lpDrv) == 1) { |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 146 | DRIVER_SendMessage(lpDrv, DRV_DISABLE, 0L, 0L); |
| 147 | DRIVER_SendMessage(lpDrv, DRV_FREE, 0L, 0L); |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 148 | } |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 149 | |
| 150 | if (lpDrv->lpPrevItem) |
| 151 | lpDrv->lpPrevItem->lpNextItem = lpDrv->lpNextItem; |
| 152 | else |
| 153 | lpDrvItemList = lpDrv->lpNextItem; |
| 154 | if (lpDrv->lpNextItem) |
| 155 | lpDrv->lpNextItem->lpPrevItem = lpDrv->lpPrevItem; |
| 156 | |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 157 | return TRUE; |
| 158 | } |
| 159 | |
| 160 | /************************************************************************** |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 161 | * DRIVER_AddToList [internal] |
| 162 | * |
| 163 | * Adds a driver struct to the list of open drivers. |
| 164 | * Generates all the logic to handle driver creation / open. |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 165 | */ |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 166 | static BOOL DRIVER_AddToList(LPWINE_DRIVER lpNewDrv, LPARAM lParam1, LPARAM lParam2) |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 167 | { |
| 168 | /* First driver to be loaded for this module, need to load correctly the module */ |
| 169 | if (DRIVER_GetNumberOfModuleRefs(lpNewDrv) == 0) { |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 170 | if (DRIVER_SendMessage(lpNewDrv, DRV_LOAD, 0L, 0L) != DRV_SUCCESS) { |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 171 | TRACE("DRV_LOAD failed on driver 0x%08lx\n", (DWORD)lpNewDrv); |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 172 | return FALSE; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 173 | } |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 174 | /* returned value is not checked */ |
| 175 | DRIVER_SendMessage(lpNewDrv, DRV_ENABLE, 0L, 0L); |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 176 | } |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 177 | |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 178 | lpNewDrv->lpNextItem = NULL; |
| 179 | if (lpDrvItemList == NULL) { |
| 180 | lpDrvItemList = lpNewDrv; |
| 181 | lpNewDrv->lpPrevItem = NULL; |
| 182 | } else { |
| 183 | LPWINE_DRIVER lpDrv = lpDrvItemList; /* find end of list */ |
| 184 | while (lpDrv->lpNextItem != NULL) |
| 185 | lpDrv = lpDrv->lpNextItem; |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 186 | |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 187 | lpDrv->lpNextItem = lpNewDrv; |
| 188 | lpNewDrv->lpPrevItem = lpDrv; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 189 | } |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 190 | /* Now just open a new instance of a driver on this module */ |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 191 | lpNewDrv->dwDriverID = DRIVER_SendMessage(lpNewDrv, DRV_OPEN, lParam1, lParam2); |
| 192 | |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 193 | if (lpNewDrv->dwDriverID == 0) { |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 194 | TRACE("DRV_OPEN failed on driver 0x%08lx\n", (DWORD)lpNewDrv); |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 195 | DRIVER_RemoveFromList(lpNewDrv); |
| 196 | return FALSE; |
| 197 | } |
| 198 | |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 199 | return TRUE; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /************************************************************************** |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 203 | * DRIVER_TryOpenDriver16 [internal] |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 204 | * |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 205 | * Tries to load a 16 bit driver whose DLL's (module) name is lpFileName. |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 206 | */ |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 207 | static LPWINE_DRIVER DRIVER_TryOpenDriver16(LPCSTR lpFileName, LPARAM lParam2) |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 208 | { |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 209 | static WORD DRIVER_hDrvr16Counter /* = 0 */; |
| 210 | LPWINE_DRIVER lpDrv = NULL; |
| 211 | HMODULE16 hModule; |
| 212 | DRIVERPROC16 lpProc; |
| 213 | LPCSTR lpSFN; |
| 214 | LPSTR ptr; |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 215 | |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 216 | TRACE("('%s', %08lX);\n", lpFileName, lParam2); |
| 217 | |
| 218 | if (strlen(lpFileName) < 1) return lpDrv; |
| 219 | |
| 220 | if ((lpSFN = strrchr(lpFileName, '\\')) == NULL) |
| 221 | lpSFN = lpFileName; |
| 222 | else |
| 223 | lpSFN++; |
| 224 | if ((ptr = strchr(lpFileName, ' ')) != NULL) { |
| 225 | *ptr++ = '\0'; |
| 226 | while (*ptr == ' ') ptr++; |
| 227 | if (*ptr == '\0') ptr = NULL; |
| 228 | } |
| 229 | |
Eric Pouech | 247a94f | 2000-12-21 20:21:53 +0000 | [diff] [blame] | 230 | if ((hModule = LoadLibrary16(lpFileName)) < 32) goto exit; |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 231 | if ((lpProc = (DRIVERPROC16)GetProcAddress16(hModule, "DRIVERPROC")) == NULL) |
| 232 | goto exit; |
| 233 | |
| 234 | if ((lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER))) == NULL) |
| 235 | goto exit; |
| 236 | |
| 237 | lpDrv->dwDriverID = 0; |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 238 | while (DRIVER_FindFromHDrvr16(++DRIVER_hDrvr16Counter)); |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 239 | lpDrv->hDriver16 = DRIVER_hDrvr16Counter; |
| 240 | lstrcpynA(lpDrv->szAliasName, lpSFN, sizeof(lpDrv->szAliasName)); |
| 241 | lpDrv->hModule16 = hModule; |
| 242 | lpDrv->lpDrvProc = lpProc; |
| 243 | |
| 244 | if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, lParam2)) goto exit; |
| 245 | |
| 246 | return lpDrv; |
| 247 | exit: |
| 248 | TRACE("Unable to load 16 bit module (%s): %04x\n", lpFileName, hModule); |
| 249 | if (hModule >= 32) FreeLibrary16(hModule); |
| 250 | HeapFree(GetProcessHeap(), 0, lpDrv); |
| 251 | return NULL; |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /************************************************************************** |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 255 | * OpenDriver (USER.252) |
| 256 | * OpenDriver16 (USER32.@) |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 257 | */ |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 258 | HDRVR16 WINAPI OpenDriver16(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam2) |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 259 | { |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 260 | LPWINE_DRIVER lpDrv = NULL; |
| 261 | char drvName[128]; |
| 262 | |
| 263 | TRACE("('%s', '%s', %08lX);\n", lpDriverName, lpSectionName, lParam2); |
| 264 | |
| 265 | if (!lpDriverName || !*lpDriverName) return 0; |
| 266 | |
| 267 | if (lpSectionName == NULL) { |
| 268 | strcpy(drvName, lpDriverName); |
| 269 | |
| 270 | if ((lpDrv = DRIVER_TryOpenDriver16(drvName, lParam2))) |
| 271 | goto the_end; |
| 272 | /* in case hDriver is NULL, search in Drivers section */ |
| 273 | lpSectionName = "Drivers"; |
| 274 | } |
| 275 | if (GetPrivateProfileStringA(lpSectionName, lpDriverName, "", |
| 276 | drvName, sizeof(drvName), "SYSTEM.INI") > 0) { |
| 277 | lpDrv = DRIVER_TryOpenDriver16(drvName, lParam2); |
| 278 | } |
| 279 | if (!lpDrv) { |
Eric Pouech | 247a94f | 2000-12-21 20:21:53 +0000 | [diff] [blame] | 280 | TRACE("Failed to open driver %s from system.ini file, section %s\n", lpDriverName, lpSectionName); |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 281 | return 0; |
| 282 | } |
| 283 | the_end: |
| 284 | TRACE("=> %04x / %08lx\n", lpDrv->hDriver16, (DWORD)lpDrv); |
| 285 | return lpDrv->hDriver16; |
| 286 | } |
| 287 | |
| 288 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 289 | * CloseDriver (USER.253) |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 290 | * CloseDriver16 (USER32.@) |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 291 | */ |
| 292 | LRESULT WINAPI CloseDriver16(HDRVR16 hDrvr, LPARAM lParam1, LPARAM lParam2) |
| 293 | { |
| 294 | LPWINE_DRIVER lpDrv; |
| 295 | |
| 296 | TRACE("(%04x, %08lX, %08lX);\n", hDrvr, lParam1, lParam2); |
| 297 | |
| 298 | if ((lpDrv = DRIVER_FindFromHDrvr16(hDrvr)) != NULL) { |
| 299 | DRIVER_SendMessage(lpDrv, DRV_CLOSE, lParam1, lParam2); |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 300 | |
| 301 | if (DRIVER_RemoveFromList(lpDrv)) { |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 302 | HeapFree(GetProcessHeap(), 0, lpDrv); |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 303 | return TRUE; |
| 304 | } |
| 305 | } |
| 306 | WARN("Failed to close driver\n"); |
| 307 | return FALSE; |
| 308 | } |
| 309 | |
| 310 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 311 | * GetDriverModuleHandle (USER.254) |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 312 | * GetDriverModuleHandle16 (USER32.@) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 313 | */ |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 314 | HMODULE16 WINAPI GetDriverModuleHandle16(HDRVR16 hDrvr) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 315 | { |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 316 | LPWINE_DRIVER lpDrv; |
| 317 | HMODULE16 hModule = 0; |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 318 | |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 319 | TRACE("(%04x);\n", hDrvr); |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 320 | |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 321 | if ((lpDrv = DRIVER_FindFromHDrvr16(hDrvr)) != NULL) { |
| 322 | hModule = lpDrv->hModule16; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 323 | } |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 324 | TRACE("=> %04x\n", hModule); |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 325 | return hModule; |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 329 | * DefDriverProc (USER.255) |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 330 | * DefDriverProc16 (USER32.@) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 331 | */ |
Turchanov Sergey | 86f5d82 | 1998-10-18 11:22:36 +0000 | [diff] [blame] | 332 | LRESULT WINAPI DefDriverProc16(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg, |
| 333 | LPARAM lParam1, LPARAM lParam2) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 334 | { |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 335 | TRACE("devID=0x%08lx hDrv=0x%04x wMsg=%04x lP1=0x%08lx lP2=0x%08lx\n", |
Eric Pouech | c9ed21f | 1999-03-19 16:57:29 +0000 | [diff] [blame] | 336 | dwDevID, hDriv, wMsg, lParam1, lParam2); |
| 337 | |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 338 | switch(wMsg) { |
Eric Pouech | 9f2ad56 | 1999-03-22 14:47:36 +0000 | [diff] [blame] | 339 | case DRV_LOAD: |
| 340 | case DRV_FREE: |
| 341 | case DRV_ENABLE: |
| 342 | case DRV_DISABLE: |
| 343 | return (LRESULT)1L; |
| 344 | case DRV_OPEN: |
| 345 | case DRV_CLOSE: |
| 346 | case DRV_QUERYCONFIGURE: |
| 347 | return (LRESULT)0L; |
| 348 | case DRV_CONFIGURE: |
| 349 | MessageBoxA(0, "Driver isn't configurable !", "Wine Driver", MB_OK); |
| 350 | return (LRESULT)0L; |
| 351 | case DRV_INSTALL: |
| 352 | case DRV_REMOVE: |
| 353 | return DRV_SUCCESS; |
| 354 | default: |
| 355 | return (LRESULT)0L; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 356 | } |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 360 | * GetDriverInfo (USER.256) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 361 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 362 | BOOL16 WINAPI GetDriverInfo16(HDRVR16 hDrvr, LPDRIVERINFOSTRUCT16 lpDrvInfo) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 363 | { |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 364 | LPWINE_DRIVER lpDrv; |
| 365 | BOOL16 ret = FALSE; |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 366 | |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 367 | TRACE("(%04x, %p);\n", hDrvr, lpDrvInfo); |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 368 | |
Eric Pouech | bd1a0a6 | 1999-04-10 16:50:24 +0000 | [diff] [blame] | 369 | if (lpDrvInfo == NULL || lpDrvInfo->length != sizeof(DRIVERINFOSTRUCT16)) |
| 370 | return FALSE; |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 371 | |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 372 | if ((lpDrv = DRIVER_FindFromHDrvr16(hDrvr)) != NULL) { |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 373 | lpDrvInfo->hDriver = lpDrv->hDriver16; |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 374 | lpDrvInfo->hModule = lpDrv->hModule16; |
Francois Gouget | baa9bf9 | 1999-12-27 05:24:06 +0000 | [diff] [blame] | 375 | lstrcpynA(lpDrvInfo->szAliasName, lpDrv->szAliasName, sizeof(lpDrvInfo->szAliasName)); |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 376 | ret = TRUE; |
| 377 | } |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 378 | |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 379 | return ret; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 383 | * GetNextDriver (USER.257) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 384 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 385 | HDRVR16 WINAPI GetNextDriver16(HDRVR16 hDrvr, DWORD dwFlags) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 386 | { |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 387 | HDRVR16 hRetDrv = 0; |
| 388 | LPWINE_DRIVER lpDrv; |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 389 | |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 390 | TRACE("(%04x, %08lX);\n", hDrvr, dwFlags); |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 391 | |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 392 | if (hDrvr == 0) { |
| 393 | if (lpDrvItemList == NULL) { |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 394 | FIXME("drivers list empty !\n"); |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 395 | /* FIXME: code was using DRIVER_LoadStartupDrivers(); before ? |
| 396 | * I (EPP) don't quite understand this |
| 397 | */ |
Eric Pouech | bd1a0a6 | 1999-04-10 16:50:24 +0000 | [diff] [blame] | 398 | if (lpDrvItemList == NULL) |
| 399 | return 0; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 400 | } |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 401 | lpDrv = lpDrvItemList; |
| 402 | if (dwFlags & GND_REVERSE) { |
| 403 | while (lpDrv->lpNextItem) |
| 404 | lpDrv = lpDrv->lpNextItem; |
| 405 | } |
| 406 | } else { |
Eric Pouech | 66b4468 | 2000-12-13 02:07:40 +0000 | [diff] [blame] | 407 | if ((lpDrv = DRIVER_FindFromHDrvr16(hDrvr)) != NULL) { |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 408 | if (dwFlags & GND_REVERSE) { |
| 409 | lpDrv = (lpDrv->lpPrevItem) ? lpDrv->lpPrevItem : NULL; |
| 410 | } else { |
| 411 | lpDrv = (lpDrv->lpNextItem) ? lpDrv->lpNextItem : NULL; |
| 412 | } |
| 413 | } |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 414 | } |
Eric Pouech | 3fb2f42 | 1999-03-15 15:14:06 +0000 | [diff] [blame] | 415 | |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 416 | hRetDrv = (lpDrv) ? lpDrv->hDriver16 : (HDRVR16)0; |
Eric Pouech | 09f03b4 | 1999-06-22 19:07:34 +0000 | [diff] [blame] | 417 | TRACE("return %04x !\n", hRetDrv); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 418 | return hRetDrv; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 419 | } |
Eric Pouech | 0248381 | 1999-01-26 17:23:30 +0000 | [diff] [blame] | 420 | |