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 */
101 SP_DEVINFO_DATA *devices;
104 /* Pointed to by SP_DEVICE_INTERFACE_DATA's Reserved member */
107 LPWSTR referenceString;
109 PSP_DEVINFO_DATA device;
112 /* A device may have multiple instances of the same interface, so this holds
113 * each instance belonging to a particular interface.
115 struct InterfaceInstances
119 DWORD cInstancesAllocated;
120 SP_DEVICE_INTERFACE_DATA *instances;
124 /* Pointed to by SP_DEVINFO_DATA's Reserved member */
127 struct DeviceInfoSet *set;
132 struct list interfaces;
135 static void SETUPDI_GuidToString(const GUID *guid, LPWSTR guidStr)
137 static const WCHAR fmt[] = {'{','%','0','8','X','-','%','0','4','X','-',
138 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
139 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
142 sprintfW(guidStr, fmt, guid->Data1, guid->Data2, guid->Data3,
143 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
144 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
147 static void SETUPDI_FreeInterfaceInstances(struct InterfaceInstances *instances)
151 for (i = 0; i < instances->cInstances; i++)
153 struct InterfaceInfo *ifaceInfo =
154 (struct InterfaceInfo *)instances->instances[i].Reserved;
156 if (ifaceInfo->device && ifaceInfo->device->Reserved)
158 struct DeviceInfo *devInfo =
159 (struct DeviceInfo *)ifaceInfo->device->Reserved;
161 if (devInfo->phantom)
162 SetupDiDeleteDeviceInterfaceRegKey(devInfo->set,
163 &instances->instances[i], 0);
165 HeapFree(GetProcessHeap(), 0, ifaceInfo->referenceString);
166 HeapFree(GetProcessHeap(), 0, ifaceInfo->symbolicLink);
168 HeapFree(GetProcessHeap(), 0, instances->instances);
171 /* Finds the interface with interface class InterfaceClassGuid in the device.
172 * Returns TRUE if found, and updates *interface to point to device's
173 * interfaces member where the given interface was found.
174 * Returns FALSE if not found.
176 static BOOL SETUPDI_FindInterface(const struct DeviceInfo *devInfo,
177 const GUID *InterfaceClassGuid, struct InterfaceInstances **interface)
180 struct InterfaceInstances *iface;
182 TRACE("%s\n", debugstr_guid(InterfaceClassGuid));
184 LIST_FOR_EACH_ENTRY(iface, &devInfo->interfaces, struct InterfaceInstances,
187 if (IsEqualGUID(&iface->guid, InterfaceClassGuid))
194 TRACE("returning %d (%p)\n", found, found ? *interface : NULL);
198 /* Finds the interface instance with reference string ReferenceString in the
199 * interface instance map. Returns TRUE if found, and updates instanceIndex to
200 * the index of the interface instance's instances member
201 * where the given instance was found. Returns FALSE if not found.
203 static BOOL SETUPDI_FindInterfaceInstance(
204 const struct InterfaceInstances *instances,
205 LPCWSTR ReferenceString, DWORD *instanceIndex)
210 TRACE("%s\n", debugstr_w(ReferenceString));
212 for (i = 0; !found && i < instances->cInstances; i++)
214 SP_DEVICE_INTERFACE_DATA *ifaceData = &instances->instances[i];
215 struct InterfaceInfo *ifaceInfo =
216 (struct InterfaceInfo *)ifaceData->Reserved;
218 if (!ReferenceString && !ifaceInfo->referenceString)
223 else if (ReferenceString && ifaceInfo->referenceString &&
224 !lstrcmpiW(ifaceInfo->referenceString, ReferenceString))
230 TRACE("returning %d (%d)\n", found, found ? *instanceIndex : 0);
234 static LPWSTR SETUPDI_CreateSymbolicLinkPath(LPCWSTR instanceId,
235 const GUID *InterfaceClassGuid, LPCWSTR ReferenceString)
237 static const WCHAR fmt[] = {'\\','\\','?','\\','%','s','#','%','s',0};
242 SETUPDI_GuidToString(InterfaceClassGuid, guidStr);
243 /* omit length of format specifiers, but include NULL terminator: */
244 len = lstrlenW(fmt) - 4 + 1;
245 len += lstrlenW(instanceId) + lstrlenW(guidStr);
248 /* space for a hash between string and reference string: */
249 len += lstrlenW(ReferenceString) + 1;
251 ret = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
254 int printed = sprintfW(ret, fmt, instanceId, guidStr);
257 /* replace '\\' with '#' after the "\\\\?\\" beginning */
258 for (ptr = strchrW(ret + 4, '\\'); ptr; ptr = strchrW(ptr + 1, '\\'))
262 ret[printed - 1] = '\\';
263 lstrcpyW(ret + printed, ReferenceString);
269 /* Adds an interface with the given interface class and reference string to
270 * the device, if it doesn't already exist in the device. If iface is not
271 * NULL, returns a pointer to the newly added (or already existing) interface.
273 static BOOL SETUPDI_AddInterfaceInstance(PSP_DEVINFO_DATA DeviceInfoData,
274 const GUID *InterfaceClassGuid, LPCWSTR ReferenceString,
275 SP_DEVICE_INTERFACE_DATA **ifaceData)
277 struct DeviceInfo *devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
278 BOOL newInterface = FALSE, ret;
279 struct InterfaceInstances *iface = NULL;
281 TRACE("%p %s %s %p\n", devInfo, debugstr_guid(InterfaceClassGuid),
282 debugstr_w(ReferenceString), iface);
284 if (!(ret = SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface)))
286 iface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
287 sizeof(struct InterfaceInstances));
290 list_add_tail(&devInfo->interfaces, &iface->entry);
296 DWORD instanceIndex = 0;
298 if (!(ret = SETUPDI_FindInterfaceInstance(iface, ReferenceString,
301 SP_DEVICE_INTERFACE_DATA *instance = NULL;
303 if (!iface->cInstancesAllocated)
305 iface->instances = HeapAlloc(GetProcessHeap(), 0,
306 sizeof(SP_DEVICE_INTERFACE_DATA));
307 if (iface->instances)
308 instance = &iface->instances[iface->cInstancesAllocated++];
310 else if (iface->cInstances == iface->cInstancesAllocated)
312 iface->instances = HeapReAlloc(GetProcessHeap(), 0,
314 (iface->cInstancesAllocated + 1) *
315 sizeof(SP_DEVICE_INTERFACE_DATA));
316 if (iface->instances)
317 instance = &iface->instances[iface->cInstancesAllocated++];
320 instance = &iface->instances[iface->cInstances];
323 struct InterfaceInfo *ifaceInfo = HeapAlloc(GetProcessHeap(),
324 0, sizeof(struct InterfaceInfo));
329 ifaceInfo->device = DeviceInfoData;
330 ifaceInfo->symbolicLink = SETUPDI_CreateSymbolicLinkPath(
331 devInfo->instanceId, InterfaceClassGuid,
335 ifaceInfo->referenceString =
336 HeapAlloc(GetProcessHeap(), 0,
337 (lstrlenW(ReferenceString) + 1) *
339 if (ifaceInfo->referenceString)
340 lstrcpyW(ifaceInfo->referenceString,
346 ifaceInfo->referenceString = NULL;
353 sizeof(SP_DEVICE_INTERFACE_DATA);
354 memcpy(&instance->InterfaceClassGuid,
355 InterfaceClassGuid, sizeof(GUID));
356 instance->Flags = SPINT_ACTIVE; /* FIXME */
357 instance->Reserved = (ULONG_PTR)ifaceInfo;
359 memcpy(&iface->guid, InterfaceClassGuid,
361 key = SetupDiCreateDeviceInterfaceRegKeyW(devInfo->set,
362 instance, 0, KEY_WRITE, NULL, NULL);
363 if (key != INVALID_HANDLE_VALUE)
365 RegSetValueExW(key, SymbolicLink, 0, REG_SZ,
366 (BYTE *)ifaceInfo->symbolicLink,
367 lstrlenW(ifaceInfo->symbolicLink) *
372 *ifaceData = instance;
375 HeapFree(GetProcessHeap(), 0, ifaceInfo);
382 *ifaceData = &iface->instances[instanceIndex];
387 TRACE("returning %d\n", ret);
391 static BOOL SETUPDI_SetInterfaceSymbolicLink(SP_DEVICE_INTERFACE_DATA *iface,
392 LPCWSTR symbolicLink)
394 struct InterfaceInfo *info = (struct InterfaceInfo *)iface->Reserved;
399 HeapFree(GetProcessHeap(), 0, info->symbolicLink);
400 info->symbolicLink = HeapAlloc(GetProcessHeap(), 0,
401 (lstrlenW(symbolicLink) + 1) * sizeof(WCHAR));
402 if (info->symbolicLink)
404 lstrcpyW(info->symbolicLink, symbolicLink);
411 static HKEY SETUPDI_CreateDevKey(struct DeviceInfo *devInfo)
413 HKEY enumKey, key = INVALID_HANDLE_VALUE;
416 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
417 NULL, &enumKey, NULL);
420 RegCreateKeyExW(enumKey, devInfo->instanceId, 0, NULL, 0,
421 KEY_READ | KEY_WRITE, NULL, &key, NULL);
422 RegCloseKey(enumKey);
427 static HKEY SETUPDI_CreateDrvKey(struct DeviceInfo *devInfo)
429 static const WCHAR slash[] = { '\\',0 };
430 WCHAR classKeyPath[MAX_PATH];
431 HKEY classKey, key = INVALID_HANDLE_VALUE;
434 lstrcpyW(classKeyPath, ControlClass);
435 lstrcatW(classKeyPath, slash);
436 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
437 classKeyPath + lstrlenW(classKeyPath));
438 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
439 KEY_ALL_ACCESS, NULL, &classKey, NULL);
442 static const WCHAR fmt[] = { '%','0','4','u',0 };
445 sprintfW(devId, fmt, devInfo->devId);
446 RegCreateKeyExW(classKey, devId, 0, NULL, 0, KEY_READ | KEY_WRITE,
448 RegCloseKey(classKey);
453 static struct DeviceInfo *SETUPDI_AllocateDeviceInfo(struct DeviceInfoSet *set,
454 DWORD devId, LPCWSTR instanceId, BOOL phantom)
456 struct DeviceInfo *devInfo = HeapAlloc(GetProcessHeap(), 0,
457 sizeof(struct DeviceInfo));
462 devInfo->devId = devId;
463 devInfo->instanceId = HeapAlloc(GetProcessHeap(), 0,
464 (lstrlenW(instanceId) + 1) * sizeof(WCHAR));
465 if (devInfo->instanceId)
467 devInfo->key = INVALID_HANDLE_VALUE;
468 devInfo->phantom = phantom;
469 lstrcpyW(devInfo->instanceId, instanceId);
470 struprW(devInfo->instanceId);
471 devInfo->key = SETUPDI_CreateDevKey(devInfo);
472 if (devInfo->key != INVALID_HANDLE_VALUE)
475 RegSetValueExW(devInfo->key, Phantom, 0, REG_DWORD,
476 (LPBYTE)&phantom, sizeof(phantom));
478 list_init(&devInfo->interfaces);
482 HeapFree(GetProcessHeap(), 0, devInfo);
489 static void SETUPDI_FreeDeviceInfo(struct DeviceInfo *devInfo)
491 struct InterfaceInstances *iface, *next;
493 if (devInfo->key != INVALID_HANDLE_VALUE)
494 RegCloseKey(devInfo->key);
495 if (devInfo->phantom)
500 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0,
501 KEY_ALL_ACCESS, NULL, &enumKey, NULL);
504 RegDeleteTreeW(enumKey, devInfo->instanceId);
505 RegCloseKey(enumKey);
508 HeapFree(GetProcessHeap(), 0, devInfo->instanceId);
509 LIST_FOR_EACH_ENTRY_SAFE(iface, next, &devInfo->interfaces,
510 struct InterfaceInstances, entry)
512 list_remove(&iface->entry);
513 SETUPDI_FreeInterfaceInstances(iface);
514 HeapFree(GetProcessHeap(), 0, iface);
516 HeapFree(GetProcessHeap(), 0, devInfo);
519 /* Adds a device with GUID guid and identifer devInst to set. Allocates a
520 * struct DeviceInfo, and points the returned device info's Reserved member
521 * to it. "Phantom" devices are deleted from the registry when closed.
522 * Returns a pointer to the newly allocated device info.
524 static BOOL SETUPDI_AddDeviceToSet(struct DeviceInfoSet *set,
529 SP_DEVINFO_DATA **dev)
532 struct DeviceInfo *devInfo = SETUPDI_AllocateDeviceInfo(set, set->cDevices,
533 instanceId, phantom);
535 TRACE("%p, %s, %d, %s, %d\n", set, debugstr_guid(guid), devInst,
536 debugstr_w(instanceId), phantom);
541 set->devices = HeapReAlloc(GetProcessHeap(), 0, set->devices,
542 (set->cDevices + 1) * sizeof(SP_DEVINFO_DATA));
544 set->devices = HeapAlloc(GetProcessHeap(), 0,
545 sizeof(SP_DEVINFO_DATA));
548 WCHAR classGuidStr[39];
549 SP_DEVINFO_DATA *DeviceInfoData = &set->devices[set->cDevices++];
551 DeviceInfoData->cbSize = sizeof(SP_DEVINFO_DATA);
552 memcpy(&DeviceInfoData->ClassGuid, guid, sizeof(GUID));
553 DeviceInfoData->DevInst = devInst;
554 DeviceInfoData->Reserved = (ULONG_PTR)devInfo;
555 SETUPDI_GuidToString(guid, classGuidStr);
556 SetupDiSetDeviceRegistryPropertyW((HDEVINFO)set,
557 DeviceInfoData, SPDRP_CLASSGUID, (const BYTE *)classGuidStr,
558 lstrlenW(classGuidStr) * sizeof(WCHAR));
560 *dev = DeviceInfoData;
565 HeapFree(GetProcessHeap(), 0, devInfo);
566 SetLastError(ERROR_OUTOFMEMORY);
572 /***********************************************************************
573 * SetupDiBuildClassInfoList (SETUPAPI.@)
575 * Returns a list of setup class GUIDs that identify the classes
576 * that are installed on a local machine.
579 * Flags [I] control exclusion of classes from the list.
580 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
581 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
582 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
588 BOOL WINAPI SetupDiBuildClassInfoList(
590 LPGUID ClassGuidList,
591 DWORD ClassGuidListSize,
595 return SetupDiBuildClassInfoListExW(Flags, ClassGuidList,
596 ClassGuidListSize, RequiredSize,
600 /***********************************************************************
601 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
603 * Returns a list of setup class GUIDs that identify the classes
604 * that are installed on a local or remote macine.
607 * Flags [I] control exclusion of classes from the list.
608 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
609 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
610 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
611 * MachineName [I] name of a remote machine.
612 * Reserved [I] must be NULL.
618 BOOL WINAPI SetupDiBuildClassInfoListExA(
620 LPGUID ClassGuidList,
621 DWORD ClassGuidListSize,
626 LPWSTR MachineNameW = NULL;
633 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
634 if (MachineNameW == NULL) return FALSE;
637 bResult = SetupDiBuildClassInfoListExW(Flags, ClassGuidList,
638 ClassGuidListSize, RequiredSize,
639 MachineNameW, Reserved);
641 MyFree(MachineNameW);
646 /***********************************************************************
647 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
649 * Returns a list of setup class GUIDs that identify the classes
650 * that are installed on a local or remote macine.
653 * Flags [I] control exclusion of classes from the list.
654 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
655 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
656 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
657 * MachineName [I] name of a remote machine.
658 * Reserved [I] must be NULL.
664 BOOL WINAPI SetupDiBuildClassInfoListExW(
666 LPGUID ClassGuidList,
667 DWORD ClassGuidListSize,
678 DWORD dwGuidListIndex = 0;
682 if (RequiredSize != NULL)
685 hClassesKey = SetupDiOpenClassRegKeyExW(NULL,
690 if (hClassesKey == INVALID_HANDLE_VALUE)
695 for (dwIndex = 0; ; dwIndex++)
698 lError = RegEnumKeyExW(hClassesKey,
706 TRACE("RegEnumKeyExW() returns %d\n", lError);
707 if (lError == ERROR_SUCCESS || lError == ERROR_MORE_DATA)
709 TRACE("Key name: %p\n", szKeyName);
711 if (RegOpenKeyExW(hClassesKey,
717 RegCloseKey(hClassesKey);
721 if (!RegQueryValueExW(hClassKey,
728 TRACE("'NoUseClass' value found!\n");
729 RegCloseKey(hClassKey);
733 if ((Flags & DIBCI_NOINSTALLCLASS) &&
734 (!RegQueryValueExW(hClassKey,
741 TRACE("'NoInstallClass' value found!\n");
742 RegCloseKey(hClassKey);
746 if ((Flags & DIBCI_NODISPLAYCLASS) &&
747 (!RegQueryValueExW(hClassKey,
754 TRACE("'NoDisplayClass' value found!\n");
755 RegCloseKey(hClassKey);
759 RegCloseKey(hClassKey);
761 TRACE("Guid: %p\n", szKeyName);
762 if (dwGuidListIndex < ClassGuidListSize)
764 if (szKeyName[0] == '{' && szKeyName[37] == '}')
768 TRACE("Guid: %p\n", &szKeyName[1]);
770 UuidFromStringW(&szKeyName[1],
771 &ClassGuidList[dwGuidListIndex]);
777 if (lError != ERROR_SUCCESS)
781 RegCloseKey(hClassesKey);
783 if (RequiredSize != NULL)
784 *RequiredSize = dwGuidListIndex;
786 if (ClassGuidListSize < dwGuidListIndex)
788 SetLastError(ERROR_INSUFFICIENT_BUFFER);
795 /***********************************************************************
796 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
798 BOOL WINAPI SetupDiClassGuidsFromNameA(
800 LPGUID ClassGuidList,
801 DWORD ClassGuidListSize,
804 return SetupDiClassGuidsFromNameExA(ClassName, ClassGuidList,
805 ClassGuidListSize, RequiredSize,
809 /***********************************************************************
810 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
812 BOOL WINAPI SetupDiClassGuidsFromNameW(
814 LPGUID ClassGuidList,
815 DWORD ClassGuidListSize,
818 return SetupDiClassGuidsFromNameExW(ClassName, ClassGuidList,
819 ClassGuidListSize, RequiredSize,
823 /***********************************************************************
824 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
826 BOOL WINAPI SetupDiClassGuidsFromNameExA(
828 LPGUID ClassGuidList,
829 DWORD ClassGuidListSize,
834 LPWSTR ClassNameW = NULL;
835 LPWSTR MachineNameW = NULL;
838 ClassNameW = MultiByteToUnicode(ClassName, CP_ACP);
839 if (ClassNameW == NULL)
844 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
845 if (MachineNameW == NULL)
852 bResult = SetupDiClassGuidsFromNameExW(ClassNameW, ClassGuidList,
853 ClassGuidListSize, RequiredSize,
854 MachineNameW, Reserved);
856 MyFree(MachineNameW);
862 /***********************************************************************
863 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
865 BOOL WINAPI SetupDiClassGuidsFromNameExW(
867 LPGUID ClassGuidList,
868 DWORD ClassGuidListSize,
874 WCHAR szClassName[256];
880 DWORD dwGuidListIndex = 0;
882 if (RequiredSize != NULL)
885 hClassesKey = SetupDiOpenClassRegKeyExW(NULL,
890 if (hClassesKey == INVALID_HANDLE_VALUE)
895 for (dwIndex = 0; ; dwIndex++)
898 lError = RegEnumKeyExW(hClassesKey,
906 TRACE("RegEnumKeyExW() returns %d\n", lError);
907 if (lError == ERROR_SUCCESS || lError == ERROR_MORE_DATA)
909 TRACE("Key name: %p\n", szKeyName);
911 if (RegOpenKeyExW(hClassesKey,
917 RegCloseKey(hClassesKey);
921 dwLength = 256 * sizeof(WCHAR);
922 if (!RegQueryValueExW(hClassKey,
929 TRACE("Class name: %p\n", szClassName);
931 if (strcmpiW(szClassName, ClassName) == 0)
933 TRACE("Found matching class name\n");
935 TRACE("Guid: %p\n", szKeyName);
936 if (dwGuidListIndex < ClassGuidListSize)
938 if (szKeyName[0] == '{' && szKeyName[37] == '}')
942 TRACE("Guid: %p\n", &szKeyName[1]);
944 UuidFromStringW(&szKeyName[1],
945 &ClassGuidList[dwGuidListIndex]);
952 RegCloseKey(hClassKey);
955 if (lError != ERROR_SUCCESS)
959 RegCloseKey(hClassesKey);
961 if (RequiredSize != NULL)
962 *RequiredSize = dwGuidListIndex;
964 if (ClassGuidListSize < dwGuidListIndex)
966 SetLastError(ERROR_INSUFFICIENT_BUFFER);
973 /***********************************************************************
974 * SetupDiClassNameFromGuidA (SETUPAPI.@)
976 BOOL WINAPI SetupDiClassNameFromGuidA(
977 const GUID* ClassGuid,
982 return SetupDiClassNameFromGuidExA(ClassGuid, ClassName,
983 ClassNameSize, RequiredSize,
987 /***********************************************************************
988 * SetupDiClassNameFromGuidW (SETUPAPI.@)
990 BOOL WINAPI SetupDiClassNameFromGuidW(
991 const GUID* ClassGuid,
996 return SetupDiClassNameFromGuidExW(ClassGuid, ClassName,
997 ClassNameSize, RequiredSize,
1001 /***********************************************************************
1002 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1004 BOOL WINAPI SetupDiClassNameFromGuidExA(
1005 const GUID* ClassGuid,
1007 DWORD ClassNameSize,
1008 PDWORD RequiredSize,
1012 WCHAR ClassNameW[MAX_CLASS_NAME_LEN];
1013 LPWSTR MachineNameW = NULL;
1017 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
1018 ret = SetupDiClassNameFromGuidExW(ClassGuid, ClassNameW, MAX_CLASS_NAME_LEN,
1019 NULL, MachineNameW, Reserved);
1022 int len = WideCharToMultiByte(CP_ACP, 0, ClassNameW, -1, ClassName,
1023 ClassNameSize, NULL, NULL);
1025 if (!ClassNameSize && RequiredSize)
1026 *RequiredSize = len;
1028 MyFree(MachineNameW);
1032 /***********************************************************************
1033 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1035 BOOL WINAPI SetupDiClassNameFromGuidExW(
1036 const GUID* ClassGuid,
1038 DWORD ClassNameSize,
1039 PDWORD RequiredSize,
1046 hKey = SetupDiOpenClassRegKeyExW(ClassGuid,
1051 if (hKey == INVALID_HANDLE_VALUE)
1056 if (RequiredSize != NULL)
1059 if (RegQueryValueExW(hKey,
1070 *RequiredSize = dwLength / sizeof(WCHAR);
1073 dwLength = ClassNameSize * sizeof(WCHAR);
1074 if (RegQueryValueExW(hKey,
1090 /***********************************************************************
1091 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1094 SetupDiCreateDeviceInfoList(const GUID *ClassGuid,
1097 return SetupDiCreateDeviceInfoListExW(ClassGuid, hwndParent, NULL, NULL);
1100 /***********************************************************************
1101 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1104 SetupDiCreateDeviceInfoListExA(const GUID *ClassGuid,
1109 LPWSTR MachineNameW = NULL;
1116 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
1117 if (MachineNameW == NULL)
1118 return (HDEVINFO)INVALID_HANDLE_VALUE;
1121 hDevInfo = SetupDiCreateDeviceInfoListExW(ClassGuid, hwndParent,
1122 MachineNameW, Reserved);
1124 MyFree(MachineNameW);
1129 /***********************************************************************
1130 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1132 * Create an empty DeviceInfoSet list.
1135 * ClassGuid [I] if not NULL only devices with GUID ClcassGuid are associated
1137 * hwndParent [I] hwnd needed for interface related actions.
1138 * MachineName [I] name of machine to create emtpy DeviceInfoSet list, if NULL
1139 * local registry will be used.
1140 * Reserved [I] must be NULL
1143 * Success: empty list.
1144 * Failure: INVALID_HANDLE_VALUE.
1147 SetupDiCreateDeviceInfoListExW(const GUID *ClassGuid,
1152 struct DeviceInfoSet *list = NULL;
1153 DWORD size = sizeof(struct DeviceInfoSet);
1155 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid), hwndParent,
1156 debugstr_w(MachineName), Reserved);
1158 if (MachineName != NULL)
1160 FIXME("remote support is not implemented\n");
1161 SetLastError(ERROR_INVALID_MACHINENAME);
1162 return (HDEVINFO)INVALID_HANDLE_VALUE;
1165 if (Reserved != NULL)
1167 SetLastError(ERROR_INVALID_PARAMETER);
1168 return (HDEVINFO)INVALID_HANDLE_VALUE;
1171 list = HeapAlloc(GetProcessHeap(), 0, size);
1174 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1175 return (HDEVINFO)INVALID_HANDLE_VALUE;
1178 list->magic = SETUP_DEVICE_INFO_SET_MAGIC;
1179 list->hwndParent = hwndParent;
1180 memcpy(&list->ClassGuid,
1181 ClassGuid ? ClassGuid : &GUID_NULL,
1182 sizeof(list->ClassGuid));
1184 list->devices = NULL;
1186 return (HDEVINFO)list;
1189 /***********************************************************************
1190 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1192 HKEY WINAPI SetupDiCreateDevRegKeyA(
1193 HDEVINFO DeviceInfoSet,
1194 PSP_DEVINFO_DATA DeviceInfoData,
1199 PCSTR InfSectionName)
1201 PWSTR InfSectionNameW = NULL;
1204 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet, DeviceInfoData, Scope,
1205 HwProfile, KeyType, InfHandle, debugstr_a(InfSectionName));
1209 if (!InfSectionName)
1211 SetLastError(ERROR_INVALID_PARAMETER);
1212 return INVALID_HANDLE_VALUE;
1216 InfSectionNameW = MultiByteToUnicode(InfSectionName, CP_ACP);
1217 if (InfSectionNameW == NULL) return INVALID_HANDLE_VALUE;
1220 key = SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, Scope,
1221 HwProfile, KeyType, InfHandle, InfSectionNameW);
1222 MyFree(InfSectionNameW);
1226 /***********************************************************************
1227 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1229 HKEY WINAPI SetupDiCreateDevRegKeyW(
1230 HDEVINFO DeviceInfoSet,
1231 PSP_DEVINFO_DATA DeviceInfoData,
1236 PCWSTR InfSectionName)
1238 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
1239 struct DeviceInfo *devInfo;
1240 HKEY key = INVALID_HANDLE_VALUE;
1242 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet, DeviceInfoData, Scope,
1243 HwProfile, KeyType, InfHandle, debugstr_w(InfSectionName));
1245 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE)
1247 SetLastError(ERROR_INVALID_HANDLE);
1248 return INVALID_HANDLE_VALUE;
1250 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1252 SetLastError(ERROR_INVALID_HANDLE);
1253 return INVALID_HANDLE_VALUE;
1255 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
1256 || !DeviceInfoData->Reserved)
1258 SetLastError(ERROR_INVALID_PARAMETER);
1259 return INVALID_HANDLE_VALUE;
1261 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1262 if (devInfo->set != set)
1264 SetLastError(ERROR_INVALID_PARAMETER);
1265 return INVALID_HANDLE_VALUE;
1267 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
1269 SetLastError(ERROR_INVALID_FLAGS);
1270 return INVALID_HANDLE_VALUE;
1272 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV)
1274 SetLastError(ERROR_INVALID_FLAGS);
1275 return INVALID_HANDLE_VALUE;
1277 if (devInfo->phantom)
1279 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
1280 return INVALID_HANDLE_VALUE;
1282 if (Scope != DICS_FLAG_GLOBAL)
1283 FIXME("unimplemented for scope %d\n", Scope);
1287 key = SETUPDI_CreateDevKey(devInfo);
1290 key = SETUPDI_CreateDrvKey(devInfo);
1293 WARN("unknown KeyType %d\n", KeyType);
1296 SetupInstallFromInfSectionW(NULL, InfHandle, InfSectionName, SPINST_ALL,
1297 NULL, NULL, SP_COPY_NEWER_ONLY, NULL, NULL, DeviceInfoSet,
1302 /***********************************************************************
1303 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1305 BOOL WINAPI SetupDiCreateDeviceInfoA(
1306 HDEVINFO DeviceInfoSet,
1308 CONST GUID *ClassGuid,
1309 PCSTR DeviceDescription,
1311 DWORD CreationFlags,
1312 PSP_DEVINFO_DATA DeviceInfoData)
1315 LPWSTR DeviceNameW = NULL;
1316 LPWSTR DeviceDescriptionW = NULL;
1320 DeviceNameW = MultiByteToUnicode(DeviceName, CP_ACP);
1321 if (DeviceNameW == NULL) return FALSE;
1323 if (DeviceDescription)
1325 DeviceDescriptionW = MultiByteToUnicode(DeviceDescription, CP_ACP);
1326 if (DeviceDescriptionW == NULL)
1328 MyFree(DeviceNameW);
1333 ret = SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceNameW, ClassGuid, DeviceDescriptionW,
1334 hwndParent, CreationFlags, DeviceInfoData);
1336 MyFree(DeviceNameW);
1337 MyFree(DeviceDescriptionW);
1342 static DWORD SETUPDI_DevNameToDevID(LPCWSTR devName)
1345 DWORD devNameLen = lstrlenW(devName), devInst = 0;
1348 TRACE("%s\n", debugstr_w(devName));
1349 for (ptr = devName; valid && *ptr && ptr - devName < devNameLen; )
1354 devInst |= *ptr - '0';
1360 TRACE("%d\n", valid ? devInst : 0xffffffff);
1361 return valid ? devInst : 0xffffffff;
1364 /***********************************************************************
1365 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1367 BOOL WINAPI SetupDiCreateDeviceInfoW(
1368 HDEVINFO DeviceInfoSet,
1370 CONST GUID *ClassGuid,
1371 PCWSTR DeviceDescription,
1373 DWORD CreationFlags,
1374 PSP_DEVINFO_DATA DeviceInfoData)
1376 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
1377 BOOL ret = FALSE, allocatedInstanceId = FALSE;
1378 LPCWSTR instanceId = NULL;
1380 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet, debugstr_w(DeviceName),
1381 debugstr_guid(ClassGuid), debugstr_w(DeviceDescription),
1382 hwndParent, CreationFlags, DeviceInfoData);
1386 SetLastError(ERROR_INVALID_DEVINST_NAME);
1389 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE)
1391 SetLastError(ERROR_INVALID_HANDLE);
1396 SetLastError(ERROR_INVALID_PARAMETER);
1399 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1401 SetLastError(ERROR_INVALID_HANDLE);
1404 if (!IsEqualGUID(&set->ClassGuid, &GUID_NULL) &&
1405 !IsEqualGUID(ClassGuid, &set->ClassGuid))
1407 SetLastError(ERROR_CLASS_MISMATCH);
1410 if ((CreationFlags & DICD_GENERATE_ID))
1412 if (strchrW(DeviceName, '\\'))
1413 SetLastError(ERROR_INVALID_DEVINST_NAME);
1416 static const WCHAR newDeviceFmt[] = {'R','O','O','T','\\','%','s',
1417 '\\','%','0','4','d',0};
1422 DWORD i, highestDevID = 0;
1424 for (i = 0; i < set->cDevices; i++)
1426 struct DeviceInfo *devInfo =
1427 (struct DeviceInfo *)set->devices[i].Reserved;
1428 LPCWSTR devName = strrchrW(devInfo->instanceId, '\\');
1434 devName = devInfo->instanceId;
1435 id = SETUPDI_DevNameToDevID(devName);
1436 if (id != 0xffffffff && id > highestDevID)
1439 devId = highestDevID + 1;
1443 /* 17 == lstrlenW(L"Root\\") + lstrlenW("\\") + 1 + %d max size */
1444 instanceId = HeapAlloc(GetProcessHeap(), 0,
1445 (17 + lstrlenW(DeviceName)) * sizeof(WCHAR));
1448 sprintfW((LPWSTR)instanceId, newDeviceFmt, DeviceName,
1450 allocatedInstanceId = TRUE;
1462 instanceId = DeviceName;
1463 for (i = 0; ret && i < set->cDevices; i++)
1465 struct DeviceInfo *devInfo =
1466 (struct DeviceInfo *)set->devices[i].Reserved;
1468 if (!lstrcmpiW(DeviceName, devInfo->instanceId))
1470 SetLastError(ERROR_DEVINST_ALREADY_EXISTS);
1477 SP_DEVINFO_DATA *dev = NULL;
1479 ret = SETUPDI_AddDeviceToSet(set, ClassGuid, 0 /* FIXME: DevInst */,
1480 instanceId, TRUE, &dev);
1483 if (DeviceDescription)
1484 SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet,
1485 dev, SPDRP_DEVICEDESC, (const BYTE *)DeviceDescription,
1486 lstrlenW(DeviceDescription) * sizeof(WCHAR));
1489 if (DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA))
1491 SetLastError(ERROR_INVALID_USER_BUFFER);
1495 memcpy(DeviceInfoData, dev, sizeof(SP_DEVINFO_DATA));
1499 if (allocatedInstanceId)
1500 HeapFree(GetProcessHeap(), 0, (LPWSTR)instanceId);
1505 /***********************************************************************
1506 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1508 BOOL WINAPI SetupDiRegisterDeviceInfo(
1509 HDEVINFO DeviceInfoSet,
1510 PSP_DEVINFO_DATA DeviceInfoData,
1512 PSP_DETSIG_CMPPROC CompareProc,
1513 PVOID CompareContext,
1514 PSP_DEVINFO_DATA DupDeviceInfoData)
1516 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
1517 struct DeviceInfo *devInfo;
1519 TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet, DeviceInfoData, Flags,
1520 CompareProc, CompareContext, DupDeviceInfoData);
1522 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE)
1524 SetLastError(ERROR_INVALID_HANDLE);
1527 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1529 SetLastError(ERROR_INVALID_HANDLE);
1532 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
1533 || !DeviceInfoData->Reserved)
1535 SetLastError(ERROR_INVALID_PARAMETER);
1538 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1539 if (devInfo->set != set)
1541 SetLastError(ERROR_INVALID_PARAMETER);
1544 if (devInfo->phantom)
1546 devInfo->phantom = FALSE;
1547 RegDeleteValueW(devInfo->key, Phantom);
1552 /***********************************************************************
1553 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1555 BOOL WINAPI SetupDiEnumDeviceInfo(
1558 PSP_DEVINFO_DATA info)
1562 TRACE("%p %d %p\n", devinfo, index, info);
1566 SetLastError(ERROR_INVALID_PARAMETER);
1569 if (devinfo && devinfo != (HDEVINFO)INVALID_HANDLE_VALUE)
1571 struct DeviceInfoSet *list = (struct DeviceInfoSet *)devinfo;
1572 if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC)
1574 if (index < list->cDevices)
1576 if (info->cbSize == sizeof(SP_DEVINFO_DATA))
1578 memcpy(info, &list->devices[index], info->cbSize);
1582 SetLastError(ERROR_INVALID_USER_BUFFER);
1585 SetLastError(ERROR_NO_MORE_ITEMS);
1588 SetLastError(ERROR_INVALID_HANDLE);
1591 SetLastError(ERROR_INVALID_HANDLE);
1595 /***********************************************************************
1596 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1598 BOOL WINAPI SetupDiGetDeviceInstanceIdA(
1599 HDEVINFO DeviceInfoSet,
1600 PSP_DEVINFO_DATA DeviceInfoData,
1601 PSTR DeviceInstanceId,
1602 DWORD DeviceInstanceIdSize,
1603 PDWORD RequiredSize)
1609 TRACE("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId,
1610 DeviceInstanceIdSize, RequiredSize);
1612 SetupDiGetDeviceInstanceIdW(DeviceInfoSet,
1617 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
1619 instanceId = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
1622 ret = SetupDiGetDeviceInstanceIdW(DeviceInfoSet,
1629 int len = WideCharToMultiByte(CP_ACP, 0, instanceId, -1,
1631 DeviceInstanceIdSize, NULL, NULL);
1637 if (len > DeviceInstanceIdSize)
1639 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1643 *RequiredSize = len;
1646 HeapFree(GetProcessHeap(), 0, instanceId);
1651 /***********************************************************************
1652 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1654 BOOL WINAPI SetupDiGetDeviceInstanceIdW(
1655 HDEVINFO DeviceInfoSet,
1656 PSP_DEVINFO_DATA DeviceInfoData,
1657 PWSTR DeviceInstanceId,
1658 DWORD DeviceInstanceIdSize,
1659 PDWORD RequiredSize)
1661 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
1662 struct DeviceInfo *devInfo;
1664 TRACE("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId,
1665 DeviceInstanceIdSize, RequiredSize);
1667 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
1669 SetLastError(ERROR_INVALID_HANDLE);
1672 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1674 SetLastError(ERROR_INVALID_HANDLE);
1677 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
1678 || !DeviceInfoData->Reserved)
1680 SetLastError(ERROR_INVALID_PARAMETER);
1683 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1684 if (devInfo->set != set)
1686 SetLastError(ERROR_INVALID_PARAMETER);
1689 TRACE("instance ID: %s\n", debugstr_w(devInfo->instanceId));
1690 if (DeviceInstanceIdSize < lstrlenW(devInfo->instanceId) + 1)
1692 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1694 *RequiredSize = lstrlenW(devInfo->instanceId) + 1;
1697 lstrcpyW(DeviceInstanceId, devInfo->instanceId);
1699 *RequiredSize = lstrlenW(devInfo->instanceId) + 1;
1703 /***********************************************************************
1704 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1706 BOOL WINAPI SetupDiGetActualSectionToInstallA(
1708 PCSTR InfSectionName,
1709 PSTR InfSectionWithExt,
1710 DWORD InfSectionWithExtSize,
1711 PDWORD RequiredSize,
1718 /***********************************************************************
1719 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
1721 BOOL WINAPI SetupDiGetActualSectionToInstallW(
1723 PCWSTR InfSectionName,
1724 PWSTR InfSectionWithExt,
1725 DWORD InfSectionWithExtSize,
1726 PDWORD RequiredSize,
1729 WCHAR szBuffer[MAX_PATH];
1732 LONG lLineCount = -1;
1734 lstrcpyW(szBuffer, InfSectionName);
1735 dwLength = lstrlenW(szBuffer);
1737 if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
1739 /* Test section name with '.NTx86' extension */
1740 lstrcpyW(&szBuffer[dwLength], NtPlatformExtension);
1741 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1743 if (lLineCount == -1)
1745 /* Test section name with '.NT' extension */
1746 lstrcpyW(&szBuffer[dwLength], NtExtension);
1747 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1752 /* Test section name with '.Win' extension */
1753 lstrcpyW(&szBuffer[dwLength], WinExtension);
1754 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1757 if (lLineCount == -1)
1759 /* Test section name without extension */
1760 szBuffer[dwLength] = 0;
1761 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1764 if (lLineCount == -1)
1766 SetLastError(ERROR_INVALID_PARAMETER);
1770 dwFullLength = lstrlenW(szBuffer);
1772 if (InfSectionWithExt != NULL && InfSectionWithExtSize != 0)
1774 if (InfSectionWithExtSize < (dwFullLength + 1))
1776 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1780 lstrcpyW(InfSectionWithExt, szBuffer);
1781 if (Extension != NULL)
1783 *Extension = (dwLength == dwFullLength) ? NULL : &InfSectionWithExt[dwLength];
1787 if (RequiredSize != NULL)
1789 *RequiredSize = dwFullLength + 1;
1795 /***********************************************************************
1796 * SetupDiGetClassDescriptionA (SETUPAPI.@)
1798 BOOL WINAPI SetupDiGetClassDescriptionA(
1799 const GUID* ClassGuid,
1800 PSTR ClassDescription,
1801 DWORD ClassDescriptionSize,
1802 PDWORD RequiredSize)
1804 return SetupDiGetClassDescriptionExA(ClassGuid, ClassDescription,
1805 ClassDescriptionSize,
1806 RequiredSize, NULL, NULL);
1809 /***********************************************************************
1810 * SetupDiGetClassDescriptionW (SETUPAPI.@)
1812 BOOL WINAPI SetupDiGetClassDescriptionW(
1813 const GUID* ClassGuid,
1814 PWSTR ClassDescription,
1815 DWORD ClassDescriptionSize,
1816 PDWORD RequiredSize)
1818 return SetupDiGetClassDescriptionExW(ClassGuid, ClassDescription,
1819 ClassDescriptionSize,
1820 RequiredSize, NULL, NULL);
1823 /***********************************************************************
1824 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
1826 BOOL WINAPI SetupDiGetClassDescriptionExA(
1827 const GUID* ClassGuid,
1828 PSTR ClassDescription,
1829 DWORD ClassDescriptionSize,
1830 PDWORD RequiredSize,
1838 hKey = SetupDiOpenClassRegKeyExA(ClassGuid,
1843 if (hKey == INVALID_HANDLE_VALUE)
1845 WARN("SetupDiOpenClassRegKeyExA() failed (Error %u)\n", GetLastError());
1849 dwLength = ClassDescriptionSize;
1850 ret = !RegQueryValueExA( hKey, NULL, NULL, NULL,
1851 (LPBYTE)ClassDescription, &dwLength );
1852 if (RequiredSize) *RequiredSize = dwLength;
1857 /***********************************************************************
1858 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
1860 BOOL WINAPI SetupDiGetClassDescriptionExW(
1861 const GUID* ClassGuid,
1862 PWSTR ClassDescription,
1863 DWORD ClassDescriptionSize,
1864 PDWORD RequiredSize,
1872 hKey = SetupDiOpenClassRegKeyExW(ClassGuid,
1877 if (hKey == INVALID_HANDLE_VALUE)
1879 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
1883 dwLength = ClassDescriptionSize * sizeof(WCHAR);
1884 ret = !RegQueryValueExW( hKey, NULL, NULL, NULL,
1885 (LPBYTE)ClassDescription, &dwLength );
1886 if (RequiredSize) *RequiredSize = dwLength / sizeof(WCHAR);
1891 /***********************************************************************
1892 * SetupDiGetClassDevsA (SETUPAPI.@)
1894 HDEVINFO WINAPI SetupDiGetClassDevsA(
1901 LPWSTR enumstrW = NULL;
1905 int len = MultiByteToWideChar(CP_ACP, 0, enumstr, -1, NULL, 0);
1906 enumstrW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1909 ret = (HDEVINFO)INVALID_HANDLE_VALUE;
1912 MultiByteToWideChar(CP_ACP, 0, enumstr, -1, enumstrW, len);
1914 ret = SetupDiGetClassDevsExW(class, enumstrW, parent, flags, NULL, NULL,
1916 HeapFree(GetProcessHeap(), 0, enumstrW);
1922 /***********************************************************************
1923 * SetupDiGetClassDevsExA (SETUPAPI.@)
1925 HDEVINFO WINAPI SetupDiGetClassDevsExA(
1935 LPWSTR enumstrW = NULL, machineW = NULL;
1939 int len = MultiByteToWideChar(CP_ACP, 0, enumstr, -1, NULL, 0);
1940 enumstrW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1943 ret = (HDEVINFO)INVALID_HANDLE_VALUE;
1946 MultiByteToWideChar(CP_ACP, 0, enumstr, -1, enumstrW, len);
1950 int len = MultiByteToWideChar(CP_ACP, 0, machine, -1, NULL, 0);
1951 machineW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1954 HeapFree(GetProcessHeap(), 0, enumstrW);
1955 ret = (HDEVINFO)INVALID_HANDLE_VALUE;
1958 MultiByteToWideChar(CP_ACP, 0, machine, -1, machineW, len);
1960 ret = SetupDiGetClassDevsExW(class, enumstrW, parent, flags, deviceset,
1961 machineW, reserved);
1962 HeapFree(GetProcessHeap(), 0, enumstrW);
1963 HeapFree(GetProcessHeap(), 0, machineW);
1969 static void SETUPDI_AddDeviceInterfaces(SP_DEVINFO_DATA *dev, HKEY key,
1970 const GUID *interface)
1973 WCHAR subKeyName[MAX_PATH];
1974 LONG l = ERROR_SUCCESS;
1976 for (i = 0; !l; i++)
1978 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
1979 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
1983 SP_DEVICE_INTERFACE_DATA *iface = NULL;
1985 /* The subkey name is the reference string, with a '#' prepended */
1986 SETUPDI_AddInterfaceInstance(dev, interface, subKeyName + 1,
1988 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
1991 WCHAR symbolicLink[MAX_PATH];
1994 len = sizeof(symbolicLink);
1995 l = RegQueryValueExW(subKey, SymbolicLink, NULL, &dataType,
1996 (BYTE *)symbolicLink, &len);
1997 if (!l && dataType == REG_SZ)
1998 SETUPDI_SetInterfaceSymbolicLink(iface, symbolicLink);
1999 RegCloseKey(subKey);
2001 /* Allow enumeration to continue */
2005 /* FIXME: find and add all the device's interfaces to the device */
2008 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet,
2009 HKEY key, const GUID *interface, LPCWSTR enumstr)
2011 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2013 WCHAR subKeyName[MAX_PATH];
2015 HKEY enumKey = INVALID_HANDLE_VALUE;
2017 TRACE("%s\n", debugstr_w(enumstr));
2019 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
2021 for (i = 0; !l; i++)
2023 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2024 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2029 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2032 WCHAR deviceInst[MAX_PATH * 3];
2035 len = sizeof(deviceInst);
2036 l = RegQueryValueExW(subKey, DeviceInstance, NULL, &dataType,
2037 (BYTE *)deviceInst, &len);
2038 if (!l && dataType == REG_SZ)
2040 TRACE("found instance ID %s\n", debugstr_w(deviceInst));
2041 if (!enumstr || !lstrcmpiW(enumstr, deviceInst))
2045 l = RegOpenKeyExW(enumKey, deviceInst, 0, KEY_READ,
2049 WCHAR deviceClassStr[40];
2051 len = sizeof(deviceClassStr);
2052 l = RegQueryValueExW(deviceKey, ClassGUID, NULL,
2053 &dataType, (BYTE *)deviceClassStr, &len);
2054 if (!l && dataType == REG_SZ &&
2055 deviceClassStr[0] == '{' &&
2056 deviceClassStr[37] == '}')
2059 SP_DEVINFO_DATA *dev;
2061 deviceClassStr[37] = 0;
2062 UuidFromStringW(&deviceClassStr[1],
2064 if (SETUPDI_AddDeviceToSet(set, &deviceClass,
2065 0 /* FIXME: DevInst */, deviceInst,
2067 SETUPDI_AddDeviceInterfaces(dev, subKey,
2070 RegCloseKey(deviceKey);
2074 RegCloseKey(subKey);
2076 /* Allow enumeration to continue */
2080 if (enumKey != INVALID_HANDLE_VALUE)
2081 RegCloseKey(enumKey);
2084 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet,
2085 const GUID *interface, LPCWSTR enumstr, DWORD flags)
2087 HKEY interfacesKey = SetupDiOpenClassRegKeyExW(interface, KEY_READ,
2088 DIOCR_INTERFACE, NULL, NULL);
2090 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(interface),
2091 debugstr_w(enumstr), flags);
2093 if (interfacesKey != INVALID_HANDLE_VALUE)
2095 if (flags & DIGCF_ALLCLASSES)
2098 WCHAR interfaceGuidStr[40];
2099 LONG l = ERROR_SUCCESS;
2101 for (i = 0; !l; i++)
2103 len = sizeof(interfaceGuidStr) / sizeof(interfaceGuidStr[0]);
2104 l = RegEnumKeyExW(interfacesKey, i, interfaceGuidStr, &len,
2105 NULL, NULL, NULL, NULL);
2108 if (interfaceGuidStr[0] == '{' &&
2109 interfaceGuidStr[37] == '}')
2114 interfaceGuidStr[37] = 0;
2115 UuidFromStringW(&interfaceGuidStr[1], &interfaceGuid);
2116 l = RegOpenKeyExW(interfacesKey, interfaceGuidStr, 0,
2117 KEY_READ, &interfaceKey);
2120 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
2121 interfaceKey, &interfaceGuid, enumstr);
2122 RegCloseKey(interfaceKey);
2130 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2131 * interface's key, so just pass that long
2133 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
2134 interfacesKey, interface, enumstr);
2136 RegCloseKey(interfacesKey);
2140 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet *set,
2141 LPCWSTR enumerator, LPCWSTR deviceName, HKEY deviceKey,
2142 const GUID *class, DWORD flags)
2145 WCHAR deviceInstance[MAX_PATH];
2146 LONG l = ERROR_SUCCESS;
2148 TRACE("%s %s\n", debugstr_w(enumerator), debugstr_w(deviceName));
2150 for (i = 0; !l; i++)
2152 len = sizeof(deviceInstance) / sizeof(deviceInstance[0]);
2153 l = RegEnumKeyExW(deviceKey, i, deviceInstance, &len, NULL, NULL, NULL,
2159 l = RegOpenKeyExW(deviceKey, deviceInstance, 0, KEY_READ, &subKey);
2162 WCHAR classGuid[40];
2165 len = sizeof(classGuid);
2166 l = RegQueryValueExW(subKey, ClassGUID, NULL, &dataType,
2167 (BYTE *)classGuid, &len);
2168 if (!l && dataType == REG_SZ)
2170 if (classGuid[0] == '{' && classGuid[37] == '}')
2175 UuidFromStringW(&classGuid[1], &deviceClass);
2176 if ((flags & DIGCF_ALLCLASSES) ||
2177 IsEqualGUID(class, &deviceClass))
2179 static const WCHAR fmt[] = {'%','s','\\','%','s',0};
2182 instanceId = HeapAlloc(GetProcessHeap(), 0,
2183 (lstrlenW(deviceName) +
2184 lstrlenW(deviceInstance) + 2) * sizeof(WCHAR));
2187 sprintfW(instanceId, fmt, deviceName,
2189 SETUPDI_AddDeviceToSet(set, &deviceClass,
2190 0 /* FIXME: DevInst */, instanceId,
2192 HeapFree(GetProcessHeap(), 0, instanceId);
2197 RegCloseKey(subKey);
2199 /* Allow enumeration to continue */
2205 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet,
2206 LPCWSTR parent, HKEY key, const GUID *class, DWORD flags)
2208 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2210 WCHAR subKeyName[MAX_PATH];
2211 LONG l = ERROR_SUCCESS;
2213 TRACE("%s\n", debugstr_w(parent));
2215 for (i = 0; !l; i++)
2217 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2218 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2223 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2226 TRACE("%s\n", debugstr_w(subKeyName));
2227 SETUPDI_EnumerateMatchingDeviceInstances(set, parent,
2228 subKeyName, subKey, class, flags);
2229 RegCloseKey(subKey);
2231 /* Allow enumeration to continue */
2237 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet, const GUID *class,
2238 LPCWSTR enumstr, DWORD flags)
2243 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(class),
2244 debugstr_w(enumstr), flags);
2246 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
2248 if (enumKey != INVALID_HANDLE_VALUE)
2254 l = RegOpenKeyExW(enumKey, enumstr, 0, KEY_READ,
2258 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet, enumstr,
2259 enumStrKey, class, flags);
2260 RegCloseKey(enumStrKey);
2266 WCHAR subKeyName[MAX_PATH];
2269 for (i = 0; !l; i++)
2271 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2272 l = RegEnumKeyExW(enumKey, i, subKeyName, &len, NULL,
2278 l = RegOpenKeyExW(enumKey, subKeyName, 0, KEY_READ,
2282 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet,
2283 subKeyName, subKey, class, flags);
2284 RegCloseKey(subKey);
2286 /* Allow enumeration to continue */
2291 RegCloseKey(enumKey);
2295 /***********************************************************************
2296 * SetupDiGetClassDevsW (SETUPAPI.@)
2298 HDEVINFO WINAPI SetupDiGetClassDevsW(
2304 return SetupDiGetClassDevsExW(class, enumstr, parent, flags, NULL, NULL,
2308 /***********************************************************************
2309 * SetupDiGetClassDevsExW (SETUPAPI.@)
2311 HDEVINFO WINAPI SetupDiGetClassDevsExW(
2320 static const DWORD unsupportedFlags = DIGCF_DEFAULT | DIGCF_PRESENT |
2324 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2325 debugstr_w(enumstr), parent, flags, deviceset, debugstr_w(machine),
2328 if (!(flags & DIGCF_ALLCLASSES) && !class)
2330 SetLastError(ERROR_INVALID_PARAMETER);
2333 if (flags & unsupportedFlags)
2334 WARN("unsupported flags %08x\n", flags & unsupportedFlags);
2338 set = SetupDiCreateDeviceInfoListExW(class, parent, machine, reserved);
2342 FIXME("%s: unimplemented for remote machines\n",
2343 debugstr_w(machine));
2344 else if (flags & DIGCF_DEVICEINTERFACE)
2345 SETUPDI_EnumerateInterfaces(set, class, enumstr, flags);
2347 SETUPDI_EnumerateDevices(set, class, enumstr, flags);
2352 /***********************************************************************
2353 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2355 BOOL WINAPI SetupDiGetDeviceInfoListDetailA(
2356 HDEVINFO DeviceInfoSet,
2357 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData )
2359 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2361 TRACE("%p %p\n", DeviceInfoSet, DevInfoData);
2363 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE)
2365 SetLastError(ERROR_INVALID_HANDLE);
2368 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2370 SetLastError(ERROR_INVALID_HANDLE);
2374 DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A))
2376 SetLastError(ERROR_INVALID_PARAMETER);
2379 memcpy(&DevInfoData->ClassGuid, &set->ClassGuid, sizeof(GUID));
2380 DevInfoData->RemoteMachineHandle = NULL;
2381 DevInfoData->RemoteMachineName[0] = '\0';
2385 /***********************************************************************
2386 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2388 BOOL WINAPI SetupDiGetDeviceInfoListDetailW(
2389 HDEVINFO DeviceInfoSet,
2390 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData )
2392 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2394 TRACE("%p %p\n", DeviceInfoSet, DevInfoData);
2396 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE)
2398 SetLastError(ERROR_INVALID_HANDLE);
2401 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2403 SetLastError(ERROR_INVALID_HANDLE);
2407 DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W))
2409 SetLastError(ERROR_INVALID_PARAMETER);
2412 memcpy(&DevInfoData->ClassGuid, &set->ClassGuid, sizeof(GUID));
2413 DevInfoData->RemoteMachineHandle = NULL;
2414 DevInfoData->RemoteMachineName[0] = '\0';
2418 /***********************************************************************
2419 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2421 BOOL WINAPI SetupDiCreateDeviceInterfaceA(
2422 HDEVINFO DeviceInfoSet,
2423 PSP_DEVINFO_DATA DeviceInfoData,
2424 const GUID *InterfaceClassGuid,
2425 PCSTR ReferenceString,
2426 DWORD CreationFlags,
2427 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2430 LPWSTR ReferenceStringW = NULL;
2432 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
2433 debugstr_guid(InterfaceClassGuid), debugstr_a(ReferenceString),
2434 CreationFlags, DeviceInterfaceData);
2436 if (ReferenceString)
2438 ReferenceStringW = MultiByteToUnicode(ReferenceString, CP_ACP);
2439 if (ReferenceStringW == NULL) return FALSE;
2442 ret = SetupDiCreateDeviceInterfaceW(DeviceInfoSet, DeviceInfoData,
2443 InterfaceClassGuid, ReferenceStringW, CreationFlags,
2444 DeviceInterfaceData);
2446 MyFree(ReferenceStringW);
2451 /***********************************************************************
2452 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2454 BOOL WINAPI SetupDiCreateDeviceInterfaceW(
2455 HDEVINFO DeviceInfoSet,
2456 PSP_DEVINFO_DATA DeviceInfoData,
2457 const GUID *InterfaceClassGuid,
2458 PCWSTR ReferenceString,
2459 DWORD CreationFlags,
2460 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2462 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2463 struct DeviceInfo *devInfo;
2464 SP_DEVICE_INTERFACE_DATA *iface = NULL;
2467 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
2468 debugstr_guid(InterfaceClassGuid), debugstr_w(ReferenceString),
2469 CreationFlags, DeviceInterfaceData);
2471 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE)
2473 SetLastError(ERROR_INVALID_HANDLE);
2476 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2478 SetLastError(ERROR_INVALID_HANDLE);
2481 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
2482 || !DeviceInfoData->Reserved)
2484 SetLastError(ERROR_INVALID_PARAMETER);
2487 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
2488 if (devInfo->set != set)
2490 SetLastError(ERROR_INVALID_PARAMETER);
2493 if (!InterfaceClassGuid)
2495 SetLastError(ERROR_INVALID_USER_BUFFER);
2498 if ((ret = SETUPDI_AddInterfaceInstance(DeviceInfoData, InterfaceClassGuid,
2499 ReferenceString, &iface)))
2501 if (DeviceInterfaceData)
2503 if (DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
2505 SetLastError(ERROR_INVALID_USER_BUFFER);
2509 memcpy(DeviceInterfaceData, iface, sizeof(*iface));
2515 /***********************************************************************
2516 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2518 HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyA(
2519 HDEVINFO DeviceInfoSet,
2520 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2524 PCSTR InfSectionName)
2527 PWSTR InfSectionNameW = NULL;
2529 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
2530 samDesired, InfHandle, InfSectionName);
2533 if (!InfSectionName)
2535 SetLastError(ERROR_INVALID_PARAMETER);
2536 return INVALID_HANDLE_VALUE;
2538 InfSectionNameW = MultiByteToUnicode(InfSectionName, CP_ACP);
2539 if (!InfSectionNameW)
2540 return INVALID_HANDLE_VALUE;
2542 key = SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet,
2543 DeviceInterfaceData, Reserved, samDesired, InfHandle,
2545 MyFree(InfSectionNameW);
2549 static PWSTR SETUPDI_GetInstancePath(struct InterfaceInfo *ifaceInfo)
2551 static const WCHAR hash[] = {'#',0};
2552 PWSTR instancePath = NULL;
2554 if (ifaceInfo->referenceString)
2556 instancePath = HeapAlloc(GetProcessHeap(), 0,
2557 (lstrlenW(ifaceInfo->referenceString) + 2) * sizeof(WCHAR));
2560 lstrcpyW(instancePath, hash);
2561 lstrcatW(instancePath, ifaceInfo->referenceString);
2564 SetLastError(ERROR_OUTOFMEMORY);
2568 instancePath = HeapAlloc(GetProcessHeap(), 0,
2569 (lstrlenW(hash) + 1) * sizeof(WCHAR));
2571 lstrcpyW(instancePath, hash);
2573 return instancePath;
2576 /***********************************************************************
2577 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2579 HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyW(
2580 HDEVINFO DeviceInfoSet,
2581 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2585 PCWSTR InfSectionName)
2587 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2588 HKEY key = INVALID_HANDLE_VALUE, interfacesKey;
2591 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
2592 samDesired, InfHandle, InfSectionName);
2594 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE ||
2595 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2597 SetLastError(ERROR_INVALID_HANDLE);
2598 return INVALID_HANDLE_VALUE;
2600 if (!DeviceInterfaceData ||
2601 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2602 !DeviceInterfaceData->Reserved)
2604 SetLastError(ERROR_INVALID_PARAMETER);
2605 return INVALID_HANDLE_VALUE;
2607 if (InfHandle && !InfSectionName)
2609 SetLastError(ERROR_INVALID_PARAMETER);
2610 return INVALID_HANDLE_VALUE;
2612 if (!(l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, DeviceClasses, 0, NULL, 0,
2613 samDesired, NULL, &interfacesKey, NULL)))
2616 WCHAR bracedGuidString[39];
2618 SETUPDI_GuidToString(&DeviceInterfaceData->InterfaceClassGuid,
2620 if (!(l = RegCreateKeyExW(interfacesKey, bracedGuidString, 0, NULL, 0,
2621 samDesired, NULL, &parent, NULL)))
2623 struct InterfaceInfo *ifaceInfo =
2624 (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2625 PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo);
2631 l = RegCreateKeyExW(parent, instancePath, 0, NULL, 0,
2632 samDesired, NULL, &key, NULL);
2636 key = INVALID_HANDLE_VALUE;
2639 FIXME("INF section installation unsupported\n");
2641 HeapFree(GetProcessHeap(), 0, instancePath);
2642 RegCloseKey(parent);
2646 RegCloseKey(interfacesKey);
2653 /***********************************************************************
2654 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2656 BOOL WINAPI SetupDiDeleteDeviceInterfaceRegKey(
2657 HDEVINFO DeviceInfoSet,
2658 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2661 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2665 TRACE("%p %p %d\n", DeviceInfoSet, DeviceInterfaceData, Reserved);
2667 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE ||
2668 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2670 SetLastError(ERROR_INVALID_HANDLE);
2673 if (!DeviceInterfaceData ||
2674 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2675 !DeviceInterfaceData->Reserved)
2677 SetLastError(ERROR_INVALID_PARAMETER);
2680 parent = SetupDiOpenClassRegKeyExW(&DeviceInterfaceData->InterfaceClassGuid,
2681 KEY_ALL_ACCESS, DIOCR_INTERFACE, NULL, NULL);
2682 if (parent != INVALID_HANDLE_VALUE)
2684 struct InterfaceInfo *ifaceInfo =
2685 (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2686 PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo);
2690 LONG l = RegDeleteKeyW(parent, instancePath);
2696 HeapFree(GetProcessHeap(), 0, instancePath);
2698 RegCloseKey(parent);
2703 /***********************************************************************
2704 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2707 * DeviceInfoSet [I] Set of devices from which to enumerate
2709 * DeviceInfoData [I] (Optional) If specified, a specific device
2710 * instance from which to enumerate interfaces.
2711 * If it isn't specified, all interfaces for all
2712 * devices in the set are enumerated.
2713 * InterfaceClassGuid [I] The interface class to enumerate.
2714 * MemberIndex [I] An index of the interface instance to enumerate.
2715 * A caller should start with MemberIndex set to 0,
2716 * and continue until the function fails with
2717 * ERROR_NO_MORE_ITEMS.
2718 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2719 * member must be set to
2720 * sizeof(SP_DEVICE_INTERFACE_DATA).
2723 * Success: non-zero value.
2724 * Failure: FALSE. Call GetLastError() for more info.
2726 BOOL WINAPI SetupDiEnumDeviceInterfaces(
2727 HDEVINFO DeviceInfoSet,
2728 PSP_DEVINFO_DATA DeviceInfoData,
2729 CONST GUID * InterfaceClassGuid,
2731 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2733 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2736 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet, DeviceInfoData,
2737 debugstr_guid(InterfaceClassGuid), MemberIndex, DeviceInterfaceData);
2739 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE ||
2740 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2742 SetLastError(ERROR_INVALID_HANDLE);
2745 if (DeviceInfoData && (DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) ||
2746 !DeviceInfoData->Reserved))
2748 SetLastError(ERROR_INVALID_PARAMETER);
2751 if (!DeviceInterfaceData ||
2752 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
2754 SetLastError(ERROR_INVALID_PARAMETER);
2759 struct DeviceInfo *devInfo =
2760 (struct DeviceInfo *)DeviceInfoData->Reserved;
2761 struct InterfaceInstances *iface;
2763 if ((ret = SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface)))
2765 if (MemberIndex < iface->cInstances)
2766 memcpy(DeviceInterfaceData, &iface->instances[MemberIndex],
2767 sizeof(SP_DEVICE_INTERFACE_DATA));
2770 SetLastError(ERROR_NO_MORE_ITEMS);
2775 SetLastError(ERROR_NO_MORE_ITEMS);
2779 DWORD i, cEnumerated = 0;
2782 for (i = 0; !found && cEnumerated < MemberIndex + 1 &&
2783 i < set->cDevices; i++)
2785 struct DeviceInfo *devInfo =
2786 (struct DeviceInfo *)set->devices[i].Reserved;
2787 struct InterfaceInstances *iface;
2789 if (SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface))
2791 if (cEnumerated + iface->cInstances < MemberIndex + 1)
2792 cEnumerated += iface->cInstances;
2795 DWORD instanceIndex = MemberIndex - cEnumerated;
2797 memcpy(DeviceInterfaceData,
2798 &iface->instances[instanceIndex],
2799 sizeof(SP_DEVICE_INTERFACE_DATA));
2800 cEnumerated += instanceIndex + 1;
2807 SetLastError(ERROR_NO_MORE_ITEMS);
2812 /***********************************************************************
2813 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2815 * Destroy a DeviceInfoList and free all used memory of the list.
2818 * devinfo [I] DeviceInfoList pointer to list to destroy
2821 * Success: non zero value.
2822 * Failure: zero value.
2824 BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
2828 TRACE("%p\n", devinfo);
2829 if (devinfo && devinfo != (HDEVINFO)INVALID_HANDLE_VALUE)
2831 struct DeviceInfoSet *list = (struct DeviceInfoSet *)devinfo;
2833 if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC)
2837 for (i = 0; i < list->cDevices; i++)
2838 SETUPDI_FreeDeviceInfo(
2839 (struct DeviceInfo *)list->devices[i].Reserved);
2840 HeapFree(GetProcessHeap(), 0, list->devices);
2841 HeapFree(GetProcessHeap(), 0, list);
2847 SetLastError(ERROR_INVALID_HANDLE);
2852 /***********************************************************************
2853 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2855 BOOL WINAPI SetupDiGetDeviceInterfaceDetailA(
2856 HDEVINFO DeviceInfoSet,
2857 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2858 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData,
2859 DWORD DeviceInterfaceDetailDataSize,
2860 PDWORD RequiredSize,
2861 PSP_DEVINFO_DATA DeviceInfoData)
2863 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2864 struct InterfaceInfo *info;
2865 DWORD bytesNeeded = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath)
2869 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet,
2870 DeviceInterfaceData, DeviceInterfaceDetailData,
2871 DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
2873 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE ||
2874 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2876 SetLastError(ERROR_INVALID_HANDLE);
2879 if (!DeviceInterfaceData ||
2880 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2881 !DeviceInterfaceData->Reserved)
2883 SetLastError(ERROR_INVALID_PARAMETER);
2886 if (DeviceInterfaceDetailData && (DeviceInterfaceDetailData->cbSize <
2887 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath) + sizeof(char) ||
2888 DeviceInterfaceDetailData->cbSize > sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A)))
2890 SetLastError(ERROR_INVALID_USER_BUFFER);
2893 if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
2895 SetLastError(ERROR_INVALID_USER_BUFFER);
2898 info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2899 if (info->symbolicLink)
2900 bytesNeeded += WideCharToMultiByte(CP_ACP, 0, info->symbolicLink, -1,
2901 NULL, 0, NULL, NULL);
2902 if (DeviceInterfaceDetailDataSize >= bytesNeeded)
2904 if (info->symbolicLink)
2905 WideCharToMultiByte(CP_ACP, 0, info->symbolicLink, -1,
2906 DeviceInterfaceDetailData->DevicePath,
2907 DeviceInterfaceDetailDataSize -
2908 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath),
2911 DeviceInterfaceDetailData->DevicePath[0] = '\0';
2912 if (DeviceInfoData && DeviceInfoData->cbSize == sizeof(SP_DEVINFO_DATA))
2913 memcpy(DeviceInfoData, info->device, sizeof(SP_DEVINFO_DATA));
2919 *RequiredSize = bytesNeeded;
2920 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2925 /***********************************************************************
2926 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2928 BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(
2929 HDEVINFO DeviceInfoSet,
2930 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2931 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData,
2932 DWORD DeviceInterfaceDetailDataSize,
2933 PDWORD RequiredSize,
2934 PSP_DEVINFO_DATA DeviceInfoData)
2936 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
2937 struct InterfaceInfo *info;
2938 DWORD bytesNeeded = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath)
2939 + sizeof(WCHAR); /* include NULL terminator */
2942 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet,
2943 DeviceInterfaceData, DeviceInterfaceDetailData,
2944 DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
2946 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE ||
2947 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2949 SetLastError(ERROR_INVALID_HANDLE);
2952 if (!DeviceInterfaceData ||
2953 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2954 !DeviceInterfaceData->Reserved)
2956 SetLastError(ERROR_INVALID_PARAMETER);
2959 if (DeviceInterfaceDetailData && (DeviceInterfaceDetailData->cbSize <
2960 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR) ||
2961 DeviceInterfaceDetailData->cbSize > sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W)))
2963 SetLastError(ERROR_INVALID_USER_BUFFER);
2966 if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
2968 SetLastError(ERROR_INVALID_USER_BUFFER);
2971 info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2972 if (info->symbolicLink)
2973 bytesNeeded += lstrlenW(info->symbolicLink);
2974 if (DeviceInterfaceDetailDataSize >= bytesNeeded)
2976 if (info->symbolicLink)
2977 lstrcpyW(DeviceInterfaceDetailData->DevicePath, info->symbolicLink);
2979 DeviceInterfaceDetailData->DevicePath[0] = '\0';
2980 if (DeviceInfoData && DeviceInfoData->cbSize == sizeof(SP_DEVINFO_DATA))
2981 memcpy(DeviceInfoData, info->device, sizeof(SP_DEVINFO_DATA));
2987 *RequiredSize = bytesNeeded;
2988 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2993 struct PropertyMapEntry
3000 static struct PropertyMapEntry PropertyMap[] = {
3001 { REG_SZ, "DeviceDesc", DeviceDesc },
3002 { REG_MULTI_SZ, "HardwareId", HardwareId },
3003 { REG_MULTI_SZ, "CompatibleIDs", CompatibleIDs },
3004 { 0, NULL, NULL }, /* SPDRP_UNUSED0 */
3005 { REG_SZ, "Service", Service },
3006 { 0, NULL, NULL }, /* SPDRP_UNUSED1 */
3007 { 0, NULL, NULL }, /* SPDRP_UNUSED2 */
3008 { REG_SZ, "Class", Class },
3009 { REG_SZ, "ClassGUID", ClassGUID },
3010 { REG_SZ, "Driver", Driver },
3011 { REG_DWORD, "ConfigFlags", ConfigFlags },
3012 { REG_SZ, "Mfg", Mfg },
3013 { REG_SZ, "FriendlyName", FriendlyName },
3014 { REG_SZ, "LocationInformation", LocationInformation },
3015 { 0, NULL, NULL }, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3016 { REG_DWORD, "Capabilities", Capabilities },
3017 { REG_DWORD, "UINumber", UINumber },
3018 { REG_MULTI_SZ, "UpperFilters", UpperFilters },
3019 { REG_MULTI_SZ, "LowerFilters", LowerFilters },
3022 /***********************************************************************
3023 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3025 BOOL WINAPI SetupDiGetDeviceRegistryPropertyA(
3026 HDEVINFO DeviceInfoSet,
3027 PSP_DEVINFO_DATA DeviceInfoData,
3029 PDWORD PropertyRegDataType,
3030 PBYTE PropertyBuffer,
3031 DWORD PropertyBufferSize,
3032 PDWORD RequiredSize)
3035 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
3036 struct DeviceInfo *devInfo;
3038 TRACE("%04x %p %d %p %p %d %p\n", (DWORD)DeviceInfoSet, DeviceInfoData,
3039 Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize,
3042 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3044 SetLastError(ERROR_INVALID_HANDLE);
3047 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3049 SetLastError(ERROR_INVALID_HANDLE);
3052 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3053 || !DeviceInfoData->Reserved)
3055 SetLastError(ERROR_INVALID_PARAMETER);
3058 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3059 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3060 && PropertyMap[Property].nameA)
3062 DWORD size = PropertyBufferSize;
3063 LONG l = RegQueryValueExA(devInfo->key, PropertyMap[Property].nameA,
3064 NULL, PropertyRegDataType, PropertyBuffer, &size);
3067 *RequiredSize = size;
3076 /***********************************************************************
3077 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3079 BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(
3080 HDEVINFO DeviceInfoSet,
3081 PSP_DEVINFO_DATA DeviceInfoData,
3083 PDWORD PropertyRegDataType,
3084 PBYTE PropertyBuffer,
3085 DWORD PropertyBufferSize,
3086 PDWORD RequiredSize)
3089 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
3090 struct DeviceInfo *devInfo;
3092 TRACE("%04x %p %d %p %p %d %p\n", (DWORD)DeviceInfoSet, DeviceInfoData,
3093 Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize,
3096 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3098 SetLastError(ERROR_INVALID_HANDLE);
3101 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3103 SetLastError(ERROR_INVALID_HANDLE);
3106 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3107 || !DeviceInfoData->Reserved)
3109 SetLastError(ERROR_INVALID_PARAMETER);
3112 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3113 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3114 && PropertyMap[Property].nameW)
3116 DWORD size = PropertyBufferSize;
3117 LONG l = RegQueryValueExW(devInfo->key, PropertyMap[Property].nameW,
3118 NULL, PropertyRegDataType, PropertyBuffer, &size);
3121 *RequiredSize = size;
3130 /***********************************************************************
3131 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3133 BOOL WINAPI SetupDiSetDeviceRegistryPropertyA(
3134 HDEVINFO DeviceInfoSet,
3135 PSP_DEVINFO_DATA DeviceInfoData,
3137 const BYTE *PropertyBuffer,
3138 DWORD PropertyBufferSize)
3141 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
3142 struct DeviceInfo *devInfo;
3144 TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property,
3145 PropertyBuffer, PropertyBufferSize);
3147 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3149 SetLastError(ERROR_INVALID_HANDLE);
3152 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3154 SetLastError(ERROR_INVALID_HANDLE);
3157 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3158 || !DeviceInfoData->Reserved)
3160 SetLastError(ERROR_INVALID_PARAMETER);
3163 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3164 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3165 && PropertyMap[Property].nameA)
3167 LONG l = RegSetValueExA(devInfo->key, PropertyMap[Property].nameA, 0,
3168 PropertyMap[Property].regType, PropertyBuffer,
3169 PropertyBufferSize);
3178 /***********************************************************************
3179 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3181 BOOL WINAPI SetupDiSetDeviceRegistryPropertyW(
3182 HDEVINFO DeviceInfoSet,
3183 PSP_DEVINFO_DATA DeviceInfoData,
3185 const BYTE *PropertyBuffer,
3186 DWORD PropertyBufferSize)
3189 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
3190 struct DeviceInfo *devInfo;
3192 TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property,
3193 PropertyBuffer, PropertyBufferSize);
3195 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3197 SetLastError(ERROR_INVALID_HANDLE);
3200 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3202 SetLastError(ERROR_INVALID_HANDLE);
3205 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3206 || !DeviceInfoData->Reserved)
3208 SetLastError(ERROR_INVALID_PARAMETER);
3211 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3212 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3213 && PropertyMap[Property].nameW)
3215 LONG l = RegSetValueExW(devInfo->key, PropertyMap[Property].nameW, 0,
3216 PropertyMap[Property].regType, PropertyBuffer,
3217 PropertyBufferSize);
3226 /***********************************************************************
3227 * SetupDiInstallClassA (SETUPAPI.@)
3229 BOOL WINAPI SetupDiInstallClassA(
3235 UNICODE_STRING FileNameW;
3240 SetLastError(ERROR_INVALID_PARAMETER);
3243 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW, InfFileName))
3245 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
3249 Result = SetupDiInstallClassW(hwndParent, FileNameW.Buffer, Flags, FileQueue);
3251 RtlFreeUnicodeString(&FileNameW);
3256 static HKEY CreateClassKey(HINF hInf)
3258 static const WCHAR slash[] = { '\\',0 };
3259 WCHAR FullBuffer[MAX_PATH];
3260 WCHAR Buffer[MAX_PATH];
3264 if (!SetupGetLineTextW(NULL,
3272 return INVALID_HANDLE_VALUE;
3275 lstrcpyW(FullBuffer, ControlClass);
3276 lstrcatW(FullBuffer, slash);
3277 lstrcatW(FullBuffer, Buffer);
3279 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3285 if (!SetupGetLineTextW(NULL,
3293 return INVALID_HANDLE_VALUE;
3296 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,
3300 REG_OPTION_NON_VOLATILE,
3306 return INVALID_HANDLE_VALUE;
3311 if (RegSetValueExW(hClassKey,
3316 RequiredSize * sizeof(WCHAR)))
3318 RegCloseKey(hClassKey);
3319 RegDeleteKeyW(HKEY_LOCAL_MACHINE,
3321 return INVALID_HANDLE_VALUE;
3327 /***********************************************************************
3328 * SetupDiInstallClassW (SETUPAPI.@)
3330 BOOL WINAPI SetupDiInstallClassW(
3336 WCHAR SectionName[MAX_PATH];
3337 DWORD SectionNameLength = 0;
3339 BOOL bFileQueueCreated = FALSE;
3347 SetLastError(ERROR_INVALID_PARAMETER);
3350 if ((Flags & DI_NOVCP) && (FileQueue == NULL || FileQueue == INVALID_HANDLE_VALUE))
3352 SetLastError(ERROR_INVALID_PARAMETER);
3356 /* Open the .inf file */
3357 hInf = SetupOpenInfFileW(InfFileName,
3361 if (hInf == INVALID_HANDLE_VALUE)
3367 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3368 hClassKey = CreateClassKey(hInf);
3369 if (hClassKey == INVALID_HANDLE_VALUE)
3371 SetupCloseInfFile(hInf);
3376 /* Try to append a layout file */
3377 SetupOpenAppendInfFileW(NULL, hInf, NULL);
3379 /* Retrieve the actual section name */
3380 SetupDiGetActualSectionToInstallW(hInf,
3388 if (!(Flags & DI_NOVCP))
3390 FileQueue = SetupOpenFileQueue();
3391 if (FileQueue == INVALID_HANDLE_VALUE)
3393 SetupCloseInfFile(hInf);
3397 bFileQueueCreated = TRUE;
3402 SetupInstallFromInfSectionW(NULL,
3405 SPINST_COPYINF | SPINST_FILES | SPINST_REGISTRY,
3411 INVALID_HANDLE_VALUE,
3414 /* FIXME: More code! */
3416 if (bFileQueueCreated)
3417 SetupCloseFileQueue(FileQueue);
3419 SetupCloseInfFile(hInf);
3425 /***********************************************************************
3426 * SetupDiOpenClassRegKey (SETUPAPI.@)
3428 HKEY WINAPI SetupDiOpenClassRegKey(
3429 const GUID* ClassGuid,
3432 return SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
3433 DIOCR_INSTALLER, NULL, NULL);
3437 /***********************************************************************
3438 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3440 HKEY WINAPI SetupDiOpenClassRegKeyExA(
3441 const GUID* ClassGuid,
3447 PWSTR MachineNameW = NULL;
3454 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
3455 if (MachineNameW == NULL)
3456 return INVALID_HANDLE_VALUE;
3459 hKey = SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
3460 Flags, MachineNameW, Reserved);
3462 MyFree(MachineNameW);
3468 /***********************************************************************
3469 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3471 HKEY WINAPI SetupDiOpenClassRegKeyExW(
3472 const GUID* ClassGuid,
3483 if (MachineName != NULL)
3485 FIXME("Remote access not supported yet!\n");
3486 return INVALID_HANDLE_VALUE;
3489 if (Flags == DIOCR_INSTALLER)
3491 lpKeyName = ControlClass;
3493 else if (Flags == DIOCR_INTERFACE)
3495 lpKeyName = DeviceClasses;
3499 ERR("Invalid Flags parameter!\n");
3500 SetLastError(ERROR_INVALID_PARAMETER);
3501 return INVALID_HANDLE_VALUE;
3506 if ((l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3513 hClassesKey = INVALID_HANDLE_VALUE;
3519 WCHAR bracedGuidString[39];
3521 SETUPDI_GuidToString(ClassGuid, bracedGuidString);
3523 if (!(l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3529 if ((l = RegOpenKeyExW(hClassesKey,
3536 key = INVALID_HANDLE_VALUE;
3538 RegCloseKey(hClassesKey);
3543 key = INVALID_HANDLE_VALUE;
3549 /***********************************************************************
3550 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3552 BOOL WINAPI SetupDiOpenDeviceInterfaceW(
3553 HDEVINFO DeviceInfoSet,
3556 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
3558 FIXME("%p %s %08x %p\n",
3559 DeviceInfoSet, debugstr_w(DevicePath), OpenFlags, DeviceInterfaceData);
3563 /***********************************************************************
3564 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3566 BOOL WINAPI SetupDiOpenDeviceInterfaceA(
3567 HDEVINFO DeviceInfoSet,
3570 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
3572 FIXME("%p %s %08x %p\n", DeviceInfoSet,
3573 debugstr_a(DevicePath), OpenFlags, DeviceInterfaceData);
3577 /***********************************************************************
3578 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3580 BOOL WINAPI SetupDiSetClassInstallParamsA(
3581 HDEVINFO DeviceInfoSet,
3582 PSP_DEVINFO_DATA DeviceInfoData,
3583 PSP_CLASSINSTALL_HEADER ClassInstallParams,
3584 DWORD ClassInstallParamsSize)
3586 FIXME("%p %p %x %u\n",DeviceInfoSet, DeviceInfoData,
3587 ClassInstallParams->InstallFunction, ClassInstallParamsSize);
3591 /***********************************************************************
3592 * SetupDiCallClassInstaller (SETUPAPI.@)
3594 BOOL WINAPI SetupDiCallClassInstaller(
3595 DI_FUNCTION InstallFunction,
3596 HDEVINFO DeviceInfoSet,
3597 PSP_DEVINFO_DATA DeviceInfoData)
3599 FIXME("%d %p %p\n", InstallFunction, DeviceInfoSet, DeviceInfoData);
3603 /***********************************************************************
3604 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3606 BOOL WINAPI SetupDiGetDeviceInstallParamsA(
3607 HDEVINFO DeviceInfoSet,
3608 PSP_DEVINFO_DATA DeviceInfoData,
3609 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams)
3611 FIXME("%p %p %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3615 static HKEY SETUPDI_OpenDevKey(struct DeviceInfo *devInfo, REGSAM samDesired)
3617 HKEY enumKey, key = INVALID_HANDLE_VALUE;
3620 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
3621 NULL, &enumKey, NULL);
3624 RegOpenKeyExW(enumKey, devInfo->instanceId, 0, samDesired, &key);
3625 RegCloseKey(enumKey);
3630 static HKEY SETUPDI_OpenDrvKey(struct DeviceInfo *devInfo, REGSAM samDesired)
3632 static const WCHAR slash[] = { '\\',0 };
3633 WCHAR classKeyPath[MAX_PATH];
3634 HKEY classKey, key = INVALID_HANDLE_VALUE;
3637 lstrcpyW(classKeyPath, ControlClass);
3638 lstrcatW(classKeyPath, slash);
3639 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
3640 classKeyPath + lstrlenW(classKeyPath));
3641 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
3642 KEY_ALL_ACCESS, NULL, &classKey, NULL);
3645 static const WCHAR fmt[] = { '%','0','4','u',0 };
3648 sprintfW(devId, fmt, devInfo->devId);
3649 RegOpenKeyExW(classKey, devId, 0, samDesired, &key);
3650 RegCloseKey(classKey);
3655 /***********************************************************************
3656 * SetupDiOpenDevRegKey (SETUPAPI.@)
3658 HKEY WINAPI SetupDiOpenDevRegKey(
3659 HDEVINFO DeviceInfoSet,
3660 PSP_DEVINFO_DATA DeviceInfoData,
3666 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
3667 struct DeviceInfo *devInfo;
3668 HKEY key = INVALID_HANDLE_VALUE;
3670 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet, DeviceInfoData,
3671 Scope, HwProfile, KeyType, samDesired);
3673 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE)
3675 SetLastError(ERROR_INVALID_HANDLE);
3676 return INVALID_HANDLE_VALUE;
3678 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3680 SetLastError(ERROR_INVALID_HANDLE);
3681 return INVALID_HANDLE_VALUE;
3683 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3684 || !DeviceInfoData->Reserved)
3686 SetLastError(ERROR_INVALID_PARAMETER);
3687 return INVALID_HANDLE_VALUE;
3689 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
3691 SetLastError(ERROR_INVALID_FLAGS);
3692 return INVALID_HANDLE_VALUE;
3694 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV)
3696 SetLastError(ERROR_INVALID_FLAGS);
3697 return INVALID_HANDLE_VALUE;
3699 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3700 if (devInfo->set != set)
3702 SetLastError(ERROR_INVALID_PARAMETER);
3703 return INVALID_HANDLE_VALUE;
3705 if (devInfo->phantom)
3707 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
3708 return INVALID_HANDLE_VALUE;
3710 if (Scope != DICS_FLAG_GLOBAL)
3711 FIXME("unimplemented for scope %d\n", Scope);
3715 key = SETUPDI_OpenDevKey(devInfo, samDesired);
3718 key = SETUPDI_OpenDrvKey(devInfo, samDesired);
3721 WARN("unknown KeyType %d\n", KeyType);
3726 static BOOL SETUPDI_DeleteDevKey(struct DeviceInfo *devInfo)
3732 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
3733 NULL, &enumKey, NULL);
3736 ret = RegDeleteTreeW(enumKey, devInfo->instanceId);
3737 RegCloseKey(enumKey);
3744 static BOOL SETUPDI_DeleteDrvKey(struct DeviceInfo *devInfo)
3746 static const WCHAR slash[] = { '\\',0 };
3747 WCHAR classKeyPath[MAX_PATH];
3752 lstrcpyW(classKeyPath, ControlClass);
3753 lstrcatW(classKeyPath, slash);
3754 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
3755 classKeyPath + lstrlenW(classKeyPath));
3756 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
3757 KEY_ALL_ACCESS, NULL, &classKey, NULL);
3760 static const WCHAR fmt[] = { '%','0','4','u',0 };
3763 sprintfW(devId, fmt, devInfo->devId);
3764 ret = RegDeleteTreeW(classKey, devId);
3765 RegCloseKey(classKey);
3772 /***********************************************************************
3773 * SetupDiOpenDevRegKey (SETUPAPI.@)
3775 BOOL WINAPI SetupDiDeleteDevRegKey(
3776 HDEVINFO DeviceInfoSet,
3777 PSP_DEVINFO_DATA DeviceInfoData,
3782 struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet;
3783 struct DeviceInfo *devInfo;
3786 TRACE("%p %p %d %d %d\n", DeviceInfoSet, DeviceInfoData, Scope, HwProfile,
3789 if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE)
3791 SetLastError(ERROR_INVALID_HANDLE);
3794 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3796 SetLastError(ERROR_INVALID_HANDLE);
3799 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3800 || !DeviceInfoData->Reserved)
3802 SetLastError(ERROR_INVALID_PARAMETER);
3805 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
3807 SetLastError(ERROR_INVALID_FLAGS);
3810 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV)
3812 SetLastError(ERROR_INVALID_FLAGS);
3815 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3816 if (devInfo->set != set)
3818 SetLastError(ERROR_INVALID_PARAMETER);
3821 if (devInfo->phantom)
3823 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
3826 if (Scope != DICS_FLAG_GLOBAL)
3827 FIXME("unimplemented for scope %d\n", Scope);
3831 ret = SETUPDI_DeleteDevKey(devInfo);
3834 ret = SETUPDI_DeleteDrvKey(devInfo);
3837 ret = SETUPDI_DeleteDevKey(devInfo);
3839 ret = SETUPDI_DeleteDrvKey(devInfo);
3842 WARN("unknown KeyType %d\n", KeyType);