The real, definitive, Visual C++ support branch. Accept no substitutes
[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 <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 <regstr.h>
37 #include <sddl.h>
38 #include <setupapi.h>
39 #include <shlobj.h>
40 #include <wine/debug.h>
41 #include <wine/unicode.h>
42 #define NTOS_MODE_USER
43 #include <ndk/ntndk.h>
44
45 #include <pnp_c.h>
46 #include "rpc_private.h"
47 #include "resource.h"
48
49 #ifdef __REACTOS__
50 #undef __WINESRC__
51 #endif
52
53 #define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff057
54 #define SETUP_CLASS_IMAGE_LIST_MAGIC 0xd00ff058
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 extern HINSTANCE hInstance;
222 #define RC_STRING_MAX_SIZE 256
223
224 #define REG_INSTALLEDFILES "System\\CurrentControlSet\\Control\\InstalledFiles"
225 #define REGPART_RENAME "\\Rename"
226 #define REG_VERSIONCONFLICT "Software\\Microsoft\\VersionConflictManager"
227
228 inline static WCHAR *strdupAtoW( const char *str )
229 {
230 WCHAR *ret = NULL;
231 if (str)
232 {
233 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
234 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
235 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
236 }
237 return ret;
238 }
239
240 /* string substitutions */
241
242 struct inf_file;
243 extern const WCHAR *DIRID_get_string( int dirid );
244 extern unsigned int PARSER_string_substA( const struct inf_file *file, const WCHAR *text,
245 char *buffer, unsigned int size );
246 extern unsigned int PARSER_string_substW( const struct inf_file *file, const WCHAR *text,
247 WCHAR *buffer, unsigned int size );
248 extern const WCHAR *PARSER_get_inf_filename( HINF hinf );
249 extern WCHAR *PARSER_get_src_root( HINF hinf );
250 extern WCHAR *PARSER_get_dest_dir( INFCONTEXT *context );
251
252 /* support for Ascii queue callback functions */
253
254 struct callback_WtoA_context
255 {
256 void *orig_context;
257 PSP_FILE_CALLBACK_A orig_handler;
258 };
259
260 UINT CALLBACK QUEUE_callback_WtoA( void *context, UINT notification, UINT_PTR, UINT_PTR );
261
262 /* from msvcrt/sys/stat.h */
263 #define _S_IWRITE 0x0080
264 #define _S_IREAD 0x0100
265
266 extern HINSTANCE hInstance;
267 extern OSVERSIONINFOW OsVersionInfo;
268
269 /* devinst.c */
270
271 BOOL
272 CreateDeviceInfo(
273 IN struct DeviceInfoSet *list,
274 IN LPCWSTR InstancePath,
275 IN LPCGUID pClassGuid,
276 OUT struct DeviceInfo **pDeviceInfo);
277
278 /* driver.c */
279
280 struct InfFileDetails *
281 CreateInfFileDetails(
282 IN LPCWSTR FullInfFileName);
283
284 VOID
285 DereferenceInfFile(struct InfFileDetails* infFile);
286
287 BOOL
288 DestroyDriverInfoElement(struct DriverInfoElement* driverInfo);
289
290 /* install.c */
291
292 BOOL
293 GetStringField( PINFCONTEXT context, DWORD index, PWSTR *value);
294
295 /* interface.c */
296
297 BOOL
298 DestroyDeviceInterface(
299 struct DeviceInterface* deviceInterface);
300
301 LONG
302 SETUP_CreateInterfaceList(
303 struct DeviceInfoSet *list,
304 PCWSTR MachineName,
305 CONST GUID *InterfaceGuid,
306 PCWSTR DeviceInstanceW /* OPTIONAL */,
307 BOOL OnlyPresentInterfaces);
308
309 /* misc.c */
310
311 DWORD
312 GetFunctionPointer(
313 IN PWSTR InstallerName,
314 OUT HMODULE* ModulePointer,
315 OUT PVOID* FunctionPointer);
316
317 DWORD
318 FreeFunctionPointer(
319 IN HMODULE ModulePointer,
320 IN PVOID FunctionPointer);
321
322 DWORD WINAPI CaptureAndConvertAnsiArg(LPCSTR pSrc, LPWSTR *pDst);
323
324 VOID WINAPI MyFree(LPVOID lpMem);
325 LPVOID WINAPI MyMalloc(DWORD dwSize);
326 LPVOID WINAPI MyRealloc(LPVOID lpSrc, DWORD dwSize);
327 LPWSTR WINAPI DuplicateString(LPCWSTR lpSrc);
328 BOOL WINAPI IsUserAdmin(VOID);
329 LPWSTR WINAPI MultiByteToUnicode(LPCSTR lpMultiByteStr, UINT uCodePage);
330 LPSTR WINAPI UnicodeToMultiByte(LPCWSTR lpUnicodeStr, UINT uCodePage);
331
332 /* parser.c */
333
334 typedef BOOL (*FIND_CALLBACK)(LPCWSTR SectionName, PVOID Context);
335 BOOL EnumerateSectionsStartingWith(HINF hInf, LPCWSTR pStr, FIND_CALLBACK Callback, PVOID Context);
336
337 #endif /* __SETUPAPI_PRIVATE_H */