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