2 * SetupAPI device installer
4 * Copyright 2000 Andreas Mohr for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
35 #include "wine/debug.h"
36 #include "wine/list.h"
37 #include "wine/unicode.h"
44 #include "setupapi_private.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
49 /* Unicode constants */
50 static const WCHAR ClassGUID[] = {'C','l','a','s','s','G','U','I','D',0};
51 static const WCHAR Class[] = {'C','l','a','s','s',0};
52 static const WCHAR ClassInstall32[] = {'C','l','a','s','s','I','n','s','t','a','l','l','3','2',0};
53 static const WCHAR NoDisplayClass[] = {'N','o','D','i','s','p','l','a','y','C','l','a','s','s',0};
54 static const WCHAR NoInstallClass[] = {'N','o','I','n','s','t','a','l','l','C','l','a','s','s',0};
55 static const WCHAR NoUseClass[] = {'N','o','U','s','e','C','l','a','s','s',0};
56 static const WCHAR NtExtension[] = {'.','N','T',0};
57 static const WCHAR NtPlatformExtension[] = {'.','N','T','x','8','6',0};
58 static const WCHAR Version[] = {'V','e','r','s','i','o','n',0};
59 static const WCHAR WinExtension[] = {'.','W','i','n',0};
61 /* Registry key and value names */
62 static const WCHAR ControlClass[] = {'S','y','s','t','e','m','\\',
63 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
64 'C','o','n','t','r','o','l','\\',
65 'C','l','a','s','s',0};
67 static const WCHAR DeviceClasses[] = {'S','y','s','t','e','m','\\',
68 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
69 'C','o','n','t','r','o','l','\\',
70 'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
71 static const WCHAR Enum[] = {'S','y','s','t','e','m','\\',
72 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
74 static const WCHAR DeviceDesc[] = {'D','e','v','i','c','e','D','e','s','c',0};
75 static const WCHAR DeviceInstance[] = {'D','e','v','i','c','e','I','n','s','t','a','n','c','e',0};
76 static const WCHAR HardwareId[] = {'H','a','r','d','w','a','r','e','I','D',0};
77 static const WCHAR CompatibleIDs[] = {'C','o','m','p','a','t','i','b','l','e','I','d','s',0};
78 static const WCHAR Service[] = {'S','e','r','v','i','c','e',0};
79 static const WCHAR Driver[] = {'D','r','i','v','e','r',0};
80 static const WCHAR ConfigFlags[] = {'C','o','n','f','i','g','F','l','a','g','s',0};
81 static const WCHAR Mfg[] = {'M','f','g',0};
82 static const WCHAR FriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
83 static const WCHAR LocationInformation[] = {'L','o','c','a','t','i','o','n','I','n','f','o','r','m','a','t','i','o','n',0};
84 static const WCHAR Capabilities[] = {'C','a','p','a','b','i','l','i','t','i','e','s',0};
85 static const WCHAR UINumber[] = {'U','I','N','u','m','b','e','r',0};
86 static const WCHAR UpperFilters[] = {'U','p','p','e','r','F','i','l','t','e','r','s',0};
87 static const WCHAR LowerFilters[] = {'L','o','w','e','r','F','i','l','t','e','r','s',0};
88 static const WCHAR Phantom[] = {'P','h','a','n','t','o','m',0};
89 static const WCHAR SymbolicLink[] = {'S','y','m','b','o','l','i','c','L','i','n','k',0};
91 /* is used to identify if a DeviceInfoSet pointer is
93 #define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff056
97 DWORD magic; /* if is equal to SETUP_DEVICE_INFO_SET_MAGIC struct is okay */
104 struct DeviceInstance
107 SP_DEVINFO_DATA data;
110 /* Pointed to by SP_DEVICE_INTERFACE_DATA's Reserved member */
113 LPWSTR referenceString;
115 PSP_DEVINFO_DATA device;
118 /* A device may have multiple instances of the same interface, so this holds
119 * each instance belonging to a particular interface.
121 struct InterfaceInstances
125 DWORD cInstancesAllocated;
126 SP_DEVICE_INTERFACE_DATA *instances;
130 /* Pointed to by SP_DEVINFO_DATA's Reserved member */
133 struct DeviceInfoSet *set;
138 struct list interfaces;
141 static void SETUPDI_GuidToString(const GUID *guid, LPWSTR guidStr)
143 static const WCHAR fmt[] = {'{','%','0','8','X','-','%','0','4','X','-',
144 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
145 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
148 sprintfW(guidStr, fmt, guid->Data1, guid->Data2, guid->Data3,
149 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
150 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
153 static void SETUPDI_FreeInterfaceInstances(struct InterfaceInstances *instances)
157 for (i = 0; i < instances->cInstances; i++)
159 struct InterfaceInfo *ifaceInfo =
160 (struct InterfaceInfo *)instances->instances[i].Reserved;
162 if (ifaceInfo->device && ifaceInfo->device->Reserved)
164 struct DeviceInfo *devInfo =
165 (struct DeviceInfo *)ifaceInfo->device->Reserved;
167 if (devInfo->phantom)
168 SetupDiDeleteDeviceInterfaceRegKey(devInfo->set,
169 &instances->instances[i], 0);
171 HeapFree(GetProcessHeap(), 0, ifaceInfo->referenceString);
172 HeapFree(GetProcessHeap(), 0, ifaceInfo->symbolicLink);
173 HeapFree(GetProcessHeap(), 0, ifaceInfo);
175 HeapFree(GetProcessHeap(), 0, instances->instances);
178 /* Finds the interface with interface class InterfaceClassGuid in the device.
179 * Returns TRUE if found, and updates *interface to point to device's
180 * interfaces member where the given interface was found.
181 * Returns FALSE if not found.
183 static BOOL SETUPDI_FindInterface(const struct DeviceInfo *devInfo,
184 const GUID *InterfaceClassGuid, struct InterfaceInstances **interface)
187 struct InterfaceInstances *iface;
189 TRACE("%s\n", debugstr_guid(InterfaceClassGuid));
191 LIST_FOR_EACH_ENTRY(iface, &devInfo->interfaces, struct InterfaceInstances,
194 if (IsEqualGUID(&iface->guid, InterfaceClassGuid))
201 TRACE("returning %d (%p)\n", found, found ? *interface : NULL);
205 /* Finds the interface instance with reference string ReferenceString in the
206 * interface instance map. Returns TRUE if found, and updates instanceIndex to
207 * the index of the interface instance's instances member
208 * where the given instance was found. Returns FALSE if not found.
210 static BOOL SETUPDI_FindInterfaceInstance(
211 const struct InterfaceInstances *instances,
212 LPCWSTR ReferenceString, DWORD *instanceIndex)
217 TRACE("%s\n", debugstr_w(ReferenceString));
219 for (i = 0; !found && i < instances->cInstances; i++)
221 SP_DEVICE_INTERFACE_DATA *ifaceData = &instances->instances[i];
222 struct InterfaceInfo *ifaceInfo =
223 (struct InterfaceInfo *)ifaceData->Reserved;
225 if (!ReferenceString && !ifaceInfo->referenceString)
230 else if (ReferenceString && ifaceInfo->referenceString &&
231 !lstrcmpiW(ifaceInfo->referenceString, ReferenceString))
237 TRACE("returning %d (%d)\n", found, found ? *instanceIndex : 0);
241 static LPWSTR SETUPDI_CreateSymbolicLinkPath(LPCWSTR instanceId,
242 const GUID *InterfaceClassGuid, LPCWSTR ReferenceString)
244 static const WCHAR fmt[] = {'\\','\\','?','\\','%','s','#','%','s',0};
249 SETUPDI_GuidToString(InterfaceClassGuid, guidStr);
250 /* omit length of format specifiers, but include NULL terminator: */
251 len = lstrlenW(fmt) - 4 + 1;
252 len += lstrlenW(instanceId) + lstrlenW(guidStr);
253 if (ReferenceString && *ReferenceString)
255 /* space for a hash between string and reference string: */
256 len += lstrlenW(ReferenceString) + 1;
258 ret = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
261 int printed = sprintfW(ret, fmt, instanceId, guidStr);
264 /* replace '\\' with '#' after the "\\\\?\\" beginning */
265 for (ptr = strchrW(ret + 4, '\\'); ptr; ptr = strchrW(ptr + 1, '\\'))
267 if (ReferenceString && *ReferenceString)
270 lstrcpyW(ret + printed + 1, ReferenceString);
276 /* Adds an interface with the given interface class and reference string to
277 * the device, if it doesn't already exist in the device. If iface is not
278 * NULL, returns a pointer to the newly added (or already existing) interface.
280 static BOOL SETUPDI_AddInterfaceInstance(PSP_DEVINFO_DATA DeviceInfoData,
281 const GUID *InterfaceClassGuid, LPCWSTR ReferenceString,
282 SP_DEVICE_INTERFACE_DATA **ifaceData)
284 struct DeviceInfo *devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
285 BOOL newInterface = FALSE, ret;
286 struct InterfaceInstances *iface = NULL;
288 TRACE("%p %s %s %p\n", devInfo, debugstr_guid(InterfaceClassGuid),
289 debugstr_w(ReferenceString), iface);
291 if (!(ret = SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface)))
293 iface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
294 sizeof(struct InterfaceInstances));
297 list_add_tail(&devInfo->interfaces, &iface->entry);
303 DWORD instanceIndex = 0;
305 if (!(ret = SETUPDI_FindInterfaceInstance(iface, ReferenceString,
308 SP_DEVICE_INTERFACE_DATA *instance = NULL;
310 if (!iface->cInstancesAllocated)
312 iface->instances = HeapAlloc(GetProcessHeap(), 0,
313 sizeof(SP_DEVICE_INTERFACE_DATA));
314 if (iface->instances)
315 instance = &iface->instances[iface->cInstancesAllocated++];
317 else if (iface->cInstances == iface->cInstancesAllocated)
319 iface->instances = HeapReAlloc(GetProcessHeap(), 0,
321 (iface->cInstancesAllocated + 1) *
322 sizeof(SP_DEVICE_INTERFACE_DATA));
323 if (iface->instances)
324 instance = &iface->instances[iface->cInstancesAllocated++];
327 instance = &iface->instances[iface->cInstances];
330 struct InterfaceInfo *ifaceInfo = HeapAlloc(GetProcessHeap(),
331 0, sizeof(struct InterfaceInfo));
336 ifaceInfo->device = DeviceInfoData;
337 ifaceInfo->symbolicLink = SETUPDI_CreateSymbolicLinkPath(
338 devInfo->instanceId, InterfaceClassGuid,
342 ifaceInfo->referenceString =
343 HeapAlloc(GetProcessHeap(), 0,
344 (lstrlenW(ReferenceString) + 1) *
346 if (ifaceInfo->referenceString)
347 lstrcpyW(ifaceInfo->referenceString,
353 ifaceInfo->referenceString = NULL;
360 sizeof(SP_DEVICE_INTERFACE_DATA);
361 instance->InterfaceClassGuid = *InterfaceClassGuid;
362 instance->Flags = SPINT_ACTIVE; /* FIXME */
363 instance->Reserved = (ULONG_PTR)ifaceInfo;
365 iface->guid = *InterfaceClassGuid;
366 key = SetupDiCreateDeviceInterfaceRegKeyW(devInfo->set,
367 instance, 0, KEY_WRITE, NULL, NULL);
368 if (key != INVALID_HANDLE_VALUE)
370 RegSetValueExW(key, SymbolicLink, 0, REG_SZ,
371 (BYTE *)ifaceInfo->symbolicLink,
372 lstrlenW(ifaceInfo->symbolicLink) *
377 *ifaceData = instance;
380 HeapFree(GetProcessHeap(), 0, ifaceInfo);
387 *ifaceData = &iface->instances[instanceIndex];
392 TRACE("returning %d\n", ret);
396 static BOOL SETUPDI_SetInterfaceSymbolicLink(SP_DEVICE_INTERFACE_DATA *iface,
397 LPCWSTR symbolicLink)
399 struct InterfaceInfo *info = (struct InterfaceInfo *)iface->Reserved;
404 HeapFree(GetProcessHeap(), 0, info->symbolicLink);
405 info->symbolicLink = HeapAlloc(GetProcessHeap(), 0,
406 (lstrlenW(symbolicLink) + 1) * sizeof(WCHAR));
407 if (info->symbolicLink)
409 lstrcpyW(info->symbolicLink, symbolicLink);
416 static HKEY SETUPDI_CreateDevKey(struct DeviceInfo *devInfo)
418 HKEY enumKey, key = INVALID_HANDLE_VALUE;
421 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
422 NULL, &enumKey, NULL);
425 RegCreateKeyExW(enumKey, devInfo->instanceId, 0, NULL, 0,
426 KEY_READ | KEY_WRITE, NULL, &key, NULL);
427 RegCloseKey(enumKey);
432 static HKEY SETUPDI_CreateDrvKey(struct DeviceInfo *devInfo)
434 static const WCHAR slash[] = { '\\',0 };
435 WCHAR classKeyPath[MAX_PATH];
436 HKEY classKey, key = INVALID_HANDLE_VALUE;
439 lstrcpyW(classKeyPath, ControlClass);
440 lstrcatW(classKeyPath, slash);
441 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
442 classKeyPath + lstrlenW(classKeyPath));
443 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
444 KEY_ALL_ACCESS, NULL, &classKey, NULL);
447 static const WCHAR fmt[] = { '%','0','4','u',0 };
450 sprintfW(devId, fmt, devInfo->devId);
451 RegCreateKeyExW(classKey, devId, 0, NULL, 0, KEY_READ | KEY_WRITE,
453 RegCloseKey(classKey);
458 static struct DeviceInfo *SETUPDI_AllocateDeviceInfo(struct DeviceInfoSet *set,
459 DWORD devId, LPCWSTR instanceId, BOOL phantom)
461 struct DeviceInfo *devInfo = NULL;
462 HANDLE devInst = GlobalAlloc(GMEM_FIXED, sizeof(struct DeviceInfo));
464 devInfo = GlobalLock(devInst);
469 devInfo->devId = (DWORD)devInst;
471 devInfo->instanceId = HeapAlloc(GetProcessHeap(), 0,
472 (lstrlenW(instanceId) + 1) * sizeof(WCHAR));
473 if (devInfo->instanceId)
475 devInfo->key = INVALID_HANDLE_VALUE;
476 devInfo->phantom = phantom;
477 lstrcpyW(devInfo->instanceId, instanceId);
478 struprW(devInfo->instanceId);
479 devInfo->key = SETUPDI_CreateDevKey(devInfo);
480 if (devInfo->key != INVALID_HANDLE_VALUE)
483 RegSetValueExW(devInfo->key, Phantom, 0, REG_DWORD,
484 (LPBYTE)&phantom, sizeof(phantom));
486 list_init(&devInfo->interfaces);
487 GlobalUnlock(devInst);
491 GlobalUnlock(devInst);
499 static void SETUPDI_FreeDeviceInfo(struct DeviceInfo *devInfo)
501 struct InterfaceInstances *iface, *next;
503 if (devInfo->key != INVALID_HANDLE_VALUE)
504 RegCloseKey(devInfo->key);
505 if (devInfo->phantom)
510 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0,
511 KEY_ALL_ACCESS, NULL, &enumKey, NULL);
514 RegDeleteTreeW(enumKey, devInfo->instanceId);
515 RegCloseKey(enumKey);
518 HeapFree(GetProcessHeap(), 0, devInfo->instanceId);
519 LIST_FOR_EACH_ENTRY_SAFE(iface, next, &devInfo->interfaces,
520 struct InterfaceInstances, entry)
522 list_remove(&iface->entry);
523 SETUPDI_FreeInterfaceInstances(iface);
524 HeapFree(GetProcessHeap(), 0, iface);
526 GlobalFree((HANDLE)devInfo->devId);
529 /* Adds a device with GUID guid and identifer devInst to set. Allocates a
530 * struct DeviceInfo, and points the returned device info's Reserved member
531 * to it. "Phantom" devices are deleted from the registry when closed.
532 * Returns a pointer to the newly allocated device info.
534 static BOOL SETUPDI_AddDeviceToSet(struct DeviceInfoSet *set,
539 SP_DEVINFO_DATA **dev)
542 struct DeviceInfo *devInfo = SETUPDI_AllocateDeviceInfo(set, set->cDevices,
543 instanceId, phantom);
545 TRACE("%p, %s, %d, %s, %d\n", set, debugstr_guid(guid), devInst,
546 debugstr_w(instanceId), phantom);
550 struct DeviceInstance *devInst =
551 HeapAlloc(GetProcessHeap(), 0, sizeof(struct DeviceInstance));
555 WCHAR classGuidStr[39];
557 list_add_tail(&set->devices, &devInst->entry);
559 devInst->data.cbSize = sizeof(SP_DEVINFO_DATA);
560 devInst->data.ClassGuid = *guid;
561 devInst->data.DevInst = devInfo->devId;
562 devInst->data.Reserved = (ULONG_PTR)devInfo;
563 SETUPDI_GuidToString(guid, classGuidStr);
564 SetupDiSetDeviceRegistryPropertyW(set, &devInst->data,
565 SPDRP_CLASSGUID, (const BYTE *)classGuidStr,
566 lstrlenW(classGuidStr) * sizeof(WCHAR));
567 if (dev) *dev = &devInst->data;
572 HeapFree(GetProcessHeap(), 0, devInfo);
573 SetLastError(ERROR_OUTOFMEMORY);
579 /***********************************************************************
580 * SetupDiBuildClassInfoList (SETUPAPI.@)
582 * Returns a list of setup class GUIDs that identify the classes
583 * that are installed on a local machine.
586 * Flags [I] control exclusion of classes from the list.
587 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
588 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
589 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
595 BOOL WINAPI SetupDiBuildClassInfoList(
597 LPGUID ClassGuidList,
598 DWORD ClassGuidListSize,
602 return SetupDiBuildClassInfoListExW(Flags, ClassGuidList,
603 ClassGuidListSize, RequiredSize,
607 /***********************************************************************
608 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
610 * Returns a list of setup class GUIDs that identify the classes
611 * that are installed on a local or remote macine.
614 * Flags [I] control exclusion of classes from the list.
615 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
616 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
617 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
618 * MachineName [I] name of a remote machine.
619 * Reserved [I] must be NULL.
625 BOOL WINAPI SetupDiBuildClassInfoListExA(
627 LPGUID ClassGuidList,
628 DWORD ClassGuidListSize,
633 LPWSTR MachineNameW = NULL;
640 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
641 if (MachineNameW == NULL) return FALSE;
644 bResult = SetupDiBuildClassInfoListExW(Flags, ClassGuidList,
645 ClassGuidListSize, RequiredSize,
646 MachineNameW, Reserved);
648 MyFree(MachineNameW);
653 /***********************************************************************
654 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
656 * Returns a list of setup class GUIDs that identify the classes
657 * that are installed on a local or remote macine.
660 * Flags [I] control exclusion of classes from the list.
661 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
662 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
663 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
664 * MachineName [I] name of a remote machine.
665 * Reserved [I] must be NULL.
671 BOOL WINAPI SetupDiBuildClassInfoListExW(
673 LPGUID ClassGuidList,
674 DWORD ClassGuidListSize,
685 DWORD dwGuidListIndex = 0;
689 if (RequiredSize != NULL)
692 hClassesKey = SetupDiOpenClassRegKeyExW(NULL,
697 if (hClassesKey == INVALID_HANDLE_VALUE)
702 for (dwIndex = 0; ; dwIndex++)
705 lError = RegEnumKeyExW(hClassesKey,
713 TRACE("RegEnumKeyExW() returns %d\n", lError);
714 if (lError == ERROR_SUCCESS || lError == ERROR_MORE_DATA)
716 TRACE("Key name: %p\n", szKeyName);
718 if (RegOpenKeyExW(hClassesKey,
724 RegCloseKey(hClassesKey);
728 if (!RegQueryValueExW(hClassKey,
735 TRACE("'NoUseClass' value found!\n");
736 RegCloseKey(hClassKey);
740 if ((Flags & DIBCI_NOINSTALLCLASS) &&
741 (!RegQueryValueExW(hClassKey,
748 TRACE("'NoInstallClass' value found!\n");
749 RegCloseKey(hClassKey);
753 if ((Flags & DIBCI_NODISPLAYCLASS) &&
754 (!RegQueryValueExW(hClassKey,
761 TRACE("'NoDisplayClass' value found!\n");
762 RegCloseKey(hClassKey);
766 RegCloseKey(hClassKey);
768 TRACE("Guid: %p\n", szKeyName);
769 if (dwGuidListIndex < ClassGuidListSize)
771 if (szKeyName[0] == '{' && szKeyName[37] == '}')
775 TRACE("Guid: %p\n", &szKeyName[1]);
777 UuidFromStringW(&szKeyName[1],
778 &ClassGuidList[dwGuidListIndex]);
784 if (lError != ERROR_SUCCESS)
788 RegCloseKey(hClassesKey);
790 if (RequiredSize != NULL)
791 *RequiredSize = dwGuidListIndex;
793 if (ClassGuidListSize < dwGuidListIndex)
795 SetLastError(ERROR_INSUFFICIENT_BUFFER);
802 /***********************************************************************
803 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
805 BOOL WINAPI SetupDiClassGuidsFromNameA(
807 LPGUID ClassGuidList,
808 DWORD ClassGuidListSize,
811 return SetupDiClassGuidsFromNameExA(ClassName, ClassGuidList,
812 ClassGuidListSize, RequiredSize,
816 /***********************************************************************
817 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
819 BOOL WINAPI SetupDiClassGuidsFromNameW(
821 LPGUID ClassGuidList,
822 DWORD ClassGuidListSize,
825 return SetupDiClassGuidsFromNameExW(ClassName, ClassGuidList,
826 ClassGuidListSize, RequiredSize,
830 /***********************************************************************
831 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
833 BOOL WINAPI SetupDiClassGuidsFromNameExA(
835 LPGUID ClassGuidList,
836 DWORD ClassGuidListSize,
841 LPWSTR ClassNameW = NULL;
842 LPWSTR MachineNameW = NULL;
845 ClassNameW = MultiByteToUnicode(ClassName, CP_ACP);
846 if (ClassNameW == NULL)
851 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
852 if (MachineNameW == NULL)
859 bResult = SetupDiClassGuidsFromNameExW(ClassNameW, ClassGuidList,
860 ClassGuidListSize, RequiredSize,
861 MachineNameW, Reserved);
863 MyFree(MachineNameW);
869 /***********************************************************************
870 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
872 BOOL WINAPI SetupDiClassGuidsFromNameExW(
874 LPGUID ClassGuidList,
875 DWORD ClassGuidListSize,
881 WCHAR szClassName[256];
887 DWORD dwGuidListIndex = 0;
889 if (RequiredSize != NULL)
892 hClassesKey = SetupDiOpenClassRegKeyExW(NULL,
897 if (hClassesKey == INVALID_HANDLE_VALUE)
902 for (dwIndex = 0; ; dwIndex++)
905 lError = RegEnumKeyExW(hClassesKey,
913 TRACE("RegEnumKeyExW() returns %d\n", lError);
914 if (lError == ERROR_SUCCESS || lError == ERROR_MORE_DATA)
916 TRACE("Key name: %p\n", szKeyName);
918 if (RegOpenKeyExW(hClassesKey,
924 RegCloseKey(hClassesKey);
928 dwLength = 256 * sizeof(WCHAR);
929 if (!RegQueryValueExW(hClassKey,
936 TRACE("Class name: %p\n", szClassName);
938 if (strcmpiW(szClassName, ClassName) == 0)
940 TRACE("Found matching class name\n");
942 TRACE("Guid: %p\n", szKeyName);
943 if (dwGuidListIndex < ClassGuidListSize)
945 if (szKeyName[0] == '{' && szKeyName[37] == '}')
949 TRACE("Guid: %p\n", &szKeyName[1]);
951 UuidFromStringW(&szKeyName[1],
952 &ClassGuidList[dwGuidListIndex]);
959 RegCloseKey(hClassKey);
962 if (lError != ERROR_SUCCESS)
966 RegCloseKey(hClassesKey);
968 if (RequiredSize != NULL)
969 *RequiredSize = dwGuidListIndex;
971 if (ClassGuidListSize < dwGuidListIndex)
973 SetLastError(ERROR_INSUFFICIENT_BUFFER);
980 /***********************************************************************
981 * SetupDiClassNameFromGuidA (SETUPAPI.@)
983 BOOL WINAPI SetupDiClassNameFromGuidA(
984 const GUID* ClassGuid,
989 return SetupDiClassNameFromGuidExA(ClassGuid, ClassName,
990 ClassNameSize, RequiredSize,
994 /***********************************************************************
995 * SetupDiClassNameFromGuidW (SETUPAPI.@)
997 BOOL WINAPI SetupDiClassNameFromGuidW(
998 const GUID* ClassGuid,
1000 DWORD ClassNameSize,
1001 PDWORD RequiredSize)
1003 return SetupDiClassNameFromGuidExW(ClassGuid, ClassName,
1004 ClassNameSize, RequiredSize,
1008 /***********************************************************************
1009 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1011 BOOL WINAPI SetupDiClassNameFromGuidExA(
1012 const GUID* ClassGuid,
1014 DWORD ClassNameSize,
1015 PDWORD RequiredSize,
1019 WCHAR ClassNameW[MAX_CLASS_NAME_LEN];
1020 LPWSTR MachineNameW = NULL;
1024 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
1025 ret = SetupDiClassNameFromGuidExW(ClassGuid, ClassNameW, MAX_CLASS_NAME_LEN,
1026 NULL, MachineNameW, Reserved);
1029 int len = WideCharToMultiByte(CP_ACP, 0, ClassNameW, -1, ClassName,
1030 ClassNameSize, NULL, NULL);
1032 if (!ClassNameSize && RequiredSize)
1033 *RequiredSize = len;
1035 MyFree(MachineNameW);
1039 /***********************************************************************
1040 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1042 BOOL WINAPI SetupDiClassNameFromGuidExW(
1043 const GUID* ClassGuid,
1045 DWORD ClassNameSize,
1046 PDWORD RequiredSize,
1053 hKey = SetupDiOpenClassRegKeyExW(ClassGuid,
1058 if (hKey == INVALID_HANDLE_VALUE)
1063 if (RequiredSize != NULL)
1066 if (RegQueryValueExW(hKey,
1077 *RequiredSize = dwLength / sizeof(WCHAR);
1080 dwLength = ClassNameSize * sizeof(WCHAR);
1081 if (RegQueryValueExW(hKey,
1097 /***********************************************************************
1098 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1101 SetupDiCreateDeviceInfoList(const GUID *ClassGuid,
1104 return SetupDiCreateDeviceInfoListExW(ClassGuid, hwndParent, NULL, NULL);
1107 /***********************************************************************
1108 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1111 SetupDiCreateDeviceInfoListExA(const GUID *ClassGuid,
1116 LPWSTR MachineNameW = NULL;
1123 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
1124 if (MachineNameW == NULL)
1125 return INVALID_HANDLE_VALUE;
1128 hDevInfo = SetupDiCreateDeviceInfoListExW(ClassGuid, hwndParent,
1129 MachineNameW, Reserved);
1131 MyFree(MachineNameW);
1136 /***********************************************************************
1137 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1139 * Create an empty DeviceInfoSet list.
1142 * ClassGuid [I] if not NULL only devices with GUID ClassGuid are associated
1144 * hwndParent [I] hwnd needed for interface related actions.
1145 * MachineName [I] name of machine to create emtpy DeviceInfoSet list, if NULL
1146 * local registry will be used.
1147 * Reserved [I] must be NULL
1150 * Success: empty list.
1151 * Failure: INVALID_HANDLE_VALUE.
1154 SetupDiCreateDeviceInfoListExW(const GUID *ClassGuid,
1159 struct DeviceInfoSet *list = NULL;
1160 DWORD size = sizeof(struct DeviceInfoSet);
1162 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid), hwndParent,
1163 debugstr_w(MachineName), Reserved);
1165 if (MachineName != NULL)
1167 FIXME("remote support is not implemented\n");
1168 SetLastError(ERROR_INVALID_MACHINENAME);
1169 return INVALID_HANDLE_VALUE;
1172 if (Reserved != NULL)
1174 SetLastError(ERROR_INVALID_PARAMETER);
1175 return INVALID_HANDLE_VALUE;
1178 list = HeapAlloc(GetProcessHeap(), 0, size);
1181 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1182 return INVALID_HANDLE_VALUE;
1185 list->magic = SETUP_DEVICE_INFO_SET_MAGIC;
1186 list->hwndParent = hwndParent;
1187 memcpy(&list->ClassGuid,
1188 ClassGuid ? ClassGuid : &GUID_NULL,
1189 sizeof(list->ClassGuid));
1191 list_init(&list->devices);
1196 /***********************************************************************
1197 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1199 HKEY WINAPI SetupDiCreateDevRegKeyA(
1200 HDEVINFO DeviceInfoSet,
1201 PSP_DEVINFO_DATA DeviceInfoData,
1206 PCSTR InfSectionName)
1208 PWSTR InfSectionNameW = NULL;
1211 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet, DeviceInfoData, Scope,
1212 HwProfile, KeyType, InfHandle, debugstr_a(InfSectionName));
1216 if (!InfSectionName)
1218 SetLastError(ERROR_INVALID_PARAMETER);
1219 return INVALID_HANDLE_VALUE;
1223 InfSectionNameW = MultiByteToUnicode(InfSectionName, CP_ACP);
1224 if (InfSectionNameW == NULL) return INVALID_HANDLE_VALUE;
1227 key = SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, Scope,
1228 HwProfile, KeyType, InfHandle, InfSectionNameW);
1229 MyFree(InfSectionNameW);
1233 /***********************************************************************
1234 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1236 HKEY WINAPI SetupDiCreateDevRegKeyW(
1237 HDEVINFO DeviceInfoSet,
1238 PSP_DEVINFO_DATA DeviceInfoData,
1243 PCWSTR InfSectionName)
1245 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
1246 struct DeviceInfo *devInfo;
1247 HKEY key = INVALID_HANDLE_VALUE;
1249 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet, DeviceInfoData, Scope,
1250 HwProfile, KeyType, InfHandle, debugstr_w(InfSectionName));
1252 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
1254 SetLastError(ERROR_INVALID_HANDLE);
1255 return INVALID_HANDLE_VALUE;
1257 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1259 SetLastError(ERROR_INVALID_HANDLE);
1260 return INVALID_HANDLE_VALUE;
1262 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
1263 || !DeviceInfoData->Reserved)
1265 SetLastError(ERROR_INVALID_PARAMETER);
1266 return INVALID_HANDLE_VALUE;
1268 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1269 if (devInfo->set != set)
1271 SetLastError(ERROR_INVALID_PARAMETER);
1272 return INVALID_HANDLE_VALUE;
1274 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
1276 SetLastError(ERROR_INVALID_FLAGS);
1277 return INVALID_HANDLE_VALUE;
1279 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV)
1281 SetLastError(ERROR_INVALID_FLAGS);
1282 return INVALID_HANDLE_VALUE;
1284 if (devInfo->phantom)
1286 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
1287 return INVALID_HANDLE_VALUE;
1289 if (Scope != DICS_FLAG_GLOBAL)
1290 FIXME("unimplemented for scope %d\n", Scope);
1294 key = SETUPDI_CreateDevKey(devInfo);
1297 key = SETUPDI_CreateDrvKey(devInfo);
1300 WARN("unknown KeyType %d\n", KeyType);
1303 SetupInstallFromInfSectionW(NULL, InfHandle, InfSectionName, SPINST_ALL,
1304 NULL, NULL, SP_COPY_NEWER_ONLY, NULL, NULL, DeviceInfoSet,
1309 /***********************************************************************
1310 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1312 BOOL WINAPI SetupDiCreateDeviceInfoA(
1313 HDEVINFO DeviceInfoSet,
1315 CONST GUID *ClassGuid,
1316 PCSTR DeviceDescription,
1318 DWORD CreationFlags,
1319 PSP_DEVINFO_DATA DeviceInfoData)
1322 LPWSTR DeviceNameW = NULL;
1323 LPWSTR DeviceDescriptionW = NULL;
1327 DeviceNameW = MultiByteToUnicode(DeviceName, CP_ACP);
1328 if (DeviceNameW == NULL) return FALSE;
1330 if (DeviceDescription)
1332 DeviceDescriptionW = MultiByteToUnicode(DeviceDescription, CP_ACP);
1333 if (DeviceDescriptionW == NULL)
1335 MyFree(DeviceNameW);
1340 ret = SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceNameW, ClassGuid, DeviceDescriptionW,
1341 hwndParent, CreationFlags, DeviceInfoData);
1343 MyFree(DeviceNameW);
1344 MyFree(DeviceDescriptionW);
1349 static DWORD SETUPDI_DevNameToDevID(LPCWSTR devName)
1352 int devNameLen = lstrlenW(devName);
1356 TRACE("%s\n", debugstr_w(devName));
1357 for (ptr = devName; valid && *ptr && ptr - devName < devNameLen; )
1362 devInst |= *ptr - '0';
1368 TRACE("%d\n", valid ? devInst : 0xffffffff);
1369 return valid ? devInst : 0xffffffff;
1372 /***********************************************************************
1373 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1375 BOOL WINAPI SetupDiCreateDeviceInfoW(
1376 HDEVINFO DeviceInfoSet,
1378 CONST GUID *ClassGuid,
1379 PCWSTR DeviceDescription,
1381 DWORD CreationFlags,
1382 PSP_DEVINFO_DATA DeviceInfoData)
1384 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
1385 BOOL ret = FALSE, allocatedInstanceId = FALSE;
1386 LPCWSTR instanceId = NULL;
1388 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet, debugstr_w(DeviceName),
1389 debugstr_guid(ClassGuid), debugstr_w(DeviceDescription),
1390 hwndParent, CreationFlags, DeviceInfoData);
1394 SetLastError(ERROR_INVALID_DEVINST_NAME);
1397 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
1399 SetLastError(ERROR_INVALID_HANDLE);
1404 SetLastError(ERROR_INVALID_PARAMETER);
1407 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1409 SetLastError(ERROR_INVALID_HANDLE);
1412 if (!IsEqualGUID(&set->ClassGuid, &GUID_NULL) &&
1413 !IsEqualGUID(ClassGuid, &set->ClassGuid))
1415 SetLastError(ERROR_CLASS_MISMATCH);
1418 if ((CreationFlags & DICD_GENERATE_ID))
1420 if (strchrW(DeviceName, '\\'))
1421 SetLastError(ERROR_INVALID_DEVINST_NAME);
1424 static const WCHAR newDeviceFmt[] = {'R','O','O','T','\\','%','s',
1425 '\\','%','0','4','d',0};
1430 DWORD highestDevID = 0;
1431 struct DeviceInstance *devInst;
1433 LIST_FOR_EACH_ENTRY(devInst, &set->devices, struct DeviceInstance, entry)
1435 struct DeviceInfo *devInfo = (struct DeviceInfo *)devInst->data.Reserved;
1436 LPCWSTR devName = strrchrW(devInfo->instanceId, '\\');
1442 devName = devInfo->instanceId;
1443 id = SETUPDI_DevNameToDevID(devName);
1444 if (id != 0xffffffff && id > highestDevID)
1447 devId = highestDevID + 1;
1451 /* 17 == lstrlenW(L"Root\\") + lstrlenW("\\") + 1 + %d max size */
1452 instanceId = HeapAlloc(GetProcessHeap(), 0,
1453 (17 + lstrlenW(DeviceName)) * sizeof(WCHAR));
1456 sprintfW((LPWSTR)instanceId, newDeviceFmt, DeviceName,
1458 allocatedInstanceId = TRUE;
1467 struct DeviceInstance *devInst;
1470 instanceId = DeviceName;
1471 LIST_FOR_EACH_ENTRY(devInst, &set->devices, struct DeviceInstance, entry)
1473 struct DeviceInfo *devInfo = (struct DeviceInfo *)devInst->data.Reserved;
1475 if (!lstrcmpiW(DeviceName, devInfo->instanceId))
1477 SetLastError(ERROR_DEVINST_ALREADY_EXISTS);
1484 SP_DEVINFO_DATA *dev = NULL;
1486 ret = SETUPDI_AddDeviceToSet(set, ClassGuid, 0 /* FIXME: DevInst */,
1487 instanceId, TRUE, &dev);
1490 if (DeviceDescription)
1491 SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet,
1492 dev, SPDRP_DEVICEDESC, (const BYTE *)DeviceDescription,
1493 lstrlenW(DeviceDescription) * sizeof(WCHAR));
1496 if (DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA))
1498 SetLastError(ERROR_INVALID_USER_BUFFER);
1502 *DeviceInfoData = *dev;
1506 if (allocatedInstanceId)
1507 HeapFree(GetProcessHeap(), 0, (LPWSTR)instanceId);
1512 /***********************************************************************
1513 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1515 BOOL WINAPI SetupDiRegisterDeviceInfo(
1516 HDEVINFO DeviceInfoSet,
1517 PSP_DEVINFO_DATA DeviceInfoData,
1519 PSP_DETSIG_CMPPROC CompareProc,
1520 PVOID CompareContext,
1521 PSP_DEVINFO_DATA DupDeviceInfoData)
1523 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
1524 struct DeviceInfo *devInfo;
1526 TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet, DeviceInfoData, Flags,
1527 CompareProc, CompareContext, DupDeviceInfoData);
1529 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
1531 SetLastError(ERROR_INVALID_HANDLE);
1534 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1536 SetLastError(ERROR_INVALID_HANDLE);
1539 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
1540 || !DeviceInfoData->Reserved)
1542 SetLastError(ERROR_INVALID_PARAMETER);
1545 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1546 if (devInfo->set != set)
1548 SetLastError(ERROR_INVALID_PARAMETER);
1551 if (devInfo->phantom)
1553 devInfo->phantom = FALSE;
1554 RegDeleteValueW(devInfo->key, Phantom);
1559 /***********************************************************************
1560 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1562 BOOL WINAPI SetupDiEnumDeviceInfo(
1565 PSP_DEVINFO_DATA info)
1569 TRACE("%p %d %p\n", devinfo, index, info);
1573 SetLastError(ERROR_INVALID_PARAMETER);
1576 if (devinfo && devinfo != INVALID_HANDLE_VALUE)
1578 struct DeviceInfoSet *list = (struct DeviceInfoSet *)devinfo;
1579 if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC)
1581 if (index < list->cDevices)
1583 if (info->cbSize == sizeof(SP_DEVINFO_DATA))
1585 struct DeviceInstance *devInst;
1588 LIST_FOR_EACH_ENTRY(devInst, &list->devices,
1589 struct DeviceInstance, entry)
1593 *info = devInst->data;
1600 SetLastError(ERROR_INVALID_USER_BUFFER);
1603 SetLastError(ERROR_NO_MORE_ITEMS);
1606 SetLastError(ERROR_INVALID_HANDLE);
1609 SetLastError(ERROR_INVALID_HANDLE);
1613 /***********************************************************************
1614 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1616 BOOL WINAPI SetupDiGetDeviceInstanceIdA(
1617 HDEVINFO DeviceInfoSet,
1618 PSP_DEVINFO_DATA DeviceInfoData,
1619 PSTR DeviceInstanceId,
1620 DWORD DeviceInstanceIdSize,
1621 PDWORD RequiredSize)
1627 TRACE("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId,
1628 DeviceInstanceIdSize, RequiredSize);
1630 SetupDiGetDeviceInstanceIdW(DeviceInfoSet,
1635 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
1637 instanceId = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
1640 ret = SetupDiGetDeviceInstanceIdW(DeviceInfoSet,
1647 int len = WideCharToMultiByte(CP_ACP, 0, instanceId, -1,
1649 DeviceInstanceIdSize, NULL, NULL);
1655 if (len > DeviceInstanceIdSize)
1657 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1661 *RequiredSize = len;
1664 HeapFree(GetProcessHeap(), 0, instanceId);
1669 /***********************************************************************
1670 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1672 BOOL WINAPI SetupDiGetDeviceInstanceIdW(
1673 HDEVINFO DeviceInfoSet,
1674 PSP_DEVINFO_DATA DeviceInfoData,
1675 PWSTR DeviceInstanceId,
1676 DWORD DeviceInstanceIdSize,
1677 PDWORD RequiredSize)
1679 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
1680 struct DeviceInfo *devInfo;
1682 TRACE("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId,
1683 DeviceInstanceIdSize, RequiredSize);
1685 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
1687 SetLastError(ERROR_INVALID_HANDLE);
1690 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1692 SetLastError(ERROR_INVALID_HANDLE);
1695 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
1696 || !DeviceInfoData->Reserved)
1698 SetLastError(ERROR_INVALID_PARAMETER);
1701 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1702 if (devInfo->set != set)
1704 SetLastError(ERROR_INVALID_PARAMETER);
1707 TRACE("instance ID: %s\n", debugstr_w(devInfo->instanceId));
1708 if (DeviceInstanceIdSize < strlenW(devInfo->instanceId) + 1)
1710 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1712 *RequiredSize = lstrlenW(devInfo->instanceId) + 1;
1715 lstrcpyW(DeviceInstanceId, devInfo->instanceId);
1717 *RequiredSize = lstrlenW(devInfo->instanceId) + 1;
1721 /***********************************************************************
1722 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1724 BOOL WINAPI SetupDiGetActualSectionToInstallA(
1726 PCSTR InfSectionName,
1727 PSTR InfSectionWithExt,
1728 DWORD InfSectionWithExtSize,
1729 PDWORD RequiredSize,
1736 /***********************************************************************
1737 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
1739 BOOL WINAPI SetupDiGetActualSectionToInstallW(
1741 PCWSTR InfSectionName,
1742 PWSTR InfSectionWithExt,
1743 DWORD InfSectionWithExtSize,
1744 PDWORD RequiredSize,
1747 WCHAR szBuffer[MAX_PATH];
1750 LONG lLineCount = -1;
1752 lstrcpyW(szBuffer, InfSectionName);
1753 dwLength = lstrlenW(szBuffer);
1755 if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
1757 /* Test section name with '.NTx86' extension */
1758 lstrcpyW(&szBuffer[dwLength], NtPlatformExtension);
1759 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1761 if (lLineCount == -1)
1763 /* Test section name with '.NT' extension */
1764 lstrcpyW(&szBuffer[dwLength], NtExtension);
1765 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1770 /* Test section name with '.Win' extension */
1771 lstrcpyW(&szBuffer[dwLength], WinExtension);
1772 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1775 if (lLineCount == -1)
1777 /* Test section name without extension */
1778 szBuffer[dwLength] = 0;
1779 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1782 if (lLineCount == -1)
1784 SetLastError(ERROR_INVALID_PARAMETER);
1788 dwFullLength = lstrlenW(szBuffer);
1790 if (InfSectionWithExt != NULL && InfSectionWithExtSize != 0)
1792 if (InfSectionWithExtSize < (dwFullLength + 1))
1794 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1798 lstrcpyW(InfSectionWithExt, szBuffer);
1799 if (Extension != NULL)
1801 *Extension = (dwLength == dwFullLength) ? NULL : &InfSectionWithExt[dwLength];
1805 if (RequiredSize != NULL)
1807 *RequiredSize = dwFullLength + 1;
1813 /***********************************************************************
1814 * SetupDiGetClassDescriptionA (SETUPAPI.@)
1816 BOOL WINAPI SetupDiGetClassDescriptionA(
1817 const GUID* ClassGuid,
1818 PSTR ClassDescription,
1819 DWORD ClassDescriptionSize,
1820 PDWORD RequiredSize)
1822 return SetupDiGetClassDescriptionExA(ClassGuid, ClassDescription,
1823 ClassDescriptionSize,
1824 RequiredSize, NULL, NULL);
1827 /***********************************************************************
1828 * SetupDiGetClassDescriptionW (SETUPAPI.@)
1830 BOOL WINAPI SetupDiGetClassDescriptionW(
1831 const GUID* ClassGuid,
1832 PWSTR ClassDescription,
1833 DWORD ClassDescriptionSize,
1834 PDWORD RequiredSize)
1836 return SetupDiGetClassDescriptionExW(ClassGuid, ClassDescription,
1837 ClassDescriptionSize,
1838 RequiredSize, NULL, NULL);
1841 /***********************************************************************
1842 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
1844 BOOL WINAPI SetupDiGetClassDescriptionExA(
1845 const GUID* ClassGuid,
1846 PSTR ClassDescription,
1847 DWORD ClassDescriptionSize,
1848 PDWORD RequiredSize,
1856 hKey = SetupDiOpenClassRegKeyExA(ClassGuid,
1861 if (hKey == INVALID_HANDLE_VALUE)
1863 WARN("SetupDiOpenClassRegKeyExA() failed (Error %u)\n", GetLastError());
1867 dwLength = ClassDescriptionSize;
1868 ret = !RegQueryValueExA( hKey, NULL, NULL, NULL,
1869 (LPBYTE)ClassDescription, &dwLength );
1870 if (RequiredSize) *RequiredSize = dwLength;
1875 /***********************************************************************
1876 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
1878 BOOL WINAPI SetupDiGetClassDescriptionExW(
1879 const GUID* ClassGuid,
1880 PWSTR ClassDescription,
1881 DWORD ClassDescriptionSize,
1882 PDWORD RequiredSize,
1890 hKey = SetupDiOpenClassRegKeyExW(ClassGuid,
1895 if (hKey == INVALID_HANDLE_VALUE)
1897 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
1901 dwLength = ClassDescriptionSize * sizeof(WCHAR);
1902 ret = !RegQueryValueExW( hKey, NULL, NULL, NULL,
1903 (LPBYTE)ClassDescription, &dwLength );
1904 if (RequiredSize) *RequiredSize = dwLength / sizeof(WCHAR);
1909 /***********************************************************************
1910 * SetupDiGetClassDevsA (SETUPAPI.@)
1912 HDEVINFO WINAPI SetupDiGetClassDevsA(
1919 LPWSTR enumstrW = NULL;
1923 int len = MultiByteToWideChar(CP_ACP, 0, enumstr, -1, NULL, 0);
1924 enumstrW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1927 ret = INVALID_HANDLE_VALUE;
1930 MultiByteToWideChar(CP_ACP, 0, enumstr, -1, enumstrW, len);
1932 ret = SetupDiGetClassDevsExW(class, enumstrW, parent, flags, NULL, NULL,
1934 HeapFree(GetProcessHeap(), 0, enumstrW);
1940 /***********************************************************************
1941 * SetupDiGetClassDevsExA (SETUPAPI.@)
1943 HDEVINFO WINAPI SetupDiGetClassDevsExA(
1953 LPWSTR enumstrW = NULL, machineW = NULL;
1957 int len = MultiByteToWideChar(CP_ACP, 0, enumstr, -1, NULL, 0);
1958 enumstrW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1961 ret = INVALID_HANDLE_VALUE;
1964 MultiByteToWideChar(CP_ACP, 0, enumstr, -1, enumstrW, len);
1968 int len = MultiByteToWideChar(CP_ACP, 0, machine, -1, NULL, 0);
1969 machineW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1972 HeapFree(GetProcessHeap(), 0, enumstrW);
1973 ret = INVALID_HANDLE_VALUE;
1976 MultiByteToWideChar(CP_ACP, 0, machine, -1, machineW, len);
1978 ret = SetupDiGetClassDevsExW(class, enumstrW, parent, flags, deviceset,
1979 machineW, reserved);
1980 HeapFree(GetProcessHeap(), 0, enumstrW);
1981 HeapFree(GetProcessHeap(), 0, machineW);
1987 static void SETUPDI_AddDeviceInterfaces(SP_DEVINFO_DATA *dev, HKEY key,
1988 const GUID *interface)
1991 WCHAR subKeyName[MAX_PATH];
1992 LONG l = ERROR_SUCCESS;
1994 for (i = 0; !l; i++)
1996 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
1997 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2001 SP_DEVICE_INTERFACE_DATA *iface = NULL;
2003 if (*subKeyName == '#')
2005 /* The subkey name is the reference string, with a '#' prepended */
2006 SETUPDI_AddInterfaceInstance(dev, interface, subKeyName + 1,
2008 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2011 WCHAR symbolicLink[MAX_PATH];
2014 len = sizeof(symbolicLink);
2015 l = RegQueryValueExW(subKey, SymbolicLink, NULL, &dataType,
2016 (BYTE *)symbolicLink, &len);
2017 if (!l && dataType == REG_SZ)
2018 SETUPDI_SetInterfaceSymbolicLink(iface, symbolicLink);
2019 RegCloseKey(subKey);
2022 /* Allow enumeration to continue */
2026 /* FIXME: find and add all the device's interfaces to the device */
2029 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet,
2030 HKEY key, const GUID *interface, LPCWSTR enumstr)
2032 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2034 WCHAR subKeyName[MAX_PATH];
2036 HKEY enumKey = INVALID_HANDLE_VALUE;
2038 TRACE("%s\n", debugstr_w(enumstr));
2040 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
2042 for (i = 0; !l; i++)
2044 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2045 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2050 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2053 WCHAR deviceInst[MAX_PATH * 3];
2056 len = sizeof(deviceInst);
2057 l = RegQueryValueExW(subKey, DeviceInstance, NULL, &dataType,
2058 (BYTE *)deviceInst, &len);
2059 if (!l && dataType == REG_SZ)
2061 TRACE("found instance ID %s\n", debugstr_w(deviceInst));
2062 if (!enumstr || !lstrcmpiW(enumstr, deviceInst))
2066 l = RegOpenKeyExW(enumKey, deviceInst, 0, KEY_READ,
2070 WCHAR deviceClassStr[40];
2072 len = sizeof(deviceClassStr);
2073 l = RegQueryValueExW(deviceKey, ClassGUID, NULL,
2074 &dataType, (BYTE *)deviceClassStr, &len);
2075 if (!l && dataType == REG_SZ &&
2076 deviceClassStr[0] == '{' &&
2077 deviceClassStr[37] == '}')
2080 SP_DEVINFO_DATA *dev;
2082 deviceClassStr[37] = 0;
2083 UuidFromStringW(&deviceClassStr[1],
2085 if (SETUPDI_AddDeviceToSet(set, &deviceClass,
2086 0 /* FIXME: DevInst */, deviceInst,
2088 SETUPDI_AddDeviceInterfaces(dev, subKey,
2091 RegCloseKey(deviceKey);
2095 RegCloseKey(subKey);
2097 /* Allow enumeration to continue */
2101 if (enumKey != INVALID_HANDLE_VALUE)
2102 RegCloseKey(enumKey);
2105 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet,
2106 const GUID *interface, LPCWSTR enumstr, DWORD flags)
2108 HKEY interfacesKey = SetupDiOpenClassRegKeyExW(interface, KEY_READ,
2109 DIOCR_INTERFACE, NULL, NULL);
2111 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(interface),
2112 debugstr_w(enumstr), flags);
2114 if (interfacesKey != INVALID_HANDLE_VALUE)
2116 if (flags & DIGCF_ALLCLASSES)
2119 WCHAR interfaceGuidStr[40];
2120 LONG l = ERROR_SUCCESS;
2122 for (i = 0; !l; i++)
2124 len = sizeof(interfaceGuidStr) / sizeof(interfaceGuidStr[0]);
2125 l = RegEnumKeyExW(interfacesKey, i, interfaceGuidStr, &len,
2126 NULL, NULL, NULL, NULL);
2129 if (interfaceGuidStr[0] == '{' &&
2130 interfaceGuidStr[37] == '}')
2135 interfaceGuidStr[37] = 0;
2136 UuidFromStringW(&interfaceGuidStr[1], &interfaceGuid);
2137 l = RegOpenKeyExW(interfacesKey, interfaceGuidStr, 0,
2138 KEY_READ, &interfaceKey);
2141 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
2142 interfaceKey, &interfaceGuid, enumstr);
2143 RegCloseKey(interfaceKey);
2151 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2152 * interface's key, so just pass that long
2154 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
2155 interfacesKey, interface, enumstr);
2157 RegCloseKey(interfacesKey);
2161 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet *set,
2162 LPCWSTR enumerator, LPCWSTR deviceName, HKEY deviceKey,
2163 const GUID *class, DWORD flags)
2166 WCHAR deviceInstance[MAX_PATH];
2167 LONG l = ERROR_SUCCESS;
2169 TRACE("%s %s\n", debugstr_w(enumerator), debugstr_w(deviceName));
2171 for (i = 0; !l; i++)
2173 len = sizeof(deviceInstance) / sizeof(deviceInstance[0]);
2174 l = RegEnumKeyExW(deviceKey, i, deviceInstance, &len, NULL, NULL, NULL,
2180 l = RegOpenKeyExW(deviceKey, deviceInstance, 0, KEY_READ, &subKey);
2183 WCHAR classGuid[40];
2186 len = sizeof(classGuid);
2187 l = RegQueryValueExW(subKey, ClassGUID, NULL, &dataType,
2188 (BYTE *)classGuid, &len);
2189 if (!l && dataType == REG_SZ)
2191 if (classGuid[0] == '{' && classGuid[37] == '}')
2196 UuidFromStringW(&classGuid[1], &deviceClass);
2197 if ((flags & DIGCF_ALLCLASSES) ||
2198 IsEqualGUID(class, &deviceClass))
2200 static const WCHAR fmt[] =
2201 {'%','s','\\','%','s','\\','%','s',0};
2204 instanceId = HeapAlloc(GetProcessHeap(), 0,
2205 (lstrlenW(enumerator) + lstrlenW(deviceName) +
2206 lstrlenW(deviceInstance) + 3) * sizeof(WCHAR));
2209 sprintfW(instanceId, fmt, enumerator,
2210 deviceName, deviceInstance);
2211 SETUPDI_AddDeviceToSet(set, &deviceClass,
2212 0 /* FIXME: DevInst */, instanceId,
2214 HeapFree(GetProcessHeap(), 0, instanceId);
2219 RegCloseKey(subKey);
2221 /* Allow enumeration to continue */
2227 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet,
2228 LPCWSTR parent, HKEY key, const GUID *class, DWORD flags)
2230 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2232 WCHAR subKeyName[MAX_PATH];
2233 LONG l = ERROR_SUCCESS;
2235 TRACE("%s\n", debugstr_w(parent));
2237 for (i = 0; !l; i++)
2239 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2240 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2245 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2248 TRACE("%s\n", debugstr_w(subKeyName));
2249 SETUPDI_EnumerateMatchingDeviceInstances(set, parent,
2250 subKeyName, subKey, class, flags);
2251 RegCloseKey(subKey);
2253 /* Allow enumeration to continue */
2259 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet, const GUID *class,
2260 LPCWSTR enumstr, DWORD flags)
2265 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(class),
2266 debugstr_w(enumstr), flags);
2268 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
2270 if (enumKey != INVALID_HANDLE_VALUE)
2276 l = RegOpenKeyExW(enumKey, enumstr, 0, KEY_READ,
2280 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet, enumstr,
2281 enumStrKey, class, flags);
2282 RegCloseKey(enumStrKey);
2288 WCHAR subKeyName[MAX_PATH];
2291 for (i = 0; !l; i++)
2293 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2294 l = RegEnumKeyExW(enumKey, i, subKeyName, &len, NULL,
2300 l = RegOpenKeyExW(enumKey, subKeyName, 0, KEY_READ,
2304 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet,
2305 subKeyName, subKey, class, flags);
2306 RegCloseKey(subKey);
2308 /* Allow enumeration to continue */
2313 RegCloseKey(enumKey);
2317 /***********************************************************************
2318 * SetupDiGetClassDevsW (SETUPAPI.@)
2320 HDEVINFO WINAPI SetupDiGetClassDevsW(
2326 return SetupDiGetClassDevsExW(class, enumstr, parent, flags, NULL, NULL,
2330 /***********************************************************************
2331 * SetupDiGetClassDevsExW (SETUPAPI.@)
2333 HDEVINFO WINAPI SetupDiGetClassDevsExW(
2342 static const DWORD unsupportedFlags = DIGCF_DEFAULT | DIGCF_PRESENT |
2346 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2347 debugstr_w(enumstr), parent, flags, deviceset, debugstr_w(machine),
2350 if (!(flags & DIGCF_ALLCLASSES) && !class)
2352 SetLastError(ERROR_INVALID_PARAMETER);
2355 if (flags & unsupportedFlags)
2356 WARN("unsupported flags %08x\n", flags & unsupportedFlags);
2360 set = SetupDiCreateDeviceInfoListExW(class, parent, machine, reserved);
2364 FIXME("%s: unimplemented for remote machines\n",
2365 debugstr_w(machine));
2366 else if (flags & DIGCF_DEVICEINTERFACE)
2367 SETUPDI_EnumerateInterfaces(set, class, enumstr, flags);
2369 SETUPDI_EnumerateDevices(set, class, enumstr, flags);
2374 /***********************************************************************
2375 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2377 BOOL WINAPI SetupDiGetDeviceInfoListDetailA(
2378 HDEVINFO DeviceInfoSet,
2379 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData )
2381 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2383 TRACE("%p %p\n", DeviceInfoSet, DevInfoData);
2385 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2387 SetLastError(ERROR_INVALID_HANDLE);
2390 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2392 SetLastError(ERROR_INVALID_HANDLE);
2396 DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A))
2398 SetLastError(ERROR_INVALID_PARAMETER);
2401 DevInfoData->ClassGuid = set->ClassGuid;
2402 DevInfoData->RemoteMachineHandle = NULL;
2403 DevInfoData->RemoteMachineName[0] = '\0';
2407 /***********************************************************************
2408 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2410 BOOL WINAPI SetupDiGetDeviceInfoListDetailW(
2411 HDEVINFO DeviceInfoSet,
2412 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData )
2414 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2416 TRACE("%p %p\n", DeviceInfoSet, DevInfoData);
2418 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2420 SetLastError(ERROR_INVALID_HANDLE);
2423 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2425 SetLastError(ERROR_INVALID_HANDLE);
2429 DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W))
2431 SetLastError(ERROR_INVALID_PARAMETER);
2434 DevInfoData->ClassGuid = set->ClassGuid;
2435 DevInfoData->RemoteMachineHandle = NULL;
2436 DevInfoData->RemoteMachineName[0] = '\0';
2440 /***********************************************************************
2441 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2443 BOOL WINAPI SetupDiCreateDeviceInterfaceA(
2444 HDEVINFO DeviceInfoSet,
2445 PSP_DEVINFO_DATA DeviceInfoData,
2446 const GUID *InterfaceClassGuid,
2447 PCSTR ReferenceString,
2448 DWORD CreationFlags,
2449 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2452 LPWSTR ReferenceStringW = NULL;
2454 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
2455 debugstr_guid(InterfaceClassGuid), debugstr_a(ReferenceString),
2456 CreationFlags, DeviceInterfaceData);
2458 if (ReferenceString)
2460 ReferenceStringW = MultiByteToUnicode(ReferenceString, CP_ACP);
2461 if (ReferenceStringW == NULL) return FALSE;
2464 ret = SetupDiCreateDeviceInterfaceW(DeviceInfoSet, DeviceInfoData,
2465 InterfaceClassGuid, ReferenceStringW, CreationFlags,
2466 DeviceInterfaceData);
2468 MyFree(ReferenceStringW);
2473 /***********************************************************************
2474 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2476 BOOL WINAPI SetupDiCreateDeviceInterfaceW(
2477 HDEVINFO DeviceInfoSet,
2478 PSP_DEVINFO_DATA DeviceInfoData,
2479 const GUID *InterfaceClassGuid,
2480 PCWSTR ReferenceString,
2481 DWORD CreationFlags,
2482 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2484 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2485 struct DeviceInfo *devInfo;
2486 SP_DEVICE_INTERFACE_DATA *iface = NULL;
2489 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
2490 debugstr_guid(InterfaceClassGuid), debugstr_w(ReferenceString),
2491 CreationFlags, DeviceInterfaceData);
2493 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2495 SetLastError(ERROR_INVALID_HANDLE);
2498 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2500 SetLastError(ERROR_INVALID_HANDLE);
2503 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
2504 || !DeviceInfoData->Reserved)
2506 SetLastError(ERROR_INVALID_PARAMETER);
2509 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
2510 if (devInfo->set != set)
2512 SetLastError(ERROR_INVALID_PARAMETER);
2515 if (!InterfaceClassGuid)
2517 SetLastError(ERROR_INVALID_USER_BUFFER);
2520 if ((ret = SETUPDI_AddInterfaceInstance(DeviceInfoData, InterfaceClassGuid,
2521 ReferenceString, &iface)))
2523 if (DeviceInterfaceData)
2525 if (DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
2527 SetLastError(ERROR_INVALID_USER_BUFFER);
2531 *DeviceInterfaceData = *iface;
2537 /***********************************************************************
2538 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2540 HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyA(
2541 HDEVINFO DeviceInfoSet,
2542 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2546 PCSTR InfSectionName)
2549 PWSTR InfSectionNameW = NULL;
2551 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
2552 samDesired, InfHandle, InfSectionName);
2555 if (!InfSectionName)
2557 SetLastError(ERROR_INVALID_PARAMETER);
2558 return INVALID_HANDLE_VALUE;
2560 InfSectionNameW = MultiByteToUnicode(InfSectionName, CP_ACP);
2561 if (!InfSectionNameW)
2562 return INVALID_HANDLE_VALUE;
2564 key = SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet,
2565 DeviceInterfaceData, Reserved, samDesired, InfHandle,
2567 MyFree(InfSectionNameW);
2571 static PWSTR SETUPDI_GetInstancePath(struct InterfaceInfo *ifaceInfo)
2573 static const WCHAR hash[] = {'#',0};
2574 PWSTR instancePath = NULL;
2576 if (ifaceInfo->referenceString)
2578 instancePath = HeapAlloc(GetProcessHeap(), 0,
2579 (lstrlenW(ifaceInfo->referenceString) + 2) * sizeof(WCHAR));
2582 lstrcpyW(instancePath, hash);
2583 lstrcatW(instancePath, ifaceInfo->referenceString);
2586 SetLastError(ERROR_OUTOFMEMORY);
2590 instancePath = HeapAlloc(GetProcessHeap(), 0,
2591 (lstrlenW(hash) + 1) * sizeof(WCHAR));
2593 lstrcpyW(instancePath, hash);
2595 return instancePath;
2598 /***********************************************************************
2599 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2601 HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyW(
2602 HDEVINFO DeviceInfoSet,
2603 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2607 PCWSTR InfSectionName)
2609 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2610 HKEY key = INVALID_HANDLE_VALUE, interfacesKey;
2613 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
2614 samDesired, InfHandle, InfSectionName);
2616 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2617 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2619 SetLastError(ERROR_INVALID_HANDLE);
2620 return INVALID_HANDLE_VALUE;
2622 if (!DeviceInterfaceData ||
2623 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2624 !DeviceInterfaceData->Reserved)
2626 SetLastError(ERROR_INVALID_PARAMETER);
2627 return INVALID_HANDLE_VALUE;
2629 if (InfHandle && !InfSectionName)
2631 SetLastError(ERROR_INVALID_PARAMETER);
2632 return INVALID_HANDLE_VALUE;
2634 if (!(l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, DeviceClasses, 0, NULL, 0,
2635 samDesired, NULL, &interfacesKey, NULL)))
2638 WCHAR bracedGuidString[39];
2640 SETUPDI_GuidToString(&DeviceInterfaceData->InterfaceClassGuid,
2642 if (!(l = RegCreateKeyExW(interfacesKey, bracedGuidString, 0, NULL, 0,
2643 samDesired, NULL, &parent, NULL)))
2645 struct InterfaceInfo *ifaceInfo =
2646 (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2647 PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo);
2648 PWSTR interfKeyName = HeapAlloc(GetProcessHeap(), 0,
2649 (lstrlenW(ifaceInfo->symbolicLink) + 1) * sizeof(WCHAR));
2653 lstrcpyW(interfKeyName, ifaceInfo->symbolicLink);
2654 if (lstrlenW(ifaceInfo->symbolicLink) > 3)
2656 interfKeyName[0] = '#';
2657 interfKeyName[1] = '#';
2658 interfKeyName[3] = '#';
2660 ptr = strchrW(interfKeyName, '\\');
2663 l = RegCreateKeyExW(parent, interfKeyName, 0, NULL, 0,
2664 samDesired, NULL, &interfKey, NULL);
2667 struct DeviceInfo *devInfo =
2668 (struct DeviceInfo *)ifaceInfo->device->Reserved;
2670 l = RegSetValueExW(interfKey, DeviceInstance, 0, REG_SZ,
2671 (BYTE *)devInfo->instanceId,
2672 (lstrlenW(devInfo->instanceId) + 1) * sizeof(WCHAR));
2679 l = RegCreateKeyExW(interfKey, instancePath, 0, NULL, 0,
2680 samDesired, NULL, &key, NULL);
2684 key = INVALID_HANDLE_VALUE;
2687 FIXME("INF section installation unsupported\n");
2692 RegCloseKey(interfKey);
2696 HeapFree(GetProcessHeap(), 0, interfKeyName);
2697 HeapFree(GetProcessHeap(), 0, instancePath);
2698 RegCloseKey(parent);
2702 RegCloseKey(interfacesKey);
2709 /***********************************************************************
2710 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2712 BOOL WINAPI SetupDiDeleteDeviceInterfaceRegKey(
2713 HDEVINFO DeviceInfoSet,
2714 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2717 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2721 TRACE("%p %p %d\n", DeviceInfoSet, DeviceInterfaceData, Reserved);
2723 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2724 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2726 SetLastError(ERROR_INVALID_HANDLE);
2729 if (!DeviceInterfaceData ||
2730 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2731 !DeviceInterfaceData->Reserved)
2733 SetLastError(ERROR_INVALID_PARAMETER);
2736 parent = SetupDiOpenClassRegKeyExW(&DeviceInterfaceData->InterfaceClassGuid,
2737 KEY_ALL_ACCESS, DIOCR_INTERFACE, NULL, NULL);
2738 if (parent != INVALID_HANDLE_VALUE)
2740 struct InterfaceInfo *ifaceInfo =
2741 (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2742 PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo);
2746 LONG l = RegDeleteKeyW(parent, instancePath);
2752 HeapFree(GetProcessHeap(), 0, instancePath);
2754 RegCloseKey(parent);
2759 /***********************************************************************
2760 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2763 * DeviceInfoSet [I] Set of devices from which to enumerate
2765 * DeviceInfoData [I] (Optional) If specified, a specific device
2766 * instance from which to enumerate interfaces.
2767 * If it isn't specified, all interfaces for all
2768 * devices in the set are enumerated.
2769 * InterfaceClassGuid [I] The interface class to enumerate.
2770 * MemberIndex [I] An index of the interface instance to enumerate.
2771 * A caller should start with MemberIndex set to 0,
2772 * and continue until the function fails with
2773 * ERROR_NO_MORE_ITEMS.
2774 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2775 * member must be set to
2776 * sizeof(SP_DEVICE_INTERFACE_DATA).
2779 * Success: non-zero value.
2780 * Failure: FALSE. Call GetLastError() for more info.
2782 BOOL WINAPI SetupDiEnumDeviceInterfaces(
2783 HDEVINFO DeviceInfoSet,
2784 PSP_DEVINFO_DATA DeviceInfoData,
2785 CONST GUID * InterfaceClassGuid,
2787 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2789 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2792 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet, DeviceInfoData,
2793 debugstr_guid(InterfaceClassGuid), MemberIndex, DeviceInterfaceData);
2795 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2796 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2798 SetLastError(ERROR_INVALID_HANDLE);
2801 if (DeviceInfoData && (DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) ||
2802 !DeviceInfoData->Reserved))
2804 SetLastError(ERROR_INVALID_PARAMETER);
2807 if (!DeviceInterfaceData ||
2808 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
2810 SetLastError(ERROR_INVALID_PARAMETER);
2815 struct DeviceInfo *devInfo =
2816 (struct DeviceInfo *)DeviceInfoData->Reserved;
2817 struct InterfaceInstances *iface;
2819 if ((ret = SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface)))
2821 if (MemberIndex < iface->cInstances)
2822 *DeviceInterfaceData = iface->instances[MemberIndex];
2825 SetLastError(ERROR_NO_MORE_ITEMS);
2830 SetLastError(ERROR_NO_MORE_ITEMS);
2834 struct DeviceInstance *devInst;
2835 DWORD cEnumerated = 0;
2838 LIST_FOR_EACH_ENTRY(devInst, &set->devices, struct DeviceInstance, entry)
2840 struct DeviceInfo *devInfo = (struct DeviceInfo *)devInst->data.Reserved;
2841 struct InterfaceInstances *iface;
2843 if (found || cEnumerated >= MemberIndex + 1)
2845 if (SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface))
2847 if (cEnumerated + iface->cInstances < MemberIndex + 1)
2848 cEnumerated += iface->cInstances;
2851 DWORD instanceIndex = MemberIndex - cEnumerated;
2853 *DeviceInterfaceData = iface->instances[instanceIndex];
2854 cEnumerated += instanceIndex + 1;
2861 SetLastError(ERROR_NO_MORE_ITEMS);
2866 /***********************************************************************
2867 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2869 * Destroy a DeviceInfoList and free all used memory of the list.
2872 * devinfo [I] DeviceInfoList pointer to list to destroy
2875 * Success: non zero value.
2876 * Failure: zero value.
2878 BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
2882 TRACE("%p\n", devinfo);
2883 if (devinfo && devinfo != INVALID_HANDLE_VALUE)
2885 struct DeviceInfoSet *list = (struct DeviceInfoSet *)devinfo;
2887 if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC)
2889 struct DeviceInstance *devInst, *devInst2;
2891 LIST_FOR_EACH_ENTRY_SAFE(devInst, devInst2, &list->devices,
2892 struct DeviceInstance, entry)
2894 SETUPDI_FreeDeviceInfo( (struct DeviceInfo *)devInst->data.Reserved );
2895 list_remove(&devInst->entry);
2896 HeapFree(GetProcessHeap(), 0, devInst);
2898 HeapFree(GetProcessHeap(), 0, list);
2904 SetLastError(ERROR_INVALID_HANDLE);
2909 /***********************************************************************
2910 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2912 BOOL WINAPI SetupDiGetDeviceInterfaceDetailA(
2913 HDEVINFO DeviceInfoSet,
2914 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2915 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData,
2916 DWORD DeviceInterfaceDetailDataSize,
2917 PDWORD RequiredSize,
2918 PSP_DEVINFO_DATA DeviceInfoData)
2920 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2921 struct InterfaceInfo *info;
2922 DWORD bytesNeeded = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath)
2926 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet,
2927 DeviceInterfaceData, DeviceInterfaceDetailData,
2928 DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
2930 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2931 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2933 SetLastError(ERROR_INVALID_HANDLE);
2936 if (!DeviceInterfaceData ||
2937 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2938 !DeviceInterfaceData->Reserved)
2940 SetLastError(ERROR_INVALID_PARAMETER);
2943 if (DeviceInterfaceDetailData && (DeviceInterfaceDetailData->cbSize !=
2944 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath) + sizeof(char)))
2946 SetLastError(ERROR_INVALID_USER_BUFFER);
2949 if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
2951 SetLastError(ERROR_INVALID_USER_BUFFER);
2954 info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2955 if (info->symbolicLink)
2956 bytesNeeded += WideCharToMultiByte(CP_ACP, 0, info->symbolicLink, -1,
2957 NULL, 0, NULL, NULL);
2958 if (DeviceInterfaceDetailDataSize >= bytesNeeded)
2960 if (info->symbolicLink)
2961 WideCharToMultiByte(CP_ACP, 0, info->symbolicLink, -1,
2962 DeviceInterfaceDetailData->DevicePath,
2963 DeviceInterfaceDetailDataSize -
2964 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath),
2967 DeviceInterfaceDetailData->DevicePath[0] = '\0';
2968 if (DeviceInfoData && DeviceInfoData->cbSize == sizeof(SP_DEVINFO_DATA))
2969 *DeviceInfoData = *info->device;
2975 *RequiredSize = bytesNeeded;
2976 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2981 /***********************************************************************
2982 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2984 BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(
2985 HDEVINFO DeviceInfoSet,
2986 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2987 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData,
2988 DWORD DeviceInterfaceDetailDataSize,
2989 PDWORD RequiredSize,
2990 PSP_DEVINFO_DATA DeviceInfoData)
2992 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2993 struct InterfaceInfo *info;
2994 DWORD bytesNeeded = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath)
2995 + sizeof(WCHAR); /* include NULL terminator */
2998 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet,
2999 DeviceInterfaceData, DeviceInterfaceDetailData,
3000 DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
3002 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
3003 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3005 SetLastError(ERROR_INVALID_HANDLE);
3008 if (!DeviceInterfaceData ||
3009 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
3010 !DeviceInterfaceData->Reserved)
3012 SetLastError(ERROR_INVALID_PARAMETER);
3015 if (DeviceInterfaceDetailData && (DeviceInterfaceDetailData->cbSize <
3016 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR) ||
3017 DeviceInterfaceDetailData->cbSize > sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W)))
3019 SetLastError(ERROR_INVALID_USER_BUFFER);
3022 if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
3024 SetLastError(ERROR_INVALID_USER_BUFFER);
3027 info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
3028 if (info->symbolicLink)
3029 bytesNeeded += sizeof(WCHAR)*lstrlenW(info->symbolicLink);
3030 if (DeviceInterfaceDetailDataSize >= bytesNeeded)
3032 if (info->symbolicLink)
3033 lstrcpyW(DeviceInterfaceDetailData->DevicePath, info->symbolicLink);
3035 DeviceInterfaceDetailData->DevicePath[0] = '\0';
3036 if (DeviceInfoData && DeviceInfoData->cbSize == sizeof(SP_DEVINFO_DATA))
3037 *DeviceInfoData = *info->device;
3043 *RequiredSize = bytesNeeded;
3044 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3049 struct PropertyMapEntry
3056 static const struct PropertyMapEntry PropertyMap[] = {
3057 { REG_SZ, "DeviceDesc", DeviceDesc },
3058 { REG_MULTI_SZ, "HardwareId", HardwareId },
3059 { REG_MULTI_SZ, "CompatibleIDs", CompatibleIDs },
3060 { 0, NULL, NULL }, /* SPDRP_UNUSED0 */
3061 { REG_SZ, "Service", Service },
3062 { 0, NULL, NULL }, /* SPDRP_UNUSED1 */
3063 { 0, NULL, NULL }, /* SPDRP_UNUSED2 */
3064 { REG_SZ, "Class", Class },
3065 { REG_SZ, "ClassGUID", ClassGUID },
3066 { REG_SZ, "Driver", Driver },
3067 { REG_DWORD, "ConfigFlags", ConfigFlags },
3068 { REG_SZ, "Mfg", Mfg },
3069 { REG_SZ, "FriendlyName", FriendlyName },
3070 { REG_SZ, "LocationInformation", LocationInformation },
3071 { 0, NULL, NULL }, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3072 { REG_DWORD, "Capabilities", Capabilities },
3073 { REG_DWORD, "UINumber", UINumber },
3074 { REG_MULTI_SZ, "UpperFilters", UpperFilters },
3075 { REG_MULTI_SZ, "LowerFilters", LowerFilters },
3078 /***********************************************************************
3079 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3081 BOOL WINAPI SetupDiGetDeviceRegistryPropertyA(
3082 HDEVINFO DeviceInfoSet,
3083 PSP_DEVINFO_DATA DeviceInfoData,
3085 PDWORD PropertyRegDataType,
3086 PBYTE PropertyBuffer,
3087 DWORD PropertyBufferSize,
3088 PDWORD RequiredSize)
3091 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
3092 struct DeviceInfo *devInfo;
3094 TRACE("%04x %p %d %p %p %d %p\n", (DWORD)DeviceInfoSet, DeviceInfoData,
3095 Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize,
3098 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3100 SetLastError(ERROR_INVALID_HANDLE);
3103 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3105 SetLastError(ERROR_INVALID_HANDLE);
3108 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3109 || !DeviceInfoData->Reserved)
3111 SetLastError(ERROR_INVALID_PARAMETER);
3114 if (PropertyBufferSize && PropertyBuffer == NULL)
3116 SetLastError(ERROR_INVALID_DATA);
3119 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3120 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3121 && PropertyMap[Property].nameA)
3123 DWORD size = PropertyBufferSize;
3124 LONG l = RegQueryValueExA(devInfo->key, PropertyMap[Property].nameA,
3125 NULL, PropertyRegDataType, PropertyBuffer, &size);
3127 if (l == ERROR_MORE_DATA || !PropertyBufferSize)
3128 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3134 *RequiredSize = size;
3139 /***********************************************************************
3140 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3142 BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(
3143 HDEVINFO DeviceInfoSet,
3144 PSP_DEVINFO_DATA DeviceInfoData,
3146 PDWORD PropertyRegDataType,
3147 PBYTE PropertyBuffer,
3148 DWORD PropertyBufferSize,
3149 PDWORD RequiredSize)
3152 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
3153 struct DeviceInfo *devInfo;
3155 TRACE("%04x %p %d %p %p %d %p\n", (DWORD)DeviceInfoSet, DeviceInfoData,
3156 Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize,
3159 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3161 SetLastError(ERROR_INVALID_HANDLE);
3164 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3166 SetLastError(ERROR_INVALID_HANDLE);
3169 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3170 || !DeviceInfoData->Reserved)
3172 SetLastError(ERROR_INVALID_PARAMETER);
3175 if (PropertyBufferSize && PropertyBuffer == NULL)
3177 SetLastError(ERROR_INVALID_DATA);
3180 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3181 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3182 && PropertyMap[Property].nameW)
3184 DWORD size = PropertyBufferSize;
3185 LONG l = RegQueryValueExW(devInfo->key, PropertyMap[Property].nameW,
3186 NULL, PropertyRegDataType, PropertyBuffer, &size);
3188 if (l == ERROR_MORE_DATA || !PropertyBufferSize)
3189 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3195 *RequiredSize = size;
3200 /***********************************************************************
3201 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3203 BOOL WINAPI SetupDiSetDeviceRegistryPropertyA(
3204 HDEVINFO DeviceInfoSet,
3205 PSP_DEVINFO_DATA DeviceInfoData,
3207 const BYTE *PropertyBuffer,
3208 DWORD PropertyBufferSize)
3211 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
3212 struct DeviceInfo *devInfo;
3214 TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property,
3215 PropertyBuffer, PropertyBufferSize);
3217 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3219 SetLastError(ERROR_INVALID_HANDLE);
3222 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3224 SetLastError(ERROR_INVALID_HANDLE);
3227 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3228 || !DeviceInfoData->Reserved)
3230 SetLastError(ERROR_INVALID_PARAMETER);
3233 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3234 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3235 && PropertyMap[Property].nameA)
3237 LONG l = RegSetValueExA(devInfo->key, PropertyMap[Property].nameA, 0,
3238 PropertyMap[Property].regType, PropertyBuffer,
3239 PropertyBufferSize);
3248 /***********************************************************************
3249 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3251 BOOL WINAPI SetupDiSetDeviceRegistryPropertyW(
3252 HDEVINFO DeviceInfoSet,
3253 PSP_DEVINFO_DATA DeviceInfoData,
3255 const BYTE *PropertyBuffer,
3256 DWORD PropertyBufferSize)
3259 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
3260 struct DeviceInfo *devInfo;
3262 TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property,
3263 PropertyBuffer, PropertyBufferSize);
3265 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3267 SetLastError(ERROR_INVALID_HANDLE);
3270 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3272 SetLastError(ERROR_INVALID_HANDLE);
3275 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3276 || !DeviceInfoData->Reserved)
3278 SetLastError(ERROR_INVALID_PARAMETER);
3281 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3282 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3283 && PropertyMap[Property].nameW)
3285 LONG l = RegSetValueExW(devInfo->key, PropertyMap[Property].nameW, 0,
3286 PropertyMap[Property].regType, PropertyBuffer,
3287 PropertyBufferSize);
3296 /***********************************************************************
3297 * SetupDiInstallClassA (SETUPAPI.@)
3299 BOOL WINAPI SetupDiInstallClassA(
3305 UNICODE_STRING FileNameW;
3310 SetLastError(ERROR_INVALID_PARAMETER);
3313 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW, InfFileName))
3315 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
3319 Result = SetupDiInstallClassW(hwndParent, FileNameW.Buffer, Flags, FileQueue);
3321 RtlFreeUnicodeString(&FileNameW);
3326 static HKEY CreateClassKey(HINF hInf)
3328 static const WCHAR slash[] = { '\\',0 };
3329 WCHAR FullBuffer[MAX_PATH];
3330 WCHAR Buffer[MAX_PATH];
3334 if (!SetupGetLineTextW(NULL,
3342 return INVALID_HANDLE_VALUE;
3345 lstrcpyW(FullBuffer, ControlClass);
3346 lstrcatW(FullBuffer, slash);
3347 lstrcatW(FullBuffer, Buffer);
3349 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3355 if (!SetupGetLineTextW(NULL,
3363 return INVALID_HANDLE_VALUE;
3366 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,
3370 REG_OPTION_NON_VOLATILE,
3376 return INVALID_HANDLE_VALUE;
3381 if (RegSetValueExW(hClassKey,
3386 RequiredSize * sizeof(WCHAR)))
3388 RegCloseKey(hClassKey);
3389 RegDeleteKeyW(HKEY_LOCAL_MACHINE,
3391 return INVALID_HANDLE_VALUE;
3397 /***********************************************************************
3398 * SetupDiInstallClassW (SETUPAPI.@)
3400 BOOL WINAPI SetupDiInstallClassW(
3406 WCHAR SectionName[MAX_PATH];
3407 DWORD SectionNameLength = 0;
3409 BOOL bFileQueueCreated = FALSE;
3417 SetLastError(ERROR_INVALID_PARAMETER);
3420 if ((Flags & DI_NOVCP) && (FileQueue == NULL || FileQueue == INVALID_HANDLE_VALUE))
3422 SetLastError(ERROR_INVALID_PARAMETER);
3426 /* Open the .inf file */
3427 hInf = SetupOpenInfFileW(InfFileName,
3431 if (hInf == INVALID_HANDLE_VALUE)
3437 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3438 hClassKey = CreateClassKey(hInf);
3439 if (hClassKey == INVALID_HANDLE_VALUE)
3441 SetupCloseInfFile(hInf);
3446 /* Try to append a layout file */
3447 SetupOpenAppendInfFileW(NULL, hInf, NULL);
3449 /* Retrieve the actual section name */
3450 SetupDiGetActualSectionToInstallW(hInf,
3458 if (!(Flags & DI_NOVCP))
3460 FileQueue = SetupOpenFileQueue();
3461 if (FileQueue == INVALID_HANDLE_VALUE)
3463 SetupCloseInfFile(hInf);
3467 bFileQueueCreated = TRUE;
3472 SetupInstallFromInfSectionW(NULL,
3475 SPINST_COPYINF | SPINST_FILES | SPINST_REGISTRY,
3481 INVALID_HANDLE_VALUE,
3484 /* FIXME: More code! */
3486 if (bFileQueueCreated)
3487 SetupCloseFileQueue(FileQueue);
3489 SetupCloseInfFile(hInf);
3495 /***********************************************************************
3496 * SetupDiOpenClassRegKey (SETUPAPI.@)
3498 HKEY WINAPI SetupDiOpenClassRegKey(
3499 const GUID* ClassGuid,
3502 return SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
3503 DIOCR_INSTALLER, NULL, NULL);
3507 /***********************************************************************
3508 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3510 HKEY WINAPI SetupDiOpenClassRegKeyExA(
3511 const GUID* ClassGuid,
3517 PWSTR MachineNameW = NULL;
3524 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
3525 if (MachineNameW == NULL)
3526 return INVALID_HANDLE_VALUE;
3529 hKey = SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
3530 Flags, MachineNameW, Reserved);
3532 MyFree(MachineNameW);
3538 /***********************************************************************
3539 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3541 HKEY WINAPI SetupDiOpenClassRegKeyExW(
3542 const GUID* ClassGuid,
3553 if (MachineName != NULL)
3555 FIXME("Remote access not supported yet!\n");
3556 return INVALID_HANDLE_VALUE;
3559 if (Flags == DIOCR_INSTALLER)
3561 lpKeyName = ControlClass;
3563 else if (Flags == DIOCR_INTERFACE)
3565 lpKeyName = DeviceClasses;
3569 ERR("Invalid Flags parameter!\n");
3570 SetLastError(ERROR_INVALID_PARAMETER);
3571 return INVALID_HANDLE_VALUE;
3576 if ((l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3583 hClassesKey = INVALID_HANDLE_VALUE;
3589 WCHAR bracedGuidString[39];
3591 SETUPDI_GuidToString(ClassGuid, bracedGuidString);
3593 if (!(l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3599 if ((l = RegOpenKeyExW(hClassesKey,
3606 key = INVALID_HANDLE_VALUE;
3608 RegCloseKey(hClassesKey);
3613 key = INVALID_HANDLE_VALUE;
3619 /***********************************************************************
3620 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3622 BOOL WINAPI SetupDiOpenDeviceInterfaceW(
3623 HDEVINFO DeviceInfoSet,
3626 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
3628 FIXME("%p %s %08x %p\n",
3629 DeviceInfoSet, debugstr_w(DevicePath), OpenFlags, DeviceInterfaceData);
3633 /***********************************************************************
3634 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3636 BOOL WINAPI SetupDiOpenDeviceInterfaceA(
3637 HDEVINFO DeviceInfoSet,
3640 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
3642 FIXME("%p %s %08x %p\n", DeviceInfoSet,
3643 debugstr_a(DevicePath), OpenFlags, DeviceInterfaceData);
3647 /***********************************************************************
3648 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3650 BOOL WINAPI SetupDiSetClassInstallParamsA(
3651 HDEVINFO DeviceInfoSet,
3652 PSP_DEVINFO_DATA DeviceInfoData,
3653 PSP_CLASSINSTALL_HEADER ClassInstallParams,
3654 DWORD ClassInstallParamsSize)
3656 FIXME("%p %p %x %u\n",DeviceInfoSet, DeviceInfoData,
3657 ClassInstallParams->InstallFunction, ClassInstallParamsSize);
3661 /***********************************************************************
3662 * SetupDiCallClassInstaller (SETUPAPI.@)
3664 BOOL WINAPI SetupDiCallClassInstaller(
3665 DI_FUNCTION InstallFunction,
3666 HDEVINFO DeviceInfoSet,
3667 PSP_DEVINFO_DATA DeviceInfoData)
3669 FIXME("%d %p %p\n", InstallFunction, DeviceInfoSet, DeviceInfoData);
3673 /***********************************************************************
3674 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3676 BOOL WINAPI SetupDiGetDeviceInstallParamsA(
3677 HDEVINFO DeviceInfoSet,
3678 PSP_DEVINFO_DATA DeviceInfoData,
3679 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams)
3681 FIXME("%p %p %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3685 static HKEY SETUPDI_OpenDevKey(struct DeviceInfo *devInfo, REGSAM samDesired)
3687 HKEY enumKey, key = INVALID_HANDLE_VALUE;
3690 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
3691 NULL, &enumKey, NULL);
3694 RegOpenKeyExW(enumKey, devInfo->instanceId, 0, samDesired, &key);
3695 RegCloseKey(enumKey);
3700 static HKEY SETUPDI_OpenDrvKey(struct DeviceInfo *devInfo, REGSAM samDesired)
3702 static const WCHAR slash[] = { '\\',0 };
3703 WCHAR classKeyPath[MAX_PATH];
3704 HKEY classKey, key = INVALID_HANDLE_VALUE;
3707 lstrcpyW(classKeyPath, ControlClass);
3708 lstrcatW(classKeyPath, slash);
3709 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
3710 classKeyPath + lstrlenW(classKeyPath));
3711 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
3712 KEY_ALL_ACCESS, NULL, &classKey, NULL);
3715 static const WCHAR fmt[] = { '%','0','4','u',0 };
3718 sprintfW(devId, fmt, devInfo->devId);
3719 RegOpenKeyExW(classKey, devId, 0, samDesired, &key);
3720 RegCloseKey(classKey);
3725 /***********************************************************************
3726 * SetupDiOpenDevRegKey (SETUPAPI.@)
3728 HKEY WINAPI SetupDiOpenDevRegKey(
3729 HDEVINFO DeviceInfoSet,
3730 PSP_DEVINFO_DATA DeviceInfoData,
3736 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
3737 struct DeviceInfo *devInfo;
3738 HKEY key = INVALID_HANDLE_VALUE;
3740 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet, DeviceInfoData,
3741 Scope, HwProfile, KeyType, samDesired);
3743 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3745 SetLastError(ERROR_INVALID_HANDLE);
3746 return INVALID_HANDLE_VALUE;
3748 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3750 SetLastError(ERROR_INVALID_HANDLE);
3751 return INVALID_HANDLE_VALUE;
3753 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3754 || !DeviceInfoData->Reserved)
3756 SetLastError(ERROR_INVALID_PARAMETER);
3757 return INVALID_HANDLE_VALUE;
3759 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
3761 SetLastError(ERROR_INVALID_FLAGS);
3762 return INVALID_HANDLE_VALUE;
3764 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV)
3766 SetLastError(ERROR_INVALID_FLAGS);
3767 return INVALID_HANDLE_VALUE;
3769 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3770 if (devInfo->set != set)
3772 SetLastError(ERROR_INVALID_PARAMETER);
3773 return INVALID_HANDLE_VALUE;
3775 if (devInfo->phantom)
3777 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
3778 return INVALID_HANDLE_VALUE;
3780 if (Scope != DICS_FLAG_GLOBAL)
3781 FIXME("unimplemented for scope %d\n", Scope);
3785 key = SETUPDI_OpenDevKey(devInfo, samDesired);
3788 key = SETUPDI_OpenDrvKey(devInfo, samDesired);
3791 WARN("unknown KeyType %d\n", KeyType);
3796 static BOOL SETUPDI_DeleteDevKey(struct DeviceInfo *devInfo)
3802 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
3803 NULL, &enumKey, NULL);
3806 ret = RegDeleteTreeW(enumKey, devInfo->instanceId);
3807 RegCloseKey(enumKey);
3814 static BOOL SETUPDI_DeleteDrvKey(struct DeviceInfo *devInfo)
3816 static const WCHAR slash[] = { '\\',0 };
3817 WCHAR classKeyPath[MAX_PATH];
3822 lstrcpyW(classKeyPath, ControlClass);
3823 lstrcatW(classKeyPath, slash);
3824 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
3825 classKeyPath + lstrlenW(classKeyPath));
3826 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
3827 KEY_ALL_ACCESS, NULL, &classKey, NULL);
3830 static const WCHAR fmt[] = { '%','0','4','u',0 };
3833 sprintfW(devId, fmt, devInfo->devId);
3834 ret = RegDeleteTreeW(classKey, devId);
3835 RegCloseKey(classKey);
3842 /***********************************************************************
3843 * SetupDiOpenDevRegKey (SETUPAPI.@)
3845 BOOL WINAPI SetupDiDeleteDevRegKey(
3846 HDEVINFO DeviceInfoSet,
3847 PSP_DEVINFO_DATA DeviceInfoData,
3852 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
3853 struct DeviceInfo *devInfo;
3856 TRACE("%p %p %d %d %d\n", DeviceInfoSet, DeviceInfoData, Scope, HwProfile,
3859 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3861 SetLastError(ERROR_INVALID_HANDLE);
3864 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3866 SetLastError(ERROR_INVALID_HANDLE);
3869 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3870 || !DeviceInfoData->Reserved)
3872 SetLastError(ERROR_INVALID_PARAMETER);
3875 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
3877 SetLastError(ERROR_INVALID_FLAGS);
3880 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV && KeyType != DIREG_BOTH)
3882 SetLastError(ERROR_INVALID_FLAGS);
3885 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3886 if (devInfo->set != set)
3888 SetLastError(ERROR_INVALID_PARAMETER);
3891 if (devInfo->phantom)
3893 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
3896 if (Scope != DICS_FLAG_GLOBAL)
3897 FIXME("unimplemented for scope %d\n", Scope);
3901 ret = SETUPDI_DeleteDevKey(devInfo);
3904 ret = SETUPDI_DeleteDrvKey(devInfo);
3907 ret = SETUPDI_DeleteDevKey(devInfo);
3909 ret = SETUPDI_DeleteDrvKey(devInfo);
3912 WARN("unknown KeyType %d\n", KeyType);
3917 /***********************************************************************
3918 * CM_Get_Device_IDA (SETUPAPI.@)
3920 CONFIGRET WINAPI CM_Get_Device_IDA( DEVINST dnDevInst, PSTR Buffer,
3921 ULONG BufferLen, ULONG ulFlags)
3923 struct DeviceInfo *devInfo = GlobalLock((HANDLE)dnDevInst);
3925 TRACE("%x->%p, %p, %u %u\n", dnDevInst, devInfo, Buffer, BufferLen, ulFlags);
3928 return CR_NO_SUCH_DEVINST;
3930 WideCharToMultiByte(CP_ACP, 0, devInfo->instanceId, -1, Buffer, BufferLen, 0, 0);
3931 TRACE("Returning %s\n", debugstr_a(Buffer));
3935 /***********************************************************************
3936 * CM_Get_Device_IDW (SETUPAPI.@)
3938 CONFIGRET WINAPI CM_Get_Device_IDW( DEVINST dnDevInst, LPWSTR Buffer,
3939 ULONG BufferLen, ULONG ulFlags)
3941 struct DeviceInfo *devInfo = GlobalLock((HANDLE)dnDevInst);
3943 TRACE("%x->%p, %p, %u %u\n", dnDevInst, devInfo, Buffer, BufferLen, ulFlags);
3947 WARN("dev instance %d not found!\n", dnDevInst);
3948 return CR_NO_SUCH_DEVINST;
3951 lstrcpynW(Buffer, devInfo->instanceId, BufferLen);
3952 TRACE("Returning %s\n", debugstr_w(Buffer));
3953 GlobalUnlock((HANDLE)dnDevInst);
3959 /***********************************************************************
3960 * CM_Get_Device_ID_Size (SETUPAPI.@)
3962 CONFIGRET WINAPI CM_Get_Device_ID_Size( PULONG pulLen, DEVINST dnDevInst,
3965 struct DeviceInfo *ppdevInfo = GlobalLock((HANDLE)dnDevInst);
3967 TRACE("%x->%p, %p, %u\n", dnDevInst, ppdevInfo, pulLen, ulFlags);
3971 WARN("dev instance %d not found!\n", dnDevInst);
3972 return CR_NO_SUCH_DEVINST;
3975 *pulLen = lstrlenW(ppdevInfo->instanceId);
3976 GlobalUnlock((HANDLE)dnDevInst);