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
++)
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
= 256 * sizeof(WCHAR
);
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_MORE_DATA
|| !PropertyBufferSize
)
3129 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3135 *RequiredSize
= size
;
3140 /***********************************************************************
3141 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3143 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3144 HDEVINFO DeviceInfoSet
,
3145 PSP_DEVINFO_DATA DeviceInfoData
,
3147 PDWORD PropertyRegDataType
,
3148 PBYTE PropertyBuffer
,
3149 DWORD PropertyBufferSize
,
3150 PDWORD RequiredSize
)
3153 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3154 struct DeviceInfo
*devInfo
;
3156 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3157 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3160 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3162 SetLastError(ERROR_INVALID_HANDLE
);
3165 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3167 SetLastError(ERROR_INVALID_HANDLE
);
3170 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3171 || !DeviceInfoData
->Reserved
)
3173 SetLastError(ERROR_INVALID_PARAMETER
);
3176 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
3178 SetLastError(ERROR_INVALID_DATA
);
3181 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3182 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3183 && PropertyMap
[Property
].nameW
)
3185 DWORD size
= PropertyBufferSize
;
3186 LONG l
= RegQueryValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
,
3187 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3189 if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3190 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3196 *RequiredSize
= size
;
3201 /***********************************************************************
3202 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3204 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3205 HDEVINFO DeviceInfoSet
,
3206 PSP_DEVINFO_DATA DeviceInfoData
,
3208 const BYTE
*PropertyBuffer
,
3209 DWORD PropertyBufferSize
)
3212 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3213 struct DeviceInfo
*devInfo
;
3215 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3216 PropertyBuffer
, PropertyBufferSize
);
3218 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3220 SetLastError(ERROR_INVALID_HANDLE
);
3223 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3225 SetLastError(ERROR_INVALID_HANDLE
);
3228 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3229 || !DeviceInfoData
->Reserved
)
3231 SetLastError(ERROR_INVALID_PARAMETER
);
3234 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3235 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3236 && PropertyMap
[Property
].nameA
)
3238 LONG l
= RegSetValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
, 0,
3239 PropertyMap
[Property
].regType
, PropertyBuffer
,
3240 PropertyBufferSize
);
3249 /***********************************************************************
3250 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3252 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
3253 HDEVINFO DeviceInfoSet
,
3254 PSP_DEVINFO_DATA DeviceInfoData
,
3256 const BYTE
*PropertyBuffer
,
3257 DWORD PropertyBufferSize
)
3260 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3261 struct DeviceInfo
*devInfo
;
3263 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3264 PropertyBuffer
, PropertyBufferSize
);
3266 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3268 SetLastError(ERROR_INVALID_HANDLE
);
3271 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3273 SetLastError(ERROR_INVALID_HANDLE
);
3276 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3277 || !DeviceInfoData
->Reserved
)
3279 SetLastError(ERROR_INVALID_PARAMETER
);
3282 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3283 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3284 && PropertyMap
[Property
].nameW
)
3286 LONG l
= RegSetValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
, 0,
3287 PropertyMap
[Property
].regType
, PropertyBuffer
,
3288 PropertyBufferSize
);
3297 /***********************************************************************
3298 * SetupDiInstallClassA (SETUPAPI.@)
3300 BOOL WINAPI
SetupDiInstallClassA(
3306 UNICODE_STRING FileNameW
;
3311 SetLastError(ERROR_INVALID_PARAMETER
);
3314 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW
, InfFileName
))
3316 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3320 Result
= SetupDiInstallClassW(hwndParent
, FileNameW
.Buffer
, Flags
, FileQueue
);
3322 RtlFreeUnicodeString(&FileNameW
);
3327 static HKEY
CreateClassKey(HINF hInf
)
3329 static const WCHAR slash
[] = { '\\',0 };
3330 WCHAR FullBuffer
[MAX_PATH
];
3331 WCHAR Buffer
[MAX_PATH
];
3335 if (!SetupGetLineTextW(NULL
,
3343 return INVALID_HANDLE_VALUE
;
3346 lstrcpyW(FullBuffer
, ControlClass
);
3347 lstrcatW(FullBuffer
, slash
);
3348 lstrcatW(FullBuffer
, Buffer
);
3350 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3356 if (!SetupGetLineTextW(NULL
,
3364 return INVALID_HANDLE_VALUE
;
3367 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3371 REG_OPTION_NON_VOLATILE
,
3377 return INVALID_HANDLE_VALUE
;
3382 if (RegSetValueExW(hClassKey
,
3387 RequiredSize
* sizeof(WCHAR
)))
3389 RegCloseKey(hClassKey
);
3390 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3392 return INVALID_HANDLE_VALUE
;
3398 /***********************************************************************
3399 * SetupDiInstallClassW (SETUPAPI.@)
3401 BOOL WINAPI
SetupDiInstallClassW(
3407 WCHAR SectionName
[MAX_PATH
];
3408 DWORD SectionNameLength
= 0;
3410 BOOL bFileQueueCreated
= FALSE
;
3418 SetLastError(ERROR_INVALID_PARAMETER
);
3421 if ((Flags
& DI_NOVCP
) && (FileQueue
== NULL
|| FileQueue
== INVALID_HANDLE_VALUE
))
3423 SetLastError(ERROR_INVALID_PARAMETER
);
3427 /* Open the .inf file */
3428 hInf
= SetupOpenInfFileW(InfFileName
,
3432 if (hInf
== INVALID_HANDLE_VALUE
)
3438 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3439 hClassKey
= CreateClassKey(hInf
);
3440 if (hClassKey
== INVALID_HANDLE_VALUE
)
3442 SetupCloseInfFile(hInf
);
3447 /* Try to append a layout file */
3448 SetupOpenAppendInfFileW(NULL
, hInf
, NULL
);
3450 /* Retrieve the actual section name */
3451 SetupDiGetActualSectionToInstallW(hInf
,
3459 if (!(Flags
& DI_NOVCP
))
3461 FileQueue
= SetupOpenFileQueue();
3462 if (FileQueue
== INVALID_HANDLE_VALUE
)
3464 SetupCloseInfFile(hInf
);
3468 bFileQueueCreated
= TRUE
;
3473 SetupInstallFromInfSectionW(NULL
,
3476 SPINST_COPYINF
| SPINST_FILES
| SPINST_REGISTRY
,
3482 INVALID_HANDLE_VALUE
,
3485 /* FIXME: More code! */
3487 if (bFileQueueCreated
)
3488 SetupCloseFileQueue(FileQueue
);
3490 SetupCloseInfFile(hInf
);
3496 /***********************************************************************
3497 * SetupDiOpenClassRegKey (SETUPAPI.@)
3499 HKEY WINAPI
SetupDiOpenClassRegKey(
3500 const GUID
* ClassGuid
,
3503 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3504 DIOCR_INSTALLER
, NULL
, NULL
);
3508 /***********************************************************************
3509 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3511 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3512 const GUID
* ClassGuid
,
3518 PWSTR MachineNameW
= NULL
;
3525 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
3526 if (MachineNameW
== NULL
)
3527 return INVALID_HANDLE_VALUE
;
3530 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3531 Flags
, MachineNameW
, Reserved
);
3533 MyFree(MachineNameW
);
3539 /***********************************************************************
3540 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3542 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3543 const GUID
* ClassGuid
,
3554 if (MachineName
&& *MachineName
)
3556 FIXME("Remote access not supported yet!\n");
3557 return INVALID_HANDLE_VALUE
;
3560 if (Flags
== DIOCR_INSTALLER
)
3562 lpKeyName
= ControlClass
;
3564 else if (Flags
== DIOCR_INTERFACE
)
3566 lpKeyName
= DeviceClasses
;
3570 ERR("Invalid Flags parameter!\n");
3571 SetLastError(ERROR_INVALID_PARAMETER
);
3572 return INVALID_HANDLE_VALUE
;
3577 if ((l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3584 hClassesKey
= INVALID_HANDLE_VALUE
;
3590 WCHAR bracedGuidString
[39];
3592 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3594 if (!(l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3600 if ((l
= RegOpenKeyExW(hClassesKey
,
3607 key
= INVALID_HANDLE_VALUE
;
3609 RegCloseKey(hClassesKey
);
3614 key
= INVALID_HANDLE_VALUE
;
3620 /***********************************************************************
3621 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3623 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3624 HDEVINFO DeviceInfoSet
,
3627 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3629 FIXME("%p %s %08x %p\n",
3630 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3634 /***********************************************************************
3635 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3637 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
3638 HDEVINFO DeviceInfoSet
,
3641 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3643 FIXME("%p %s %08x %p\n", DeviceInfoSet
,
3644 debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3648 /***********************************************************************
3649 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3651 BOOL WINAPI
SetupDiSetClassInstallParamsA(
3652 HDEVINFO DeviceInfoSet
,
3653 PSP_DEVINFO_DATA DeviceInfoData
,
3654 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3655 DWORD ClassInstallParamsSize
)
3657 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3658 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3662 /***********************************************************************
3663 * SetupDiSetClassInstallParamsW (SETUPAPI.@)
3665 BOOL WINAPI
SetupDiSetClassInstallParamsW(
3666 HDEVINFO DeviceInfoSet
,
3667 PSP_DEVINFO_DATA DeviceInfoData
,
3668 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3669 DWORD ClassInstallParamsSize
)
3671 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3672 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3676 /***********************************************************************
3677 * SetupDiCallClassInstaller (SETUPAPI.@)
3679 BOOL WINAPI
SetupDiCallClassInstaller(
3680 DI_FUNCTION InstallFunction
,
3681 HDEVINFO DeviceInfoSet
,
3682 PSP_DEVINFO_DATA DeviceInfoData
)
3684 FIXME("%d %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3688 /***********************************************************************
3689 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
3691 BOOL WINAPI
SetupDiGetDeviceInstallParamsW(
3692 HDEVINFO DeviceInfoSet
,
3693 PSP_DEVINFO_DATA DeviceInfoData
,
3694 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
3696 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3700 /***********************************************************************
3701 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3703 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
3704 HDEVINFO DeviceInfoSet
,
3705 PSP_DEVINFO_DATA DeviceInfoData
,
3706 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3708 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3712 /***********************************************************************
3713 * SetupDiSetDeviceInstallParamsA (SETUPAPI.@)
3715 BOOL WINAPI
SetupDiSetDeviceInstallParamsA(
3716 HDEVINFO DeviceInfoSet
,
3717 PSP_DEVINFO_DATA DeviceInfoData
,
3718 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3720 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3725 /***********************************************************************
3726 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
3728 BOOL WINAPI
SetupDiSetDeviceInstallParamsW(
3729 HDEVINFO DeviceInfoSet
,
3730 PSP_DEVINFO_DATA DeviceInfoData
,
3731 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
3733 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3738 static HKEY
SETUPDI_OpenDevKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3740 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
3743 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3744 NULL
, &enumKey
, NULL
);
3747 RegOpenKeyExW(enumKey
, devInfo
->instanceId
, 0, samDesired
, &key
);
3748 RegCloseKey(enumKey
);
3753 static HKEY
SETUPDI_OpenDrvKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3755 static const WCHAR slash
[] = { '\\',0 };
3756 WCHAR classKeyPath
[MAX_PATH
];
3757 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
3760 lstrcpyW(classKeyPath
, ControlClass
);
3761 lstrcatW(classKeyPath
, slash
);
3762 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3763 classKeyPath
+ lstrlenW(classKeyPath
));
3764 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3765 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3768 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3771 sprintfW(devId
, fmt
, devInfo
->devId
);
3772 l
= RegOpenKeyExW(classKey
, devId
, 0, samDesired
, &key
);
3773 RegCloseKey(classKey
);
3776 SetLastError(ERROR_KEY_DOES_NOT_EXIST
);
3777 return INVALID_HANDLE_VALUE
;
3783 /***********************************************************************
3784 * SetupDiOpenDevRegKey (SETUPAPI.@)
3786 HKEY WINAPI
SetupDiOpenDevRegKey(
3787 HDEVINFO DeviceInfoSet
,
3788 PSP_DEVINFO_DATA DeviceInfoData
,
3794 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3795 struct DeviceInfo
*devInfo
;
3796 HKEY key
= INVALID_HANDLE_VALUE
;
3798 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
3799 Scope
, HwProfile
, KeyType
, samDesired
);
3801 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3803 SetLastError(ERROR_INVALID_HANDLE
);
3804 return INVALID_HANDLE_VALUE
;
3806 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3808 SetLastError(ERROR_INVALID_HANDLE
);
3809 return INVALID_HANDLE_VALUE
;
3811 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3812 || !DeviceInfoData
->Reserved
)
3814 SetLastError(ERROR_INVALID_PARAMETER
);
3815 return INVALID_HANDLE_VALUE
;
3817 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3819 SetLastError(ERROR_INVALID_FLAGS
);
3820 return INVALID_HANDLE_VALUE
;
3822 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
3824 SetLastError(ERROR_INVALID_FLAGS
);
3825 return INVALID_HANDLE_VALUE
;
3827 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3828 if (devInfo
->set
!= set
)
3830 SetLastError(ERROR_INVALID_PARAMETER
);
3831 return INVALID_HANDLE_VALUE
;
3833 if (devInfo
->phantom
)
3835 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3836 return INVALID_HANDLE_VALUE
;
3838 if (Scope
!= DICS_FLAG_GLOBAL
)
3839 FIXME("unimplemented for scope %d\n", Scope
);
3843 key
= SETUPDI_OpenDevKey(devInfo
, samDesired
);
3846 key
= SETUPDI_OpenDrvKey(devInfo
, samDesired
);
3849 WARN("unknown KeyType %d\n", KeyType
);
3854 static BOOL
SETUPDI_DeleteDevKey(struct DeviceInfo
*devInfo
)
3860 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3861 NULL
, &enumKey
, NULL
);
3864 ret
= RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
3865 RegCloseKey(enumKey
);
3872 static BOOL
SETUPDI_DeleteDrvKey(struct DeviceInfo
*devInfo
)
3874 static const WCHAR slash
[] = { '\\',0 };
3875 WCHAR classKeyPath
[MAX_PATH
];
3880 lstrcpyW(classKeyPath
, ControlClass
);
3881 lstrcatW(classKeyPath
, slash
);
3882 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3883 classKeyPath
+ lstrlenW(classKeyPath
));
3884 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3885 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3888 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3891 sprintfW(devId
, fmt
, devInfo
->devId
);
3892 ret
= RegDeleteTreeW(classKey
, devId
);
3893 RegCloseKey(classKey
);
3900 /***********************************************************************
3901 * SetupDiDeleteDevRegKey (SETUPAPI.@)
3903 BOOL WINAPI
SetupDiDeleteDevRegKey(
3904 HDEVINFO DeviceInfoSet
,
3905 PSP_DEVINFO_DATA DeviceInfoData
,
3910 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3911 struct DeviceInfo
*devInfo
;
3914 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
3917 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3919 SetLastError(ERROR_INVALID_HANDLE
);
3922 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3924 SetLastError(ERROR_INVALID_HANDLE
);
3927 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3928 || !DeviceInfoData
->Reserved
)
3930 SetLastError(ERROR_INVALID_PARAMETER
);
3933 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3935 SetLastError(ERROR_INVALID_FLAGS
);
3938 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
3940 SetLastError(ERROR_INVALID_FLAGS
);
3943 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3944 if (devInfo
->set
!= set
)
3946 SetLastError(ERROR_INVALID_PARAMETER
);
3949 if (devInfo
->phantom
)
3951 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3954 if (Scope
!= DICS_FLAG_GLOBAL
)
3955 FIXME("unimplemented for scope %d\n", Scope
);
3959 ret
= SETUPDI_DeleteDevKey(devInfo
);
3962 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3965 ret
= SETUPDI_DeleteDevKey(devInfo
);
3967 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3970 WARN("unknown KeyType %d\n", KeyType
);
3975 /***********************************************************************
3976 * CM_Get_Device_IDA (SETUPAPI.@)
3978 CONFIGRET WINAPI
CM_Get_Device_IDA( DEVINST dnDevInst
, PSTR Buffer
,
3979 ULONG BufferLen
, ULONG ulFlags
)
3981 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
3983 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
3986 return CR_NO_SUCH_DEVINST
;
3988 WideCharToMultiByte(CP_ACP
, 0, devInfo
->instanceId
, -1, Buffer
, BufferLen
, 0, 0);
3989 TRACE("Returning %s\n", debugstr_a(Buffer
));
3993 /***********************************************************************
3994 * CM_Get_Device_IDW (SETUPAPI.@)
3996 CONFIGRET WINAPI
CM_Get_Device_IDW( DEVINST dnDevInst
, LPWSTR Buffer
,
3997 ULONG BufferLen
, ULONG ulFlags
)
3999 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
4001 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
4005 WARN("dev instance %d not found!\n", dnDevInst
);
4006 return CR_NO_SUCH_DEVINST
;
4009 lstrcpynW(Buffer
, devInfo
->instanceId
, BufferLen
);
4010 TRACE("Returning %s\n", debugstr_w(Buffer
));
4011 GlobalUnlock((HANDLE
)dnDevInst
);
4017 /***********************************************************************
4018 * CM_Get_Device_ID_Size (SETUPAPI.@)
4020 CONFIGRET WINAPI
CM_Get_Device_ID_Size( PULONG pulLen
, DEVINST dnDevInst
,
4023 struct DeviceInfo
*ppdevInfo
= GlobalLock((HANDLE
)dnDevInst
);
4025 TRACE("%x->%p, %p, %u\n", dnDevInst
, ppdevInfo
, pulLen
, ulFlags
);
4029 WARN("dev instance %d not found!\n", dnDevInst
);
4030 return CR_NO_SUCH_DEVINST
;
4033 *pulLen
= lstrlenW(ppdevInfo
->instanceId
);
4034 GlobalUnlock((HANDLE
)dnDevInst
);
4038 /***********************************************************************
4039 * SetupDiGetINFClassA (SETUPAPI.@)
4041 BOOL WINAPI
SetupDiGetINFClassA(PCSTR inf
, LPGUID class_guid
, PSTR class_name
,
4042 DWORD size
, PDWORD required_size
)
4045 DWORD required_sizeA
, required_sizeW
;
4046 PWSTR class_nameW
= NULL
;
4047 UNICODE_STRING infW
;
4051 if (!RtlCreateUnicodeStringFromAsciiz(&infW
, inf
))
4053 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4060 if (class_name
&& size
)
4062 if (!(class_nameW
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
))))
4064 RtlFreeUnicodeString(&infW
);
4065 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4070 retval
= SetupDiGetINFClassW(infW
.Buffer
, class_guid
, class_nameW
, size
, &required_sizeW
);
4074 required_sizeA
= WideCharToMultiByte( CP_ACP
, 0, class_nameW
, required_sizeW
,
4075 class_name
, size
, NULL
, NULL
);
4077 if(required_size
) *required_size
= required_sizeA
;
4080 if(required_size
) *required_size
= required_sizeW
;
4082 HeapFree(GetProcessHeap(), 0, class_nameW
);
4083 RtlFreeUnicodeString(&infW
);
4087 /***********************************************************************
4088 * SetupDiGetINFClassW (SETUPAPI.@)
4090 BOOL WINAPI
SetupDiGetINFClassW(PCWSTR inf
, LPGUID class_guid
, PWSTR class_name
,
4091 DWORD size
, PDWORD required_size
)
4093 BOOL have_guid
, have_name
;
4095 WCHAR buffer
[MAX_PATH
];
4099 SetLastError(ERROR_INVALID_PARAMETER
);
4103 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(inf
))
4105 FIXME("%s not found. Searching via DevicePath not implemented\n", debugstr_w(inf
));
4106 SetLastError(ERROR_FILE_NOT_FOUND
);
4110 if (!class_guid
|| !class_name
|| !size
)
4112 SetLastError(ERROR_INVALID_PARAMETER
);
4116 if (!GetPrivateProfileStringW(Version
, Signature
, NULL
, buffer
, MAX_PATH
, inf
))
4119 if (lstrcmpiW(buffer
, Chicago
) && lstrcmpiW(buffer
, WindowsNT
))
4123 have_guid
= 0 < GetPrivateProfileStringW(Version
, ClassGUID
, NULL
, buffer
, MAX_PATH
, inf
);
4126 buffer
[lstrlenW(buffer
)-1] = 0;
4127 if (RPC_S_OK
!= UuidFromStringW(buffer
+ 1, class_guid
))
4129 FIXME("failed to convert \"%s\" into a guid\n", debugstr_w(buffer
));
4130 SetLastError(ERROR_INVALID_PARAMETER
);
4136 dret
= GetPrivateProfileStringW(Version
, Class
, NULL
, buffer
, MAX_PATH
, inf
);
4137 have_name
= 0 < dret
;
4139 if (dret
>= MAX_PATH
-1) FIXME("buffer might be too small\n");
4140 if (have_guid
&& !have_name
) FIXME("class name lookup via guid not implemented\n");
4144 if (dret
< size
) lstrcpyW(class_name
, buffer
);
4147 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4152 if (required_size
) *required_size
= dret
+ ((dret
) ? 1 : 0);
4154 return (have_guid
|| have_name
);
4157 /***********************************************************************
4158 * SetupDiGetDevicePropertyW (SETUPAPI.@)
4160 BOOL WINAPI
SetupDiGetDevicePropertyW(HDEVINFO info_set
, PSP_DEVINFO_DATA info_data
,
4161 const DEVPROPKEY
*prop_key
, DEVPROPTYPE
*prop_type
, BYTE
*prop_buff
,
4162 DWORD prop_buff_size
, DWORD
*required_size
, DWORD flags
)
4164 FIXME("%p, %p, %p, %p, %p, %d, %p, 0x%08x stub\n", info_set
, info_data
, prop_key
,
4165 prop_type
, prop_buff
, prop_buff_size
, required_size
, flags
);
4167 SetLastError(ERROR_NOT_FOUND
);