[SETUPAPI]
[reactos.git] / reactos / dll / win32 / setupapi / devclass.c
1 /*
2 * SetupAPI device class-related functions
3 *
4 * Copyright 2000 Andreas Mohr for CodeWeavers
5 * 2005-2006 Hervé Poussineau (hpoussin@reactos.org)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "setupapi_private.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
25
26 /* Unicode constants */
27 static const WCHAR BackSlash[] = {'\\',0};
28 static const WCHAR Class[] = {'C','l','a','s','s',0};
29 static const WCHAR ClassGUID[] = {'C','l','a','s','s','G','U','I','D',0};
30 static const WCHAR ClassInstall32[] = {'C','l','a','s','s','I','n','s','t','a','l','l','3','2',0};
31 static const WCHAR DotServices[] = {'.','S','e','r','v','i','c','e','s',0};
32 static const WCHAR InterfaceInstall32[] = {'I','n','t','e','r','f','a','c','e','I','n','s','t','a','l','l','3','2',0};
33 static const WCHAR SetupapiDll[] = {'s','e','t','u','p','a','p','i','.','d','l','l',0};
34 static const WCHAR Version[] = {'V','e','r','s','i','o','n',0};
35
36 typedef BOOL
37 (WINAPI* PROPERTY_PAGE_PROVIDER) (
38 IN PSP_PROPSHEETPAGE_REQUEST PropPageRequest,
39 IN LPFNADDPROPSHEETPAGE fAddFunc,
40 IN LPARAM lParam);
41 typedef BOOL
42 (*UPDATE_CLASS_PARAM_HANDLER) (
43 IN HDEVINFO DeviceInfoSet,
44 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
45 IN PSP_CLASSINSTALL_HEADER ClassInstallParams OPTIONAL,
46 IN DWORD ClassInstallParamsSize);
47
48 static BOOL
49 SETUP_PropertyChangeHandler(
50 IN HDEVINFO DeviceInfoSet,
51 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
52 IN PSP_CLASSINSTALL_HEADER ClassInstallParams OPTIONAL,
53 IN DWORD ClassInstallParamsSize);
54
55 static BOOL
56 SETUP_PropertyAddPropertyAdvancedHandler(
57 IN HDEVINFO DeviceInfoSet,
58 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
59 IN PSP_CLASSINSTALL_HEADER ClassInstallParams OPTIONAL,
60 IN DWORD ClassInstallParamsSize);
61
62 typedef struct _INSTALL_PARAMS_DATA
63 {
64 DI_FUNCTION Function;
65 UPDATE_CLASS_PARAM_HANDLER UpdateHandler;
66 ULONG ParamsSize;
67 LONG FieldOffset;
68 } INSTALL_PARAMS_DATA;
69
70 #define ADD_PARAM_HANDLER(Function, UpdateHandler, ParamsType, ParamsField) \
71 { Function, UpdateHandler, sizeof(ParamsType), FIELD_OFFSET(struct ClassInstallParams, ParamsField) },
72
73 static const INSTALL_PARAMS_DATA InstallParamsData[] = {
74 ADD_PARAM_HANDLER(DIF_PROPERTYCHANGE, SETUP_PropertyChangeHandler, SP_PROPCHANGE_PARAMS, PropChangeParams)
75 ADD_PARAM_HANDLER(DIF_ADDPROPERTYPAGE_ADVANCED, SETUP_PropertyAddPropertyAdvancedHandler, SP_ADDPROPERTYPAGE_DATA, AddPropertyPageData)
76 };
77 #undef ADD_PARAM_HANDLER
78
79
80 /***********************************************************************
81 * SetupDiDestroyClassImageList(SETUPAPI.@)
82 */
83 BOOL WINAPI
84 SetupDiDestroyClassImageList(
85 IN PSP_CLASSIMAGELIST_DATA ClassImageListData)
86 {
87 struct ClassImageList *list;
88 BOOL ret = FALSE;
89
90 TRACE("%p\n", ClassImageListData);
91
92 if (!ClassImageListData)
93 SetLastError(ERROR_INVALID_PARAMETER);
94 else if (ClassImageListData->cbSize != sizeof(SP_CLASSIMAGELIST_DATA))
95 SetLastError(ERROR_INVALID_USER_BUFFER);
96 else if ((list = (struct ClassImageList *)ClassImageListData->Reserved) == NULL)
97 SetLastError(ERROR_INVALID_USER_BUFFER);
98 else if (list->magic != SETUP_CLASS_IMAGE_LIST_MAGIC)
99 SetLastError(ERROR_INVALID_USER_BUFFER);
100 else
101 {
102 //DestroyIcon()
103 //ImageList_Destroy();
104 FIXME("Stub %p\n", ClassImageListData);
105 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
106 }
107
108 TRACE("Returning %d\n", ret);
109 return ret;
110 }
111
112 /***********************************************************************
113 * SETUP_CreateDevicesListFromEnumerator
114 *
115 * PARAMS
116 * list [IO] Device info set to fill with discovered devices.
117 * pClassGuid [I] If specified, only devices which belong to this class will be added.
118 * Enumerator [I] Location to search devices to add.
119 * hEnumeratorKey [I] Registry key corresponding to Enumerator key. Must have KEY_ENUMERATE_SUB_KEYS right.
120 *
121 * RETURNS
122 * Success: ERROR_SUCCESS.
123 * Failure: an error code.
124 */
125 static LONG
126 SETUP_CreateDevicesListFromEnumerator(
127 IN OUT struct DeviceInfoSet *list,
128 IN CONST GUID *pClassGuid OPTIONAL,
129 IN LPCWSTR Enumerator,
130 IN HKEY hEnumeratorKey) /* handle to Enumerator registry key */
131 {
132 HKEY hDeviceIdKey = NULL, hInstanceIdKey;
133 WCHAR KeyBuffer[MAX_PATH];
134 WCHAR InstancePath[MAX_PATH];
135 LPWSTR pEndOfInstancePath; /* Pointer into InstancePath buffer */
136 struct DeviceInfo *deviceInfo;
137 DWORD i = 0, j;
138 DWORD dwLength, dwRegType;
139 DWORD rc;
140
141 /* Enumerate device IDs (subkeys of hEnumeratorKey) */
142 while (TRUE)
143 {
144 dwLength = sizeof(KeyBuffer) / sizeof(KeyBuffer[0]);
145 rc = RegEnumKeyExW(hEnumeratorKey, i, KeyBuffer, &dwLength, NULL, NULL, NULL, NULL);
146 if (rc == ERROR_NO_MORE_ITEMS)
147 break;
148 if (rc != ERROR_SUCCESS)
149 goto cleanup;
150 i++;
151
152 /* Open device id sub key */
153 if (hDeviceIdKey != NULL)
154 RegCloseKey(hDeviceIdKey);
155 rc = RegOpenKeyExW(hEnumeratorKey, KeyBuffer, 0, KEY_ENUMERATE_SUB_KEYS, &hDeviceIdKey);
156 if (rc != ERROR_SUCCESS)
157 goto cleanup;
158 strcpyW(InstancePath, Enumerator);
159 strcatW(InstancePath, BackSlash);
160 strcatW(InstancePath, KeyBuffer);
161 strcatW(InstancePath, BackSlash);
162 pEndOfInstancePath = &InstancePath[strlenW(InstancePath)];
163
164 /* Enumerate instance IDs (subkeys of hDeviceIdKey) */
165 j = 0;
166 while (TRUE)
167 {
168 GUID KeyGuid;
169
170 dwLength = sizeof(KeyBuffer) / sizeof(KeyBuffer[0]);
171 rc = RegEnumKeyExW(hDeviceIdKey, j, KeyBuffer, &dwLength, NULL, NULL, NULL, NULL);
172 if (rc == ERROR_NO_MORE_ITEMS)
173 break;
174 if (rc != ERROR_SUCCESS)
175 goto cleanup;
176 j++;
177
178 /* Open instance id sub key */
179 rc = RegOpenKeyExW(hDeviceIdKey, KeyBuffer, 0, KEY_QUERY_VALUE, &hInstanceIdKey);
180 if (rc != ERROR_SUCCESS)
181 goto cleanup;
182 *pEndOfInstancePath = '\0';
183 strcatW(InstancePath, KeyBuffer);
184
185 /* Read ClassGUID value */
186 dwLength = sizeof(KeyBuffer) - sizeof(WCHAR);
187 rc = RegQueryValueExW(hInstanceIdKey, ClassGUID, NULL, &dwRegType, (LPBYTE)KeyBuffer, &dwLength);
188 RegCloseKey(hInstanceIdKey);
189 if (rc == ERROR_FILE_NOT_FOUND)
190 {
191 if (pClassGuid)
192 /* Skip this bad entry as we can't verify it */
193 continue;
194 /* Set a default GUID for this device */
195 memcpy(&KeyGuid, &GUID_NULL, sizeof(GUID));
196 }
197 else if (rc != ERROR_SUCCESS)
198 {
199 goto cleanup;
200 }
201 else if (dwRegType != REG_SZ || dwLength < MAX_GUID_STRING_LEN * sizeof(WCHAR))
202 {
203 rc = ERROR_GEN_FAILURE;
204 goto cleanup;
205 }
206 else
207 {
208 KeyBuffer[MAX_GUID_STRING_LEN - 2] = '\0'; /* Replace the } by a NULL character */
209 if (UuidFromStringW(&KeyBuffer[1], &KeyGuid) != RPC_S_OK)
210 /* Bad GUID, skip the entry */
211 continue;
212 }
213
214 if (pClassGuid && !IsEqualIID(&KeyGuid, pClassGuid))
215 {
216 /* Skip this entry as it is not the right device class */
217 continue;
218 }
219
220 /* Add the entry to the list */
221 if (!CreateDeviceInfo(list, InstancePath, &KeyGuid, &deviceInfo))
222 {
223 rc = GetLastError();
224 goto cleanup;
225 }
226 TRACE("Adding '%s' to device info set %p\n", debugstr_w(InstancePath), list);
227 InsertTailList(&list->ListHead, &deviceInfo->ListEntry);
228 }
229 }
230
231 rc = ERROR_SUCCESS;
232
233 cleanup:
234 if (hDeviceIdKey != NULL)
235 RegCloseKey(hDeviceIdKey);
236 return rc;
237 }
238
239 LONG
240 SETUP_CreateDevicesList(
241 IN OUT struct DeviceInfoSet *list,
242 IN PCWSTR MachineName OPTIONAL,
243 IN CONST GUID *Class OPTIONAL,
244 IN PCWSTR Enumerator OPTIONAL)
245 {
246 HKEY HKLM = HKEY_LOCAL_MACHINE;
247 HKEY hEnumKey = NULL;
248 HKEY hEnumeratorKey = NULL;
249 WCHAR KeyBuffer[MAX_PATH];
250 DWORD i;
251 DWORD dwLength;
252 DWORD rc;
253
254 if (Class && IsEqualIID(Class, &GUID_NULL))
255 Class = NULL;
256
257 /* Open Enum key (if applicable) */
258 if (MachineName != NULL)
259 {
260 rc = RegConnectRegistryW(MachineName, HKEY_LOCAL_MACHINE, &HKLM);
261 if (rc != ERROR_SUCCESS)
262 goto cleanup;
263 }
264
265 rc = RegOpenKeyExW(
266 HKLM,
267 REGSTR_PATH_SYSTEMENUM,
268 0,
269 KEY_ENUMERATE_SUB_KEYS,
270 &hEnumKey);
271 if (rc != ERROR_SUCCESS)
272 goto cleanup;
273
274 /* If enumerator is provided, call directly SETUP_CreateDevicesListFromEnumerator.
275 * Else, enumerate all enumerators and call SETUP_CreateDevicesListFromEnumerator
276 * for each one.
277 */
278 if (Enumerator)
279 {
280 rc = RegOpenKeyExW(
281 hEnumKey,
282 Enumerator,
283 0,
284 KEY_ENUMERATE_SUB_KEYS,
285 &hEnumeratorKey);
286 if (rc != ERROR_SUCCESS)
287 {
288 if (rc == ERROR_FILE_NOT_FOUND)
289 rc = ERROR_INVALID_DATA;
290 goto cleanup;
291 }
292 rc = SETUP_CreateDevicesListFromEnumerator(list, Class, Enumerator, hEnumeratorKey);
293 }
294 else
295 {
296 /* Enumerate enumerators */
297 i = 0;
298 while (TRUE)
299 {
300 dwLength = sizeof(KeyBuffer) / sizeof(KeyBuffer[0]);
301 rc = RegEnumKeyExW(hEnumKey, i, KeyBuffer, &dwLength, NULL, NULL, NULL, NULL);
302 if (rc == ERROR_NO_MORE_ITEMS)
303 break;
304 else if (rc != ERROR_SUCCESS)
305 goto cleanup;
306 i++;
307
308 /* Open sub key */
309 if (hEnumeratorKey != NULL)
310 RegCloseKey(hEnumeratorKey);
311 rc = RegOpenKeyExW(hEnumKey, KeyBuffer, 0, KEY_ENUMERATE_SUB_KEYS, &hEnumeratorKey);
312 if (rc != ERROR_SUCCESS)
313 goto cleanup;
314
315 /* Call SETUP_CreateDevicesListFromEnumerator */
316 rc = SETUP_CreateDevicesListFromEnumerator(list, Class, KeyBuffer, hEnumeratorKey);
317 if (rc != ERROR_SUCCESS)
318 goto cleanup;
319 }
320 rc = ERROR_SUCCESS;
321 }
322
323 cleanup:
324 if (HKLM != HKEY_LOCAL_MACHINE)
325 RegCloseKey(HKLM);
326 if (hEnumKey != NULL)
327 RegCloseKey(hEnumKey);
328 if (hEnumeratorKey != NULL)
329 RegCloseKey(hEnumeratorKey);
330 return rc;
331 }
332
333 /***********************************************************************
334 * SetupDiGetClassImageIndex (SETUPAPI.@)
335 */
336 static BOOL
337 SETUP_GetIconIndex(
338 IN HKEY hClassKey,
339 OUT PINT ImageIndex)
340 {
341 LPWSTR Buffer = NULL;
342 DWORD dwRegType, dwLength;
343 LONG rc;
344 BOOL ret = FALSE;
345
346 /* Read icon registry key */
347 rc = RegQueryValueExW(hClassKey, REGSTR_VAL_INSICON, NULL, &dwRegType, NULL, &dwLength);
348 if (rc != ERROR_SUCCESS)
349 {
350 SetLastError(rc);
351 goto cleanup;
352 } else if (dwRegType != REG_SZ)
353 {
354 SetLastError(ERROR_INVALID_INDEX);
355 goto cleanup;
356 }
357 Buffer = MyMalloc(dwLength + sizeof(WCHAR));
358 if (!Buffer)
359 {
360 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
361 goto cleanup;
362 }
363 rc = RegQueryValueExW(hClassKey, REGSTR_VAL_INSICON, NULL, NULL, (LPBYTE)Buffer, &dwLength);
364 if (rc != ERROR_SUCCESS)
365 {
366 SetLastError(rc);
367 goto cleanup;
368 }
369 /* make sure the returned buffer is NULL-terminated */
370 Buffer[dwLength / sizeof(WCHAR)] = 0;
371
372 /* Transform icon value to a INT */
373 *ImageIndex = atoiW(Buffer);
374 ret = TRUE;
375
376 cleanup:
377 MyFree(Buffer);
378 return ret;
379 }
380
381 BOOL WINAPI
382 SetupDiGetClassImageIndex(
383 IN PSP_CLASSIMAGELIST_DATA ClassImageListData,
384 IN CONST GUID *ClassGuid,
385 OUT PINT ImageIndex)
386 {
387 struct ClassImageList *list;
388 BOOL ret = FALSE;
389
390 TRACE("%p %s %p\n", ClassImageListData, debugstr_guid(ClassGuid), ImageIndex);
391
392 if (!ClassImageListData || !ClassGuid || !ImageIndex)
393 SetLastError(ERROR_INVALID_PARAMETER);
394 else if (ClassImageListData->cbSize != sizeof(SP_CLASSIMAGELIST_DATA))
395 SetLastError(ERROR_INVALID_USER_BUFFER);
396 else if ((list = (struct ClassImageList *)ClassImageListData->Reserved) == NULL)
397 SetLastError(ERROR_INVALID_USER_BUFFER);
398 else if (list->magic != SETUP_CLASS_IMAGE_LIST_MAGIC)
399 SetLastError(ERROR_INVALID_USER_BUFFER);
400 else if (!ImageIndex)
401 SetLastError(ERROR_INVALID_PARAMETER);
402 else
403 {
404 DWORD i;
405
406 for (i = 0; i < list->NumberOfGuids; i++)
407 {
408 if (IsEqualIID(ClassGuid, &list->Guids[i]))
409 break;
410 }
411
412 if (i == list->NumberOfGuids || list->IconIndexes[i] < 0)
413 SetLastError(ERROR_FILE_NOT_FOUND);
414 else
415 {
416 *ImageIndex = list->IconIndexes[i];
417 ret = TRUE;
418 }
419 }
420
421 TRACE("Returning %d\n", ret);
422 return ret;
423 }
424
425 /***********************************************************************
426 * SetupDiGetClassImageList(SETUPAPI.@)
427 */
428 BOOL WINAPI
429 SetupDiGetClassImageList(
430 OUT PSP_CLASSIMAGELIST_DATA ClassImageListData)
431 {
432 return SetupDiGetClassImageListExW(ClassImageListData, NULL, NULL);
433 }
434
435 /***********************************************************************
436 * SetupDiGetClassImageListExA(SETUPAPI.@)
437 */
438 BOOL WINAPI
439 SetupDiGetClassImageListExA(
440 OUT PSP_CLASSIMAGELIST_DATA ClassImageListData,
441 IN PCSTR MachineName OPTIONAL,
442 IN PVOID Reserved)
443 {
444 PWSTR MachineNameW = NULL;
445 BOOL ret;
446
447 if (MachineName)
448 {
449 MachineNameW = pSetupMultiByteToUnicode(MachineName, CP_ACP);
450 if (MachineNameW == NULL)
451 return FALSE;
452 }
453
454 ret = SetupDiGetClassImageListExW(ClassImageListData, MachineNameW, Reserved);
455
456 MyFree(MachineNameW);
457
458 return ret;
459 }
460
461 /***********************************************************************
462 * SetupDiGetClassImageListExW(SETUPAPI.@)
463 */
464 BOOL WINAPI
465 SetupDiGetClassImageListExW(
466 OUT PSP_CLASSIMAGELIST_DATA ClassImageListData,
467 IN PCWSTR MachineName OPTIONAL,
468 IN PVOID Reserved)
469 {
470 BOOL ret = FALSE;
471
472 TRACE("%p %p %p\n", ClassImageListData, debugstr_w(MachineName), Reserved);
473
474 if (!ClassImageListData)
475 SetLastError(ERROR_INVALID_PARAMETER);
476 else if (ClassImageListData->cbSize != sizeof(SP_CLASSIMAGELIST_DATA))
477 SetLastError(ERROR_INVALID_USER_BUFFER);
478 else if (Reserved)
479 SetLastError(ERROR_INVALID_PARAMETER);
480 else
481 {
482 struct ClassImageList *list = NULL;
483 HDC hDC;
484 DWORD RequiredSize;
485 DWORD ilMask, bkColor;
486 HICON hIcon;
487 DWORD size;
488 INT i, bpp;
489
490 /* Get list of all class GUIDs in given computer */
491 ret = SetupDiBuildClassInfoListExW(
492 0,
493 NULL,
494 0,
495 &RequiredSize,
496 MachineName,
497 NULL);
498 if (!ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
499 goto cleanup;
500
501 size = sizeof(struct ClassImageList)
502 + (sizeof(GUID) + sizeof(INT)) * RequiredSize;
503 list = HeapAlloc(GetProcessHeap(), 0, size);
504 if (!list)
505 {
506 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
507 goto cleanup;
508 }
509 list->magic = SETUP_CLASS_IMAGE_LIST_MAGIC;
510 list->NumberOfGuids = RequiredSize;
511 list->Guids = (GUID*)(list + 1);
512 list->IconIndexes = (INT*)((ULONG_PTR)(list + 1) + sizeof(GUID) * RequiredSize);
513
514 ret = SetupDiBuildClassInfoListExW(
515 0,
516 list->Guids,
517 list->NumberOfGuids,
518 &RequiredSize,
519 MachineName,
520 NULL);
521 if (!ret)
522 goto cleanup;
523 else if (RequiredSize != list->NumberOfGuids)
524 {
525 /* Hm. Class list changed since last call. Ignore
526 * this case as it should be very rare */
527 SetLastError(ERROR_GEN_FAILURE);
528 ret = FALSE;
529 goto cleanup;
530 }
531
532 /* Prepare a HIMAGELIST */
533 InitCommonControls();
534
535 hDC = GetDC(NULL);
536 if (!hDC)
537 goto cleanup;
538
539 bpp = GetDeviceCaps(hDC, BITSPIXEL);
540 ReleaseDC(NULL, hDC);
541
542 if (bpp <= 4)
543 ilMask = ILC_COLOR4;
544 else if (bpp <= 8)
545 ilMask = ILC_COLOR8;
546 else if (bpp <= 16)
547 ilMask = ILC_COLOR16;
548 else if (bpp <= 24)
549 ilMask = ILC_COLOR24;
550 else if (bpp <= 32)
551 ilMask = ILC_COLOR32;
552 else
553 ilMask = ILC_COLOR;
554
555 ilMask |= ILC_MASK;
556
557 ClassImageListData->ImageList = ImageList_Create(16, 16, ilMask, 100, 10);
558 if (!ClassImageListData->ImageList)
559 goto cleanup;
560
561 ClassImageListData->Reserved = (ULONG_PTR)list;
562
563 /* For some reason, Windows sets the list background to COLOR_WINDOW */
564 bkColor = GetSysColor(COLOR_WINDOW);
565 ImageList_SetBkColor(ClassImageListData->ImageList, bkColor);
566
567 /* Now, we "simply" need to load icons associated with all class guids,
568 * and put their index in the image list in the IconIndexes array */
569 for (i = 0; i < list->NumberOfGuids; i++)
570 {
571 INT miniIconIndex;
572
573 ret = SetupDiLoadClassIcon(
574 &list->Guids[i],
575 NULL,
576 &miniIconIndex);
577 if (ret)
578 {
579 hIcon = LoadImage(hInstance, MAKEINTRESOURCE(miniIconIndex), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
580 if (hIcon)
581 {
582 list->IconIndexes[i] = ImageList_AddIcon(ClassImageListData->ImageList, hIcon);
583 DestroyIcon(hIcon);
584 }
585 else
586 list->IconIndexes[i] = -1;
587 }
588 else
589 list->IconIndexes[i] = -1; /* Special value to indicate that the icon is unavailable */
590 }
591
592 ret = TRUE;
593
594 cleanup:
595 if (!ret)
596 {
597 if (ClassImageListData->Reserved)
598 SetupDiDestroyClassImageList(ClassImageListData);
599 else if (list)
600 MyFree(list);
601 }
602 }
603
604 TRACE("Returning %d\n", ret);
605 return ret;
606 }
607
608 /***********************************************************************
609 * SetupDiGetClassInstallParamsA(SETUPAPI.@)
610 */
611 BOOL WINAPI
612 SetupDiGetClassInstallParamsA(
613 IN HDEVINFO DeviceInfoSet,
614 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
615 OUT PSP_CLASSINSTALL_HEADER ClassInstallParams OPTIONAL,
616 IN DWORD ClassInstallParamsSize,
617 OUT PDWORD RequiredSize OPTIONAL)
618 {
619 FIXME("SetupDiGetClassInstallParamsA(%p %p %p %lu %p) Stub\n",
620 DeviceInfoSet, DeviceInfoData, ClassInstallParams, ClassInstallParamsSize, RequiredSize);
621 return FALSE;
622 }
623
624 /***********************************************************************
625 * SetupDiGetClassInstallParamsW(SETUPAPI.@)
626 */
627 BOOL WINAPI
628 SetupDiGetClassInstallParamsW(
629 IN HDEVINFO DeviceInfoSet,
630 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
631 OUT PSP_CLASSINSTALL_HEADER ClassInstallParams OPTIONAL,
632 IN DWORD ClassInstallParamsSize,
633 OUT PDWORD RequiredSize OPTIONAL)
634 {
635 FIXME("SetupDiGetClassInstallParamsW(%p %p %p %lu %p) Stub\n",
636 DeviceInfoSet, DeviceInfoData, ClassInstallParams, ClassInstallParamsSize, RequiredSize);
637 return FALSE;
638 }
639
640 /***********************************************************************
641 * SetupDiLoadClassIcon(SETUPAPI.@)
642 */
643 BOOL WINAPI
644 SetupDiLoadClassIcon(
645 IN CONST GUID *ClassGuid,
646 OUT HICON *LargeIcon OPTIONAL,
647 OUT PINT MiniIconIndex OPTIONAL)
648 {
649 BOOL ret = FALSE;
650
651 if (!ClassGuid)
652 SetLastError(ERROR_INVALID_PARAMETER);
653 else
654 {
655 LPWSTR Buffer = NULL;
656 LPCWSTR DllName;
657 INT iconIndex = 0;
658 HKEY hKey = INVALID_HANDLE_VALUE;
659
660 hKey = SetupDiOpenClassRegKey(ClassGuid, KEY_QUERY_VALUE);
661 if (hKey == INVALID_HANDLE_VALUE)
662 goto cleanup;
663
664 if (!SETUP_GetIconIndex(hKey, &iconIndex))
665 goto cleanup;
666
667 if (iconIndex > 0)
668 {
669 /* Look up icon in dll specified by Installer32 or EnumPropPages32 key */
670 PWCHAR Comma;
671 LONG rc;
672 DWORD dwRegType, dwLength;
673 rc = RegQueryValueExW(hKey, REGSTR_VAL_INSTALLER_32, NULL, &dwRegType, NULL, &dwLength);
674 if (rc == ERROR_SUCCESS && dwRegType == REG_SZ)
675 {
676 Buffer = MyMalloc(dwLength + sizeof(WCHAR));
677 if (Buffer == NULL)
678 {
679 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
680 goto cleanup;
681 }
682 rc = RegQueryValueExW(hKey, REGSTR_VAL_INSTALLER_32, NULL, NULL, (LPBYTE)Buffer, &dwLength);
683 if (rc != ERROR_SUCCESS)
684 {
685 SetLastError(rc);
686 goto cleanup;
687 }
688 /* make sure the returned buffer is NULL-terminated */
689 Buffer[dwLength / sizeof(WCHAR)] = 0;
690 }
691 else if
692 (ERROR_SUCCESS == (rc = RegQueryValueExW(hKey, REGSTR_VAL_ENUMPROPPAGES_32, NULL, &dwRegType, NULL, &dwLength))
693 && dwRegType == REG_SZ)
694 {
695 Buffer = MyMalloc(dwLength + sizeof(WCHAR));
696 if (Buffer == NULL)
697 {
698 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
699 goto cleanup;
700 }
701 rc = RegQueryValueExW(hKey, REGSTR_VAL_ENUMPROPPAGES_32, NULL, NULL, (LPBYTE)Buffer, &dwLength);
702 if (rc != ERROR_SUCCESS)
703 {
704 SetLastError(rc);
705 goto cleanup;
706 }
707 /* make sure the returned buffer is NULL-terminated */
708 Buffer[dwLength / sizeof(WCHAR)] = 0;
709 }
710 else
711 {
712 /* Unable to find where to load the icon */
713 SetLastError(ERROR_FILE_NOT_FOUND);
714 goto cleanup;
715 }
716 Comma = strchrW(Buffer, ',');
717 if (!Comma)
718 {
719 SetLastError(ERROR_GEN_FAILURE);
720 goto cleanup;
721 }
722 *Comma = '\0';
723 DllName = Buffer;
724 }
725 else
726 {
727 /* Look up icon in setupapi.dll */
728 DllName = SetupapiDll;
729 iconIndex = -iconIndex;
730 }
731
732 TRACE("Icon index %d, dll name %s\n", iconIndex, debugstr_w(DllName));
733 if (LargeIcon)
734 {
735 *LargeIcon = LoadImage(hInstance, MAKEINTRESOURCE(iconIndex), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
736 if (!*LargeIcon)
737 {
738 SetLastError(ERROR_INVALID_INDEX);
739 goto cleanup;
740 }
741 }
742 if (MiniIconIndex)
743 *MiniIconIndex = iconIndex;
744 ret = TRUE;
745
746 cleanup:
747 if (hKey != INVALID_HANDLE_VALUE)
748 RegCloseKey(hKey);
749 MyFree(Buffer);
750 }
751
752 TRACE("Returning %d\n", ret);
753 return ret;
754 }
755
756 /***********************************************************************
757 * SetupDiInstallClassExW (SETUPAPI.@)
758 */
759 HKEY
760 SETUP_CreateClassKey(HINF hInf);
761 BOOL WINAPI
762 SetupDiInstallClassExW(
763 IN HWND hwndParent OPTIONAL,
764 IN PCWSTR InfFileName OPTIONAL,
765 IN DWORD Flags,
766 IN HSPFILEQ FileQueue OPTIONAL,
767 IN CONST GUID *InterfaceClassGuid OPTIONAL,
768 IN PVOID Reserved1,
769 IN PVOID Reserved2)
770 {
771 BOOL ret = FALSE;
772
773 TRACE("%p %s 0x%lx %p %s %p %p\n", hwndParent, debugstr_w(InfFileName), Flags,
774 FileQueue, debugstr_guid(InterfaceClassGuid), Reserved1, Reserved2);
775
776 if (!InfFileName)
777 {
778 FIXME("Case not implemented: InfFileName NULL\n");
779 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
780 }
781 else if (Flags & ~(DI_NOVCP | DI_NOBROWSE | DI_FORCECOPY | DI_QUIETINSTALL))
782 {
783 TRACE("Unknown flags: 0x%08lx\n", Flags & ~(DI_NOVCP | DI_NOBROWSE | DI_FORCECOPY | DI_QUIETINSTALL));
784 SetLastError(ERROR_INVALID_FLAGS);
785 }
786 else if ((Flags & DI_NOVCP) && FileQueue == NULL)
787 SetLastError(ERROR_INVALID_PARAMETER);
788 else if (Reserved1 != NULL)
789 SetLastError(ERROR_INVALID_PARAMETER);
790 else if (Reserved2 != NULL)
791 SetLastError(ERROR_INVALID_PARAMETER);
792 else
793 {
794 HDEVINFO hDeviceInfo = INVALID_HANDLE_VALUE;
795 SP_DEVINSTALL_PARAMS_W InstallParams;
796 WCHAR SectionName[MAX_PATH];
797 HINF hInf = INVALID_HANDLE_VALUE;
798 HKEY hRootKey = INVALID_HANDLE_VALUE;
799 PVOID callback_context = NULL;
800
801 hDeviceInfo = SetupDiCreateDeviceInfoList(NULL, NULL);
802 if (hDeviceInfo == INVALID_HANDLE_VALUE)
803 goto cleanup;
804
805 InstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
806 if (!SetupDiGetDeviceInstallParamsW(hDeviceInfo, NULL, &InstallParams))
807 goto cleanup;
808 InstallParams.Flags &= ~(DI_NOVCP | DI_NOBROWSE | DI_QUIETINSTALL);
809 InstallParams.Flags |= Flags & (DI_NOVCP | DI_NOBROWSE | DI_QUIETINSTALL);
810 if (Flags & DI_NOVCP)
811 InstallParams.FileQueue = FileQueue;
812 if (!SetupDiSetDeviceInstallParamsW(hDeviceInfo, NULL, &InstallParams))
813 goto cleanup;
814
815 /* Open the .inf file */
816 hInf = SetupOpenInfFileW(
817 InfFileName,
818 NULL,
819 INF_STYLE_WIN4,
820 NULL);
821 if (hInf == INVALID_HANDLE_VALUE)
822 goto cleanup;
823
824 /* Try to append a layout file */
825 SetupOpenAppendInfFileW(NULL, hInf, NULL);
826
827 if (InterfaceClassGuid)
828 {
829 /* Retrieve the actual section name */
830 ret = SetupDiGetActualSectionToInstallW(
831 hInf,
832 InterfaceInstall32,
833 SectionName,
834 MAX_PATH,
835 NULL,
836 NULL);
837 if (!ret)
838 goto cleanup;
839
840 /* Open registry key related to this interface */
841 /* FIXME: What happens if the key doesn't exist? */
842 hRootKey = SetupDiOpenClassRegKeyExW(InterfaceClassGuid, KEY_ENUMERATE_SUB_KEYS, DIOCR_INTERFACE, NULL, NULL);
843 if (hRootKey == INVALID_HANDLE_VALUE)
844 goto cleanup;
845
846 /* SetupDiCreateDeviceInterface??? */
847 FIXME("Installing an interface is not implemented\n");
848 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
849 }
850 else
851 {
852 /* Create or open the class registry key 'HKLM\CurrentControlSet\Class\{GUID}' */
853 hRootKey = SETUP_CreateClassKey(hInf);
854 if (hRootKey == INVALID_HANDLE_VALUE)
855 goto cleanup;
856
857 /* Retrieve the actual section name */
858 ret = SetupDiGetActualSectionToInstallW(
859 hInf,
860 ClassInstall32,
861 SectionName,
862 MAX_PATH - strlenW(DotServices),
863 NULL,
864 NULL);
865 if (!ret)
866 goto cleanup;
867
868 callback_context = SetupInitDefaultQueueCallback(hwndParent);
869 if (!callback_context)
870 goto cleanup;
871
872 ret = SetupInstallFromInfSectionW(
873 hwndParent,
874 hInf,
875 SectionName,
876 SPINST_REGISTRY | SPINST_FILES | SPINST_BITREG | SPINST_INIFILES | SPINST_INI2REG,
877 hRootKey,
878 NULL, /* FIXME: SourceRootPath */
879 !(Flags & DI_NOVCP) && (Flags & DI_FORCECOPY) ? SP_COPY_FORCE_IN_USE : 0, /* CopyFlags */
880 SetupDefaultQueueCallbackW,
881 callback_context,
882 hDeviceInfo,
883 NULL);
884 if (!ret)
885 goto cleanup;
886
887 /* Install .Services section */
888 lstrcatW(SectionName, DotServices);
889 ret = SetupInstallServicesFromInfSectionExW(
890 hInf,
891 SectionName,
892 0,
893 hDeviceInfo,
894 NULL,
895 NULL,
896 NULL);
897 if (!ret)
898 goto cleanup;
899
900 ret = TRUE;
901 }
902
903 cleanup:
904 if (hDeviceInfo != INVALID_HANDLE_VALUE)
905 SetupDiDestroyDeviceInfoList(hDeviceInfo);
906 if (hInf != INVALID_HANDLE_VALUE)
907 SetupCloseInfFile(hInf);
908 if (hRootKey != INVALID_HANDLE_VALUE)
909 RegCloseKey(hRootKey);
910 SetupTermDefaultQueueCallback(callback_context);
911 }
912
913 TRACE("Returning %d\n", ret);
914 return ret;
915 }
916
917 /***********************************************************************
918 * Helper functions for SetupDiSetClassInstallParamsW
919 */
920 static BOOL
921 SETUP_PropertyChangeHandler(
922 IN HDEVINFO DeviceInfoSet,
923 IN PSP_DEVINFO_DATA DeviceInfoData,
924 IN PSP_CLASSINSTALL_HEADER ClassInstallParams OPTIONAL,
925 IN DWORD ClassInstallParamsSize)
926 {
927 PSP_PROPCHANGE_PARAMS PropChangeParams = (PSP_PROPCHANGE_PARAMS)ClassInstallParams;
928 BOOL ret = FALSE;
929
930 if (!DeviceInfoData)
931 SetLastError(ERROR_INVALID_PARAMETER);
932 else if (ClassInstallParamsSize != sizeof(SP_PROPCHANGE_PARAMS))
933 SetLastError(ERROR_INVALID_PARAMETER);
934 else if (PropChangeParams && PropChangeParams->StateChange != DICS_ENABLE
935 && PropChangeParams->StateChange != DICS_DISABLE && PropChangeParams->StateChange != DICS_PROPCHANGE
936 && PropChangeParams->StateChange != DICS_START && PropChangeParams->StateChange != DICS_STOP)
937 SetLastError(ERROR_INVALID_FLAGS);
938 else if (PropChangeParams && PropChangeParams->Scope != DICS_FLAG_GLOBAL
939 && PropChangeParams->Scope != DICS_FLAG_CONFIGSPECIFIC)
940 SetLastError(ERROR_INVALID_FLAGS);
941 else if (PropChangeParams
942 && (PropChangeParams->StateChange == DICS_START || PropChangeParams->StateChange == DICS_STOP)
943 && PropChangeParams->Scope != DICS_FLAG_CONFIGSPECIFIC)
944 SetLastError(ERROR_INVALID_USER_BUFFER);
945 else
946 {
947 PSP_PROPCHANGE_PARAMS *CurrentPropChangeParams;
948 struct DeviceInfo *deviceInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
949 CurrentPropChangeParams = &deviceInfo->ClassInstallParams.PropChangeParams;
950
951 if (*CurrentPropChangeParams)
952 {
953 MyFree(*CurrentPropChangeParams);
954 *CurrentPropChangeParams = NULL;
955 }
956 if (PropChangeParams)
957 {
958 *CurrentPropChangeParams = MyMalloc(ClassInstallParamsSize);
959 if (!*CurrentPropChangeParams)
960 {
961 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
962 goto done;
963 }
964 memcpy(*CurrentPropChangeParams, PropChangeParams, ClassInstallParamsSize);
965 }
966 ret = TRUE;
967 }
968
969 done:
970 return ret;
971 }
972
973 static BOOL
974 SETUP_PropertyAddPropertyAdvancedHandler(
975 IN HDEVINFO DeviceInfoSet,
976 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
977 IN PSP_CLASSINSTALL_HEADER ClassInstallParams OPTIONAL,
978 IN DWORD ClassInstallParamsSize)
979 {
980 PSP_ADDPROPERTYPAGE_DATA AddPropertyPageData = (PSP_ADDPROPERTYPAGE_DATA)ClassInstallParams;
981 BOOL ret = FALSE;
982
983 if (ClassInstallParamsSize != sizeof(SP_PROPCHANGE_PARAMS))
984 SetLastError(ERROR_INVALID_PARAMETER);
985 else if (AddPropertyPageData && AddPropertyPageData->Flags != 0)
986 SetLastError(ERROR_INVALID_FLAGS);
987 else if (AddPropertyPageData && AddPropertyPageData->NumDynamicPages >= MAX_INSTALLWIZARD_DYNAPAGES)
988 SetLastError(ERROR_INVALID_USER_BUFFER);
989 else
990 {
991 PSP_ADDPROPERTYPAGE_DATA *CurrentAddPropertyPageData;
992 if (!DeviceInfoData)
993 {
994 struct DeviceInfoSet *list = (struct DeviceInfoSet *)DeviceInfoSet;
995 CurrentAddPropertyPageData = &list->ClassInstallParams.AddPropertyPageData;
996 }
997 else
998 {
999 struct DeviceInfo *deviceInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1000 CurrentAddPropertyPageData = &deviceInfo->ClassInstallParams.AddPropertyPageData;
1001 }
1002 if (*CurrentAddPropertyPageData)
1003 {
1004 MyFree(*CurrentAddPropertyPageData);
1005 *CurrentAddPropertyPageData = NULL;
1006 }
1007 if (AddPropertyPageData)
1008 {
1009 *CurrentAddPropertyPageData = MyMalloc(ClassInstallParamsSize);
1010 if (!*CurrentAddPropertyPageData)
1011 {
1012 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1013 goto done;
1014 }
1015 memcpy(*CurrentAddPropertyPageData, AddPropertyPageData, ClassInstallParamsSize);
1016 }
1017 ret = TRUE;
1018 }
1019
1020 done:
1021 return ret;
1022 }
1023
1024 /***********************************************************************
1025 * SetupDiSetClassInstallParamsW (SETUPAPI.@)
1026 */
1027 BOOL WINAPI
1028 SetupDiSetClassInstallParamsW(
1029 IN HDEVINFO DeviceInfoSet,
1030 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
1031 IN PSP_CLASSINSTALL_HEADER ClassInstallParams OPTIONAL,
1032 IN DWORD ClassInstallParamsSize)
1033 {
1034 struct DeviceInfoSet *list;
1035 BOOL ret = FALSE;
1036
1037 TRACE("%p %p %p %lu\n", DeviceInfoSet, DeviceInfoData,
1038 ClassInstallParams, ClassInstallParamsSize);
1039
1040 if (!DeviceInfoSet)
1041 SetLastError(ERROR_INVALID_PARAMETER);
1042 else if (DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE)
1043 SetLastError(ERROR_INVALID_HANDLE);
1044 else if ((list = (struct DeviceInfoSet *)DeviceInfoSet)->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1045 SetLastError(ERROR_INVALID_HANDLE);
1046 else if (DeviceInfoData && DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA))
1047 SetLastError(ERROR_INVALID_USER_BUFFER);
1048 else if (ClassInstallParams && ClassInstallParams->cbSize != sizeof(SP_CLASSINSTALL_HEADER))
1049 SetLastError(ERROR_INVALID_USER_BUFFER);
1050 else if (ClassInstallParams && ClassInstallParamsSize < sizeof(SP_CLASSINSTALL_HEADER))
1051 SetLastError(ERROR_INVALID_PARAMETER);
1052 else if (!ClassInstallParams && ClassInstallParamsSize != 0)
1053 SetLastError(ERROR_INVALID_PARAMETER);
1054 else
1055 {
1056 SP_DEVINSTALL_PARAMS_W InstallParams;
1057 BOOL Result;
1058
1059 InstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS_W);
1060 Result = SetupDiGetDeviceInstallParamsW(DeviceInfoSet, DeviceInfoData, &InstallParams);
1061 if (!Result)
1062 goto done;
1063
1064 if (ClassInstallParams)
1065 {
1066 DWORD i;
1067 /* Check parameters in ClassInstallParams */
1068 for (i = 0; i < sizeof(InstallParamsData) / sizeof(InstallParamsData[0]); i++)
1069 {
1070 if (InstallParamsData[i].Function == ClassInstallParams->InstallFunction)
1071 {
1072 ret = InstallParamsData[i].UpdateHandler(
1073 DeviceInfoSet,
1074 DeviceInfoData,
1075 ClassInstallParams,
1076 ClassInstallParamsSize);
1077 if (ret)
1078 {
1079 InstallParams.Flags |= DI_CLASSINSTALLPARAMS;
1080 ret = SetupDiSetDeviceInstallParamsW(DeviceInfoSet, DeviceInfoData, &InstallParams);
1081 }
1082 goto done;
1083 }
1084 }
1085 ERR("InstallFunction %u has no associated update handler\n", ClassInstallParams->InstallFunction);
1086 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1087 goto done;
1088 }
1089 else
1090 {
1091 InstallParams.Flags &= ~DI_CLASSINSTALLPARAMS;
1092 ret = SetupDiSetDeviceInstallParamsW(DeviceInfoSet, DeviceInfoData, &InstallParams);
1093 }
1094 }
1095
1096 done:
1097 TRACE("Returning %d\n", ret);
1098 return ret;
1099 }
1100
1101 /***********************************************************************
1102 * SetupDiGetClassDevPropertySheetsA(SETUPAPI.@)
1103 */
1104 BOOL WINAPI
1105 SetupDiGetClassDevPropertySheetsA(
1106 IN HDEVINFO DeviceInfoSet,
1107 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
1108 IN LPPROPSHEETHEADERA PropertySheetHeader,
1109 IN DWORD PropertySheetHeaderPageListSize,
1110 OUT PDWORD RequiredSize OPTIONAL,
1111 IN DWORD PropertySheetType)
1112 {
1113 PROPSHEETHEADERW psh;
1114 BOOL ret = FALSE;
1115
1116 TRACE("%p %p %p 0%lx %p 0x%lx\n", DeviceInfoSet, DeviceInfoData,
1117 PropertySheetHeader, PropertySheetHeaderPageListSize,
1118 RequiredSize, PropertySheetType);
1119
1120 psh.dwFlags = PropertySheetHeader->dwFlags;
1121 psh.phpage = PropertySheetHeader->phpage;
1122 psh.nPages = PropertySheetHeader->nPages;
1123
1124 ret = SetupDiGetClassDevPropertySheetsW(DeviceInfoSet, DeviceInfoData, PropertySheetHeader ? &psh : NULL,
1125 PropertySheetHeaderPageListSize, RequiredSize,
1126 PropertySheetType);
1127 if (ret)
1128 {
1129 PropertySheetHeader->nPages = psh.nPages;
1130 }
1131
1132 TRACE("Returning %d\n", ret);
1133 return ret;
1134 }
1135
1136 struct ClassDevPropertySheetsData
1137 {
1138 HPROPSHEETPAGE *PropertySheetPages;
1139 DWORD MaximumNumberOfPages;
1140 DWORD NumberOfPages;
1141 };
1142
1143 static BOOL WINAPI
1144 SETUP_GetClassDevPropertySheetsCallback(
1145 IN HPROPSHEETPAGE hPropSheetPage,
1146 IN OUT LPARAM lParam)
1147 {
1148 struct ClassDevPropertySheetsData *PropPageData;
1149
1150 PropPageData = (struct ClassDevPropertySheetsData *)lParam;
1151
1152 if (PropPageData->NumberOfPages < PropPageData->MaximumNumberOfPages)
1153 {
1154 *PropPageData->PropertySheetPages = hPropSheetPage;
1155 PropPageData->PropertySheetPages++;
1156 }
1157
1158 PropPageData->NumberOfPages++;
1159 return TRUE;
1160 }
1161
1162 /***********************************************************************
1163 * SetupDiGetClassDevPropertySheetsW(SETUPAPI.@)
1164 */
1165 BOOL WINAPI
1166 SetupDiGetClassDevPropertySheetsW(
1167 IN HDEVINFO DeviceInfoSet,
1168 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
1169 IN OUT LPPROPSHEETHEADERW PropertySheetHeader,
1170 IN DWORD PropertySheetHeaderPageListSize,
1171 OUT PDWORD RequiredSize OPTIONAL,
1172 IN DWORD PropertySheetType)
1173 {
1174 struct DeviceInfoSet *list;
1175 BOOL ret = FALSE;
1176
1177 TRACE("%p %p %p 0%lx %p 0x%lx\n", DeviceInfoSet, DeviceInfoData,
1178 PropertySheetHeader, PropertySheetHeaderPageListSize,
1179 RequiredSize, PropertySheetType);
1180
1181 if (!DeviceInfoSet)
1182 SetLastError(ERROR_INVALID_HANDLE);
1183 else if (((struct DeviceInfoSet *)DeviceInfoSet)->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1184 SetLastError(ERROR_INVALID_HANDLE);
1185 else if ((list = (struct DeviceInfoSet *)DeviceInfoSet)->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1186 SetLastError(ERROR_INVALID_HANDLE);
1187 else if (!PropertySheetHeader)
1188 SetLastError(ERROR_INVALID_PARAMETER);
1189 else if (PropertySheetHeader->dwFlags & PSH_PROPSHEETPAGE)
1190 SetLastError(ERROR_INVALID_FLAGS);
1191 else if (DeviceInfoData && DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA))
1192 SetLastError(ERROR_INVALID_USER_BUFFER);
1193 else if (!DeviceInfoData && IsEqualIID(&list->ClassGuid, &GUID_NULL))
1194 SetLastError(ERROR_INVALID_PARAMETER);
1195 else if (!PropertySheetHeader)
1196 SetLastError(ERROR_INVALID_PARAMETER);
1197 else if (PropertySheetType != DIGCDP_FLAG_ADVANCED
1198 && PropertySheetType != DIGCDP_FLAG_BASIC
1199 && PropertySheetType != DIGCDP_FLAG_REMOTE_ADVANCED
1200 && PropertySheetType != DIGCDP_FLAG_REMOTE_BASIC)
1201 SetLastError(ERROR_INVALID_PARAMETER);
1202 else
1203 {
1204 HKEY hKey = INVALID_HANDLE_VALUE;
1205 SP_PROPSHEETPAGE_REQUEST Request;
1206 LPWSTR PropPageProvider = NULL;
1207 HMODULE hModule = NULL;
1208 PROPERTY_PAGE_PROVIDER pPropPageProvider = NULL;
1209 struct ClassDevPropertySheetsData PropPageData;
1210 DWORD dwLength, dwRegType;
1211 DWORD rc;
1212
1213 if (DeviceInfoData)
1214 hKey = SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_QUERY_VALUE);
1215 else
1216 {
1217 hKey = SetupDiOpenClassRegKeyExW(&list->ClassGuid, KEY_QUERY_VALUE,
1218 DIOCR_INSTALLER, list->MachineName + 2, NULL);
1219 }
1220 if (hKey == INVALID_HANDLE_VALUE)
1221 goto cleanup;
1222
1223 rc = RegQueryValueExW(hKey, REGSTR_VAL_ENUMPROPPAGES_32, NULL, &dwRegType, NULL, &dwLength);
1224 if (rc == ERROR_FILE_NOT_FOUND)
1225 {
1226 /* No registry key. As it is optional, don't say it's a bad error */
1227 if (RequiredSize)
1228 *RequiredSize = 0;
1229 ret = TRUE;
1230 goto cleanup;
1231 }
1232 else if (rc != ERROR_SUCCESS && dwRegType != REG_SZ)
1233 {
1234 SetLastError(rc);
1235 goto cleanup;
1236 }
1237
1238 PropPageProvider = HeapAlloc(GetProcessHeap(), 0, dwLength + sizeof(WCHAR));
1239 if (!PropPageProvider)
1240 {
1241 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1242 goto cleanup;
1243 }
1244 rc = RegQueryValueExW(hKey, REGSTR_VAL_ENUMPROPPAGES_32, NULL, NULL, (LPBYTE)PropPageProvider, &dwLength);
1245 if (rc != ERROR_SUCCESS)
1246 {
1247 SetLastError(rc);
1248 goto cleanup;
1249 }
1250 PropPageProvider[dwLength / sizeof(WCHAR)] = 0;
1251
1252 rc = GetFunctionPointer(PropPageProvider, &hModule, (PVOID*)&pPropPageProvider);
1253 if (rc != ERROR_SUCCESS)
1254 {
1255 SetLastError(ERROR_INVALID_PROPPAGE_PROVIDER);
1256 goto cleanup;
1257 }
1258
1259 Request.cbSize = sizeof(SP_PROPSHEETPAGE_REQUEST);
1260 Request.PageRequested = SPPSR_ENUM_ADV_DEVICE_PROPERTIES;
1261 Request.DeviceInfoSet = DeviceInfoSet;
1262 Request.DeviceInfoData = DeviceInfoData;
1263 PropPageData.PropertySheetPages = &PropertySheetHeader->phpage[PropertySheetHeader->nPages];
1264 PropPageData.MaximumNumberOfPages = PropertySheetHeaderPageListSize - PropertySheetHeader->nPages;
1265 PropPageData.NumberOfPages = 0;
1266 ret = pPropPageProvider(&Request, SETUP_GetClassDevPropertySheetsCallback, (LPARAM)&PropPageData);
1267 if (!ret)
1268 goto cleanup;
1269
1270 if (RequiredSize)
1271 *RequiredSize = PropPageData.NumberOfPages + PropertySheetHeader->nPages;
1272 if (PropPageData.NumberOfPages <= PropPageData.MaximumNumberOfPages)
1273 {
1274 PropertySheetHeader->nPages += PropPageData.NumberOfPages;
1275 ret = TRUE;
1276 }
1277 else
1278 {
1279 PropertySheetHeader->nPages += PropPageData.MaximumNumberOfPages;
1280 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1281 }
1282
1283 cleanup:
1284 if (hKey != INVALID_HANDLE_VALUE)
1285 RegCloseKey(hKey);
1286 HeapFree(GetProcessHeap(), 0, PropPageProvider);
1287 FreeFunctionPointer(hModule, pPropPageProvider);
1288 }
1289
1290 TRACE("Returning %d\n", ret);
1291 return ret;
1292 }