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
;
131 struct list interfaces
;
134 static void SETUPDI_GuidToString(const GUID
*guid
, LPWSTR guidStr
)
136 static const WCHAR fmt
[] = {'{','%','0','8','X','-','%','0','4','X','-',
137 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
138 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
141 sprintfW(guidStr
, fmt
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
142 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
143 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
146 static void SETUPDI_FreeInterfaceInstances(struct InterfaceInstances
*instances
)
150 for (i
= 0; i
< instances
->cInstances
; i
++)
152 struct InterfaceInfo
*ifaceInfo
=
153 (struct InterfaceInfo
*)instances
->instances
[i
].Reserved
;
155 if (ifaceInfo
->device
&& ifaceInfo
->device
->Reserved
)
157 struct DeviceInfo
*devInfo
=
158 (struct DeviceInfo
*)ifaceInfo
->device
->Reserved
;
160 if (devInfo
->phantom
)
161 SetupDiDeleteDeviceInterfaceRegKey(devInfo
->set
,
162 &instances
->instances
[i
], 0);
164 HeapFree(GetProcessHeap(), 0, ifaceInfo
->referenceString
);
165 HeapFree(GetProcessHeap(), 0, ifaceInfo
->symbolicLink
);
167 HeapFree(GetProcessHeap(), 0, instances
->instances
);
170 /* Finds the interface with interface class InterfaceClassGuid in the device.
171 * Returns TRUE if found, and updates *interface to point to device's
172 * interfaces member where the given interface was found.
173 * Returns FALSE if not found.
175 static BOOL
SETUPDI_FindInterface(const struct DeviceInfo
*devInfo
,
176 const GUID
*InterfaceClassGuid
, struct InterfaceInstances
**interface
)
179 struct InterfaceInstances
*iface
;
181 TRACE("%s\n", debugstr_guid(InterfaceClassGuid
));
183 LIST_FOR_EACH_ENTRY(iface
, &devInfo
->interfaces
, struct InterfaceInstances
,
186 if (IsEqualGUID(&iface
->guid
, InterfaceClassGuid
))
193 TRACE("returning %d (%p)\n", found
, found
? *interface
: NULL
);
197 /* Finds the interface instance with reference string ReferenceString in the
198 * interface instance map. Returns TRUE if found, and updates instanceIndex to
199 * the index of the interface instance's instances member
200 * where the given instance was found. Returns FALSE if not found.
202 static BOOL
SETUPDI_FindInterfaceInstance(
203 const struct InterfaceInstances
*instances
,
204 LPCWSTR ReferenceString
, DWORD
*instanceIndex
)
209 TRACE("%s\n", debugstr_w(ReferenceString
));
211 for (i
= 0; !found
&& i
< instances
->cInstances
; i
++)
213 SP_DEVICE_INTERFACE_DATA
*ifaceData
= &instances
->instances
[i
];
214 struct InterfaceInfo
*ifaceInfo
=
215 (struct InterfaceInfo
*)ifaceData
->Reserved
;
217 if (!ReferenceString
&& !ifaceInfo
->referenceString
)
222 else if (ReferenceString
&& ifaceInfo
->referenceString
&&
223 !lstrcmpiW(ifaceInfo
->referenceString
, ReferenceString
))
229 TRACE("returning %d (%d)\n", found
, found
? *instanceIndex
: 0);
233 static LPWSTR
SETUPDI_CreateSymbolicLinkPath(LPCWSTR instanceId
,
234 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
)
236 static const WCHAR fmt
[] = {'\\','\\','?','\\','%','s','#','%','s',0};
241 SETUPDI_GuidToString(InterfaceClassGuid
, guidStr
);
242 /* omit length of format specifiers, but include NULL terminator: */
243 len
= lstrlenW(fmt
) - 4 + 1;
244 len
+= lstrlenW(instanceId
) + lstrlenW(guidStr
);
247 /* space for a hash between string and reference string: */
248 len
+= lstrlenW(ReferenceString
) + 1;
250 ret
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
253 int printed
= sprintfW(ret
, fmt
, instanceId
, guidStr
);
256 /* replace '\\' with '#' after the "\\\\?\\" beginning */
257 for (ptr
= strchrW(ret
+ 4, '\\'); ptr
; ptr
= strchrW(ptr
+ 1, '\\'))
261 ret
[printed
- 1] = '\\';
262 lstrcpyW(ret
+ printed
, ReferenceString
);
268 /* Adds an interface with the given interface class and reference string to
269 * the device, if it doesn't already exist in the device. If iface is not
270 * NULL, returns a pointer to the newly added (or already existing) interface.
272 static BOOL
SETUPDI_AddInterfaceInstance(PSP_DEVINFO_DATA DeviceInfoData
,
273 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
,
274 SP_DEVICE_INTERFACE_DATA
**ifaceData
)
276 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
277 BOOL newInterface
= FALSE
, ret
;
278 struct InterfaceInstances
*iface
= NULL
;
280 TRACE("%p %s %s %p\n", devInfo
, debugstr_guid(InterfaceClassGuid
),
281 debugstr_w(ReferenceString
), iface
);
283 if (!(ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
285 iface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
286 sizeof(struct InterfaceInstances
));
289 list_add_tail(&devInfo
->interfaces
, &iface
->entry
);
295 DWORD instanceIndex
= 0;
297 if (!(ret
= SETUPDI_FindInterfaceInstance(iface
, ReferenceString
,
300 SP_DEVICE_INTERFACE_DATA
*instance
= NULL
;
302 if (!iface
->cInstancesAllocated
)
304 iface
->instances
= HeapAlloc(GetProcessHeap(), 0,
305 sizeof(SP_DEVICE_INTERFACE_DATA
));
306 if (iface
->instances
)
307 instance
= &iface
->instances
[iface
->cInstancesAllocated
++];
309 else if (iface
->cInstances
== iface
->cInstancesAllocated
)
311 iface
->instances
= HeapReAlloc(GetProcessHeap(), 0,
313 (iface
->cInstancesAllocated
+ 1) *
314 sizeof(SP_DEVICE_INTERFACE_DATA
));
315 if (iface
->instances
)
316 instance
= &iface
->instances
[iface
->cInstancesAllocated
++];
319 instance
= &iface
->instances
[iface
->cInstances
];
322 struct InterfaceInfo
*ifaceInfo
= HeapAlloc(GetProcessHeap(),
323 0, sizeof(struct InterfaceInfo
));
328 ifaceInfo
->device
= DeviceInfoData
;
329 ifaceInfo
->symbolicLink
= SETUPDI_CreateSymbolicLinkPath(
330 devInfo
->instanceId
, InterfaceClassGuid
,
334 ifaceInfo
->referenceString
=
335 HeapAlloc(GetProcessHeap(), 0,
336 (lstrlenW(ReferenceString
) + 1) *
338 if (ifaceInfo
->referenceString
)
339 lstrcpyW(ifaceInfo
->referenceString
,
345 ifaceInfo
->referenceString
= NULL
;
352 sizeof(SP_DEVICE_INTERFACE_DATA
);
353 memcpy(&instance
->InterfaceClassGuid
,
354 InterfaceClassGuid
, sizeof(GUID
));
355 instance
->Flags
= SPINT_ACTIVE
; /* FIXME */
356 instance
->Reserved
= (ULONG_PTR
)ifaceInfo
;
358 memcpy(&iface
->guid
, InterfaceClassGuid
,
360 key
= SetupDiCreateDeviceInterfaceRegKeyW(devInfo
->set
,
361 instance
, 0, KEY_WRITE
, NULL
, NULL
);
362 if (key
!= INVALID_HANDLE_VALUE
)
364 RegSetValueExW(key
, SymbolicLink
, 0, REG_SZ
,
365 (BYTE
*)ifaceInfo
->symbolicLink
,
366 lstrlenW(ifaceInfo
->symbolicLink
) *
371 *ifaceData
= instance
;
374 HeapFree(GetProcessHeap(), 0, ifaceInfo
);
381 *ifaceData
= &iface
->instances
[instanceIndex
];
386 TRACE("returning %d\n", ret
);
390 static BOOL
SETUPDI_SetInterfaceSymbolicLink(SP_DEVICE_INTERFACE_DATA
*iface
,
391 LPCWSTR symbolicLink
)
393 struct InterfaceInfo
*info
= (struct InterfaceInfo
*)iface
->Reserved
;
398 HeapFree(GetProcessHeap(), 0, info
->symbolicLink
);
399 info
->symbolicLink
= HeapAlloc(GetProcessHeap(), 0,
400 (lstrlenW(symbolicLink
) + 1) * sizeof(WCHAR
));
401 if (info
->symbolicLink
)
403 lstrcpyW(info
->symbolicLink
, symbolicLink
);
410 static struct DeviceInfo
*SETUPDI_AllocateDeviceInfo(struct DeviceInfoSet
*set
,
411 LPCWSTR instanceId
, BOOL phantom
)
413 struct DeviceInfo
*devInfo
= HeapAlloc(GetProcessHeap(), 0,
414 sizeof(struct DeviceInfo
));
419 devInfo
->instanceId
= HeapAlloc(GetProcessHeap(), 0,
420 (lstrlenW(instanceId
) + 1) * sizeof(WCHAR
));
421 if (devInfo
->instanceId
)
426 devInfo
->key
= INVALID_HANDLE_VALUE
;
427 devInfo
->phantom
= phantom
;
428 lstrcpyW(devInfo
->instanceId
, instanceId
);
429 struprW(devInfo
->instanceId
);
430 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0,
431 KEY_ALL_ACCESS
, NULL
, &enumKey
, NULL
);
434 RegCreateKeyExW(enumKey
, devInfo
->instanceId
, 0, NULL
, 0,
435 KEY_ALL_ACCESS
, NULL
, &devInfo
->key
, NULL
);
437 RegSetValueExW(devInfo
->key
, Phantom
, 0, REG_DWORD
,
438 (LPBYTE
)&phantom
, sizeof(phantom
));
439 RegCloseKey(enumKey
);
441 list_init(&devInfo
->interfaces
);
445 HeapFree(GetProcessHeap(), 0, devInfo
);
452 static void SETUPDI_FreeDeviceInfo(struct DeviceInfo
*devInfo
)
454 struct InterfaceInstances
*iface
, *next
;
456 if (devInfo
->key
!= INVALID_HANDLE_VALUE
)
457 RegCloseKey(devInfo
->key
);
458 if (devInfo
->phantom
)
463 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0,
464 KEY_ALL_ACCESS
, NULL
, &enumKey
, NULL
);
467 RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
468 RegCloseKey(enumKey
);
471 HeapFree(GetProcessHeap(), 0, devInfo
->instanceId
);
472 LIST_FOR_EACH_ENTRY_SAFE(iface
, next
, &devInfo
->interfaces
,
473 struct InterfaceInstances
, entry
)
475 list_remove(&iface
->entry
);
476 SETUPDI_FreeInterfaceInstances(iface
);
477 HeapFree(GetProcessHeap(), 0, iface
);
479 HeapFree(GetProcessHeap(), 0, devInfo
);
482 /* Adds a device with GUID guid and identifer devInst to set. Allocates a
483 * struct DeviceInfo, and points the returned device info's Reserved member
484 * to it. "Phantom" devices are deleted from the registry when closed.
485 * Returns a pointer to the newly allocated device info.
487 static BOOL
SETUPDI_AddDeviceToSet(struct DeviceInfoSet
*set
,
492 SP_DEVINFO_DATA
**dev
)
495 struct DeviceInfo
*devInfo
= SETUPDI_AllocateDeviceInfo(set
, instanceId
,
498 TRACE("%p, %s, %d, %s, %d\n", set
, debugstr_guid(guid
), devInst
,
499 debugstr_w(instanceId
), phantom
);
504 set
->devices
= HeapReAlloc(GetProcessHeap(), 0, set
->devices
,
505 (set
->cDevices
+ 1) * sizeof(SP_DEVINFO_DATA
));
507 set
->devices
= HeapAlloc(GetProcessHeap(), 0,
508 sizeof(SP_DEVINFO_DATA
));
511 WCHAR classGuidStr
[39];
513 *dev
= &set
->devices
[set
->cDevices
++];
514 (*dev
)->cbSize
= sizeof(SP_DEVINFO_DATA
);
515 memcpy(&(*dev
)->ClassGuid
, guid
, sizeof(GUID
));
516 (*dev
)->DevInst
= devInst
;
517 (*dev
)->Reserved
= (ULONG_PTR
)devInfo
;
518 SETUPDI_GuidToString(guid
, classGuidStr
);
519 SetupDiSetDeviceRegistryPropertyW((HDEVINFO
)set
,
520 *dev
, SPDRP_CLASSGUID
, (const BYTE
*)classGuidStr
,
521 lstrlenW(classGuidStr
) * sizeof(WCHAR
));
526 HeapFree(GetProcessHeap(), 0, devInfo
);
527 SetLastError(ERROR_OUTOFMEMORY
);
533 /***********************************************************************
534 * SetupDiBuildClassInfoList (SETUPAPI.@)
536 * Returns a list of setup class GUIDs that identify the classes
537 * that are installed on a local machine.
540 * Flags [I] control exclusion of classes from the list.
541 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
542 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
543 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
549 BOOL WINAPI
SetupDiBuildClassInfoList(
551 LPGUID ClassGuidList
,
552 DWORD ClassGuidListSize
,
556 return SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
557 ClassGuidListSize
, RequiredSize
,
561 /***********************************************************************
562 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
564 * Returns a list of setup class GUIDs that identify the classes
565 * that are installed on a local or remote macine.
568 * Flags [I] control exclusion of classes from the list.
569 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
570 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
571 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
572 * MachineName [I] name of a remote machine.
573 * Reserved [I] must be NULL.
579 BOOL WINAPI
SetupDiBuildClassInfoListExA(
581 LPGUID ClassGuidList
,
582 DWORD ClassGuidListSize
,
587 LPWSTR MachineNameW
= NULL
;
594 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
595 if (MachineNameW
== NULL
) return FALSE
;
598 bResult
= SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
599 ClassGuidListSize
, RequiredSize
,
600 MachineNameW
, Reserved
);
602 MyFree(MachineNameW
);
607 /***********************************************************************
608 * SetupDiBuildClassInfoListExW (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
SetupDiBuildClassInfoListExW(
627 LPGUID ClassGuidList
,
628 DWORD ClassGuidListSize
,
639 DWORD dwGuidListIndex
= 0;
643 if (RequiredSize
!= NULL
)
646 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
651 if (hClassesKey
== INVALID_HANDLE_VALUE
)
656 for (dwIndex
= 0; ; dwIndex
++)
659 lError
= RegEnumKeyExW(hClassesKey
,
667 TRACE("RegEnumKeyExW() returns %d\n", lError
);
668 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
670 TRACE("Key name: %p\n", szKeyName
);
672 if (RegOpenKeyExW(hClassesKey
,
678 RegCloseKey(hClassesKey
);
682 if (!RegQueryValueExW(hClassKey
,
689 TRACE("'NoUseClass' value found!\n");
690 RegCloseKey(hClassKey
);
694 if ((Flags
& DIBCI_NOINSTALLCLASS
) &&
695 (!RegQueryValueExW(hClassKey
,
702 TRACE("'NoInstallClass' value found!\n");
703 RegCloseKey(hClassKey
);
707 if ((Flags
& DIBCI_NODISPLAYCLASS
) &&
708 (!RegQueryValueExW(hClassKey
,
715 TRACE("'NoDisplayClass' value found!\n");
716 RegCloseKey(hClassKey
);
720 RegCloseKey(hClassKey
);
722 TRACE("Guid: %p\n", szKeyName
);
723 if (dwGuidListIndex
< ClassGuidListSize
)
725 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
729 TRACE("Guid: %p\n", &szKeyName
[1]);
731 UuidFromStringW(&szKeyName
[1],
732 &ClassGuidList
[dwGuidListIndex
]);
738 if (lError
!= ERROR_SUCCESS
)
742 RegCloseKey(hClassesKey
);
744 if (RequiredSize
!= NULL
)
745 *RequiredSize
= dwGuidListIndex
;
747 if (ClassGuidListSize
< dwGuidListIndex
)
749 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
756 /***********************************************************************
757 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
759 BOOL WINAPI
SetupDiClassGuidsFromNameA(
761 LPGUID ClassGuidList
,
762 DWORD ClassGuidListSize
,
765 return SetupDiClassGuidsFromNameExA(ClassName
, ClassGuidList
,
766 ClassGuidListSize
, RequiredSize
,
770 /***********************************************************************
771 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
773 BOOL WINAPI
SetupDiClassGuidsFromNameW(
775 LPGUID ClassGuidList
,
776 DWORD ClassGuidListSize
,
779 return SetupDiClassGuidsFromNameExW(ClassName
, ClassGuidList
,
780 ClassGuidListSize
, RequiredSize
,
784 /***********************************************************************
785 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
787 BOOL WINAPI
SetupDiClassGuidsFromNameExA(
789 LPGUID ClassGuidList
,
790 DWORD ClassGuidListSize
,
795 LPWSTR ClassNameW
= NULL
;
796 LPWSTR MachineNameW
= NULL
;
801 ClassNameW
= MultiByteToUnicode(ClassName
, CP_ACP
);
802 if (ClassNameW
== NULL
)
807 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
808 if (MachineNameW
== NULL
)
815 bResult
= SetupDiClassGuidsFromNameExW(ClassNameW
, ClassGuidList
,
816 ClassGuidListSize
, RequiredSize
,
817 MachineNameW
, Reserved
);
819 MyFree(MachineNameW
);
825 /***********************************************************************
826 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
828 BOOL WINAPI
SetupDiClassGuidsFromNameExW(
830 LPGUID ClassGuidList
,
831 DWORD ClassGuidListSize
,
837 WCHAR szClassName
[256];
843 DWORD dwGuidListIndex
= 0;
845 if (RequiredSize
!= NULL
)
848 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
853 if (hClassesKey
== INVALID_HANDLE_VALUE
)
858 for (dwIndex
= 0; ; dwIndex
++)
861 lError
= RegEnumKeyExW(hClassesKey
,
869 TRACE("RegEnumKeyExW() returns %d\n", lError
);
870 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
872 TRACE("Key name: %p\n", szKeyName
);
874 if (RegOpenKeyExW(hClassesKey
,
880 RegCloseKey(hClassesKey
);
884 dwLength
= 256 * sizeof(WCHAR
);
885 if (!RegQueryValueExW(hClassKey
,
892 TRACE("Class name: %p\n", szClassName
);
894 if (strcmpiW(szClassName
, ClassName
) == 0)
896 TRACE("Found matching class name\n");
898 TRACE("Guid: %p\n", szKeyName
);
899 if (dwGuidListIndex
< ClassGuidListSize
)
901 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
905 TRACE("Guid: %p\n", &szKeyName
[1]);
907 UuidFromStringW(&szKeyName
[1],
908 &ClassGuidList
[dwGuidListIndex
]);
915 RegCloseKey(hClassKey
);
918 if (lError
!= ERROR_SUCCESS
)
922 RegCloseKey(hClassesKey
);
924 if (RequiredSize
!= NULL
)
925 *RequiredSize
= dwGuidListIndex
;
927 if (ClassGuidListSize
< dwGuidListIndex
)
929 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
936 /***********************************************************************
937 * SetupDiClassNameFromGuidA (SETUPAPI.@)
939 BOOL WINAPI
SetupDiClassNameFromGuidA(
940 const GUID
* ClassGuid
,
945 return SetupDiClassNameFromGuidExA(ClassGuid
, ClassName
,
946 ClassNameSize
, RequiredSize
,
950 /***********************************************************************
951 * SetupDiClassNameFromGuidW (SETUPAPI.@)
953 BOOL WINAPI
SetupDiClassNameFromGuidW(
954 const GUID
* ClassGuid
,
959 return SetupDiClassNameFromGuidExW(ClassGuid
, ClassName
,
960 ClassNameSize
, RequiredSize
,
964 /***********************************************************************
965 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
967 BOOL WINAPI
SetupDiClassNameFromGuidExA(
968 const GUID
* ClassGuid
,
975 WCHAR ClassNameW
[MAX_CLASS_NAME_LEN
];
976 LPWSTR MachineNameW
= NULL
;
980 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
981 ret
= SetupDiClassNameFromGuidExW(ClassGuid
, ClassNameW
, MAX_CLASS_NAME_LEN
,
982 NULL
, MachineNameW
, Reserved
);
985 int len
= WideCharToMultiByte(CP_ACP
, 0, ClassNameW
, -1, ClassName
,
986 ClassNameSize
, NULL
, NULL
);
988 if (!ClassNameSize
&& RequiredSize
)
991 MyFree(MachineNameW
);
995 /***********************************************************************
996 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
998 BOOL WINAPI
SetupDiClassNameFromGuidExW(
999 const GUID
* ClassGuid
,
1001 DWORD ClassNameSize
,
1002 PDWORD RequiredSize
,
1009 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1014 if (hKey
== INVALID_HANDLE_VALUE
)
1019 if (RequiredSize
!= NULL
)
1022 if (RegQueryValueExW(hKey
,
1033 *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1036 dwLength
= ClassNameSize
* sizeof(WCHAR
);
1037 if (RegQueryValueExW(hKey
,
1053 /***********************************************************************
1054 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1057 SetupDiCreateDeviceInfoList(const GUID
*ClassGuid
,
1060 return SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
, NULL
, NULL
);
1063 /***********************************************************************
1064 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1067 SetupDiCreateDeviceInfoListExA(const GUID
*ClassGuid
,
1072 LPWSTR MachineNameW
= NULL
;
1079 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1080 if (MachineNameW
== NULL
)
1081 return (HDEVINFO
)INVALID_HANDLE_VALUE
;
1084 hDevInfo
= SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
,
1085 MachineNameW
, Reserved
);
1087 MyFree(MachineNameW
);
1092 /***********************************************************************
1093 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1095 * Create an empty DeviceInfoSet list.
1098 * ClassGuid [I] if not NULL only devices with GUID ClcassGuid are associated
1100 * hwndParent [I] hwnd needed for interface related actions.
1101 * MachineName [I] name of machine to create emtpy DeviceInfoSet list, if NULL
1102 * local registry will be used.
1103 * Reserved [I] must be NULL
1106 * Success: empty list.
1107 * Failure: INVALID_HANDLE_VALUE.
1110 SetupDiCreateDeviceInfoListExW(const GUID
*ClassGuid
,
1115 struct DeviceInfoSet
*list
= NULL
;
1116 DWORD size
= sizeof(struct DeviceInfoSet
);
1118 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1119 debugstr_w(MachineName
), Reserved
);
1121 if (MachineName
!= NULL
)
1123 FIXME("remote support is not implemented\n");
1124 SetLastError(ERROR_INVALID_MACHINENAME
);
1125 return (HDEVINFO
)INVALID_HANDLE_VALUE
;
1128 if (Reserved
!= NULL
)
1130 SetLastError(ERROR_INVALID_PARAMETER
);
1131 return (HDEVINFO
)INVALID_HANDLE_VALUE
;
1134 list
= HeapAlloc(GetProcessHeap(), 0, size
);
1137 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1138 return (HDEVINFO
)INVALID_HANDLE_VALUE
;
1141 list
->magic
= SETUP_DEVICE_INFO_SET_MAGIC
;
1142 list
->hwndParent
= hwndParent
;
1143 memcpy(&list
->ClassGuid
,
1144 ClassGuid
? ClassGuid
: &GUID_NULL
,
1145 sizeof(list
->ClassGuid
));
1147 list
->devices
= NULL
;
1149 return (HDEVINFO
)list
;
1152 /***********************************************************************
1153 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1155 BOOL WINAPI
SetupDiCreateDeviceInfoA(
1156 HDEVINFO DeviceInfoSet
,
1158 CONST GUID
*ClassGuid
,
1159 PCSTR DeviceDescription
,
1161 DWORD CreationFlags
,
1162 PSP_DEVINFO_DATA DeviceInfoData
)
1165 LPWSTR DeviceNameW
= NULL
;
1166 LPWSTR DeviceDescriptionW
= NULL
;
1170 DeviceNameW
= MultiByteToUnicode(DeviceName
, CP_ACP
);
1171 if (DeviceNameW
== NULL
) return FALSE
;
1173 if (DeviceDescription
)
1175 DeviceDescriptionW
= MultiByteToUnicode(DeviceDescription
, CP_ACP
);
1176 if (DeviceDescriptionW
== NULL
)
1178 MyFree(DeviceNameW
);
1183 ret
= SetupDiCreateDeviceInfoW(DeviceInfoSet
, DeviceNameW
, ClassGuid
, DeviceDescriptionW
,
1184 hwndParent
, CreationFlags
, DeviceInfoData
);
1186 MyFree(DeviceNameW
);
1187 MyFree(DeviceDescriptionW
);
1192 static DWORD
SETUPDI_DevNameToDevID(LPCWSTR devName
)
1195 DWORD devNameLen
= lstrlenW(devName
), devInst
= 0;
1198 TRACE("%s\n", debugstr_w(devName
));
1199 for (ptr
= devName
; valid
&& *ptr
&& ptr
- devName
< devNameLen
; )
1204 devInst
|= *ptr
- '0';
1210 TRACE("%d\n", valid
? devInst
: 0xffffffff);
1211 return valid
? devInst
: 0xffffffff;
1214 /***********************************************************************
1215 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1217 BOOL WINAPI
SetupDiCreateDeviceInfoW(
1218 HDEVINFO DeviceInfoSet
,
1220 CONST GUID
*ClassGuid
,
1221 PCWSTR DeviceDescription
,
1223 DWORD CreationFlags
,
1224 PSP_DEVINFO_DATA DeviceInfoData
)
1226 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1227 BOOL ret
= FALSE
, allocatedInstanceId
= FALSE
;
1228 LPCWSTR instanceId
= NULL
;
1230 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet
, debugstr_w(DeviceName
),
1231 debugstr_guid(ClassGuid
), debugstr_w(DeviceDescription
),
1232 hwndParent
, CreationFlags
, DeviceInfoData
);
1236 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1239 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
1241 SetLastError(ERROR_INVALID_HANDLE
);
1246 SetLastError(ERROR_INVALID_PARAMETER
);
1249 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1251 SetLastError(ERROR_INVALID_HANDLE
);
1254 if (!IsEqualGUID(&set
->ClassGuid
, &GUID_NULL
) &&
1255 !IsEqualGUID(ClassGuid
, &set
->ClassGuid
))
1257 SetLastError(ERROR_CLASS_MISMATCH
);
1260 if ((CreationFlags
& DICD_GENERATE_ID
))
1262 if (strchrW(DeviceName
, '\\'))
1263 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1266 static const WCHAR newDeviceFmt
[] = {'R','O','O','T','\\','%','s',
1267 '\\','%','0','4','d',0};
1272 DWORD i
, highestDevID
= 0;
1274 for (i
= 0; i
< set
->cDevices
; i
++)
1276 struct DeviceInfo
*devInfo
=
1277 (struct DeviceInfo
*)set
->devices
[i
].Reserved
;
1278 LPCWSTR devName
= strrchrW(devInfo
->instanceId
, '\\');
1284 devName
= devInfo
->instanceId
;
1285 id
= SETUPDI_DevNameToDevID(devName
);
1286 if (id
!= 0xffffffff && id
> highestDevID
)
1289 devId
= highestDevID
+ 1;
1293 /* 17 == lstrlenW(L"Root\\") + lstrlenW("\\") + 1 + %d max size */
1294 instanceId
= HeapAlloc(GetProcessHeap(), 0,
1295 (17 + lstrlenW(DeviceName
)) * sizeof(WCHAR
));
1298 sprintfW((LPWSTR
)instanceId
, newDeviceFmt
, DeviceName
,
1300 allocatedInstanceId
= TRUE
;
1312 instanceId
= DeviceName
;
1313 for (i
= 0; ret
&& i
< set
->cDevices
; i
++)
1315 struct DeviceInfo
*devInfo
=
1316 (struct DeviceInfo
*)set
->devices
[i
].Reserved
;
1318 if (!lstrcmpiW(DeviceName
, devInfo
->instanceId
))
1320 SetLastError(ERROR_DEVINST_ALREADY_EXISTS
);
1327 SP_DEVINFO_DATA
*dev
= NULL
;
1329 ret
= SETUPDI_AddDeviceToSet(set
, ClassGuid
, 0 /* FIXME: DevInst */,
1330 instanceId
, TRUE
, &dev
);
1333 if (DeviceDescription
)
1334 SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet
,
1335 dev
, SPDRP_DEVICEDESC
, (const BYTE
*)DeviceDescription
,
1336 lstrlenW(DeviceDescription
) * sizeof(WCHAR
));
1339 if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1341 SetLastError(ERROR_INVALID_USER_BUFFER
);
1345 memcpy(DeviceInfoData
, dev
, sizeof(SP_DEVINFO_DATA
));
1349 if (allocatedInstanceId
)
1350 HeapFree(GetProcessHeap(), 0, (LPWSTR
)instanceId
);
1355 /***********************************************************************
1356 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1358 BOOL WINAPI
SetupDiRegisterDeviceInfo(
1359 HDEVINFO DeviceInfoSet
,
1360 PSP_DEVINFO_DATA DeviceInfoData
,
1362 PSP_DETSIG_CMPPROC CompareProc
,
1363 PVOID CompareContext
,
1364 PSP_DEVINFO_DATA DupDeviceInfoData
)
1366 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1367 struct DeviceInfo
*devInfo
;
1369 TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet
, DeviceInfoData
, Flags
,
1370 CompareProc
, CompareContext
, DupDeviceInfoData
);
1372 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
1374 SetLastError(ERROR_INVALID_HANDLE
);
1377 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1379 SetLastError(ERROR_INVALID_HANDLE
);
1382 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1383 || !DeviceInfoData
->Reserved
)
1385 SetLastError(ERROR_INVALID_PARAMETER
);
1388 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1389 if (devInfo
->set
!= set
)
1391 SetLastError(ERROR_INVALID_PARAMETER
);
1394 if (devInfo
->phantom
)
1396 devInfo
->phantom
= FALSE
;
1397 RegDeleteValueW(devInfo
->key
, Phantom
);
1402 /***********************************************************************
1403 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1405 BOOL WINAPI
SetupDiEnumDeviceInfo(
1408 PSP_DEVINFO_DATA info
)
1412 TRACE("%p %d %p\n", devinfo
, index
, info
);
1416 SetLastError(ERROR_INVALID_PARAMETER
);
1419 if (devinfo
&& devinfo
!= (HDEVINFO
)INVALID_HANDLE_VALUE
)
1421 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
1422 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
1424 if (index
< list
->cDevices
)
1426 if (info
->cbSize
== sizeof(SP_DEVINFO_DATA
))
1428 memcpy(info
, &list
->devices
[index
], info
->cbSize
);
1432 SetLastError(ERROR_INVALID_USER_BUFFER
);
1435 SetLastError(ERROR_NO_MORE_ITEMS
);
1438 SetLastError(ERROR_INVALID_HANDLE
);
1441 SetLastError(ERROR_INVALID_HANDLE
);
1445 /***********************************************************************
1446 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1448 BOOL WINAPI
SetupDiGetDeviceInstanceIdA(
1449 HDEVINFO DeviceInfoSet
,
1450 PSP_DEVINFO_DATA DeviceInfoData
,
1451 PSTR DeviceInstanceId
,
1452 DWORD DeviceInstanceIdSize
,
1453 PDWORD RequiredSize
)
1459 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1460 DeviceInstanceIdSize
, RequiredSize
);
1462 SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1467 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1469 instanceId
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
1472 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1479 int len
= WideCharToMultiByte(CP_ACP
, 0, instanceId
, -1,
1481 DeviceInstanceIdSize
, NULL
, NULL
);
1487 if (len
> DeviceInstanceIdSize
)
1489 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1493 *RequiredSize
= len
;
1496 HeapFree(GetProcessHeap(), 0, instanceId
);
1501 /***********************************************************************
1502 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1504 BOOL WINAPI
SetupDiGetDeviceInstanceIdW(
1505 HDEVINFO DeviceInfoSet
,
1506 PSP_DEVINFO_DATA DeviceInfoData
,
1507 PWSTR DeviceInstanceId
,
1508 DWORD DeviceInstanceIdSize
,
1509 PDWORD RequiredSize
)
1511 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1512 struct DeviceInfo
*devInfo
;
1514 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1515 DeviceInstanceIdSize
, RequiredSize
);
1517 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1519 SetLastError(ERROR_INVALID_HANDLE
);
1522 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1524 SetLastError(ERROR_INVALID_HANDLE
);
1527 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1528 || !DeviceInfoData
->Reserved
)
1530 SetLastError(ERROR_INVALID_PARAMETER
);
1533 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1534 if (devInfo
->set
!= set
)
1536 SetLastError(ERROR_INVALID_PARAMETER
);
1539 TRACE("instance ID: %s\n", debugstr_w(devInfo
->instanceId
));
1540 if (DeviceInstanceIdSize
< lstrlenW(devInfo
->instanceId
) + 1)
1542 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1544 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1547 lstrcpyW(DeviceInstanceId
, devInfo
->instanceId
);
1549 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1553 /***********************************************************************
1554 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1556 BOOL WINAPI
SetupDiGetActualSectionToInstallA(
1558 PCSTR InfSectionName
,
1559 PSTR InfSectionWithExt
,
1560 DWORD InfSectionWithExtSize
,
1561 PDWORD RequiredSize
,
1568 /***********************************************************************
1569 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
1571 BOOL WINAPI
SetupDiGetActualSectionToInstallW(
1573 PCWSTR InfSectionName
,
1574 PWSTR InfSectionWithExt
,
1575 DWORD InfSectionWithExtSize
,
1576 PDWORD RequiredSize
,
1579 WCHAR szBuffer
[MAX_PATH
];
1582 LONG lLineCount
= -1;
1584 lstrcpyW(szBuffer
, InfSectionName
);
1585 dwLength
= lstrlenW(szBuffer
);
1587 if (OsVersionInfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
1589 /* Test section name with '.NTx86' extension */
1590 lstrcpyW(&szBuffer
[dwLength
], NtPlatformExtension
);
1591 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1593 if (lLineCount
== -1)
1595 /* Test section name with '.NT' extension */
1596 lstrcpyW(&szBuffer
[dwLength
], NtExtension
);
1597 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1602 /* Test section name with '.Win' extension */
1603 lstrcpyW(&szBuffer
[dwLength
], WinExtension
);
1604 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1607 if (lLineCount
== -1)
1609 /* Test section name without extension */
1610 szBuffer
[dwLength
] = 0;
1611 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1614 if (lLineCount
== -1)
1616 SetLastError(ERROR_INVALID_PARAMETER
);
1620 dwFullLength
= lstrlenW(szBuffer
);
1622 if (InfSectionWithExt
!= NULL
&& InfSectionWithExtSize
!= 0)
1624 if (InfSectionWithExtSize
< (dwFullLength
+ 1))
1626 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1630 lstrcpyW(InfSectionWithExt
, szBuffer
);
1631 if (Extension
!= NULL
)
1633 *Extension
= (dwLength
== dwFullLength
) ? NULL
: &InfSectionWithExt
[dwLength
];
1637 if (RequiredSize
!= NULL
)
1639 *RequiredSize
= dwFullLength
+ 1;
1645 /***********************************************************************
1646 * SetupDiGetClassDescriptionA (SETUPAPI.@)
1648 BOOL WINAPI
SetupDiGetClassDescriptionA(
1649 const GUID
* ClassGuid
,
1650 PSTR ClassDescription
,
1651 DWORD ClassDescriptionSize
,
1652 PDWORD RequiredSize
)
1654 return SetupDiGetClassDescriptionExA(ClassGuid
, ClassDescription
,
1655 ClassDescriptionSize
,
1656 RequiredSize
, NULL
, NULL
);
1659 /***********************************************************************
1660 * SetupDiGetClassDescriptionW (SETUPAPI.@)
1662 BOOL WINAPI
SetupDiGetClassDescriptionW(
1663 const GUID
* ClassGuid
,
1664 PWSTR ClassDescription
,
1665 DWORD ClassDescriptionSize
,
1666 PDWORD RequiredSize
)
1668 return SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescription
,
1669 ClassDescriptionSize
,
1670 RequiredSize
, NULL
, NULL
);
1673 /***********************************************************************
1674 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
1676 BOOL WINAPI
SetupDiGetClassDescriptionExA(
1677 const GUID
* ClassGuid
,
1678 PSTR ClassDescription
,
1679 DWORD ClassDescriptionSize
,
1680 PDWORD RequiredSize
,
1688 hKey
= SetupDiOpenClassRegKeyExA(ClassGuid
,
1693 if (hKey
== INVALID_HANDLE_VALUE
)
1695 WARN("SetupDiOpenClassRegKeyExA() failed (Error %u)\n", GetLastError());
1699 dwLength
= ClassDescriptionSize
;
1700 ret
= !RegQueryValueExA( hKey
, NULL
, NULL
, NULL
,
1701 (LPBYTE
)ClassDescription
, &dwLength
);
1702 if (RequiredSize
) *RequiredSize
= dwLength
;
1707 /***********************************************************************
1708 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
1710 BOOL WINAPI
SetupDiGetClassDescriptionExW(
1711 const GUID
* ClassGuid
,
1712 PWSTR ClassDescription
,
1713 DWORD ClassDescriptionSize
,
1714 PDWORD RequiredSize
,
1722 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1727 if (hKey
== INVALID_HANDLE_VALUE
)
1729 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
1733 dwLength
= ClassDescriptionSize
* sizeof(WCHAR
);
1734 ret
= !RegQueryValueExW( hKey
, NULL
, NULL
, NULL
,
1735 (LPBYTE
)ClassDescription
, &dwLength
);
1736 if (RequiredSize
) *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1741 /***********************************************************************
1742 * SetupDiGetClassDevsA (SETUPAPI.@)
1744 HDEVINFO WINAPI
SetupDiGetClassDevsA(
1751 LPWSTR enumstrW
= NULL
;
1755 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1756 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1759 ret
= (HDEVINFO
)INVALID_HANDLE_VALUE
;
1762 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1764 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, NULL
, NULL
,
1766 HeapFree(GetProcessHeap(), 0, enumstrW
);
1772 /***********************************************************************
1773 * SetupDiGetClassDevsExA (SETUPAPI.@)
1775 HDEVINFO WINAPI
SetupDiGetClassDevsExA(
1785 LPWSTR enumstrW
= NULL
, machineW
= NULL
;
1789 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1790 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1793 ret
= (HDEVINFO
)INVALID_HANDLE_VALUE
;
1796 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1800 int len
= MultiByteToWideChar(CP_ACP
, 0, machine
, -1, NULL
, 0);
1801 machineW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1804 HeapFree(GetProcessHeap(), 0, enumstrW
);
1805 ret
= (HDEVINFO
)INVALID_HANDLE_VALUE
;
1808 MultiByteToWideChar(CP_ACP
, 0, machine
, -1, machineW
, len
);
1810 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, deviceset
,
1811 machineW
, reserved
);
1812 HeapFree(GetProcessHeap(), 0, enumstrW
);
1813 HeapFree(GetProcessHeap(), 0, machineW
);
1819 static void SETUPDI_AddDeviceInterfaces(SP_DEVINFO_DATA
*dev
, HKEY key
,
1820 const GUID
*interface
)
1823 WCHAR subKeyName
[MAX_PATH
];
1824 LONG l
= ERROR_SUCCESS
;
1826 for (i
= 0; !l
; i
++)
1828 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
1829 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
1833 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
1835 /* The subkey name is the reference string, with a '#' prepended */
1836 SETUPDI_AddInterfaceInstance(dev
, interface
, subKeyName
+ 1,
1838 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
1841 WCHAR symbolicLink
[MAX_PATH
];
1844 len
= sizeof(symbolicLink
);
1845 l
= RegQueryValueExW(subKey
, SymbolicLink
, NULL
, &dataType
,
1846 (BYTE
*)symbolicLink
, &len
);
1847 if (!l
&& dataType
== REG_SZ
)
1848 SETUPDI_SetInterfaceSymbolicLink(iface
, symbolicLink
);
1849 RegCloseKey(subKey
);
1853 /* FIXME: find and add all the device's interfaces to the device */
1856 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet
,
1857 HKEY key
, const GUID
*interface
, LPCWSTR enumstr
)
1859 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1861 WCHAR subKeyName
[MAX_PATH
];
1863 HKEY enumKey
= INVALID_HANDLE_VALUE
;
1865 TRACE("%s\n", debugstr_w(enumstr
));
1867 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
1869 for (i
= 0; !l
; i
++)
1871 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
1872 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
1877 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
1880 WCHAR deviceInst
[MAX_PATH
* 3];
1883 len
= sizeof(deviceInst
);
1884 l
= RegQueryValueExW(subKey
, DeviceInstance
, NULL
, &dataType
,
1885 (BYTE
*)deviceInst
, &len
);
1886 if (!l
&& dataType
== REG_SZ
)
1888 TRACE("found instance ID %s\n", debugstr_w(deviceInst
));
1889 if (!enumstr
|| !lstrcmpiW(enumstr
, deviceInst
))
1893 l
= RegOpenKeyExW(enumKey
, deviceInst
, 0, KEY_READ
,
1897 WCHAR deviceClassStr
[40];
1899 len
= sizeof(deviceClassStr
);
1900 l
= RegQueryValueExW(deviceKey
, ClassGUID
, NULL
,
1901 &dataType
, (BYTE
*)deviceClassStr
, &len
);
1902 if (!l
&& dataType
== REG_SZ
&&
1903 deviceClassStr
[0] == '{' &&
1904 deviceClassStr
[37] == '}')
1907 SP_DEVINFO_DATA
*dev
;
1909 deviceClassStr
[37] = 0;
1910 UuidFromStringW(&deviceClassStr
[1],
1912 if (SETUPDI_AddDeviceToSet(set
, &deviceClass
,
1913 0 /* FIXME: DevInst */, deviceInst
,
1915 SETUPDI_AddDeviceInterfaces(dev
, subKey
,
1918 RegCloseKey(deviceKey
);
1922 RegCloseKey(subKey
);
1926 if (enumKey
!= INVALID_HANDLE_VALUE
)
1927 RegCloseKey(enumKey
);
1930 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet
,
1931 const GUID
*interface
, LPCWSTR enumstr
, DWORD flags
)
1933 HKEY interfacesKey
= SetupDiOpenClassRegKeyExW(interface
, KEY_READ
,
1934 DIOCR_INTERFACE
, NULL
, NULL
);
1936 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(interface
),
1937 debugstr_w(enumstr
), flags
);
1939 if (interfacesKey
!= INVALID_HANDLE_VALUE
)
1941 if (flags
& DIGCF_ALLCLASSES
)
1944 WCHAR interfaceGuidStr
[40];
1945 LONG l
= ERROR_SUCCESS
;
1947 for (i
= 0; !l
; i
++)
1949 len
= sizeof(interfaceGuidStr
) / sizeof(interfaceGuidStr
[0]);
1950 l
= RegEnumKeyExW(interfacesKey
, i
, interfaceGuidStr
, &len
,
1951 NULL
, NULL
, NULL
, NULL
);
1954 if (interfaceGuidStr
[0] == '{' &&
1955 interfaceGuidStr
[37] == '}')
1960 interfaceGuidStr
[37] = 0;
1961 UuidFromStringW(&interfaceGuidStr
[1], &interfaceGuid
);
1962 l
= RegOpenKeyExW(interfacesKey
, interfaceGuidStr
, 0,
1963 KEY_READ
, &interfaceKey
);
1966 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
1967 interfaceKey
, &interfaceGuid
, enumstr
);
1968 RegCloseKey(interfaceKey
);
1976 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
1977 * interface's key, so just pass that long
1979 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
1980 interfacesKey
, interface
, enumstr
);
1982 RegCloseKey(interfacesKey
);
1986 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet
,
1987 LPCWSTR parent
, HKEY key
, const GUID
*class, DWORD flags
)
1989 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1991 WCHAR subKeyName
[MAX_PATH
];
1992 LONG l
= ERROR_SUCCESS
;
1994 TRACE("%s\n", debugstr_w(parent
));
1996 for (i
= 0; !l
; i
++)
1998 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
1999 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2004 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2007 WCHAR classGuid
[40];
2010 len
= sizeof(classGuid
);
2011 l
= RegQueryValueExW(subKey
, ClassGUID
, NULL
, &dataType
,
2012 (BYTE
*)classGuid
, &len
);
2013 if (!l
&& dataType
== REG_SZ
)
2015 if (classGuid
[0] == '{' && classGuid
[37] == '}')
2020 UuidFromStringW(&classGuid
[1], &deviceClass
);
2021 if ((flags
& DIGCF_ALLCLASSES
) ||
2022 IsEqualGUID(class, &deviceClass
))
2024 static const WCHAR fmt
[] = {'%','s','\\','%','s',0};
2027 instanceId
= HeapAlloc(GetProcessHeap(), 0,
2028 (lstrlenW(parent
) + lstrlenW(subKeyName
) + 2)
2032 SP_DEVINFO_DATA
*dev
;
2034 sprintfW(instanceId
, fmt
, parent
, subKeyName
);
2035 SETUPDI_AddDeviceToSet(set
, &deviceClass
,
2036 0 /* FIXME: DevInst */, instanceId
,
2038 HeapFree(GetProcessHeap(), 0, instanceId
);
2043 RegCloseKey(subKey
);
2049 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet
, const GUID
*class,
2050 LPCWSTR enumstr
, DWORD flags
)
2052 HKEY classesKey
= SetupDiOpenClassRegKeyExW(class, KEY_READ
,
2053 DIOCR_INSTALLER
, NULL
, NULL
);
2055 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(class),
2056 debugstr_w(enumstr
), flags
);
2058 if (classesKey
!= INVALID_HANDLE_VALUE
)
2063 LONG l
= RegOpenKeyExW(classesKey
, enumstr
, 0, KEY_READ
,
2068 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
, enumstr
,
2069 enumKey
, class, flags
);
2070 RegCloseKey(enumKey
);
2076 WCHAR subKeyName
[MAX_PATH
];
2077 LONG l
= ERROR_SUCCESS
;
2079 for (i
= 0; !l
; i
++)
2081 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2082 l
= RegEnumKeyExW(classesKey
, i
, subKeyName
, &len
, NULL
,
2088 l
= RegOpenKeyExW(classesKey
, subKeyName
, 0, KEY_READ
,
2092 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
,
2093 subKeyName
, subKey
, class, flags
);
2094 RegCloseKey(subKey
);
2099 RegCloseKey(classesKey
);
2103 /***********************************************************************
2104 * SetupDiGetClassDevsW (SETUPAPI.@)
2106 HDEVINFO WINAPI
SetupDiGetClassDevsW(
2112 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2116 /***********************************************************************
2117 * SetupDiGetClassDevsExW (SETUPAPI.@)
2119 HDEVINFO WINAPI
SetupDiGetClassDevsExW(
2128 static const DWORD unsupportedFlags
= DIGCF_DEFAULT
| DIGCF_PRESENT
|
2132 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2133 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2136 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2138 SetLastError(ERROR_INVALID_PARAMETER
);
2141 if (flags
& unsupportedFlags
)
2142 WARN("unsupported flags %08x\n", flags
& unsupportedFlags
);
2146 set
= SetupDiCreateDeviceInfoListExW(class, parent
, machine
, reserved
);
2150 FIXME("%s: unimplemented for remote machines\n",
2151 debugstr_w(machine
));
2152 else if (flags
& DIGCF_DEVICEINTERFACE
)
2153 SETUPDI_EnumerateInterfaces(set
, class, enumstr
, flags
);
2155 SETUPDI_EnumerateDevices(set
, class, enumstr
, flags
);
2160 /***********************************************************************
2161 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2163 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2164 HDEVINFO DeviceInfoSet
,
2165 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2167 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2169 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2171 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
2173 SetLastError(ERROR_INVALID_HANDLE
);
2176 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2178 SetLastError(ERROR_INVALID_HANDLE
);
2182 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2184 SetLastError(ERROR_INVALID_PARAMETER
);
2187 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2188 DevInfoData
->RemoteMachineHandle
= NULL
;
2189 DevInfoData
->RemoteMachineName
[0] = '\0';
2193 /***********************************************************************
2194 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2196 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2197 HDEVINFO DeviceInfoSet
,
2198 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2200 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2202 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2204 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
2206 SetLastError(ERROR_INVALID_HANDLE
);
2209 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2211 SetLastError(ERROR_INVALID_HANDLE
);
2215 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2217 SetLastError(ERROR_INVALID_PARAMETER
);
2220 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2221 DevInfoData
->RemoteMachineHandle
= NULL
;
2222 DevInfoData
->RemoteMachineName
[0] = '\0';
2226 /***********************************************************************
2227 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2229 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2230 HDEVINFO DeviceInfoSet
,
2231 PSP_DEVINFO_DATA DeviceInfoData
,
2232 const GUID
*InterfaceClassGuid
,
2233 PCSTR ReferenceString
,
2234 DWORD CreationFlags
,
2235 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2238 LPWSTR ReferenceStringW
= NULL
;
2240 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2241 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2242 CreationFlags
, DeviceInterfaceData
);
2244 if (ReferenceString
)
2246 ReferenceStringW
= MultiByteToUnicode(ReferenceString
, CP_ACP
);
2247 if (ReferenceStringW
== NULL
) return FALSE
;
2250 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2251 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2252 DeviceInterfaceData
);
2254 MyFree(ReferenceStringW
);
2259 /***********************************************************************
2260 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2262 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2263 HDEVINFO DeviceInfoSet
,
2264 PSP_DEVINFO_DATA DeviceInfoData
,
2265 const GUID
*InterfaceClassGuid
,
2266 PCWSTR ReferenceString
,
2267 DWORD CreationFlags
,
2268 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2270 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2271 struct DeviceInfo
*devInfo
;
2272 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
2275 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2276 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2277 CreationFlags
, DeviceInterfaceData
);
2279 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
2281 SetLastError(ERROR_INVALID_HANDLE
);
2284 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2286 SetLastError(ERROR_INVALID_HANDLE
);
2289 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2290 || !DeviceInfoData
->Reserved
)
2292 SetLastError(ERROR_INVALID_PARAMETER
);
2295 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2296 if (devInfo
->set
!= set
)
2298 SetLastError(ERROR_INVALID_PARAMETER
);
2301 if (!InterfaceClassGuid
)
2303 SetLastError(ERROR_INVALID_USER_BUFFER
);
2306 if ((ret
= SETUPDI_AddInterfaceInstance(DeviceInfoData
, InterfaceClassGuid
,
2307 ReferenceString
, &iface
)))
2309 if (DeviceInterfaceData
)
2311 if (DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2313 SetLastError(ERROR_INVALID_USER_BUFFER
);
2317 memcpy(DeviceInterfaceData
, iface
, sizeof(*iface
));
2323 /***********************************************************************
2324 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2326 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2327 HDEVINFO DeviceInfoSet
,
2328 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2332 PCSTR InfSectionName
)
2335 PWSTR InfSectionNameW
= NULL
;
2337 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2338 samDesired
, InfHandle
, InfSectionName
);
2341 if (!InfSectionName
)
2343 SetLastError(ERROR_INVALID_PARAMETER
);
2344 return INVALID_HANDLE_VALUE
;
2346 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2347 if (!InfSectionNameW
)
2348 return INVALID_HANDLE_VALUE
;
2350 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2351 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2353 MyFree(InfSectionNameW
);
2357 static PWSTR
SETUPDI_GetInstancePath(struct InterfaceInfo
*ifaceInfo
)
2359 static const WCHAR hash
[] = {'#',0};
2360 PWSTR instancePath
= NULL
;
2362 if (ifaceInfo
->referenceString
)
2364 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2365 (lstrlenW(ifaceInfo
->referenceString
) + 2) * sizeof(WCHAR
));
2368 lstrcpyW(instancePath
, hash
);
2369 lstrcatW(instancePath
, ifaceInfo
->referenceString
);
2372 SetLastError(ERROR_OUTOFMEMORY
);
2376 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2377 (lstrlenW(hash
) + 1) * sizeof(WCHAR
));
2379 lstrcpyW(instancePath
, hash
);
2381 return instancePath
;
2384 /***********************************************************************
2385 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2387 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2388 HDEVINFO DeviceInfoSet
,
2389 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2393 PCWSTR InfSectionName
)
2395 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2396 HKEY key
= INVALID_HANDLE_VALUE
, interfacesKey
;
2399 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2400 samDesired
, InfHandle
, InfSectionName
);
2402 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
||
2403 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2405 SetLastError(ERROR_INVALID_HANDLE
);
2406 return INVALID_HANDLE_VALUE
;
2408 if (!DeviceInterfaceData
||
2409 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2410 !DeviceInterfaceData
->Reserved
)
2412 SetLastError(ERROR_INVALID_PARAMETER
);
2413 return INVALID_HANDLE_VALUE
;
2415 if (InfHandle
&& !InfSectionName
)
2417 SetLastError(ERROR_INVALID_PARAMETER
);
2418 return INVALID_HANDLE_VALUE
;
2420 if (!(l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, DeviceClasses
, 0, NULL
, 0,
2421 samDesired
, NULL
, &interfacesKey
, NULL
)))
2424 WCHAR bracedGuidString
[39];
2426 SETUPDI_GuidToString(&DeviceInterfaceData
->InterfaceClassGuid
,
2428 if (!(l
= RegCreateKeyExW(interfacesKey
, bracedGuidString
, 0, NULL
, 0,
2429 samDesired
, NULL
, &parent
, NULL
)))
2431 struct InterfaceInfo
*ifaceInfo
=
2432 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2433 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2439 l
= RegCreateKeyExW(parent
, instancePath
, 0, NULL
, 0,
2440 samDesired
, NULL
, &key
, NULL
);
2444 key
= INVALID_HANDLE_VALUE
;
2447 FIXME("INF section installation unsupported\n");
2449 HeapFree(GetProcessHeap(), 0, instancePath
);
2450 RegCloseKey(parent
);
2454 RegCloseKey(interfacesKey
);
2461 /***********************************************************************
2462 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2464 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2465 HDEVINFO DeviceInfoSet
,
2466 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2469 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2473 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2475 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
||
2476 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2478 SetLastError(ERROR_INVALID_HANDLE
);
2481 if (!DeviceInterfaceData
||
2482 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2483 !DeviceInterfaceData
->Reserved
)
2485 SetLastError(ERROR_INVALID_PARAMETER
);
2488 parent
= SetupDiOpenClassRegKeyExW(&DeviceInterfaceData
->InterfaceClassGuid
,
2489 KEY_ALL_ACCESS
, DIOCR_INTERFACE
, NULL
, NULL
);
2490 if (parent
!= INVALID_HANDLE_VALUE
)
2492 struct InterfaceInfo
*ifaceInfo
=
2493 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2494 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2498 LONG l
= RegDeleteKeyW(parent
, instancePath
);
2504 HeapFree(GetProcessHeap(), 0, instancePath
);
2506 RegCloseKey(parent
);
2511 /***********************************************************************
2512 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2515 * DeviceInfoSet [I] Set of devices from which to enumerate
2517 * DeviceInfoData [I] (Optional) If specified, a specific device
2518 * instance from which to enumerate interfaces.
2519 * If it isn't specified, all interfaces for all
2520 * devices in the set are enumerated.
2521 * InterfaceClassGuid [I] The interface class to enumerate.
2522 * MemberIndex [I] An index of the interface instance to enumerate.
2523 * A caller should start with MemberIndex set to 0,
2524 * and continue until the function fails with
2525 * ERROR_NO_MORE_ITEMS.
2526 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2527 * member must be set to
2528 * sizeof(SP_DEVICE_INTERFACE_DATA).
2531 * Success: non-zero value.
2532 * Failure: FALSE. Call GetLastError() for more info.
2534 BOOL WINAPI
SetupDiEnumDeviceInterfaces(
2535 HDEVINFO DeviceInfoSet
,
2536 PSP_DEVINFO_DATA DeviceInfoData
,
2537 CONST GUID
* InterfaceClassGuid
,
2539 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2541 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2544 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet
, DeviceInfoData
,
2545 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
2547 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
||
2548 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2550 SetLastError(ERROR_INVALID_HANDLE
);
2553 if (DeviceInfoData
&& (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2554 !DeviceInfoData
->Reserved
))
2556 SetLastError(ERROR_INVALID_PARAMETER
);
2559 if (!DeviceInterfaceData
||
2560 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2562 SetLastError(ERROR_INVALID_PARAMETER
);
2567 struct DeviceInfo
*devInfo
=
2568 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2569 struct InterfaceInstances
*iface
;
2571 if ((ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
2573 if (MemberIndex
< iface
->cInstances
)
2574 memcpy(DeviceInterfaceData
, &iface
->instances
[MemberIndex
],
2575 sizeof(SP_DEVICE_INTERFACE_DATA
));
2578 SetLastError(ERROR_NO_MORE_ITEMS
);
2583 SetLastError(ERROR_NO_MORE_ITEMS
);
2587 DWORD i
, cEnumerated
= 0;
2590 for (i
= 0; !found
&& cEnumerated
< MemberIndex
+ 1 &&
2591 i
< set
->cDevices
; i
++)
2593 struct DeviceInfo
*devInfo
=
2594 (struct DeviceInfo
*)set
->devices
[i
].Reserved
;
2595 struct InterfaceInstances
*iface
;
2597 if (SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
))
2599 if (cEnumerated
+ iface
->cInstances
< MemberIndex
+ 1)
2600 cEnumerated
+= iface
->cInstances
;
2603 DWORD instanceIndex
= MemberIndex
- cEnumerated
;
2605 memcpy(DeviceInterfaceData
,
2606 &iface
->instances
[instanceIndex
],
2607 sizeof(SP_DEVICE_INTERFACE_DATA
));
2608 cEnumerated
+= instanceIndex
+ 1;
2615 SetLastError(ERROR_NO_MORE_ITEMS
);
2620 /***********************************************************************
2621 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2623 * Destroy a DeviceInfoList and free all used memory of the list.
2626 * devinfo [I] DeviceInfoList pointer to list to destroy
2629 * Success: non zero value.
2630 * Failure: zero value.
2632 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
2636 TRACE("%p\n", devinfo
);
2637 if (devinfo
&& devinfo
!= (HDEVINFO
)INVALID_HANDLE_VALUE
)
2639 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
2641 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
2645 for (i
= 0; i
< list
->cDevices
; i
++)
2646 SETUPDI_FreeDeviceInfo(
2647 (struct DeviceInfo
*)list
->devices
[i
].Reserved
);
2648 HeapFree(GetProcessHeap(), 0, list
->devices
);
2649 HeapFree(GetProcessHeap(), 0, list
);
2655 SetLastError(ERROR_INVALID_HANDLE
);
2660 /***********************************************************************
2661 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2663 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
2664 HDEVINFO DeviceInfoSet
,
2665 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2666 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
2667 DWORD DeviceInterfaceDetailDataSize
,
2668 PDWORD RequiredSize
,
2669 PSP_DEVINFO_DATA DeviceInfoData
)
2671 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2672 struct InterfaceInfo
*info
;
2673 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
)
2677 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2678 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2679 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2681 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
||
2682 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2684 SetLastError(ERROR_INVALID_HANDLE
);
2687 if (!DeviceInterfaceData
||
2688 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2689 !DeviceInterfaceData
->Reserved
)
2691 SetLastError(ERROR_INVALID_PARAMETER
);
2694 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
2695 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + sizeof(char) ||
2696 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
)))
2698 SetLastError(ERROR_INVALID_USER_BUFFER
);
2701 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2703 SetLastError(ERROR_INVALID_USER_BUFFER
);
2706 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2707 if (info
->symbolicLink
)
2708 bytesNeeded
+= WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2709 NULL
, 0, NULL
, NULL
);
2710 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2712 if (info
->symbolicLink
)
2713 WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2714 DeviceInterfaceDetailData
->DevicePath
,
2715 DeviceInterfaceDetailDataSize
-
2716 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
2719 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2720 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2721 memcpy(DeviceInfoData
, info
->device
, sizeof(SP_DEVINFO_DATA
));
2727 *RequiredSize
= bytesNeeded
;
2728 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2733 /***********************************************************************
2734 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2736 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
2737 HDEVINFO DeviceInfoSet
,
2738 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2739 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
2740 DWORD DeviceInterfaceDetailDataSize
,
2741 PDWORD RequiredSize
,
2742 PSP_DEVINFO_DATA DeviceInfoData
)
2744 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2745 struct InterfaceInfo
*info
;
2746 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
2747 + sizeof(WCHAR
); /* include NULL terminator */
2750 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2751 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2752 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2754 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
||
2755 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2757 SetLastError(ERROR_INVALID_HANDLE
);
2760 if (!DeviceInterfaceData
||
2761 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2762 !DeviceInterfaceData
->Reserved
)
2764 SetLastError(ERROR_INVALID_PARAMETER
);
2767 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
2768 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
) ||
2769 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
)))
2771 SetLastError(ERROR_INVALID_USER_BUFFER
);
2774 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2776 SetLastError(ERROR_INVALID_USER_BUFFER
);
2779 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2780 if (info
->symbolicLink
)
2781 bytesNeeded
+= lstrlenW(info
->symbolicLink
);
2782 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2784 if (info
->symbolicLink
)
2785 lstrcpyW(DeviceInterfaceDetailData
->DevicePath
, info
->symbolicLink
);
2787 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2788 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2789 memcpy(DeviceInfoData
, info
->device
, sizeof(SP_DEVINFO_DATA
));
2795 *RequiredSize
= bytesNeeded
;
2796 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2801 struct PropertyMapEntry
2808 static struct PropertyMapEntry PropertyMap
[] = {
2809 { REG_SZ
, "DeviceDesc", DeviceDesc
},
2810 { REG_MULTI_SZ
, "HardwareId", HardwareId
},
2811 { REG_MULTI_SZ
, "CompatibleIDs", CompatibleIDs
},
2812 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
2813 { REG_SZ
, "Service", Service
},
2814 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
2815 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
2816 { REG_SZ
, "Class", Class
},
2817 { REG_SZ
, "ClassGUID", ClassGUID
},
2818 { REG_SZ
, "Driver", Driver
},
2819 { REG_DWORD
, "ConfigFlags", ConfigFlags
},
2820 { REG_SZ
, "Mfg", Mfg
},
2821 { REG_SZ
, "FriendlyName", FriendlyName
},
2822 { REG_SZ
, "LocationInformation", LocationInformation
},
2823 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
2824 { REG_DWORD
, "Capabilities", Capabilities
},
2825 { REG_DWORD
, "UINumber", UINumber
},
2826 { REG_MULTI_SZ
, "UpperFilters", UpperFilters
},
2827 { REG_MULTI_SZ
, "LowerFilters", LowerFilters
},
2830 /***********************************************************************
2831 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
2833 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
2834 HDEVINFO DeviceInfoSet
,
2835 PSP_DEVINFO_DATA DeviceInfoData
,
2837 PDWORD PropertyRegDataType
,
2838 PBYTE PropertyBuffer
,
2839 DWORD PropertyBufferSize
,
2840 PDWORD RequiredSize
)
2843 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2844 struct DeviceInfo
*devInfo
;
2846 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
2847 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
2850 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2852 SetLastError(ERROR_INVALID_HANDLE
);
2855 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2857 SetLastError(ERROR_INVALID_HANDLE
);
2860 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2861 || !DeviceInfoData
->Reserved
)
2863 SetLastError(ERROR_INVALID_PARAMETER
);
2866 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2867 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
2868 && PropertyMap
[Property
].nameA
)
2870 DWORD size
= PropertyBufferSize
;
2871 LONG l
= RegQueryValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
,
2872 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
2875 *RequiredSize
= size
;
2884 /***********************************************************************
2885 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
2887 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
2888 HDEVINFO DeviceInfoSet
,
2889 PSP_DEVINFO_DATA DeviceInfoData
,
2891 PDWORD PropertyRegDataType
,
2892 PBYTE PropertyBuffer
,
2893 DWORD PropertyBufferSize
,
2894 PDWORD RequiredSize
)
2897 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2898 struct DeviceInfo
*devInfo
;
2900 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
2901 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
2904 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2906 SetLastError(ERROR_INVALID_HANDLE
);
2909 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2911 SetLastError(ERROR_INVALID_HANDLE
);
2914 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2915 || !DeviceInfoData
->Reserved
)
2917 SetLastError(ERROR_INVALID_PARAMETER
);
2920 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2921 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
2922 && PropertyMap
[Property
].nameW
)
2924 DWORD size
= PropertyBufferSize
;
2925 LONG l
= RegQueryValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
,
2926 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
2929 *RequiredSize
= size
;
2938 /***********************************************************************
2939 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
2941 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
2942 HDEVINFO DeviceInfoSet
,
2943 PSP_DEVINFO_DATA DeviceInfoData
,
2945 const BYTE
*PropertyBuffer
,
2946 DWORD PropertyBufferSize
)
2949 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2950 struct DeviceInfo
*devInfo
;
2952 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
2953 PropertyBuffer
, PropertyBufferSize
);
2955 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2957 SetLastError(ERROR_INVALID_HANDLE
);
2960 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2962 SetLastError(ERROR_INVALID_HANDLE
);
2965 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2966 || !DeviceInfoData
->Reserved
)
2968 SetLastError(ERROR_INVALID_PARAMETER
);
2971 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2972 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
2973 && PropertyMap
[Property
].nameA
)
2975 LONG l
= RegSetValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
, 0,
2976 PropertyMap
[Property
].regType
, PropertyBuffer
,
2977 PropertyBufferSize
);
2986 /***********************************************************************
2987 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
2989 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
2990 HDEVINFO DeviceInfoSet
,
2991 PSP_DEVINFO_DATA DeviceInfoData
,
2993 const BYTE
*PropertyBuffer
,
2994 DWORD PropertyBufferSize
)
2997 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2998 struct DeviceInfo
*devInfo
;
3000 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3001 PropertyBuffer
, PropertyBufferSize
);
3003 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3005 SetLastError(ERROR_INVALID_HANDLE
);
3008 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3010 SetLastError(ERROR_INVALID_HANDLE
);
3013 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3014 || !DeviceInfoData
->Reserved
)
3016 SetLastError(ERROR_INVALID_PARAMETER
);
3019 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3020 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3021 && PropertyMap
[Property
].nameW
)
3023 LONG l
= RegSetValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
, 0,
3024 PropertyMap
[Property
].regType
, PropertyBuffer
,
3025 PropertyBufferSize
);
3034 /***********************************************************************
3035 * SetupDiInstallClassA (SETUPAPI.@)
3037 BOOL WINAPI
SetupDiInstallClassA(
3043 UNICODE_STRING FileNameW
;
3046 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW
, InfFileName
))
3048 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3052 Result
= SetupDiInstallClassW(hwndParent
, FileNameW
.Buffer
, Flags
, FileQueue
);
3054 RtlFreeUnicodeString(&FileNameW
);
3059 static HKEY
CreateClassKey(HINF hInf
)
3061 WCHAR FullBuffer
[MAX_PATH
];
3062 WCHAR Buffer
[MAX_PATH
];
3066 if (!SetupGetLineTextW(NULL
,
3074 return INVALID_HANDLE_VALUE
;
3077 lstrcpyW(FullBuffer
, ControlClass
);
3078 lstrcatW(FullBuffer
, Buffer
);
3080 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3086 if (!SetupGetLineTextW(NULL
,
3094 return INVALID_HANDLE_VALUE
;
3097 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3101 REG_OPTION_NON_VOLATILE
,
3107 return INVALID_HANDLE_VALUE
;
3112 if (RegSetValueExW(hClassKey
,
3117 RequiredSize
* sizeof(WCHAR
)))
3119 RegCloseKey(hClassKey
);
3120 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3122 return INVALID_HANDLE_VALUE
;
3128 /***********************************************************************
3129 * SetupDiInstallClassW (SETUPAPI.@)
3131 BOOL WINAPI
SetupDiInstallClassW(
3137 WCHAR SectionName
[MAX_PATH
];
3138 DWORD SectionNameLength
= 0;
3140 BOOL bFileQueueCreated
= FALSE
;
3146 if ((Flags
& DI_NOVCP
) && (FileQueue
== NULL
|| FileQueue
== INVALID_HANDLE_VALUE
))
3148 SetLastError(ERROR_INVALID_PARAMETER
);
3152 /* Open the .inf file */
3153 hInf
= SetupOpenInfFileW(InfFileName
,
3157 if (hInf
== INVALID_HANDLE_VALUE
)
3163 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3164 hClassKey
= CreateClassKey(hInf
);
3165 if (hClassKey
== INVALID_HANDLE_VALUE
)
3167 SetupCloseInfFile(hInf
);
3172 /* Try to append a layout file */
3174 SetupOpenAppendInfFileW(NULL
, hInf
, NULL
);
3177 /* Retrieve the actual section name */
3178 SetupDiGetActualSectionToInstallW(hInf
,
3186 if (!(Flags
& DI_NOVCP
))
3188 FileQueue
= SetupOpenFileQueue();
3189 if (FileQueue
== INVALID_HANDLE_VALUE
)
3191 SetupCloseInfFile(hInf
);
3195 bFileQueueCreated
= TRUE
;
3200 SetupInstallFromInfSectionW(NULL
,
3209 INVALID_HANDLE_VALUE
,
3212 /* FIXME: More code! */
3214 if (bFileQueueCreated
)
3215 SetupCloseFileQueue(FileQueue
);
3217 SetupCloseInfFile(hInf
);
3223 /***********************************************************************
3224 * SetupDiOpenClassRegKey (SETUPAPI.@)
3226 HKEY WINAPI
SetupDiOpenClassRegKey(
3227 const GUID
* ClassGuid
,
3230 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3231 DIOCR_INSTALLER
, NULL
, NULL
);
3235 /***********************************************************************
3236 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3238 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3239 const GUID
* ClassGuid
,
3245 PWSTR MachineNameW
= NULL
;
3252 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
3253 if (MachineNameW
== NULL
)
3254 return INVALID_HANDLE_VALUE
;
3257 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3258 Flags
, MachineNameW
, Reserved
);
3260 MyFree(MachineNameW
);
3266 /***********************************************************************
3267 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3269 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3270 const GUID
* ClassGuid
,
3281 if (MachineName
!= NULL
)
3283 FIXME("Remote access not supported yet!\n");
3284 return INVALID_HANDLE_VALUE
;
3287 if (Flags
== DIOCR_INSTALLER
)
3289 lpKeyName
= ControlClass
;
3291 else if (Flags
== DIOCR_INTERFACE
)
3293 lpKeyName
= DeviceClasses
;
3297 ERR("Invalid Flags parameter!\n");
3298 SetLastError(ERROR_INVALID_PARAMETER
);
3299 return INVALID_HANDLE_VALUE
;
3304 if ((l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3311 hClassesKey
= INVALID_HANDLE_VALUE
;
3317 WCHAR bracedGuidString
[39];
3319 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3321 if (!(l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3327 if ((l
= RegOpenKeyExW(hClassesKey
,
3334 key
= INVALID_HANDLE_VALUE
;
3336 RegCloseKey(hClassesKey
);
3341 key
= INVALID_HANDLE_VALUE
;
3347 /***********************************************************************
3348 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3350 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3351 HDEVINFO DeviceInfoSet
,
3354 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3356 FIXME("%p %s %08x %p\n",
3357 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3361 /***********************************************************************
3362 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3364 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
3365 HDEVINFO DeviceInfoSet
,
3368 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3370 FIXME("%p %s %08x %p\n", DeviceInfoSet
,
3371 debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3375 /***********************************************************************
3376 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3378 BOOL WINAPI
SetupDiSetClassInstallParamsA(
3379 HDEVINFO DeviceInfoSet
,
3380 PSP_DEVINFO_DATA DeviceInfoData
,
3381 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3382 DWORD ClassInstallParamsSize
)
3384 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3385 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3389 /***********************************************************************
3390 * SetupDiCallClassInstaller (SETUPAPI.@)
3392 BOOL WINAPI
SetupDiCallClassInstaller(
3393 DI_FUNCTION InstallFunction
,
3394 HDEVINFO DeviceInfoSet
,
3395 PSP_DEVINFO_DATA DeviceInfoData
)
3397 FIXME("%d %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3401 /***********************************************************************
3402 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3404 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
3405 HDEVINFO DeviceInfoSet
,
3406 PSP_DEVINFO_DATA DeviceInfoData
,
3407 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3409 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3413 /***********************************************************************
3414 * SetupDiOpenDevRegKey (SETUPAPI.@)
3416 HKEY WINAPI
SetupDiOpenDevRegKey(
3417 HDEVINFO DeviceInfoSet
,
3418 PSP_DEVINFO_DATA DeviceInfoData
,
3424 FIXME("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
3425 Scope
, HwProfile
, KeyType
, samDesired
);
3426 return INVALID_HANDLE_VALUE
;