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
= SetupDiGetClassDevsW(class, enumstrW
, parent
, flags
);
1765 HeapFree(GetProcessHeap(), 0, enumstrW
);
1771 static void SETUPDI_AddDeviceInterfaces(SP_DEVINFO_DATA
*dev
, HKEY key
,
1772 const GUID
*interface
)
1775 WCHAR subKeyName
[MAX_PATH
];
1776 LONG l
= ERROR_SUCCESS
;
1778 for (i
= 0; !l
; i
++)
1780 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
1781 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
1785 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
1787 /* The subkey name is the reference string, with a '#' prepended */
1788 SETUPDI_AddInterfaceInstance(dev
, interface
, subKeyName
+ 1,
1790 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
1793 WCHAR symbolicLink
[MAX_PATH
];
1796 len
= sizeof(symbolicLink
);
1797 l
= RegQueryValueExW(subKey
, SymbolicLink
, NULL
, &dataType
,
1798 (BYTE
*)symbolicLink
, &len
);
1799 if (!l
&& dataType
== REG_SZ
)
1800 SETUPDI_SetInterfaceSymbolicLink(iface
, symbolicLink
);
1801 RegCloseKey(subKey
);
1805 /* FIXME: find and add all the device's interfaces to the device */
1808 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet
,
1809 HKEY key
, const GUID
*interface
, LPCWSTR enumstr
)
1811 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1813 WCHAR subKeyName
[MAX_PATH
];
1815 HKEY enumKey
= INVALID_HANDLE_VALUE
;
1817 TRACE("%s\n", debugstr_w(enumstr
));
1819 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
1821 for (i
= 0; !l
; i
++)
1823 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
1824 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
1829 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
1832 WCHAR deviceInst
[MAX_PATH
* 3];
1835 len
= sizeof(deviceInst
);
1836 l
= RegQueryValueExW(subKey
, DeviceInstance
, NULL
, &dataType
,
1837 (BYTE
*)deviceInst
, &len
);
1838 if (!l
&& dataType
== REG_SZ
)
1840 TRACE("found instance ID %s\n", debugstr_w(deviceInst
));
1841 if (!enumstr
|| !lstrcmpiW(enumstr
, deviceInst
))
1845 l
= RegOpenKeyExW(enumKey
, deviceInst
, 0, KEY_READ
,
1849 WCHAR deviceClassStr
[40];
1851 len
= sizeof(deviceClassStr
);
1852 l
= RegQueryValueExW(deviceKey
, ClassGUID
, NULL
,
1853 &dataType
, (BYTE
*)deviceClassStr
, &len
);
1854 if (!l
&& dataType
== REG_SZ
&&
1855 deviceClassStr
[0] == '{' &&
1856 deviceClassStr
[37] == '}')
1859 SP_DEVINFO_DATA
*dev
;
1861 deviceClassStr
[37] = 0;
1862 UuidFromStringW(&deviceClassStr
[1],
1864 if (SETUPDI_AddDeviceToSet(set
, &deviceClass
,
1865 0 /* FIXME: DevInst */, deviceInst
,
1867 SETUPDI_AddDeviceInterfaces(dev
, subKey
,
1870 RegCloseKey(deviceKey
);
1874 RegCloseKey(subKey
);
1878 if (enumKey
!= INVALID_HANDLE_VALUE
)
1879 RegCloseKey(enumKey
);
1882 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet
,
1883 const GUID
*interface
, LPCWSTR enumstr
, DWORD flags
)
1885 HKEY interfacesKey
= SetupDiOpenClassRegKeyExW(interface
, KEY_READ
,
1886 DIOCR_INTERFACE
, NULL
, NULL
);
1888 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(interface
),
1889 debugstr_w(enumstr
), flags
);
1891 if (interfacesKey
!= INVALID_HANDLE_VALUE
)
1893 if (flags
& DIGCF_ALLCLASSES
)
1896 WCHAR interfaceGuidStr
[40];
1897 LONG l
= ERROR_SUCCESS
;
1899 for (i
= 0; !l
; i
++)
1901 len
= sizeof(interfaceGuidStr
) / sizeof(interfaceGuidStr
[0]);
1902 l
= RegEnumKeyExW(interfacesKey
, i
, interfaceGuidStr
, &len
,
1903 NULL
, NULL
, NULL
, NULL
);
1906 if (interfaceGuidStr
[0] == '{' &&
1907 interfaceGuidStr
[37] == '}')
1912 interfaceGuidStr
[37] = 0;
1913 UuidFromStringW(&interfaceGuidStr
[1], &interfaceGuid
);
1914 l
= RegOpenKeyExW(interfacesKey
, interfaceGuidStr
, 0,
1915 KEY_READ
, &interfaceKey
);
1918 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
1919 interfaceKey
, &interfaceGuid
, enumstr
);
1920 RegCloseKey(interfaceKey
);
1928 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
1929 * interface's key, so just pass that long
1931 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
1932 interfacesKey
, interface
, enumstr
);
1934 RegCloseKey(interfacesKey
);
1938 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet
,
1939 LPCWSTR parent
, HKEY key
, const GUID
*class, DWORD flags
)
1941 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)set
;
1943 WCHAR subKeyName
[MAX_PATH
];
1944 LONG l
= ERROR_SUCCESS
;
1946 TRACE("%s\n", debugstr_w(parent
));
1948 for (i
= 0; !l
; i
++)
1950 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
1951 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
1956 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
1959 WCHAR classGuid
[40];
1962 len
= sizeof(classGuid
);
1963 l
= RegQueryValueExW(subKey
, ClassGUID
, NULL
, &dataType
,
1964 (BYTE
*)classGuid
, &len
);
1965 if (!l
&& dataType
== REG_SZ
)
1967 if (classGuid
[0] == '{' && classGuid
[37] == '}')
1972 UuidFromStringW(&classGuid
[1], &deviceClass
);
1973 if ((flags
& DIGCF_ALLCLASSES
) ||
1974 IsEqualGUID(class, &deviceClass
))
1976 static const WCHAR fmt
[] = {'%','s','\\','%','s',0};
1979 instanceId
= HeapAlloc(GetProcessHeap(), 0,
1980 (lstrlenW(parent
) + lstrlenW(subKeyName
) + 2)
1984 SP_DEVINFO_DATA
*dev
;
1986 sprintfW(instanceId
, fmt
, parent
, subKeyName
);
1987 SETUPDI_AddDeviceToSet(set
, &deviceClass
,
1988 0 /* FIXME: DevInst */, instanceId
,
1990 HeapFree(GetProcessHeap(), 0, instanceId
);
1995 RegCloseKey(subKey
);
2001 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet
, const GUID
*class,
2002 LPCWSTR enumstr
, DWORD flags
)
2004 HKEY classesKey
= SetupDiOpenClassRegKeyExW(class, KEY_READ
,
2005 DIOCR_INSTALLER
, NULL
, NULL
);
2007 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(class),
2008 debugstr_w(enumstr
), flags
);
2010 if (classesKey
!= INVALID_HANDLE_VALUE
)
2015 LONG l
= RegOpenKeyExW(classesKey
, enumstr
, 0, KEY_READ
,
2020 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
, enumstr
,
2021 enumKey
, class, flags
);
2022 RegCloseKey(enumKey
);
2028 WCHAR subKeyName
[MAX_PATH
];
2029 LONG l
= ERROR_SUCCESS
;
2031 for (i
= 0; !l
; i
++)
2033 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2034 l
= RegEnumKeyExW(classesKey
, i
, subKeyName
, &len
, NULL
,
2040 l
= RegOpenKeyExW(classesKey
, subKeyName
, 0, KEY_READ
,
2044 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
,
2045 subKeyName
, subKey
, class, flags
);
2046 RegCloseKey(subKey
);
2051 RegCloseKey(classesKey
);
2055 /***********************************************************************
2056 * SetupDiGetClassDevsW (SETUPAPI.@)
2058 HDEVINFO WINAPI
SetupDiGetClassDevsW(
2064 static const DWORD unsupportedFlags
= DIGCF_DEFAULT
| DIGCF_PRESENT
|
2068 TRACE("%s %s %p 0x%08x\n", debugstr_guid(class), debugstr_w(enumstr
), parent
, flags
);
2070 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2072 SetLastError(ERROR_INVALID_PARAMETER
);
2075 if (flags
& unsupportedFlags
)
2076 WARN("unsupported flags %08x\n", flags
& unsupportedFlags
);
2077 /* WinXP always succeeds, returns empty list for unknown classes */
2078 set
= SetupDiCreateDeviceInfoList(class, parent
);
2081 if (flags
& DIGCF_DEVICEINTERFACE
)
2082 SETUPDI_EnumerateInterfaces(set
, class, enumstr
, flags
);
2084 SETUPDI_EnumerateDevices(set
, class, enumstr
, flags
);
2089 /***********************************************************************
2090 * SetupDiGetClassDevsExW (SETUPAPI.@)
2092 HDEVINFO WINAPI
SetupDiGetClassDevsExW(
2101 static const DWORD unsupportedFlags
= DIGCF_DEFAULT
| DIGCF_PRESENT
|
2105 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2106 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2109 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2111 SetLastError(ERROR_INVALID_PARAMETER
);
2114 if (flags
& unsupportedFlags
)
2115 WARN("unsupported flags %08x\n", flags
& unsupportedFlags
);
2119 set
= SetupDiCreateDeviceInfoListExW(class, parent
, machine
, reserved
);
2123 FIXME("%s: unimplemented for remote machines\n",
2124 debugstr_w(machine
));
2125 else if (flags
& DIGCF_DEVICEINTERFACE
)
2126 SETUPDI_EnumerateInterfaces(set
, class, enumstr
, flags
);
2128 SETUPDI_EnumerateDevices(set
, class, enumstr
, flags
);
2133 /***********************************************************************
2134 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2136 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2137 HDEVINFO DeviceInfoSet
,
2138 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2140 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2142 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2144 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
2146 SetLastError(ERROR_INVALID_HANDLE
);
2149 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2151 SetLastError(ERROR_INVALID_HANDLE
);
2155 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2157 SetLastError(ERROR_INVALID_PARAMETER
);
2160 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2161 DevInfoData
->RemoteMachineHandle
= NULL
;
2162 DevInfoData
->RemoteMachineName
[0] = '\0';
2166 /***********************************************************************
2167 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2169 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2170 HDEVINFO DeviceInfoSet
,
2171 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2173 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2175 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2177 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
2179 SetLastError(ERROR_INVALID_HANDLE
);
2182 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2184 SetLastError(ERROR_INVALID_HANDLE
);
2188 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2190 SetLastError(ERROR_INVALID_PARAMETER
);
2193 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2194 DevInfoData
->RemoteMachineHandle
= NULL
;
2195 DevInfoData
->RemoteMachineName
[0] = '\0';
2199 /***********************************************************************
2200 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2202 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2203 HDEVINFO DeviceInfoSet
,
2204 PSP_DEVINFO_DATA DeviceInfoData
,
2205 const GUID
*InterfaceClassGuid
,
2206 PCSTR ReferenceString
,
2207 DWORD CreationFlags
,
2208 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2211 LPWSTR ReferenceStringW
= NULL
;
2213 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2214 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2215 CreationFlags
, DeviceInterfaceData
);
2217 if (ReferenceString
)
2219 ReferenceStringW
= MultiByteToUnicode(ReferenceString
, CP_ACP
);
2220 if (ReferenceStringW
== NULL
) return FALSE
;
2223 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2224 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2225 DeviceInterfaceData
);
2227 MyFree(ReferenceStringW
);
2232 /***********************************************************************
2233 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2235 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2236 HDEVINFO DeviceInfoSet
,
2237 PSP_DEVINFO_DATA DeviceInfoData
,
2238 const GUID
*InterfaceClassGuid
,
2239 PCWSTR ReferenceString
,
2240 DWORD CreationFlags
,
2241 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2243 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2244 struct DeviceInfo
*devInfo
;
2245 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
2248 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2249 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2250 CreationFlags
, DeviceInterfaceData
);
2252 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
2254 SetLastError(ERROR_INVALID_HANDLE
);
2257 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2259 SetLastError(ERROR_INVALID_HANDLE
);
2262 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2263 || !DeviceInfoData
->Reserved
)
2265 SetLastError(ERROR_INVALID_PARAMETER
);
2268 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2269 if (devInfo
->set
!= set
)
2271 SetLastError(ERROR_INVALID_PARAMETER
);
2274 if (!InterfaceClassGuid
)
2276 SetLastError(ERROR_INVALID_USER_BUFFER
);
2279 if ((ret
= SETUPDI_AddInterfaceInstance(DeviceInfoData
, InterfaceClassGuid
,
2280 ReferenceString
, &iface
)))
2282 if (DeviceInterfaceData
)
2284 if (DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2286 SetLastError(ERROR_INVALID_USER_BUFFER
);
2290 memcpy(DeviceInterfaceData
, iface
, sizeof(*iface
));
2296 /***********************************************************************
2297 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2299 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2300 HDEVINFO DeviceInfoSet
,
2301 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2305 PCSTR InfSectionName
)
2308 PWSTR InfSectionNameW
= NULL
;
2310 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2311 samDesired
, InfHandle
, InfSectionName
);
2314 if (!InfSectionName
)
2316 SetLastError(ERROR_INVALID_PARAMETER
);
2317 return INVALID_HANDLE_VALUE
;
2319 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2320 if (!InfSectionNameW
)
2321 return INVALID_HANDLE_VALUE
;
2323 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2324 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2326 MyFree(InfSectionNameW
);
2330 static PWSTR
SETUPDI_GetInstancePath(struct InterfaceInfo
*ifaceInfo
)
2332 static const WCHAR hash
[] = {'#',0};
2333 PWSTR instancePath
= NULL
;
2335 if (ifaceInfo
->referenceString
)
2337 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2338 (lstrlenW(ifaceInfo
->referenceString
) + 2) * sizeof(WCHAR
));
2341 lstrcpyW(instancePath
, hash
);
2342 lstrcatW(instancePath
, ifaceInfo
->referenceString
);
2345 SetLastError(ERROR_OUTOFMEMORY
);
2349 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2350 (lstrlenW(hash
) + 1) * sizeof(WCHAR
));
2352 lstrcpyW(instancePath
, hash
);
2354 return instancePath
;
2357 /***********************************************************************
2358 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2360 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2361 HDEVINFO DeviceInfoSet
,
2362 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2366 PCWSTR InfSectionName
)
2368 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2369 HKEY key
= INVALID_HANDLE_VALUE
, interfacesKey
;
2372 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2373 samDesired
, InfHandle
, InfSectionName
);
2375 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
||
2376 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2378 SetLastError(ERROR_INVALID_HANDLE
);
2379 return INVALID_HANDLE_VALUE
;
2381 if (!DeviceInterfaceData
||
2382 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2383 !DeviceInterfaceData
->Reserved
)
2385 SetLastError(ERROR_INVALID_PARAMETER
);
2386 return INVALID_HANDLE_VALUE
;
2388 if (InfHandle
&& !InfSectionName
)
2390 SetLastError(ERROR_INVALID_PARAMETER
);
2391 return INVALID_HANDLE_VALUE
;
2393 if (!(l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, DeviceClasses
, 0, NULL
, 0,
2394 samDesired
, NULL
, &interfacesKey
, NULL
)))
2397 WCHAR bracedGuidString
[39];
2399 SETUPDI_GuidToString(&DeviceInterfaceData
->InterfaceClassGuid
,
2401 if (!(l
= RegCreateKeyExW(interfacesKey
, bracedGuidString
, 0, NULL
, 0,
2402 samDesired
, NULL
, &parent
, NULL
)))
2404 struct InterfaceInfo
*ifaceInfo
=
2405 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2406 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2412 l
= RegCreateKeyExW(parent
, instancePath
, 0, NULL
, 0,
2413 samDesired
, NULL
, &key
, NULL
);
2417 key
= INVALID_HANDLE_VALUE
;
2420 FIXME("INF section installation unsupported\n");
2422 HeapFree(GetProcessHeap(), 0, instancePath
);
2423 RegCloseKey(parent
);
2427 RegCloseKey(interfacesKey
);
2434 /***********************************************************************
2435 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2437 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2438 HDEVINFO DeviceInfoSet
,
2439 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2442 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2446 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2448 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
||
2449 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2451 SetLastError(ERROR_INVALID_HANDLE
);
2454 if (!DeviceInterfaceData
||
2455 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2456 !DeviceInterfaceData
->Reserved
)
2458 SetLastError(ERROR_INVALID_PARAMETER
);
2461 parent
= SetupDiOpenClassRegKeyExW(&DeviceInterfaceData
->InterfaceClassGuid
,
2462 KEY_ALL_ACCESS
, DIOCR_INTERFACE
, NULL
, NULL
);
2463 if (parent
!= INVALID_HANDLE_VALUE
)
2465 struct InterfaceInfo
*ifaceInfo
=
2466 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2467 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2471 LONG l
= RegDeleteKeyW(parent
, instancePath
);
2477 HeapFree(GetProcessHeap(), 0, instancePath
);
2479 RegCloseKey(parent
);
2484 /***********************************************************************
2485 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2488 * DeviceInfoSet [I] Set of devices from which to enumerate
2490 * DeviceInfoData [I] (Optional) If specified, a specific device
2491 * instance from which to enumerate interfaces.
2492 * If it isn't specified, all interfaces for all
2493 * devices in the set are enumerated.
2494 * InterfaceClassGuid [I] The interface class to enumerate.
2495 * MemberIndex [I] An index of the interface instance to enumerate.
2496 * A caller should start with MemberIndex set to 0,
2497 * and continue until the function fails with
2498 * ERROR_NO_MORE_ITEMS.
2499 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2500 * member must be set to
2501 * sizeof(SP_DEVICE_INTERFACE_DATA).
2504 * Success: non-zero value.
2505 * Failure: FALSE. Call GetLastError() for more info.
2507 BOOL WINAPI
SetupDiEnumDeviceInterfaces(
2508 HDEVINFO DeviceInfoSet
,
2509 PSP_DEVINFO_DATA DeviceInfoData
,
2510 CONST GUID
* InterfaceClassGuid
,
2512 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2514 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2517 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet
, DeviceInfoData
,
2518 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
2520 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
||
2521 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2523 SetLastError(ERROR_INVALID_HANDLE
);
2526 if (DeviceInfoData
&& (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2527 !DeviceInfoData
->Reserved
))
2529 SetLastError(ERROR_INVALID_PARAMETER
);
2532 if (!DeviceInterfaceData
||
2533 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2535 SetLastError(ERROR_INVALID_PARAMETER
);
2540 struct DeviceInfo
*devInfo
=
2541 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2542 struct InterfaceInstances
*iface
;
2544 if ((ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
2546 if (MemberIndex
< iface
->cInstances
)
2547 memcpy(DeviceInterfaceData
, &iface
->instances
[MemberIndex
],
2548 sizeof(SP_DEVICE_INTERFACE_DATA
));
2551 SetLastError(ERROR_NO_MORE_ITEMS
);
2556 SetLastError(ERROR_NO_MORE_ITEMS
);
2560 DWORD i
, cEnumerated
= 0;
2563 for (i
= 0; !found
&& cEnumerated
< MemberIndex
+ 1 &&
2564 i
< set
->cDevices
; i
++)
2566 struct DeviceInfo
*devInfo
=
2567 (struct DeviceInfo
*)set
->devices
[i
].Reserved
;
2568 struct InterfaceInstances
*iface
;
2570 if (SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
))
2572 if (cEnumerated
+ iface
->cInstances
< MemberIndex
+ 1)
2573 cEnumerated
+= iface
->cInstances
;
2576 DWORD instanceIndex
= MemberIndex
- cEnumerated
;
2578 memcpy(DeviceInterfaceData
,
2579 &iface
->instances
[instanceIndex
],
2580 sizeof(SP_DEVICE_INTERFACE_DATA
));
2581 cEnumerated
+= instanceIndex
+ 1;
2588 SetLastError(ERROR_NO_MORE_ITEMS
);
2593 /***********************************************************************
2594 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2596 * Destroy a DeviceInfoList and free all used memory of the list.
2599 * devinfo [I] DeviceInfoList pointer to list to destroy
2602 * Success: non zero value.
2603 * Failure: zero value.
2605 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
2609 TRACE("%p\n", devinfo
);
2610 if (devinfo
&& devinfo
!= (HDEVINFO
)INVALID_HANDLE_VALUE
)
2612 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
2614 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
2618 for (i
= 0; i
< list
->cDevices
; i
++)
2619 SETUPDI_FreeDeviceInfo(
2620 (struct DeviceInfo
*)list
->devices
[i
].Reserved
);
2621 HeapFree(GetProcessHeap(), 0, list
->devices
);
2622 HeapFree(GetProcessHeap(), 0, list
);
2628 SetLastError(ERROR_INVALID_HANDLE
);
2633 /***********************************************************************
2634 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2636 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
2637 HDEVINFO DeviceInfoSet
,
2638 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2639 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
2640 DWORD DeviceInterfaceDetailDataSize
,
2641 PDWORD RequiredSize
,
2642 PSP_DEVINFO_DATA DeviceInfoData
)
2644 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2645 struct InterfaceInfo
*info
;
2646 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
)
2650 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2651 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2652 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2654 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
||
2655 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2657 SetLastError(ERROR_INVALID_HANDLE
);
2660 if (!DeviceInterfaceData
||
2661 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2662 !DeviceInterfaceData
->Reserved
)
2664 SetLastError(ERROR_INVALID_PARAMETER
);
2667 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
2668 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + sizeof(char) ||
2669 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
)))
2671 SetLastError(ERROR_INVALID_USER_BUFFER
);
2674 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2676 SetLastError(ERROR_INVALID_USER_BUFFER
);
2679 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2680 if (info
->symbolicLink
)
2681 bytesNeeded
+= WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2682 NULL
, 0, NULL
, NULL
);
2683 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2685 if (info
->symbolicLink
)
2686 WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2687 DeviceInterfaceDetailData
->DevicePath
,
2688 DeviceInterfaceDetailDataSize
-
2689 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
2692 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2693 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2694 memcpy(DeviceInfoData
, info
->device
, sizeof(SP_DEVINFO_DATA
));
2700 *RequiredSize
= bytesNeeded
;
2701 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2706 /***********************************************************************
2707 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2709 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
2710 HDEVINFO DeviceInfoSet
,
2711 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2712 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
2713 DWORD DeviceInterfaceDetailDataSize
,
2714 PDWORD RequiredSize
,
2715 PSP_DEVINFO_DATA DeviceInfoData
)
2717 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2718 struct InterfaceInfo
*info
;
2719 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
2720 + sizeof(WCHAR
); /* include NULL terminator */
2723 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2724 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2725 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2727 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
||
2728 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2730 SetLastError(ERROR_INVALID_HANDLE
);
2733 if (!DeviceInterfaceData
||
2734 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2735 !DeviceInterfaceData
->Reserved
)
2737 SetLastError(ERROR_INVALID_PARAMETER
);
2740 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
2741 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
) ||
2742 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
)))
2744 SetLastError(ERROR_INVALID_USER_BUFFER
);
2747 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2749 SetLastError(ERROR_INVALID_USER_BUFFER
);
2752 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2753 if (info
->symbolicLink
)
2754 bytesNeeded
+= lstrlenW(info
->symbolicLink
);
2755 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2757 if (info
->symbolicLink
)
2758 lstrcpyW(DeviceInterfaceDetailData
->DevicePath
, info
->symbolicLink
);
2760 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2761 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2762 memcpy(DeviceInfoData
, info
->device
, sizeof(SP_DEVINFO_DATA
));
2768 *RequiredSize
= bytesNeeded
;
2769 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2774 struct PropertyMapEntry
2781 static struct PropertyMapEntry PropertyMap
[] = {
2782 { REG_SZ
, "DeviceDesc", DeviceDesc
},
2783 { REG_MULTI_SZ
, "HardwareId", HardwareId
},
2784 { REG_MULTI_SZ
, "CompatibleIDs", CompatibleIDs
},
2785 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
2786 { REG_SZ
, "Service", Service
},
2787 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
2788 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
2789 { REG_SZ
, "Class", Class
},
2790 { REG_SZ
, "ClassGUID", ClassGUID
},
2791 { REG_SZ
, "Driver", Driver
},
2792 { REG_DWORD
, "ConfigFlags", ConfigFlags
},
2793 { REG_SZ
, "Mfg", Mfg
},
2794 { REG_SZ
, "FriendlyName", FriendlyName
},
2795 { REG_SZ
, "LocationInformation", LocationInformation
},
2796 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
2797 { REG_DWORD
, "Capabilities", Capabilities
},
2798 { REG_DWORD
, "UINumber", UINumber
},
2799 { REG_MULTI_SZ
, "UpperFilters", UpperFilters
},
2800 { REG_MULTI_SZ
, "LowerFilters", LowerFilters
},
2803 /***********************************************************************
2804 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
2806 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
2807 HDEVINFO DeviceInfoSet
,
2808 PSP_DEVINFO_DATA DeviceInfoData
,
2810 PDWORD PropertyRegDataType
,
2811 PBYTE PropertyBuffer
,
2812 DWORD PropertyBufferSize
,
2813 PDWORD RequiredSize
)
2816 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2817 struct DeviceInfo
*devInfo
;
2819 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
2820 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
2823 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2825 SetLastError(ERROR_INVALID_HANDLE
);
2828 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2830 SetLastError(ERROR_INVALID_HANDLE
);
2833 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2834 || !DeviceInfoData
->Reserved
)
2836 SetLastError(ERROR_INVALID_PARAMETER
);
2839 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2840 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
2841 && PropertyMap
[Property
].nameA
)
2843 DWORD size
= PropertyBufferSize
;
2844 LONG l
= RegQueryValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
,
2845 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
2848 *RequiredSize
= size
;
2857 /***********************************************************************
2858 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
2860 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
2861 HDEVINFO DeviceInfoSet
,
2862 PSP_DEVINFO_DATA DeviceInfoData
,
2864 PDWORD PropertyRegDataType
,
2865 PBYTE PropertyBuffer
,
2866 DWORD PropertyBufferSize
,
2867 PDWORD RequiredSize
)
2870 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2871 struct DeviceInfo
*devInfo
;
2873 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
2874 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
2877 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2879 SetLastError(ERROR_INVALID_HANDLE
);
2882 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2884 SetLastError(ERROR_INVALID_HANDLE
);
2887 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2888 || !DeviceInfoData
->Reserved
)
2890 SetLastError(ERROR_INVALID_PARAMETER
);
2893 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2894 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
2895 && PropertyMap
[Property
].nameW
)
2897 DWORD size
= PropertyBufferSize
;
2898 LONG l
= RegQueryValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
,
2899 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
2902 *RequiredSize
= size
;
2911 /***********************************************************************
2912 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
2914 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
2915 HDEVINFO DeviceInfoSet
,
2916 PSP_DEVINFO_DATA DeviceInfoData
,
2918 const BYTE
*PropertyBuffer
,
2919 DWORD PropertyBufferSize
)
2922 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2923 struct DeviceInfo
*devInfo
;
2925 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
2926 PropertyBuffer
, PropertyBufferSize
);
2928 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2930 SetLastError(ERROR_INVALID_HANDLE
);
2933 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2935 SetLastError(ERROR_INVALID_HANDLE
);
2938 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2939 || !DeviceInfoData
->Reserved
)
2941 SetLastError(ERROR_INVALID_PARAMETER
);
2944 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2945 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
2946 && PropertyMap
[Property
].nameA
)
2948 LONG l
= RegSetValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
, 0,
2949 PropertyMap
[Property
].regType
, PropertyBuffer
,
2950 PropertyBufferSize
);
2959 /***********************************************************************
2960 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
2962 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
2963 HDEVINFO DeviceInfoSet
,
2964 PSP_DEVINFO_DATA DeviceInfoData
,
2966 const BYTE
*PropertyBuffer
,
2967 DWORD PropertyBufferSize
)
2970 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2971 struct DeviceInfo
*devInfo
;
2973 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
2974 PropertyBuffer
, PropertyBufferSize
);
2976 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2978 SetLastError(ERROR_INVALID_HANDLE
);
2981 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2983 SetLastError(ERROR_INVALID_HANDLE
);
2986 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2987 || !DeviceInfoData
->Reserved
)
2989 SetLastError(ERROR_INVALID_PARAMETER
);
2992 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2993 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
2994 && PropertyMap
[Property
].nameW
)
2996 LONG l
= RegSetValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
, 0,
2997 PropertyMap
[Property
].regType
, PropertyBuffer
,
2998 PropertyBufferSize
);
3007 /***********************************************************************
3008 * SetupDiInstallClassA (SETUPAPI.@)
3010 BOOL WINAPI
SetupDiInstallClassA(
3016 UNICODE_STRING FileNameW
;
3019 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW
, InfFileName
))
3021 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3025 Result
= SetupDiInstallClassW(hwndParent
, FileNameW
.Buffer
, Flags
, FileQueue
);
3027 RtlFreeUnicodeString(&FileNameW
);
3032 static HKEY
CreateClassKey(HINF hInf
)
3034 WCHAR FullBuffer
[MAX_PATH
];
3035 WCHAR Buffer
[MAX_PATH
];
3039 if (!SetupGetLineTextW(NULL
,
3047 return INVALID_HANDLE_VALUE
;
3050 lstrcpyW(FullBuffer
, ControlClass
);
3051 lstrcatW(FullBuffer
, Buffer
);
3053 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3059 if (!SetupGetLineTextW(NULL
,
3067 return INVALID_HANDLE_VALUE
;
3070 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3074 REG_OPTION_NON_VOLATILE
,
3080 return INVALID_HANDLE_VALUE
;
3085 if (RegSetValueExW(hClassKey
,
3090 RequiredSize
* sizeof(WCHAR
)))
3092 RegCloseKey(hClassKey
);
3093 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3095 return INVALID_HANDLE_VALUE
;
3101 /***********************************************************************
3102 * SetupDiInstallClassW (SETUPAPI.@)
3104 BOOL WINAPI
SetupDiInstallClassW(
3110 WCHAR SectionName
[MAX_PATH
];
3111 DWORD SectionNameLength
= 0;
3113 BOOL bFileQueueCreated
= FALSE
;
3119 if ((Flags
& DI_NOVCP
) && (FileQueue
== NULL
|| FileQueue
== INVALID_HANDLE_VALUE
))
3121 SetLastError(ERROR_INVALID_PARAMETER
);
3125 /* Open the .inf file */
3126 hInf
= SetupOpenInfFileW(InfFileName
,
3130 if (hInf
== INVALID_HANDLE_VALUE
)
3136 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3137 hClassKey
= CreateClassKey(hInf
);
3138 if (hClassKey
== INVALID_HANDLE_VALUE
)
3140 SetupCloseInfFile(hInf
);
3145 /* Try to append a layout file */
3147 SetupOpenAppendInfFileW(NULL
, hInf
, NULL
);
3150 /* Retrieve the actual section name */
3151 SetupDiGetActualSectionToInstallW(hInf
,
3159 if (!(Flags
& DI_NOVCP
))
3161 FileQueue
= SetupOpenFileQueue();
3162 if (FileQueue
== INVALID_HANDLE_VALUE
)
3164 SetupCloseInfFile(hInf
);
3168 bFileQueueCreated
= TRUE
;
3173 SetupInstallFromInfSectionW(NULL
,
3182 INVALID_HANDLE_VALUE
,
3185 /* FIXME: More code! */
3187 if (bFileQueueCreated
)
3188 SetupCloseFileQueue(FileQueue
);
3190 SetupCloseInfFile(hInf
);
3196 /***********************************************************************
3197 * SetupDiOpenClassRegKey (SETUPAPI.@)
3199 HKEY WINAPI
SetupDiOpenClassRegKey(
3200 const GUID
* ClassGuid
,
3203 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3204 DIOCR_INSTALLER
, NULL
, NULL
);
3208 /***********************************************************************
3209 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3211 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3212 const GUID
* ClassGuid
,
3218 PWSTR MachineNameW
= NULL
;
3225 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
3226 if (MachineNameW
== NULL
)
3227 return INVALID_HANDLE_VALUE
;
3230 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3231 Flags
, MachineNameW
, Reserved
);
3233 MyFree(MachineNameW
);
3239 /***********************************************************************
3240 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3242 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3243 const GUID
* ClassGuid
,
3254 if (MachineName
!= NULL
)
3256 FIXME("Remote access not supported yet!\n");
3257 return INVALID_HANDLE_VALUE
;
3260 if (Flags
== DIOCR_INSTALLER
)
3262 lpKeyName
= ControlClass
;
3264 else if (Flags
== DIOCR_INTERFACE
)
3266 lpKeyName
= DeviceClasses
;
3270 ERR("Invalid Flags parameter!\n");
3271 SetLastError(ERROR_INVALID_PARAMETER
);
3272 return INVALID_HANDLE_VALUE
;
3277 if ((l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3284 hClassesKey
= INVALID_HANDLE_VALUE
;
3290 WCHAR bracedGuidString
[39];
3292 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3294 if (!(l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3300 if ((l
= RegOpenKeyExW(hClassesKey
,
3307 key
= INVALID_HANDLE_VALUE
;
3309 RegCloseKey(hClassesKey
);
3314 key
= INVALID_HANDLE_VALUE
;
3320 /***********************************************************************
3321 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3323 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3324 HDEVINFO DeviceInfoSet
,
3327 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3329 FIXME("%p %s %08x %p\n",
3330 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3334 /***********************************************************************
3335 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3337 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
3338 HDEVINFO DeviceInfoSet
,
3341 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3343 FIXME("%p %s %08x %p\n", DeviceInfoSet
,
3344 debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3348 /***********************************************************************
3349 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3351 BOOL WINAPI
SetupDiSetClassInstallParamsA(
3352 HDEVINFO DeviceInfoSet
,
3353 PSP_DEVINFO_DATA DeviceInfoData
,
3354 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3355 DWORD ClassInstallParamsSize
)
3357 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3358 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3362 /***********************************************************************
3363 * SetupDiCallClassInstaller (SETUPAPI.@)
3365 BOOL WINAPI
SetupDiCallClassInstaller(
3366 DI_FUNCTION InstallFunction
,
3367 HDEVINFO DeviceInfoSet
,
3368 PSP_DEVINFO_DATA DeviceInfoData
)
3370 FIXME("%d %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3374 /***********************************************************************
3375 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3377 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
3378 HDEVINFO DeviceInfoSet
,
3379 PSP_DEVINFO_DATA DeviceInfoData
,
3380 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3382 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3386 /***********************************************************************
3387 * SetupDiOpenDevRegKey (SETUPAPI.@)
3389 HKEY WINAPI
SetupDiOpenDevRegKey(
3390 HDEVINFO DeviceInfoSet
,
3391 PSP_DEVINFO_DATA DeviceInfoData
,
3397 FIXME("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
3398 Scope
, HwProfile
, KeyType
, samDesired
);
3399 return INVALID_HANDLE_VALUE
;