2 * SetupAPI device installer
4 * Copyright 2000 Andreas Mohr for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
35 #include "wine/debug.h"
36 #include "wine/list.h"
37 #include "wine/unicode.h"
44 #include "setupapi_private.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
49 /* Unicode constants */
50 static const WCHAR ClassGUID
[] = {'C','l','a','s','s','G','U','I','D',0};
51 static const WCHAR Class
[] = {'C','l','a','s','s',0};
52 static const WCHAR ClassInstall32
[] = {'C','l','a','s','s','I','n','s','t','a','l','l','3','2',0};
53 static const WCHAR NoDisplayClass
[] = {'N','o','D','i','s','p','l','a','y','C','l','a','s','s',0};
54 static const WCHAR NoInstallClass
[] = {'N','o','I','n','s','t','a','l','l','C','l','a','s','s',0};
55 static const WCHAR NoUseClass
[] = {'N','o','U','s','e','C','l','a','s','s',0};
56 static const WCHAR NtExtension
[] = {'.','N','T',0};
57 static const WCHAR NtPlatformExtension
[] = {'.','N','T','x','8','6',0};
58 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
59 static const WCHAR WinExtension
[] = {'.','W','i','n',0};
61 /* Registry key and value names */
62 static const WCHAR ControlClass
[] = {'S','y','s','t','e','m','\\',
63 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
64 'C','o','n','t','r','o','l','\\',
65 'C','l','a','s','s',0};
67 static const WCHAR DeviceClasses
[] = {'S','y','s','t','e','m','\\',
68 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
69 'C','o','n','t','r','o','l','\\',
70 'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
71 static const WCHAR Enum
[] = {'S','y','s','t','e','m','\\',
72 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
74 static const WCHAR DeviceDesc
[] = {'D','e','v','i','c','e','D','e','s','c',0};
75 static const WCHAR DeviceInstance
[] = {'D','e','v','i','c','e','I','n','s','t','a','n','c','e',0};
76 static const WCHAR HardwareId
[] = {'H','a','r','d','w','a','r','e','I','D',0};
77 static const WCHAR CompatibleIDs
[] = {'C','o','m','p','a','t','i','b','l','e','I','d','s',0};
78 static const WCHAR Service
[] = {'S','e','r','v','i','c','e',0};
79 static const WCHAR Driver
[] = {'D','r','i','v','e','r',0};
80 static const WCHAR ConfigFlags
[] = {'C','o','n','f','i','g','F','l','a','g','s',0};
81 static const WCHAR Mfg
[] = {'M','f','g',0};
82 static const WCHAR FriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
83 static const WCHAR LocationInformation
[] = {'L','o','c','a','t','i','o','n','I','n','f','o','r','m','a','t','i','o','n',0};
84 static const WCHAR Capabilities
[] = {'C','a','p','a','b','i','l','i','t','i','e','s',0};
85 static const WCHAR UINumber
[] = {'U','I','N','u','m','b','e','r',0};
86 static const WCHAR UpperFilters
[] = {'U','p','p','e','r','F','i','l','t','e','r','s',0};
87 static const WCHAR LowerFilters
[] = {'L','o','w','e','r','F','i','l','t','e','r','s',0};
88 static const WCHAR Phantom
[] = {'P','h','a','n','t','o','m',0};
89 static const WCHAR SymbolicLink
[] = {'S','y','m','b','o','l','i','c','L','i','n','k',0};
91 /* is used to identify if a DeviceInfoSet pointer is
93 #define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff056
97 DWORD magic
; /* if is equal to SETUP_DEVICE_INFO_SET_MAGIC struct is okay */
101 SP_DEVINFO_DATA
*devices
;
104 /* Pointed to by SP_DEVICE_INTERFACE_DATA's Reserved member */
107 LPWSTR referenceString
;
109 PSP_DEVINFO_DATA device
;
112 /* A device may have multiple instances of the same interface, so this holds
113 * each instance belonging to a particular interface.
115 struct InterfaceInstances
119 DWORD cInstancesAllocated
;
120 SP_DEVICE_INTERFACE_DATA
*instances
;
124 /* Pointed to by SP_DEVINFO_DATA's Reserved member */
127 struct DeviceInfoSet
*set
;
132 struct list interfaces
;
135 static void SETUPDI_GuidToString(const GUID
*guid
, LPWSTR guidStr
)
137 static const WCHAR fmt
[] = {'{','%','0','8','X','-','%','0','4','X','-',
138 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
139 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
142 sprintfW(guidStr
, fmt
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
143 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
144 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
147 static void SETUPDI_FreeInterfaceInstances(struct InterfaceInstances
*instances
)
151 for (i
= 0; i
< instances
->cInstances
; i
++)
153 struct InterfaceInfo
*ifaceInfo
=
154 (struct InterfaceInfo
*)instances
->instances
[i
].Reserved
;
156 if (ifaceInfo
->device
&& ifaceInfo
->device
->Reserved
)
158 struct DeviceInfo
*devInfo
=
159 (struct DeviceInfo
*)ifaceInfo
->device
->Reserved
;
161 if (devInfo
->phantom
)
162 SetupDiDeleteDeviceInterfaceRegKey(devInfo
->set
,
163 &instances
->instances
[i
], 0);
165 HeapFree(GetProcessHeap(), 0, ifaceInfo
->referenceString
);
166 HeapFree(GetProcessHeap(), 0, ifaceInfo
->symbolicLink
);
167 HeapFree(GetProcessHeap(), 0, ifaceInfo
);
169 HeapFree(GetProcessHeap(), 0, instances
->instances
);
172 /* Finds the interface with interface class InterfaceClassGuid in the device.
173 * Returns TRUE if found, and updates *interface to point to device's
174 * interfaces member where the given interface was found.
175 * Returns FALSE if not found.
177 static BOOL
SETUPDI_FindInterface(const struct DeviceInfo
*devInfo
,
178 const GUID
*InterfaceClassGuid
, struct InterfaceInstances
**interface
)
181 struct InterfaceInstances
*iface
;
183 TRACE("%s\n", debugstr_guid(InterfaceClassGuid
));
185 LIST_FOR_EACH_ENTRY(iface
, &devInfo
->interfaces
, struct InterfaceInstances
,
188 if (IsEqualGUID(&iface
->guid
, InterfaceClassGuid
))
195 TRACE("returning %d (%p)\n", found
, found
? *interface
: NULL
);
199 /* Finds the interface instance with reference string ReferenceString in the
200 * interface instance map. Returns TRUE if found, and updates instanceIndex to
201 * the index of the interface instance's instances member
202 * where the given instance was found. Returns FALSE if not found.
204 static BOOL
SETUPDI_FindInterfaceInstance(
205 const struct InterfaceInstances
*instances
,
206 LPCWSTR ReferenceString
, DWORD
*instanceIndex
)
211 TRACE("%s\n", debugstr_w(ReferenceString
));
213 for (i
= 0; !found
&& i
< instances
->cInstances
; i
++)
215 SP_DEVICE_INTERFACE_DATA
*ifaceData
= &instances
->instances
[i
];
216 struct InterfaceInfo
*ifaceInfo
=
217 (struct InterfaceInfo
*)ifaceData
->Reserved
;
219 if (!ReferenceString
&& !ifaceInfo
->referenceString
)
224 else if (ReferenceString
&& ifaceInfo
->referenceString
&&
225 !lstrcmpiW(ifaceInfo
->referenceString
, ReferenceString
))
231 TRACE("returning %d (%d)\n", found
, found
? *instanceIndex
: 0);
235 static LPWSTR
SETUPDI_CreateSymbolicLinkPath(LPCWSTR instanceId
,
236 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
)
238 static const WCHAR fmt
[] = {'\\','\\','?','\\','%','s','#','%','s',0};
243 SETUPDI_GuidToString(InterfaceClassGuid
, guidStr
);
244 /* omit length of format specifiers, but include NULL terminator: */
245 len
= lstrlenW(fmt
) - 4 + 1;
246 len
+= lstrlenW(instanceId
) + lstrlenW(guidStr
);
249 /* space for a hash between string and reference string: */
250 len
+= lstrlenW(ReferenceString
) + 1;
252 ret
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
255 int printed
= sprintfW(ret
, fmt
, instanceId
, guidStr
);
258 /* replace '\\' with '#' after the "\\\\?\\" beginning */
259 for (ptr
= strchrW(ret
+ 4, '\\'); ptr
; ptr
= strchrW(ptr
+ 1, '\\'))
263 ret
[printed
- 1] = '\\';
264 lstrcpyW(ret
+ printed
, ReferenceString
);
270 /* Adds an interface with the given interface class and reference string to
271 * the device, if it doesn't already exist in the device. If iface is not
272 * NULL, returns a pointer to the newly added (or already existing) interface.
274 static BOOL
SETUPDI_AddInterfaceInstance(PSP_DEVINFO_DATA DeviceInfoData
,
275 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
,
276 SP_DEVICE_INTERFACE_DATA
**ifaceData
)
278 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
279 BOOL newInterface
= FALSE
, ret
;
280 struct InterfaceInstances
*iface
= NULL
;
282 TRACE("%p %s %s %p\n", devInfo
, debugstr_guid(InterfaceClassGuid
),
283 debugstr_w(ReferenceString
), iface
);
285 if (!(ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
287 iface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
288 sizeof(struct InterfaceInstances
));
291 list_add_tail(&devInfo
->interfaces
, &iface
->entry
);
297 DWORD instanceIndex
= 0;
299 if (!(ret
= SETUPDI_FindInterfaceInstance(iface
, ReferenceString
,
302 SP_DEVICE_INTERFACE_DATA
*instance
= NULL
;
304 if (!iface
->cInstancesAllocated
)
306 iface
->instances
= HeapAlloc(GetProcessHeap(), 0,
307 sizeof(SP_DEVICE_INTERFACE_DATA
));
308 if (iface
->instances
)
309 instance
= &iface
->instances
[iface
->cInstancesAllocated
++];
311 else if (iface
->cInstances
== iface
->cInstancesAllocated
)
313 iface
->instances
= HeapReAlloc(GetProcessHeap(), 0,
315 (iface
->cInstancesAllocated
+ 1) *
316 sizeof(SP_DEVICE_INTERFACE_DATA
));
317 if (iface
->instances
)
318 instance
= &iface
->instances
[iface
->cInstancesAllocated
++];
321 instance
= &iface
->instances
[iface
->cInstances
];
324 struct InterfaceInfo
*ifaceInfo
= HeapAlloc(GetProcessHeap(),
325 0, sizeof(struct InterfaceInfo
));
330 ifaceInfo
->device
= DeviceInfoData
;
331 ifaceInfo
->symbolicLink
= SETUPDI_CreateSymbolicLinkPath(
332 devInfo
->instanceId
, InterfaceClassGuid
,
336 ifaceInfo
->referenceString
=
337 HeapAlloc(GetProcessHeap(), 0,
338 (lstrlenW(ReferenceString
) + 1) *
340 if (ifaceInfo
->referenceString
)
341 lstrcpyW(ifaceInfo
->referenceString
,
347 ifaceInfo
->referenceString
= NULL
;
354 sizeof(SP_DEVICE_INTERFACE_DATA
);
355 memcpy(&instance
->InterfaceClassGuid
,
356 InterfaceClassGuid
, sizeof(GUID
));
357 instance
->Flags
= SPINT_ACTIVE
; /* FIXME */
358 instance
->Reserved
= (ULONG_PTR
)ifaceInfo
;
360 memcpy(&iface
->guid
, InterfaceClassGuid
,
362 key
= SetupDiCreateDeviceInterfaceRegKeyW(devInfo
->set
,
363 instance
, 0, KEY_WRITE
, NULL
, NULL
);
364 if (key
!= INVALID_HANDLE_VALUE
)
366 RegSetValueExW(key
, SymbolicLink
, 0, REG_SZ
,
367 (BYTE
*)ifaceInfo
->symbolicLink
,
368 lstrlenW(ifaceInfo
->symbolicLink
) *
373 *ifaceData
= instance
;
376 HeapFree(GetProcessHeap(), 0, ifaceInfo
);
383 *ifaceData
= &iface
->instances
[instanceIndex
];
388 TRACE("returning %d\n", ret
);
392 static BOOL
SETUPDI_SetInterfaceSymbolicLink(SP_DEVICE_INTERFACE_DATA
*iface
,
393 LPCWSTR symbolicLink
)
395 struct InterfaceInfo
*info
= (struct InterfaceInfo
*)iface
->Reserved
;
400 HeapFree(GetProcessHeap(), 0, info
->symbolicLink
);
401 info
->symbolicLink
= HeapAlloc(GetProcessHeap(), 0,
402 (lstrlenW(symbolicLink
) + 1) * sizeof(WCHAR
));
403 if (info
->symbolicLink
)
405 lstrcpyW(info
->symbolicLink
, symbolicLink
);
412 static HKEY
SETUPDI_CreateDevKey(struct DeviceInfo
*devInfo
)
414 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
417 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
418 NULL
, &enumKey
, NULL
);
421 RegCreateKeyExW(enumKey
, devInfo
->instanceId
, 0, NULL
, 0,
422 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
423 RegCloseKey(enumKey
);
428 static HKEY
SETUPDI_CreateDrvKey(struct DeviceInfo
*devInfo
)
430 static const WCHAR slash
[] = { '\\',0 };
431 WCHAR classKeyPath
[MAX_PATH
];
432 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
435 lstrcpyW(classKeyPath
, ControlClass
);
436 lstrcatW(classKeyPath
, slash
);
437 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
438 classKeyPath
+ lstrlenW(classKeyPath
));
439 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
440 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
443 static const WCHAR fmt
[] = { '%','0','4','u',0 };
446 sprintfW(devId
, fmt
, devInfo
->devId
);
447 RegCreateKeyExW(classKey
, devId
, 0, NULL
, 0, KEY_READ
| KEY_WRITE
,
449 RegCloseKey(classKey
);
454 static struct DeviceInfo
*SETUPDI_AllocateDeviceInfo(struct DeviceInfoSet
*set
,
455 DWORD devId
, LPCWSTR instanceId
, BOOL phantom
)
457 struct DeviceInfo
*devInfo
= NULL
;
458 HANDLE devInst
= GlobalAlloc(GMEM_FIXED
, sizeof(struct DeviceInfo
));
460 devInfo
= GlobalLock(devInst
);
465 devInfo
->devId
= (DWORD
)devInst
;
467 devInfo
->instanceId
= HeapAlloc(GetProcessHeap(), 0,
468 (lstrlenW(instanceId
) + 1) * sizeof(WCHAR
));
469 if (devInfo
->instanceId
)
471 devInfo
->key
= INVALID_HANDLE_VALUE
;
472 devInfo
->phantom
= phantom
;
473 lstrcpyW(devInfo
->instanceId
, instanceId
);
474 struprW(devInfo
->instanceId
);
475 devInfo
->key
= SETUPDI_CreateDevKey(devInfo
);
476 if (devInfo
->key
!= INVALID_HANDLE_VALUE
)
479 RegSetValueExW(devInfo
->key
, Phantom
, 0, REG_DWORD
,
480 (LPBYTE
)&phantom
, sizeof(phantom
));
482 list_init(&devInfo
->interfaces
);
483 GlobalUnlock(devInst
);
487 GlobalUnlock(devInst
);
495 static void SETUPDI_FreeDeviceInfo(struct DeviceInfo
*devInfo
)
497 struct InterfaceInstances
*iface
, *next
;
499 if (devInfo
->key
!= INVALID_HANDLE_VALUE
)
500 RegCloseKey(devInfo
->key
);
501 if (devInfo
->phantom
)
506 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0,
507 KEY_ALL_ACCESS
, NULL
, &enumKey
, NULL
);
510 RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
511 RegCloseKey(enumKey
);
514 HeapFree(GetProcessHeap(), 0, devInfo
->instanceId
);
515 LIST_FOR_EACH_ENTRY_SAFE(iface
, next
, &devInfo
->interfaces
,
516 struct InterfaceInstances
, entry
)
518 list_remove(&iface
->entry
);
519 SETUPDI_FreeInterfaceInstances(iface
);
520 HeapFree(GetProcessHeap(), 0, iface
);
522 GlobalFree((HANDLE
)devInfo
->devId
);
525 /* Adds a device with GUID guid and identifer devInst to set. Allocates a
526 * struct DeviceInfo, and points the returned device info's Reserved member
527 * to it. "Phantom" devices are deleted from the registry when closed.
528 * Returns a pointer to the newly allocated device info.
530 static BOOL
SETUPDI_AddDeviceToSet(struct DeviceInfoSet
*set
,
535 SP_DEVINFO_DATA
**dev
)
538 struct DeviceInfo
*devInfo
= SETUPDI_AllocateDeviceInfo(set
, set
->cDevices
,
539 instanceId
, phantom
);
541 TRACE("%p, %s, %d, %s, %d\n", set
, debugstr_guid(guid
), devInst
,
542 debugstr_w(instanceId
), phantom
);
547 set
->devices
= HeapReAlloc(GetProcessHeap(), 0, set
->devices
,
548 (set
->cDevices
+ 1) * sizeof(SP_DEVINFO_DATA
));
550 set
->devices
= HeapAlloc(GetProcessHeap(), 0,
551 sizeof(SP_DEVINFO_DATA
));
554 WCHAR classGuidStr
[39];
555 SP_DEVINFO_DATA
*DeviceInfoData
= &set
->devices
[set
->cDevices
++];
557 DeviceInfoData
->cbSize
= sizeof(SP_DEVINFO_DATA
);
558 memcpy(&DeviceInfoData
->ClassGuid
, guid
, sizeof(GUID
));
559 DeviceInfoData
->DevInst
= devInfo
->devId
;
560 DeviceInfoData
->Reserved
= (ULONG_PTR
)devInfo
;
561 SETUPDI_GuidToString(guid
, classGuidStr
);
562 SetupDiSetDeviceRegistryPropertyW((HDEVINFO
)set
,
563 DeviceInfoData
, SPDRP_CLASSGUID
, (const BYTE
*)classGuidStr
,
564 lstrlenW(classGuidStr
) * sizeof(WCHAR
));
566 *dev
= DeviceInfoData
;
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 ClcassGuid 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
->devices
= NULL
;
1192 return (HDEVINFO
)list
;
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
= (struct DeviceInfoSet
*)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 DWORD devNameLen
= lstrlenW(devName
), devInst
= 0;
1354 TRACE("%s\n", debugstr_w(devName
));
1355 for (ptr
= devName
; valid
&& *ptr
&& ptr
- devName
< devNameLen
; )
1360 devInst
|= *ptr
- '0';
1366 TRACE("%d\n", valid
? devInst
: 0xffffffff);
1367 return valid
? devInst
: 0xffffffff;
1370 /***********************************************************************
1371 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1373 BOOL WINAPI
SetupDiCreateDeviceInfoW(
1374 HDEVINFO DeviceInfoSet
,
1376 CONST GUID
*ClassGuid
,
1377 PCWSTR DeviceDescription
,
1379 DWORD CreationFlags
,
1380 PSP_DEVINFO_DATA DeviceInfoData
)
1382 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1383 BOOL ret
= FALSE
, allocatedInstanceId
= FALSE
;
1384 LPCWSTR instanceId
= NULL
;
1386 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet
, debugstr_w(DeviceName
),
1387 debugstr_guid(ClassGuid
), debugstr_w(DeviceDescription
),
1388 hwndParent
, CreationFlags
, DeviceInfoData
);
1392 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1395 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1397 SetLastError(ERROR_INVALID_HANDLE
);
1402 SetLastError(ERROR_INVALID_PARAMETER
);
1405 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1407 SetLastError(ERROR_INVALID_HANDLE
);
1410 if (!IsEqualGUID(&set
->ClassGuid
, &GUID_NULL
) &&
1411 !IsEqualGUID(ClassGuid
, &set
->ClassGuid
))
1413 SetLastError(ERROR_CLASS_MISMATCH
);
1416 if ((CreationFlags
& DICD_GENERATE_ID
))
1418 if (strchrW(DeviceName
, '\\'))
1419 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1422 static const WCHAR newDeviceFmt
[] = {'R','O','O','T','\\','%','s',
1423 '\\','%','0','4','d',0};
1428 DWORD i
, highestDevID
= 0;
1430 for (i
= 0; i
< set
->cDevices
; i
++)
1432 struct DeviceInfo
*devInfo
=
1433 (struct DeviceInfo
*)set
->devices
[i
].Reserved
;
1434 LPCWSTR devName
= strrchrW(devInfo
->instanceId
, '\\');
1440 devName
= devInfo
->instanceId
;
1441 id
= SETUPDI_DevNameToDevID(devName
);
1442 if (id
!= 0xffffffff && id
> highestDevID
)
1445 devId
= highestDevID
+ 1;
1449 /* 17 == lstrlenW(L"Root\\") + lstrlenW("\\") + 1 + %d max size */
1450 instanceId
= HeapAlloc(GetProcessHeap(), 0,
1451 (17 + lstrlenW(DeviceName
)) * sizeof(WCHAR
));
1454 sprintfW((LPWSTR
)instanceId
, newDeviceFmt
, DeviceName
,
1456 allocatedInstanceId
= TRUE
;
1468 instanceId
= DeviceName
;
1469 for (i
= 0; ret
&& i
< set
->cDevices
; i
++)
1471 struct DeviceInfo
*devInfo
=
1472 (struct DeviceInfo
*)set
->devices
[i
].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 memcpy(DeviceInfoData
, dev
, sizeof(SP_DEVINFO_DATA
));
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 memcpy(info
, &list
->devices
[index
], info
->cbSize
);
1588 SetLastError(ERROR_INVALID_USER_BUFFER
);
1591 SetLastError(ERROR_NO_MORE_ITEMS
);
1594 SetLastError(ERROR_INVALID_HANDLE
);
1597 SetLastError(ERROR_INVALID_HANDLE
);
1601 /***********************************************************************
1602 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1604 BOOL WINAPI
SetupDiGetDeviceInstanceIdA(
1605 HDEVINFO DeviceInfoSet
,
1606 PSP_DEVINFO_DATA DeviceInfoData
,
1607 PSTR DeviceInstanceId
,
1608 DWORD DeviceInstanceIdSize
,
1609 PDWORD RequiredSize
)
1615 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1616 DeviceInstanceIdSize
, RequiredSize
);
1618 SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1623 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1625 instanceId
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
1628 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1635 int len
= WideCharToMultiByte(CP_ACP
, 0, instanceId
, -1,
1637 DeviceInstanceIdSize
, NULL
, NULL
);
1643 if (len
> DeviceInstanceIdSize
)
1645 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1649 *RequiredSize
= len
;
1652 HeapFree(GetProcessHeap(), 0, instanceId
);
1657 /***********************************************************************
1658 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1660 BOOL WINAPI
SetupDiGetDeviceInstanceIdW(
1661 HDEVINFO DeviceInfoSet
,
1662 PSP_DEVINFO_DATA DeviceInfoData
,
1663 PWSTR DeviceInstanceId
,
1664 DWORD DeviceInstanceIdSize
,
1665 PDWORD RequiredSize
)
1667 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1668 struct DeviceInfo
*devInfo
;
1670 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1671 DeviceInstanceIdSize
, RequiredSize
);
1673 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1675 SetLastError(ERROR_INVALID_HANDLE
);
1678 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1680 SetLastError(ERROR_INVALID_HANDLE
);
1683 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1684 || !DeviceInfoData
->Reserved
)
1686 SetLastError(ERROR_INVALID_PARAMETER
);
1689 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1690 if (devInfo
->set
!= set
)
1692 SetLastError(ERROR_INVALID_PARAMETER
);
1695 TRACE("instance ID: %s\n", debugstr_w(devInfo
->instanceId
));
1696 if (DeviceInstanceIdSize
< lstrlenW(devInfo
->instanceId
) + 1)
1698 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1700 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1703 lstrcpyW(DeviceInstanceId
, devInfo
->instanceId
);
1705 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1709 /***********************************************************************
1710 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1712 BOOL WINAPI
SetupDiGetActualSectionToInstallA(
1714 PCSTR InfSectionName
,
1715 PSTR InfSectionWithExt
,
1716 DWORD InfSectionWithExtSize
,
1717 PDWORD RequiredSize
,
1724 /***********************************************************************
1725 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
1727 BOOL WINAPI
SetupDiGetActualSectionToInstallW(
1729 PCWSTR InfSectionName
,
1730 PWSTR InfSectionWithExt
,
1731 DWORD InfSectionWithExtSize
,
1732 PDWORD RequiredSize
,
1735 WCHAR szBuffer
[MAX_PATH
];
1738 LONG lLineCount
= -1;
1740 lstrcpyW(szBuffer
, InfSectionName
);
1741 dwLength
= lstrlenW(szBuffer
);
1743 if (OsVersionInfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
1745 /* Test section name with '.NTx86' extension */
1746 lstrcpyW(&szBuffer
[dwLength
], NtPlatformExtension
);
1747 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1749 if (lLineCount
== -1)
1751 /* Test section name with '.NT' extension */
1752 lstrcpyW(&szBuffer
[dwLength
], NtExtension
);
1753 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1758 /* Test section name with '.Win' extension */
1759 lstrcpyW(&szBuffer
[dwLength
], WinExtension
);
1760 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1763 if (lLineCount
== -1)
1765 /* Test section name without extension */
1766 szBuffer
[dwLength
] = 0;
1767 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1770 if (lLineCount
== -1)
1772 SetLastError(ERROR_INVALID_PARAMETER
);
1776 dwFullLength
= lstrlenW(szBuffer
);
1778 if (InfSectionWithExt
!= NULL
&& InfSectionWithExtSize
!= 0)
1780 if (InfSectionWithExtSize
< (dwFullLength
+ 1))
1782 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1786 lstrcpyW(InfSectionWithExt
, szBuffer
);
1787 if (Extension
!= NULL
)
1789 *Extension
= (dwLength
== dwFullLength
) ? NULL
: &InfSectionWithExt
[dwLength
];
1793 if (RequiredSize
!= NULL
)
1795 *RequiredSize
= dwFullLength
+ 1;
1801 /***********************************************************************
1802 * SetupDiGetClassDescriptionA (SETUPAPI.@)
1804 BOOL WINAPI
SetupDiGetClassDescriptionA(
1805 const GUID
* ClassGuid
,
1806 PSTR ClassDescription
,
1807 DWORD ClassDescriptionSize
,
1808 PDWORD RequiredSize
)
1810 return SetupDiGetClassDescriptionExA(ClassGuid
, ClassDescription
,
1811 ClassDescriptionSize
,
1812 RequiredSize
, NULL
, NULL
);
1815 /***********************************************************************
1816 * SetupDiGetClassDescriptionW (SETUPAPI.@)
1818 BOOL WINAPI
SetupDiGetClassDescriptionW(
1819 const GUID
* ClassGuid
,
1820 PWSTR ClassDescription
,
1821 DWORD ClassDescriptionSize
,
1822 PDWORD RequiredSize
)
1824 return SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescription
,
1825 ClassDescriptionSize
,
1826 RequiredSize
, NULL
, NULL
);
1829 /***********************************************************************
1830 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
1832 BOOL WINAPI
SetupDiGetClassDescriptionExA(
1833 const GUID
* ClassGuid
,
1834 PSTR ClassDescription
,
1835 DWORD ClassDescriptionSize
,
1836 PDWORD RequiredSize
,
1844 hKey
= SetupDiOpenClassRegKeyExA(ClassGuid
,
1849 if (hKey
== INVALID_HANDLE_VALUE
)
1851 WARN("SetupDiOpenClassRegKeyExA() failed (Error %u)\n", GetLastError());
1855 dwLength
= ClassDescriptionSize
;
1856 ret
= !RegQueryValueExA( hKey
, NULL
, NULL
, NULL
,
1857 (LPBYTE
)ClassDescription
, &dwLength
);
1858 if (RequiredSize
) *RequiredSize
= dwLength
;
1863 /***********************************************************************
1864 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
1866 BOOL WINAPI
SetupDiGetClassDescriptionExW(
1867 const GUID
* ClassGuid
,
1868 PWSTR ClassDescription
,
1869 DWORD ClassDescriptionSize
,
1870 PDWORD RequiredSize
,
1878 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1883 if (hKey
== INVALID_HANDLE_VALUE
)
1885 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
1889 dwLength
= ClassDescriptionSize
* sizeof(WCHAR
);
1890 ret
= !RegQueryValueExW( hKey
, NULL
, NULL
, NULL
,
1891 (LPBYTE
)ClassDescription
, &dwLength
);
1892 if (RequiredSize
) *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1897 /***********************************************************************
1898 * SetupDiGetClassDevsA (SETUPAPI.@)
1900 HDEVINFO WINAPI
SetupDiGetClassDevsA(
1907 LPWSTR enumstrW
= NULL
;
1911 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1912 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1915 ret
= INVALID_HANDLE_VALUE
;
1918 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1920 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, NULL
, NULL
,
1922 HeapFree(GetProcessHeap(), 0, enumstrW
);
1928 /***********************************************************************
1929 * SetupDiGetClassDevsExA (SETUPAPI.@)
1931 HDEVINFO WINAPI
SetupDiGetClassDevsExA(
1941 LPWSTR enumstrW
= NULL
, machineW
= NULL
;
1945 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1946 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1949 ret
= INVALID_HANDLE_VALUE
;
1952 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1956 int len
= MultiByteToWideChar(CP_ACP
, 0, machine
, -1, NULL
, 0);
1957 machineW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1960 HeapFree(GetProcessHeap(), 0, enumstrW
);
1961 ret
= INVALID_HANDLE_VALUE
;
1964 MultiByteToWideChar(CP_ACP
, 0, machine
, -1, machineW
, len
);
1966 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, deviceset
,
1967 machineW
, reserved
);
1968 HeapFree(GetProcessHeap(), 0, enumstrW
);
1969 HeapFree(GetProcessHeap(), 0, machineW
);
1975 static void SETUPDI_AddDeviceInterfaces(SP_DEVINFO_DATA
*dev
, HKEY key
,
1976 const GUID
*interface
)
1979 WCHAR subKeyName
[MAX_PATH
];
1980 LONG l
= ERROR_SUCCESS
;
1982 for (i
= 0; !l
; i
++)
1984 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
1985 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
1989 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
1991 /* The subkey name is the reference string, with a '#' prepended */
1992 SETUPDI_AddInterfaceInstance(dev
, interface
, subKeyName
+ 1,
1994 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
1997 WCHAR symbolicLink
[MAX_PATH
];
2000 len
= sizeof(symbolicLink
);
2001 l
= RegQueryValueExW(subKey
, SymbolicLink
, NULL
, &dataType
,
2002 (BYTE
*)symbolicLink
, &len
);
2003 if (!l
&& dataType
== REG_SZ
)
2004 SETUPDI_SetInterfaceSymbolicLink(iface
, symbolicLink
);
2005 RegCloseKey(subKey
);
2007 /* Allow enumeration to continue */
2011 /* FIXME: find and add all the device's interfaces to the device */
2014 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet
,
2015 HKEY key
, const GUID
*interface
, LPCWSTR enumstr
)
2017 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2019 WCHAR subKeyName
[MAX_PATH
];
2021 HKEY enumKey
= INVALID_HANDLE_VALUE
;
2023 TRACE("%s\n", debugstr_w(enumstr
));
2025 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2027 for (i
= 0; !l
; i
++)
2029 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2030 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2035 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2038 WCHAR deviceInst
[MAX_PATH
* 3];
2041 len
= sizeof(deviceInst
);
2042 l
= RegQueryValueExW(subKey
, DeviceInstance
, NULL
, &dataType
,
2043 (BYTE
*)deviceInst
, &len
);
2044 if (!l
&& dataType
== REG_SZ
)
2046 TRACE("found instance ID %s\n", debugstr_w(deviceInst
));
2047 if (!enumstr
|| !lstrcmpiW(enumstr
, deviceInst
))
2051 l
= RegOpenKeyExW(enumKey
, deviceInst
, 0, KEY_READ
,
2055 WCHAR deviceClassStr
[40];
2057 len
= sizeof(deviceClassStr
);
2058 l
= RegQueryValueExW(deviceKey
, ClassGUID
, NULL
,
2059 &dataType
, (BYTE
*)deviceClassStr
, &len
);
2060 if (!l
&& dataType
== REG_SZ
&&
2061 deviceClassStr
[0] == '{' &&
2062 deviceClassStr
[37] == '}')
2065 SP_DEVINFO_DATA
*dev
;
2067 deviceClassStr
[37] = 0;
2068 UuidFromStringW(&deviceClassStr
[1],
2070 if (SETUPDI_AddDeviceToSet(set
, &deviceClass
,
2071 0 /* FIXME: DevInst */, deviceInst
,
2073 SETUPDI_AddDeviceInterfaces(dev
, subKey
,
2076 RegCloseKey(deviceKey
);
2080 RegCloseKey(subKey
);
2082 /* Allow enumeration to continue */
2086 if (enumKey
!= INVALID_HANDLE_VALUE
)
2087 RegCloseKey(enumKey
);
2090 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet
,
2091 const GUID
*interface
, LPCWSTR enumstr
, DWORD flags
)
2093 HKEY interfacesKey
= SetupDiOpenClassRegKeyExW(interface
, KEY_READ
,
2094 DIOCR_INTERFACE
, NULL
, NULL
);
2096 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(interface
),
2097 debugstr_w(enumstr
), flags
);
2099 if (interfacesKey
!= INVALID_HANDLE_VALUE
)
2101 if (flags
& DIGCF_ALLCLASSES
)
2104 WCHAR interfaceGuidStr
[40];
2105 LONG l
= ERROR_SUCCESS
;
2107 for (i
= 0; !l
; i
++)
2109 len
= sizeof(interfaceGuidStr
) / sizeof(interfaceGuidStr
[0]);
2110 l
= RegEnumKeyExW(interfacesKey
, i
, interfaceGuidStr
, &len
,
2111 NULL
, NULL
, NULL
, NULL
);
2114 if (interfaceGuidStr
[0] == '{' &&
2115 interfaceGuidStr
[37] == '}')
2120 interfaceGuidStr
[37] = 0;
2121 UuidFromStringW(&interfaceGuidStr
[1], &interfaceGuid
);
2122 l
= RegOpenKeyExW(interfacesKey
, interfaceGuidStr
, 0,
2123 KEY_READ
, &interfaceKey
);
2126 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2127 interfaceKey
, &interfaceGuid
, enumstr
);
2128 RegCloseKey(interfaceKey
);
2136 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2137 * interface's key, so just pass that long
2139 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2140 interfacesKey
, interface
, enumstr
);
2142 RegCloseKey(interfacesKey
);
2146 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet
*set
,
2147 LPCWSTR enumerator
, LPCWSTR deviceName
, HKEY deviceKey
,
2148 const GUID
*class, DWORD flags
)
2151 WCHAR deviceInstance
[MAX_PATH
];
2152 LONG l
= ERROR_SUCCESS
;
2154 TRACE("%s %s\n", debugstr_w(enumerator
), debugstr_w(deviceName
));
2156 for (i
= 0; !l
; i
++)
2158 len
= sizeof(deviceInstance
) / sizeof(deviceInstance
[0]);
2159 l
= RegEnumKeyExW(deviceKey
, i
, deviceInstance
, &len
, NULL
, NULL
, NULL
,
2165 l
= RegOpenKeyExW(deviceKey
, deviceInstance
, 0, KEY_READ
, &subKey
);
2168 WCHAR classGuid
[40];
2171 len
= sizeof(classGuid
);
2172 l
= RegQueryValueExW(subKey
, ClassGUID
, NULL
, &dataType
,
2173 (BYTE
*)classGuid
, &len
);
2174 if (!l
&& dataType
== REG_SZ
)
2176 if (classGuid
[0] == '{' && classGuid
[37] == '}')
2181 UuidFromStringW(&classGuid
[1], &deviceClass
);
2182 if ((flags
& DIGCF_ALLCLASSES
) ||
2183 IsEqualGUID(class, &deviceClass
))
2185 static const WCHAR fmt
[] =
2186 {'%','s','\\','%','s','\\','%','s',0};
2189 instanceId
= HeapAlloc(GetProcessHeap(), 0,
2190 (lstrlenW(enumerator
) + lstrlenW(deviceName
) +
2191 lstrlenW(deviceInstance
) + 3) * sizeof(WCHAR
));
2194 sprintfW(instanceId
, fmt
, enumerator
,
2195 deviceName
, deviceInstance
);
2196 SETUPDI_AddDeviceToSet(set
, &deviceClass
,
2197 0 /* FIXME: DevInst */, instanceId
,
2199 HeapFree(GetProcessHeap(), 0, instanceId
);
2204 RegCloseKey(subKey
);
2206 /* Allow enumeration to continue */
2212 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet
,
2213 LPCWSTR parent
, HKEY key
, const GUID
*class, DWORD flags
)
2215 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2217 WCHAR subKeyName
[MAX_PATH
];
2218 LONG l
= ERROR_SUCCESS
;
2220 TRACE("%s\n", debugstr_w(parent
));
2222 for (i
= 0; !l
; i
++)
2224 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2225 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2230 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2233 TRACE("%s\n", debugstr_w(subKeyName
));
2234 SETUPDI_EnumerateMatchingDeviceInstances(set
, parent
,
2235 subKeyName
, subKey
, class, flags
);
2236 RegCloseKey(subKey
);
2238 /* Allow enumeration to continue */
2244 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet
, const GUID
*class,
2245 LPCWSTR enumstr
, DWORD flags
)
2250 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(class),
2251 debugstr_w(enumstr
), flags
);
2253 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2255 if (enumKey
!= INVALID_HANDLE_VALUE
)
2261 l
= RegOpenKeyExW(enumKey
, enumstr
, 0, KEY_READ
,
2265 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
, enumstr
,
2266 enumStrKey
, class, flags
);
2267 RegCloseKey(enumStrKey
);
2273 WCHAR subKeyName
[MAX_PATH
];
2276 for (i
= 0; !l
; i
++)
2278 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2279 l
= RegEnumKeyExW(enumKey
, i
, subKeyName
, &len
, NULL
,
2285 l
= RegOpenKeyExW(enumKey
, subKeyName
, 0, KEY_READ
,
2289 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
,
2290 subKeyName
, subKey
, class, flags
);
2291 RegCloseKey(subKey
);
2293 /* Allow enumeration to continue */
2298 RegCloseKey(enumKey
);
2302 /***********************************************************************
2303 * SetupDiGetClassDevsW (SETUPAPI.@)
2305 HDEVINFO WINAPI
SetupDiGetClassDevsW(
2311 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2315 /***********************************************************************
2316 * SetupDiGetClassDevsExW (SETUPAPI.@)
2318 HDEVINFO WINAPI
SetupDiGetClassDevsExW(
2327 static const DWORD unsupportedFlags
= DIGCF_DEFAULT
| DIGCF_PRESENT
|
2331 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2332 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2335 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2337 SetLastError(ERROR_INVALID_PARAMETER
);
2340 if (flags
& unsupportedFlags
)
2341 WARN("unsupported flags %08x\n", flags
& unsupportedFlags
);
2345 set
= SetupDiCreateDeviceInfoListExW(class, parent
, machine
, reserved
);
2349 FIXME("%s: unimplemented for remote machines\n",
2350 debugstr_w(machine
));
2351 else if (flags
& DIGCF_DEVICEINTERFACE
)
2352 SETUPDI_EnumerateInterfaces(set
, class, enumstr
, flags
);
2354 SETUPDI_EnumerateDevices(set
, class, enumstr
, flags
);
2359 /***********************************************************************
2360 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2362 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2363 HDEVINFO DeviceInfoSet
,
2364 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2366 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2368 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2370 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2372 SetLastError(ERROR_INVALID_HANDLE
);
2375 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2377 SetLastError(ERROR_INVALID_HANDLE
);
2381 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2383 SetLastError(ERROR_INVALID_PARAMETER
);
2386 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2387 DevInfoData
->RemoteMachineHandle
= NULL
;
2388 DevInfoData
->RemoteMachineName
[0] = '\0';
2392 /***********************************************************************
2393 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2395 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2396 HDEVINFO DeviceInfoSet
,
2397 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2399 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2401 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2403 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2405 SetLastError(ERROR_INVALID_HANDLE
);
2408 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2410 SetLastError(ERROR_INVALID_HANDLE
);
2414 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2416 SetLastError(ERROR_INVALID_PARAMETER
);
2419 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2420 DevInfoData
->RemoteMachineHandle
= NULL
;
2421 DevInfoData
->RemoteMachineName
[0] = '\0';
2425 /***********************************************************************
2426 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2428 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2429 HDEVINFO DeviceInfoSet
,
2430 PSP_DEVINFO_DATA DeviceInfoData
,
2431 const GUID
*InterfaceClassGuid
,
2432 PCSTR ReferenceString
,
2433 DWORD CreationFlags
,
2434 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2437 LPWSTR ReferenceStringW
= NULL
;
2439 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2440 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2441 CreationFlags
, DeviceInterfaceData
);
2443 if (ReferenceString
)
2445 ReferenceStringW
= MultiByteToUnicode(ReferenceString
, CP_ACP
);
2446 if (ReferenceStringW
== NULL
) return FALSE
;
2449 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2450 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2451 DeviceInterfaceData
);
2453 MyFree(ReferenceStringW
);
2458 /***********************************************************************
2459 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2461 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2462 HDEVINFO DeviceInfoSet
,
2463 PSP_DEVINFO_DATA DeviceInfoData
,
2464 const GUID
*InterfaceClassGuid
,
2465 PCWSTR ReferenceString
,
2466 DWORD CreationFlags
,
2467 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2469 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2470 struct DeviceInfo
*devInfo
;
2471 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
2474 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2475 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2476 CreationFlags
, DeviceInterfaceData
);
2478 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2480 SetLastError(ERROR_INVALID_HANDLE
);
2483 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2485 SetLastError(ERROR_INVALID_HANDLE
);
2488 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2489 || !DeviceInfoData
->Reserved
)
2491 SetLastError(ERROR_INVALID_PARAMETER
);
2494 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2495 if (devInfo
->set
!= set
)
2497 SetLastError(ERROR_INVALID_PARAMETER
);
2500 if (!InterfaceClassGuid
)
2502 SetLastError(ERROR_INVALID_USER_BUFFER
);
2505 if ((ret
= SETUPDI_AddInterfaceInstance(DeviceInfoData
, InterfaceClassGuid
,
2506 ReferenceString
, &iface
)))
2508 if (DeviceInterfaceData
)
2510 if (DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2512 SetLastError(ERROR_INVALID_USER_BUFFER
);
2516 memcpy(DeviceInterfaceData
, iface
, sizeof(*iface
));
2522 /***********************************************************************
2523 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2525 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2526 HDEVINFO DeviceInfoSet
,
2527 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2531 PCSTR InfSectionName
)
2534 PWSTR InfSectionNameW
= NULL
;
2536 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2537 samDesired
, InfHandle
, InfSectionName
);
2540 if (!InfSectionName
)
2542 SetLastError(ERROR_INVALID_PARAMETER
);
2543 return INVALID_HANDLE_VALUE
;
2545 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2546 if (!InfSectionNameW
)
2547 return INVALID_HANDLE_VALUE
;
2549 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2550 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2552 MyFree(InfSectionNameW
);
2556 static PWSTR
SETUPDI_GetInstancePath(struct InterfaceInfo
*ifaceInfo
)
2558 static const WCHAR hash
[] = {'#',0};
2559 PWSTR instancePath
= NULL
;
2561 if (ifaceInfo
->referenceString
)
2563 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2564 (lstrlenW(ifaceInfo
->referenceString
) + 2) * sizeof(WCHAR
));
2567 lstrcpyW(instancePath
, hash
);
2568 lstrcatW(instancePath
, ifaceInfo
->referenceString
);
2571 SetLastError(ERROR_OUTOFMEMORY
);
2575 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2576 (lstrlenW(hash
) + 1) * sizeof(WCHAR
));
2578 lstrcpyW(instancePath
, hash
);
2580 return instancePath
;
2583 /***********************************************************************
2584 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2586 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2587 HDEVINFO DeviceInfoSet
,
2588 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2592 PCWSTR InfSectionName
)
2594 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2595 HKEY key
= INVALID_HANDLE_VALUE
, interfacesKey
;
2598 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2599 samDesired
, InfHandle
, InfSectionName
);
2601 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2602 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2604 SetLastError(ERROR_INVALID_HANDLE
);
2605 return INVALID_HANDLE_VALUE
;
2607 if (!DeviceInterfaceData
||
2608 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2609 !DeviceInterfaceData
->Reserved
)
2611 SetLastError(ERROR_INVALID_PARAMETER
);
2612 return INVALID_HANDLE_VALUE
;
2614 if (InfHandle
&& !InfSectionName
)
2616 SetLastError(ERROR_INVALID_PARAMETER
);
2617 return INVALID_HANDLE_VALUE
;
2619 if (!(l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, DeviceClasses
, 0, NULL
, 0,
2620 samDesired
, NULL
, &interfacesKey
, NULL
)))
2623 WCHAR bracedGuidString
[39];
2625 SETUPDI_GuidToString(&DeviceInterfaceData
->InterfaceClassGuid
,
2627 if (!(l
= RegCreateKeyExW(interfacesKey
, bracedGuidString
, 0, NULL
, 0,
2628 samDesired
, NULL
, &parent
, NULL
)))
2630 struct InterfaceInfo
*ifaceInfo
=
2631 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2632 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2638 l
= RegCreateKeyExW(parent
, instancePath
, 0, NULL
, 0,
2639 samDesired
, NULL
, &key
, NULL
);
2643 key
= INVALID_HANDLE_VALUE
;
2646 FIXME("INF section installation unsupported\n");
2648 HeapFree(GetProcessHeap(), 0, instancePath
);
2649 RegCloseKey(parent
);
2653 RegCloseKey(interfacesKey
);
2660 /***********************************************************************
2661 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2663 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2664 HDEVINFO DeviceInfoSet
,
2665 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2668 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2672 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2674 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2675 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2677 SetLastError(ERROR_INVALID_HANDLE
);
2680 if (!DeviceInterfaceData
||
2681 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2682 !DeviceInterfaceData
->Reserved
)
2684 SetLastError(ERROR_INVALID_PARAMETER
);
2687 parent
= SetupDiOpenClassRegKeyExW(&DeviceInterfaceData
->InterfaceClassGuid
,
2688 KEY_ALL_ACCESS
, DIOCR_INTERFACE
, NULL
, NULL
);
2689 if (parent
!= INVALID_HANDLE_VALUE
)
2691 struct InterfaceInfo
*ifaceInfo
=
2692 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2693 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2697 LONG l
= RegDeleteKeyW(parent
, instancePath
);
2703 HeapFree(GetProcessHeap(), 0, instancePath
);
2705 RegCloseKey(parent
);
2710 /***********************************************************************
2711 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2714 * DeviceInfoSet [I] Set of devices from which to enumerate
2716 * DeviceInfoData [I] (Optional) If specified, a specific device
2717 * instance from which to enumerate interfaces.
2718 * If it isn't specified, all interfaces for all
2719 * devices in the set are enumerated.
2720 * InterfaceClassGuid [I] The interface class to enumerate.
2721 * MemberIndex [I] An index of the interface instance to enumerate.
2722 * A caller should start with MemberIndex set to 0,
2723 * and continue until the function fails with
2724 * ERROR_NO_MORE_ITEMS.
2725 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2726 * member must be set to
2727 * sizeof(SP_DEVICE_INTERFACE_DATA).
2730 * Success: non-zero value.
2731 * Failure: FALSE. Call GetLastError() for more info.
2733 BOOL WINAPI
SetupDiEnumDeviceInterfaces(
2734 HDEVINFO DeviceInfoSet
,
2735 PSP_DEVINFO_DATA DeviceInfoData
,
2736 CONST GUID
* InterfaceClassGuid
,
2738 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2740 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2743 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet
, DeviceInfoData
,
2744 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
2746 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2747 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2749 SetLastError(ERROR_INVALID_HANDLE
);
2752 if (DeviceInfoData
&& (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2753 !DeviceInfoData
->Reserved
))
2755 SetLastError(ERROR_INVALID_PARAMETER
);
2758 if (!DeviceInterfaceData
||
2759 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2761 SetLastError(ERROR_INVALID_PARAMETER
);
2766 struct DeviceInfo
*devInfo
=
2767 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2768 struct InterfaceInstances
*iface
;
2770 if ((ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
2772 if (MemberIndex
< iface
->cInstances
)
2773 memcpy(DeviceInterfaceData
, &iface
->instances
[MemberIndex
],
2774 sizeof(SP_DEVICE_INTERFACE_DATA
));
2777 SetLastError(ERROR_NO_MORE_ITEMS
);
2782 SetLastError(ERROR_NO_MORE_ITEMS
);
2786 DWORD i
, cEnumerated
= 0;
2789 for (i
= 0; !found
&& cEnumerated
< MemberIndex
+ 1 &&
2790 i
< set
->cDevices
; i
++)
2792 struct DeviceInfo
*devInfo
=
2793 (struct DeviceInfo
*)set
->devices
[i
].Reserved
;
2794 struct InterfaceInstances
*iface
;
2796 if (SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
))
2798 if (cEnumerated
+ iface
->cInstances
< MemberIndex
+ 1)
2799 cEnumerated
+= iface
->cInstances
;
2802 DWORD instanceIndex
= MemberIndex
- cEnumerated
;
2804 memcpy(DeviceInterfaceData
,
2805 &iface
->instances
[instanceIndex
],
2806 sizeof(SP_DEVICE_INTERFACE_DATA
));
2807 cEnumerated
+= instanceIndex
+ 1;
2814 SetLastError(ERROR_NO_MORE_ITEMS
);
2819 /***********************************************************************
2820 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2822 * Destroy a DeviceInfoList and free all used memory of the list.
2825 * devinfo [I] DeviceInfoList pointer to list to destroy
2828 * Success: non zero value.
2829 * Failure: zero value.
2831 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
2835 TRACE("%p\n", devinfo
);
2836 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
2838 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
2840 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
2844 for (i
= 0; i
< list
->cDevices
; i
++)
2845 SETUPDI_FreeDeviceInfo(
2846 (struct DeviceInfo
*)list
->devices
[i
].Reserved
);
2847 HeapFree(GetProcessHeap(), 0, list
->devices
);
2848 HeapFree(GetProcessHeap(), 0, list
);
2854 SetLastError(ERROR_INVALID_HANDLE
);
2859 /***********************************************************************
2860 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2862 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
2863 HDEVINFO DeviceInfoSet
,
2864 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2865 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
2866 DWORD DeviceInterfaceDetailDataSize
,
2867 PDWORD RequiredSize
,
2868 PSP_DEVINFO_DATA DeviceInfoData
)
2870 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2871 struct InterfaceInfo
*info
;
2872 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
)
2876 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2877 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2878 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2880 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2881 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2883 SetLastError(ERROR_INVALID_HANDLE
);
2886 if (!DeviceInterfaceData
||
2887 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2888 !DeviceInterfaceData
->Reserved
)
2890 SetLastError(ERROR_INVALID_PARAMETER
);
2893 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
!=
2894 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + sizeof(char)))
2896 SetLastError(ERROR_INVALID_USER_BUFFER
);
2899 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2901 SetLastError(ERROR_INVALID_USER_BUFFER
);
2904 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2905 if (info
->symbolicLink
)
2906 bytesNeeded
+= WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2907 NULL
, 0, NULL
, NULL
);
2908 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2910 if (info
->symbolicLink
)
2911 WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2912 DeviceInterfaceDetailData
->DevicePath
,
2913 DeviceInterfaceDetailDataSize
-
2914 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
2917 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2918 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2919 memcpy(DeviceInfoData
, info
->device
, sizeof(SP_DEVINFO_DATA
));
2925 *RequiredSize
= bytesNeeded
;
2926 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2931 /***********************************************************************
2932 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2934 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
2935 HDEVINFO DeviceInfoSet
,
2936 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2937 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
2938 DWORD DeviceInterfaceDetailDataSize
,
2939 PDWORD RequiredSize
,
2940 PSP_DEVINFO_DATA DeviceInfoData
)
2942 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2943 struct InterfaceInfo
*info
;
2944 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
2945 + sizeof(WCHAR
); /* include NULL terminator */
2948 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2949 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2950 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2952 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2953 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2955 SetLastError(ERROR_INVALID_HANDLE
);
2958 if (!DeviceInterfaceData
||
2959 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2960 !DeviceInterfaceData
->Reserved
)
2962 SetLastError(ERROR_INVALID_PARAMETER
);
2965 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
2966 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
) ||
2967 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
)))
2969 SetLastError(ERROR_INVALID_USER_BUFFER
);
2972 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2974 SetLastError(ERROR_INVALID_USER_BUFFER
);
2977 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2978 if (info
->symbolicLink
)
2979 bytesNeeded
+= lstrlenW(info
->symbolicLink
);
2980 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2982 if (info
->symbolicLink
)
2983 lstrcpyW(DeviceInterfaceDetailData
->DevicePath
, info
->symbolicLink
);
2985 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2986 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2987 memcpy(DeviceInfoData
, info
->device
, sizeof(SP_DEVINFO_DATA
));
2993 *RequiredSize
= bytesNeeded
;
2994 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2999 struct PropertyMapEntry
3006 static struct PropertyMapEntry PropertyMap
[] = {
3007 { REG_SZ
, "DeviceDesc", DeviceDesc
},
3008 { REG_MULTI_SZ
, "HardwareId", HardwareId
},
3009 { REG_MULTI_SZ
, "CompatibleIDs", CompatibleIDs
},
3010 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
3011 { REG_SZ
, "Service", Service
},
3012 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
3013 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
3014 { REG_SZ
, "Class", Class
},
3015 { REG_SZ
, "ClassGUID", ClassGUID
},
3016 { REG_SZ
, "Driver", Driver
},
3017 { REG_DWORD
, "ConfigFlags", ConfigFlags
},
3018 { REG_SZ
, "Mfg", Mfg
},
3019 { REG_SZ
, "FriendlyName", FriendlyName
},
3020 { REG_SZ
, "LocationInformation", LocationInformation
},
3021 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3022 { REG_DWORD
, "Capabilities", Capabilities
},
3023 { REG_DWORD
, "UINumber", UINumber
},
3024 { REG_MULTI_SZ
, "UpperFilters", UpperFilters
},
3025 { REG_MULTI_SZ
, "LowerFilters", LowerFilters
},
3028 /***********************************************************************
3029 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3031 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
3032 HDEVINFO DeviceInfoSet
,
3033 PSP_DEVINFO_DATA DeviceInfoData
,
3035 PDWORD PropertyRegDataType
,
3036 PBYTE PropertyBuffer
,
3037 DWORD PropertyBufferSize
,
3038 PDWORD RequiredSize
)
3041 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3042 struct DeviceInfo
*devInfo
;
3044 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3045 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3048 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3050 SetLastError(ERROR_INVALID_HANDLE
);
3053 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3055 SetLastError(ERROR_INVALID_HANDLE
);
3058 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3059 || !DeviceInfoData
->Reserved
)
3061 SetLastError(ERROR_INVALID_PARAMETER
);
3064 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3065 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3066 && PropertyMap
[Property
].nameA
)
3068 DWORD size
= PropertyBufferSize
;
3069 LONG l
= RegQueryValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
,
3070 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3073 *RequiredSize
= size
;
3074 if (!PropertyBuffer
)
3075 ; /* do nothing, ret is already FALSE, last error is already set */
3084 /***********************************************************************
3085 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3087 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3088 HDEVINFO DeviceInfoSet
,
3089 PSP_DEVINFO_DATA DeviceInfoData
,
3091 PDWORD PropertyRegDataType
,
3092 PBYTE PropertyBuffer
,
3093 DWORD PropertyBufferSize
,
3094 PDWORD RequiredSize
)
3097 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3098 struct DeviceInfo
*devInfo
;
3100 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3101 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3104 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3106 SetLastError(ERROR_INVALID_HANDLE
);
3109 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3111 SetLastError(ERROR_INVALID_HANDLE
);
3114 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3115 || !DeviceInfoData
->Reserved
)
3117 SetLastError(ERROR_INVALID_PARAMETER
);
3120 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3121 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3122 && PropertyMap
[Property
].nameW
)
3124 DWORD size
= PropertyBufferSize
;
3125 LONG l
= RegQueryValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
,
3126 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3129 *RequiredSize
= size
;
3130 if (!PropertyBuffer
)
3131 ; /* do nothing, ret is already FALSE, last error is already set */
3140 /***********************************************************************
3141 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3143 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3144 HDEVINFO DeviceInfoSet
,
3145 PSP_DEVINFO_DATA DeviceInfoData
,
3147 const BYTE
*PropertyBuffer
,
3148 DWORD PropertyBufferSize
)
3151 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3152 struct DeviceInfo
*devInfo
;
3154 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3155 PropertyBuffer
, PropertyBufferSize
);
3157 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3159 SetLastError(ERROR_INVALID_HANDLE
);
3162 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3164 SetLastError(ERROR_INVALID_HANDLE
);
3167 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3168 || !DeviceInfoData
->Reserved
)
3170 SetLastError(ERROR_INVALID_PARAMETER
);
3173 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3174 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3175 && PropertyMap
[Property
].nameA
)
3177 LONG l
= RegSetValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
, 0,
3178 PropertyMap
[Property
].regType
, PropertyBuffer
,
3179 PropertyBufferSize
);
3188 /***********************************************************************
3189 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3191 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
3192 HDEVINFO DeviceInfoSet
,
3193 PSP_DEVINFO_DATA DeviceInfoData
,
3195 const BYTE
*PropertyBuffer
,
3196 DWORD PropertyBufferSize
)
3199 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3200 struct DeviceInfo
*devInfo
;
3202 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3203 PropertyBuffer
, PropertyBufferSize
);
3205 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3207 SetLastError(ERROR_INVALID_HANDLE
);
3210 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3212 SetLastError(ERROR_INVALID_HANDLE
);
3215 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3216 || !DeviceInfoData
->Reserved
)
3218 SetLastError(ERROR_INVALID_PARAMETER
);
3221 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3222 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3223 && PropertyMap
[Property
].nameW
)
3225 LONG l
= RegSetValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
, 0,
3226 PropertyMap
[Property
].regType
, PropertyBuffer
,
3227 PropertyBufferSize
);
3236 /***********************************************************************
3237 * SetupDiInstallClassA (SETUPAPI.@)
3239 BOOL WINAPI
SetupDiInstallClassA(
3245 UNICODE_STRING FileNameW
;
3250 SetLastError(ERROR_INVALID_PARAMETER
);
3253 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW
, InfFileName
))
3255 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3259 Result
= SetupDiInstallClassW(hwndParent
, FileNameW
.Buffer
, Flags
, FileQueue
);
3261 RtlFreeUnicodeString(&FileNameW
);
3266 static HKEY
CreateClassKey(HINF hInf
)
3268 static const WCHAR slash
[] = { '\\',0 };
3269 WCHAR FullBuffer
[MAX_PATH
];
3270 WCHAR Buffer
[MAX_PATH
];
3274 if (!SetupGetLineTextW(NULL
,
3282 return INVALID_HANDLE_VALUE
;
3285 lstrcpyW(FullBuffer
, ControlClass
);
3286 lstrcatW(FullBuffer
, slash
);
3287 lstrcatW(FullBuffer
, Buffer
);
3289 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3295 if (!SetupGetLineTextW(NULL
,
3303 return INVALID_HANDLE_VALUE
;
3306 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3310 REG_OPTION_NON_VOLATILE
,
3316 return INVALID_HANDLE_VALUE
;
3321 if (RegSetValueExW(hClassKey
,
3326 RequiredSize
* sizeof(WCHAR
)))
3328 RegCloseKey(hClassKey
);
3329 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3331 return INVALID_HANDLE_VALUE
;
3337 /***********************************************************************
3338 * SetupDiInstallClassW (SETUPAPI.@)
3340 BOOL WINAPI
SetupDiInstallClassW(
3346 WCHAR SectionName
[MAX_PATH
];
3347 DWORD SectionNameLength
= 0;
3349 BOOL bFileQueueCreated
= FALSE
;
3357 SetLastError(ERROR_INVALID_PARAMETER
);
3360 if ((Flags
& DI_NOVCP
) && (FileQueue
== NULL
|| FileQueue
== INVALID_HANDLE_VALUE
))
3362 SetLastError(ERROR_INVALID_PARAMETER
);
3366 /* Open the .inf file */
3367 hInf
= SetupOpenInfFileW(InfFileName
,
3371 if (hInf
== INVALID_HANDLE_VALUE
)
3377 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3378 hClassKey
= CreateClassKey(hInf
);
3379 if (hClassKey
== INVALID_HANDLE_VALUE
)
3381 SetupCloseInfFile(hInf
);
3386 /* Try to append a layout file */
3387 SetupOpenAppendInfFileW(NULL
, hInf
, NULL
);
3389 /* Retrieve the actual section name */
3390 SetupDiGetActualSectionToInstallW(hInf
,
3398 if (!(Flags
& DI_NOVCP
))
3400 FileQueue
= SetupOpenFileQueue();
3401 if (FileQueue
== INVALID_HANDLE_VALUE
)
3403 SetupCloseInfFile(hInf
);
3407 bFileQueueCreated
= TRUE
;
3412 SetupInstallFromInfSectionW(NULL
,
3415 SPINST_COPYINF
| SPINST_FILES
| SPINST_REGISTRY
,
3421 INVALID_HANDLE_VALUE
,
3424 /* FIXME: More code! */
3426 if (bFileQueueCreated
)
3427 SetupCloseFileQueue(FileQueue
);
3429 SetupCloseInfFile(hInf
);
3435 /***********************************************************************
3436 * SetupDiOpenClassRegKey (SETUPAPI.@)
3438 HKEY WINAPI
SetupDiOpenClassRegKey(
3439 const GUID
* ClassGuid
,
3442 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3443 DIOCR_INSTALLER
, NULL
, NULL
);
3447 /***********************************************************************
3448 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3450 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3451 const GUID
* ClassGuid
,
3457 PWSTR MachineNameW
= NULL
;
3464 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
3465 if (MachineNameW
== NULL
)
3466 return INVALID_HANDLE_VALUE
;
3469 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3470 Flags
, MachineNameW
, Reserved
);
3472 MyFree(MachineNameW
);
3478 /***********************************************************************
3479 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3481 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3482 const GUID
* ClassGuid
,
3493 if (MachineName
!= NULL
)
3495 FIXME("Remote access not supported yet!\n");
3496 return INVALID_HANDLE_VALUE
;
3499 if (Flags
== DIOCR_INSTALLER
)
3501 lpKeyName
= ControlClass
;
3503 else if (Flags
== DIOCR_INTERFACE
)
3505 lpKeyName
= DeviceClasses
;
3509 ERR("Invalid Flags parameter!\n");
3510 SetLastError(ERROR_INVALID_PARAMETER
);
3511 return INVALID_HANDLE_VALUE
;
3516 if ((l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3523 hClassesKey
= INVALID_HANDLE_VALUE
;
3529 WCHAR bracedGuidString
[39];
3531 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3533 if (!(l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3539 if ((l
= RegOpenKeyExW(hClassesKey
,
3546 key
= INVALID_HANDLE_VALUE
;
3548 RegCloseKey(hClassesKey
);
3553 key
= INVALID_HANDLE_VALUE
;
3559 /***********************************************************************
3560 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3562 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3563 HDEVINFO DeviceInfoSet
,
3566 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3568 FIXME("%p %s %08x %p\n",
3569 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3573 /***********************************************************************
3574 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3576 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
3577 HDEVINFO DeviceInfoSet
,
3580 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3582 FIXME("%p %s %08x %p\n", DeviceInfoSet
,
3583 debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3587 /***********************************************************************
3588 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3590 BOOL WINAPI
SetupDiSetClassInstallParamsA(
3591 HDEVINFO DeviceInfoSet
,
3592 PSP_DEVINFO_DATA DeviceInfoData
,
3593 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3594 DWORD ClassInstallParamsSize
)
3596 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3597 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3601 /***********************************************************************
3602 * SetupDiCallClassInstaller (SETUPAPI.@)
3604 BOOL WINAPI
SetupDiCallClassInstaller(
3605 DI_FUNCTION InstallFunction
,
3606 HDEVINFO DeviceInfoSet
,
3607 PSP_DEVINFO_DATA DeviceInfoData
)
3609 FIXME("%d %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3613 /***********************************************************************
3614 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3616 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
3617 HDEVINFO DeviceInfoSet
,
3618 PSP_DEVINFO_DATA DeviceInfoData
,
3619 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3621 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3625 static HKEY
SETUPDI_OpenDevKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3627 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
3630 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3631 NULL
, &enumKey
, NULL
);
3634 RegOpenKeyExW(enumKey
, devInfo
->instanceId
, 0, samDesired
, &key
);
3635 RegCloseKey(enumKey
);
3640 static HKEY
SETUPDI_OpenDrvKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3642 static const WCHAR slash
[] = { '\\',0 };
3643 WCHAR classKeyPath
[MAX_PATH
];
3644 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
3647 lstrcpyW(classKeyPath
, ControlClass
);
3648 lstrcatW(classKeyPath
, slash
);
3649 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3650 classKeyPath
+ lstrlenW(classKeyPath
));
3651 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3652 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3655 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3658 sprintfW(devId
, fmt
, devInfo
->devId
);
3659 RegOpenKeyExW(classKey
, devId
, 0, samDesired
, &key
);
3660 RegCloseKey(classKey
);
3665 /***********************************************************************
3666 * SetupDiOpenDevRegKey (SETUPAPI.@)
3668 HKEY WINAPI
SetupDiOpenDevRegKey(
3669 HDEVINFO DeviceInfoSet
,
3670 PSP_DEVINFO_DATA DeviceInfoData
,
3676 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3677 struct DeviceInfo
*devInfo
;
3678 HKEY key
= INVALID_HANDLE_VALUE
;
3680 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
3681 Scope
, HwProfile
, KeyType
, samDesired
);
3683 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3685 SetLastError(ERROR_INVALID_HANDLE
);
3686 return INVALID_HANDLE_VALUE
;
3688 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3690 SetLastError(ERROR_INVALID_HANDLE
);
3691 return INVALID_HANDLE_VALUE
;
3693 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3694 || !DeviceInfoData
->Reserved
)
3696 SetLastError(ERROR_INVALID_PARAMETER
);
3697 return INVALID_HANDLE_VALUE
;
3699 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3701 SetLastError(ERROR_INVALID_FLAGS
);
3702 return INVALID_HANDLE_VALUE
;
3704 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
3706 SetLastError(ERROR_INVALID_FLAGS
);
3707 return INVALID_HANDLE_VALUE
;
3709 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3710 if (devInfo
->set
!= set
)
3712 SetLastError(ERROR_INVALID_PARAMETER
);
3713 return INVALID_HANDLE_VALUE
;
3715 if (devInfo
->phantom
)
3717 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3718 return INVALID_HANDLE_VALUE
;
3720 if (Scope
!= DICS_FLAG_GLOBAL
)
3721 FIXME("unimplemented for scope %d\n", Scope
);
3725 key
= SETUPDI_OpenDevKey(devInfo
, samDesired
);
3728 key
= SETUPDI_OpenDrvKey(devInfo
, samDesired
);
3731 WARN("unknown KeyType %d\n", KeyType
);
3736 static BOOL
SETUPDI_DeleteDevKey(struct DeviceInfo
*devInfo
)
3742 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3743 NULL
, &enumKey
, NULL
);
3746 ret
= RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
3747 RegCloseKey(enumKey
);
3754 static BOOL
SETUPDI_DeleteDrvKey(struct DeviceInfo
*devInfo
)
3756 static const WCHAR slash
[] = { '\\',0 };
3757 WCHAR classKeyPath
[MAX_PATH
];
3762 lstrcpyW(classKeyPath
, ControlClass
);
3763 lstrcatW(classKeyPath
, slash
);
3764 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3765 classKeyPath
+ lstrlenW(classKeyPath
));
3766 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3767 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3770 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3773 sprintfW(devId
, fmt
, devInfo
->devId
);
3774 ret
= RegDeleteTreeW(classKey
, devId
);
3775 RegCloseKey(classKey
);
3782 /***********************************************************************
3783 * SetupDiOpenDevRegKey (SETUPAPI.@)
3785 BOOL WINAPI
SetupDiDeleteDevRegKey(
3786 HDEVINFO DeviceInfoSet
,
3787 PSP_DEVINFO_DATA DeviceInfoData
,
3792 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3793 struct DeviceInfo
*devInfo
;
3796 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
3799 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3801 SetLastError(ERROR_INVALID_HANDLE
);
3804 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3806 SetLastError(ERROR_INVALID_HANDLE
);
3809 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3810 || !DeviceInfoData
->Reserved
)
3812 SetLastError(ERROR_INVALID_PARAMETER
);
3815 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3817 SetLastError(ERROR_INVALID_FLAGS
);
3820 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
3822 SetLastError(ERROR_INVALID_FLAGS
);
3825 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3826 if (devInfo
->set
!= set
)
3828 SetLastError(ERROR_INVALID_PARAMETER
);
3831 if (devInfo
->phantom
)
3833 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3836 if (Scope
!= DICS_FLAG_GLOBAL
)
3837 FIXME("unimplemented for scope %d\n", Scope
);
3841 ret
= SETUPDI_DeleteDevKey(devInfo
);
3844 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3847 ret
= SETUPDI_DeleteDevKey(devInfo
);
3849 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3852 WARN("unknown KeyType %d\n", KeyType
);
3857 /***********************************************************************
3858 * CM_Get_Device_IDA (SETUPAPI.@)
3860 CONFIGRET WINAPI
CM_Get_Device_IDA( DEVINST dnDevInst
, PSTR Buffer
,
3861 ULONG BufferLen
, ULONG ulFlags
)
3863 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
3865 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
3868 return CR_NO_SUCH_DEVINST
;
3870 WideCharToMultiByte(CP_ACP
, 0, devInfo
->instanceId
, -1, Buffer
, BufferLen
, 0, 0);
3871 TRACE("Returning %s\n", debugstr_a(Buffer
));
3875 /***********************************************************************
3876 * CM_Get_Device_IDW (SETUPAPI.@)
3878 CONFIGRET WINAPI
CM_Get_Device_IDW( DEVINST dnDevInst
, LPWSTR Buffer
,
3879 ULONG BufferLen
, ULONG ulFlags
)
3881 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
3883 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
3887 WARN("dev instance %d not found!\n", dnDevInst
);
3888 return CR_NO_SUCH_DEVINST
;
3891 lstrcpynW(Buffer
, devInfo
->instanceId
, BufferLen
);
3892 TRACE("Returning %s\n", debugstr_w(Buffer
));
3893 GlobalUnlock((HANDLE
)dnDevInst
);
3899 /***********************************************************************
3900 * CM_Get_Device_ID_Size (SETUPAPI.@)
3902 CONFIGRET WINAPI
CM_Get_Device_ID_Size( PULONG pulLen
, DEVINST dnDevInst
,
3905 struct DeviceInfo
*ppdevInfo
= GlobalLock((HANDLE
)dnDevInst
);
3907 TRACE("%x->%p, %p, %u\n", dnDevInst
, ppdevInfo
, pulLen
, ulFlags
);
3911 WARN("dev instance %d not found!\n", dnDevInst
);
3912 return CR_NO_SUCH_DEVINST
;
3915 *pulLen
= lstrlenW(ppdevInfo
->instanceId
);
3916 GlobalUnlock((HANDLE
)dnDevInst
);