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 Chicago
[] = {'$','C','h','i','c','a','g','o','$',0};
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 Signature
[] = {'S','i','g','n','a','t','u','r','e',0};
59 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
60 static const WCHAR WinExtension
[] = {'.','W','i','n',0};
61 static const WCHAR WindowsNT
[] = {'$','W','i','n','d','o','w','s',' ','N','T','$',0};
63 /* Registry key and value names */
64 static const WCHAR ControlClass
[] = {'S','y','s','t','e','m','\\',
65 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
66 'C','o','n','t','r','o','l','\\',
67 'C','l','a','s','s',0};
69 static const WCHAR DeviceClasses
[] = {'S','y','s','t','e','m','\\',
70 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
71 'C','o','n','t','r','o','l','\\',
72 'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
73 static const WCHAR Enum
[] = {'S','y','s','t','e','m','\\',
74 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
76 static const WCHAR DeviceDesc
[] = {'D','e','v','i','c','e','D','e','s','c',0};
77 static const WCHAR DeviceInstance
[] = {'D','e','v','i','c','e','I','n','s','t','a','n','c','e',0};
78 static const WCHAR HardwareId
[] = {'H','a','r','d','w','a','r','e','I','D',0};
79 static const WCHAR CompatibleIDs
[] = {'C','o','m','p','a','t','i','b','l','e','I','d','s',0};
80 static const WCHAR Service
[] = {'S','e','r','v','i','c','e',0};
81 static const WCHAR Driver
[] = {'D','r','i','v','e','r',0};
82 static const WCHAR ConfigFlags
[] = {'C','o','n','f','i','g','F','l','a','g','s',0};
83 static const WCHAR Mfg
[] = {'M','f','g',0};
84 static const WCHAR FriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
85 static const WCHAR LocationInformation
[] = {'L','o','c','a','t','i','o','n','I','n','f','o','r','m','a','t','i','o','n',0};
86 static const WCHAR Capabilities
[] = {'C','a','p','a','b','i','l','i','t','i','e','s',0};
87 static const WCHAR UINumber
[] = {'U','I','N','u','m','b','e','r',0};
88 static const WCHAR UpperFilters
[] = {'U','p','p','e','r','F','i','l','t','e','r','s',0};
89 static const WCHAR LowerFilters
[] = {'L','o','w','e','r','F','i','l','t','e','r','s',0};
90 static const WCHAR Phantom
[] = {'P','h','a','n','t','o','m',0};
91 static const WCHAR SymbolicLink
[] = {'S','y','m','b','o','l','i','c','L','i','n','k',0};
93 /* is used to identify if a DeviceInfoSet pointer is
95 #define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff056
99 DWORD magic
; /* if is equal to SETUP_DEVICE_INFO_SET_MAGIC struct is okay */
106 struct DeviceInstance
109 SP_DEVINFO_DATA data
;
112 /* Pointed to by SP_DEVICE_INTERFACE_DATA's Reserved member */
115 LPWSTR referenceString
;
117 PSP_DEVINFO_DATA device
;
120 /* A device may have multiple instances of the same interface, so this holds
121 * each instance belonging to a particular interface.
123 struct InterfaceInstances
127 DWORD cInstancesAllocated
;
128 SP_DEVICE_INTERFACE_DATA
*instances
;
132 /* Pointed to by SP_DEVINFO_DATA's Reserved member */
135 struct DeviceInfoSet
*set
;
140 struct list interfaces
;
143 static void SETUPDI_GuidToString(const GUID
*guid
, LPWSTR guidStr
)
145 static const WCHAR fmt
[] = {'{','%','0','8','X','-','%','0','4','X','-',
146 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
147 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
150 sprintfW(guidStr
, fmt
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
151 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
152 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
155 static void SETUPDI_FreeInterfaceInstances(struct InterfaceInstances
*instances
)
159 for (i
= 0; i
< instances
->cInstances
; i
++)
161 struct InterfaceInfo
*ifaceInfo
=
162 (struct InterfaceInfo
*)instances
->instances
[i
].Reserved
;
164 if (ifaceInfo
->device
&& ifaceInfo
->device
->Reserved
)
166 struct DeviceInfo
*devInfo
=
167 (struct DeviceInfo
*)ifaceInfo
->device
->Reserved
;
169 if (devInfo
->phantom
)
170 SetupDiDeleteDeviceInterfaceRegKey(devInfo
->set
,
171 &instances
->instances
[i
], 0);
173 HeapFree(GetProcessHeap(), 0, ifaceInfo
->referenceString
);
174 HeapFree(GetProcessHeap(), 0, ifaceInfo
->symbolicLink
);
175 HeapFree(GetProcessHeap(), 0, ifaceInfo
);
177 HeapFree(GetProcessHeap(), 0, instances
->instances
);
180 /* Finds the interface with interface class InterfaceClassGuid in the device.
181 * Returns TRUE if found, and updates *interface to point to device's
182 * interfaces member where the given interface was found.
183 * Returns FALSE if not found.
185 static BOOL
SETUPDI_FindInterface(const struct DeviceInfo
*devInfo
,
186 const GUID
*InterfaceClassGuid
, struct InterfaceInstances
**iface_ret
)
189 struct InterfaceInstances
*iface
;
191 TRACE("%s\n", debugstr_guid(InterfaceClassGuid
));
193 LIST_FOR_EACH_ENTRY(iface
, &devInfo
->interfaces
, struct InterfaceInstances
,
196 if (IsEqualGUID(&iface
->guid
, InterfaceClassGuid
))
203 TRACE("returning %d (%p)\n", found
, found
? *iface_ret
: NULL
);
207 /* Finds the interface instance with reference string ReferenceString in the
208 * interface instance map. Returns TRUE if found, and updates instanceIndex to
209 * the index of the interface instance's instances member
210 * where the given instance was found. Returns FALSE if not found.
212 static BOOL
SETUPDI_FindInterfaceInstance(
213 const struct InterfaceInstances
*instances
,
214 LPCWSTR ReferenceString
, DWORD
*instanceIndex
)
219 TRACE("%s\n", debugstr_w(ReferenceString
));
221 for (i
= 0; !found
&& i
< instances
->cInstances
; i
++)
223 SP_DEVICE_INTERFACE_DATA
*ifaceData
= &instances
->instances
[i
];
224 struct InterfaceInfo
*ifaceInfo
=
225 (struct InterfaceInfo
*)ifaceData
->Reserved
;
227 if (!ReferenceString
&& !ifaceInfo
->referenceString
)
232 else if (ReferenceString
&& ifaceInfo
->referenceString
&&
233 !lstrcmpiW(ifaceInfo
->referenceString
, ReferenceString
))
239 TRACE("returning %d (%d)\n", found
, found
? *instanceIndex
: 0);
243 static LPWSTR
SETUPDI_CreateSymbolicLinkPath(LPCWSTR instanceId
,
244 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
)
246 static const WCHAR fmt
[] = {'\\','\\','?','\\','%','s','#','%','s',0};
251 SETUPDI_GuidToString(InterfaceClassGuid
, guidStr
);
252 /* omit length of format specifiers, but include NULL terminator: */
253 len
= lstrlenW(fmt
) - 4 + 1;
254 len
+= lstrlenW(instanceId
) + lstrlenW(guidStr
);
255 if (ReferenceString
&& *ReferenceString
)
257 /* space for a hash between string and reference string: */
258 len
+= lstrlenW(ReferenceString
) + 1;
260 ret
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
263 int printed
= sprintfW(ret
, fmt
, instanceId
, guidStr
);
266 /* replace '\\' with '#' after the "\\\\?\\" beginning */
267 for (ptr
= strchrW(ret
+ 4, '\\'); ptr
; ptr
= strchrW(ptr
+ 1, '\\'))
269 if (ReferenceString
&& *ReferenceString
)
272 lstrcpyW(ret
+ printed
+ 1, ReferenceString
);
278 /* Adds an interface with the given interface class and reference string to
279 * the device, if it doesn't already exist in the device. If iface is not
280 * NULL, returns a pointer to the newly added (or already existing) interface.
282 static BOOL
SETUPDI_AddInterfaceInstance(PSP_DEVINFO_DATA DeviceInfoData
,
283 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
,
284 SP_DEVICE_INTERFACE_DATA
**ifaceData
)
286 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
287 BOOL newInterface
= FALSE
, ret
;
288 struct InterfaceInstances
*iface
= NULL
;
290 TRACE("%p %s %s %p\n", devInfo
, debugstr_guid(InterfaceClassGuid
),
291 debugstr_w(ReferenceString
), iface
);
293 if (!(ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
295 iface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
296 sizeof(struct InterfaceInstances
));
299 list_add_tail(&devInfo
->interfaces
, &iface
->entry
);
305 DWORD instanceIndex
= 0;
307 if (!(ret
= SETUPDI_FindInterfaceInstance(iface
, ReferenceString
,
310 SP_DEVICE_INTERFACE_DATA
*instance
= NULL
;
312 if (!iface
->cInstancesAllocated
)
314 iface
->instances
= HeapAlloc(GetProcessHeap(), 0,
315 sizeof(SP_DEVICE_INTERFACE_DATA
));
316 if (iface
->instances
)
317 instance
= &iface
->instances
[iface
->cInstancesAllocated
++];
319 else if (iface
->cInstances
== iface
->cInstancesAllocated
)
321 iface
->instances
= HeapReAlloc(GetProcessHeap(), 0,
323 (iface
->cInstancesAllocated
+ 1) *
324 sizeof(SP_DEVICE_INTERFACE_DATA
));
325 if (iface
->instances
)
326 instance
= &iface
->instances
[iface
->cInstancesAllocated
++];
329 instance
= &iface
->instances
[iface
->cInstances
];
332 struct InterfaceInfo
*ifaceInfo
= HeapAlloc(GetProcessHeap(),
333 0, sizeof(struct InterfaceInfo
));
338 ifaceInfo
->device
= DeviceInfoData
;
339 ifaceInfo
->symbolicLink
= SETUPDI_CreateSymbolicLinkPath(
340 devInfo
->instanceId
, InterfaceClassGuid
,
344 ifaceInfo
->referenceString
=
345 HeapAlloc(GetProcessHeap(), 0,
346 (lstrlenW(ReferenceString
) + 1) *
348 if (ifaceInfo
->referenceString
)
349 lstrcpyW(ifaceInfo
->referenceString
,
355 ifaceInfo
->referenceString
= NULL
;
362 sizeof(SP_DEVICE_INTERFACE_DATA
);
363 instance
->InterfaceClassGuid
= *InterfaceClassGuid
;
364 instance
->Flags
= SPINT_ACTIVE
; /* FIXME */
365 instance
->Reserved
= (ULONG_PTR
)ifaceInfo
;
367 iface
->guid
= *InterfaceClassGuid
;
368 key
= SetupDiCreateDeviceInterfaceRegKeyW(devInfo
->set
,
369 instance
, 0, KEY_WRITE
, NULL
, NULL
);
370 if (key
!= INVALID_HANDLE_VALUE
)
372 RegSetValueExW(key
, SymbolicLink
, 0, REG_SZ
,
373 (BYTE
*)ifaceInfo
->symbolicLink
,
374 lstrlenW(ifaceInfo
->symbolicLink
) *
379 *ifaceData
= instance
;
382 HeapFree(GetProcessHeap(), 0, ifaceInfo
);
389 *ifaceData
= &iface
->instances
[instanceIndex
];
394 TRACE("returning %d\n", ret
);
398 static BOOL
SETUPDI_SetInterfaceSymbolicLink(SP_DEVICE_INTERFACE_DATA
*iface
,
399 LPCWSTR symbolicLink
)
401 struct InterfaceInfo
*info
= (struct InterfaceInfo
*)iface
->Reserved
;
406 HeapFree(GetProcessHeap(), 0, info
->symbolicLink
);
407 info
->symbolicLink
= HeapAlloc(GetProcessHeap(), 0,
408 (lstrlenW(symbolicLink
) + 1) * sizeof(WCHAR
));
409 if (info
->symbolicLink
)
411 lstrcpyW(info
->symbolicLink
, symbolicLink
);
418 static HKEY
SETUPDI_CreateDevKey(struct DeviceInfo
*devInfo
)
420 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
423 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
424 NULL
, &enumKey
, NULL
);
427 RegCreateKeyExW(enumKey
, devInfo
->instanceId
, 0, NULL
, 0,
428 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
429 RegCloseKey(enumKey
);
434 static HKEY
SETUPDI_CreateDrvKey(struct DeviceInfo
*devInfo
)
436 static const WCHAR slash
[] = { '\\',0 };
437 WCHAR classKeyPath
[MAX_PATH
];
438 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
441 lstrcpyW(classKeyPath
, ControlClass
);
442 lstrcatW(classKeyPath
, slash
);
443 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
444 classKeyPath
+ lstrlenW(classKeyPath
));
445 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
446 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
449 static const WCHAR fmt
[] = { '%','0','4','u',0 };
452 sprintfW(devId
, fmt
, devInfo
->devId
);
453 RegCreateKeyExW(classKey
, devId
, 0, NULL
, 0, KEY_READ
| KEY_WRITE
,
455 RegCloseKey(classKey
);
460 static struct DeviceInfo
*SETUPDI_AllocateDeviceInfo(struct DeviceInfoSet
*set
,
461 DWORD devId
, LPCWSTR instanceId
, BOOL phantom
)
463 struct DeviceInfo
*devInfo
= NULL
;
464 HANDLE devInst
= GlobalAlloc(GMEM_FIXED
, sizeof(struct DeviceInfo
));
466 devInfo
= GlobalLock(devInst
);
471 devInfo
->devId
= (DWORD
)devInst
;
473 devInfo
->instanceId
= HeapAlloc(GetProcessHeap(), 0,
474 (lstrlenW(instanceId
) + 1) * sizeof(WCHAR
));
475 if (devInfo
->instanceId
)
477 devInfo
->key
= INVALID_HANDLE_VALUE
;
478 devInfo
->phantom
= phantom
;
479 lstrcpyW(devInfo
->instanceId
, instanceId
);
480 struprW(devInfo
->instanceId
);
481 devInfo
->key
= SETUPDI_CreateDevKey(devInfo
);
482 if (devInfo
->key
!= INVALID_HANDLE_VALUE
)
485 RegSetValueExW(devInfo
->key
, Phantom
, 0, REG_DWORD
,
486 (LPBYTE
)&phantom
, sizeof(phantom
));
488 list_init(&devInfo
->interfaces
);
489 GlobalUnlock(devInst
);
493 GlobalUnlock(devInst
);
501 static void SETUPDI_FreeDeviceInfo(struct DeviceInfo
*devInfo
)
503 struct InterfaceInstances
*iface
, *next
;
505 if (devInfo
->key
!= INVALID_HANDLE_VALUE
)
506 RegCloseKey(devInfo
->key
);
507 if (devInfo
->phantom
)
512 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0,
513 KEY_ALL_ACCESS
, NULL
, &enumKey
, NULL
);
516 RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
517 RegCloseKey(enumKey
);
520 HeapFree(GetProcessHeap(), 0, devInfo
->instanceId
);
521 LIST_FOR_EACH_ENTRY_SAFE(iface
, next
, &devInfo
->interfaces
,
522 struct InterfaceInstances
, entry
)
524 list_remove(&iface
->entry
);
525 SETUPDI_FreeInterfaceInstances(iface
);
526 HeapFree(GetProcessHeap(), 0, iface
);
528 GlobalFree((HANDLE
)devInfo
->devId
);
531 /* Adds a device with GUID guid and identifier devInst to set. Allocates a
532 * struct DeviceInfo, and points the returned device info's Reserved member
533 * to it. "Phantom" devices are deleted from the registry when closed.
534 * Returns a pointer to the newly allocated device info.
536 static BOOL
SETUPDI_AddDeviceToSet(struct DeviceInfoSet
*set
,
541 SP_DEVINFO_DATA
**dev
)
544 struct DeviceInfo
*devInfo
= SETUPDI_AllocateDeviceInfo(set
, set
->cDevices
,
545 instanceId
, phantom
);
547 TRACE("%p, %s, %d, %s, %d\n", set
, debugstr_guid(guid
), dev_inst
,
548 debugstr_w(instanceId
), phantom
);
552 struct DeviceInstance
*devInst
=
553 HeapAlloc(GetProcessHeap(), 0, sizeof(struct DeviceInstance
));
557 WCHAR classGuidStr
[39];
559 list_add_tail(&set
->devices
, &devInst
->entry
);
561 devInst
->data
.cbSize
= sizeof(SP_DEVINFO_DATA
);
562 devInst
->data
.ClassGuid
= *guid
;
563 devInst
->data
.DevInst
= devInfo
->devId
;
564 devInst
->data
.Reserved
= (ULONG_PTR
)devInfo
;
565 SETUPDI_GuidToString(guid
, classGuidStr
);
566 SetupDiSetDeviceRegistryPropertyW(set
, &devInst
->data
,
567 SPDRP_CLASSGUID
, (const BYTE
*)classGuidStr
,
568 lstrlenW(classGuidStr
) * sizeof(WCHAR
));
569 if (dev
) *dev
= &devInst
->data
;
574 HeapFree(GetProcessHeap(), 0, devInfo
);
575 SetLastError(ERROR_OUTOFMEMORY
);
581 /***********************************************************************
582 * SetupDiBuildClassInfoList (SETUPAPI.@)
584 * Returns a list of setup class GUIDs that identify the classes
585 * that are installed on a local machine.
588 * Flags [I] control exclusion of classes from the list.
589 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
590 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
591 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
597 BOOL WINAPI
SetupDiBuildClassInfoList(
599 LPGUID ClassGuidList
,
600 DWORD ClassGuidListSize
,
604 return SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
605 ClassGuidListSize
, RequiredSize
,
609 /***********************************************************************
610 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
612 * Returns a list of setup class GUIDs that identify the classes
613 * that are installed on a local or remote machine.
616 * Flags [I] control exclusion of classes from the list.
617 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
618 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
619 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
620 * MachineName [I] name of a remote machine.
621 * Reserved [I] must be NULL.
627 BOOL WINAPI
SetupDiBuildClassInfoListExA(
629 LPGUID ClassGuidList
,
630 DWORD ClassGuidListSize
,
635 LPWSTR MachineNameW
= NULL
;
642 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
643 if (MachineNameW
== NULL
) return FALSE
;
646 bResult
= SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
647 ClassGuidListSize
, RequiredSize
,
648 MachineNameW
, Reserved
);
650 MyFree(MachineNameW
);
655 /***********************************************************************
656 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
658 * Returns a list of setup class GUIDs that identify the classes
659 * that are installed on a local or remote machine.
662 * Flags [I] control exclusion of classes from the list.
663 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
664 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
665 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
666 * MachineName [I] name of a remote machine.
667 * Reserved [I] must be NULL.
673 BOOL WINAPI
SetupDiBuildClassInfoListExW(
675 LPGUID ClassGuidList
,
676 DWORD ClassGuidListSize
,
687 DWORD dwGuidListIndex
= 0;
691 if (RequiredSize
!= NULL
)
694 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
699 if (hClassesKey
== INVALID_HANDLE_VALUE
)
704 for (dwIndex
= 0; ; dwIndex
++)
707 lError
= RegEnumKeyExW(hClassesKey
,
715 TRACE("RegEnumKeyExW() returns %d\n", lError
);
716 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
718 TRACE("Key name: %p\n", szKeyName
);
720 if (RegOpenKeyExW(hClassesKey
,
726 RegCloseKey(hClassesKey
);
730 if (!RegQueryValueExW(hClassKey
,
737 TRACE("'NoUseClass' value found!\n");
738 RegCloseKey(hClassKey
);
742 if ((Flags
& DIBCI_NOINSTALLCLASS
) &&
743 (!RegQueryValueExW(hClassKey
,
750 TRACE("'NoInstallClass' value found!\n");
751 RegCloseKey(hClassKey
);
755 if ((Flags
& DIBCI_NODISPLAYCLASS
) &&
756 (!RegQueryValueExW(hClassKey
,
763 TRACE("'NoDisplayClass' value found!\n");
764 RegCloseKey(hClassKey
);
768 RegCloseKey(hClassKey
);
770 TRACE("Guid: %p\n", szKeyName
);
771 if (dwGuidListIndex
< ClassGuidListSize
)
773 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
777 TRACE("Guid: %p\n", &szKeyName
[1]);
779 UuidFromStringW(&szKeyName
[1],
780 &ClassGuidList
[dwGuidListIndex
]);
786 if (lError
!= ERROR_SUCCESS
)
790 RegCloseKey(hClassesKey
);
792 if (RequiredSize
!= NULL
)
793 *RequiredSize
= dwGuidListIndex
;
795 if (ClassGuidListSize
< dwGuidListIndex
)
797 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
804 /***********************************************************************
805 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
807 BOOL WINAPI
SetupDiClassGuidsFromNameA(
809 LPGUID ClassGuidList
,
810 DWORD ClassGuidListSize
,
813 return SetupDiClassGuidsFromNameExA(ClassName
, ClassGuidList
,
814 ClassGuidListSize
, RequiredSize
,
818 /***********************************************************************
819 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
821 BOOL WINAPI
SetupDiClassGuidsFromNameW(
823 LPGUID ClassGuidList
,
824 DWORD ClassGuidListSize
,
827 return SetupDiClassGuidsFromNameExW(ClassName
, ClassGuidList
,
828 ClassGuidListSize
, RequiredSize
,
832 /***********************************************************************
833 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
835 BOOL WINAPI
SetupDiClassGuidsFromNameExA(
837 LPGUID ClassGuidList
,
838 DWORD ClassGuidListSize
,
843 LPWSTR ClassNameW
= NULL
;
844 LPWSTR MachineNameW
= NULL
;
847 ClassNameW
= MultiByteToUnicode(ClassName
, CP_ACP
);
848 if (ClassNameW
== NULL
)
853 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
854 if (MachineNameW
== NULL
)
861 bResult
= SetupDiClassGuidsFromNameExW(ClassNameW
, ClassGuidList
,
862 ClassGuidListSize
, RequiredSize
,
863 MachineNameW
, Reserved
);
865 MyFree(MachineNameW
);
871 /***********************************************************************
872 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
874 BOOL WINAPI
SetupDiClassGuidsFromNameExW(
876 LPGUID ClassGuidList
,
877 DWORD ClassGuidListSize
,
883 WCHAR szClassName
[256];
889 DWORD dwGuidListIndex
= 0;
891 if (RequiredSize
!= NULL
)
894 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
899 if (hClassesKey
== INVALID_HANDLE_VALUE
)
904 for (dwIndex
= 0; ; dwIndex
++)
906 dwLength
= sizeof(szKeyName
) / sizeof(WCHAR
);
907 lError
= RegEnumKeyExW(hClassesKey
,
915 TRACE("RegEnumKeyExW() returns %d\n", lError
);
916 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
918 TRACE("Key name: %p\n", szKeyName
);
920 if (RegOpenKeyExW(hClassesKey
,
926 RegCloseKey(hClassesKey
);
930 dwLength
= sizeof(szClassName
);
931 if (!RegQueryValueExW(hClassKey
,
938 TRACE("Class name: %p\n", szClassName
);
940 if (strcmpiW(szClassName
, ClassName
) == 0)
942 TRACE("Found matching class name\n");
944 TRACE("Guid: %p\n", szKeyName
);
945 if (dwGuidListIndex
< ClassGuidListSize
)
947 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
951 TRACE("Guid: %p\n", &szKeyName
[1]);
953 UuidFromStringW(&szKeyName
[1],
954 &ClassGuidList
[dwGuidListIndex
]);
961 RegCloseKey(hClassKey
);
964 if (lError
!= ERROR_SUCCESS
)
968 RegCloseKey(hClassesKey
);
970 if (RequiredSize
!= NULL
)
971 *RequiredSize
= dwGuidListIndex
;
973 if (ClassGuidListSize
< dwGuidListIndex
)
975 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
982 /***********************************************************************
983 * SetupDiClassNameFromGuidA (SETUPAPI.@)
985 BOOL WINAPI
SetupDiClassNameFromGuidA(
986 const GUID
* ClassGuid
,
991 return SetupDiClassNameFromGuidExA(ClassGuid
, ClassName
,
992 ClassNameSize
, RequiredSize
,
996 /***********************************************************************
997 * SetupDiClassNameFromGuidW (SETUPAPI.@)
999 BOOL WINAPI
SetupDiClassNameFromGuidW(
1000 const GUID
* ClassGuid
,
1002 DWORD ClassNameSize
,
1003 PDWORD RequiredSize
)
1005 return SetupDiClassNameFromGuidExW(ClassGuid
, ClassName
,
1006 ClassNameSize
, RequiredSize
,
1010 /***********************************************************************
1011 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1013 BOOL WINAPI
SetupDiClassNameFromGuidExA(
1014 const GUID
* ClassGuid
,
1016 DWORD ClassNameSize
,
1017 PDWORD RequiredSize
,
1021 WCHAR ClassNameW
[MAX_CLASS_NAME_LEN
];
1022 LPWSTR MachineNameW
= NULL
;
1026 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1027 ret
= SetupDiClassNameFromGuidExW(ClassGuid
, ClassNameW
, MAX_CLASS_NAME_LEN
,
1028 NULL
, MachineNameW
, Reserved
);
1031 int len
= WideCharToMultiByte(CP_ACP
, 0, ClassNameW
, -1, ClassName
,
1032 ClassNameSize
, NULL
, NULL
);
1034 if (!ClassNameSize
&& RequiredSize
)
1035 *RequiredSize
= len
;
1037 MyFree(MachineNameW
);
1041 /***********************************************************************
1042 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1044 BOOL WINAPI
SetupDiClassNameFromGuidExW(
1045 const GUID
* ClassGuid
,
1047 DWORD ClassNameSize
,
1048 PDWORD RequiredSize
,
1055 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1060 if (hKey
== INVALID_HANDLE_VALUE
)
1065 if (RequiredSize
!= NULL
)
1068 if (RegQueryValueExW(hKey
,
1079 *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1082 dwLength
= ClassNameSize
* sizeof(WCHAR
);
1083 if (RegQueryValueExW(hKey
,
1099 /***********************************************************************
1100 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1103 SetupDiCreateDeviceInfoList(const GUID
*ClassGuid
,
1106 return SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
, NULL
, NULL
);
1109 /***********************************************************************
1110 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1113 SetupDiCreateDeviceInfoListExA(const GUID
*ClassGuid
,
1118 LPWSTR MachineNameW
= NULL
;
1125 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1126 if (MachineNameW
== NULL
)
1127 return INVALID_HANDLE_VALUE
;
1130 hDevInfo
= SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
,
1131 MachineNameW
, Reserved
);
1133 MyFree(MachineNameW
);
1138 /***********************************************************************
1139 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1141 * Create an empty DeviceInfoSet list.
1144 * ClassGuid [I] if not NULL only devices with GUID ClassGuid are associated
1146 * hwndParent [I] hwnd needed for interface related actions.
1147 * MachineName [I] name of machine to create empty DeviceInfoSet list, if NULL
1148 * local registry will be used.
1149 * Reserved [I] must be NULL
1152 * Success: empty list.
1153 * Failure: INVALID_HANDLE_VALUE.
1156 SetupDiCreateDeviceInfoListExW(const GUID
*ClassGuid
,
1161 struct DeviceInfoSet
*list
= NULL
;
1162 DWORD size
= sizeof(struct DeviceInfoSet
);
1164 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1165 debugstr_w(MachineName
), Reserved
);
1167 if (MachineName
&& *MachineName
)
1169 FIXME("remote support is not implemented\n");
1170 SetLastError(ERROR_INVALID_MACHINENAME
);
1171 return INVALID_HANDLE_VALUE
;
1174 if (Reserved
!= NULL
)
1176 SetLastError(ERROR_INVALID_PARAMETER
);
1177 return INVALID_HANDLE_VALUE
;
1180 list
= HeapAlloc(GetProcessHeap(), 0, size
);
1183 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1184 return INVALID_HANDLE_VALUE
;
1187 list
->magic
= SETUP_DEVICE_INFO_SET_MAGIC
;
1188 list
->hwndParent
= hwndParent
;
1189 memcpy(&list
->ClassGuid
,
1190 ClassGuid
? ClassGuid
: &GUID_NULL
,
1191 sizeof(list
->ClassGuid
));
1193 list_init(&list
->devices
);
1198 /***********************************************************************
1199 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1201 HKEY WINAPI
SetupDiCreateDevRegKeyA(
1202 HDEVINFO DeviceInfoSet
,
1203 PSP_DEVINFO_DATA DeviceInfoData
,
1208 PCSTR InfSectionName
)
1210 PWSTR InfSectionNameW
= NULL
;
1213 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1214 HwProfile
, KeyType
, InfHandle
, debugstr_a(InfSectionName
));
1218 if (!InfSectionName
)
1220 SetLastError(ERROR_INVALID_PARAMETER
);
1221 return INVALID_HANDLE_VALUE
;
1225 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
1226 if (InfSectionNameW
== NULL
) return INVALID_HANDLE_VALUE
;
1229 key
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, Scope
,
1230 HwProfile
, KeyType
, InfHandle
, InfSectionNameW
);
1231 MyFree(InfSectionNameW
);
1235 /***********************************************************************
1236 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1238 HKEY WINAPI
SetupDiCreateDevRegKeyW(
1239 HDEVINFO DeviceInfoSet
,
1240 PSP_DEVINFO_DATA DeviceInfoData
,
1245 PCWSTR InfSectionName
)
1247 struct DeviceInfoSet
*set
= DeviceInfoSet
;
1248 struct DeviceInfo
*devInfo
;
1249 HKEY key
= INVALID_HANDLE_VALUE
;
1251 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1252 HwProfile
, KeyType
, InfHandle
, debugstr_w(InfSectionName
));
1254 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1256 SetLastError(ERROR_INVALID_HANDLE
);
1257 return INVALID_HANDLE_VALUE
;
1259 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1261 SetLastError(ERROR_INVALID_HANDLE
);
1262 return INVALID_HANDLE_VALUE
;
1264 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1265 || !DeviceInfoData
->Reserved
)
1267 SetLastError(ERROR_INVALID_PARAMETER
);
1268 return INVALID_HANDLE_VALUE
;
1270 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1271 if (devInfo
->set
!= set
)
1273 SetLastError(ERROR_INVALID_PARAMETER
);
1274 return INVALID_HANDLE_VALUE
;
1276 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
1278 SetLastError(ERROR_INVALID_FLAGS
);
1279 return INVALID_HANDLE_VALUE
;
1281 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
1283 SetLastError(ERROR_INVALID_FLAGS
);
1284 return INVALID_HANDLE_VALUE
;
1286 if (devInfo
->phantom
)
1288 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
1289 return INVALID_HANDLE_VALUE
;
1291 if (Scope
!= DICS_FLAG_GLOBAL
)
1292 FIXME("unimplemented for scope %d\n", Scope
);
1296 key
= SETUPDI_CreateDevKey(devInfo
);
1299 key
= SETUPDI_CreateDrvKey(devInfo
);
1302 WARN("unknown KeyType %d\n", KeyType
);
1305 SetupInstallFromInfSectionW(NULL
, InfHandle
, InfSectionName
, SPINST_ALL
,
1306 NULL
, NULL
, SP_COPY_NEWER_ONLY
, NULL
, NULL
, DeviceInfoSet
,
1311 /***********************************************************************
1312 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1314 BOOL WINAPI
SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet
, PCSTR DeviceName
,
1315 const GUID
*ClassGuid
, PCSTR DeviceDescription
, HWND hwndParent
, DWORD CreationFlags
,
1316 PSP_DEVINFO_DATA DeviceInfoData
)
1319 LPWSTR DeviceNameW
= NULL
;
1320 LPWSTR DeviceDescriptionW
= NULL
;
1324 DeviceNameW
= MultiByteToUnicode(DeviceName
, CP_ACP
);
1325 if (DeviceNameW
== NULL
) return FALSE
;
1327 if (DeviceDescription
)
1329 DeviceDescriptionW
= MultiByteToUnicode(DeviceDescription
, CP_ACP
);
1330 if (DeviceDescriptionW
== NULL
)
1332 MyFree(DeviceNameW
);
1337 ret
= SetupDiCreateDeviceInfoW(DeviceInfoSet
, DeviceNameW
, ClassGuid
, DeviceDescriptionW
,
1338 hwndParent
, CreationFlags
, DeviceInfoData
);
1340 MyFree(DeviceNameW
);
1341 MyFree(DeviceDescriptionW
);
1346 static DWORD
SETUPDI_DevNameToDevID(LPCWSTR devName
)
1349 int devNameLen
= lstrlenW(devName
);
1353 TRACE("%s\n", debugstr_w(devName
));
1354 for (ptr
= devName
; valid
&& *ptr
&& ptr
- devName
< devNameLen
; )
1359 devInst
|= *ptr
- '0';
1365 TRACE("%d\n", valid
? devInst
: 0xffffffff);
1366 return valid
? devInst
: 0xffffffff;
1369 /***********************************************************************
1370 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1372 BOOL WINAPI
SetupDiCreateDeviceInfoW(HDEVINFO DeviceInfoSet
, PCWSTR DeviceName
,
1373 const GUID
*ClassGuid
, PCWSTR DeviceDescription
, HWND hwndParent
, DWORD CreationFlags
,
1374 PSP_DEVINFO_DATA DeviceInfoData
)
1376 struct DeviceInfoSet
*set
= DeviceInfoSet
;
1377 BOOL ret
= FALSE
, allocatedInstanceId
= FALSE
;
1378 LPCWSTR instanceId
= NULL
;
1380 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet
, debugstr_w(DeviceName
),
1381 debugstr_guid(ClassGuid
), debugstr_w(DeviceDescription
),
1382 hwndParent
, CreationFlags
, DeviceInfoData
);
1386 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1389 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1391 SetLastError(ERROR_INVALID_HANDLE
);
1396 SetLastError(ERROR_INVALID_PARAMETER
);
1399 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1401 SetLastError(ERROR_INVALID_HANDLE
);
1404 if (!IsEqualGUID(&set
->ClassGuid
, &GUID_NULL
) &&
1405 !IsEqualGUID(ClassGuid
, &set
->ClassGuid
))
1407 SetLastError(ERROR_CLASS_MISMATCH
);
1410 if ((CreationFlags
& DICD_GENERATE_ID
))
1412 if (strchrW(DeviceName
, '\\'))
1413 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1416 static const WCHAR newDeviceFmt
[] = {'R','O','O','T','\\','%','s',
1417 '\\','%','0','4','d',0};
1422 DWORD highestDevID
= 0;
1423 struct DeviceInstance
*devInst
;
1425 LIST_FOR_EACH_ENTRY(devInst
, &set
->devices
, struct DeviceInstance
, entry
)
1427 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)devInst
->data
.Reserved
;
1428 LPCWSTR devName
= strrchrW(devInfo
->instanceId
, '\\');
1434 devName
= devInfo
->instanceId
;
1435 id
= SETUPDI_DevNameToDevID(devName
);
1436 if (id
!= 0xffffffff && id
> highestDevID
)
1439 devId
= highestDevID
+ 1;
1443 /* 17 == lstrlenW(L"Root\\") + lstrlenW("\\") + 1 + %d max size */
1444 instanceId
= HeapAlloc(GetProcessHeap(), 0,
1445 (17 + lstrlenW(DeviceName
)) * sizeof(WCHAR
));
1448 sprintfW((LPWSTR
)instanceId
, newDeviceFmt
, DeviceName
,
1450 allocatedInstanceId
= TRUE
;
1459 struct DeviceInstance
*devInst
;
1462 instanceId
= DeviceName
;
1463 LIST_FOR_EACH_ENTRY(devInst
, &set
->devices
, struct DeviceInstance
, entry
)
1465 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)devInst
->data
.Reserved
;
1467 if (!lstrcmpiW(DeviceName
, devInfo
->instanceId
))
1469 SetLastError(ERROR_DEVINST_ALREADY_EXISTS
);
1476 SP_DEVINFO_DATA
*dev
= NULL
;
1478 ret
= SETUPDI_AddDeviceToSet(set
, ClassGuid
, 0 /* FIXME: DevInst */,
1479 instanceId
, TRUE
, &dev
);
1482 if (DeviceDescription
)
1483 SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet
,
1484 dev
, SPDRP_DEVICEDESC
, (const BYTE
*)DeviceDescription
,
1485 lstrlenW(DeviceDescription
) * sizeof(WCHAR
));
1488 if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1490 SetLastError(ERROR_INVALID_USER_BUFFER
);
1494 *DeviceInfoData
= *dev
;
1498 if (allocatedInstanceId
)
1499 HeapFree(GetProcessHeap(), 0, (LPWSTR
)instanceId
);
1504 /***********************************************************************
1505 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1507 BOOL WINAPI
SetupDiRegisterDeviceInfo(
1508 HDEVINFO DeviceInfoSet
,
1509 PSP_DEVINFO_DATA DeviceInfoData
,
1511 PSP_DETSIG_CMPPROC CompareProc
,
1512 PVOID CompareContext
,
1513 PSP_DEVINFO_DATA DupDeviceInfoData
)
1515 struct DeviceInfoSet
*set
= DeviceInfoSet
;
1516 struct DeviceInfo
*devInfo
;
1518 TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet
, DeviceInfoData
, Flags
,
1519 CompareProc
, CompareContext
, DupDeviceInfoData
);
1521 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1523 SetLastError(ERROR_INVALID_HANDLE
);
1526 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1528 SetLastError(ERROR_INVALID_HANDLE
);
1531 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1532 || !DeviceInfoData
->Reserved
)
1534 SetLastError(ERROR_INVALID_PARAMETER
);
1537 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1538 if (devInfo
->set
!= set
)
1540 SetLastError(ERROR_INVALID_PARAMETER
);
1543 if (devInfo
->phantom
)
1545 devInfo
->phantom
= FALSE
;
1546 RegDeleteValueW(devInfo
->key
, Phantom
);
1551 /***********************************************************************
1552 * SetupDiRemoveDevice (SETUPAPI.@)
1554 BOOL WINAPI
SetupDiRemoveDevice(
1556 PSP_DEVINFO_DATA info
)
1558 FIXME("(%p, %p): stub\n", devinfo
, info
);
1559 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1563 /***********************************************************************
1564 * SetupDiRemoveDeviceInterface (SETUPAPI.@)
1566 BOOL WINAPI
SetupDiRemoveDeviceInterface(HDEVINFO info
, PSP_DEVICE_INTERFACE_DATA data
)
1568 FIXME("(%p, %p): stub\n", info
, data
);
1569 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1573 /***********************************************************************
1574 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1576 BOOL WINAPI
SetupDiEnumDeviceInfo(
1579 PSP_DEVINFO_DATA info
)
1583 TRACE("%p %d %p\n", devinfo
, index
, info
);
1587 SetLastError(ERROR_INVALID_PARAMETER
);
1590 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
1592 struct DeviceInfoSet
*list
= devinfo
;
1593 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
1595 if (index
< list
->cDevices
)
1597 if (info
->cbSize
== sizeof(SP_DEVINFO_DATA
))
1599 struct DeviceInstance
*devInst
;
1602 LIST_FOR_EACH_ENTRY(devInst
, &list
->devices
,
1603 struct DeviceInstance
, entry
)
1607 *info
= devInst
->data
;
1614 SetLastError(ERROR_INVALID_USER_BUFFER
);
1617 SetLastError(ERROR_NO_MORE_ITEMS
);
1620 SetLastError(ERROR_INVALID_HANDLE
);
1623 SetLastError(ERROR_INVALID_HANDLE
);
1627 /***********************************************************************
1628 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1630 BOOL WINAPI
SetupDiGetDeviceInstanceIdA(
1631 HDEVINFO DeviceInfoSet
,
1632 PSP_DEVINFO_DATA DeviceInfoData
,
1633 PSTR DeviceInstanceId
,
1634 DWORD DeviceInstanceIdSize
,
1635 PDWORD RequiredSize
)
1641 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1642 DeviceInstanceIdSize
, RequiredSize
);
1644 SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1649 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1651 instanceId
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
1654 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1661 int len
= WideCharToMultiByte(CP_ACP
, 0, instanceId
, -1,
1663 DeviceInstanceIdSize
, NULL
, NULL
);
1669 if (len
> DeviceInstanceIdSize
)
1671 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1675 *RequiredSize
= len
;
1678 HeapFree(GetProcessHeap(), 0, instanceId
);
1683 /***********************************************************************
1684 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1686 BOOL WINAPI
SetupDiGetDeviceInstanceIdW(
1687 HDEVINFO DeviceInfoSet
,
1688 PSP_DEVINFO_DATA DeviceInfoData
,
1689 PWSTR DeviceInstanceId
,
1690 DWORD DeviceInstanceIdSize
,
1691 PDWORD RequiredSize
)
1693 struct DeviceInfoSet
*set
= DeviceInfoSet
;
1694 struct DeviceInfo
*devInfo
;
1696 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1697 DeviceInstanceIdSize
, RequiredSize
);
1699 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1701 SetLastError(ERROR_INVALID_HANDLE
);
1704 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1706 SetLastError(ERROR_INVALID_HANDLE
);
1709 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1710 || !DeviceInfoData
->Reserved
)
1712 SetLastError(ERROR_INVALID_PARAMETER
);
1715 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1716 if (devInfo
->set
!= set
)
1718 SetLastError(ERROR_INVALID_PARAMETER
);
1721 TRACE("instance ID: %s\n", debugstr_w(devInfo
->instanceId
));
1722 if (DeviceInstanceIdSize
< strlenW(devInfo
->instanceId
) + 1)
1724 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1726 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1729 lstrcpyW(DeviceInstanceId
, devInfo
->instanceId
);
1731 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1735 /***********************************************************************
1736 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1738 BOOL WINAPI
SetupDiGetActualSectionToInstallA(
1740 PCSTR InfSectionName
,
1741 PSTR InfSectionWithExt
,
1742 DWORD InfSectionWithExtSize
,
1743 PDWORD RequiredSize
,
1750 /***********************************************************************
1751 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
1753 BOOL WINAPI
SetupDiGetActualSectionToInstallW(
1755 PCWSTR InfSectionName
,
1756 PWSTR InfSectionWithExt
,
1757 DWORD InfSectionWithExtSize
,
1758 PDWORD RequiredSize
,
1761 WCHAR szBuffer
[MAX_PATH
];
1764 LONG lLineCount
= -1;
1766 lstrcpyW(szBuffer
, InfSectionName
);
1767 dwLength
= lstrlenW(szBuffer
);
1769 if (OsVersionInfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
1771 /* Test section name with '.NTx86' extension */
1772 lstrcpyW(&szBuffer
[dwLength
], NtPlatformExtension
);
1773 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1775 if (lLineCount
== -1)
1777 /* Test section name with '.NT' extension */
1778 lstrcpyW(&szBuffer
[dwLength
], NtExtension
);
1779 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1784 /* Test section name with '.Win' extension */
1785 lstrcpyW(&szBuffer
[dwLength
], WinExtension
);
1786 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1789 if (lLineCount
== -1)
1791 /* Test section name without extension */
1792 szBuffer
[dwLength
] = 0;
1793 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1796 if (lLineCount
== -1)
1798 SetLastError(ERROR_INVALID_PARAMETER
);
1802 dwFullLength
= lstrlenW(szBuffer
);
1804 if (InfSectionWithExt
!= NULL
&& InfSectionWithExtSize
!= 0)
1806 if (InfSectionWithExtSize
< (dwFullLength
+ 1))
1808 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1812 lstrcpyW(InfSectionWithExt
, szBuffer
);
1813 if (Extension
!= NULL
)
1815 *Extension
= (dwLength
== dwFullLength
) ? NULL
: &InfSectionWithExt
[dwLength
];
1819 if (RequiredSize
!= NULL
)
1821 *RequiredSize
= dwFullLength
+ 1;
1827 /***********************************************************************
1828 * SetupDiGetClassDescriptionA (SETUPAPI.@)
1830 BOOL WINAPI
SetupDiGetClassDescriptionA(
1831 const GUID
* ClassGuid
,
1832 PSTR ClassDescription
,
1833 DWORD ClassDescriptionSize
,
1834 PDWORD RequiredSize
)
1836 return SetupDiGetClassDescriptionExA(ClassGuid
, ClassDescription
,
1837 ClassDescriptionSize
,
1838 RequiredSize
, NULL
, NULL
);
1841 /***********************************************************************
1842 * SetupDiGetClassDescriptionW (SETUPAPI.@)
1844 BOOL WINAPI
SetupDiGetClassDescriptionW(
1845 const GUID
* ClassGuid
,
1846 PWSTR ClassDescription
,
1847 DWORD ClassDescriptionSize
,
1848 PDWORD RequiredSize
)
1850 return SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescription
,
1851 ClassDescriptionSize
,
1852 RequiredSize
, NULL
, NULL
);
1855 /***********************************************************************
1856 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
1858 BOOL WINAPI
SetupDiGetClassDescriptionExA(
1859 const GUID
* ClassGuid
,
1860 PSTR ClassDescription
,
1861 DWORD ClassDescriptionSize
,
1862 PDWORD RequiredSize
,
1870 hKey
= SetupDiOpenClassRegKeyExA(ClassGuid
,
1875 if (hKey
== INVALID_HANDLE_VALUE
)
1877 WARN("SetupDiOpenClassRegKeyExA() failed (Error %u)\n", GetLastError());
1881 dwLength
= ClassDescriptionSize
;
1882 ret
= !RegQueryValueExA( hKey
, NULL
, NULL
, NULL
,
1883 (LPBYTE
)ClassDescription
, &dwLength
);
1884 if (RequiredSize
) *RequiredSize
= dwLength
;
1889 /***********************************************************************
1890 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
1892 BOOL WINAPI
SetupDiGetClassDescriptionExW(
1893 const GUID
* ClassGuid
,
1894 PWSTR ClassDescription
,
1895 DWORD ClassDescriptionSize
,
1896 PDWORD RequiredSize
,
1904 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1909 if (hKey
== INVALID_HANDLE_VALUE
)
1911 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
1915 dwLength
= ClassDescriptionSize
* sizeof(WCHAR
);
1916 ret
= !RegQueryValueExW( hKey
, NULL
, NULL
, NULL
,
1917 (LPBYTE
)ClassDescription
, &dwLength
);
1918 if (RequiredSize
) *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1923 /***********************************************************************
1924 * SetupDiGetClassDevsA (SETUPAPI.@)
1926 HDEVINFO WINAPI
SetupDiGetClassDevsA(const GUID
*class, LPCSTR enumstr
, HWND parent
, DWORD flags
)
1929 LPWSTR enumstrW
= NULL
;
1933 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1934 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1937 ret
= INVALID_HANDLE_VALUE
;
1940 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1942 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, NULL
, NULL
,
1944 HeapFree(GetProcessHeap(), 0, enumstrW
);
1950 /***********************************************************************
1951 * SetupDiGetClassDevsExA (SETUPAPI.@)
1953 HDEVINFO WINAPI
SetupDiGetClassDevsExA(
1963 LPWSTR enumstrW
= NULL
, machineW
= NULL
;
1967 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1968 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1971 ret
= INVALID_HANDLE_VALUE
;
1974 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1978 int len
= MultiByteToWideChar(CP_ACP
, 0, machine
, -1, NULL
, 0);
1979 machineW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1982 HeapFree(GetProcessHeap(), 0, enumstrW
);
1983 ret
= INVALID_HANDLE_VALUE
;
1986 MultiByteToWideChar(CP_ACP
, 0, machine
, -1, machineW
, len
);
1988 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, deviceset
,
1989 machineW
, reserved
);
1990 HeapFree(GetProcessHeap(), 0, enumstrW
);
1991 HeapFree(GetProcessHeap(), 0, machineW
);
1997 static void SETUPDI_AddDeviceInterfaces(SP_DEVINFO_DATA
*dev
, HKEY key
,
2001 WCHAR subKeyName
[MAX_PATH
];
2002 LONG l
= ERROR_SUCCESS
;
2004 for (i
= 0; !l
; i
++)
2006 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2007 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2011 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
2013 if (*subKeyName
== '#')
2015 /* The subkey name is the reference string, with a '#' prepended */
2016 SETUPDI_AddInterfaceInstance(dev
, guid
, subKeyName
+ 1, &iface
);
2017 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2020 WCHAR symbolicLink
[MAX_PATH
];
2023 len
= sizeof(symbolicLink
);
2024 l
= RegQueryValueExW(subKey
, SymbolicLink
, NULL
, &dataType
,
2025 (BYTE
*)symbolicLink
, &len
);
2026 if (!l
&& dataType
== REG_SZ
)
2027 SETUPDI_SetInterfaceSymbolicLink(iface
, symbolicLink
);
2028 RegCloseKey(subKey
);
2031 /* Allow enumeration to continue */
2035 /* FIXME: find and add all the device's interfaces to the device */
2038 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet
,
2039 HKEY key
, const GUID
*guid
, LPCWSTR enumstr
)
2041 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2043 WCHAR subKeyName
[MAX_PATH
];
2045 HKEY enumKey
= INVALID_HANDLE_VALUE
;
2047 TRACE("%s\n", debugstr_w(enumstr
));
2049 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2051 for (i
= 0; !l
; i
++)
2053 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2054 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2059 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2062 WCHAR deviceInst
[MAX_PATH
* 3];
2065 len
= sizeof(deviceInst
);
2066 l
= RegQueryValueExW(subKey
, DeviceInstance
, NULL
, &dataType
,
2067 (BYTE
*)deviceInst
, &len
);
2068 if (!l
&& dataType
== REG_SZ
)
2070 TRACE("found instance ID %s\n", debugstr_w(deviceInst
));
2071 if (!enumstr
|| !lstrcmpiW(enumstr
, deviceInst
))
2075 l
= RegOpenKeyExW(enumKey
, deviceInst
, 0, KEY_READ
,
2079 WCHAR deviceClassStr
[40];
2081 len
= sizeof(deviceClassStr
);
2082 l
= RegQueryValueExW(deviceKey
, ClassGUID
, NULL
,
2083 &dataType
, (BYTE
*)deviceClassStr
, &len
);
2084 if (!l
&& dataType
== REG_SZ
&&
2085 deviceClassStr
[0] == '{' &&
2086 deviceClassStr
[37] == '}')
2089 SP_DEVINFO_DATA
*dev
;
2091 deviceClassStr
[37] = 0;
2092 UuidFromStringW(&deviceClassStr
[1],
2094 if (SETUPDI_AddDeviceToSet(set
, &deviceClass
,
2095 0 /* FIXME: DevInst */, deviceInst
,
2097 SETUPDI_AddDeviceInterfaces(dev
, subKey
, guid
);
2099 RegCloseKey(deviceKey
);
2103 RegCloseKey(subKey
);
2105 /* Allow enumeration to continue */
2109 if (enumKey
!= INVALID_HANDLE_VALUE
)
2110 RegCloseKey(enumKey
);
2113 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet
,
2114 const GUID
*guid
, LPCWSTR enumstr
, DWORD flags
)
2116 HKEY interfacesKey
= SetupDiOpenClassRegKeyExW(guid
, KEY_READ
,
2117 DIOCR_INTERFACE
, NULL
, NULL
);
2119 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(guid
),
2120 debugstr_w(enumstr
), flags
);
2122 if (interfacesKey
!= INVALID_HANDLE_VALUE
)
2124 if (flags
& DIGCF_ALLCLASSES
)
2127 WCHAR interfaceGuidStr
[40];
2128 LONG l
= ERROR_SUCCESS
;
2130 for (i
= 0; !l
; i
++)
2132 len
= sizeof(interfaceGuidStr
) / sizeof(interfaceGuidStr
[0]);
2133 l
= RegEnumKeyExW(interfacesKey
, i
, interfaceGuidStr
, &len
,
2134 NULL
, NULL
, NULL
, NULL
);
2137 if (interfaceGuidStr
[0] == '{' &&
2138 interfaceGuidStr
[37] == '}')
2143 interfaceGuidStr
[37] = 0;
2144 UuidFromStringW(&interfaceGuidStr
[1], &interfaceGuid
);
2145 interfaceGuidStr
[37] = '}';
2146 interfaceGuidStr
[38] = 0;
2147 l
= RegOpenKeyExW(interfacesKey
, interfaceGuidStr
, 0,
2148 KEY_READ
, &interfaceKey
);
2151 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2152 interfaceKey
, &interfaceGuid
, enumstr
);
2153 RegCloseKey(interfaceKey
);
2161 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2162 * interface's key, so just pass that long
2164 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2165 interfacesKey
, guid
, enumstr
);
2167 RegCloseKey(interfacesKey
);
2171 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet
*set
,
2172 LPCWSTR enumerator
, LPCWSTR deviceName
, HKEY deviceKey
,
2173 const GUID
*class, DWORD flags
)
2176 WCHAR deviceInstance
[MAX_PATH
];
2177 LONG l
= ERROR_SUCCESS
;
2179 TRACE("%s %s\n", debugstr_w(enumerator
), debugstr_w(deviceName
));
2181 for (i
= 0; !l
; i
++)
2183 len
= sizeof(deviceInstance
) / sizeof(deviceInstance
[0]);
2184 l
= RegEnumKeyExW(deviceKey
, i
, deviceInstance
, &len
, NULL
, NULL
, NULL
,
2190 l
= RegOpenKeyExW(deviceKey
, deviceInstance
, 0, KEY_READ
, &subKey
);
2193 WCHAR classGuid
[40];
2196 len
= sizeof(classGuid
);
2197 l
= RegQueryValueExW(subKey
, ClassGUID
, NULL
, &dataType
,
2198 (BYTE
*)classGuid
, &len
);
2199 if (!l
&& dataType
== REG_SZ
)
2201 if (classGuid
[0] == '{' && classGuid
[37] == '}')
2206 UuidFromStringW(&classGuid
[1], &deviceClass
);
2207 if ((flags
& DIGCF_ALLCLASSES
) ||
2208 IsEqualGUID(class, &deviceClass
))
2210 static const WCHAR fmt
[] =
2211 {'%','s','\\','%','s','\\','%','s',0};
2214 instanceId
= HeapAlloc(GetProcessHeap(), 0,
2215 (lstrlenW(enumerator
) + lstrlenW(deviceName
) +
2216 lstrlenW(deviceInstance
) + 3) * sizeof(WCHAR
));
2219 sprintfW(instanceId
, fmt
, enumerator
,
2220 deviceName
, deviceInstance
);
2221 SETUPDI_AddDeviceToSet(set
, &deviceClass
,
2222 0 /* FIXME: DevInst */, instanceId
,
2224 HeapFree(GetProcessHeap(), 0, instanceId
);
2229 RegCloseKey(subKey
);
2231 /* Allow enumeration to continue */
2237 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet
,
2238 LPCWSTR parent
, HKEY key
, const GUID
*class, DWORD flags
)
2240 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2242 WCHAR subKeyName
[MAX_PATH
];
2243 LONG l
= ERROR_SUCCESS
;
2245 TRACE("%s\n", debugstr_w(parent
));
2247 for (i
= 0; !l
; i
++)
2249 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2250 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2255 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2258 TRACE("%s\n", debugstr_w(subKeyName
));
2259 SETUPDI_EnumerateMatchingDeviceInstances(set
, parent
,
2260 subKeyName
, subKey
, class, flags
);
2261 RegCloseKey(subKey
);
2263 /* Allow enumeration to continue */
2269 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet
, const GUID
*class,
2270 LPCWSTR enumstr
, DWORD flags
)
2275 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(class),
2276 debugstr_w(enumstr
), flags
);
2278 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2280 if (enumKey
!= INVALID_HANDLE_VALUE
)
2286 l
= RegOpenKeyExW(enumKey
, enumstr
, 0, KEY_READ
,
2290 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
, enumstr
,
2291 enumStrKey
, class, flags
);
2292 RegCloseKey(enumStrKey
);
2298 WCHAR subKeyName
[MAX_PATH
];
2301 for (i
= 0; !l
; i
++)
2303 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2304 l
= RegEnumKeyExW(enumKey
, i
, subKeyName
, &len
, NULL
,
2310 l
= RegOpenKeyExW(enumKey
, subKeyName
, 0, KEY_READ
,
2314 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
,
2315 subKeyName
, subKey
, class, flags
);
2316 RegCloseKey(subKey
);
2318 /* Allow enumeration to continue */
2323 RegCloseKey(enumKey
);
2327 /***********************************************************************
2328 * SetupDiGetClassDevsW (SETUPAPI.@)
2330 HDEVINFO WINAPI
SetupDiGetClassDevsW(const GUID
*class, LPCWSTR enumstr
, HWND parent
, DWORD flags
)
2332 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2336 /***********************************************************************
2337 * SetupDiGetClassDevsExW (SETUPAPI.@)
2339 HDEVINFO WINAPI
SetupDiGetClassDevsExW(const GUID
*class, PCWSTR enumstr
, HWND parent
, DWORD flags
,
2340 HDEVINFO deviceset
, PCWSTR machine
, void *reserved
)
2342 static const DWORD unsupportedFlags
= DIGCF_DEFAULT
| DIGCF_PRESENT
|
2346 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2347 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2350 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2352 SetLastError(ERROR_INVALID_PARAMETER
);
2353 return INVALID_HANDLE_VALUE
;
2355 if (flags
& unsupportedFlags
)
2356 WARN("unsupported flags %08x\n", flags
& unsupportedFlags
);
2360 set
= SetupDiCreateDeviceInfoListExW(class, parent
, machine
, reserved
);
2361 if (set
!= INVALID_HANDLE_VALUE
)
2363 if (machine
&& *machine
)
2364 FIXME("%s: unimplemented for remote machines\n",
2365 debugstr_w(machine
));
2366 else if (flags
& DIGCF_DEVICEINTERFACE
)
2367 SETUPDI_EnumerateInterfaces(set
, class, enumstr
, flags
);
2369 SETUPDI_EnumerateDevices(set
, class, enumstr
, flags
);
2374 /***********************************************************************
2375 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2377 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2378 HDEVINFO DeviceInfoSet
,
2379 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2381 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2383 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2385 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2387 SetLastError(ERROR_INVALID_HANDLE
);
2390 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2392 SetLastError(ERROR_INVALID_HANDLE
);
2396 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2398 SetLastError(ERROR_INVALID_PARAMETER
);
2401 DevInfoData
->ClassGuid
= set
->ClassGuid
;
2402 DevInfoData
->RemoteMachineHandle
= NULL
;
2403 DevInfoData
->RemoteMachineName
[0] = '\0';
2407 /***********************************************************************
2408 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2410 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2411 HDEVINFO DeviceInfoSet
,
2412 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2414 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2416 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2418 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2420 SetLastError(ERROR_INVALID_HANDLE
);
2423 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2425 SetLastError(ERROR_INVALID_HANDLE
);
2429 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2431 SetLastError(ERROR_INVALID_PARAMETER
);
2434 DevInfoData
->ClassGuid
= set
->ClassGuid
;
2435 DevInfoData
->RemoteMachineHandle
= NULL
;
2436 DevInfoData
->RemoteMachineName
[0] = '\0';
2440 /***********************************************************************
2441 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2443 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2444 HDEVINFO DeviceInfoSet
,
2445 PSP_DEVINFO_DATA DeviceInfoData
,
2446 const GUID
*InterfaceClassGuid
,
2447 PCSTR ReferenceString
,
2448 DWORD CreationFlags
,
2449 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2452 LPWSTR ReferenceStringW
= NULL
;
2454 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2455 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2456 CreationFlags
, DeviceInterfaceData
);
2458 if (ReferenceString
)
2460 ReferenceStringW
= MultiByteToUnicode(ReferenceString
, CP_ACP
);
2461 if (ReferenceStringW
== NULL
) return FALSE
;
2464 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2465 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2466 DeviceInterfaceData
);
2468 MyFree(ReferenceStringW
);
2473 /***********************************************************************
2474 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2476 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2477 HDEVINFO DeviceInfoSet
,
2478 PSP_DEVINFO_DATA DeviceInfoData
,
2479 const GUID
*InterfaceClassGuid
,
2480 PCWSTR ReferenceString
,
2481 DWORD CreationFlags
,
2482 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2484 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2485 struct DeviceInfo
*devInfo
;
2486 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
2489 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2490 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2491 CreationFlags
, DeviceInterfaceData
);
2493 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2495 SetLastError(ERROR_INVALID_HANDLE
);
2498 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2500 SetLastError(ERROR_INVALID_HANDLE
);
2503 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2504 || !DeviceInfoData
->Reserved
)
2506 SetLastError(ERROR_INVALID_PARAMETER
);
2509 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2510 if (devInfo
->set
!= set
)
2512 SetLastError(ERROR_INVALID_PARAMETER
);
2515 if (!InterfaceClassGuid
)
2517 SetLastError(ERROR_INVALID_USER_BUFFER
);
2520 if ((ret
= SETUPDI_AddInterfaceInstance(DeviceInfoData
, InterfaceClassGuid
,
2521 ReferenceString
, &iface
)))
2523 if (DeviceInterfaceData
)
2525 if (DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2527 SetLastError(ERROR_INVALID_USER_BUFFER
);
2531 *DeviceInterfaceData
= *iface
;
2537 /***********************************************************************
2538 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2540 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2541 HDEVINFO DeviceInfoSet
,
2542 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2546 PCSTR InfSectionName
)
2549 PWSTR InfSectionNameW
= NULL
;
2551 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2552 samDesired
, InfHandle
, InfSectionName
);
2555 if (!InfSectionName
)
2557 SetLastError(ERROR_INVALID_PARAMETER
);
2558 return INVALID_HANDLE_VALUE
;
2560 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2561 if (!InfSectionNameW
)
2562 return INVALID_HANDLE_VALUE
;
2564 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2565 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2567 MyFree(InfSectionNameW
);
2571 static PWSTR
SETUPDI_GetInstancePath(struct InterfaceInfo
*ifaceInfo
)
2573 static const WCHAR hash
[] = {'#',0};
2574 PWSTR instancePath
= NULL
;
2576 if (ifaceInfo
->referenceString
)
2578 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2579 (lstrlenW(ifaceInfo
->referenceString
) + 2) * sizeof(WCHAR
));
2582 lstrcpyW(instancePath
, hash
);
2583 lstrcatW(instancePath
, ifaceInfo
->referenceString
);
2586 SetLastError(ERROR_OUTOFMEMORY
);
2590 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2591 (lstrlenW(hash
) + 1) * sizeof(WCHAR
));
2593 lstrcpyW(instancePath
, hash
);
2595 return instancePath
;
2598 /***********************************************************************
2599 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2601 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2602 HDEVINFO DeviceInfoSet
,
2603 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2607 PCWSTR InfSectionName
)
2609 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2610 HKEY key
= INVALID_HANDLE_VALUE
, interfacesKey
;
2613 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2614 samDesired
, InfHandle
, InfSectionName
);
2616 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2617 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2619 SetLastError(ERROR_INVALID_HANDLE
);
2620 return INVALID_HANDLE_VALUE
;
2622 if (!DeviceInterfaceData
||
2623 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2624 !DeviceInterfaceData
->Reserved
)
2626 SetLastError(ERROR_INVALID_PARAMETER
);
2627 return INVALID_HANDLE_VALUE
;
2629 if (InfHandle
&& !InfSectionName
)
2631 SetLastError(ERROR_INVALID_PARAMETER
);
2632 return INVALID_HANDLE_VALUE
;
2634 if (!(l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, DeviceClasses
, 0, NULL
, 0,
2635 samDesired
, NULL
, &interfacesKey
, NULL
)))
2638 WCHAR bracedGuidString
[39];
2640 SETUPDI_GuidToString(&DeviceInterfaceData
->InterfaceClassGuid
,
2642 if (!(l
= RegCreateKeyExW(interfacesKey
, bracedGuidString
, 0, NULL
, 0,
2643 samDesired
, NULL
, &parent
, NULL
)))
2645 struct InterfaceInfo
*ifaceInfo
=
2646 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2647 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2648 PWSTR interfKeyName
= HeapAlloc(GetProcessHeap(), 0,
2649 (lstrlenW(ifaceInfo
->symbolicLink
) + 1) * sizeof(WCHAR
));
2653 lstrcpyW(interfKeyName
, ifaceInfo
->symbolicLink
);
2654 if (lstrlenW(ifaceInfo
->symbolicLink
) > 3)
2656 interfKeyName
[0] = '#';
2657 interfKeyName
[1] = '#';
2658 interfKeyName
[3] = '#';
2660 ptr
= strchrW(interfKeyName
, '\\');
2663 l
= RegCreateKeyExW(parent
, interfKeyName
, 0, NULL
, 0,
2664 samDesired
, NULL
, &interfKey
, NULL
);
2667 struct DeviceInfo
*devInfo
=
2668 (struct DeviceInfo
*)ifaceInfo
->device
->Reserved
;
2670 l
= RegSetValueExW(interfKey
, DeviceInstance
, 0, REG_SZ
,
2671 (BYTE
*)devInfo
->instanceId
,
2672 (lstrlenW(devInfo
->instanceId
) + 1) * sizeof(WCHAR
));
2679 l
= RegCreateKeyExW(interfKey
, instancePath
, 0, NULL
, 0,
2680 samDesired
, NULL
, &key
, NULL
);
2684 key
= INVALID_HANDLE_VALUE
;
2687 FIXME("INF section installation unsupported\n");
2692 RegCloseKey(interfKey
);
2696 HeapFree(GetProcessHeap(), 0, interfKeyName
);
2697 HeapFree(GetProcessHeap(), 0, instancePath
);
2698 RegCloseKey(parent
);
2702 RegCloseKey(interfacesKey
);
2709 /***********************************************************************
2710 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2712 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2713 HDEVINFO DeviceInfoSet
,
2714 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2717 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2721 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2723 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2724 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2726 SetLastError(ERROR_INVALID_HANDLE
);
2729 if (!DeviceInterfaceData
||
2730 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2731 !DeviceInterfaceData
->Reserved
)
2733 SetLastError(ERROR_INVALID_PARAMETER
);
2736 parent
= SetupDiOpenClassRegKeyExW(&DeviceInterfaceData
->InterfaceClassGuid
,
2737 KEY_ALL_ACCESS
, DIOCR_INTERFACE
, NULL
, NULL
);
2738 if (parent
!= INVALID_HANDLE_VALUE
)
2740 struct InterfaceInfo
*ifaceInfo
=
2741 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2742 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2746 LONG l
= RegDeleteKeyW(parent
, instancePath
);
2752 HeapFree(GetProcessHeap(), 0, instancePath
);
2754 RegCloseKey(parent
);
2759 /***********************************************************************
2760 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2763 * DeviceInfoSet [I] Set of devices from which to enumerate
2765 * DeviceInfoData [I] (Optional) If specified, a specific device
2766 * instance from which to enumerate interfaces.
2767 * If it isn't specified, all interfaces for all
2768 * devices in the set are enumerated.
2769 * InterfaceClassGuid [I] The interface class to enumerate.
2770 * MemberIndex [I] An index of the interface instance to enumerate.
2771 * A caller should start with MemberIndex set to 0,
2772 * and continue until the function fails with
2773 * ERROR_NO_MORE_ITEMS.
2774 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2775 * member must be set to
2776 * sizeof(SP_DEVICE_INTERFACE_DATA).
2779 * Success: non-zero value.
2780 * Failure: FALSE. Call GetLastError() for more info.
2782 BOOL WINAPI
SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet
, PSP_DEVINFO_DATA DeviceInfoData
,
2783 const GUID
*InterfaceClassGuid
, DWORD MemberIndex
,
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
);
2811 /* In case application fails to check return value, clear output */
2812 memset(DeviceInterfaceData
, 0, sizeof(*DeviceInterfaceData
));
2813 DeviceInterfaceData
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DATA
);
2817 struct DeviceInfo
*devInfo
=
2818 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2819 struct InterfaceInstances
*iface
;
2821 if ((ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
2823 if (MemberIndex
< iface
->cInstances
)
2824 *DeviceInterfaceData
= iface
->instances
[MemberIndex
];
2827 SetLastError(ERROR_NO_MORE_ITEMS
);
2832 SetLastError(ERROR_NO_MORE_ITEMS
);
2836 struct DeviceInstance
*devInst
;
2837 DWORD cEnumerated
= 0;
2840 LIST_FOR_EACH_ENTRY(devInst
, &set
->devices
, struct DeviceInstance
, entry
)
2842 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)devInst
->data
.Reserved
;
2843 struct InterfaceInstances
*iface
;
2845 if (found
|| cEnumerated
>= MemberIndex
+ 1)
2847 if (SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
))
2849 if (cEnumerated
+ iface
->cInstances
< MemberIndex
+ 1)
2850 cEnumerated
+= iface
->cInstances
;
2853 DWORD instanceIndex
= MemberIndex
- cEnumerated
;
2855 *DeviceInterfaceData
= iface
->instances
[instanceIndex
];
2856 cEnumerated
+= instanceIndex
+ 1;
2863 SetLastError(ERROR_NO_MORE_ITEMS
);
2868 /***********************************************************************
2869 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2871 * Destroy a DeviceInfoList and free all used memory of the list.
2874 * devinfo [I] DeviceInfoList pointer to list to destroy
2877 * Success: non zero value.
2878 * Failure: zero value.
2880 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
2884 TRACE("%p\n", devinfo
);
2885 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
2887 struct DeviceInfoSet
*list
= devinfo
;
2889 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
2891 struct DeviceInstance
*devInst
, *devInst2
;
2893 LIST_FOR_EACH_ENTRY_SAFE(devInst
, devInst2
, &list
->devices
,
2894 struct DeviceInstance
, entry
)
2896 SETUPDI_FreeDeviceInfo( (struct DeviceInfo
*)devInst
->data
.Reserved
);
2897 list_remove(&devInst
->entry
);
2898 HeapFree(GetProcessHeap(), 0, devInst
);
2900 HeapFree(GetProcessHeap(), 0, list
);
2906 SetLastError(ERROR_INVALID_HANDLE
);
2911 /***********************************************************************
2912 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2914 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
2915 HDEVINFO DeviceInfoSet
,
2916 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2917 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
2918 DWORD DeviceInterfaceDetailDataSize
,
2919 PDWORD RequiredSize
,
2920 PSP_DEVINFO_DATA DeviceInfoData
)
2922 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2923 struct InterfaceInfo
*info
;
2924 DWORD bytesNeeded
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
[1]);
2927 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2928 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2929 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2931 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2932 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2934 SetLastError(ERROR_INVALID_HANDLE
);
2937 if (!DeviceInterfaceData
||
2938 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2939 !DeviceInterfaceData
->Reserved
)
2941 SetLastError(ERROR_INVALID_PARAMETER
);
2944 if (DeviceInterfaceDetailData
&&
2945 DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
))
2947 SetLastError(ERROR_INVALID_USER_BUFFER
);
2950 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2952 SetLastError(ERROR_INVALID_USER_BUFFER
);
2955 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2956 if (info
->symbolicLink
)
2957 bytesNeeded
+= WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2958 NULL
, 0, NULL
, NULL
);
2959 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2961 if (info
->symbolicLink
)
2962 WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2963 DeviceInterfaceDetailData
->DevicePath
,
2964 DeviceInterfaceDetailDataSize
-
2965 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
2968 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2969 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2970 *DeviceInfoData
= *info
->device
;
2976 *RequiredSize
= bytesNeeded
;
2977 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2982 /***********************************************************************
2983 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2985 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
2986 HDEVINFO DeviceInfoSet
,
2987 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2988 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
2989 DWORD DeviceInterfaceDetailDataSize
,
2990 PDWORD RequiredSize
,
2991 PSP_DEVINFO_DATA DeviceInfoData
)
2993 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2994 struct InterfaceInfo
*info
;
2995 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
2996 + sizeof(WCHAR
); /* include NULL terminator */
2999 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
3000 DeviceInterfaceData
, DeviceInterfaceDetailData
,
3001 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
3003 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
3004 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3006 SetLastError(ERROR_INVALID_HANDLE
);
3009 if (!DeviceInterfaceData
||
3010 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
3011 !DeviceInterfaceData
->Reserved
)
3013 SetLastError(ERROR_INVALID_PARAMETER
);
3016 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
3017 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
) ||
3018 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
)))
3020 SetLastError(ERROR_INVALID_USER_BUFFER
);
3023 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
3025 SetLastError(ERROR_INVALID_USER_BUFFER
);
3028 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
3029 if (info
->symbolicLink
)
3030 bytesNeeded
+= sizeof(WCHAR
)*lstrlenW(info
->symbolicLink
);
3031 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
3033 if (info
->symbolicLink
)
3034 lstrcpyW(DeviceInterfaceDetailData
->DevicePath
, info
->symbolicLink
);
3036 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
3037 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
3038 *DeviceInfoData
= *info
->device
;
3044 *RequiredSize
= bytesNeeded
;
3045 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3050 struct PropertyMapEntry
3057 static const struct PropertyMapEntry PropertyMap
[] = {
3058 { REG_SZ
, "DeviceDesc", DeviceDesc
},
3059 { REG_MULTI_SZ
, "HardwareId", HardwareId
},
3060 { REG_MULTI_SZ
, "CompatibleIDs", CompatibleIDs
},
3061 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
3062 { REG_SZ
, "Service", Service
},
3063 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
3064 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
3065 { REG_SZ
, "Class", Class
},
3066 { REG_SZ
, "ClassGUID", ClassGUID
},
3067 { REG_SZ
, "Driver", Driver
},
3068 { REG_DWORD
, "ConfigFlags", ConfigFlags
},
3069 { REG_SZ
, "Mfg", Mfg
},
3070 { REG_SZ
, "FriendlyName", FriendlyName
},
3071 { REG_SZ
, "LocationInformation", LocationInformation
},
3072 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3073 { REG_DWORD
, "Capabilities", Capabilities
},
3074 { REG_DWORD
, "UINumber", UINumber
},
3075 { REG_MULTI_SZ
, "UpperFilters", UpperFilters
},
3076 { REG_MULTI_SZ
, "LowerFilters", LowerFilters
},
3079 /***********************************************************************
3080 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3082 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
3083 HDEVINFO DeviceInfoSet
,
3084 PSP_DEVINFO_DATA DeviceInfoData
,
3086 PDWORD PropertyRegDataType
,
3087 PBYTE PropertyBuffer
,
3088 DWORD PropertyBufferSize
,
3089 PDWORD RequiredSize
)
3092 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3093 struct DeviceInfo
*devInfo
;
3095 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3096 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3099 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3101 SetLastError(ERROR_INVALID_HANDLE
);
3104 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3106 SetLastError(ERROR_INVALID_HANDLE
);
3109 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3110 || !DeviceInfoData
->Reserved
)
3112 SetLastError(ERROR_INVALID_PARAMETER
);
3115 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
3117 SetLastError(ERROR_INVALID_DATA
);
3120 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3121 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3122 && PropertyMap
[Property
].nameA
)
3124 DWORD size
= PropertyBufferSize
;
3125 LONG l
= RegQueryValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
,
3126 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3128 if (l
== ERROR_FILE_NOT_FOUND
)
3129 SetLastError(ERROR_INVALID_DATA
);
3130 else if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3131 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3137 *RequiredSize
= size
;
3142 /***********************************************************************
3143 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3145 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3146 HDEVINFO DeviceInfoSet
,
3147 PSP_DEVINFO_DATA DeviceInfoData
,
3149 PDWORD PropertyRegDataType
,
3150 PBYTE PropertyBuffer
,
3151 DWORD PropertyBufferSize
,
3152 PDWORD RequiredSize
)
3155 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3156 struct DeviceInfo
*devInfo
;
3158 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3159 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3162 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3164 SetLastError(ERROR_INVALID_HANDLE
);
3167 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3169 SetLastError(ERROR_INVALID_HANDLE
);
3172 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3173 || !DeviceInfoData
->Reserved
)
3175 SetLastError(ERROR_INVALID_PARAMETER
);
3178 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
3180 SetLastError(ERROR_INVALID_DATA
);
3183 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3184 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3185 && PropertyMap
[Property
].nameW
)
3187 DWORD size
= PropertyBufferSize
;
3188 LONG l
= RegQueryValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
,
3189 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3191 if (l
== ERROR_FILE_NOT_FOUND
)
3192 SetLastError(ERROR_INVALID_DATA
);
3193 else if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3194 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3200 *RequiredSize
= size
;
3205 /***********************************************************************
3206 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3208 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3209 HDEVINFO DeviceInfoSet
,
3210 PSP_DEVINFO_DATA DeviceInfoData
,
3212 const BYTE
*PropertyBuffer
,
3213 DWORD PropertyBufferSize
)
3216 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3217 struct DeviceInfo
*devInfo
;
3219 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3220 PropertyBuffer
, PropertyBufferSize
);
3222 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3224 SetLastError(ERROR_INVALID_HANDLE
);
3227 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3229 SetLastError(ERROR_INVALID_HANDLE
);
3232 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3233 || !DeviceInfoData
->Reserved
)
3235 SetLastError(ERROR_INVALID_PARAMETER
);
3238 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3239 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3240 && PropertyMap
[Property
].nameA
)
3242 LONG l
= RegSetValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
, 0,
3243 PropertyMap
[Property
].regType
, PropertyBuffer
,
3244 PropertyBufferSize
);
3253 /***********************************************************************
3254 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3256 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
3257 HDEVINFO DeviceInfoSet
,
3258 PSP_DEVINFO_DATA DeviceInfoData
,
3260 const BYTE
*PropertyBuffer
,
3261 DWORD PropertyBufferSize
)
3264 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3265 struct DeviceInfo
*devInfo
;
3267 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3268 PropertyBuffer
, PropertyBufferSize
);
3270 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3272 SetLastError(ERROR_INVALID_HANDLE
);
3275 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3277 SetLastError(ERROR_INVALID_HANDLE
);
3280 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3281 || !DeviceInfoData
->Reserved
)
3283 SetLastError(ERROR_INVALID_PARAMETER
);
3286 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3287 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3288 && PropertyMap
[Property
].nameW
)
3290 LONG l
= RegSetValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
, 0,
3291 PropertyMap
[Property
].regType
, PropertyBuffer
,
3292 PropertyBufferSize
);
3301 /***********************************************************************
3302 * SetupDiInstallClassA (SETUPAPI.@)
3304 BOOL WINAPI
SetupDiInstallClassA(
3310 UNICODE_STRING FileNameW
;
3315 SetLastError(ERROR_INVALID_PARAMETER
);
3318 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW
, InfFileName
))
3320 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3324 Result
= SetupDiInstallClassW(hwndParent
, FileNameW
.Buffer
, Flags
, FileQueue
);
3326 RtlFreeUnicodeString(&FileNameW
);
3331 static HKEY
CreateClassKey(HINF hInf
)
3333 static const WCHAR slash
[] = { '\\',0 };
3334 WCHAR FullBuffer
[MAX_PATH
];
3335 WCHAR Buffer
[MAX_PATH
];
3339 if (!SetupGetLineTextW(NULL
,
3347 return INVALID_HANDLE_VALUE
;
3350 lstrcpyW(FullBuffer
, ControlClass
);
3351 lstrcatW(FullBuffer
, slash
);
3352 lstrcatW(FullBuffer
, Buffer
);
3354 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3360 if (!SetupGetLineTextW(NULL
,
3368 return INVALID_HANDLE_VALUE
;
3371 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3375 REG_OPTION_NON_VOLATILE
,
3381 return INVALID_HANDLE_VALUE
;
3386 if (RegSetValueExW(hClassKey
,
3391 RequiredSize
* sizeof(WCHAR
)))
3393 RegCloseKey(hClassKey
);
3394 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3396 return INVALID_HANDLE_VALUE
;
3402 /***********************************************************************
3403 * SetupDiInstallClassW (SETUPAPI.@)
3405 BOOL WINAPI
SetupDiInstallClassW(
3411 WCHAR SectionName
[MAX_PATH
];
3412 DWORD SectionNameLength
= 0;
3414 BOOL bFileQueueCreated
= FALSE
;
3422 SetLastError(ERROR_INVALID_PARAMETER
);
3425 if ((Flags
& DI_NOVCP
) && (FileQueue
== NULL
|| FileQueue
== INVALID_HANDLE_VALUE
))
3427 SetLastError(ERROR_INVALID_PARAMETER
);
3431 /* Open the .inf file */
3432 hInf
= SetupOpenInfFileW(InfFileName
,
3436 if (hInf
== INVALID_HANDLE_VALUE
)
3442 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3443 hClassKey
= CreateClassKey(hInf
);
3444 if (hClassKey
== INVALID_HANDLE_VALUE
)
3446 SetupCloseInfFile(hInf
);
3451 /* Try to append a layout file */
3452 SetupOpenAppendInfFileW(NULL
, hInf
, NULL
);
3454 /* Retrieve the actual section name */
3455 SetupDiGetActualSectionToInstallW(hInf
,
3463 if (!(Flags
& DI_NOVCP
))
3465 FileQueue
= SetupOpenFileQueue();
3466 if (FileQueue
== INVALID_HANDLE_VALUE
)
3468 SetupCloseInfFile(hInf
);
3472 bFileQueueCreated
= TRUE
;
3477 SetupInstallFromInfSectionW(NULL
,
3480 SPINST_COPYINF
| SPINST_FILES
| SPINST_REGISTRY
,
3486 INVALID_HANDLE_VALUE
,
3489 /* FIXME: More code! */
3491 if (bFileQueueCreated
)
3492 SetupCloseFileQueue(FileQueue
);
3494 SetupCloseInfFile(hInf
);
3500 /***********************************************************************
3501 * SetupDiOpenClassRegKey (SETUPAPI.@)
3503 HKEY WINAPI
SetupDiOpenClassRegKey(
3504 const GUID
* ClassGuid
,
3507 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3508 DIOCR_INSTALLER
, NULL
, NULL
);
3512 /***********************************************************************
3513 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3515 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3516 const GUID
* ClassGuid
,
3522 PWSTR MachineNameW
= NULL
;
3529 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
3530 if (MachineNameW
== NULL
)
3531 return INVALID_HANDLE_VALUE
;
3534 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3535 Flags
, MachineNameW
, Reserved
);
3537 MyFree(MachineNameW
);
3543 /***********************************************************************
3544 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3546 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3547 const GUID
* ClassGuid
,
3558 if (MachineName
&& *MachineName
)
3560 FIXME("Remote access not supported yet!\n");
3561 return INVALID_HANDLE_VALUE
;
3564 if (Flags
== DIOCR_INSTALLER
)
3566 lpKeyName
= ControlClass
;
3568 else if (Flags
== DIOCR_INTERFACE
)
3570 lpKeyName
= DeviceClasses
;
3574 ERR("Invalid Flags parameter!\n");
3575 SetLastError(ERROR_INVALID_PARAMETER
);
3576 return INVALID_HANDLE_VALUE
;
3581 if ((l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3588 hClassesKey
= INVALID_HANDLE_VALUE
;
3594 WCHAR bracedGuidString
[39];
3596 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3598 if (!(l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3604 if ((l
= RegOpenKeyExW(hClassesKey
,
3611 key
= INVALID_HANDLE_VALUE
;
3613 RegCloseKey(hClassesKey
);
3618 key
= INVALID_HANDLE_VALUE
;
3624 /***********************************************************************
3625 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3627 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3628 HDEVINFO DeviceInfoSet
,
3631 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3633 FIXME("%p %s %08x %p\n",
3634 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3638 /***********************************************************************
3639 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3641 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
3642 HDEVINFO DeviceInfoSet
,
3645 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3647 FIXME("%p %s %08x %p\n", DeviceInfoSet
,
3648 debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3652 /***********************************************************************
3653 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3655 BOOL WINAPI
SetupDiSetClassInstallParamsA(
3656 HDEVINFO DeviceInfoSet
,
3657 PSP_DEVINFO_DATA DeviceInfoData
,
3658 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3659 DWORD ClassInstallParamsSize
)
3661 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3662 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3666 /***********************************************************************
3667 * SetupDiSetClassInstallParamsW (SETUPAPI.@)
3669 BOOL WINAPI
SetupDiSetClassInstallParamsW(
3670 HDEVINFO DeviceInfoSet
,
3671 PSP_DEVINFO_DATA DeviceInfoData
,
3672 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3673 DWORD ClassInstallParamsSize
)
3675 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3676 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3680 /***********************************************************************
3681 * SetupDiCallClassInstaller (SETUPAPI.@)
3683 BOOL WINAPI
SetupDiCallClassInstaller(
3684 DI_FUNCTION InstallFunction
,
3685 HDEVINFO DeviceInfoSet
,
3686 PSP_DEVINFO_DATA DeviceInfoData
)
3688 FIXME("%d %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3692 /***********************************************************************
3693 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
3695 BOOL WINAPI
SetupDiGetDeviceInstallParamsW(
3696 HDEVINFO DeviceInfoSet
,
3697 PSP_DEVINFO_DATA DeviceInfoData
,
3698 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
3700 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3704 /***********************************************************************
3705 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3707 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
3708 HDEVINFO DeviceInfoSet
,
3709 PSP_DEVINFO_DATA DeviceInfoData
,
3710 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3712 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3716 /***********************************************************************
3717 * SetupDiSetDeviceInstallParamsA (SETUPAPI.@)
3719 BOOL WINAPI
SetupDiSetDeviceInstallParamsA(
3720 HDEVINFO DeviceInfoSet
,
3721 PSP_DEVINFO_DATA DeviceInfoData
,
3722 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3724 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3729 /***********************************************************************
3730 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
3732 BOOL WINAPI
SetupDiSetDeviceInstallParamsW(
3733 HDEVINFO DeviceInfoSet
,
3734 PSP_DEVINFO_DATA DeviceInfoData
,
3735 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
3737 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3742 static HKEY
SETUPDI_OpenDevKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3744 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
3747 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3748 NULL
, &enumKey
, NULL
);
3751 RegOpenKeyExW(enumKey
, devInfo
->instanceId
, 0, samDesired
, &key
);
3752 RegCloseKey(enumKey
);
3757 static HKEY
SETUPDI_OpenDrvKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3759 static const WCHAR slash
[] = { '\\',0 };
3760 WCHAR classKeyPath
[MAX_PATH
];
3761 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
3764 lstrcpyW(classKeyPath
, ControlClass
);
3765 lstrcatW(classKeyPath
, slash
);
3766 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3767 classKeyPath
+ lstrlenW(classKeyPath
));
3768 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3769 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3772 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3775 sprintfW(devId
, fmt
, devInfo
->devId
);
3776 l
= RegOpenKeyExW(classKey
, devId
, 0, samDesired
, &key
);
3777 RegCloseKey(classKey
);
3780 SetLastError(ERROR_KEY_DOES_NOT_EXIST
);
3781 return INVALID_HANDLE_VALUE
;
3787 /***********************************************************************
3788 * SetupDiOpenDevRegKey (SETUPAPI.@)
3790 HKEY WINAPI
SetupDiOpenDevRegKey(
3791 HDEVINFO DeviceInfoSet
,
3792 PSP_DEVINFO_DATA DeviceInfoData
,
3798 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3799 struct DeviceInfo
*devInfo
;
3800 HKEY key
= INVALID_HANDLE_VALUE
;
3802 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
3803 Scope
, HwProfile
, KeyType
, samDesired
);
3805 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3807 SetLastError(ERROR_INVALID_HANDLE
);
3808 return INVALID_HANDLE_VALUE
;
3810 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3812 SetLastError(ERROR_INVALID_HANDLE
);
3813 return INVALID_HANDLE_VALUE
;
3815 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3816 || !DeviceInfoData
->Reserved
)
3818 SetLastError(ERROR_INVALID_PARAMETER
);
3819 return INVALID_HANDLE_VALUE
;
3821 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3823 SetLastError(ERROR_INVALID_FLAGS
);
3824 return INVALID_HANDLE_VALUE
;
3826 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
3828 SetLastError(ERROR_INVALID_FLAGS
);
3829 return INVALID_HANDLE_VALUE
;
3831 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3832 if (devInfo
->set
!= set
)
3834 SetLastError(ERROR_INVALID_PARAMETER
);
3835 return INVALID_HANDLE_VALUE
;
3837 if (devInfo
->phantom
)
3839 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3840 return INVALID_HANDLE_VALUE
;
3842 if (Scope
!= DICS_FLAG_GLOBAL
)
3843 FIXME("unimplemented for scope %d\n", Scope
);
3847 key
= SETUPDI_OpenDevKey(devInfo
, samDesired
);
3850 key
= SETUPDI_OpenDrvKey(devInfo
, samDesired
);
3853 WARN("unknown KeyType %d\n", KeyType
);
3858 static BOOL
SETUPDI_DeleteDevKey(struct DeviceInfo
*devInfo
)
3864 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3865 NULL
, &enumKey
, NULL
);
3868 ret
= RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
3869 RegCloseKey(enumKey
);
3876 static BOOL
SETUPDI_DeleteDrvKey(struct DeviceInfo
*devInfo
)
3878 static const WCHAR slash
[] = { '\\',0 };
3879 WCHAR classKeyPath
[MAX_PATH
];
3884 lstrcpyW(classKeyPath
, ControlClass
);
3885 lstrcatW(classKeyPath
, slash
);
3886 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3887 classKeyPath
+ lstrlenW(classKeyPath
));
3888 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3889 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3892 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3895 sprintfW(devId
, fmt
, devInfo
->devId
);
3896 ret
= RegDeleteTreeW(classKey
, devId
);
3897 RegCloseKey(classKey
);
3904 /***********************************************************************
3905 * SetupDiDeleteDevRegKey (SETUPAPI.@)
3907 BOOL WINAPI
SetupDiDeleteDevRegKey(
3908 HDEVINFO DeviceInfoSet
,
3909 PSP_DEVINFO_DATA DeviceInfoData
,
3914 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3915 struct DeviceInfo
*devInfo
;
3918 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
3921 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3923 SetLastError(ERROR_INVALID_HANDLE
);
3926 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3928 SetLastError(ERROR_INVALID_HANDLE
);
3931 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3932 || !DeviceInfoData
->Reserved
)
3934 SetLastError(ERROR_INVALID_PARAMETER
);
3937 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3939 SetLastError(ERROR_INVALID_FLAGS
);
3942 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
3944 SetLastError(ERROR_INVALID_FLAGS
);
3947 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3948 if (devInfo
->set
!= set
)
3950 SetLastError(ERROR_INVALID_PARAMETER
);
3953 if (devInfo
->phantom
)
3955 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3958 if (Scope
!= DICS_FLAG_GLOBAL
)
3959 FIXME("unimplemented for scope %d\n", Scope
);
3963 ret
= SETUPDI_DeleteDevKey(devInfo
);
3966 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3969 ret
= SETUPDI_DeleteDevKey(devInfo
);
3971 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3974 WARN("unknown KeyType %d\n", KeyType
);
3979 /***********************************************************************
3980 * CM_Get_Device_IDA (SETUPAPI.@)
3982 CONFIGRET WINAPI
CM_Get_Device_IDA( DEVINST dnDevInst
, PSTR Buffer
,
3983 ULONG BufferLen
, ULONG ulFlags
)
3985 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
3987 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
3990 return CR_NO_SUCH_DEVINST
;
3992 WideCharToMultiByte(CP_ACP
, 0, devInfo
->instanceId
, -1, Buffer
, BufferLen
, 0, 0);
3993 TRACE("Returning %s\n", debugstr_a(Buffer
));
3997 /***********************************************************************
3998 * CM_Get_Device_IDW (SETUPAPI.@)
4000 CONFIGRET WINAPI
CM_Get_Device_IDW( DEVINST dnDevInst
, LPWSTR Buffer
,
4001 ULONG BufferLen
, ULONG ulFlags
)
4003 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
4005 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
4009 WARN("dev instance %d not found!\n", dnDevInst
);
4010 return CR_NO_SUCH_DEVINST
;
4013 lstrcpynW(Buffer
, devInfo
->instanceId
, BufferLen
);
4014 TRACE("Returning %s\n", debugstr_w(Buffer
));
4015 GlobalUnlock((HANDLE
)dnDevInst
);
4021 /***********************************************************************
4022 * CM_Get_Device_ID_Size (SETUPAPI.@)
4024 CONFIGRET WINAPI
CM_Get_Device_ID_Size( PULONG pulLen
, DEVINST dnDevInst
,
4027 struct DeviceInfo
*ppdevInfo
= GlobalLock((HANDLE
)dnDevInst
);
4029 TRACE("%x->%p, %p, %u\n", dnDevInst
, ppdevInfo
, pulLen
, ulFlags
);
4033 WARN("dev instance %d not found!\n", dnDevInst
);
4034 return CR_NO_SUCH_DEVINST
;
4037 *pulLen
= lstrlenW(ppdevInfo
->instanceId
);
4038 GlobalUnlock((HANDLE
)dnDevInst
);
4042 /***********************************************************************
4043 * SetupDiGetINFClassA (SETUPAPI.@)
4045 BOOL WINAPI
SetupDiGetINFClassA(PCSTR inf
, LPGUID class_guid
, PSTR class_name
,
4046 DWORD size
, PDWORD required_size
)
4049 DWORD required_sizeA
, required_sizeW
;
4050 PWSTR class_nameW
= NULL
;
4051 UNICODE_STRING infW
;
4055 if (!RtlCreateUnicodeStringFromAsciiz(&infW
, inf
))
4057 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4064 if (class_name
&& size
)
4066 if (!(class_nameW
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
))))
4068 RtlFreeUnicodeString(&infW
);
4069 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4074 retval
= SetupDiGetINFClassW(infW
.Buffer
, class_guid
, class_nameW
, size
, &required_sizeW
);
4078 required_sizeA
= WideCharToMultiByte( CP_ACP
, 0, class_nameW
, required_sizeW
,
4079 class_name
, size
, NULL
, NULL
);
4081 if(required_size
) *required_size
= required_sizeA
;
4084 if(required_size
) *required_size
= required_sizeW
;
4086 HeapFree(GetProcessHeap(), 0, class_nameW
);
4087 RtlFreeUnicodeString(&infW
);
4091 /***********************************************************************
4092 * SetupDiGetINFClassW (SETUPAPI.@)
4094 BOOL WINAPI
SetupDiGetINFClassW(PCWSTR inf
, LPGUID class_guid
, PWSTR class_name
,
4095 DWORD size
, PDWORD required_size
)
4097 BOOL have_guid
, have_name
;
4099 WCHAR buffer
[MAX_PATH
];
4103 SetLastError(ERROR_INVALID_PARAMETER
);
4107 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(inf
))
4109 FIXME("%s not found. Searching via DevicePath not implemented\n", debugstr_w(inf
));
4110 SetLastError(ERROR_FILE_NOT_FOUND
);
4114 if (!class_guid
|| !class_name
|| !size
)
4116 SetLastError(ERROR_INVALID_PARAMETER
);
4120 if (!GetPrivateProfileStringW(Version
, Signature
, NULL
, buffer
, MAX_PATH
, inf
))
4123 if (lstrcmpiW(buffer
, Chicago
) && lstrcmpiW(buffer
, WindowsNT
))
4127 have_guid
= 0 < GetPrivateProfileStringW(Version
, ClassGUID
, NULL
, buffer
, MAX_PATH
, inf
);
4130 buffer
[lstrlenW(buffer
)-1] = 0;
4131 if (RPC_S_OK
!= UuidFromStringW(buffer
+ 1, class_guid
))
4133 FIXME("failed to convert \"%s\" into a guid\n", debugstr_w(buffer
));
4134 SetLastError(ERROR_INVALID_PARAMETER
);
4140 dret
= GetPrivateProfileStringW(Version
, Class
, NULL
, buffer
, MAX_PATH
, inf
);
4141 have_name
= 0 < dret
;
4143 if (dret
>= MAX_PATH
-1) FIXME("buffer might be too small\n");
4144 if (have_guid
&& !have_name
) FIXME("class name lookup via guid not implemented\n");
4148 if (dret
< size
) lstrcpyW(class_name
, buffer
);
4151 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4156 if (required_size
) *required_size
= dret
+ ((dret
) ? 1 : 0);
4158 return (have_guid
|| have_name
);
4161 /***********************************************************************
4162 * SetupDiGetDevicePropertyW (SETUPAPI.@)
4164 BOOL WINAPI
SetupDiGetDevicePropertyW(HDEVINFO info_set
, PSP_DEVINFO_DATA info_data
,
4165 const DEVPROPKEY
*prop_key
, DEVPROPTYPE
*prop_type
, BYTE
*prop_buff
,
4166 DWORD prop_buff_size
, DWORD
*required_size
, DWORD flags
)
4168 FIXME("%p, %p, %p, %p, %p, %d, %p, 0x%08x stub\n", info_set
, info_data
, prop_key
,
4169 prop_type
, prop_buff
, prop_buff_size
, required_size
, flags
);
4171 SetLastError(ERROR_NOT_FOUND
);