2 * SetupAPI device installer
4 * Copyright 2000 Andreas Mohr for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
35 #include "wine/debug.h"
36 #include "wine/list.h"
37 #include "wine/unicode.h"
44 #include "setupapi_private.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
49 /* Unicode constants */
50 static const WCHAR ClassGUID
[] = {'C','l','a','s','s','G','U','I','D',0};
51 static const WCHAR Class
[] = {'C','l','a','s','s',0};
52 static const WCHAR ClassInstall32
[] = {'C','l','a','s','s','I','n','s','t','a','l','l','3','2',0};
53 static const WCHAR NoDisplayClass
[] = {'N','o','D','i','s','p','l','a','y','C','l','a','s','s',0};
54 static const WCHAR NoInstallClass
[] = {'N','o','I','n','s','t','a','l','l','C','l','a','s','s',0};
55 static const WCHAR NoUseClass
[] = {'N','o','U','s','e','C','l','a','s','s',0};
56 static const WCHAR NtExtension
[] = {'.','N','T',0};
57 static const WCHAR NtPlatformExtension
[] = {'.','N','T','x','8','6',0};
58 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
59 static const WCHAR WinExtension
[] = {'.','W','i','n',0};
61 /* Registry key and value names */
62 static const WCHAR ControlClass
[] = {'S','y','s','t','e','m','\\',
63 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
64 'C','o','n','t','r','o','l','\\',
65 'C','l','a','s','s',0};
67 static const WCHAR DeviceClasses
[] = {'S','y','s','t','e','m','\\',
68 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
69 'C','o','n','t','r','o','l','\\',
70 'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
71 static const WCHAR Enum
[] = {'S','y','s','t','e','m','\\',
72 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
74 static const WCHAR DeviceDesc
[] = {'D','e','v','i','c','e','D','e','s','c',0};
75 static const WCHAR DeviceInstance
[] = {'D','e','v','i','c','e','I','n','s','t','a','n','c','e',0};
76 static const WCHAR HardwareId
[] = {'H','a','r','d','w','a','r','e','I','D',0};
77 static const WCHAR CompatibleIDs
[] = {'C','o','m','p','a','t','i','b','l','e','I','d','s',0};
78 static const WCHAR Service
[] = {'S','e','r','v','i','c','e',0};
79 static const WCHAR Driver
[] = {'D','r','i','v','e','r',0};
80 static const WCHAR ConfigFlags
[] = {'C','o','n','f','i','g','F','l','a','g','s',0};
81 static const WCHAR Mfg
[] = {'M','f','g',0};
82 static const WCHAR FriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
83 static const WCHAR LocationInformation
[] = {'L','o','c','a','t','i','o','n','I','n','f','o','r','m','a','t','i','o','n',0};
84 static const WCHAR Capabilities
[] = {'C','a','p','a','b','i','l','i','t','i','e','s',0};
85 static const WCHAR UINumber
[] = {'U','I','N','u','m','b','e','r',0};
86 static const WCHAR UpperFilters
[] = {'U','p','p','e','r','F','i','l','t','e','r','s',0};
87 static const WCHAR LowerFilters
[] = {'L','o','w','e','r','F','i','l','t','e','r','s',0};
88 static const WCHAR Phantom
[] = {'P','h','a','n','t','o','m',0};
89 static const WCHAR SymbolicLink
[] = {'S','y','m','b','o','l','i','c','L','i','n','k',0};
91 /* is used to identify if a DeviceInfoSet pointer is
93 #define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff056
97 DWORD magic
; /* if is equal to SETUP_DEVICE_INFO_SET_MAGIC struct is okay */
104 struct DeviceInstance
107 SP_DEVINFO_DATA data
;
110 /* Pointed to by SP_DEVICE_INTERFACE_DATA's Reserved member */
113 LPWSTR referenceString
;
115 PSP_DEVINFO_DATA device
;
118 /* A device may have multiple instances of the same interface, so this holds
119 * each instance belonging to a particular interface.
121 struct InterfaceInstances
125 DWORD cInstancesAllocated
;
126 SP_DEVICE_INTERFACE_DATA
*instances
;
130 /* Pointed to by SP_DEVINFO_DATA's Reserved member */
133 struct DeviceInfoSet
*set
;
138 struct list interfaces
;
141 static void SETUPDI_GuidToString(const GUID
*guid
, LPWSTR guidStr
)
143 static const WCHAR fmt
[] = {'{','%','0','8','X','-','%','0','4','X','-',
144 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
145 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
148 sprintfW(guidStr
, fmt
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
149 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
150 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
153 static void SETUPDI_FreeInterfaceInstances(struct InterfaceInstances
*instances
)
157 for (i
= 0; i
< instances
->cInstances
; i
++)
159 struct InterfaceInfo
*ifaceInfo
=
160 (struct InterfaceInfo
*)instances
->instances
[i
].Reserved
;
162 if (ifaceInfo
->device
&& ifaceInfo
->device
->Reserved
)
164 struct DeviceInfo
*devInfo
=
165 (struct DeviceInfo
*)ifaceInfo
->device
->Reserved
;
167 if (devInfo
->phantom
)
168 SetupDiDeleteDeviceInterfaceRegKey(devInfo
->set
,
169 &instances
->instances
[i
], 0);
171 HeapFree(GetProcessHeap(), 0, ifaceInfo
->referenceString
);
172 HeapFree(GetProcessHeap(), 0, ifaceInfo
->symbolicLink
);
173 HeapFree(GetProcessHeap(), 0, ifaceInfo
);
175 HeapFree(GetProcessHeap(), 0, instances
->instances
);
178 /* Finds the interface with interface class InterfaceClassGuid in the device.
179 * Returns TRUE if found, and updates *interface to point to device's
180 * interfaces member where the given interface was found.
181 * Returns FALSE if not found.
183 static BOOL
SETUPDI_FindInterface(const struct DeviceInfo
*devInfo
,
184 const GUID
*InterfaceClassGuid
, struct InterfaceInstances
**interface
)
187 struct InterfaceInstances
*iface
;
189 TRACE("%s\n", debugstr_guid(InterfaceClassGuid
));
191 LIST_FOR_EACH_ENTRY(iface
, &devInfo
->interfaces
, struct InterfaceInstances
,
194 if (IsEqualGUID(&iface
->guid
, InterfaceClassGuid
))
201 TRACE("returning %d (%p)\n", found
, found
? *interface
: NULL
);
205 /* Finds the interface instance with reference string ReferenceString in the
206 * interface instance map. Returns TRUE if found, and updates instanceIndex to
207 * the index of the interface instance's instances member
208 * where the given instance was found. Returns FALSE if not found.
210 static BOOL
SETUPDI_FindInterfaceInstance(
211 const struct InterfaceInstances
*instances
,
212 LPCWSTR ReferenceString
, DWORD
*instanceIndex
)
217 TRACE("%s\n", debugstr_w(ReferenceString
));
219 for (i
= 0; !found
&& i
< instances
->cInstances
; i
++)
221 SP_DEVICE_INTERFACE_DATA
*ifaceData
= &instances
->instances
[i
];
222 struct InterfaceInfo
*ifaceInfo
=
223 (struct InterfaceInfo
*)ifaceData
->Reserved
;
225 if (!ReferenceString
&& !ifaceInfo
->referenceString
)
230 else if (ReferenceString
&& ifaceInfo
->referenceString
&&
231 !lstrcmpiW(ifaceInfo
->referenceString
, ReferenceString
))
237 TRACE("returning %d (%d)\n", found
, found
? *instanceIndex
: 0);
241 static LPWSTR
SETUPDI_CreateSymbolicLinkPath(LPCWSTR instanceId
,
242 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
)
244 static const WCHAR fmt
[] = {'\\','\\','?','\\','%','s','#','%','s',0};
249 SETUPDI_GuidToString(InterfaceClassGuid
, guidStr
);
250 /* omit length of format specifiers, but include NULL terminator: */
251 len
= lstrlenW(fmt
) - 4 + 1;
252 len
+= lstrlenW(instanceId
) + lstrlenW(guidStr
);
253 if (ReferenceString
&& *ReferenceString
)
255 /* space for a hash between string and reference string: */
256 len
+= lstrlenW(ReferenceString
) + 1;
258 ret
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
261 int printed
= sprintfW(ret
, fmt
, instanceId
, guidStr
);
264 /* replace '\\' with '#' after the "\\\\?\\" beginning */
265 for (ptr
= strchrW(ret
+ 4, '\\'); ptr
; ptr
= strchrW(ptr
+ 1, '\\'))
267 if (ReferenceString
&& *ReferenceString
)
270 lstrcpyW(ret
+ printed
+ 1, ReferenceString
);
276 /* Adds an interface with the given interface class and reference string to
277 * the device, if it doesn't already exist in the device. If iface is not
278 * NULL, returns a pointer to the newly added (or already existing) interface.
280 static BOOL
SETUPDI_AddInterfaceInstance(PSP_DEVINFO_DATA DeviceInfoData
,
281 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
,
282 SP_DEVICE_INTERFACE_DATA
**ifaceData
)
284 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
285 BOOL newInterface
= FALSE
, ret
;
286 struct InterfaceInstances
*iface
= NULL
;
288 TRACE("%p %s %s %p\n", devInfo
, debugstr_guid(InterfaceClassGuid
),
289 debugstr_w(ReferenceString
), iface
);
291 if (!(ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
293 iface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
294 sizeof(struct InterfaceInstances
));
297 list_add_tail(&devInfo
->interfaces
, &iface
->entry
);
303 DWORD instanceIndex
= 0;
305 if (!(ret
= SETUPDI_FindInterfaceInstance(iface
, ReferenceString
,
308 SP_DEVICE_INTERFACE_DATA
*instance
= NULL
;
310 if (!iface
->cInstancesAllocated
)
312 iface
->instances
= HeapAlloc(GetProcessHeap(), 0,
313 sizeof(SP_DEVICE_INTERFACE_DATA
));
314 if (iface
->instances
)
315 instance
= &iface
->instances
[iface
->cInstancesAllocated
++];
317 else if (iface
->cInstances
== iface
->cInstancesAllocated
)
319 iface
->instances
= HeapReAlloc(GetProcessHeap(), 0,
321 (iface
->cInstancesAllocated
+ 1) *
322 sizeof(SP_DEVICE_INTERFACE_DATA
));
323 if (iface
->instances
)
324 instance
= &iface
->instances
[iface
->cInstancesAllocated
++];
327 instance
= &iface
->instances
[iface
->cInstances
];
330 struct InterfaceInfo
*ifaceInfo
= HeapAlloc(GetProcessHeap(),
331 0, sizeof(struct InterfaceInfo
));
336 ifaceInfo
->device
= DeviceInfoData
;
337 ifaceInfo
->symbolicLink
= SETUPDI_CreateSymbolicLinkPath(
338 devInfo
->instanceId
, InterfaceClassGuid
,
342 ifaceInfo
->referenceString
=
343 HeapAlloc(GetProcessHeap(), 0,
344 (lstrlenW(ReferenceString
) + 1) *
346 if (ifaceInfo
->referenceString
)
347 lstrcpyW(ifaceInfo
->referenceString
,
353 ifaceInfo
->referenceString
= NULL
;
360 sizeof(SP_DEVICE_INTERFACE_DATA
);
361 instance
->InterfaceClassGuid
= *InterfaceClassGuid
;
362 instance
->Flags
= SPINT_ACTIVE
; /* FIXME */
363 instance
->Reserved
= (ULONG_PTR
)ifaceInfo
;
365 iface
->guid
= *InterfaceClassGuid
;
366 key
= SetupDiCreateDeviceInterfaceRegKeyW(devInfo
->set
,
367 instance
, 0, KEY_WRITE
, NULL
, NULL
);
368 if (key
!= INVALID_HANDLE_VALUE
)
370 RegSetValueExW(key
, SymbolicLink
, 0, REG_SZ
,
371 (BYTE
*)ifaceInfo
->symbolicLink
,
372 lstrlenW(ifaceInfo
->symbolicLink
) *
377 *ifaceData
= instance
;
380 HeapFree(GetProcessHeap(), 0, ifaceInfo
);
387 *ifaceData
= &iface
->instances
[instanceIndex
];
392 TRACE("returning %d\n", ret
);
396 static BOOL
SETUPDI_SetInterfaceSymbolicLink(SP_DEVICE_INTERFACE_DATA
*iface
,
397 LPCWSTR symbolicLink
)
399 struct InterfaceInfo
*info
= (struct InterfaceInfo
*)iface
->Reserved
;
404 HeapFree(GetProcessHeap(), 0, info
->symbolicLink
);
405 info
->symbolicLink
= HeapAlloc(GetProcessHeap(), 0,
406 (lstrlenW(symbolicLink
) + 1) * sizeof(WCHAR
));
407 if (info
->symbolicLink
)
409 lstrcpyW(info
->symbolicLink
, symbolicLink
);
416 static HKEY
SETUPDI_CreateDevKey(struct DeviceInfo
*devInfo
)
418 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
421 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
422 NULL
, &enumKey
, NULL
);
425 RegCreateKeyExW(enumKey
, devInfo
->instanceId
, 0, NULL
, 0,
426 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
427 RegCloseKey(enumKey
);
432 static HKEY
SETUPDI_CreateDrvKey(struct DeviceInfo
*devInfo
)
434 static const WCHAR slash
[] = { '\\',0 };
435 WCHAR classKeyPath
[MAX_PATH
];
436 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
439 lstrcpyW(classKeyPath
, ControlClass
);
440 lstrcatW(classKeyPath
, slash
);
441 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
442 classKeyPath
+ lstrlenW(classKeyPath
));
443 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
444 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
447 static const WCHAR fmt
[] = { '%','0','4','u',0 };
450 sprintfW(devId
, fmt
, devInfo
->devId
);
451 RegCreateKeyExW(classKey
, devId
, 0, NULL
, 0, KEY_READ
| KEY_WRITE
,
453 RegCloseKey(classKey
);
458 static struct DeviceInfo
*SETUPDI_AllocateDeviceInfo(struct DeviceInfoSet
*set
,
459 DWORD devId
, LPCWSTR instanceId
, BOOL phantom
)
461 struct DeviceInfo
*devInfo
= NULL
;
462 HANDLE devInst
= GlobalAlloc(GMEM_FIXED
, sizeof(struct DeviceInfo
));
464 devInfo
= GlobalLock(devInst
);
469 devInfo
->devId
= (DWORD
)devInst
;
471 devInfo
->instanceId
= HeapAlloc(GetProcessHeap(), 0,
472 (lstrlenW(instanceId
) + 1) * sizeof(WCHAR
));
473 if (devInfo
->instanceId
)
475 devInfo
->key
= INVALID_HANDLE_VALUE
;
476 devInfo
->phantom
= phantom
;
477 lstrcpyW(devInfo
->instanceId
, instanceId
);
478 struprW(devInfo
->instanceId
);
479 devInfo
->key
= SETUPDI_CreateDevKey(devInfo
);
480 if (devInfo
->key
!= INVALID_HANDLE_VALUE
)
483 RegSetValueExW(devInfo
->key
, Phantom
, 0, REG_DWORD
,
484 (LPBYTE
)&phantom
, sizeof(phantom
));
486 list_init(&devInfo
->interfaces
);
487 GlobalUnlock(devInst
);
491 GlobalUnlock(devInst
);
499 static void SETUPDI_FreeDeviceInfo(struct DeviceInfo
*devInfo
)
501 struct InterfaceInstances
*iface
, *next
;
503 if (devInfo
->key
!= INVALID_HANDLE_VALUE
)
504 RegCloseKey(devInfo
->key
);
505 if (devInfo
->phantom
)
510 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0,
511 KEY_ALL_ACCESS
, NULL
, &enumKey
, NULL
);
514 RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
515 RegCloseKey(enumKey
);
518 HeapFree(GetProcessHeap(), 0, devInfo
->instanceId
);
519 LIST_FOR_EACH_ENTRY_SAFE(iface
, next
, &devInfo
->interfaces
,
520 struct InterfaceInstances
, entry
)
522 list_remove(&iface
->entry
);
523 SETUPDI_FreeInterfaceInstances(iface
);
524 HeapFree(GetProcessHeap(), 0, iface
);
526 GlobalFree((HANDLE
)devInfo
->devId
);
529 /* Adds a device with GUID guid and identifer devInst to set. Allocates a
530 * struct DeviceInfo, and points the returned device info's Reserved member
531 * to it. "Phantom" devices are deleted from the registry when closed.
532 * Returns a pointer to the newly allocated device info.
534 static BOOL
SETUPDI_AddDeviceToSet(struct DeviceInfoSet
*set
,
539 SP_DEVINFO_DATA
**dev
)
542 struct DeviceInfo
*devInfo
= SETUPDI_AllocateDeviceInfo(set
, set
->cDevices
,
543 instanceId
, phantom
);
545 TRACE("%p, %s, %d, %s, %d\n", set
, debugstr_guid(guid
), devInst
,
546 debugstr_w(instanceId
), phantom
);
550 struct DeviceInstance
*devInst
=
551 HeapAlloc(GetProcessHeap(), 0, sizeof(struct DeviceInstance
));
555 WCHAR classGuidStr
[39];
557 list_add_tail(&set
->devices
, &devInst
->entry
);
559 devInst
->data
.cbSize
= sizeof(SP_DEVINFO_DATA
);
560 devInst
->data
.ClassGuid
= *guid
;
561 devInst
->data
.DevInst
= devInfo
->devId
;
562 devInst
->data
.Reserved
= (ULONG_PTR
)devInfo
;
563 SETUPDI_GuidToString(guid
, classGuidStr
);
564 SetupDiSetDeviceRegistryPropertyW((HDEVINFO
)set
,
565 &devInst
->data
, SPDRP_CLASSGUID
, (const BYTE
*)classGuidStr
,
566 lstrlenW(classGuidStr
) * sizeof(WCHAR
));
567 if (dev
) *dev
= &devInst
->data
;
572 HeapFree(GetProcessHeap(), 0, devInfo
);
573 SetLastError(ERROR_OUTOFMEMORY
);
579 /***********************************************************************
580 * SetupDiBuildClassInfoList (SETUPAPI.@)
582 * Returns a list of setup class GUIDs that identify the classes
583 * that are installed on a local machine.
586 * Flags [I] control exclusion of classes from the list.
587 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
588 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
589 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
595 BOOL WINAPI
SetupDiBuildClassInfoList(
597 LPGUID ClassGuidList
,
598 DWORD ClassGuidListSize
,
602 return SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
603 ClassGuidListSize
, RequiredSize
,
607 /***********************************************************************
608 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
610 * Returns a list of setup class GUIDs that identify the classes
611 * that are installed on a local or remote macine.
614 * Flags [I] control exclusion of classes from the list.
615 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
616 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
617 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
618 * MachineName [I] name of a remote machine.
619 * Reserved [I] must be NULL.
625 BOOL WINAPI
SetupDiBuildClassInfoListExA(
627 LPGUID ClassGuidList
,
628 DWORD ClassGuidListSize
,
633 LPWSTR MachineNameW
= NULL
;
640 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
641 if (MachineNameW
== NULL
) return FALSE
;
644 bResult
= SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
645 ClassGuidListSize
, RequiredSize
,
646 MachineNameW
, Reserved
);
648 MyFree(MachineNameW
);
653 /***********************************************************************
654 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
656 * Returns a list of setup class GUIDs that identify the classes
657 * that are installed on a local or remote macine.
660 * Flags [I] control exclusion of classes from the list.
661 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
662 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
663 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
664 * MachineName [I] name of a remote machine.
665 * Reserved [I] must be NULL.
671 BOOL WINAPI
SetupDiBuildClassInfoListExW(
673 LPGUID ClassGuidList
,
674 DWORD ClassGuidListSize
,
685 DWORD dwGuidListIndex
= 0;
689 if (RequiredSize
!= NULL
)
692 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
697 if (hClassesKey
== INVALID_HANDLE_VALUE
)
702 for (dwIndex
= 0; ; dwIndex
++)
705 lError
= RegEnumKeyExW(hClassesKey
,
713 TRACE("RegEnumKeyExW() returns %d\n", lError
);
714 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
716 TRACE("Key name: %p\n", szKeyName
);
718 if (RegOpenKeyExW(hClassesKey
,
724 RegCloseKey(hClassesKey
);
728 if (!RegQueryValueExW(hClassKey
,
735 TRACE("'NoUseClass' value found!\n");
736 RegCloseKey(hClassKey
);
740 if ((Flags
& DIBCI_NOINSTALLCLASS
) &&
741 (!RegQueryValueExW(hClassKey
,
748 TRACE("'NoInstallClass' value found!\n");
749 RegCloseKey(hClassKey
);
753 if ((Flags
& DIBCI_NODISPLAYCLASS
) &&
754 (!RegQueryValueExW(hClassKey
,
761 TRACE("'NoDisplayClass' value found!\n");
762 RegCloseKey(hClassKey
);
766 RegCloseKey(hClassKey
);
768 TRACE("Guid: %p\n", szKeyName
);
769 if (dwGuidListIndex
< ClassGuidListSize
)
771 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
775 TRACE("Guid: %p\n", &szKeyName
[1]);
777 UuidFromStringW(&szKeyName
[1],
778 &ClassGuidList
[dwGuidListIndex
]);
784 if (lError
!= ERROR_SUCCESS
)
788 RegCloseKey(hClassesKey
);
790 if (RequiredSize
!= NULL
)
791 *RequiredSize
= dwGuidListIndex
;
793 if (ClassGuidListSize
< dwGuidListIndex
)
795 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
802 /***********************************************************************
803 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
805 BOOL WINAPI
SetupDiClassGuidsFromNameA(
807 LPGUID ClassGuidList
,
808 DWORD ClassGuidListSize
,
811 return SetupDiClassGuidsFromNameExA(ClassName
, ClassGuidList
,
812 ClassGuidListSize
, RequiredSize
,
816 /***********************************************************************
817 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
819 BOOL WINAPI
SetupDiClassGuidsFromNameW(
821 LPGUID ClassGuidList
,
822 DWORD ClassGuidListSize
,
825 return SetupDiClassGuidsFromNameExW(ClassName
, ClassGuidList
,
826 ClassGuidListSize
, RequiredSize
,
830 /***********************************************************************
831 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
833 BOOL WINAPI
SetupDiClassGuidsFromNameExA(
835 LPGUID ClassGuidList
,
836 DWORD ClassGuidListSize
,
841 LPWSTR ClassNameW
= NULL
;
842 LPWSTR MachineNameW
= NULL
;
845 ClassNameW
= MultiByteToUnicode(ClassName
, CP_ACP
);
846 if (ClassNameW
== NULL
)
851 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
852 if (MachineNameW
== NULL
)
859 bResult
= SetupDiClassGuidsFromNameExW(ClassNameW
, ClassGuidList
,
860 ClassGuidListSize
, RequiredSize
,
861 MachineNameW
, Reserved
);
863 MyFree(MachineNameW
);
869 /***********************************************************************
870 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
872 BOOL WINAPI
SetupDiClassGuidsFromNameExW(
874 LPGUID ClassGuidList
,
875 DWORD ClassGuidListSize
,
881 WCHAR szClassName
[256];
887 DWORD dwGuidListIndex
= 0;
889 if (RequiredSize
!= NULL
)
892 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
897 if (hClassesKey
== INVALID_HANDLE_VALUE
)
902 for (dwIndex
= 0; ; dwIndex
++)
905 lError
= RegEnumKeyExW(hClassesKey
,
913 TRACE("RegEnumKeyExW() returns %d\n", lError
);
914 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
916 TRACE("Key name: %p\n", szKeyName
);
918 if (RegOpenKeyExW(hClassesKey
,
924 RegCloseKey(hClassesKey
);
928 dwLength
= 256 * sizeof(WCHAR
);
929 if (!RegQueryValueExW(hClassKey
,
936 TRACE("Class name: %p\n", szClassName
);
938 if (strcmpiW(szClassName
, ClassName
) == 0)
940 TRACE("Found matching class name\n");
942 TRACE("Guid: %p\n", szKeyName
);
943 if (dwGuidListIndex
< ClassGuidListSize
)
945 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
949 TRACE("Guid: %p\n", &szKeyName
[1]);
951 UuidFromStringW(&szKeyName
[1],
952 &ClassGuidList
[dwGuidListIndex
]);
959 RegCloseKey(hClassKey
);
962 if (lError
!= ERROR_SUCCESS
)
966 RegCloseKey(hClassesKey
);
968 if (RequiredSize
!= NULL
)
969 *RequiredSize
= dwGuidListIndex
;
971 if (ClassGuidListSize
< dwGuidListIndex
)
973 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
980 /***********************************************************************
981 * SetupDiClassNameFromGuidA (SETUPAPI.@)
983 BOOL WINAPI
SetupDiClassNameFromGuidA(
984 const GUID
* ClassGuid
,
989 return SetupDiClassNameFromGuidExA(ClassGuid
, ClassName
,
990 ClassNameSize
, RequiredSize
,
994 /***********************************************************************
995 * SetupDiClassNameFromGuidW (SETUPAPI.@)
997 BOOL WINAPI
SetupDiClassNameFromGuidW(
998 const GUID
* ClassGuid
,
1000 DWORD ClassNameSize
,
1001 PDWORD RequiredSize
)
1003 return SetupDiClassNameFromGuidExW(ClassGuid
, ClassName
,
1004 ClassNameSize
, RequiredSize
,
1008 /***********************************************************************
1009 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1011 BOOL WINAPI
SetupDiClassNameFromGuidExA(
1012 const GUID
* ClassGuid
,
1014 DWORD ClassNameSize
,
1015 PDWORD RequiredSize
,
1019 WCHAR ClassNameW
[MAX_CLASS_NAME_LEN
];
1020 LPWSTR MachineNameW
= NULL
;
1024 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1025 ret
= SetupDiClassNameFromGuidExW(ClassGuid
, ClassNameW
, MAX_CLASS_NAME_LEN
,
1026 NULL
, MachineNameW
, Reserved
);
1029 int len
= WideCharToMultiByte(CP_ACP
, 0, ClassNameW
, -1, ClassName
,
1030 ClassNameSize
, NULL
, NULL
);
1032 if (!ClassNameSize
&& RequiredSize
)
1033 *RequiredSize
= len
;
1035 MyFree(MachineNameW
);
1039 /***********************************************************************
1040 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1042 BOOL WINAPI
SetupDiClassNameFromGuidExW(
1043 const GUID
* ClassGuid
,
1045 DWORD ClassNameSize
,
1046 PDWORD RequiredSize
,
1053 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1058 if (hKey
== INVALID_HANDLE_VALUE
)
1063 if (RequiredSize
!= NULL
)
1066 if (RegQueryValueExW(hKey
,
1077 *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1080 dwLength
= ClassNameSize
* sizeof(WCHAR
);
1081 if (RegQueryValueExW(hKey
,
1097 /***********************************************************************
1098 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1101 SetupDiCreateDeviceInfoList(const GUID
*ClassGuid
,
1104 return SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
, NULL
, NULL
);
1107 /***********************************************************************
1108 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1111 SetupDiCreateDeviceInfoListExA(const GUID
*ClassGuid
,
1116 LPWSTR MachineNameW
= NULL
;
1123 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1124 if (MachineNameW
== NULL
)
1125 return INVALID_HANDLE_VALUE
;
1128 hDevInfo
= SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
,
1129 MachineNameW
, Reserved
);
1131 MyFree(MachineNameW
);
1136 /***********************************************************************
1137 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1139 * Create an empty DeviceInfoSet list.
1142 * ClassGuid [I] if not NULL only devices with GUID ClassGuid are associated
1144 * hwndParent [I] hwnd needed for interface related actions.
1145 * MachineName [I] name of machine to create emtpy DeviceInfoSet list, if NULL
1146 * local registry will be used.
1147 * Reserved [I] must be NULL
1150 * Success: empty list.
1151 * Failure: INVALID_HANDLE_VALUE.
1154 SetupDiCreateDeviceInfoListExW(const GUID
*ClassGuid
,
1159 struct DeviceInfoSet
*list
= NULL
;
1160 DWORD size
= sizeof(struct DeviceInfoSet
);
1162 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1163 debugstr_w(MachineName
), Reserved
);
1165 if (MachineName
!= NULL
)
1167 FIXME("remote support is not implemented\n");
1168 SetLastError(ERROR_INVALID_MACHINENAME
);
1169 return INVALID_HANDLE_VALUE
;
1172 if (Reserved
!= NULL
)
1174 SetLastError(ERROR_INVALID_PARAMETER
);
1175 return INVALID_HANDLE_VALUE
;
1178 list
= HeapAlloc(GetProcessHeap(), 0, size
);
1181 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1182 return INVALID_HANDLE_VALUE
;
1185 list
->magic
= SETUP_DEVICE_INFO_SET_MAGIC
;
1186 list
->hwndParent
= hwndParent
;
1187 memcpy(&list
->ClassGuid
,
1188 ClassGuid
? ClassGuid
: &GUID_NULL
,
1189 sizeof(list
->ClassGuid
));
1191 list_init(&list
->devices
);
1193 return (HDEVINFO
)list
;
1196 /***********************************************************************
1197 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1199 HKEY WINAPI
SetupDiCreateDevRegKeyA(
1200 HDEVINFO DeviceInfoSet
,
1201 PSP_DEVINFO_DATA DeviceInfoData
,
1206 PCSTR InfSectionName
)
1208 PWSTR InfSectionNameW
= NULL
;
1211 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1212 HwProfile
, KeyType
, InfHandle
, debugstr_a(InfSectionName
));
1216 if (!InfSectionName
)
1218 SetLastError(ERROR_INVALID_PARAMETER
);
1219 return INVALID_HANDLE_VALUE
;
1223 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
1224 if (InfSectionNameW
== NULL
) return INVALID_HANDLE_VALUE
;
1227 key
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, Scope
,
1228 HwProfile
, KeyType
, InfHandle
, InfSectionNameW
);
1229 MyFree(InfSectionNameW
);
1233 /***********************************************************************
1234 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1236 HKEY WINAPI
SetupDiCreateDevRegKeyW(
1237 HDEVINFO DeviceInfoSet
,
1238 PSP_DEVINFO_DATA DeviceInfoData
,
1243 PCWSTR InfSectionName
)
1245 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1246 struct DeviceInfo
*devInfo
;
1247 HKEY key
= INVALID_HANDLE_VALUE
;
1249 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1250 HwProfile
, KeyType
, InfHandle
, debugstr_w(InfSectionName
));
1252 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1254 SetLastError(ERROR_INVALID_HANDLE
);
1255 return INVALID_HANDLE_VALUE
;
1257 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1259 SetLastError(ERROR_INVALID_HANDLE
);
1260 return INVALID_HANDLE_VALUE
;
1262 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1263 || !DeviceInfoData
->Reserved
)
1265 SetLastError(ERROR_INVALID_PARAMETER
);
1266 return INVALID_HANDLE_VALUE
;
1268 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1269 if (devInfo
->set
!= set
)
1271 SetLastError(ERROR_INVALID_PARAMETER
);
1272 return INVALID_HANDLE_VALUE
;
1274 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
1276 SetLastError(ERROR_INVALID_FLAGS
);
1277 return INVALID_HANDLE_VALUE
;
1279 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
1281 SetLastError(ERROR_INVALID_FLAGS
);
1282 return INVALID_HANDLE_VALUE
;
1284 if (devInfo
->phantom
)
1286 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
1287 return INVALID_HANDLE_VALUE
;
1289 if (Scope
!= DICS_FLAG_GLOBAL
)
1290 FIXME("unimplemented for scope %d\n", Scope
);
1294 key
= SETUPDI_CreateDevKey(devInfo
);
1297 key
= SETUPDI_CreateDrvKey(devInfo
);
1300 WARN("unknown KeyType %d\n", KeyType
);
1303 SetupInstallFromInfSectionW(NULL
, InfHandle
, InfSectionName
, SPINST_ALL
,
1304 NULL
, NULL
, SP_COPY_NEWER_ONLY
, NULL
, NULL
, DeviceInfoSet
,
1309 /***********************************************************************
1310 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1312 BOOL WINAPI
SetupDiCreateDeviceInfoA(
1313 HDEVINFO DeviceInfoSet
,
1315 CONST GUID
*ClassGuid
,
1316 PCSTR DeviceDescription
,
1318 DWORD CreationFlags
,
1319 PSP_DEVINFO_DATA DeviceInfoData
)
1322 LPWSTR DeviceNameW
= NULL
;
1323 LPWSTR DeviceDescriptionW
= NULL
;
1327 DeviceNameW
= MultiByteToUnicode(DeviceName
, CP_ACP
);
1328 if (DeviceNameW
== NULL
) return FALSE
;
1330 if (DeviceDescription
)
1332 DeviceDescriptionW
= MultiByteToUnicode(DeviceDescription
, CP_ACP
);
1333 if (DeviceDescriptionW
== NULL
)
1335 MyFree(DeviceNameW
);
1340 ret
= SetupDiCreateDeviceInfoW(DeviceInfoSet
, DeviceNameW
, ClassGuid
, DeviceDescriptionW
,
1341 hwndParent
, CreationFlags
, DeviceInfoData
);
1343 MyFree(DeviceNameW
);
1344 MyFree(DeviceDescriptionW
);
1349 static DWORD
SETUPDI_DevNameToDevID(LPCWSTR devName
)
1352 DWORD devNameLen
= lstrlenW(devName
), devInst
= 0;
1355 TRACE("%s\n", debugstr_w(devName
));
1356 for (ptr
= devName
; valid
&& *ptr
&& ptr
- devName
< devNameLen
; )
1361 devInst
|= *ptr
- '0';
1367 TRACE("%d\n", valid
? devInst
: 0xffffffff);
1368 return valid
? devInst
: 0xffffffff;
1371 /***********************************************************************
1372 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1374 BOOL WINAPI
SetupDiCreateDeviceInfoW(
1375 HDEVINFO DeviceInfoSet
,
1377 CONST GUID
*ClassGuid
,
1378 PCWSTR DeviceDescription
,
1380 DWORD CreationFlags
,
1381 PSP_DEVINFO_DATA DeviceInfoData
)
1383 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1384 BOOL ret
= FALSE
, allocatedInstanceId
= FALSE
;
1385 LPCWSTR instanceId
= NULL
;
1387 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet
, debugstr_w(DeviceName
),
1388 debugstr_guid(ClassGuid
), debugstr_w(DeviceDescription
),
1389 hwndParent
, CreationFlags
, DeviceInfoData
);
1393 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1396 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1398 SetLastError(ERROR_INVALID_HANDLE
);
1403 SetLastError(ERROR_INVALID_PARAMETER
);
1406 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1408 SetLastError(ERROR_INVALID_HANDLE
);
1411 if (!IsEqualGUID(&set
->ClassGuid
, &GUID_NULL
) &&
1412 !IsEqualGUID(ClassGuid
, &set
->ClassGuid
))
1414 SetLastError(ERROR_CLASS_MISMATCH
);
1417 if ((CreationFlags
& DICD_GENERATE_ID
))
1419 if (strchrW(DeviceName
, '\\'))
1420 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1423 static const WCHAR newDeviceFmt
[] = {'R','O','O','T','\\','%','s',
1424 '\\','%','0','4','d',0};
1429 DWORD highestDevID
= 0;
1430 struct DeviceInstance
*devInst
;
1432 LIST_FOR_EACH_ENTRY(devInst
, &set
->devices
, struct DeviceInstance
, entry
)
1434 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)devInst
->data
.Reserved
;
1435 LPCWSTR devName
= strrchrW(devInfo
->instanceId
, '\\');
1441 devName
= devInfo
->instanceId
;
1442 id
= SETUPDI_DevNameToDevID(devName
);
1443 if (id
!= 0xffffffff && id
> highestDevID
)
1446 devId
= highestDevID
+ 1;
1450 /* 17 == lstrlenW(L"Root\\") + lstrlenW("\\") + 1 + %d max size */
1451 instanceId
= HeapAlloc(GetProcessHeap(), 0,
1452 (17 + lstrlenW(DeviceName
)) * sizeof(WCHAR
));
1455 sprintfW((LPWSTR
)instanceId
, newDeviceFmt
, DeviceName
,
1457 allocatedInstanceId
= TRUE
;
1466 struct DeviceInstance
*devInst
;
1469 instanceId
= DeviceName
;
1470 LIST_FOR_EACH_ENTRY(devInst
, &set
->devices
, struct DeviceInstance
, entry
)
1472 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)devInst
->data
.Reserved
;
1474 if (!lstrcmpiW(DeviceName
, devInfo
->instanceId
))
1476 SetLastError(ERROR_DEVINST_ALREADY_EXISTS
);
1483 SP_DEVINFO_DATA
*dev
= NULL
;
1485 ret
= SETUPDI_AddDeviceToSet(set
, ClassGuid
, 0 /* FIXME: DevInst */,
1486 instanceId
, TRUE
, &dev
);
1489 if (DeviceDescription
)
1490 SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet
,
1491 dev
, SPDRP_DEVICEDESC
, (const BYTE
*)DeviceDescription
,
1492 lstrlenW(DeviceDescription
) * sizeof(WCHAR
));
1495 if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1497 SetLastError(ERROR_INVALID_USER_BUFFER
);
1501 *DeviceInfoData
= *dev
;
1505 if (allocatedInstanceId
)
1506 HeapFree(GetProcessHeap(), 0, (LPWSTR
)instanceId
);
1511 /***********************************************************************
1512 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1514 BOOL WINAPI
SetupDiRegisterDeviceInfo(
1515 HDEVINFO DeviceInfoSet
,
1516 PSP_DEVINFO_DATA DeviceInfoData
,
1518 PSP_DETSIG_CMPPROC CompareProc
,
1519 PVOID CompareContext
,
1520 PSP_DEVINFO_DATA DupDeviceInfoData
)
1522 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1523 struct DeviceInfo
*devInfo
;
1525 TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet
, DeviceInfoData
, Flags
,
1526 CompareProc
, CompareContext
, DupDeviceInfoData
);
1528 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1530 SetLastError(ERROR_INVALID_HANDLE
);
1533 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1535 SetLastError(ERROR_INVALID_HANDLE
);
1538 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1539 || !DeviceInfoData
->Reserved
)
1541 SetLastError(ERROR_INVALID_PARAMETER
);
1544 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1545 if (devInfo
->set
!= set
)
1547 SetLastError(ERROR_INVALID_PARAMETER
);
1550 if (devInfo
->phantom
)
1552 devInfo
->phantom
= FALSE
;
1553 RegDeleteValueW(devInfo
->key
, Phantom
);
1558 /***********************************************************************
1559 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1561 BOOL WINAPI
SetupDiEnumDeviceInfo(
1564 PSP_DEVINFO_DATA info
)
1568 TRACE("%p %d %p\n", devinfo
, index
, info
);
1572 SetLastError(ERROR_INVALID_PARAMETER
);
1575 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
1577 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
1578 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
1580 if (index
< list
->cDevices
)
1582 if (info
->cbSize
== sizeof(SP_DEVINFO_DATA
))
1584 struct DeviceInstance
*devInst
;
1587 LIST_FOR_EACH_ENTRY(devInst
, &list
->devices
,
1588 struct DeviceInstance
, entry
)
1592 *info
= devInst
->data
;
1599 SetLastError(ERROR_INVALID_USER_BUFFER
);
1602 SetLastError(ERROR_NO_MORE_ITEMS
);
1605 SetLastError(ERROR_INVALID_HANDLE
);
1608 SetLastError(ERROR_INVALID_HANDLE
);
1612 /***********************************************************************
1613 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1615 BOOL WINAPI
SetupDiGetDeviceInstanceIdA(
1616 HDEVINFO DeviceInfoSet
,
1617 PSP_DEVINFO_DATA DeviceInfoData
,
1618 PSTR DeviceInstanceId
,
1619 DWORD DeviceInstanceIdSize
,
1620 PDWORD RequiredSize
)
1626 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1627 DeviceInstanceIdSize
, RequiredSize
);
1629 SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1634 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1636 instanceId
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
1639 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1646 int len
= WideCharToMultiByte(CP_ACP
, 0, instanceId
, -1,
1648 DeviceInstanceIdSize
, NULL
, NULL
);
1654 if (len
> DeviceInstanceIdSize
)
1656 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1660 *RequiredSize
= len
;
1663 HeapFree(GetProcessHeap(), 0, instanceId
);
1668 /***********************************************************************
1669 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1671 BOOL WINAPI
SetupDiGetDeviceInstanceIdW(
1672 HDEVINFO DeviceInfoSet
,
1673 PSP_DEVINFO_DATA DeviceInfoData
,
1674 PWSTR DeviceInstanceId
,
1675 DWORD DeviceInstanceIdSize
,
1676 PDWORD RequiredSize
)
1678 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1679 struct DeviceInfo
*devInfo
;
1681 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1682 DeviceInstanceIdSize
, RequiredSize
);
1684 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1686 SetLastError(ERROR_INVALID_HANDLE
);
1689 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1691 SetLastError(ERROR_INVALID_HANDLE
);
1694 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1695 || !DeviceInfoData
->Reserved
)
1697 SetLastError(ERROR_INVALID_PARAMETER
);
1700 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1701 if (devInfo
->set
!= set
)
1703 SetLastError(ERROR_INVALID_PARAMETER
);
1706 TRACE("instance ID: %s\n", debugstr_w(devInfo
->instanceId
));
1707 if (DeviceInstanceIdSize
< lstrlenW(devInfo
->instanceId
) + 1)
1709 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1711 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1714 lstrcpyW(DeviceInstanceId
, devInfo
->instanceId
);
1716 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1720 /***********************************************************************
1721 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1723 BOOL WINAPI
SetupDiGetActualSectionToInstallA(
1725 PCSTR InfSectionName
,
1726 PSTR InfSectionWithExt
,
1727 DWORD InfSectionWithExtSize
,
1728 PDWORD RequiredSize
,
1735 /***********************************************************************
1736 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
1738 BOOL WINAPI
SetupDiGetActualSectionToInstallW(
1740 PCWSTR InfSectionName
,
1741 PWSTR InfSectionWithExt
,
1742 DWORD InfSectionWithExtSize
,
1743 PDWORD RequiredSize
,
1746 WCHAR szBuffer
[MAX_PATH
];
1749 LONG lLineCount
= -1;
1751 lstrcpyW(szBuffer
, InfSectionName
);
1752 dwLength
= lstrlenW(szBuffer
);
1754 if (OsVersionInfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
1756 /* Test section name with '.NTx86' extension */
1757 lstrcpyW(&szBuffer
[dwLength
], NtPlatformExtension
);
1758 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1760 if (lLineCount
== -1)
1762 /* Test section name with '.NT' extension */
1763 lstrcpyW(&szBuffer
[dwLength
], NtExtension
);
1764 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1769 /* Test section name with '.Win' extension */
1770 lstrcpyW(&szBuffer
[dwLength
], WinExtension
);
1771 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1774 if (lLineCount
== -1)
1776 /* Test section name without extension */
1777 szBuffer
[dwLength
] = 0;
1778 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1781 if (lLineCount
== -1)
1783 SetLastError(ERROR_INVALID_PARAMETER
);
1787 dwFullLength
= lstrlenW(szBuffer
);
1789 if (InfSectionWithExt
!= NULL
&& InfSectionWithExtSize
!= 0)
1791 if (InfSectionWithExtSize
< (dwFullLength
+ 1))
1793 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1797 lstrcpyW(InfSectionWithExt
, szBuffer
);
1798 if (Extension
!= NULL
)
1800 *Extension
= (dwLength
== dwFullLength
) ? NULL
: &InfSectionWithExt
[dwLength
];
1804 if (RequiredSize
!= NULL
)
1806 *RequiredSize
= dwFullLength
+ 1;
1812 /***********************************************************************
1813 * SetupDiGetClassDescriptionA (SETUPAPI.@)
1815 BOOL WINAPI
SetupDiGetClassDescriptionA(
1816 const GUID
* ClassGuid
,
1817 PSTR ClassDescription
,
1818 DWORD ClassDescriptionSize
,
1819 PDWORD RequiredSize
)
1821 return SetupDiGetClassDescriptionExA(ClassGuid
, ClassDescription
,
1822 ClassDescriptionSize
,
1823 RequiredSize
, NULL
, NULL
);
1826 /***********************************************************************
1827 * SetupDiGetClassDescriptionW (SETUPAPI.@)
1829 BOOL WINAPI
SetupDiGetClassDescriptionW(
1830 const GUID
* ClassGuid
,
1831 PWSTR ClassDescription
,
1832 DWORD ClassDescriptionSize
,
1833 PDWORD RequiredSize
)
1835 return SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescription
,
1836 ClassDescriptionSize
,
1837 RequiredSize
, NULL
, NULL
);
1840 /***********************************************************************
1841 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
1843 BOOL WINAPI
SetupDiGetClassDescriptionExA(
1844 const GUID
* ClassGuid
,
1845 PSTR ClassDescription
,
1846 DWORD ClassDescriptionSize
,
1847 PDWORD RequiredSize
,
1855 hKey
= SetupDiOpenClassRegKeyExA(ClassGuid
,
1860 if (hKey
== INVALID_HANDLE_VALUE
)
1862 WARN("SetupDiOpenClassRegKeyExA() failed (Error %u)\n", GetLastError());
1866 dwLength
= ClassDescriptionSize
;
1867 ret
= !RegQueryValueExA( hKey
, NULL
, NULL
, NULL
,
1868 (LPBYTE
)ClassDescription
, &dwLength
);
1869 if (RequiredSize
) *RequiredSize
= dwLength
;
1874 /***********************************************************************
1875 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
1877 BOOL WINAPI
SetupDiGetClassDescriptionExW(
1878 const GUID
* ClassGuid
,
1879 PWSTR ClassDescription
,
1880 DWORD ClassDescriptionSize
,
1881 PDWORD RequiredSize
,
1889 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1894 if (hKey
== INVALID_HANDLE_VALUE
)
1896 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
1900 dwLength
= ClassDescriptionSize
* sizeof(WCHAR
);
1901 ret
= !RegQueryValueExW( hKey
, NULL
, NULL
, NULL
,
1902 (LPBYTE
)ClassDescription
, &dwLength
);
1903 if (RequiredSize
) *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1908 /***********************************************************************
1909 * SetupDiGetClassDevsA (SETUPAPI.@)
1911 HDEVINFO WINAPI
SetupDiGetClassDevsA(
1918 LPWSTR enumstrW
= NULL
;
1922 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1923 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1926 ret
= INVALID_HANDLE_VALUE
;
1929 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1931 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, NULL
, NULL
,
1933 HeapFree(GetProcessHeap(), 0, enumstrW
);
1939 /***********************************************************************
1940 * SetupDiGetClassDevsExA (SETUPAPI.@)
1942 HDEVINFO WINAPI
SetupDiGetClassDevsExA(
1952 LPWSTR enumstrW
= NULL
, machineW
= NULL
;
1956 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1957 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1960 ret
= INVALID_HANDLE_VALUE
;
1963 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1967 int len
= MultiByteToWideChar(CP_ACP
, 0, machine
, -1, NULL
, 0);
1968 machineW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1971 HeapFree(GetProcessHeap(), 0, enumstrW
);
1972 ret
= INVALID_HANDLE_VALUE
;
1975 MultiByteToWideChar(CP_ACP
, 0, machine
, -1, machineW
, len
);
1977 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, deviceset
,
1978 machineW
, reserved
);
1979 HeapFree(GetProcessHeap(), 0, enumstrW
);
1980 HeapFree(GetProcessHeap(), 0, machineW
);
1986 static void SETUPDI_AddDeviceInterfaces(SP_DEVINFO_DATA
*dev
, HKEY key
,
1987 const GUID
*interface
)
1990 WCHAR subKeyName
[MAX_PATH
];
1991 LONG l
= ERROR_SUCCESS
;
1993 for (i
= 0; !l
; i
++)
1995 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
1996 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2000 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
2002 if (*subKeyName
== '#')
2004 /* The subkey name is the reference string, with a '#' prepended */
2005 SETUPDI_AddInterfaceInstance(dev
, interface
, subKeyName
+ 1,
2007 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2010 WCHAR symbolicLink
[MAX_PATH
];
2013 len
= sizeof(symbolicLink
);
2014 l
= RegQueryValueExW(subKey
, SymbolicLink
, NULL
, &dataType
,
2015 (BYTE
*)symbolicLink
, &len
);
2016 if (!l
&& dataType
== REG_SZ
)
2017 SETUPDI_SetInterfaceSymbolicLink(iface
, symbolicLink
);
2018 RegCloseKey(subKey
);
2021 /* Allow enumeration to continue */
2025 /* FIXME: find and add all the device's interfaces to the device */
2028 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet
,
2029 HKEY key
, const GUID
*interface
, LPCWSTR enumstr
)
2031 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2033 WCHAR subKeyName
[MAX_PATH
];
2035 HKEY enumKey
= INVALID_HANDLE_VALUE
;
2037 TRACE("%s\n", debugstr_w(enumstr
));
2039 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2041 for (i
= 0; !l
; i
++)
2043 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2044 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2049 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2052 WCHAR deviceInst
[MAX_PATH
* 3];
2055 len
= sizeof(deviceInst
);
2056 l
= RegQueryValueExW(subKey
, DeviceInstance
, NULL
, &dataType
,
2057 (BYTE
*)deviceInst
, &len
);
2058 if (!l
&& dataType
== REG_SZ
)
2060 TRACE("found instance ID %s\n", debugstr_w(deviceInst
));
2061 if (!enumstr
|| !lstrcmpiW(enumstr
, deviceInst
))
2065 l
= RegOpenKeyExW(enumKey
, deviceInst
, 0, KEY_READ
,
2069 WCHAR deviceClassStr
[40];
2071 len
= sizeof(deviceClassStr
);
2072 l
= RegQueryValueExW(deviceKey
, ClassGUID
, NULL
,
2073 &dataType
, (BYTE
*)deviceClassStr
, &len
);
2074 if (!l
&& dataType
== REG_SZ
&&
2075 deviceClassStr
[0] == '{' &&
2076 deviceClassStr
[37] == '}')
2079 SP_DEVINFO_DATA
*dev
;
2081 deviceClassStr
[37] = 0;
2082 UuidFromStringW(&deviceClassStr
[1],
2084 if (SETUPDI_AddDeviceToSet(set
, &deviceClass
,
2085 0 /* FIXME: DevInst */, deviceInst
,
2087 SETUPDI_AddDeviceInterfaces(dev
, subKey
,
2090 RegCloseKey(deviceKey
);
2094 RegCloseKey(subKey
);
2096 /* Allow enumeration to continue */
2100 if (enumKey
!= INVALID_HANDLE_VALUE
)
2101 RegCloseKey(enumKey
);
2104 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet
,
2105 const GUID
*interface
, LPCWSTR enumstr
, DWORD flags
)
2107 HKEY interfacesKey
= SetupDiOpenClassRegKeyExW(interface
, KEY_READ
,
2108 DIOCR_INTERFACE
, NULL
, NULL
);
2110 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(interface
),
2111 debugstr_w(enumstr
), flags
);
2113 if (interfacesKey
!= INVALID_HANDLE_VALUE
)
2115 if (flags
& DIGCF_ALLCLASSES
)
2118 WCHAR interfaceGuidStr
[40];
2119 LONG l
= ERROR_SUCCESS
;
2121 for (i
= 0; !l
; i
++)
2123 len
= sizeof(interfaceGuidStr
) / sizeof(interfaceGuidStr
[0]);
2124 l
= RegEnumKeyExW(interfacesKey
, i
, interfaceGuidStr
, &len
,
2125 NULL
, NULL
, NULL
, NULL
);
2128 if (interfaceGuidStr
[0] == '{' &&
2129 interfaceGuidStr
[37] == '}')
2134 interfaceGuidStr
[37] = 0;
2135 UuidFromStringW(&interfaceGuidStr
[1], &interfaceGuid
);
2136 l
= RegOpenKeyExW(interfacesKey
, interfaceGuidStr
, 0,
2137 KEY_READ
, &interfaceKey
);
2140 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2141 interfaceKey
, &interfaceGuid
, enumstr
);
2142 RegCloseKey(interfaceKey
);
2150 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2151 * interface's key, so just pass that long
2153 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2154 interfacesKey
, interface
, enumstr
);
2156 RegCloseKey(interfacesKey
);
2160 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet
*set
,
2161 LPCWSTR enumerator
, LPCWSTR deviceName
, HKEY deviceKey
,
2162 const GUID
*class, DWORD flags
)
2165 WCHAR deviceInstance
[MAX_PATH
];
2166 LONG l
= ERROR_SUCCESS
;
2168 TRACE("%s %s\n", debugstr_w(enumerator
), debugstr_w(deviceName
));
2170 for (i
= 0; !l
; i
++)
2172 len
= sizeof(deviceInstance
) / sizeof(deviceInstance
[0]);
2173 l
= RegEnumKeyExW(deviceKey
, i
, deviceInstance
, &len
, NULL
, NULL
, NULL
,
2179 l
= RegOpenKeyExW(deviceKey
, deviceInstance
, 0, KEY_READ
, &subKey
);
2182 WCHAR classGuid
[40];
2185 len
= sizeof(classGuid
);
2186 l
= RegQueryValueExW(subKey
, ClassGUID
, NULL
, &dataType
,
2187 (BYTE
*)classGuid
, &len
);
2188 if (!l
&& dataType
== REG_SZ
)
2190 if (classGuid
[0] == '{' && classGuid
[37] == '}')
2195 UuidFromStringW(&classGuid
[1], &deviceClass
);
2196 if ((flags
& DIGCF_ALLCLASSES
) ||
2197 IsEqualGUID(class, &deviceClass
))
2199 static const WCHAR fmt
[] =
2200 {'%','s','\\','%','s','\\','%','s',0};
2203 instanceId
= HeapAlloc(GetProcessHeap(), 0,
2204 (lstrlenW(enumerator
) + lstrlenW(deviceName
) +
2205 lstrlenW(deviceInstance
) + 3) * sizeof(WCHAR
));
2208 sprintfW(instanceId
, fmt
, enumerator
,
2209 deviceName
, deviceInstance
);
2210 SETUPDI_AddDeviceToSet(set
, &deviceClass
,
2211 0 /* FIXME: DevInst */, instanceId
,
2213 HeapFree(GetProcessHeap(), 0, instanceId
);
2218 RegCloseKey(subKey
);
2220 /* Allow enumeration to continue */
2226 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet
,
2227 LPCWSTR parent
, HKEY key
, const GUID
*class, DWORD flags
)
2229 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2231 WCHAR subKeyName
[MAX_PATH
];
2232 LONG l
= ERROR_SUCCESS
;
2234 TRACE("%s\n", debugstr_w(parent
));
2236 for (i
= 0; !l
; i
++)
2238 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2239 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2244 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2247 TRACE("%s\n", debugstr_w(subKeyName
));
2248 SETUPDI_EnumerateMatchingDeviceInstances(set
, parent
,
2249 subKeyName
, subKey
, class, flags
);
2250 RegCloseKey(subKey
);
2252 /* Allow enumeration to continue */
2258 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet
, const GUID
*class,
2259 LPCWSTR enumstr
, DWORD flags
)
2264 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(class),
2265 debugstr_w(enumstr
), flags
);
2267 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2269 if (enumKey
!= INVALID_HANDLE_VALUE
)
2275 l
= RegOpenKeyExW(enumKey
, enumstr
, 0, KEY_READ
,
2279 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
, enumstr
,
2280 enumStrKey
, class, flags
);
2281 RegCloseKey(enumStrKey
);
2287 WCHAR subKeyName
[MAX_PATH
];
2290 for (i
= 0; !l
; i
++)
2292 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2293 l
= RegEnumKeyExW(enumKey
, i
, subKeyName
, &len
, NULL
,
2299 l
= RegOpenKeyExW(enumKey
, subKeyName
, 0, KEY_READ
,
2303 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
,
2304 subKeyName
, subKey
, class, flags
);
2305 RegCloseKey(subKey
);
2307 /* Allow enumeration to continue */
2312 RegCloseKey(enumKey
);
2316 /***********************************************************************
2317 * SetupDiGetClassDevsW (SETUPAPI.@)
2319 HDEVINFO WINAPI
SetupDiGetClassDevsW(
2325 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2329 /***********************************************************************
2330 * SetupDiGetClassDevsExW (SETUPAPI.@)
2332 HDEVINFO WINAPI
SetupDiGetClassDevsExW(
2341 static const DWORD unsupportedFlags
= DIGCF_DEFAULT
| DIGCF_PRESENT
|
2345 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2346 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2349 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2351 SetLastError(ERROR_INVALID_PARAMETER
);
2354 if (flags
& unsupportedFlags
)
2355 WARN("unsupported flags %08x\n", flags
& unsupportedFlags
);
2359 set
= SetupDiCreateDeviceInfoListExW(class, parent
, machine
, reserved
);
2363 FIXME("%s: unimplemented for remote machines\n",
2364 debugstr_w(machine
));
2365 else if (flags
& DIGCF_DEVICEINTERFACE
)
2366 SETUPDI_EnumerateInterfaces(set
, class, enumstr
, flags
);
2368 SETUPDI_EnumerateDevices(set
, class, enumstr
, flags
);
2373 /***********************************************************************
2374 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2376 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2377 HDEVINFO DeviceInfoSet
,
2378 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2380 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2382 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2384 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2386 SetLastError(ERROR_INVALID_HANDLE
);
2389 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2391 SetLastError(ERROR_INVALID_HANDLE
);
2395 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2397 SetLastError(ERROR_INVALID_PARAMETER
);
2400 DevInfoData
->ClassGuid
= set
->ClassGuid
;
2401 DevInfoData
->RemoteMachineHandle
= NULL
;
2402 DevInfoData
->RemoteMachineName
[0] = '\0';
2406 /***********************************************************************
2407 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2409 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2410 HDEVINFO DeviceInfoSet
,
2411 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2413 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2415 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2417 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2419 SetLastError(ERROR_INVALID_HANDLE
);
2422 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2424 SetLastError(ERROR_INVALID_HANDLE
);
2428 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2430 SetLastError(ERROR_INVALID_PARAMETER
);
2433 DevInfoData
->ClassGuid
= set
->ClassGuid
;
2434 DevInfoData
->RemoteMachineHandle
= NULL
;
2435 DevInfoData
->RemoteMachineName
[0] = '\0';
2439 /***********************************************************************
2440 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2442 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2443 HDEVINFO DeviceInfoSet
,
2444 PSP_DEVINFO_DATA DeviceInfoData
,
2445 const GUID
*InterfaceClassGuid
,
2446 PCSTR ReferenceString
,
2447 DWORD CreationFlags
,
2448 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2451 LPWSTR ReferenceStringW
= NULL
;
2453 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2454 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2455 CreationFlags
, DeviceInterfaceData
);
2457 if (ReferenceString
)
2459 ReferenceStringW
= MultiByteToUnicode(ReferenceString
, CP_ACP
);
2460 if (ReferenceStringW
== NULL
) return FALSE
;
2463 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2464 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2465 DeviceInterfaceData
);
2467 MyFree(ReferenceStringW
);
2472 /***********************************************************************
2473 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2475 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2476 HDEVINFO DeviceInfoSet
,
2477 PSP_DEVINFO_DATA DeviceInfoData
,
2478 const GUID
*InterfaceClassGuid
,
2479 PCWSTR ReferenceString
,
2480 DWORD CreationFlags
,
2481 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2483 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2484 struct DeviceInfo
*devInfo
;
2485 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
2488 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2489 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2490 CreationFlags
, DeviceInterfaceData
);
2492 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2494 SetLastError(ERROR_INVALID_HANDLE
);
2497 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2499 SetLastError(ERROR_INVALID_HANDLE
);
2502 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2503 || !DeviceInfoData
->Reserved
)
2505 SetLastError(ERROR_INVALID_PARAMETER
);
2508 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2509 if (devInfo
->set
!= set
)
2511 SetLastError(ERROR_INVALID_PARAMETER
);
2514 if (!InterfaceClassGuid
)
2516 SetLastError(ERROR_INVALID_USER_BUFFER
);
2519 if ((ret
= SETUPDI_AddInterfaceInstance(DeviceInfoData
, InterfaceClassGuid
,
2520 ReferenceString
, &iface
)))
2522 if (DeviceInterfaceData
)
2524 if (DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2526 SetLastError(ERROR_INVALID_USER_BUFFER
);
2530 *DeviceInterfaceData
= *iface
;
2536 /***********************************************************************
2537 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2539 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2540 HDEVINFO DeviceInfoSet
,
2541 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2545 PCSTR InfSectionName
)
2548 PWSTR InfSectionNameW
= NULL
;
2550 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2551 samDesired
, InfHandle
, InfSectionName
);
2554 if (!InfSectionName
)
2556 SetLastError(ERROR_INVALID_PARAMETER
);
2557 return INVALID_HANDLE_VALUE
;
2559 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2560 if (!InfSectionNameW
)
2561 return INVALID_HANDLE_VALUE
;
2563 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2564 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2566 MyFree(InfSectionNameW
);
2570 static PWSTR
SETUPDI_GetInstancePath(struct InterfaceInfo
*ifaceInfo
)
2572 static const WCHAR hash
[] = {'#',0};
2573 PWSTR instancePath
= NULL
;
2575 if (ifaceInfo
->referenceString
)
2577 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2578 (lstrlenW(ifaceInfo
->referenceString
) + 2) * sizeof(WCHAR
));
2581 lstrcpyW(instancePath
, hash
);
2582 lstrcatW(instancePath
, ifaceInfo
->referenceString
);
2585 SetLastError(ERROR_OUTOFMEMORY
);
2589 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2590 (lstrlenW(hash
) + 1) * sizeof(WCHAR
));
2592 lstrcpyW(instancePath
, hash
);
2594 return instancePath
;
2597 /***********************************************************************
2598 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2600 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2601 HDEVINFO DeviceInfoSet
,
2602 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2606 PCWSTR InfSectionName
)
2608 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2609 HKEY key
= INVALID_HANDLE_VALUE
, interfacesKey
;
2612 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2613 samDesired
, InfHandle
, InfSectionName
);
2615 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2616 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2618 SetLastError(ERROR_INVALID_HANDLE
);
2619 return INVALID_HANDLE_VALUE
;
2621 if (!DeviceInterfaceData
||
2622 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2623 !DeviceInterfaceData
->Reserved
)
2625 SetLastError(ERROR_INVALID_PARAMETER
);
2626 return INVALID_HANDLE_VALUE
;
2628 if (InfHandle
&& !InfSectionName
)
2630 SetLastError(ERROR_INVALID_PARAMETER
);
2631 return INVALID_HANDLE_VALUE
;
2633 if (!(l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, DeviceClasses
, 0, NULL
, 0,
2634 samDesired
, NULL
, &interfacesKey
, NULL
)))
2637 WCHAR bracedGuidString
[39];
2639 SETUPDI_GuidToString(&DeviceInterfaceData
->InterfaceClassGuid
,
2641 if (!(l
= RegCreateKeyExW(interfacesKey
, bracedGuidString
, 0, NULL
, 0,
2642 samDesired
, NULL
, &parent
, NULL
)))
2644 struct InterfaceInfo
*ifaceInfo
=
2645 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2646 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2647 PWSTR interfKeyName
= HeapAlloc(GetProcessHeap(), 0,
2648 (lstrlenW(ifaceInfo
->symbolicLink
) + 1) * sizeof(WCHAR
));
2652 lstrcpyW(interfKeyName
, ifaceInfo
->symbolicLink
);
2653 if (lstrlenW(ifaceInfo
->symbolicLink
) > 3)
2655 interfKeyName
[0] = '#';
2656 interfKeyName
[1] = '#';
2657 interfKeyName
[3] = '#';
2659 ptr
= strchrW(interfKeyName
, '\\');
2662 l
= RegCreateKeyExW(parent
, interfKeyName
, 0, NULL
, 0,
2663 samDesired
, NULL
, &interfKey
, NULL
);
2666 struct DeviceInfo
*devInfo
=
2667 (struct DeviceInfo
*)ifaceInfo
->device
->Reserved
;
2669 l
= RegSetValueExW(interfKey
, DeviceInstance
, 0, REG_SZ
,
2670 (BYTE
*)devInfo
->instanceId
,
2671 (lstrlenW(devInfo
->instanceId
) + 1) * sizeof(WCHAR
));
2678 l
= RegCreateKeyExW(interfKey
, instancePath
, 0, NULL
, 0,
2679 samDesired
, NULL
, &key
, NULL
);
2683 key
= INVALID_HANDLE_VALUE
;
2686 FIXME("INF section installation unsupported\n");
2691 RegCloseKey(interfKey
);
2695 HeapFree(GetProcessHeap(), 0, interfKeyName
);
2696 HeapFree(GetProcessHeap(), 0, instancePath
);
2697 RegCloseKey(parent
);
2701 RegCloseKey(interfacesKey
);
2708 /***********************************************************************
2709 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2711 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2712 HDEVINFO DeviceInfoSet
,
2713 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2716 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2720 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2722 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2723 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2725 SetLastError(ERROR_INVALID_HANDLE
);
2728 if (!DeviceInterfaceData
||
2729 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2730 !DeviceInterfaceData
->Reserved
)
2732 SetLastError(ERROR_INVALID_PARAMETER
);
2735 parent
= SetupDiOpenClassRegKeyExW(&DeviceInterfaceData
->InterfaceClassGuid
,
2736 KEY_ALL_ACCESS
, DIOCR_INTERFACE
, NULL
, NULL
);
2737 if (parent
!= INVALID_HANDLE_VALUE
)
2739 struct InterfaceInfo
*ifaceInfo
=
2740 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2741 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2745 LONG l
= RegDeleteKeyW(parent
, instancePath
);
2751 HeapFree(GetProcessHeap(), 0, instancePath
);
2753 RegCloseKey(parent
);
2758 /***********************************************************************
2759 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2762 * DeviceInfoSet [I] Set of devices from which to enumerate
2764 * DeviceInfoData [I] (Optional) If specified, a specific device
2765 * instance from which to enumerate interfaces.
2766 * If it isn't specified, all interfaces for all
2767 * devices in the set are enumerated.
2768 * InterfaceClassGuid [I] The interface class to enumerate.
2769 * MemberIndex [I] An index of the interface instance to enumerate.
2770 * A caller should start with MemberIndex set to 0,
2771 * and continue until the function fails with
2772 * ERROR_NO_MORE_ITEMS.
2773 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2774 * member must be set to
2775 * sizeof(SP_DEVICE_INTERFACE_DATA).
2778 * Success: non-zero value.
2779 * Failure: FALSE. Call GetLastError() for more info.
2781 BOOL WINAPI
SetupDiEnumDeviceInterfaces(
2782 HDEVINFO DeviceInfoSet
,
2783 PSP_DEVINFO_DATA DeviceInfoData
,
2784 CONST GUID
* InterfaceClassGuid
,
2786 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2788 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2791 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet
, DeviceInfoData
,
2792 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
2794 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2795 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2797 SetLastError(ERROR_INVALID_HANDLE
);
2800 if (DeviceInfoData
&& (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2801 !DeviceInfoData
->Reserved
))
2803 SetLastError(ERROR_INVALID_PARAMETER
);
2806 if (!DeviceInterfaceData
||
2807 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2809 SetLastError(ERROR_INVALID_PARAMETER
);
2814 struct DeviceInfo
*devInfo
=
2815 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2816 struct InterfaceInstances
*iface
;
2818 if ((ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
2820 if (MemberIndex
< iface
->cInstances
)
2821 *DeviceInterfaceData
= iface
->instances
[MemberIndex
];
2824 SetLastError(ERROR_NO_MORE_ITEMS
);
2829 SetLastError(ERROR_NO_MORE_ITEMS
);
2833 struct DeviceInstance
*devInst
;
2834 DWORD cEnumerated
= 0;
2837 LIST_FOR_EACH_ENTRY(devInst
, &set
->devices
, struct DeviceInstance
, entry
)
2839 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)devInst
->data
.Reserved
;
2840 struct InterfaceInstances
*iface
;
2842 if (found
|| cEnumerated
>= MemberIndex
+ 1)
2844 if (SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
))
2846 if (cEnumerated
+ iface
->cInstances
< MemberIndex
+ 1)
2847 cEnumerated
+= iface
->cInstances
;
2850 DWORD instanceIndex
= MemberIndex
- cEnumerated
;
2852 *DeviceInterfaceData
= iface
->instances
[instanceIndex
];
2853 cEnumerated
+= instanceIndex
+ 1;
2860 SetLastError(ERROR_NO_MORE_ITEMS
);
2865 /***********************************************************************
2866 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2868 * Destroy a DeviceInfoList and free all used memory of the list.
2871 * devinfo [I] DeviceInfoList pointer to list to destroy
2874 * Success: non zero value.
2875 * Failure: zero value.
2877 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
2881 TRACE("%p\n", devinfo
);
2882 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
2884 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
2886 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
2888 struct DeviceInstance
*devInst
, *devInst2
;
2890 LIST_FOR_EACH_ENTRY_SAFE(devInst
, devInst2
, &list
->devices
,
2891 struct DeviceInstance
, entry
)
2893 SETUPDI_FreeDeviceInfo( (struct DeviceInfo
*)devInst
->data
.Reserved
);
2894 list_remove(&devInst
->entry
);
2895 HeapFree(GetProcessHeap(), 0, devInst
);
2897 HeapFree(GetProcessHeap(), 0, list
);
2903 SetLastError(ERROR_INVALID_HANDLE
);
2908 /***********************************************************************
2909 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2911 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
2912 HDEVINFO DeviceInfoSet
,
2913 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2914 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
2915 DWORD DeviceInterfaceDetailDataSize
,
2916 PDWORD RequiredSize
,
2917 PSP_DEVINFO_DATA DeviceInfoData
)
2919 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2920 struct InterfaceInfo
*info
;
2921 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
)
2925 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2926 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2927 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2929 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2930 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2932 SetLastError(ERROR_INVALID_HANDLE
);
2935 if (!DeviceInterfaceData
||
2936 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2937 !DeviceInterfaceData
->Reserved
)
2939 SetLastError(ERROR_INVALID_PARAMETER
);
2942 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
!=
2943 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + sizeof(char)))
2945 SetLastError(ERROR_INVALID_USER_BUFFER
);
2948 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2950 SetLastError(ERROR_INVALID_USER_BUFFER
);
2953 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2954 if (info
->symbolicLink
)
2955 bytesNeeded
+= WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2956 NULL
, 0, NULL
, NULL
);
2957 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2959 if (info
->symbolicLink
)
2960 WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2961 DeviceInterfaceDetailData
->DevicePath
,
2962 DeviceInterfaceDetailDataSize
-
2963 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
2966 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2967 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2968 *DeviceInfoData
= *info
->device
;
2974 *RequiredSize
= bytesNeeded
;
2975 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2980 /***********************************************************************
2981 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2983 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
2984 HDEVINFO DeviceInfoSet
,
2985 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2986 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
2987 DWORD DeviceInterfaceDetailDataSize
,
2988 PDWORD RequiredSize
,
2989 PSP_DEVINFO_DATA DeviceInfoData
)
2991 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2992 struct InterfaceInfo
*info
;
2993 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
2994 + sizeof(WCHAR
); /* include NULL terminator */
2997 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2998 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2999 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
3001 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
3002 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3004 SetLastError(ERROR_INVALID_HANDLE
);
3007 if (!DeviceInterfaceData
||
3008 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
3009 !DeviceInterfaceData
->Reserved
)
3011 SetLastError(ERROR_INVALID_PARAMETER
);
3014 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
3015 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
) ||
3016 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
)))
3018 SetLastError(ERROR_INVALID_USER_BUFFER
);
3021 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
3023 SetLastError(ERROR_INVALID_USER_BUFFER
);
3026 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
3027 if (info
->symbolicLink
)
3028 bytesNeeded
+= sizeof(WCHAR
)*lstrlenW(info
->symbolicLink
);
3029 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
3031 if (info
->symbolicLink
)
3032 lstrcpyW(DeviceInterfaceDetailData
->DevicePath
, info
->symbolicLink
);
3034 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
3035 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
3036 *DeviceInfoData
= *info
->device
;
3042 *RequiredSize
= bytesNeeded
;
3043 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3048 struct PropertyMapEntry
3055 static const struct PropertyMapEntry PropertyMap
[] = {
3056 { REG_SZ
, "DeviceDesc", DeviceDesc
},
3057 { REG_MULTI_SZ
, "HardwareId", HardwareId
},
3058 { REG_MULTI_SZ
, "CompatibleIDs", CompatibleIDs
},
3059 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
3060 { REG_SZ
, "Service", Service
},
3061 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
3062 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
3063 { REG_SZ
, "Class", Class
},
3064 { REG_SZ
, "ClassGUID", ClassGUID
},
3065 { REG_SZ
, "Driver", Driver
},
3066 { REG_DWORD
, "ConfigFlags", ConfigFlags
},
3067 { REG_SZ
, "Mfg", Mfg
},
3068 { REG_SZ
, "FriendlyName", FriendlyName
},
3069 { REG_SZ
, "LocationInformation", LocationInformation
},
3070 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3071 { REG_DWORD
, "Capabilities", Capabilities
},
3072 { REG_DWORD
, "UINumber", UINumber
},
3073 { REG_MULTI_SZ
, "UpperFilters", UpperFilters
},
3074 { REG_MULTI_SZ
, "LowerFilters", LowerFilters
},
3077 /***********************************************************************
3078 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3080 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
3081 HDEVINFO DeviceInfoSet
,
3082 PSP_DEVINFO_DATA DeviceInfoData
,
3084 PDWORD PropertyRegDataType
,
3085 PBYTE PropertyBuffer
,
3086 DWORD PropertyBufferSize
,
3087 PDWORD RequiredSize
)
3090 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3091 struct DeviceInfo
*devInfo
;
3093 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3094 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3097 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3099 SetLastError(ERROR_INVALID_HANDLE
);
3102 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3104 SetLastError(ERROR_INVALID_HANDLE
);
3107 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3108 || !DeviceInfoData
->Reserved
)
3110 SetLastError(ERROR_INVALID_PARAMETER
);
3113 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
3115 SetLastError(ERROR_INVALID_DATA
);
3118 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3119 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3120 && PropertyMap
[Property
].nameA
)
3122 DWORD size
= PropertyBufferSize
;
3123 LONG l
= RegQueryValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
,
3124 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3126 if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3127 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3133 *RequiredSize
= size
;
3138 /***********************************************************************
3139 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3141 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3142 HDEVINFO DeviceInfoSet
,
3143 PSP_DEVINFO_DATA DeviceInfoData
,
3145 PDWORD PropertyRegDataType
,
3146 PBYTE PropertyBuffer
,
3147 DWORD PropertyBufferSize
,
3148 PDWORD RequiredSize
)
3151 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3152 struct DeviceInfo
*devInfo
;
3154 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3155 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3158 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3160 SetLastError(ERROR_INVALID_HANDLE
);
3163 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3165 SetLastError(ERROR_INVALID_HANDLE
);
3168 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3169 || !DeviceInfoData
->Reserved
)
3171 SetLastError(ERROR_INVALID_PARAMETER
);
3174 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
3176 SetLastError(ERROR_INVALID_DATA
);
3179 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3180 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3181 && PropertyMap
[Property
].nameW
)
3183 DWORD size
= PropertyBufferSize
;
3184 LONG l
= RegQueryValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
,
3185 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3187 if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3188 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3194 *RequiredSize
= size
;
3199 /***********************************************************************
3200 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3202 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3203 HDEVINFO DeviceInfoSet
,
3204 PSP_DEVINFO_DATA DeviceInfoData
,
3206 const BYTE
*PropertyBuffer
,
3207 DWORD PropertyBufferSize
)
3210 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3211 struct DeviceInfo
*devInfo
;
3213 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3214 PropertyBuffer
, PropertyBufferSize
);
3216 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3218 SetLastError(ERROR_INVALID_HANDLE
);
3221 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3223 SetLastError(ERROR_INVALID_HANDLE
);
3226 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3227 || !DeviceInfoData
->Reserved
)
3229 SetLastError(ERROR_INVALID_PARAMETER
);
3232 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3233 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3234 && PropertyMap
[Property
].nameA
)
3236 LONG l
= RegSetValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
, 0,
3237 PropertyMap
[Property
].regType
, PropertyBuffer
,
3238 PropertyBufferSize
);
3247 /***********************************************************************
3248 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3250 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
3251 HDEVINFO DeviceInfoSet
,
3252 PSP_DEVINFO_DATA DeviceInfoData
,
3254 const BYTE
*PropertyBuffer
,
3255 DWORD PropertyBufferSize
)
3258 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3259 struct DeviceInfo
*devInfo
;
3261 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3262 PropertyBuffer
, PropertyBufferSize
);
3264 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3266 SetLastError(ERROR_INVALID_HANDLE
);
3269 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3271 SetLastError(ERROR_INVALID_HANDLE
);
3274 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3275 || !DeviceInfoData
->Reserved
)
3277 SetLastError(ERROR_INVALID_PARAMETER
);
3280 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3281 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3282 && PropertyMap
[Property
].nameW
)
3284 LONG l
= RegSetValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
, 0,
3285 PropertyMap
[Property
].regType
, PropertyBuffer
,
3286 PropertyBufferSize
);
3295 /***********************************************************************
3296 * SetupDiInstallClassA (SETUPAPI.@)
3298 BOOL WINAPI
SetupDiInstallClassA(
3304 UNICODE_STRING FileNameW
;
3309 SetLastError(ERROR_INVALID_PARAMETER
);
3312 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW
, InfFileName
))
3314 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3318 Result
= SetupDiInstallClassW(hwndParent
, FileNameW
.Buffer
, Flags
, FileQueue
);
3320 RtlFreeUnicodeString(&FileNameW
);
3325 static HKEY
CreateClassKey(HINF hInf
)
3327 static const WCHAR slash
[] = { '\\',0 };
3328 WCHAR FullBuffer
[MAX_PATH
];
3329 WCHAR Buffer
[MAX_PATH
];
3333 if (!SetupGetLineTextW(NULL
,
3341 return INVALID_HANDLE_VALUE
;
3344 lstrcpyW(FullBuffer
, ControlClass
);
3345 lstrcatW(FullBuffer
, slash
);
3346 lstrcatW(FullBuffer
, Buffer
);
3348 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3354 if (!SetupGetLineTextW(NULL
,
3362 return INVALID_HANDLE_VALUE
;
3365 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3369 REG_OPTION_NON_VOLATILE
,
3375 return INVALID_HANDLE_VALUE
;
3380 if (RegSetValueExW(hClassKey
,
3385 RequiredSize
* sizeof(WCHAR
)))
3387 RegCloseKey(hClassKey
);
3388 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3390 return INVALID_HANDLE_VALUE
;
3396 /***********************************************************************
3397 * SetupDiInstallClassW (SETUPAPI.@)
3399 BOOL WINAPI
SetupDiInstallClassW(
3405 WCHAR SectionName
[MAX_PATH
];
3406 DWORD SectionNameLength
= 0;
3408 BOOL bFileQueueCreated
= FALSE
;
3416 SetLastError(ERROR_INVALID_PARAMETER
);
3419 if ((Flags
& DI_NOVCP
) && (FileQueue
== NULL
|| FileQueue
== INVALID_HANDLE_VALUE
))
3421 SetLastError(ERROR_INVALID_PARAMETER
);
3425 /* Open the .inf file */
3426 hInf
= SetupOpenInfFileW(InfFileName
,
3430 if (hInf
== INVALID_HANDLE_VALUE
)
3436 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3437 hClassKey
= CreateClassKey(hInf
);
3438 if (hClassKey
== INVALID_HANDLE_VALUE
)
3440 SetupCloseInfFile(hInf
);
3445 /* Try to append a layout file */
3446 SetupOpenAppendInfFileW(NULL
, hInf
, NULL
);
3448 /* Retrieve the actual section name */
3449 SetupDiGetActualSectionToInstallW(hInf
,
3457 if (!(Flags
& DI_NOVCP
))
3459 FileQueue
= SetupOpenFileQueue();
3460 if (FileQueue
== INVALID_HANDLE_VALUE
)
3462 SetupCloseInfFile(hInf
);
3466 bFileQueueCreated
= TRUE
;
3471 SetupInstallFromInfSectionW(NULL
,
3474 SPINST_COPYINF
| SPINST_FILES
| SPINST_REGISTRY
,
3480 INVALID_HANDLE_VALUE
,
3483 /* FIXME: More code! */
3485 if (bFileQueueCreated
)
3486 SetupCloseFileQueue(FileQueue
);
3488 SetupCloseInfFile(hInf
);
3494 /***********************************************************************
3495 * SetupDiOpenClassRegKey (SETUPAPI.@)
3497 HKEY WINAPI
SetupDiOpenClassRegKey(
3498 const GUID
* ClassGuid
,
3501 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3502 DIOCR_INSTALLER
, NULL
, NULL
);
3506 /***********************************************************************
3507 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3509 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3510 const GUID
* ClassGuid
,
3516 PWSTR MachineNameW
= NULL
;
3523 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
3524 if (MachineNameW
== NULL
)
3525 return INVALID_HANDLE_VALUE
;
3528 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3529 Flags
, MachineNameW
, Reserved
);
3531 MyFree(MachineNameW
);
3537 /***********************************************************************
3538 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3540 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3541 const GUID
* ClassGuid
,
3552 if (MachineName
!= NULL
)
3554 FIXME("Remote access not supported yet!\n");
3555 return INVALID_HANDLE_VALUE
;
3558 if (Flags
== DIOCR_INSTALLER
)
3560 lpKeyName
= ControlClass
;
3562 else if (Flags
== DIOCR_INTERFACE
)
3564 lpKeyName
= DeviceClasses
;
3568 ERR("Invalid Flags parameter!\n");
3569 SetLastError(ERROR_INVALID_PARAMETER
);
3570 return INVALID_HANDLE_VALUE
;
3575 if ((l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3582 hClassesKey
= INVALID_HANDLE_VALUE
;
3588 WCHAR bracedGuidString
[39];
3590 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3592 if (!(l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3598 if ((l
= RegOpenKeyExW(hClassesKey
,
3605 key
= INVALID_HANDLE_VALUE
;
3607 RegCloseKey(hClassesKey
);
3612 key
= INVALID_HANDLE_VALUE
;
3618 /***********************************************************************
3619 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3621 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3622 HDEVINFO DeviceInfoSet
,
3625 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3627 FIXME("%p %s %08x %p\n",
3628 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3632 /***********************************************************************
3633 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3635 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
3636 HDEVINFO DeviceInfoSet
,
3639 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3641 FIXME("%p %s %08x %p\n", DeviceInfoSet
,
3642 debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3646 /***********************************************************************
3647 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3649 BOOL WINAPI
SetupDiSetClassInstallParamsA(
3650 HDEVINFO DeviceInfoSet
,
3651 PSP_DEVINFO_DATA DeviceInfoData
,
3652 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3653 DWORD ClassInstallParamsSize
)
3655 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3656 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3660 /***********************************************************************
3661 * SetupDiCallClassInstaller (SETUPAPI.@)
3663 BOOL WINAPI
SetupDiCallClassInstaller(
3664 DI_FUNCTION InstallFunction
,
3665 HDEVINFO DeviceInfoSet
,
3666 PSP_DEVINFO_DATA DeviceInfoData
)
3668 FIXME("%d %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3672 /***********************************************************************
3673 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3675 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
3676 HDEVINFO DeviceInfoSet
,
3677 PSP_DEVINFO_DATA DeviceInfoData
,
3678 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3680 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3684 static HKEY
SETUPDI_OpenDevKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3686 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
3689 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3690 NULL
, &enumKey
, NULL
);
3693 RegOpenKeyExW(enumKey
, devInfo
->instanceId
, 0, samDesired
, &key
);
3694 RegCloseKey(enumKey
);
3699 static HKEY
SETUPDI_OpenDrvKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3701 static const WCHAR slash
[] = { '\\',0 };
3702 WCHAR classKeyPath
[MAX_PATH
];
3703 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
3706 lstrcpyW(classKeyPath
, ControlClass
);
3707 lstrcatW(classKeyPath
, slash
);
3708 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3709 classKeyPath
+ lstrlenW(classKeyPath
));
3710 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3711 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3714 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3717 sprintfW(devId
, fmt
, devInfo
->devId
);
3718 RegOpenKeyExW(classKey
, devId
, 0, samDesired
, &key
);
3719 RegCloseKey(classKey
);
3724 /***********************************************************************
3725 * SetupDiOpenDevRegKey (SETUPAPI.@)
3727 HKEY WINAPI
SetupDiOpenDevRegKey(
3728 HDEVINFO DeviceInfoSet
,
3729 PSP_DEVINFO_DATA DeviceInfoData
,
3735 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3736 struct DeviceInfo
*devInfo
;
3737 HKEY key
= INVALID_HANDLE_VALUE
;
3739 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
3740 Scope
, HwProfile
, KeyType
, samDesired
);
3742 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3744 SetLastError(ERROR_INVALID_HANDLE
);
3745 return INVALID_HANDLE_VALUE
;
3747 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3749 SetLastError(ERROR_INVALID_HANDLE
);
3750 return INVALID_HANDLE_VALUE
;
3752 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3753 || !DeviceInfoData
->Reserved
)
3755 SetLastError(ERROR_INVALID_PARAMETER
);
3756 return INVALID_HANDLE_VALUE
;
3758 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3760 SetLastError(ERROR_INVALID_FLAGS
);
3761 return INVALID_HANDLE_VALUE
;
3763 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
3765 SetLastError(ERROR_INVALID_FLAGS
);
3766 return INVALID_HANDLE_VALUE
;
3768 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3769 if (devInfo
->set
!= set
)
3771 SetLastError(ERROR_INVALID_PARAMETER
);
3772 return INVALID_HANDLE_VALUE
;
3774 if (devInfo
->phantom
)
3776 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3777 return INVALID_HANDLE_VALUE
;
3779 if (Scope
!= DICS_FLAG_GLOBAL
)
3780 FIXME("unimplemented for scope %d\n", Scope
);
3784 key
= SETUPDI_OpenDevKey(devInfo
, samDesired
);
3787 key
= SETUPDI_OpenDrvKey(devInfo
, samDesired
);
3790 WARN("unknown KeyType %d\n", KeyType
);
3795 static BOOL
SETUPDI_DeleteDevKey(struct DeviceInfo
*devInfo
)
3801 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3802 NULL
, &enumKey
, NULL
);
3805 ret
= RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
3806 RegCloseKey(enumKey
);
3813 static BOOL
SETUPDI_DeleteDrvKey(struct DeviceInfo
*devInfo
)
3815 static const WCHAR slash
[] = { '\\',0 };
3816 WCHAR classKeyPath
[MAX_PATH
];
3821 lstrcpyW(classKeyPath
, ControlClass
);
3822 lstrcatW(classKeyPath
, slash
);
3823 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3824 classKeyPath
+ lstrlenW(classKeyPath
));
3825 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3826 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3829 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3832 sprintfW(devId
, fmt
, devInfo
->devId
);
3833 ret
= RegDeleteTreeW(classKey
, devId
);
3834 RegCloseKey(classKey
);
3841 /***********************************************************************
3842 * SetupDiOpenDevRegKey (SETUPAPI.@)
3844 BOOL WINAPI
SetupDiDeleteDevRegKey(
3845 HDEVINFO DeviceInfoSet
,
3846 PSP_DEVINFO_DATA DeviceInfoData
,
3851 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3852 struct DeviceInfo
*devInfo
;
3855 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
3858 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3860 SetLastError(ERROR_INVALID_HANDLE
);
3863 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3865 SetLastError(ERROR_INVALID_HANDLE
);
3868 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3869 || !DeviceInfoData
->Reserved
)
3871 SetLastError(ERROR_INVALID_PARAMETER
);
3874 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3876 SetLastError(ERROR_INVALID_FLAGS
);
3879 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
3881 SetLastError(ERROR_INVALID_FLAGS
);
3884 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3885 if (devInfo
->set
!= set
)
3887 SetLastError(ERROR_INVALID_PARAMETER
);
3890 if (devInfo
->phantom
)
3892 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3895 if (Scope
!= DICS_FLAG_GLOBAL
)
3896 FIXME("unimplemented for scope %d\n", Scope
);
3900 ret
= SETUPDI_DeleteDevKey(devInfo
);
3903 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3906 ret
= SETUPDI_DeleteDevKey(devInfo
);
3908 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3911 WARN("unknown KeyType %d\n", KeyType
);
3916 /***********************************************************************
3917 * CM_Get_Device_IDA (SETUPAPI.@)
3919 CONFIGRET WINAPI
CM_Get_Device_IDA( DEVINST dnDevInst
, PSTR Buffer
,
3920 ULONG BufferLen
, ULONG ulFlags
)
3922 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
3924 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
3927 return CR_NO_SUCH_DEVINST
;
3929 WideCharToMultiByte(CP_ACP
, 0, devInfo
->instanceId
, -1, Buffer
, BufferLen
, 0, 0);
3930 TRACE("Returning %s\n", debugstr_a(Buffer
));
3934 /***********************************************************************
3935 * CM_Get_Device_IDW (SETUPAPI.@)
3937 CONFIGRET WINAPI
CM_Get_Device_IDW( DEVINST dnDevInst
, LPWSTR Buffer
,
3938 ULONG BufferLen
, ULONG ulFlags
)
3940 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
3942 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
3946 WARN("dev instance %d not found!\n", dnDevInst
);
3947 return CR_NO_SUCH_DEVINST
;
3950 lstrcpynW(Buffer
, devInfo
->instanceId
, BufferLen
);
3951 TRACE("Returning %s\n", debugstr_w(Buffer
));
3952 GlobalUnlock((HANDLE
)dnDevInst
);
3958 /***********************************************************************
3959 * CM_Get_Device_ID_Size (SETUPAPI.@)
3961 CONFIGRET WINAPI
CM_Get_Device_ID_Size( PULONG pulLen
, DEVINST dnDevInst
,
3964 struct DeviceInfo
*ppdevInfo
= GlobalLock((HANDLE
)dnDevInst
);
3966 TRACE("%x->%p, %p, %u\n", dnDevInst
, ppdevInfo
, pulLen
, ulFlags
);
3970 WARN("dev instance %d not found!\n", dnDevInst
);
3971 return CR_NO_SUCH_DEVINST
;
3974 *pulLen
= lstrlenW(ppdevInfo
->instanceId
);
3975 GlobalUnlock((HANDLE
)dnDevInst
);