2 * WINE Drivers functions
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1998 Marcus Meissner
8 #include "wine/winuser16.h"
17 LPDRIVERITEM lpDrvItemList
= NULL
;
18 LPDRIVERITEM32A lpDrvItemList32
= NULL
;
20 /**************************************************************************
23 static void LoadStartupDrivers(void)
29 if (GetPrivateProfileString32A( "drivers", NULL
, "", str
, sizeof(str
),
32 ERR( driver
,"Can't find drivers section in system.ini\n" );
37 while (lstrlen32A( ptr
) != 0)
39 TRACE(driver
, "str='%s'\n", ptr
);
40 hDrv
= OpenDriver16( ptr
, "drivers", 0L );
41 TRACE(driver
, "hDrv=%04x\n", hDrv
);
42 ptr
+= lstrlen32A(ptr
) + 1;
44 TRACE(driver
, "end of list !\n" );
48 /**************************************************************************
49 * SendDriverMessage [USER.251]
51 LRESULT WINAPI
SendDriverMessage16(HDRVR16 hDriver
, UINT16 msg
, LPARAM lParam1
,
57 TRACE(driver
, "(%04x, %04X, %08lX, %08lX)\n",
58 hDriver
, msg
, lParam1
, lParam2
);
60 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDriver
);
61 if (lpdrv
== NULL
|| lpdrv
->dis
.hDriver
!= hDriver
)
63 GlobalUnlock16( hDriver
);
67 retval
= Callbacks
->CallDriverProc( lpdrv
->lpDrvProc
, 0L /* FIXME */,
68 hDriver
, msg
, lParam1
, lParam2
);
70 TRACE(driver
, "retval = %ld\n", retval
);
72 GlobalUnlock16( hDriver
);
76 /**************************************************************************
77 * SendDriverMessage [WINMM.19]
79 LRESULT WINAPI
SendDriverMessage32(HDRVR32 hDriver
, UINT32 msg
, LPARAM lParam1
,
82 LPDRIVERITEM32A lpdrv
;
85 TRACE(driver
, "(%04x, %04X, %08lX, %08lX)\n",
86 hDriver
, msg
, lParam1
, lParam2
);
88 lpdrv
= (LPDRIVERITEM32A
)hDriver
;
92 retval
= lpdrv
->driverproc(lpdrv
->dis
.hDriver
,hDriver
,msg
,lParam1
,lParam2
);
94 TRACE(driver
, "retval = %ld\n", retval
);
99 /**************************************************************************
100 * OpenDriver [USER.252]
102 HDRVR16 WINAPI
OpenDriver16(
103 LPCSTR lpDriverName
, LPCSTR lpSectionName
, LPARAM lParam
106 LPDRIVERITEM lpdrv
, lpnewdrv
;
109 TRACE(driver
,"('%s', '%s', %08lX);\n",
110 lpDriverName
, lpSectionName
, lParam
);
112 if (lpSectionName
== NULL
) {
113 lstrcpyn32A(DrvName
,lpDriverName
,sizeof(DrvName
));
114 FIXME(driver
,"sectionname NULL, assuming directfilename (%s)\n",lpDriverName
);
116 GetPrivateProfileString32A( lpSectionName
, lpDriverName
, "", DrvName
,
117 sizeof(DrvName
), "SYSTEM.INI" );
119 TRACE(driver
,"DrvName='%s'\n", DrvName
);
120 if (lstrlen32A(DrvName
) < 1) return 0;
122 lpdrv
= lpDrvItemList
;
123 while (lpdrv
) /* XXX find it... like this? */
125 if (!strcasecmp( lpDriverName
, lpdrv
->dis
.szAliasName
))
128 SendDriverMessage16( lpdrv
->dis
.hDriver
, DRV_OPEN
, 0L, lParam
);
129 return lpdrv
->dis
.hDriver
;
131 lpdrv
= lpdrv
->lpNextItem
;
134 lpdrv
= lpDrvItemList
; /* find end of list */
136 while (lpdrv
->lpNextItem
!= NULL
)
137 lpdrv
= lpdrv
->lpNextItem
;
139 hDrvr
= GlobalAlloc16( GMEM_MOVEABLE
, sizeof(DRIVERITEM
) );
140 lpnewdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
141 if (lpnewdrv
== NULL
) return 0;
142 lpnewdrv
->dis
.length
= sizeof( DRIVERINFOSTRUCT16
);
143 lpnewdrv
->dis
.hModule
= LoadModule16( DrvName
, (LPVOID
)-1 );
144 if (!lpnewdrv
->dis
.hModule
)
146 GlobalUnlock16( hDrvr
);
147 GlobalFree16( hDrvr
);
150 lpnewdrv
->dis
.hDriver
= hDrvr
;
151 lstrcpy32A( lpnewdrv
->dis
.szAliasName
, lpDriverName
);
153 if (!(lpnewdrv
->lpDrvProc
= (DRIVERPROC16
)WIN32_GetProcAddress16(lpnewdrv
->dis
.hModule
, "DRIVERPROC" )))
155 FreeModule16( lpnewdrv
->dis
.hModule
);
156 GlobalUnlock16( hDrvr
);
157 GlobalFree16( hDrvr
);
161 lpnewdrv
->lpNextItem
= NULL
;
162 if (lpDrvItemList
== NULL
)
164 lpDrvItemList
= lpnewdrv
;
165 lpnewdrv
->lpPrevItem
= NULL
;
169 lpdrv
->lpNextItem
= lpnewdrv
;
170 lpnewdrv
->lpPrevItem
= lpdrv
;
173 SendDriverMessage16( hDrvr
, DRV_LOAD
, 0L, lParam
);
174 SendDriverMessage16( hDrvr
, DRV_ENABLE
, 0L, lParam
);
175 SendDriverMessage16( hDrvr
, DRV_OPEN
, 0L, lParam
);
177 TRACE(driver
, "hDrvr=%04x loaded !\n", hDrvr
);
181 /**************************************************************************
182 * OpenDriver [WINMM.15]
183 * (0,1,DRV_LOAD ,0 ,0)
184 * (0,1,DRV_ENABLE,0 ,0)
185 * (0,1,DRV_OPEN ,buf[256],0)
187 HDRVR32 WINAPI
OpenDriver32A(
188 LPCSTR lpDriverName
, LPCSTR lpSectionName
, LPARAM lParam
191 LPDRIVERITEM32A lpdrv
, lpnewdrv
;
192 char DrvName
[128],*tmpbuf
;
194 TRACE(driver
,"('%s', '%s', %08lX);\n",
195 lpDriverName
,lpSectionName
,lParam
);
197 if (lpSectionName
== NULL
) {
198 lstrcpyn32A(DrvName
,lpDriverName
,sizeof(DrvName
));
199 FIXME(driver
,"sectionname NULL, assuming directfilename (%s)\n",lpDriverName
);
201 GetPrivateProfileString32A( lpSectionName
, lpDriverName
, "", DrvName
,
202 sizeof(DrvName
), "system.ini" );
204 TRACE(driver
,"DrvName='%s'\n", DrvName
);
205 if (lstrlen32A(DrvName
) < 1) return 0;
207 lpdrv
= lpDrvItemList32
;
209 if (!strcasecmp( lpDriverName
, lpdrv
->dis
.szAliasName
)) {
211 lpdrv
->dis
.hDriver
= SendDriverMessage32( lpdrv
->dis
.hDriver
, DRV_OPEN
, (LPARAM
)""/*FIXME*/, 0L );
212 return (HDRVR32
)lpdrv
;
217 hDrvr
= (HDRVR32
)HeapAlloc(SystemHeap
,0, sizeof(DRIVERITEM32A
) );
219 ERR(driver
,"out of memory");
222 lpnewdrv
= (DRIVERITEM32A
*)hDrvr
;
223 lpnewdrv
->dis
.length
= sizeof( DRIVERINFOSTRUCT32A
);
224 lpnewdrv
->dis
.hModule
= LoadLibrary32A( DrvName
);
225 if (!lpnewdrv
->dis
.hModule
) {
226 FIXME(driver
,"could not load library %s\n",DrvName
);
227 HeapFree( SystemHeap
,0,(LPVOID
)hDrvr
);
230 lstrcpy32A( lpnewdrv
->dis
.szAliasName
, lpDriverName
);
232 if (!(lpnewdrv
->driverproc
= (DRIVERPROC32
)GetProcAddress32(lpnewdrv
->dis
.hModule
, "DriverProc" )))
234 FIXME(driver
,"no 'DriverProc' found in %s\n",DrvName
);
235 FreeModule32( lpnewdrv
->dis
.hModule
);
236 HeapFree( SystemHeap
,0, (LPVOID
)hDrvr
);
240 lpnewdrv
->next
= lpDrvItemList32
;
241 lpDrvItemList32
= lpnewdrv
;
243 SendDriverMessage32( hDrvr
, DRV_LOAD
, 0L, lParam
);
244 SendDriverMessage32( hDrvr
, DRV_ENABLE
, 0L, lParam
);
245 tmpbuf
= HeapAlloc(SystemHeap
,0,256);
246 lpnewdrv
->dis
.hDriver
=SendDriverMessage32(hDrvr
,DRV_OPEN
,(LPARAM
)tmpbuf
,lParam
);
247 HeapFree(SystemHeap
,0,tmpbuf
);
248 TRACE(driver
, "hDrvr=%04x loaded !\n", hDrvr
);
252 /**************************************************************************
253 * OpenDriver [WINMM.15]
255 HDRVR32 WINAPI
OpenDriver32W(
256 LPCWSTR lpDriverName
, LPCWSTR lpSectionName
, LPARAM lParam
258 LPSTR dn
= HEAP_strdupWtoA(GetProcessHeap(),0,lpDriverName
);
259 LPSTR sn
= HEAP_strdupWtoA(GetProcessHeap(),0,lpSectionName
);
260 HDRVR32 ret
= OpenDriver32A(dn
,sn
,lParam
);
262 if (dn
) HeapFree(GetProcessHeap(),0,dn
);
263 if (sn
) HeapFree(GetProcessHeap(),0,sn
);
267 /**************************************************************************
268 * CloseDriver [USER.253]
270 LRESULT WINAPI
CloseDriver16(HDRVR16 hDrvr
, LPARAM lParam1
, LPARAM lParam2
)
274 TRACE(driver
, "(%04x, %08lX, %08lX);\n",
275 hDrvr
, lParam1
, lParam2
);
277 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
278 if (lpdrv
!= NULL
&& lpdrv
->dis
.hDriver
== hDrvr
)
280 SendDriverMessage16( hDrvr
, DRV_CLOSE
, lParam1
, lParam2
);
281 if (--lpdrv
->count
== 0)
283 SendDriverMessage16( hDrvr
, DRV_DISABLE
, lParam1
, lParam2
);
284 SendDriverMessage16( hDrvr
, DRV_FREE
, lParam1
, lParam2
);
286 if (lpdrv
->lpPrevItem
)
287 lpdrv
->lpPrevItem
->lpNextItem
= lpdrv
->lpNextItem
;
289 lpDrvItemList
= lpdrv
->lpNextItem
;
290 if (lpdrv
->lpNextItem
)
291 lpdrv
->lpNextItem
->lpPrevItem
= lpdrv
->lpPrevItem
;
293 FreeModule16( lpdrv
->dis
.hModule
);
294 GlobalUnlock16( hDrvr
);
295 GlobalFree16( hDrvr
);
298 TRACE(driver
, "hDrvr=%04x closed !\n",
305 /**************************************************************************
306 * GetDriverModuleHandle [USER.254]
308 HMODULE16 WINAPI
GetDriverModuleHandle16(HDRVR16 hDrvr
)
311 HMODULE16 hModule
= 0;
313 TRACE(driver
, "(%04x);\n", hDrvr
);
315 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
316 if (lpdrv
!= NULL
&& lpdrv
->dis
.hDriver
== hDrvr
)
318 hModule
= lpdrv
->dis
.hModule
;
319 GlobalUnlock16( hDrvr
);
324 /**************************************************************************
325 * GetDriverModuleHandle [USER.254]
327 HMODULE32 WINAPI
GetDriverModuleHandle32(HDRVR32 hDrvr
)
329 LPDRIVERITEM32A lpdrv
= (LPDRIVERITEM32A
)hDrvr
;
331 TRACE(driver
, "(%04x);\n", hDrvr
);
334 return lpdrv
->dis
.hModule
;
337 /**************************************************************************
338 * DefDriverProc16 [USER.255]
340 LRESULT WINAPI
DefDriverProc16(DWORD dwDevID
, HDRVR16 hDriv
, UINT16 wMsg
,
341 LPARAM lParam1
, LPARAM lParam2
)
357 case DRV_QUERYCONFIGURE
:
361 MessageBox16( 0, "Driver isn't configurable !", "Wine Driver", MB_OK
);
365 return (LRESULT
)DRVCNF_RESTART
;
368 return (LRESULT
)DRVCNF_RESTART
;
375 /**************************************************************************
376 * GetDriverInfo [USER.256]
378 BOOL16 WINAPI
GetDriverInfo(HDRVR16 hDrvr
, LPDRIVERINFOSTRUCT16 lpDrvInfo
)
382 TRACE(driver
, "(%04x, %p);\n", hDrvr
, lpDrvInfo
);
384 if (lpDrvInfo
== NULL
) return FALSE
;
386 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
387 if (lpdrv
== NULL
) return FALSE
;
388 memcpy( lpDrvInfo
, &lpdrv
->dis
, sizeof(DRIVERINFOSTRUCT16
) );
389 GlobalUnlock16( hDrvr
);
394 /**************************************************************************
395 * GetNextDriver [USER.257]
397 HDRVR16 WINAPI
GetNextDriver(HDRVR16 hDrvr
, DWORD dwFlags
)
402 TRACE(driver
, "(%04x, %08lX);\n", hDrvr
, dwFlags
);
406 if (lpDrvItemList
== NULL
)
408 TRACE(driver
, "drivers list empty !\n");
409 LoadStartupDrivers();
410 if (lpDrvItemList
== NULL
) return 0;
412 TRACE(driver
,"return first %04x !\n",
413 lpDrvItemList
->dis
.hDriver
);
414 return lpDrvItemList
->dis
.hDriver
;
417 lpdrv
= (LPDRIVERITEM
)GlobalLock16( hDrvr
);
420 if (dwFlags
& GND_REVERSE
)
422 if (lpdrv
->lpPrevItem
)
423 hRetDrv
= lpdrv
->lpPrevItem
->dis
.hDriver
;
427 if (lpdrv
->lpNextItem
)
428 hRetDrv
= lpdrv
->lpNextItem
->dis
.hDriver
;
430 GlobalUnlock16( hDrvr
);
433 TRACE(driver
, "return %04x !\n", hRetDrv
);