Release 941017
[wine/gsoc-2012-control.git] / misc / driver.c
blob7e1b9fc8a500135fce4b9c97f0d00a9f31cee618
1 /*
2 * Wine Drivers functions
4 * Copyright 1994 Martin Ayotte
5 */
7 static char Copyright[] = "Copyright Martin Ayotte, 1994";
9 #include <stdio.h>
10 #include "windows.h"
11 #include "win.h"
12 #include "user.h"
13 #include "dlls.h"
14 #include "driver.h"
15 #include "stddebug.h"
16 /* #define DEBUG_DRIVER /* */
17 /* #undef DEBUG_DRIVER /* */
18 #include "debug.h"
20 LPDRIVERITEM lpDrvItemList = NULL;
22 void LoadStartupDrivers()
24 HDRVR hDrv;
25 char str[256];
26 LPSTR ptr = str;
27 LPSTR file = "SYSTEM.INI";
28 if (GetPrivateProfileString("drivers", NULL,
29 "", str, sizeof(str), file) < 2) {
30 fprintf(stderr,
31 "LoadStartupDrivers // can't find drivers section in '%s'\n",
32 file);
33 return;
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)
59 HDRVR hDrvr;
60 LPDRIVERITEM lpnewdrv;
61 LPDRIVERITEM lpdrv = lpDrvItemList;
62 char DrvName[128];
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) {
81 GlobalUnlock(hDrvr);
82 GlobalFree(hDrvr);
83 return 0;
84 } */
85 lpnewdrv->dis.hDriver = hDrvr;
86 strcpy(lpnewdrv->dis.szAliasName, lpDriverName);
87 lpnewdrv->count = 0;
88 lpnewdrv->lpNextItem = NULL;
89 if (lpDrvItemList == NULL || lpdrv == NULL) {
90 lpDrvItemList = lpnewdrv;
91 lpnewdrv->lpPrevItem = NULL;
93 else {
94 lpdrv->lpNextItem = lpnewdrv;
95 lpnewdrv->lpPrevItem = lpdrv;
97 lpnewdrv->lpDrvProc = NULL;
98 dprintf_driver(stddeb,"OpenDriver // hDrvr=%04X loaded !\n", hDrvr);
99 return hDrvr;
102 /**************************************************************************
103 * CloseDriver [USER.253]
105 LRESULT CloseDriver(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
107 LPDRIVERITEM lpdrv;
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;
116 GlobalUnlock(hDrvr);
117 GlobalFree(hDrvr);
118 dprintf_driver(stddeb,"CloseDriver // hDrvr=%04X closed !\n", hDrvr);
119 return TRUE;
121 return FALSE;
124 /**************************************************************************
125 * GetDriverModuleHandle [USER.254]
127 HANDLE GetDriverModuleHandle(HDRVR hDrvr)
129 LPDRIVERITEM lpdrv;
130 HANDLE hModule = 0;
131 dprintf_driver(stddeb,"GetDriverModuleHandle(%04X);\n", hDrvr);
132 lpdrv = (LPDRIVERITEM) GlobalLock(hDrvr);
133 if (lpdrv != NULL) {
134 hModule = lpdrv->dis.hModule;
135 GlobalUnlock(hDrvr);
137 return hModule;
140 /**************************************************************************
141 * DefDriverProc [USER.255]
143 LRESULT DefDriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg,
144 DWORD dwParam1, DWORD dwParam2)
146 switch(wMsg) {
147 case DRV_LOAD:
148 return (LRESULT)0L;
149 case DRV_FREE:
150 return (LRESULT)0L;
151 case DRV_OPEN:
152 return (LRESULT)0L;
153 case DRV_CLOSE:
154 return (LRESULT)0L;
155 case DRV_ENABLE:
156 return (LRESULT)0L;
157 case DRV_DISABLE:
158 return (LRESULT)0L;
159 case DRV_QUERYCONFIGURE:
160 return (LRESULT)0L;
161 case DRV_CONFIGURE:
162 MessageBox((HWND)NULL, "Driver isn't configurable !",
163 "Wine Driver", MB_OK);
164 return (LRESULT)0L;
165 case DRV_INSTALL:
166 return (LRESULT)DRVCNF_RESTART;
167 case DRV_REMOVE:
168 return (LRESULT)DRVCNF_RESTART;
169 default:
170 return (LRESULT)0L;
174 /**************************************************************************
175 * GetDriverInfo [USER.256]
177 BOOL GetDriverInfo(HDRVR hDrvr, LPDRIVERINFOSTRUCT lpDrvInfo)
179 LPDRIVERITEM lpdrv;
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));
185 GlobalUnlock(hDrvr);
186 return TRUE;
189 /**************************************************************************
190 * GetNextDriver [USER.257]
192 HDRVR GetNextDriver(HDRVR hDrvr, DWORD dwFlags)
194 LPDRIVERITEM lpdrv;
195 HDRVR hRetDrv = 0;
196 dprintf_driver(stddeb,"GetNextDriver(%04X, %08X);\n", hDrvr, dwFlags);
197 if (hDrvr == 0) {
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);
209 if (lpdrv != NULL) {
210 if (dwFlags & GND_REVERSE) {
211 if (lpdrv->lpPrevItem)
212 hRetDrv = ((LPDRIVERITEM)lpdrv->lpPrevItem)->dis.hDriver;
214 else {
215 if (lpdrv->lpNextItem)
216 hRetDrv = ((LPDRIVERITEM)lpdrv->lpNextItem)->dis.hDriver;
218 GlobalUnlock(hDrvr);
220 dprintf_driver(stddeb,"GetNextDriver // return %04X !\n", hRetDrv);
221 return hRetDrv;