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"
43 #include "setupapi_private.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
48 /* Unicode constants */
49 static const WCHAR ClassGUID
[] = {'C','l','a','s','s','G','U','I','D',0};
50 static const WCHAR Class
[] = {'C','l','a','s','s',0};
51 static const WCHAR ClassInstall32
[] = {'C','l','a','s','s','I','n','s','t','a','l','l','3','2',0};
52 static const WCHAR NoDisplayClass
[] = {'N','o','D','i','s','p','l','a','y','C','l','a','s','s',0};
53 static const WCHAR NoInstallClass
[] = {'N','o','I','n','s','t','a','l','l','C','l','a','s','s',0};
54 static const WCHAR NoUseClass
[] = {'N','o','U','s','e','C','l','a','s','s',0};
55 static const WCHAR NtExtension
[] = {'.','N','T',0};
56 static const WCHAR NtPlatformExtension
[] = {'.','N','T','x','8','6',0};
57 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
58 static const WCHAR WinExtension
[] = {'.','W','i','n',0};
60 /* Registry key and value names */
61 static const WCHAR ControlClass
[] = {'S','y','s','t','e','m','\\',
62 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
63 'C','o','n','t','r','o','l','\\',
64 'C','l','a','s','s',0};
66 static const WCHAR DeviceClasses
[] = {'S','y','s','t','e','m','\\',
67 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
68 'C','o','n','t','r','o','l','\\',
69 'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
70 static const WCHAR Enum
[] = {'S','y','s','t','e','m','\\',
71 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
73 static const WCHAR DeviceDesc
[] = {'D','e','v','i','c','e','D','e','s','c',0};
74 static const WCHAR DeviceInstance
[] = {'D','e','v','i','c','e','I','n','s','t','a','n','c','e',0};
75 static const WCHAR HardwareId
[] = {'H','a','r','d','w','a','r','e','I','D',0};
76 static const WCHAR CompatibleIDs
[] = {'C','o','m','p','a','t','i','b','l','e','I','d','s',0};
77 static const WCHAR Service
[] = {'S','e','r','v','i','c','e',0};
78 static const WCHAR Driver
[] = {'D','r','i','v','e','r',0};
79 static const WCHAR ConfigFlags
[] = {'C','o','n','f','i','g','F','l','a','g','s',0};
80 static const WCHAR Mfg
[] = {'M','f','g',0};
81 static const WCHAR FriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
82 static const WCHAR LocationInformation
[] = {'L','o','c','a','t','i','o','n','I','n','f','o','r','m','a','t','i','o','n',0};
83 static const WCHAR Capabilities
[] = {'C','a','p','a','b','i','l','i','t','i','e','s',0};
84 static const WCHAR UINumber
[] = {'U','I','N','u','m','b','e','r',0};
85 static const WCHAR UpperFilters
[] = {'U','p','p','e','r','F','i','l','t','e','r','s',0};
86 static const WCHAR LowerFilters
[] = {'L','o','w','e','r','F','i','l','t','e','r','s',0};
87 static const WCHAR Phantom
[] = {'P','h','a','n','t','o','m',0};
88 static const WCHAR SymbolicLink
[] = {'S','y','m','b','o','l','i','c','L','i','n','k',0};
90 /* is used to identify if a DeviceInfoSet pointer is
92 #define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff056
96 DWORD magic
; /* if is equal to SETUP_DEVICE_INFO_SET_MAGIC struct is okay */
103 struct DeviceInstance
106 SP_DEVINFO_DATA data
;
109 /* Pointed to by SP_DEVICE_INTERFACE_DATA's Reserved member */
112 LPWSTR referenceString
;
114 PSP_DEVINFO_DATA device
;
117 /* A device may have multiple instances of the same interface, so this holds
118 * each instance belonging to a particular interface.
120 struct InterfaceInstances
124 DWORD cInstancesAllocated
;
125 SP_DEVICE_INTERFACE_DATA
*instances
;
129 /* Pointed to by SP_DEVINFO_DATA's Reserved member */
132 struct DeviceInfoSet
*set
;
137 struct list interfaces
;
140 static void SETUPDI_GuidToString(const GUID
*guid
, LPWSTR guidStr
)
142 static const WCHAR fmt
[] = {'{','%','0','8','X','-','%','0','4','X','-',
143 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
144 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
147 sprintfW(guidStr
, fmt
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
148 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
149 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
152 static void SETUPDI_FreeInterfaceInstances(struct InterfaceInstances
*instances
)
156 for (i
= 0; i
< instances
->cInstances
; i
++)
158 struct InterfaceInfo
*ifaceInfo
=
159 (struct InterfaceInfo
*)instances
->instances
[i
].Reserved
;
161 if (ifaceInfo
->device
&& ifaceInfo
->device
->Reserved
)
163 struct DeviceInfo
*devInfo
=
164 (struct DeviceInfo
*)ifaceInfo
->device
->Reserved
;
166 if (devInfo
->phantom
)
167 SetupDiDeleteDeviceInterfaceRegKey(devInfo
->set
,
168 &instances
->instances
[i
], 0);
170 HeapFree(GetProcessHeap(), 0, ifaceInfo
->referenceString
);
171 HeapFree(GetProcessHeap(), 0, ifaceInfo
->symbolicLink
);
172 HeapFree(GetProcessHeap(), 0, ifaceInfo
);
174 HeapFree(GetProcessHeap(), 0, instances
->instances
);
177 /* Finds the interface with interface class InterfaceClassGuid in the device.
178 * Returns TRUE if found, and updates *interface to point to device's
179 * interfaces member where the given interface was found.
180 * Returns FALSE if not found.
182 static BOOL
SETUPDI_FindInterface(const struct DeviceInfo
*devInfo
,
183 const GUID
*InterfaceClassGuid
, struct InterfaceInstances
**iface_ret
)
186 struct InterfaceInstances
*iface
;
188 TRACE("%s\n", debugstr_guid(InterfaceClassGuid
));
190 LIST_FOR_EACH_ENTRY(iface
, &devInfo
->interfaces
, struct InterfaceInstances
,
193 if (IsEqualGUID(&iface
->guid
, InterfaceClassGuid
))
200 TRACE("returning %d (%p)\n", found
, found
? *iface_ret
: NULL
);
204 /* Finds the interface instance with reference string ReferenceString in the
205 * interface instance map. Returns TRUE if found, and updates instanceIndex to
206 * the index of the interface instance's instances member
207 * where the given instance was found. Returns FALSE if not found.
209 static BOOL
SETUPDI_FindInterfaceInstance(
210 const struct InterfaceInstances
*instances
,
211 LPCWSTR ReferenceString
, DWORD
*instanceIndex
)
216 TRACE("%s\n", debugstr_w(ReferenceString
));
218 for (i
= 0; !found
&& i
< instances
->cInstances
; i
++)
220 SP_DEVICE_INTERFACE_DATA
*ifaceData
= &instances
->instances
[i
];
221 struct InterfaceInfo
*ifaceInfo
=
222 (struct InterfaceInfo
*)ifaceData
->Reserved
;
224 if (!ReferenceString
&& !ifaceInfo
->referenceString
)
229 else if (ReferenceString
&& ifaceInfo
->referenceString
&&
230 !lstrcmpiW(ifaceInfo
->referenceString
, ReferenceString
))
236 TRACE("returning %d (%d)\n", found
, found
? *instanceIndex
: 0);
240 static LPWSTR
SETUPDI_CreateSymbolicLinkPath(LPCWSTR instanceId
,
241 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
)
243 static const WCHAR fmt
[] = {'\\','\\','?','\\','%','s','#','%','s',0};
248 SETUPDI_GuidToString(InterfaceClassGuid
, guidStr
);
249 /* omit length of format specifiers, but include NULL terminator: */
250 len
= lstrlenW(fmt
) - 4 + 1;
251 len
+= lstrlenW(instanceId
) + lstrlenW(guidStr
);
252 if (ReferenceString
&& *ReferenceString
)
254 /* space for a hash between string and reference string: */
255 len
+= lstrlenW(ReferenceString
) + 1;
257 ret
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
260 int printed
= sprintfW(ret
, fmt
, instanceId
, guidStr
);
263 /* replace '\\' with '#' after the "\\\\?\\" beginning */
264 for (ptr
= strchrW(ret
+ 4, '\\'); ptr
; ptr
= strchrW(ptr
+ 1, '\\'))
266 if (ReferenceString
&& *ReferenceString
)
269 lstrcpyW(ret
+ printed
+ 1, ReferenceString
);
275 /* Adds an interface with the given interface class and reference string to
276 * the device, if it doesn't already exist in the device. If iface is not
277 * NULL, returns a pointer to the newly added (or already existing) interface.
279 static BOOL
SETUPDI_AddInterfaceInstance(PSP_DEVINFO_DATA DeviceInfoData
,
280 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
,
281 SP_DEVICE_INTERFACE_DATA
**ifaceData
)
283 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
284 BOOL newInterface
= FALSE
, ret
;
285 struct InterfaceInstances
*iface
= NULL
;
287 TRACE("%p %s %s %p\n", devInfo
, debugstr_guid(InterfaceClassGuid
),
288 debugstr_w(ReferenceString
), iface
);
290 if (!(ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
292 iface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
293 sizeof(struct InterfaceInstances
));
296 list_add_tail(&devInfo
->interfaces
, &iface
->entry
);
302 DWORD instanceIndex
= 0;
304 if (!(ret
= SETUPDI_FindInterfaceInstance(iface
, ReferenceString
,
307 SP_DEVICE_INTERFACE_DATA
*instance
= NULL
;
309 if (!iface
->cInstancesAllocated
)
311 iface
->instances
= HeapAlloc(GetProcessHeap(), 0,
312 sizeof(SP_DEVICE_INTERFACE_DATA
));
313 if (iface
->instances
)
314 instance
= &iface
->instances
[iface
->cInstancesAllocated
++];
316 else if (iface
->cInstances
== iface
->cInstancesAllocated
)
318 iface
->instances
= HeapReAlloc(GetProcessHeap(), 0,
320 (iface
->cInstancesAllocated
+ 1) *
321 sizeof(SP_DEVICE_INTERFACE_DATA
));
322 if (iface
->instances
)
323 instance
= &iface
->instances
[iface
->cInstancesAllocated
++];
326 instance
= &iface
->instances
[iface
->cInstances
];
329 struct InterfaceInfo
*ifaceInfo
= HeapAlloc(GetProcessHeap(),
330 0, sizeof(struct InterfaceInfo
));
335 ifaceInfo
->device
= DeviceInfoData
;
336 ifaceInfo
->symbolicLink
= SETUPDI_CreateSymbolicLinkPath(
337 devInfo
->instanceId
, InterfaceClassGuid
,
341 ifaceInfo
->referenceString
=
342 HeapAlloc(GetProcessHeap(), 0,
343 (lstrlenW(ReferenceString
) + 1) *
345 if (ifaceInfo
->referenceString
)
346 lstrcpyW(ifaceInfo
->referenceString
,
352 ifaceInfo
->referenceString
= NULL
;
359 sizeof(SP_DEVICE_INTERFACE_DATA
);
360 instance
->InterfaceClassGuid
= *InterfaceClassGuid
;
361 instance
->Flags
= SPINT_ACTIVE
; /* FIXME */
362 instance
->Reserved
= (ULONG_PTR
)ifaceInfo
;
364 iface
->guid
= *InterfaceClassGuid
;
365 key
= SetupDiCreateDeviceInterfaceRegKeyW(devInfo
->set
,
366 instance
, 0, KEY_WRITE
, NULL
, NULL
);
367 if (key
!= INVALID_HANDLE_VALUE
)
369 RegSetValueExW(key
, SymbolicLink
, 0, REG_SZ
,
370 (BYTE
*)ifaceInfo
->symbolicLink
,
371 lstrlenW(ifaceInfo
->symbolicLink
) *
376 *ifaceData
= instance
;
379 HeapFree(GetProcessHeap(), 0, ifaceInfo
);
386 *ifaceData
= &iface
->instances
[instanceIndex
];
391 TRACE("returning %d\n", ret
);
395 static BOOL
SETUPDI_SetInterfaceSymbolicLink(SP_DEVICE_INTERFACE_DATA
*iface
,
396 LPCWSTR symbolicLink
)
398 struct InterfaceInfo
*info
= (struct InterfaceInfo
*)iface
->Reserved
;
403 HeapFree(GetProcessHeap(), 0, info
->symbolicLink
);
404 info
->symbolicLink
= HeapAlloc(GetProcessHeap(), 0,
405 (lstrlenW(symbolicLink
) + 1) * sizeof(WCHAR
));
406 if (info
->symbolicLink
)
408 lstrcpyW(info
->symbolicLink
, symbolicLink
);
415 static HKEY
SETUPDI_CreateDevKey(struct DeviceInfo
*devInfo
)
417 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
420 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
421 NULL
, &enumKey
, NULL
);
424 RegCreateKeyExW(enumKey
, devInfo
->instanceId
, 0, NULL
, 0,
425 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
426 RegCloseKey(enumKey
);
431 static HKEY
SETUPDI_CreateDrvKey(struct DeviceInfo
*devInfo
)
433 static const WCHAR slash
[] = { '\\',0 };
434 WCHAR classKeyPath
[MAX_PATH
];
435 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
438 lstrcpyW(classKeyPath
, ControlClass
);
439 lstrcatW(classKeyPath
, slash
);
440 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
441 classKeyPath
+ lstrlenW(classKeyPath
));
442 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
443 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
446 static const WCHAR fmt
[] = { '%','0','4','u',0 };
449 sprintfW(devId
, fmt
, devInfo
->devId
);
450 RegCreateKeyExW(classKey
, devId
, 0, NULL
, 0, KEY_READ
| KEY_WRITE
,
452 RegCloseKey(classKey
);
457 static struct DeviceInfo
*SETUPDI_AllocateDeviceInfo(struct DeviceInfoSet
*set
,
458 DWORD devId
, LPCWSTR instanceId
, BOOL phantom
)
460 struct DeviceInfo
*devInfo
= NULL
;
461 HANDLE devInst
= GlobalAlloc(GMEM_FIXED
, sizeof(struct DeviceInfo
));
463 devInfo
= GlobalLock(devInst
);
468 devInfo
->devId
= (DWORD
)devInst
;
470 devInfo
->instanceId
= HeapAlloc(GetProcessHeap(), 0,
471 (lstrlenW(instanceId
) + 1) * sizeof(WCHAR
));
472 if (devInfo
->instanceId
)
474 devInfo
->key
= INVALID_HANDLE_VALUE
;
475 devInfo
->phantom
= phantom
;
476 lstrcpyW(devInfo
->instanceId
, instanceId
);
477 struprW(devInfo
->instanceId
);
478 devInfo
->key
= SETUPDI_CreateDevKey(devInfo
);
479 if (devInfo
->key
!= INVALID_HANDLE_VALUE
)
482 RegSetValueExW(devInfo
->key
, Phantom
, 0, REG_DWORD
,
483 (LPBYTE
)&phantom
, sizeof(phantom
));
485 list_init(&devInfo
->interfaces
);
486 GlobalUnlock(devInst
);
490 GlobalUnlock(devInst
);
498 static void SETUPDI_FreeDeviceInfo(struct DeviceInfo
*devInfo
)
500 struct InterfaceInstances
*iface
, *next
;
502 if (devInfo
->key
!= INVALID_HANDLE_VALUE
)
503 RegCloseKey(devInfo
->key
);
504 if (devInfo
->phantom
)
509 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0,
510 KEY_ALL_ACCESS
, NULL
, &enumKey
, NULL
);
513 RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
514 RegCloseKey(enumKey
);
517 HeapFree(GetProcessHeap(), 0, devInfo
->instanceId
);
518 LIST_FOR_EACH_ENTRY_SAFE(iface
, next
, &devInfo
->interfaces
,
519 struct InterfaceInstances
, entry
)
521 list_remove(&iface
->entry
);
522 SETUPDI_FreeInterfaceInstances(iface
);
523 HeapFree(GetProcessHeap(), 0, iface
);
525 GlobalFree((HANDLE
)devInfo
->devId
);
528 /* Adds a device with GUID guid and identifer devInst to set. Allocates a
529 * struct DeviceInfo, and points the returned device info's Reserved member
530 * to it. "Phantom" devices are deleted from the registry when closed.
531 * Returns a pointer to the newly allocated device info.
533 static BOOL
SETUPDI_AddDeviceToSet(struct DeviceInfoSet
*set
,
538 SP_DEVINFO_DATA
**dev
)
541 struct DeviceInfo
*devInfo
= SETUPDI_AllocateDeviceInfo(set
, set
->cDevices
,
542 instanceId
, phantom
);
544 TRACE("%p, %s, %d, %s, %d\n", set
, debugstr_guid(guid
), devInst
,
545 debugstr_w(instanceId
), phantom
);
549 struct DeviceInstance
*devInst
=
550 HeapAlloc(GetProcessHeap(), 0, sizeof(struct DeviceInstance
));
554 WCHAR classGuidStr
[39];
556 list_add_tail(&set
->devices
, &devInst
->entry
);
558 devInst
->data
.cbSize
= sizeof(SP_DEVINFO_DATA
);
559 devInst
->data
.ClassGuid
= *guid
;
560 devInst
->data
.DevInst
= devInfo
->devId
;
561 devInst
->data
.Reserved
= (ULONG_PTR
)devInfo
;
562 SETUPDI_GuidToString(guid
, classGuidStr
);
563 SetupDiSetDeviceRegistryPropertyW(set
, &devInst
->data
,
564 SPDRP_CLASSGUID
, (const BYTE
*)classGuidStr
,
565 lstrlenW(classGuidStr
) * sizeof(WCHAR
));
566 if (dev
) *dev
= &devInst
->data
;
571 HeapFree(GetProcessHeap(), 0, devInfo
);
572 SetLastError(ERROR_OUTOFMEMORY
);
578 /***********************************************************************
579 * SetupDiBuildClassInfoList (SETUPAPI.@)
581 * Returns a list of setup class GUIDs that identify the classes
582 * that are installed on a local machine.
585 * Flags [I] control exclusion of classes from the list.
586 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
587 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
588 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
594 BOOL WINAPI
SetupDiBuildClassInfoList(
596 LPGUID ClassGuidList
,
597 DWORD ClassGuidListSize
,
601 return SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
602 ClassGuidListSize
, RequiredSize
,
606 /***********************************************************************
607 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
609 * Returns a list of setup class GUIDs that identify the classes
610 * that are installed on a local or remote macine.
613 * Flags [I] control exclusion of classes from the list.
614 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
615 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
616 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
617 * MachineName [I] name of a remote machine.
618 * Reserved [I] must be NULL.
624 BOOL WINAPI
SetupDiBuildClassInfoListExA(
626 LPGUID ClassGuidList
,
627 DWORD ClassGuidListSize
,
632 LPWSTR MachineNameW
= NULL
;
639 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
640 if (MachineNameW
== NULL
) return FALSE
;
643 bResult
= SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
644 ClassGuidListSize
, RequiredSize
,
645 MachineNameW
, Reserved
);
647 MyFree(MachineNameW
);
652 /***********************************************************************
653 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
655 * Returns a list of setup class GUIDs that identify the classes
656 * that are installed on a local or remote macine.
659 * Flags [I] control exclusion of classes from the list.
660 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
661 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
662 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
663 * MachineName [I] name of a remote machine.
664 * Reserved [I] must be NULL.
670 BOOL WINAPI
SetupDiBuildClassInfoListExW(
672 LPGUID ClassGuidList
,
673 DWORD ClassGuidListSize
,
684 DWORD dwGuidListIndex
= 0;
688 if (RequiredSize
!= NULL
)
691 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
696 if (hClassesKey
== INVALID_HANDLE_VALUE
)
701 for (dwIndex
= 0; ; dwIndex
++)
704 lError
= RegEnumKeyExW(hClassesKey
,
712 TRACE("RegEnumKeyExW() returns %d\n", lError
);
713 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
715 TRACE("Key name: %p\n", szKeyName
);
717 if (RegOpenKeyExW(hClassesKey
,
723 RegCloseKey(hClassesKey
);
727 if (!RegQueryValueExW(hClassKey
,
734 TRACE("'NoUseClass' value found!\n");
735 RegCloseKey(hClassKey
);
739 if ((Flags
& DIBCI_NOINSTALLCLASS
) &&
740 (!RegQueryValueExW(hClassKey
,
747 TRACE("'NoInstallClass' value found!\n");
748 RegCloseKey(hClassKey
);
752 if ((Flags
& DIBCI_NODISPLAYCLASS
) &&
753 (!RegQueryValueExW(hClassKey
,
760 TRACE("'NoDisplayClass' value found!\n");
761 RegCloseKey(hClassKey
);
765 RegCloseKey(hClassKey
);
767 TRACE("Guid: %p\n", szKeyName
);
768 if (dwGuidListIndex
< ClassGuidListSize
)
770 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
774 TRACE("Guid: %p\n", &szKeyName
[1]);
776 UuidFromStringW(&szKeyName
[1],
777 &ClassGuidList
[dwGuidListIndex
]);
783 if (lError
!= ERROR_SUCCESS
)
787 RegCloseKey(hClassesKey
);
789 if (RequiredSize
!= NULL
)
790 *RequiredSize
= dwGuidListIndex
;
792 if (ClassGuidListSize
< dwGuidListIndex
)
794 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
801 /***********************************************************************
802 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
804 BOOL WINAPI
SetupDiClassGuidsFromNameA(
806 LPGUID ClassGuidList
,
807 DWORD ClassGuidListSize
,
810 return SetupDiClassGuidsFromNameExA(ClassName
, ClassGuidList
,
811 ClassGuidListSize
, RequiredSize
,
815 /***********************************************************************
816 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
818 BOOL WINAPI
SetupDiClassGuidsFromNameW(
820 LPGUID ClassGuidList
,
821 DWORD ClassGuidListSize
,
824 return SetupDiClassGuidsFromNameExW(ClassName
, ClassGuidList
,
825 ClassGuidListSize
, RequiredSize
,
829 /***********************************************************************
830 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
832 BOOL WINAPI
SetupDiClassGuidsFromNameExA(
834 LPGUID ClassGuidList
,
835 DWORD ClassGuidListSize
,
840 LPWSTR ClassNameW
= NULL
;
841 LPWSTR MachineNameW
= NULL
;
844 ClassNameW
= MultiByteToUnicode(ClassName
, CP_ACP
);
845 if (ClassNameW
== NULL
)
850 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
851 if (MachineNameW
== NULL
)
858 bResult
= SetupDiClassGuidsFromNameExW(ClassNameW
, ClassGuidList
,
859 ClassGuidListSize
, RequiredSize
,
860 MachineNameW
, Reserved
);
862 MyFree(MachineNameW
);
868 /***********************************************************************
869 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
871 BOOL WINAPI
SetupDiClassGuidsFromNameExW(
873 LPGUID ClassGuidList
,
874 DWORD ClassGuidListSize
,
880 WCHAR szClassName
[256];
886 DWORD dwGuidListIndex
= 0;
888 if (RequiredSize
!= NULL
)
891 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
896 if (hClassesKey
== INVALID_HANDLE_VALUE
)
901 for (dwIndex
= 0; ; dwIndex
++)
904 lError
= RegEnumKeyExW(hClassesKey
,
912 TRACE("RegEnumKeyExW() returns %d\n", lError
);
913 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
915 TRACE("Key name: %p\n", szKeyName
);
917 if (RegOpenKeyExW(hClassesKey
,
923 RegCloseKey(hClassesKey
);
927 dwLength
= 256 * sizeof(WCHAR
);
928 if (!RegQueryValueExW(hClassKey
,
935 TRACE("Class name: %p\n", szClassName
);
937 if (strcmpiW(szClassName
, ClassName
) == 0)
939 TRACE("Found matching class name\n");
941 TRACE("Guid: %p\n", szKeyName
);
942 if (dwGuidListIndex
< ClassGuidListSize
)
944 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
948 TRACE("Guid: %p\n", &szKeyName
[1]);
950 UuidFromStringW(&szKeyName
[1],
951 &ClassGuidList
[dwGuidListIndex
]);
958 RegCloseKey(hClassKey
);
961 if (lError
!= ERROR_SUCCESS
)
965 RegCloseKey(hClassesKey
);
967 if (RequiredSize
!= NULL
)
968 *RequiredSize
= dwGuidListIndex
;
970 if (ClassGuidListSize
< dwGuidListIndex
)
972 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
979 /***********************************************************************
980 * SetupDiClassNameFromGuidA (SETUPAPI.@)
982 BOOL WINAPI
SetupDiClassNameFromGuidA(
983 const GUID
* ClassGuid
,
988 return SetupDiClassNameFromGuidExA(ClassGuid
, ClassName
,
989 ClassNameSize
, RequiredSize
,
993 /***********************************************************************
994 * SetupDiClassNameFromGuidW (SETUPAPI.@)
996 BOOL WINAPI
SetupDiClassNameFromGuidW(
997 const GUID
* ClassGuid
,
1000 PDWORD RequiredSize
)
1002 return SetupDiClassNameFromGuidExW(ClassGuid
, ClassName
,
1003 ClassNameSize
, RequiredSize
,
1007 /***********************************************************************
1008 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1010 BOOL WINAPI
SetupDiClassNameFromGuidExA(
1011 const GUID
* ClassGuid
,
1013 DWORD ClassNameSize
,
1014 PDWORD RequiredSize
,
1018 WCHAR ClassNameW
[MAX_CLASS_NAME_LEN
];
1019 LPWSTR MachineNameW
= NULL
;
1023 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1024 ret
= SetupDiClassNameFromGuidExW(ClassGuid
, ClassNameW
, MAX_CLASS_NAME_LEN
,
1025 NULL
, MachineNameW
, Reserved
);
1028 int len
= WideCharToMultiByte(CP_ACP
, 0, ClassNameW
, -1, ClassName
,
1029 ClassNameSize
, NULL
, NULL
);
1031 if (!ClassNameSize
&& RequiredSize
)
1032 *RequiredSize
= len
;
1034 MyFree(MachineNameW
);
1038 /***********************************************************************
1039 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1041 BOOL WINAPI
SetupDiClassNameFromGuidExW(
1042 const GUID
* ClassGuid
,
1044 DWORD ClassNameSize
,
1045 PDWORD RequiredSize
,
1052 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1057 if (hKey
== INVALID_HANDLE_VALUE
)
1062 if (RequiredSize
!= NULL
)
1065 if (RegQueryValueExW(hKey
,
1076 *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1079 dwLength
= ClassNameSize
* sizeof(WCHAR
);
1080 if (RegQueryValueExW(hKey
,
1096 /***********************************************************************
1097 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1100 SetupDiCreateDeviceInfoList(const GUID
*ClassGuid
,
1103 return SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
, NULL
, NULL
);
1106 /***********************************************************************
1107 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1110 SetupDiCreateDeviceInfoListExA(const GUID
*ClassGuid
,
1115 LPWSTR MachineNameW
= NULL
;
1122 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1123 if (MachineNameW
== NULL
)
1124 return INVALID_HANDLE_VALUE
;
1127 hDevInfo
= SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
,
1128 MachineNameW
, Reserved
);
1130 MyFree(MachineNameW
);
1135 /***********************************************************************
1136 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1138 * Create an empty DeviceInfoSet list.
1141 * ClassGuid [I] if not NULL only devices with GUID ClassGuid are associated
1143 * hwndParent [I] hwnd needed for interface related actions.
1144 * MachineName [I] name of machine to create emtpy DeviceInfoSet list, if NULL
1145 * local registry will be used.
1146 * Reserved [I] must be NULL
1149 * Success: empty list.
1150 * Failure: INVALID_HANDLE_VALUE.
1153 SetupDiCreateDeviceInfoListExW(const GUID
*ClassGuid
,
1158 struct DeviceInfoSet
*list
= NULL
;
1159 DWORD size
= sizeof(struct DeviceInfoSet
);
1161 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1162 debugstr_w(MachineName
), Reserved
);
1164 if (MachineName
!= NULL
)
1166 FIXME("remote support is not implemented\n");
1167 SetLastError(ERROR_INVALID_MACHINENAME
);
1168 return INVALID_HANDLE_VALUE
;
1171 if (Reserved
!= NULL
)
1173 SetLastError(ERROR_INVALID_PARAMETER
);
1174 return INVALID_HANDLE_VALUE
;
1177 list
= HeapAlloc(GetProcessHeap(), 0, size
);
1180 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1181 return INVALID_HANDLE_VALUE
;
1184 list
->magic
= SETUP_DEVICE_INFO_SET_MAGIC
;
1185 list
->hwndParent
= hwndParent
;
1186 memcpy(&list
->ClassGuid
,
1187 ClassGuid
? ClassGuid
: &GUID_NULL
,
1188 sizeof(list
->ClassGuid
));
1190 list_init(&list
->devices
);
1195 /***********************************************************************
1196 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1198 HKEY WINAPI
SetupDiCreateDevRegKeyA(
1199 HDEVINFO DeviceInfoSet
,
1200 PSP_DEVINFO_DATA DeviceInfoData
,
1205 PCSTR InfSectionName
)
1207 PWSTR InfSectionNameW
= NULL
;
1210 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1211 HwProfile
, KeyType
, InfHandle
, debugstr_a(InfSectionName
));
1215 if (!InfSectionName
)
1217 SetLastError(ERROR_INVALID_PARAMETER
);
1218 return INVALID_HANDLE_VALUE
;
1222 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
1223 if (InfSectionNameW
== NULL
) return INVALID_HANDLE_VALUE
;
1226 key
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, Scope
,
1227 HwProfile
, KeyType
, InfHandle
, InfSectionNameW
);
1228 MyFree(InfSectionNameW
);
1232 /***********************************************************************
1233 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1235 HKEY WINAPI
SetupDiCreateDevRegKeyW(
1236 HDEVINFO DeviceInfoSet
,
1237 PSP_DEVINFO_DATA DeviceInfoData
,
1242 PCWSTR InfSectionName
)
1244 struct DeviceInfoSet
*set
= DeviceInfoSet
;
1245 struct DeviceInfo
*devInfo
;
1246 HKEY key
= INVALID_HANDLE_VALUE
;
1248 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1249 HwProfile
, KeyType
, InfHandle
, debugstr_w(InfSectionName
));
1251 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1253 SetLastError(ERROR_INVALID_HANDLE
);
1254 return INVALID_HANDLE_VALUE
;
1256 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1258 SetLastError(ERROR_INVALID_HANDLE
);
1259 return INVALID_HANDLE_VALUE
;
1261 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1262 || !DeviceInfoData
->Reserved
)
1264 SetLastError(ERROR_INVALID_PARAMETER
);
1265 return INVALID_HANDLE_VALUE
;
1267 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1268 if (devInfo
->set
!= set
)
1270 SetLastError(ERROR_INVALID_PARAMETER
);
1271 return INVALID_HANDLE_VALUE
;
1273 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
1275 SetLastError(ERROR_INVALID_FLAGS
);
1276 return INVALID_HANDLE_VALUE
;
1278 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
1280 SetLastError(ERROR_INVALID_FLAGS
);
1281 return INVALID_HANDLE_VALUE
;
1283 if (devInfo
->phantom
)
1285 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
1286 return INVALID_HANDLE_VALUE
;
1288 if (Scope
!= DICS_FLAG_GLOBAL
)
1289 FIXME("unimplemented for scope %d\n", Scope
);
1293 key
= SETUPDI_CreateDevKey(devInfo
);
1296 key
= SETUPDI_CreateDrvKey(devInfo
);
1299 WARN("unknown KeyType %d\n", KeyType
);
1302 SetupInstallFromInfSectionW(NULL
, InfHandle
, InfSectionName
, SPINST_ALL
,
1303 NULL
, NULL
, SP_COPY_NEWER_ONLY
, NULL
, NULL
, DeviceInfoSet
,
1308 /***********************************************************************
1309 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1311 BOOL WINAPI
SetupDiCreateDeviceInfoA(
1312 HDEVINFO DeviceInfoSet
,
1314 CONST GUID
*ClassGuid
,
1315 PCSTR DeviceDescription
,
1317 DWORD CreationFlags
,
1318 PSP_DEVINFO_DATA DeviceInfoData
)
1321 LPWSTR DeviceNameW
= NULL
;
1322 LPWSTR DeviceDescriptionW
= NULL
;
1326 DeviceNameW
= MultiByteToUnicode(DeviceName
, CP_ACP
);
1327 if (DeviceNameW
== NULL
) return FALSE
;
1329 if (DeviceDescription
)
1331 DeviceDescriptionW
= MultiByteToUnicode(DeviceDescription
, CP_ACP
);
1332 if (DeviceDescriptionW
== NULL
)
1334 MyFree(DeviceNameW
);
1339 ret
= SetupDiCreateDeviceInfoW(DeviceInfoSet
, DeviceNameW
, ClassGuid
, DeviceDescriptionW
,
1340 hwndParent
, CreationFlags
, DeviceInfoData
);
1342 MyFree(DeviceNameW
);
1343 MyFree(DeviceDescriptionW
);
1348 static DWORD
SETUPDI_DevNameToDevID(LPCWSTR devName
)
1351 int devNameLen
= lstrlenW(devName
);
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
= 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
= 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
= 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
= 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
< strlenW(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
,
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
, guid
, subKeyName
+ 1, &iface
);
2006 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2009 WCHAR symbolicLink
[MAX_PATH
];
2012 len
= sizeof(symbolicLink
);
2013 l
= RegQueryValueExW(subKey
, SymbolicLink
, NULL
, &dataType
,
2014 (BYTE
*)symbolicLink
, &len
);
2015 if (!l
&& dataType
== REG_SZ
)
2016 SETUPDI_SetInterfaceSymbolicLink(iface
, symbolicLink
);
2017 RegCloseKey(subKey
);
2020 /* Allow enumeration to continue */
2024 /* FIXME: find and add all the device's interfaces to the device */
2027 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet
,
2028 HKEY key
, const GUID
*guid
, LPCWSTR enumstr
)
2030 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2032 WCHAR subKeyName
[MAX_PATH
];
2034 HKEY enumKey
= INVALID_HANDLE_VALUE
;
2036 TRACE("%s\n", debugstr_w(enumstr
));
2038 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2040 for (i
= 0; !l
; i
++)
2042 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2043 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2048 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2051 WCHAR deviceInst
[MAX_PATH
* 3];
2054 len
= sizeof(deviceInst
);
2055 l
= RegQueryValueExW(subKey
, DeviceInstance
, NULL
, &dataType
,
2056 (BYTE
*)deviceInst
, &len
);
2057 if (!l
&& dataType
== REG_SZ
)
2059 TRACE("found instance ID %s\n", debugstr_w(deviceInst
));
2060 if (!enumstr
|| !lstrcmpiW(enumstr
, deviceInst
))
2064 l
= RegOpenKeyExW(enumKey
, deviceInst
, 0, KEY_READ
,
2068 WCHAR deviceClassStr
[40];
2070 len
= sizeof(deviceClassStr
);
2071 l
= RegQueryValueExW(deviceKey
, ClassGUID
, NULL
,
2072 &dataType
, (BYTE
*)deviceClassStr
, &len
);
2073 if (!l
&& dataType
== REG_SZ
&&
2074 deviceClassStr
[0] == '{' &&
2075 deviceClassStr
[37] == '}')
2078 SP_DEVINFO_DATA
*dev
;
2080 deviceClassStr
[37] = 0;
2081 UuidFromStringW(&deviceClassStr
[1],
2083 if (SETUPDI_AddDeviceToSet(set
, &deviceClass
,
2084 0 /* FIXME: DevInst */, deviceInst
,
2086 SETUPDI_AddDeviceInterfaces(dev
, subKey
, guid
);
2088 RegCloseKey(deviceKey
);
2092 RegCloseKey(subKey
);
2094 /* Allow enumeration to continue */
2098 if (enumKey
!= INVALID_HANDLE_VALUE
)
2099 RegCloseKey(enumKey
);
2102 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet
,
2103 const GUID
*guid
, LPCWSTR enumstr
, DWORD flags
)
2105 HKEY interfacesKey
= SetupDiOpenClassRegKeyExW(guid
, KEY_READ
,
2106 DIOCR_INTERFACE
, NULL
, NULL
);
2108 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(guid
),
2109 debugstr_w(enumstr
), flags
);
2111 if (interfacesKey
!= INVALID_HANDLE_VALUE
)
2113 if (flags
& DIGCF_ALLCLASSES
)
2116 WCHAR interfaceGuidStr
[40];
2117 LONG l
= ERROR_SUCCESS
;
2119 for (i
= 0; !l
; i
++)
2121 len
= sizeof(interfaceGuidStr
) / sizeof(interfaceGuidStr
[0]);
2122 l
= RegEnumKeyExW(interfacesKey
, i
, interfaceGuidStr
, &len
,
2123 NULL
, NULL
, NULL
, NULL
);
2126 if (interfaceGuidStr
[0] == '{' &&
2127 interfaceGuidStr
[37] == '}')
2132 interfaceGuidStr
[37] = 0;
2133 UuidFromStringW(&interfaceGuidStr
[1], &interfaceGuid
);
2134 l
= RegOpenKeyExW(interfacesKey
, interfaceGuidStr
, 0,
2135 KEY_READ
, &interfaceKey
);
2138 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2139 interfaceKey
, &interfaceGuid
, enumstr
);
2140 RegCloseKey(interfaceKey
);
2148 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2149 * interface's key, so just pass that long
2151 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2152 interfacesKey
, guid
, enumstr
);
2154 RegCloseKey(interfacesKey
);
2158 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet
*set
,
2159 LPCWSTR enumerator
, LPCWSTR deviceName
, HKEY deviceKey
,
2160 const GUID
*class, DWORD flags
)
2163 WCHAR deviceInstance
[MAX_PATH
];
2164 LONG l
= ERROR_SUCCESS
;
2166 TRACE("%s %s\n", debugstr_w(enumerator
), debugstr_w(deviceName
));
2168 for (i
= 0; !l
; i
++)
2170 len
= sizeof(deviceInstance
) / sizeof(deviceInstance
[0]);
2171 l
= RegEnumKeyExW(deviceKey
, i
, deviceInstance
, &len
, NULL
, NULL
, NULL
,
2177 l
= RegOpenKeyExW(deviceKey
, deviceInstance
, 0, KEY_READ
, &subKey
);
2180 WCHAR classGuid
[40];
2183 len
= sizeof(classGuid
);
2184 l
= RegQueryValueExW(subKey
, ClassGUID
, NULL
, &dataType
,
2185 (BYTE
*)classGuid
, &len
);
2186 if (!l
&& dataType
== REG_SZ
)
2188 if (classGuid
[0] == '{' && classGuid
[37] == '}')
2193 UuidFromStringW(&classGuid
[1], &deviceClass
);
2194 if ((flags
& DIGCF_ALLCLASSES
) ||
2195 IsEqualGUID(class, &deviceClass
))
2197 static const WCHAR fmt
[] =
2198 {'%','s','\\','%','s','\\','%','s',0};
2201 instanceId
= HeapAlloc(GetProcessHeap(), 0,
2202 (lstrlenW(enumerator
) + lstrlenW(deviceName
) +
2203 lstrlenW(deviceInstance
) + 3) * sizeof(WCHAR
));
2206 sprintfW(instanceId
, fmt
, enumerator
,
2207 deviceName
, deviceInstance
);
2208 SETUPDI_AddDeviceToSet(set
, &deviceClass
,
2209 0 /* FIXME: DevInst */, instanceId
,
2211 HeapFree(GetProcessHeap(), 0, instanceId
);
2216 RegCloseKey(subKey
);
2218 /* Allow enumeration to continue */
2224 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet
,
2225 LPCWSTR parent
, HKEY key
, const GUID
*class, DWORD flags
)
2227 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2229 WCHAR subKeyName
[MAX_PATH
];
2230 LONG l
= ERROR_SUCCESS
;
2232 TRACE("%s\n", debugstr_w(parent
));
2234 for (i
= 0; !l
; i
++)
2236 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2237 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2242 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2245 TRACE("%s\n", debugstr_w(subKeyName
));
2246 SETUPDI_EnumerateMatchingDeviceInstances(set
, parent
,
2247 subKeyName
, subKey
, class, flags
);
2248 RegCloseKey(subKey
);
2250 /* Allow enumeration to continue */
2256 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet
, const GUID
*class,
2257 LPCWSTR enumstr
, DWORD flags
)
2262 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(class),
2263 debugstr_w(enumstr
), flags
);
2265 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2267 if (enumKey
!= INVALID_HANDLE_VALUE
)
2273 l
= RegOpenKeyExW(enumKey
, enumstr
, 0, KEY_READ
,
2277 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
, enumstr
,
2278 enumStrKey
, class, flags
);
2279 RegCloseKey(enumStrKey
);
2285 WCHAR subKeyName
[MAX_PATH
];
2288 for (i
= 0; !l
; i
++)
2290 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2291 l
= RegEnumKeyExW(enumKey
, i
, subKeyName
, &len
, NULL
,
2297 l
= RegOpenKeyExW(enumKey
, subKeyName
, 0, KEY_READ
,
2301 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
,
2302 subKeyName
, subKey
, class, flags
);
2303 RegCloseKey(subKey
);
2305 /* Allow enumeration to continue */
2310 RegCloseKey(enumKey
);
2314 /***********************************************************************
2315 * SetupDiGetClassDevsW (SETUPAPI.@)
2317 HDEVINFO WINAPI
SetupDiGetClassDevsW(
2323 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2327 /***********************************************************************
2328 * SetupDiGetClassDevsExW (SETUPAPI.@)
2330 HDEVINFO WINAPI
SetupDiGetClassDevsExW(
2339 static const DWORD unsupportedFlags
= DIGCF_DEFAULT
| DIGCF_PRESENT
|
2343 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2344 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2347 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2349 SetLastError(ERROR_INVALID_PARAMETER
);
2352 if (flags
& unsupportedFlags
)
2353 WARN("unsupported flags %08x\n", flags
& unsupportedFlags
);
2357 set
= SetupDiCreateDeviceInfoListExW(class, parent
, machine
, reserved
);
2361 FIXME("%s: unimplemented for remote machines\n",
2362 debugstr_w(machine
));
2363 else if (flags
& DIGCF_DEVICEINTERFACE
)
2364 SETUPDI_EnumerateInterfaces(set
, class, enumstr
, flags
);
2366 SETUPDI_EnumerateDevices(set
, class, enumstr
, flags
);
2371 /***********************************************************************
2372 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2374 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2375 HDEVINFO DeviceInfoSet
,
2376 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2378 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2380 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2382 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2384 SetLastError(ERROR_INVALID_HANDLE
);
2387 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2389 SetLastError(ERROR_INVALID_HANDLE
);
2393 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2395 SetLastError(ERROR_INVALID_PARAMETER
);
2398 DevInfoData
->ClassGuid
= set
->ClassGuid
;
2399 DevInfoData
->RemoteMachineHandle
= NULL
;
2400 DevInfoData
->RemoteMachineName
[0] = '\0';
2404 /***********************************************************************
2405 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2407 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2408 HDEVINFO DeviceInfoSet
,
2409 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2411 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2413 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2415 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2417 SetLastError(ERROR_INVALID_HANDLE
);
2420 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2422 SetLastError(ERROR_INVALID_HANDLE
);
2426 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2428 SetLastError(ERROR_INVALID_PARAMETER
);
2431 DevInfoData
->ClassGuid
= set
->ClassGuid
;
2432 DevInfoData
->RemoteMachineHandle
= NULL
;
2433 DevInfoData
->RemoteMachineName
[0] = '\0';
2437 /***********************************************************************
2438 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2440 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2441 HDEVINFO DeviceInfoSet
,
2442 PSP_DEVINFO_DATA DeviceInfoData
,
2443 const GUID
*InterfaceClassGuid
,
2444 PCSTR ReferenceString
,
2445 DWORD CreationFlags
,
2446 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2449 LPWSTR ReferenceStringW
= NULL
;
2451 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2452 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2453 CreationFlags
, DeviceInterfaceData
);
2455 if (ReferenceString
)
2457 ReferenceStringW
= MultiByteToUnicode(ReferenceString
, CP_ACP
);
2458 if (ReferenceStringW
== NULL
) return FALSE
;
2461 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2462 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2463 DeviceInterfaceData
);
2465 MyFree(ReferenceStringW
);
2470 /***********************************************************************
2471 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2473 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2474 HDEVINFO DeviceInfoSet
,
2475 PSP_DEVINFO_DATA DeviceInfoData
,
2476 const GUID
*InterfaceClassGuid
,
2477 PCWSTR ReferenceString
,
2478 DWORD CreationFlags
,
2479 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2481 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2482 struct DeviceInfo
*devInfo
;
2483 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
2486 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2487 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2488 CreationFlags
, DeviceInterfaceData
);
2490 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2492 SetLastError(ERROR_INVALID_HANDLE
);
2495 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2497 SetLastError(ERROR_INVALID_HANDLE
);
2500 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2501 || !DeviceInfoData
->Reserved
)
2503 SetLastError(ERROR_INVALID_PARAMETER
);
2506 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2507 if (devInfo
->set
!= set
)
2509 SetLastError(ERROR_INVALID_PARAMETER
);
2512 if (!InterfaceClassGuid
)
2514 SetLastError(ERROR_INVALID_USER_BUFFER
);
2517 if ((ret
= SETUPDI_AddInterfaceInstance(DeviceInfoData
, InterfaceClassGuid
,
2518 ReferenceString
, &iface
)))
2520 if (DeviceInterfaceData
)
2522 if (DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2524 SetLastError(ERROR_INVALID_USER_BUFFER
);
2528 *DeviceInterfaceData
= *iface
;
2534 /***********************************************************************
2535 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2537 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2538 HDEVINFO DeviceInfoSet
,
2539 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2543 PCSTR InfSectionName
)
2546 PWSTR InfSectionNameW
= NULL
;
2548 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2549 samDesired
, InfHandle
, InfSectionName
);
2552 if (!InfSectionName
)
2554 SetLastError(ERROR_INVALID_PARAMETER
);
2555 return INVALID_HANDLE_VALUE
;
2557 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2558 if (!InfSectionNameW
)
2559 return INVALID_HANDLE_VALUE
;
2561 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2562 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2564 MyFree(InfSectionNameW
);
2568 static PWSTR
SETUPDI_GetInstancePath(struct InterfaceInfo
*ifaceInfo
)
2570 static const WCHAR hash
[] = {'#',0};
2571 PWSTR instancePath
= NULL
;
2573 if (ifaceInfo
->referenceString
)
2575 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2576 (lstrlenW(ifaceInfo
->referenceString
) + 2) * sizeof(WCHAR
));
2579 lstrcpyW(instancePath
, hash
);
2580 lstrcatW(instancePath
, ifaceInfo
->referenceString
);
2583 SetLastError(ERROR_OUTOFMEMORY
);
2587 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2588 (lstrlenW(hash
) + 1) * sizeof(WCHAR
));
2590 lstrcpyW(instancePath
, hash
);
2592 return instancePath
;
2595 /***********************************************************************
2596 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2598 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2599 HDEVINFO DeviceInfoSet
,
2600 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2604 PCWSTR InfSectionName
)
2606 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2607 HKEY key
= INVALID_HANDLE_VALUE
, interfacesKey
;
2610 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2611 samDesired
, InfHandle
, InfSectionName
);
2613 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2614 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2616 SetLastError(ERROR_INVALID_HANDLE
);
2617 return INVALID_HANDLE_VALUE
;
2619 if (!DeviceInterfaceData
||
2620 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2621 !DeviceInterfaceData
->Reserved
)
2623 SetLastError(ERROR_INVALID_PARAMETER
);
2624 return INVALID_HANDLE_VALUE
;
2626 if (InfHandle
&& !InfSectionName
)
2628 SetLastError(ERROR_INVALID_PARAMETER
);
2629 return INVALID_HANDLE_VALUE
;
2631 if (!(l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, DeviceClasses
, 0, NULL
, 0,
2632 samDesired
, NULL
, &interfacesKey
, NULL
)))
2635 WCHAR bracedGuidString
[39];
2637 SETUPDI_GuidToString(&DeviceInterfaceData
->InterfaceClassGuid
,
2639 if (!(l
= RegCreateKeyExW(interfacesKey
, bracedGuidString
, 0, NULL
, 0,
2640 samDesired
, NULL
, &parent
, NULL
)))
2642 struct InterfaceInfo
*ifaceInfo
=
2643 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2644 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2645 PWSTR interfKeyName
= HeapAlloc(GetProcessHeap(), 0,
2646 (lstrlenW(ifaceInfo
->symbolicLink
) + 1) * sizeof(WCHAR
));
2650 lstrcpyW(interfKeyName
, ifaceInfo
->symbolicLink
);
2651 if (lstrlenW(ifaceInfo
->symbolicLink
) > 3)
2653 interfKeyName
[0] = '#';
2654 interfKeyName
[1] = '#';
2655 interfKeyName
[3] = '#';
2657 ptr
= strchrW(interfKeyName
, '\\');
2660 l
= RegCreateKeyExW(parent
, interfKeyName
, 0, NULL
, 0,
2661 samDesired
, NULL
, &interfKey
, NULL
);
2664 struct DeviceInfo
*devInfo
=
2665 (struct DeviceInfo
*)ifaceInfo
->device
->Reserved
;
2667 l
= RegSetValueExW(interfKey
, DeviceInstance
, 0, REG_SZ
,
2668 (BYTE
*)devInfo
->instanceId
,
2669 (lstrlenW(devInfo
->instanceId
) + 1) * sizeof(WCHAR
));
2676 l
= RegCreateKeyExW(interfKey
, instancePath
, 0, NULL
, 0,
2677 samDesired
, NULL
, &key
, NULL
);
2681 key
= INVALID_HANDLE_VALUE
;
2684 FIXME("INF section installation unsupported\n");
2689 RegCloseKey(interfKey
);
2693 HeapFree(GetProcessHeap(), 0, interfKeyName
);
2694 HeapFree(GetProcessHeap(), 0, instancePath
);
2695 RegCloseKey(parent
);
2699 RegCloseKey(interfacesKey
);
2706 /***********************************************************************
2707 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2709 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2710 HDEVINFO DeviceInfoSet
,
2711 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2714 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2718 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2720 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2721 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2723 SetLastError(ERROR_INVALID_HANDLE
);
2726 if (!DeviceInterfaceData
||
2727 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2728 !DeviceInterfaceData
->Reserved
)
2730 SetLastError(ERROR_INVALID_PARAMETER
);
2733 parent
= SetupDiOpenClassRegKeyExW(&DeviceInterfaceData
->InterfaceClassGuid
,
2734 KEY_ALL_ACCESS
, DIOCR_INTERFACE
, NULL
, NULL
);
2735 if (parent
!= INVALID_HANDLE_VALUE
)
2737 struct InterfaceInfo
*ifaceInfo
=
2738 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2739 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2743 LONG l
= RegDeleteKeyW(parent
, instancePath
);
2749 HeapFree(GetProcessHeap(), 0, instancePath
);
2751 RegCloseKey(parent
);
2756 /***********************************************************************
2757 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2760 * DeviceInfoSet [I] Set of devices from which to enumerate
2762 * DeviceInfoData [I] (Optional) If specified, a specific device
2763 * instance from which to enumerate interfaces.
2764 * If it isn't specified, all interfaces for all
2765 * devices in the set are enumerated.
2766 * InterfaceClassGuid [I] The interface class to enumerate.
2767 * MemberIndex [I] An index of the interface instance to enumerate.
2768 * A caller should start with MemberIndex set to 0,
2769 * and continue until the function fails with
2770 * ERROR_NO_MORE_ITEMS.
2771 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2772 * member must be set to
2773 * sizeof(SP_DEVICE_INTERFACE_DATA).
2776 * Success: non-zero value.
2777 * Failure: FALSE. Call GetLastError() for more info.
2779 BOOL WINAPI
SetupDiEnumDeviceInterfaces(
2780 HDEVINFO DeviceInfoSet
,
2781 PSP_DEVINFO_DATA DeviceInfoData
,
2782 CONST GUID
* InterfaceClassGuid
,
2784 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2786 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2789 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet
, DeviceInfoData
,
2790 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
2792 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2793 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2795 SetLastError(ERROR_INVALID_HANDLE
);
2798 if (DeviceInfoData
&& (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2799 !DeviceInfoData
->Reserved
))
2801 SetLastError(ERROR_INVALID_PARAMETER
);
2804 if (!DeviceInterfaceData
||
2805 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2807 SetLastError(ERROR_INVALID_PARAMETER
);
2812 struct DeviceInfo
*devInfo
=
2813 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2814 struct InterfaceInstances
*iface
;
2816 if ((ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
2818 if (MemberIndex
< iface
->cInstances
)
2819 *DeviceInterfaceData
= iface
->instances
[MemberIndex
];
2822 SetLastError(ERROR_NO_MORE_ITEMS
);
2827 SetLastError(ERROR_NO_MORE_ITEMS
);
2831 struct DeviceInstance
*devInst
;
2832 DWORD cEnumerated
= 0;
2835 LIST_FOR_EACH_ENTRY(devInst
, &set
->devices
, struct DeviceInstance
, entry
)
2837 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)devInst
->data
.Reserved
;
2838 struct InterfaceInstances
*iface
;
2840 if (found
|| cEnumerated
>= MemberIndex
+ 1)
2842 if (SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
))
2844 if (cEnumerated
+ iface
->cInstances
< MemberIndex
+ 1)
2845 cEnumerated
+= iface
->cInstances
;
2848 DWORD instanceIndex
= MemberIndex
- cEnumerated
;
2850 *DeviceInterfaceData
= iface
->instances
[instanceIndex
];
2851 cEnumerated
+= instanceIndex
+ 1;
2858 SetLastError(ERROR_NO_MORE_ITEMS
);
2863 /***********************************************************************
2864 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2866 * Destroy a DeviceInfoList and free all used memory of the list.
2869 * devinfo [I] DeviceInfoList pointer to list to destroy
2872 * Success: non zero value.
2873 * Failure: zero value.
2875 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
2879 TRACE("%p\n", devinfo
);
2880 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
2882 struct DeviceInfoSet
*list
= devinfo
;
2884 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
2886 struct DeviceInstance
*devInst
, *devInst2
;
2888 LIST_FOR_EACH_ENTRY_SAFE(devInst
, devInst2
, &list
->devices
,
2889 struct DeviceInstance
, entry
)
2891 SETUPDI_FreeDeviceInfo( (struct DeviceInfo
*)devInst
->data
.Reserved
);
2892 list_remove(&devInst
->entry
);
2893 HeapFree(GetProcessHeap(), 0, devInst
);
2895 HeapFree(GetProcessHeap(), 0, list
);
2901 SetLastError(ERROR_INVALID_HANDLE
);
2906 /***********************************************************************
2907 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2909 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
2910 HDEVINFO DeviceInfoSet
,
2911 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2912 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
2913 DWORD DeviceInterfaceDetailDataSize
,
2914 PDWORD RequiredSize
,
2915 PSP_DEVINFO_DATA DeviceInfoData
)
2917 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2918 struct InterfaceInfo
*info
;
2919 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
)
2923 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2924 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2925 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2927 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2928 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2930 SetLastError(ERROR_INVALID_HANDLE
);
2933 if (!DeviceInterfaceData
||
2934 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2935 !DeviceInterfaceData
->Reserved
)
2937 SetLastError(ERROR_INVALID_PARAMETER
);
2940 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
!=
2941 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + sizeof(char)))
2943 SetLastError(ERROR_INVALID_USER_BUFFER
);
2946 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2948 SetLastError(ERROR_INVALID_USER_BUFFER
);
2951 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2952 if (info
->symbolicLink
)
2953 bytesNeeded
+= WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2954 NULL
, 0, NULL
, NULL
);
2955 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2957 if (info
->symbolicLink
)
2958 WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2959 DeviceInterfaceDetailData
->DevicePath
,
2960 DeviceInterfaceDetailDataSize
-
2961 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
2964 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2965 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2966 *DeviceInfoData
= *info
->device
;
2972 *RequiredSize
= bytesNeeded
;
2973 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2978 /***********************************************************************
2979 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2981 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
2982 HDEVINFO DeviceInfoSet
,
2983 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2984 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
2985 DWORD DeviceInterfaceDetailDataSize
,
2986 PDWORD RequiredSize
,
2987 PSP_DEVINFO_DATA DeviceInfoData
)
2989 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2990 struct InterfaceInfo
*info
;
2991 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
2992 + sizeof(WCHAR
); /* include NULL terminator */
2995 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2996 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2997 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2999 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
3000 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3002 SetLastError(ERROR_INVALID_HANDLE
);
3005 if (!DeviceInterfaceData
||
3006 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
3007 !DeviceInterfaceData
->Reserved
)
3009 SetLastError(ERROR_INVALID_PARAMETER
);
3012 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
3013 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
) ||
3014 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
)))
3016 SetLastError(ERROR_INVALID_USER_BUFFER
);
3019 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
3021 SetLastError(ERROR_INVALID_USER_BUFFER
);
3024 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
3025 if (info
->symbolicLink
)
3026 bytesNeeded
+= sizeof(WCHAR
)*lstrlenW(info
->symbolicLink
);
3027 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
3029 if (info
->symbolicLink
)
3030 lstrcpyW(DeviceInterfaceDetailData
->DevicePath
, info
->symbolicLink
);
3032 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
3033 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
3034 *DeviceInfoData
= *info
->device
;
3040 *RequiredSize
= bytesNeeded
;
3041 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3046 struct PropertyMapEntry
3053 static const struct PropertyMapEntry PropertyMap
[] = {
3054 { REG_SZ
, "DeviceDesc", DeviceDesc
},
3055 { REG_MULTI_SZ
, "HardwareId", HardwareId
},
3056 { REG_MULTI_SZ
, "CompatibleIDs", CompatibleIDs
},
3057 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
3058 { REG_SZ
, "Service", Service
},
3059 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
3060 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
3061 { REG_SZ
, "Class", Class
},
3062 { REG_SZ
, "ClassGUID", ClassGUID
},
3063 { REG_SZ
, "Driver", Driver
},
3064 { REG_DWORD
, "ConfigFlags", ConfigFlags
},
3065 { REG_SZ
, "Mfg", Mfg
},
3066 { REG_SZ
, "FriendlyName", FriendlyName
},
3067 { REG_SZ
, "LocationInformation", LocationInformation
},
3068 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3069 { REG_DWORD
, "Capabilities", Capabilities
},
3070 { REG_DWORD
, "UINumber", UINumber
},
3071 { REG_MULTI_SZ
, "UpperFilters", UpperFilters
},
3072 { REG_MULTI_SZ
, "LowerFilters", LowerFilters
},
3075 /***********************************************************************
3076 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3078 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
3079 HDEVINFO DeviceInfoSet
,
3080 PSP_DEVINFO_DATA DeviceInfoData
,
3082 PDWORD PropertyRegDataType
,
3083 PBYTE PropertyBuffer
,
3084 DWORD PropertyBufferSize
,
3085 PDWORD RequiredSize
)
3088 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3089 struct DeviceInfo
*devInfo
;
3091 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3092 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3095 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3097 SetLastError(ERROR_INVALID_HANDLE
);
3100 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3102 SetLastError(ERROR_INVALID_HANDLE
);
3105 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3106 || !DeviceInfoData
->Reserved
)
3108 SetLastError(ERROR_INVALID_PARAMETER
);
3111 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
3113 SetLastError(ERROR_INVALID_DATA
);
3116 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3117 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3118 && PropertyMap
[Property
].nameA
)
3120 DWORD size
= PropertyBufferSize
;
3121 LONG l
= RegQueryValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
,
3122 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3124 if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3125 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3131 *RequiredSize
= size
;
3136 /***********************************************************************
3137 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3139 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3140 HDEVINFO DeviceInfoSet
,
3141 PSP_DEVINFO_DATA DeviceInfoData
,
3143 PDWORD PropertyRegDataType
,
3144 PBYTE PropertyBuffer
,
3145 DWORD PropertyBufferSize
,
3146 PDWORD RequiredSize
)
3149 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3150 struct DeviceInfo
*devInfo
;
3152 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3153 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3156 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3158 SetLastError(ERROR_INVALID_HANDLE
);
3161 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3163 SetLastError(ERROR_INVALID_HANDLE
);
3166 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3167 || !DeviceInfoData
->Reserved
)
3169 SetLastError(ERROR_INVALID_PARAMETER
);
3172 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
3174 SetLastError(ERROR_INVALID_DATA
);
3177 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3178 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3179 && PropertyMap
[Property
].nameW
)
3181 DWORD size
= PropertyBufferSize
;
3182 LONG l
= RegQueryValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
,
3183 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3185 if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3186 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3192 *RequiredSize
= size
;
3197 /***********************************************************************
3198 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3200 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3201 HDEVINFO DeviceInfoSet
,
3202 PSP_DEVINFO_DATA DeviceInfoData
,
3204 const BYTE
*PropertyBuffer
,
3205 DWORD PropertyBufferSize
)
3208 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3209 struct DeviceInfo
*devInfo
;
3211 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3212 PropertyBuffer
, PropertyBufferSize
);
3214 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3216 SetLastError(ERROR_INVALID_HANDLE
);
3219 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3221 SetLastError(ERROR_INVALID_HANDLE
);
3224 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3225 || !DeviceInfoData
->Reserved
)
3227 SetLastError(ERROR_INVALID_PARAMETER
);
3230 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3231 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3232 && PropertyMap
[Property
].nameA
)
3234 LONG l
= RegSetValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
, 0,
3235 PropertyMap
[Property
].regType
, PropertyBuffer
,
3236 PropertyBufferSize
);
3245 /***********************************************************************
3246 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3248 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
3249 HDEVINFO DeviceInfoSet
,
3250 PSP_DEVINFO_DATA DeviceInfoData
,
3252 const BYTE
*PropertyBuffer
,
3253 DWORD PropertyBufferSize
)
3256 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3257 struct DeviceInfo
*devInfo
;
3259 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3260 PropertyBuffer
, PropertyBufferSize
);
3262 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3264 SetLastError(ERROR_INVALID_HANDLE
);
3267 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3269 SetLastError(ERROR_INVALID_HANDLE
);
3272 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3273 || !DeviceInfoData
->Reserved
)
3275 SetLastError(ERROR_INVALID_PARAMETER
);
3278 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3279 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3280 && PropertyMap
[Property
].nameW
)
3282 LONG l
= RegSetValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
, 0,
3283 PropertyMap
[Property
].regType
, PropertyBuffer
,
3284 PropertyBufferSize
);
3293 /***********************************************************************
3294 * SetupDiInstallClassA (SETUPAPI.@)
3296 BOOL WINAPI
SetupDiInstallClassA(
3302 UNICODE_STRING FileNameW
;
3307 SetLastError(ERROR_INVALID_PARAMETER
);
3310 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW
, InfFileName
))
3312 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3316 Result
= SetupDiInstallClassW(hwndParent
, FileNameW
.Buffer
, Flags
, FileQueue
);
3318 RtlFreeUnicodeString(&FileNameW
);
3323 static HKEY
CreateClassKey(HINF hInf
)
3325 static const WCHAR slash
[] = { '\\',0 };
3326 WCHAR FullBuffer
[MAX_PATH
];
3327 WCHAR Buffer
[MAX_PATH
];
3331 if (!SetupGetLineTextW(NULL
,
3339 return INVALID_HANDLE_VALUE
;
3342 lstrcpyW(FullBuffer
, ControlClass
);
3343 lstrcatW(FullBuffer
, slash
);
3344 lstrcatW(FullBuffer
, Buffer
);
3346 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3352 if (!SetupGetLineTextW(NULL
,
3360 return INVALID_HANDLE_VALUE
;
3363 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3367 REG_OPTION_NON_VOLATILE
,
3373 return INVALID_HANDLE_VALUE
;
3378 if (RegSetValueExW(hClassKey
,
3383 RequiredSize
* sizeof(WCHAR
)))
3385 RegCloseKey(hClassKey
);
3386 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3388 return INVALID_HANDLE_VALUE
;
3394 /***********************************************************************
3395 * SetupDiInstallClassW (SETUPAPI.@)
3397 BOOL WINAPI
SetupDiInstallClassW(
3403 WCHAR SectionName
[MAX_PATH
];
3404 DWORD SectionNameLength
= 0;
3406 BOOL bFileQueueCreated
= FALSE
;
3414 SetLastError(ERROR_INVALID_PARAMETER
);
3417 if ((Flags
& DI_NOVCP
) && (FileQueue
== NULL
|| FileQueue
== INVALID_HANDLE_VALUE
))
3419 SetLastError(ERROR_INVALID_PARAMETER
);
3423 /* Open the .inf file */
3424 hInf
= SetupOpenInfFileW(InfFileName
,
3428 if (hInf
== INVALID_HANDLE_VALUE
)
3434 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3435 hClassKey
= CreateClassKey(hInf
);
3436 if (hClassKey
== INVALID_HANDLE_VALUE
)
3438 SetupCloseInfFile(hInf
);
3443 /* Try to append a layout file */
3444 SetupOpenAppendInfFileW(NULL
, hInf
, NULL
);
3446 /* Retrieve the actual section name */
3447 SetupDiGetActualSectionToInstallW(hInf
,
3455 if (!(Flags
& DI_NOVCP
))
3457 FileQueue
= SetupOpenFileQueue();
3458 if (FileQueue
== INVALID_HANDLE_VALUE
)
3460 SetupCloseInfFile(hInf
);
3464 bFileQueueCreated
= TRUE
;
3469 SetupInstallFromInfSectionW(NULL
,
3472 SPINST_COPYINF
| SPINST_FILES
| SPINST_REGISTRY
,
3478 INVALID_HANDLE_VALUE
,
3481 /* FIXME: More code! */
3483 if (bFileQueueCreated
)
3484 SetupCloseFileQueue(FileQueue
);
3486 SetupCloseInfFile(hInf
);
3492 /***********************************************************************
3493 * SetupDiOpenClassRegKey (SETUPAPI.@)
3495 HKEY WINAPI
SetupDiOpenClassRegKey(
3496 const GUID
* ClassGuid
,
3499 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3500 DIOCR_INSTALLER
, NULL
, NULL
);
3504 /***********************************************************************
3505 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3507 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3508 const GUID
* ClassGuid
,
3514 PWSTR MachineNameW
= NULL
;
3521 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
3522 if (MachineNameW
== NULL
)
3523 return INVALID_HANDLE_VALUE
;
3526 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3527 Flags
, MachineNameW
, Reserved
);
3529 MyFree(MachineNameW
);
3535 /***********************************************************************
3536 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3538 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3539 const GUID
* ClassGuid
,
3550 if (MachineName
!= NULL
)
3552 FIXME("Remote access not supported yet!\n");
3553 return INVALID_HANDLE_VALUE
;
3556 if (Flags
== DIOCR_INSTALLER
)
3558 lpKeyName
= ControlClass
;
3560 else if (Flags
== DIOCR_INTERFACE
)
3562 lpKeyName
= DeviceClasses
;
3566 ERR("Invalid Flags parameter!\n");
3567 SetLastError(ERROR_INVALID_PARAMETER
);
3568 return INVALID_HANDLE_VALUE
;
3573 if ((l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3580 hClassesKey
= INVALID_HANDLE_VALUE
;
3586 WCHAR bracedGuidString
[39];
3588 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3590 if (!(l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3596 if ((l
= RegOpenKeyExW(hClassesKey
,
3603 key
= INVALID_HANDLE_VALUE
;
3605 RegCloseKey(hClassesKey
);
3610 key
= INVALID_HANDLE_VALUE
;
3616 /***********************************************************************
3617 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3619 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3620 HDEVINFO DeviceInfoSet
,
3623 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3625 FIXME("%p %s %08x %p\n",
3626 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3630 /***********************************************************************
3631 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3633 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
3634 HDEVINFO DeviceInfoSet
,
3637 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3639 FIXME("%p %s %08x %p\n", DeviceInfoSet
,
3640 debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3644 /***********************************************************************
3645 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3647 BOOL WINAPI
SetupDiSetClassInstallParamsA(
3648 HDEVINFO DeviceInfoSet
,
3649 PSP_DEVINFO_DATA DeviceInfoData
,
3650 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3651 DWORD ClassInstallParamsSize
)
3653 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3654 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3658 /***********************************************************************
3659 * SetupDiCallClassInstaller (SETUPAPI.@)
3661 BOOL WINAPI
SetupDiCallClassInstaller(
3662 DI_FUNCTION InstallFunction
,
3663 HDEVINFO DeviceInfoSet
,
3664 PSP_DEVINFO_DATA DeviceInfoData
)
3666 FIXME("%d %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3670 /***********************************************************************
3671 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3673 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
3674 HDEVINFO DeviceInfoSet
,
3675 PSP_DEVINFO_DATA DeviceInfoData
,
3676 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3678 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3682 static HKEY
SETUPDI_OpenDevKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3684 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
3687 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3688 NULL
, &enumKey
, NULL
);
3691 RegOpenKeyExW(enumKey
, devInfo
->instanceId
, 0, samDesired
, &key
);
3692 RegCloseKey(enumKey
);
3697 static HKEY
SETUPDI_OpenDrvKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3699 static const WCHAR slash
[] = { '\\',0 };
3700 WCHAR classKeyPath
[MAX_PATH
];
3701 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
3704 lstrcpyW(classKeyPath
, ControlClass
);
3705 lstrcatW(classKeyPath
, slash
);
3706 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3707 classKeyPath
+ lstrlenW(classKeyPath
));
3708 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3709 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3712 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3715 sprintfW(devId
, fmt
, devInfo
->devId
);
3716 RegOpenKeyExW(classKey
, devId
, 0, samDesired
, &key
);
3717 RegCloseKey(classKey
);
3722 /***********************************************************************
3723 * SetupDiOpenDevRegKey (SETUPAPI.@)
3725 HKEY WINAPI
SetupDiOpenDevRegKey(
3726 HDEVINFO DeviceInfoSet
,
3727 PSP_DEVINFO_DATA DeviceInfoData
,
3733 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3734 struct DeviceInfo
*devInfo
;
3735 HKEY key
= INVALID_HANDLE_VALUE
;
3737 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
3738 Scope
, HwProfile
, KeyType
, samDesired
);
3740 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3742 SetLastError(ERROR_INVALID_HANDLE
);
3743 return INVALID_HANDLE_VALUE
;
3745 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3747 SetLastError(ERROR_INVALID_HANDLE
);
3748 return INVALID_HANDLE_VALUE
;
3750 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3751 || !DeviceInfoData
->Reserved
)
3753 SetLastError(ERROR_INVALID_PARAMETER
);
3754 return INVALID_HANDLE_VALUE
;
3756 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3758 SetLastError(ERROR_INVALID_FLAGS
);
3759 return INVALID_HANDLE_VALUE
;
3761 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
3763 SetLastError(ERROR_INVALID_FLAGS
);
3764 return INVALID_HANDLE_VALUE
;
3766 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3767 if (devInfo
->set
!= set
)
3769 SetLastError(ERROR_INVALID_PARAMETER
);
3770 return INVALID_HANDLE_VALUE
;
3772 if (devInfo
->phantom
)
3774 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3775 return INVALID_HANDLE_VALUE
;
3777 if (Scope
!= DICS_FLAG_GLOBAL
)
3778 FIXME("unimplemented for scope %d\n", Scope
);
3782 key
= SETUPDI_OpenDevKey(devInfo
, samDesired
);
3785 key
= SETUPDI_OpenDrvKey(devInfo
, samDesired
);
3788 WARN("unknown KeyType %d\n", KeyType
);
3793 static BOOL
SETUPDI_DeleteDevKey(struct DeviceInfo
*devInfo
)
3799 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3800 NULL
, &enumKey
, NULL
);
3803 ret
= RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
3804 RegCloseKey(enumKey
);
3811 static BOOL
SETUPDI_DeleteDrvKey(struct DeviceInfo
*devInfo
)
3813 static const WCHAR slash
[] = { '\\',0 };
3814 WCHAR classKeyPath
[MAX_PATH
];
3819 lstrcpyW(classKeyPath
, ControlClass
);
3820 lstrcatW(classKeyPath
, slash
);
3821 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3822 classKeyPath
+ lstrlenW(classKeyPath
));
3823 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3824 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3827 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3830 sprintfW(devId
, fmt
, devInfo
->devId
);
3831 ret
= RegDeleteTreeW(classKey
, devId
);
3832 RegCloseKey(classKey
);
3839 /***********************************************************************
3840 * SetupDiOpenDevRegKey (SETUPAPI.@)
3842 BOOL WINAPI
SetupDiDeleteDevRegKey(
3843 HDEVINFO DeviceInfoSet
,
3844 PSP_DEVINFO_DATA DeviceInfoData
,
3849 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3850 struct DeviceInfo
*devInfo
;
3853 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
3856 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3858 SetLastError(ERROR_INVALID_HANDLE
);
3861 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3863 SetLastError(ERROR_INVALID_HANDLE
);
3866 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3867 || !DeviceInfoData
->Reserved
)
3869 SetLastError(ERROR_INVALID_PARAMETER
);
3872 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3874 SetLastError(ERROR_INVALID_FLAGS
);
3877 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
3879 SetLastError(ERROR_INVALID_FLAGS
);
3882 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3883 if (devInfo
->set
!= set
)
3885 SetLastError(ERROR_INVALID_PARAMETER
);
3888 if (devInfo
->phantom
)
3890 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3893 if (Scope
!= DICS_FLAG_GLOBAL
)
3894 FIXME("unimplemented for scope %d\n", Scope
);
3898 ret
= SETUPDI_DeleteDevKey(devInfo
);
3901 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3904 ret
= SETUPDI_DeleteDevKey(devInfo
);
3906 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3909 WARN("unknown KeyType %d\n", KeyType
);
3914 /***********************************************************************
3915 * CM_Get_Device_IDA (SETUPAPI.@)
3917 CONFIGRET WINAPI
CM_Get_Device_IDA( DEVINST dnDevInst
, PSTR Buffer
,
3918 ULONG BufferLen
, ULONG ulFlags
)
3920 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
3922 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
3925 return CR_NO_SUCH_DEVINST
;
3927 WideCharToMultiByte(CP_ACP
, 0, devInfo
->instanceId
, -1, Buffer
, BufferLen
, 0, 0);
3928 TRACE("Returning %s\n", debugstr_a(Buffer
));
3932 /***********************************************************************
3933 * CM_Get_Device_IDW (SETUPAPI.@)
3935 CONFIGRET WINAPI
CM_Get_Device_IDW( DEVINST dnDevInst
, LPWSTR Buffer
,
3936 ULONG BufferLen
, ULONG ulFlags
)
3938 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
3940 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
3944 WARN("dev instance %d not found!\n", dnDevInst
);
3945 return CR_NO_SUCH_DEVINST
;
3948 lstrcpynW(Buffer
, devInfo
->instanceId
, BufferLen
);
3949 TRACE("Returning %s\n", debugstr_w(Buffer
));
3950 GlobalUnlock((HANDLE
)dnDevInst
);
3956 /***********************************************************************
3957 * CM_Get_Device_ID_Size (SETUPAPI.@)
3959 CONFIGRET WINAPI
CM_Get_Device_ID_Size( PULONG pulLen
, DEVINST dnDevInst
,
3962 struct DeviceInfo
*ppdevInfo
= GlobalLock((HANDLE
)dnDevInst
);
3964 TRACE("%x->%p, %p, %u\n", dnDevInst
, ppdevInfo
, pulLen
, ulFlags
);
3968 WARN("dev instance %d not found!\n", dnDevInst
);
3969 return CR_NO_SUCH_DEVINST
;
3972 *pulLen
= lstrlenW(ppdevInfo
->instanceId
);
3973 GlobalUnlock((HANDLE
)dnDevInst
);