* Include NDK headers on-demand.
[reactos.git] / reactos / dll / win32 / setupapi / setupapi_private.h
1 /*
2 * Copyright 2001 Andreas Mohr
3 * Copyright 2005-2006 Hervé Poussineau
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #ifndef __SETUPAPI_PRIVATE_H
21 #define __SETUPAPI_PRIVATE_H
22
23 #include <assert.h>
24 #include <errno.h>
25 #include <fcntl.h>
26 #include <limits.h>
27 #include <share.h>
28 #include <wchar.h>
29
30 #define WIN32_NO_STATUS
31 #define COBJMACROS
32 #include <windows.h>
33 #include <aclapi.h>
34 #include <cfgmgr32.h>
35 #include <fdi.h>
36 #include <reason.h>
37 #include <regstr.h>
38 #include <sddl.h>
39 #include <setupapi.h>
40 #include <shlobj.h>
41 #include <wine/debug.h>
42 #include <wine/unicode.h>
43 #define NTOS_MODE_USER
44 #include <ndk/cmfuncs.h>
45 #include <ndk/obfuncs.h>
46 #include <ndk/rtlfuncs.h>
47
48 #include <pseh/pseh2.h>
49
50 #include <pnp_c.h>
51 #include "rpc_private.h"
52 #include "resource.h"
53
54 #ifdef __REACTOS__
55 #undef __WINESRC__
56 #endif
57
58 #define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff057
59 #define SETUP_CLASS_IMAGE_LIST_MAGIC 0xd00ff058
60
61 #define CMP_MAGIC 0x01234567
62
63 struct DeviceInterface /* Element of DeviceInfo.InterfaceListHead */
64 {
65 LIST_ENTRY ListEntry;
66
67 /* Link to is parent device */
68 struct DeviceInfo *DeviceInfo;
69 GUID InterfaceClassGuid;
70
71
72 /* SPINT_ACTIVE : the interface is active/enabled
73 * SPINT_DEFAULT: the interface is the default interface for the device class
74 * SPINT_REMOVED: the interface is removed
75 */
76 DWORD Flags;
77
78 /* Contains the symbolic link of this interface, for example
79 * \\?\ACPI#PNP0501#4&2658d0a0&0#{GUID} */
80 WCHAR SymbolicLink[ANYSIZE_ARRAY];
81 };
82
83 /* We don't want to open the .inf file to read only one information in it, so keep a handle to it once it
84 * has been already loaded once. Keep also a reference counter */
85 struct InfFileDetails
86 {
87 /* Handle to the .inf file */
88 HINF hInf;
89 /* Reference count to this object. Once it raises 0, the .inf file is
90 * automatically closed and this memory structure is deleted */
91 LONG References;
92
93 /* Contains the directory name of the .inf file.
94 * Points into szData at then end of the structure */
95 PCWSTR DirectoryName;
96 /* Contains the .inf file name (without directory name).
97 * Points into szData at then end of the structure */
98 PCWSTR FileName;
99
100 /* Variable size array (contains data for DirectoryName and FileName) */
101 WCHAR szData[ANYSIZE_ARRAY];
102 };
103
104 struct DriverInfoElement /* Element of DeviceInfoSet.DriverListHead and DeviceInfo.DriverListHead */
105 {
106 LIST_ENTRY ListEntry;
107
108 SP_DRVINSTALL_PARAMS Params;
109 ULARGE_INTEGER DriverDate;
110 SP_DRVINFO_DATA_V2_W Info;
111 SP_DRVINFO_DETAIL_DATA_W Details;
112 GUID ClassGuid;
113 LPWSTR MatchingId;
114 struct InfFileDetails *InfFileDetails;
115 };
116
117 struct ClassInstallParams
118 {
119 PSP_PROPCHANGE_PARAMS PropChangeParams;
120 PSP_ADDPROPERTYPAGE_DATA AddPropertyPageData;
121 };
122
123 struct DeviceInfo /* Element of DeviceInfoSet.ListHead */
124 {
125 LIST_ENTRY ListEntry;
126 /* Used when dealing with CM_* functions */
127 DEVINST dnDevInst;
128
129 /* Link to parent DeviceInfoSet */
130 struct DeviceInfoSet *set;
131
132 /* Reserved Field of SP_DEVINSTALL_PARAMS_W structure
133 * points to a struct DriverInfoElement */
134 SP_DEVINSTALL_PARAMS_W InstallParams;
135
136 /* Information about devnode:
137 * - instanceId:
138 * "Root\*PNP0501" for example.
139 * It doesn't contain the unique ID for the device
140 * (points into the Data field at the end of the structure)
141 * WARNING: no NULL char exist between instanceId and UniqueId
142 * in Data field!
143 * - UniqueId
144 * "5&1be2108e&0" or "0000"
145 * If DICD_GENERATE_ID is specified in creation flags,
146 * this unique ID is autogenerated using 4 digits, base 10
147 * (points into the Data field at the end of the structure)
148 * - DeviceDescription
149 * String which identifies the device. Can be NULL. If not NULL,
150 * points into the Data field at the end of the structure
151 * - ClassGuid
152 * Identifies the class of this device. It is GUID_NULL if the
153 * device has not been installed
154 * - CreationFlags
155 * Is a combination of:
156 * - DICD_GENERATE_ID
157 * the unique ID needs to be generated
158 * - DICD_INHERIT_CLASSDRVS
159 * inherit driver of the device info set (== same pointer)
160 */
161 PCWSTR instanceId;
162 PCWSTR UniqueId;
163 PCWSTR DeviceDescription;
164 GUID ClassGuid;
165 DWORD CreationFlags;
166
167 /* If CreationFlags contains DICD_INHERIT_CLASSDRVS, this list is invalid */
168 /* If the driver is not searched/detected, this list is empty */
169 LIST_ENTRY DriverListHead; /* List of struct DriverInfoElement */
170
171 /* List of interfaces implemented by this device */
172 LIST_ENTRY InterfaceListHead; /* List of struct DeviceInterface */
173
174 /* Used by SetupDiGetClassInstallParamsW/SetupDiSetClassInstallParamsW */
175 struct ClassInstallParams ClassInstallParams;
176
177 /* Variable size array (contains data for instanceId, UniqueId, DeviceDescription) */
178 WCHAR Data[ANYSIZE_ARRAY];
179 };
180
181 struct DeviceInfoSet /* HDEVINFO */
182 {
183 DWORD magic; /* SETUP_DEVICE_INFO_SET_MAGIC */
184 /* If != GUID_NULL, only devices of this class can be in the device info set */
185 GUID ClassGuid;
186 /* Local or distant HKEY_LOCAL_MACHINE registry key */
187 HKEY HKLM;
188 /* Used when dealing with CM_* functions */
189 HMACHINE hMachine;
190
191 /* Reserved Field points to a struct DriverInfoElement */
192 SP_DEVINSTALL_PARAMS_W InstallParams;
193
194 /* List of struct DriverInfoElement (if no driver has been
195 * searched/detected, this list is empty) */
196 LIST_ENTRY DriverListHead;
197
198 /* List of struct DeviceInfo */
199 LIST_ENTRY ListHead;
200 struct DeviceInfo *SelectedDevice;
201
202 /* Used by SetupDiGetClassInstallParamsW/SetupDiSetClassInstallParamsW */
203 struct ClassInstallParams ClassInstallParams;
204
205 /* Contains the name of the remote computer ('\\COMPUTERNAME' for example),
206 * or NULL if related to local machine. Points into szData field at the
207 * end of the structure */
208 PCWSTR MachineName;
209
210 /* Variable size array (contains data for MachineName) */
211 WCHAR szData[ANYSIZE_ARRAY];
212 };
213
214 struct ClassImageList
215 {
216 DWORD magic; /* SETUP_CLASS_IMAGE_LIST_MAGIC */
217
218 /* Number of GUIDs contained in Guids and IconIndexes arrays */
219 DWORD NumberOfGuids;
220 /* Array of GUIDs associated to icons of the image list. Its size
221 * is NumberOfGuids and is pointing after the end this structure */
222 GUID* Guids;
223 /* Array of corresponding icons index in the image list. Its size
224 * is NumberOfGuids and is pointing after the end this structure */
225 INT* IconIndexes;
226 };
227
228 struct FileLog /* HSPFILELOG */
229 {
230 DWORD ReadOnly;
231 DWORD SystemLog;
232 LPWSTR LogName;
233 };
234
235 extern HINSTANCE hInstance;
236 #define RC_STRING_MAX_SIZE 256
237
238 #define REG_INSTALLEDFILES "System\\CurrentControlSet\\Control\\InstalledFiles"
239 #define REGPART_RENAME "\\Rename"
240 #define REG_VERSIONCONFLICT "Software\\Microsoft\\VersionConflictManager"
241
242 inline static WCHAR *strdupAtoW( const char *str )
243 {
244 WCHAR *ret = NULL;
245 if (str)
246 {
247 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
248 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
249 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
250 }
251 return ret;
252 }
253
254 /* string substitutions */
255
256 struct inf_file;
257 extern const WCHAR *DIRID_get_string( int dirid );
258 extern unsigned int PARSER_string_substA( const struct inf_file *file, const WCHAR *text,
259 char *buffer, unsigned int size );
260 extern unsigned int PARSER_string_substW( const struct inf_file *file, const WCHAR *text,
261 WCHAR *buffer, unsigned int size );
262 extern const WCHAR *PARSER_get_inf_filename( HINF hinf );
263 extern WCHAR *PARSER_get_src_root( HINF hinf );
264 extern WCHAR *PARSER_get_dest_dir( INFCONTEXT *context );
265
266 /* support for Ascii queue callback functions */
267
268 struct callback_WtoA_context
269 {
270 void *orig_context;
271 PSP_FILE_CALLBACK_A orig_handler;
272 };
273
274 UINT CALLBACK QUEUE_callback_WtoA( void *context, UINT notification, UINT_PTR, UINT_PTR );
275
276 /* from msvcrt/sys/stat.h */
277 #define _S_IWRITE 0x0080
278 #define _S_IREAD 0x0100
279
280 extern HINSTANCE hInstance;
281 extern OSVERSIONINFOW OsVersionInfo;
282
283 /* devinst.c */
284
285 BOOL
286 CreateDeviceInfo(
287 IN struct DeviceInfoSet *list,
288 IN LPCWSTR InstancePath,
289 IN LPCGUID pClassGuid,
290 OUT struct DeviceInfo **pDeviceInfo);
291
292 LONG
293 SETUP_CreateDevicesList(
294 IN OUT struct DeviceInfoSet *list,
295 IN PCWSTR MachineName OPTIONAL,
296 IN CONST GUID *Class OPTIONAL,
297 IN PCWSTR Enumerator OPTIONAL);
298
299 /* driver.c */
300
301 struct InfFileDetails *
302 CreateInfFileDetails(
303 IN LPCWSTR FullInfFileName);
304
305 VOID
306 DereferenceInfFile(struct InfFileDetails* infFile);
307
308 BOOL
309 DestroyDriverInfoElement(struct DriverInfoElement* driverInfo);
310
311 /* install.c */
312
313 BOOL
314 GetStringField( PINFCONTEXT context, DWORD index, PWSTR *value);
315
316 /* interface.c */
317
318 BOOL
319 DestroyDeviceInterface(
320 struct DeviceInterface* deviceInterface);
321
322 LONG
323 SETUP_CreateInterfaceList(
324 struct DeviceInfoSet *list,
325 PCWSTR MachineName,
326 CONST GUID *InterfaceGuid,
327 PCWSTR DeviceInstanceW /* OPTIONAL */,
328 BOOL OnlyPresentInterfaces);
329
330 /* misc.c */
331
332 DWORD
333 GetFunctionPointer(
334 IN PWSTR InstallerName,
335 OUT HMODULE* ModulePointer,
336 OUT PVOID* FunctionPointer);
337
338 DWORD
339 FreeFunctionPointer(
340 IN HMODULE ModulePointer,
341 IN PVOID FunctionPointer);
342
343 DWORD
344 WINAPI
345 pSetupStringFromGuid(LPGUID lpGUID, PWSTR pString, DWORD dwStringLen);
346
347 DWORD WINAPI CaptureAndConvertAnsiArg(LPCSTR pSrc, LPWSTR *pDst);
348
349 VOID WINAPI MyFree(LPVOID lpMem);
350 LPVOID WINAPI MyMalloc(DWORD dwSize);
351 LPVOID WINAPI MyRealloc(LPVOID lpSrc, DWORD dwSize);
352 LPWSTR WINAPI DuplicateString(LPCWSTR lpSrc);
353 BOOL WINAPI IsUserAdmin(VOID);
354 LPWSTR WINAPI MultiByteToUnicode(LPCSTR lpMultiByteStr, UINT uCodePage);
355 LPSTR WINAPI UnicodeToMultiByte(LPCWSTR lpUnicodeStr, UINT uCodePage);
356
357 /* parser.c */
358
359 typedef BOOL (*FIND_CALLBACK)(LPCWSTR SectionName, PVOID Context);
360 BOOL EnumerateSectionsStartingWith(HINF hInf, LPCWSTR pStr, FIND_CALLBACK Callback, PVOID Context);
361
362 #endif /* __SETUPAPI_PRIVATE_H */