2 * Wine Drivers functions
4 * Copyright 1994 Martin Ayotte
16 LPDRIVERITEM lpDrvItemList
= NULL
;
18 void LoadStartupDrivers(void)
24 if (GetPrivateProfileString32A( "drivers", NULL
, "", str
, sizeof(str
),
28 "LoadStartupDrivers // can't find drivers section in system.ini\n" );
33 while (lstrlen32A( ptr
) != 0)
35 dprintf_driver( stddeb
, "LoadStartupDrivers // str='%s'\n", ptr
);
36 hDrv
= OpenDriver( ptr
, "drivers", 0L );
37 dprintf_driver( stddeb
, "LoadStartupDrivers // hDrv=%04x\n", hDrv
);
38 ptr
+= lstrlen32A(ptr
) + 1;
40 dprintf_driver( stddeb
, "LoadStartupDrivers // end of list !\n" );
45 /**************************************************************************
46 * SendDriverMessage [USER.251]
48 LRESULT
SendDriverMessage(HDRVR16 hDriver
, UINT16 msg
, LPARAM lParam1
,
54 dprintf_driver( stddeb
, "SendDriverMessage(%04x, %04X, %08lX, %08lX)\n",
55 hDriver
, msg
, lParam1
, lParam2
);
57 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDriver
);
58 if (lpdrv
== NULL
|| lpdrv
->dis
.hDriver
!= hDriver
)
60 GlobalUnlock16( hDriver
);
64 retval
= CallDriverProc( lpdrv
->lpDrvProc
, 0L /* FIXME */, hDriver
, msg
,
67 dprintf_driver( stddeb
, "SendDriverMessage // retval = %ld\n", retval
);
69 GlobalUnlock16( hDriver
);
73 /**************************************************************************
74 * OpenDriver [USER.252]
76 HDRVR16
OpenDriver(LPSTR lpDriverName
, LPSTR lpSectionName
, LPARAM lParam
)
79 LPDRIVERITEM lpdrv
, lpnewdrv
;
83 dprintf_driver( stddeb
,"OpenDriver('%s', '%s', %08lX);\n",
84 lpDriverName
, lpSectionName
, lParam
);
86 if (lpSectionName
== NULL
) lpSectionName
= "drivers";
87 GetPrivateProfileString32A( lpSectionName
, lpDriverName
, "", DrvName
,
88 sizeof(DrvName
), "SYSTEM.INI" );
89 dprintf_driver( stddeb
,"OpenDriver // DrvName='%s'\n", DrvName
);
90 if (lstrlen32A(DrvName
) < 1) return 0;
92 lpdrv
= lpDrvItemList
;
93 while (lpdrv
) /* XXX find it... like this? */
95 if (!lstrcmpi32A( lpDriverName
, lpdrv
->dis
.szAliasName
))
98 SendDriverMessage( lpdrv
->dis
.hDriver
, DRV_OPEN
, 0L, lParam
);
99 return lpdrv
->dis
.hDriver
;
101 lpdrv
= lpdrv
->lpNextItem
;
104 lpdrv
= lpDrvItemList
; /* find end of list */
106 while (lpdrv
->lpNextItem
!= NULL
)
107 lpdrv
= lpdrv
->lpNextItem
;
109 hDrvr
= GlobalAlloc16( GMEM_MOVEABLE
, sizeof(DRIVERITEM
) );
110 lpnewdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
111 if (lpnewdrv
== NULL
) return 0;
112 lpnewdrv
->dis
.length
= sizeof( DRIVERINFOSTRUCT16
);
113 lpnewdrv
->dis
.hModule
= LoadModule16( DrvName
, (LPVOID
)-1 );
114 if (!lpnewdrv
->dis
.hModule
)
116 GlobalUnlock16( hDrvr
);
117 GlobalFree16( hDrvr
);
120 lpnewdrv
->dis
.hDriver
= hDrvr
;
121 lstrcpy32A( lpnewdrv
->dis
.szAliasName
, lpDriverName
);
123 ordinal
= MODULE_GetOrdinal( lpnewdrv
->dis
.hModule
, "DRIVERPROC" );
125 !(lpnewdrv
->lpDrvProc
= (DRIVERPROC16
)MODULE_GetEntryPoint(
126 lpnewdrv
->dis
.hModule
, ordinal
)))
128 FreeModule16( lpnewdrv
->dis
.hModule
);
129 GlobalUnlock16( hDrvr
);
130 GlobalFree16( hDrvr
);
134 lpnewdrv
->lpNextItem
= NULL
;
135 if (lpDrvItemList
== NULL
)
137 lpDrvItemList
= lpnewdrv
;
138 lpnewdrv
->lpPrevItem
= NULL
;
142 lpdrv
->lpNextItem
= lpnewdrv
;
143 lpnewdrv
->lpPrevItem
= lpdrv
;
146 SendDriverMessage( hDrvr
, DRV_LOAD
, 0L, lParam
);
147 SendDriverMessage( hDrvr
, DRV_ENABLE
, 0L, lParam
);
148 SendDriverMessage( hDrvr
, DRV_OPEN
, 0L, lParam
);
150 dprintf_driver( stddeb
, "OpenDriver // hDrvr=%04x loaded !\n", hDrvr
);
154 /**************************************************************************
155 * CloseDriver [USER.253]
157 LRESULT
CloseDriver(HDRVR16 hDrvr
, LPARAM lParam1
, LPARAM lParam2
)
161 dprintf_driver( stddeb
, "CloseDriver(%04x, %08lX, %08lX);\n",
162 hDrvr
, lParam1
, lParam2
);
164 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
165 if (lpdrv
!= NULL
&& lpdrv
->dis
.hDriver
== hDrvr
)
167 SendDriverMessage( hDrvr
, DRV_CLOSE
, lParam1
, lParam2
);
168 if (--lpdrv
->count
== 0)
170 SendDriverMessage( hDrvr
, DRV_DISABLE
, lParam1
, lParam2
);
171 SendDriverMessage( hDrvr
, DRV_FREE
, lParam1
, lParam2
);
173 if (lpdrv
->lpPrevItem
)
174 lpdrv
->lpPrevItem
->lpNextItem
= lpdrv
->lpNextItem
;
176 lpDrvItemList
= lpdrv
->lpNextItem
;
177 if (lpdrv
->lpNextItem
)
178 lpdrv
->lpNextItem
->lpPrevItem
= lpdrv
->lpPrevItem
;
180 FreeModule16( lpdrv
->dis
.hModule
);
181 GlobalUnlock16( hDrvr
);
182 GlobalFree16( hDrvr
);
185 dprintf_driver( stddeb
, "CloseDriver // hDrvr=%04x closed !\n",
192 /**************************************************************************
193 * GetDriverModuleHandle [USER.254]
195 HMODULE16
GetDriverModuleHandle(HDRVR16 hDrvr
)
198 HMODULE16 hModule
= 0;
200 dprintf_driver( stddeb
, "GetDriverModuleHandle(%04x);\n", hDrvr
);
202 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
203 if (lpdrv
!= NULL
&& lpdrv
->dis
.hDriver
== hDrvr
)
205 hModule
= lpdrv
->dis
.hModule
;
206 GlobalUnlock16( hDrvr
);
211 /**************************************************************************
212 * DefDriverProc [USER.255]
214 LRESULT
DefDriverProc(DWORD dwDevID
, HDRVR16 hDriv
, UINT16 wMsg
,
215 LPARAM lParam1
, LPARAM lParam2
)
231 case DRV_QUERYCONFIGURE
:
235 MessageBox16( 0, "Driver isn't configurable !", "Wine Driver", MB_OK
);
239 return (LRESULT
)DRVCNF_RESTART
;
242 return (LRESULT
)DRVCNF_RESTART
;
249 /**************************************************************************
250 * GetDriverInfo [USER.256]
252 BOOL16
GetDriverInfo(HDRVR16 hDrvr
, LPDRIVERINFOSTRUCT16 lpDrvInfo
)
256 dprintf_driver( stddeb
, "GetDriverInfo(%04x, %p);\n", hDrvr
, lpDrvInfo
);
258 if (lpDrvInfo
== NULL
) return FALSE
;
260 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
261 if (lpdrv
== NULL
) return FALSE
;
262 memcpy( lpDrvInfo
, &lpdrv
->dis
, sizeof(DRIVERINFOSTRUCT16
) );
263 GlobalUnlock16( hDrvr
);
268 /**************************************************************************
269 * GetNextDriver [USER.257]
271 HDRVR16
GetNextDriver(HDRVR16 hDrvr
, DWORD dwFlags
)
276 dprintf_driver( stddeb
, "GetNextDriver(%04x, %08lX);\n", hDrvr
, dwFlags
);
280 if (lpDrvItemList
== NULL
)
282 dprintf_driver(stddeb
, "GetNextDriver // drivers list empty !\n");
283 LoadStartupDrivers();
284 if (lpDrvItemList
== NULL
) return 0;
286 dprintf_driver( stddeb
,"GetNextDriver // return first %04x !\n",
287 lpDrvItemList
->dis
.hDriver
);
288 return lpDrvItemList
->dis
.hDriver
;
291 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
294 if (dwFlags
& GND_REVERSE
)
296 if (lpdrv
->lpPrevItem
)
297 hRetDrv
= lpdrv
->lpPrevItem
->dis
.hDriver
;
301 if (lpdrv
->lpNextItem
)
302 hRetDrv
= lpdrv
->lpNextItem
->dis
.hDriver
;
304 GlobalUnlock16( hDrvr
);
307 dprintf_driver( stddeb
, "GetNextDriver // return %04x !\n", hRetDrv
);