2 * Wine Drivers functions
4 * Copyright 1994 Martin Ayotte
7 static char Copyright
[] = "Copyright Martin Ayotte, 1994";
16 /* #define DEBUG_DRIVER /* */
17 /* #undef DEBUG_DRIVER /* */
20 LPDRIVERITEM lpDrvItemList
= NULL
;
22 void LoadStartupDrivers()
27 LPSTR file
= "SYSTEM.INI";
28 if (GetPrivateProfileString("drivers", NULL
,
29 "", str
, sizeof(str
), file
) < 2) {
31 "LoadStartupDrivers // can't find drivers section in '%s'\n",
35 while(strlen(ptr
) != 0) {
36 dprintf_driver(stddeb
,"LoadStartupDrivers // str='%s'\n", ptr
);
37 hDrv
= OpenDriver(ptr
, "drivers", 0L);
38 dprintf_driver(stddeb
,
39 "LoadStartupDrivers // hDrv=%04X\n", hDrv
);
40 ptr
+= strlen(ptr
) + 1;
42 dprintf_driver(stddeb
,"LoadStartupDrivers // end of list !\n");
45 /**************************************************************************
46 * SendDriverMessage [USER.251]
48 LRESULT WINAPI
SendDriverMessage(HDRVR hDriver
, WORD msg
, LPARAM lParam1
, LPARAM lParam2
)
50 dprintf_driver(stdnimp
,"SendDriverMessage(%04X, %04X, %08X, %08X);\n",
51 hDriver
, msg
, lParam1
, lParam2
);
54 /**************************************************************************
55 * OpenDriver [USER.252]
57 HDRVR
OpenDriver(LPSTR lpDriverName
, LPSTR lpSectionName
, LPARAM lParam
)
60 LPDRIVERITEM lpnewdrv
;
61 LPDRIVERITEM lpdrv
= lpDrvItemList
;
63 dprintf_driver(stddeb
,"OpenDriver('%s', '%s', %08X);\n",
64 lpDriverName
, lpSectionName
, lParam
);
65 if (lpSectionName
== NULL
) lpSectionName
= "drivers";
66 GetPrivateProfileString(lpSectionName
, lpDriverName
,
67 "", DrvName
, sizeof(DrvName
), "SYSTEM.INI");
68 dprintf_driver(stddeb
,"OpenDriver // DrvName='%s'\n", DrvName
);
69 if (strlen(DrvName
) < 1) return 0;
70 while (lpdrv
!= NULL
) {
71 if (lpdrv
->lpNextItem
== NULL
) break;
72 lpdrv
= lpdrv
->lpNextItem
;
74 hDrvr
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(DRIVERITEM
));
75 lpnewdrv
= (LPDRIVERITEM
) GlobalLock(hDrvr
);
76 if (lpnewdrv
== NULL
) return 0;
77 lpnewdrv
->dis
.length
= sizeof(DRIVERINFOSTRUCT
);
78 lpnewdrv
->dis
.hModule
= 0;
79 /* lpnewdrv->dis.hModule = LoadImage(DrvName, DLL, 0);
80 if (lpnewdrv->dis.hModule == 0) {
85 lpnewdrv
->dis
.hDriver
= hDrvr
;
86 strcpy(lpnewdrv
->dis
.szAliasName
, lpDriverName
);
88 lpnewdrv
->lpNextItem
= NULL
;
89 if (lpDrvItemList
== NULL
|| lpdrv
== NULL
) {
90 lpDrvItemList
= lpnewdrv
;
91 lpnewdrv
->lpPrevItem
= NULL
;
94 lpdrv
->lpNextItem
= lpnewdrv
;
95 lpnewdrv
->lpPrevItem
= lpdrv
;
97 lpnewdrv
->lpDrvProc
= NULL
;
98 dprintf_driver(stddeb
,"OpenDriver // hDrvr=%04X loaded !\n", hDrvr
);
102 /**************************************************************************
103 * CloseDriver [USER.253]
105 LRESULT
CloseDriver(HDRVR hDrvr
, LPARAM lParam1
, LPARAM lParam2
)
108 dprintf_driver(stddeb
,
109 "CloseDriver(%04X, %08X, %08X);\n", hDrvr
, lParam1
, lParam2
);
110 lpdrv
= (LPDRIVERITEM
) GlobalLock(hDrvr
);
111 if (lpdrv
!= NULL
&& lpdrv
->dis
.hDriver
== hDrvr
) {
112 if (lpdrv
->lpPrevItem
)
113 ((LPDRIVERITEM
)lpdrv
->lpPrevItem
)->lpNextItem
= lpdrv
->lpNextItem
;
114 if (lpdrv
->lpNextItem
)
115 ((LPDRIVERITEM
)lpdrv
->lpNextItem
)->lpPrevItem
= lpdrv
->lpPrevItem
;
118 dprintf_driver(stddeb
,"CloseDriver // hDrvr=%04X closed !\n", hDrvr
);
124 /**************************************************************************
125 * GetDriverModuleHandle [USER.254]
127 HANDLE
GetDriverModuleHandle(HDRVR hDrvr
)
131 dprintf_driver(stddeb
,"GetDriverModuleHandle(%04X);\n", hDrvr
);
132 lpdrv
= (LPDRIVERITEM
) GlobalLock(hDrvr
);
134 hModule
= lpdrv
->dis
.hModule
;
140 /**************************************************************************
141 * DefDriverProc [USER.255]
143 LRESULT
DefDriverProc(DWORD dwDevID
, HDRVR hDriv
, WORD wMsg
,
144 DWORD dwParam1
, DWORD dwParam2
)
159 case DRV_QUERYCONFIGURE
:
162 MessageBox((HWND
)NULL
, "Driver isn't configurable !",
163 "Wine Driver", MB_OK
);
166 return (LRESULT
)DRVCNF_RESTART
;
168 return (LRESULT
)DRVCNF_RESTART
;
174 /**************************************************************************
175 * GetDriverInfo [USER.256]
177 BOOL
GetDriverInfo(HDRVR hDrvr
, LPDRIVERINFOSTRUCT lpDrvInfo
)
180 dprintf_driver(stddeb
,"GetDriverInfo(%04X, %08X);\n", hDrvr
, lpDrvInfo
);
181 if (lpDrvInfo
== NULL
) return FALSE
;
182 lpdrv
= (LPDRIVERITEM
) GlobalLock(hDrvr
);
183 if (lpdrv
== NULL
) return FALSE
;
184 memcpy(lpDrvInfo
, &lpdrv
->dis
, sizeof(DRIVERINFOSTRUCT
));
189 /**************************************************************************
190 * GetNextDriver [USER.257]
192 HDRVR
GetNextDriver(HDRVR hDrvr
, DWORD dwFlags
)
196 dprintf_driver(stddeb
,"GetNextDriver(%04X, %08X);\n", hDrvr
, dwFlags
);
198 if (lpDrvItemList
== NULL
) {
199 dprintf_driver(stddeb
,
200 "GetNextDriver // drivers list empty !\n");
201 LoadStartupDrivers();
202 if (lpDrvItemList
== NULL
) return 0;
204 dprintf_driver(stddeb
,"GetNextDriver // return first %04X !\n",
205 lpDrvItemList
->dis
.hDriver
);
206 return lpDrvItemList
->dis
.hDriver
;
208 lpdrv
= (LPDRIVERITEM
) GlobalLock(hDrvr
);
210 if (dwFlags
& GND_REVERSE
) {
211 if (lpdrv
->lpPrevItem
)
212 hRetDrv
= ((LPDRIVERITEM
)lpdrv
->lpPrevItem
)->dis
.hDriver
;
215 if (lpdrv
->lpNextItem
)
216 hRetDrv
= ((LPDRIVERITEM
)lpdrv
->lpNextItem
)->dis
.hDriver
;
220 dprintf_driver(stddeb
,"GetNextDriver // return %04X !\n", hRetDrv
);