Add newdev.dll, and implement DevInstallW function.
[reactos.git] / reactos / lib / newdev / newdev.c
1 /*
2 * ReactOS New devices installation
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /*
20 * PROJECT: ReactOS New devices installation
21 * FILE: lib/newdev/newdev.c
22 * PURPOSE: New devices installation
23 * PROGRAMMER: Hervé Poussineau (hpoussin@reactos.org)
24 */
25
26 #include <windows.h>
27 #include <setupapi.h>
28
29 ULONG DbgPrint(PCH Format,...);
30 #define UNIMPLEMENTED \
31 DbgPrint("NEWDEV: %s at %s:%d is UNIMPLEMENTED!\n",__FUNCTION__,__FILE__,__LINE__)
32 #define DPRINT1 DbgPrint("(%s:%d) ", __FILE__, __LINE__), DbgPrint
33
34 BOOL
35 DevInstallW(
36 IN HWND Hwnd,
37 IN HINSTANCE Handle,
38 IN LPCWSTR InstanceId,
39 IN INT Show)
40 {
41 HDEVINFO hDevInfo;
42 SP_DEVINFO_DATA devInfoData;
43 SP_DRVINFO_DATA_W drvInfoData;
44 DWORD index;
45 BOOL ret;
46
47 DbgPrint("OK\n");
48 DbgPrint("Installing device %S\n", InstanceId);
49
50 hDevInfo = SetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
51 if (hDevInfo == INVALID_HANDLE_VALUE)
52 {
53 DPRINT1("SetupDiCreateDeviceInfoListExW() failed with error 0x%lx\n", GetLastError());
54 return FALSE;
55 }
56
57 devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
58 ret = SetupDiOpenDeviceInfoW(
59 hDevInfo,
60 InstanceId,
61 NULL,
62 0, /* Open flags */
63 &devInfoData);
64 if (!ret)
65 {
66 DPRINT1("SetupDiOpenDeviceInfoW() failed with error 0x%lx\n", GetLastError());
67 return FALSE;
68 }
69
70 ret = SetupDiBuildDriverInfoList(hDevInfo, &devInfoData, SPDIT_COMPATDRIVER);
71 if (!ret)
72 {
73 DPRINT1("SetupDiBuildDriverInfoList() failed with error 0x%lx\n", GetLastError());
74 return FALSE;
75 }
76
77 #ifndef NDEBUG
78 ret = TRUE;
79 index = 0;
80 drvInfoData.cbSize = sizeof(SP_DRVINFO_DATA_W);
81 while (ret)
82 {
83 ret = SetupDiEnumDriverInfoW(
84 hDevInfo,
85 &devInfoData,
86 SPDIT_COMPATDRIVER,
87 index,
88 &drvInfoData);
89 if (!ret)
90 {
91 if (GetLastError() != ERROR_NO_MORE_ITEMS)
92 {
93 DPRINT1("SetupDiEnumDriverInfoW() failed with error 0x%lx\n", GetLastError());
94 return FALSE;
95 }
96 break;
97 }
98 index++;
99 DPRINT1("- %S: %S\n", drvInfoData.MfgName, drvInfoData.Description);
100 }
101 #endif
102
103 ret = SetupDiCallClassInstaller(
104 DIF_SELECTBESTCOMPATDRV,
105 hDevInfo,
106 &devInfoData);
107 if (!ret)
108 {
109 DPRINT1("SetupDiCallClassInstaller(DIF_SELECTBESTCOMPATDRV) failed with error 0x%lx\n", GetLastError());
110 return FALSE;
111 }
112
113 ret = SetupDiCallClassInstaller(
114 DIF_ALLOW_INSTALL,
115 hDevInfo,
116 &devInfoData);
117 if (!ret)
118 {
119 DPRINT1("SetupDiCallClassInstaller(DIF_ALLOW_INSTALL) failed with error 0x%lx\n", GetLastError());
120 return FALSE;
121 }
122
123 ret = SetupDiCallClassInstaller(
124 DIF_NEWDEVICEWIZARD_PREANALYZE,
125 hDevInfo,
126 &devInfoData);
127 if (!ret)
128 {
129 DPRINT1("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_PREANALYZE) failed with error 0x%lx\n", GetLastError());
130 return FALSE;
131 }
132
133 ret = SetupDiCallClassInstaller(
134 DIF_NEWDEVICEWIZARD_POSTANALYZE,
135 hDevInfo,
136 &devInfoData);
137 if (!ret)
138 {
139 DPRINT1("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_POSTANALYZE) failed with error 0x%lx\n", GetLastError());
140 return FALSE;
141 }
142
143 ret = SetupDiCallClassInstaller(
144 DIF_INSTALLDEVICEFILES,
145 hDevInfo,
146 &devInfoData);
147 if (!ret)
148 {
149 DPRINT1("SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES) failed with error 0x%lx\n", GetLastError());
150 return FALSE;
151 }
152
153 ret = SetupDiCallClassInstaller(
154 DIF_REGISTER_COINSTALLERS,
155 hDevInfo,
156 &devInfoData);
157 if (!ret)
158 {
159 DPRINT1("SetupDiCallClassInstaller(DIF_REGISTER_COINSTALLERS) failed with error 0x%lx\n", GetLastError());
160 return FALSE;
161 }
162
163 ret = SetupDiCallClassInstaller(
164 DIF_INSTALLINTERFACES,
165 hDevInfo,
166 &devInfoData);
167 if (!ret)
168 {
169 DPRINT1("SetupDiCallClassInstaller(DIF_INSTALLINTERFACES) failed with error 0x%lx\n", GetLastError());
170 return FALSE;
171 }
172
173 ret = SetupDiCallClassInstaller(
174 DIF_INSTALLDEVICE,
175 hDevInfo,
176 &devInfoData);
177 if (!ret)
178 {
179 DPRINT1("SetupDiCallClassInstaller(DIF_INSTALLDEVICE) failed with error 0x%lx\n", GetLastError());
180 return FALSE;
181 }
182
183 ret = SetupDiCallClassInstaller(
184 DIF_NEWDEVICEWIZARD_FINISHINSTALL,
185 hDevInfo,
186 &devInfoData);
187 if (!ret)
188 {
189 DPRINT1("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_FINISHINSTALL) failed with error 0x%lx\n", GetLastError());
190 return FALSE;
191 }
192
193 ret = SetupDiCallClassInstaller(
194 DIF_DESTROYPRIVATEDATA,
195 hDevInfo,
196 &devInfoData);
197 if (!ret)
198 {
199 DPRINT1("SetupDiCallClassInstaller(DIF_DESTROYPRIVATEDATA) failed with error 0x%lx\n", GetLastError());
200 return FALSE;
201 }
202
203 ret = SetupDiDestroyDriverInfoList(hDevInfo, &devInfoData, SPDIT_COMPATDRIVER);
204 if (!ret)
205 {
206 DPRINT1("SetupDiDestroyDriverInfoList() failed with error 0x%lx\n", GetLastError());
207 return FALSE;
208 }
209
210 ret = SetupDiDestroyDeviceInfoList(hDevInfo);
211 if (!ret)
212 {
213 DPRINT1("SetupDiDestroyDeviceInfoList() failed with error 0x%lx\n", GetLastError());
214 return FALSE;
215 }
216
217 return TRUE;
218 }