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