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