2 * Wine Drivers functions
4 * Copyright 1994 Martin Ayotte
15 LPDRIVERITEM lpDrvItemList
= NULL
;
17 void LoadStartupDrivers(void)
23 if (GetPrivateProfileString32A( "drivers", NULL
, "", str
, sizeof(str
),
27 "LoadStartupDrivers // can't find drivers section in system.ini\n" );
32 while (lstrlen32A( ptr
) != 0)
34 dprintf_info(driver
, "LoadStartupDrivers // str='%s'\n", ptr
);
35 hDrv
= OpenDriver( ptr
, "drivers", 0L );
36 dprintf_info(driver
, "LoadStartupDrivers // hDrv=%04x\n", hDrv
);
37 ptr
+= lstrlen32A(ptr
) + 1;
39 dprintf_info(driver
, "LoadStartupDrivers // end of list !\n" );
44 /**************************************************************************
45 * SendDriverMessage [USER.251]
47 LRESULT WINAPI
SendDriverMessage(HDRVR16 hDriver
, UINT16 msg
, LPARAM lParam1
,
53 dprintf_info(driver
, "SendDriverMessage(%04x, %04X, %08lX, %08lX)\n",
54 hDriver
, msg
, lParam1
, lParam2
);
56 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDriver
);
57 if (lpdrv
== NULL
|| lpdrv
->dis
.hDriver
!= hDriver
)
59 GlobalUnlock16( hDriver
);
63 retval
= Callbacks
->CallDriverProc( lpdrv
->lpDrvProc
, 0L /* FIXME */,
64 hDriver
, msg
, lParam1
, lParam2
);
66 dprintf_info(driver
, "SendDriverMessage // retval = %ld\n", retval
);
68 GlobalUnlock16( hDriver
);
72 /**************************************************************************
73 * OpenDriver [USER.252]
75 HDRVR16 WINAPI
OpenDriver(LPSTR lpDriverName
, LPSTR lpSectionName
, LPARAM lParam
)
78 LPDRIVERITEM lpdrv
, lpnewdrv
;
82 dprintf_info(driver
,"OpenDriver('%s', '%s', %08lX);\n",
83 lpDriverName
, lpSectionName
, lParam
);
85 if (lpSectionName
== NULL
) lpSectionName
= "drivers";
86 GetPrivateProfileString32A( lpSectionName
, lpDriverName
, "", DrvName
,
87 sizeof(DrvName
), "SYSTEM.INI" );
88 dprintf_info(driver
,"OpenDriver // DrvName='%s'\n", DrvName
);
89 if (lstrlen32A(DrvName
) < 1) return 0;
91 lpdrv
= lpDrvItemList
;
92 while (lpdrv
) /* XXX find it... like this? */
94 if (!lstrcmpi32A( lpDriverName
, lpdrv
->dis
.szAliasName
))
97 SendDriverMessage( lpdrv
->dis
.hDriver
, DRV_OPEN
, 0L, lParam
);
98 return lpdrv
->dis
.hDriver
;
100 lpdrv
= lpdrv
->lpNextItem
;
103 lpdrv
= lpDrvItemList
; /* find end of list */
105 while (lpdrv
->lpNextItem
!= NULL
)
106 lpdrv
= lpdrv
->lpNextItem
;
108 hDrvr
= GlobalAlloc16( GMEM_MOVEABLE
, sizeof(DRIVERITEM
) );
109 lpnewdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
110 if (lpnewdrv
== NULL
) return 0;
111 lpnewdrv
->dis
.length
= sizeof( DRIVERINFOSTRUCT16
);
112 lpnewdrv
->dis
.hModule
= LoadModule16( DrvName
, (LPVOID
)-1 );
113 if (!lpnewdrv
->dis
.hModule
)
115 GlobalUnlock16( hDrvr
);
116 GlobalFree16( hDrvr
);
119 lpnewdrv
->dis
.hDriver
= hDrvr
;
120 lstrcpy32A( lpnewdrv
->dis
.szAliasName
, lpDriverName
);
122 ordinal
= MODULE_GetOrdinal( lpnewdrv
->dis
.hModule
, "DRIVERPROC" );
124 !(lpnewdrv
->lpDrvProc
= (DRIVERPROC16
)MODULE_GetEntryPoint(
125 lpnewdrv
->dis
.hModule
, ordinal
)))
127 FreeModule16( lpnewdrv
->dis
.hModule
);
128 GlobalUnlock16( hDrvr
);
129 GlobalFree16( hDrvr
);
133 lpnewdrv
->lpNextItem
= NULL
;
134 if (lpDrvItemList
== NULL
)
136 lpDrvItemList
= lpnewdrv
;
137 lpnewdrv
->lpPrevItem
= NULL
;
141 lpdrv
->lpNextItem
= lpnewdrv
;
142 lpnewdrv
->lpPrevItem
= lpdrv
;
145 SendDriverMessage( hDrvr
, DRV_LOAD
, 0L, lParam
);
146 SendDriverMessage( hDrvr
, DRV_ENABLE
, 0L, lParam
);
147 SendDriverMessage( hDrvr
, DRV_OPEN
, 0L, lParam
);
149 dprintf_info(driver
, "OpenDriver // hDrvr=%04x loaded !\n", hDrvr
);
153 /**************************************************************************
154 * CloseDriver [USER.253]
156 LRESULT WINAPI
CloseDriver(HDRVR16 hDrvr
, LPARAM lParam1
, LPARAM lParam2
)
160 dprintf_info(driver
, "CloseDriver(%04x, %08lX, %08lX);\n",
161 hDrvr
, lParam1
, lParam2
);
163 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
164 if (lpdrv
!= NULL
&& lpdrv
->dis
.hDriver
== hDrvr
)
166 SendDriverMessage( hDrvr
, DRV_CLOSE
, lParam1
, lParam2
);
167 if (--lpdrv
->count
== 0)
169 SendDriverMessage( hDrvr
, DRV_DISABLE
, lParam1
, lParam2
);
170 SendDriverMessage( hDrvr
, DRV_FREE
, lParam1
, lParam2
);
172 if (lpdrv
->lpPrevItem
)
173 lpdrv
->lpPrevItem
->lpNextItem
= lpdrv
->lpNextItem
;
175 lpDrvItemList
= lpdrv
->lpNextItem
;
176 if (lpdrv
->lpNextItem
)
177 lpdrv
->lpNextItem
->lpPrevItem
= lpdrv
->lpPrevItem
;
179 FreeModule16( lpdrv
->dis
.hModule
);
180 GlobalUnlock16( hDrvr
);
181 GlobalFree16( hDrvr
);
184 dprintf_info(driver
, "CloseDriver // hDrvr=%04x closed !\n",
191 /**************************************************************************
192 * GetDriverModuleHandle [USER.254]
194 HMODULE16 WINAPI
GetDriverModuleHandle(HDRVR16 hDrvr
)
197 HMODULE16 hModule
= 0;
199 dprintf_info(driver
, "GetDriverModuleHandle(%04x);\n", hDrvr
);
201 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
202 if (lpdrv
!= NULL
&& lpdrv
->dis
.hDriver
== hDrvr
)
204 hModule
= lpdrv
->dis
.hModule
;
205 GlobalUnlock16( hDrvr
);
210 /**************************************************************************
211 * DefDriverProc [USER.255]
213 LRESULT WINAPI
DefDriverProc(DWORD dwDevID
, HDRVR16 hDriv
, UINT16 wMsg
,
214 LPARAM lParam1
, LPARAM lParam2
)
230 case DRV_QUERYCONFIGURE
:
234 MessageBox16( 0, "Driver isn't configurable !", "Wine Driver", MB_OK
);
238 return (LRESULT
)DRVCNF_RESTART
;
241 return (LRESULT
)DRVCNF_RESTART
;
248 /**************************************************************************
249 * GetDriverInfo [USER.256]
251 BOOL16 WINAPI
GetDriverInfo(HDRVR16 hDrvr
, LPDRIVERINFOSTRUCT16 lpDrvInfo
)
255 dprintf_info(driver
, "GetDriverInfo(%04x, %p);\n", hDrvr
, lpDrvInfo
);
257 if (lpDrvInfo
== NULL
) return FALSE
;
259 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
260 if (lpdrv
== NULL
) return FALSE
;
261 memcpy( lpDrvInfo
, &lpdrv
->dis
, sizeof(DRIVERINFOSTRUCT16
) );
262 GlobalUnlock16( hDrvr
);
267 /**************************************************************************
268 * GetNextDriver [USER.257]
270 HDRVR16 WINAPI
GetNextDriver(HDRVR16 hDrvr
, DWORD dwFlags
)
275 dprintf_info(driver
, "GetNextDriver(%04x, %08lX);\n", hDrvr
, dwFlags
);
279 if (lpDrvItemList
== NULL
)
281 dprintf_info(driver
, "GetNextDriver // drivers list empty !\n");
282 LoadStartupDrivers();
283 if (lpDrvItemList
== NULL
) return 0;
285 dprintf_info(driver
,"GetNextDriver // return first %04x !\n",
286 lpDrvItemList
->dis
.hDriver
);
287 return lpDrvItemList
->dis
.hDriver
;
290 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
293 if (dwFlags
& GND_REVERSE
)
295 if (lpdrv
->lpPrevItem
)
296 hRetDrv
= lpdrv
->lpPrevItem
->dis
.hDriver
;
300 if (lpdrv
->lpNextItem
)
301 hRetDrv
= lpdrv
->lpNextItem
->dis
.hDriver
;
303 GlobalUnlock16( hDrvr
);
306 dprintf_info(driver
, "GetNextDriver // return %04x !\n", hRetDrv
);