[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 <wingdi.h>
35 #include <winspool.h>
36 #include <wincon.h>
37 #include <objbase.h>
38 #include <cfgmgr32.h>
39 #include <regstr.h>
40 #include <sddl.h>
41 #include <setupapi.h>
42 #include <softpub.h>
43 #include <mscat.h>
44 #include <shlobj.h>
45 #include <wine/unicode.h>
46 #define NTOS_MODE_USER
47 #include <ndk/rtlfuncs.h>
48
49 #include <wine/debug.h>
50 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
51
52 #ifdef __REACTOS__
53 #undef __WINESRC__
54 #endif
55
56 #define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff057
57 #define SETUP_CLASS_IMAGE_LIST_MAGIC 0xd00ff058
58
59 #define CMP_MAGIC 0x01234567
60
61 struct DeviceInterface /* Element of DeviceInfo.InterfaceListHead */
62 {
63 LIST_ENTRY ListEntry;
64
65 /* Link to is parent device */
66 struct DeviceInfo *DeviceInfo;
67 GUID InterfaceClassGuid;
68
69
70 /* SPINT_ACTIVE : the interface is active/enabled
71 * SPINT_DEFAULT: the interface is the default interface for the device class
72 * SPINT_REMOVED: the interface is removed
73 */
74 DWORD Flags;
75
76 /* Contains the symbolic link of this interface, for example
77 * \\?\ACPI#PNP0501#4&2658d0a0&0#{GUID} */
78 WCHAR SymbolicLink[ANYSIZE_ARRAY];
79 };
80
81 /* We don't want to open the .inf file to read only one information in it, so keep a handle to it once it
82 * has been already loaded once. Keep also a reference counter */
83 struct InfFileDetails
84 {
85 /* Handle to the .inf file */
86 HINF hInf;
87 /* Reference count to this object. Once it raises 0, the .inf file is
88 * automatically closed and this memory structure is deleted */
89 LONG References;
90
91 /* Contains the directory name of the .inf file.
92 * Points into szData at then end of the structure */
93 PCWSTR DirectoryName;
94 /* Contains the .inf file name (without directory name).
95 * Points into szData at then end of the structure */
96 PCWSTR FileName;
97
98 /* Variable size array (contains data for DirectoryName and FileName) */
99 WCHAR szData[ANYSIZE_ARRAY];
100 };
101
102 struct DriverInfoElement /* Element of DeviceInfoSet.DriverListHead and DeviceInfo.DriverListHead */
103 {
104 LIST_ENTRY ListEntry;
105
106 SP_DRVINSTALL_PARAMS Params;
107 ULARGE_INTEGER DriverDate;
108 SP_DRVINFO_DATA_V2_W Info;
109 SP_DRVINFO_DETAIL_DATA_W Details;
110 GUID ClassGuid;
111 LPWSTR MatchingId;
112 struct InfFileDetails *InfFileDetails;
113 };
114
115 struct ClassInstallParams
116 {
117 PSP_PROPCHANGE_PARAMS PropChangeParams;
118 PSP_ADDPROPERTYPAGE_DATA AddPropertyPageData;
119 };
120
121 struct DeviceInfo /* Element of DeviceInfoSet.ListHead */
122 {
123 LIST_ENTRY ListEntry;
124 /* Used when dealing with CM_* functions */
125 DEVINST dnDevInst;
126
127 /* Link to parent DeviceInfoSet */
128 struct DeviceInfoSet *set;
129
130 /* Reserved Field of SP_DEVINSTALL_PARAMS_W structure
131 * points to a struct DriverInfoElement */
132 SP_DEVINSTALL_PARAMS_W InstallParams;
133
134 /* Information about devnode:
135 * - instanceId:
136 * "Root\*PNP0501" for example.
137 * It doesn't contain the unique ID for the device
138 * (points into the Data field at the end of the structure)
139 * WARNING: no NULL char exist between instanceId and UniqueId
140 * in Data field!
141 * - UniqueId
142 * "5&1be2108e&0" or "0000"
143 * If DICD_GENERATE_ID is specified in creation flags,
144 * this unique ID is autogenerated using 4 digits, base 10
145 * (points into the Data field at the end of the structure)
146 * - DeviceDescription
147 * String which identifies the device. Can be NULL. If not NULL,
148 * points into the Data field at the end of the structure
149 * - ClassGuid
150 * Identifies the class of this device. It is GUID_NULL if the
151 * device has not been installed
152 * - CreationFlags
153 * Is a combination of:
154 * - DICD_GENERATE_ID
155 * the unique ID needs to be generated
156 * - DICD_INHERIT_CLASSDRVS
157 * inherit driver of the device info set (== same pointer)
158 */
159 PCWSTR instanceId;
160 PCWSTR UniqueId;
161 PCWSTR DeviceDescription;
162 GUID ClassGuid;
163 DWORD CreationFlags;
164
165 /* If CreationFlags contains DICD_INHERIT_CLASSDRVS, this list is invalid */
166 /* If the driver is not searched/detected, this list is empty */
167 LIST_ENTRY DriverListHead; /* List of struct DriverInfoElement */
168
169 /* List of interfaces implemented by this device */
170 LIST_ENTRY InterfaceListHead; /* List of struct DeviceInterface */
171
172 /* Used by SetupDiGetClassInstallParamsW/SetupDiSetClassInstallParamsW */
173 struct ClassInstallParams ClassInstallParams;
174
175 /* Device property page provider data */
176 HMODULE hmodDevicePropPageProvider;
177 PVOID pDevicePropPageProvider;
178
179 /* Variable size array (contains data for instanceId, UniqueId, DeviceDescription) */
180 WCHAR Data[ANYSIZE_ARRAY];
181 };
182
183 struct DeviceInfoSet /* HDEVINFO */
184 {
185 DWORD magic; /* SETUP_DEVICE_INFO_SET_MAGIC */
186 /* If != GUID_NULL, only devices of this class can be in the device info set */
187 GUID ClassGuid;
188 /* Local or distant HKEY_LOCAL_MACHINE registry key */
189 HKEY HKLM;
190 /* Used when dealing with CM_* functions */
191 HMACHINE hMachine;
192
193 /* Reserved Field points to a struct DriverInfoElement */
194 SP_DEVINSTALL_PARAMS_W InstallParams;
195
196 /* List of struct DriverInfoElement (if no driver has been
197 * searched/detected, this list is empty) */
198 LIST_ENTRY DriverListHead;
199
200 /* List of struct DeviceInfo */
201 LIST_ENTRY ListHead;
202 struct DeviceInfo *SelectedDevice;
203
204 /* Used by SetupDiGetClassInstallParamsW/SetupDiSetClassInstallParamsW */
205 struct ClassInstallParams ClassInstallParams;
206
207 /* Class property page provider data */
208 HMODULE hmodClassPropPageProvider;
209 PVOID pClassPropPageProvider;
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 */