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
), devInst
,
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 emtpy 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 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1566 BOOL WINAPI
SetupDiEnumDeviceInfo(
1569 PSP_DEVINFO_DATA info
)
1573 TRACE("%p %d %p\n", devinfo
, index
, info
);
1577 SetLastError(ERROR_INVALID_PARAMETER
);
1580 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
1582 struct DeviceInfoSet
*list
= devinfo
;
1583 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
1585 if (index
< list
->cDevices
)
1587 if (info
->cbSize
== sizeof(SP_DEVINFO_DATA
))
1589 struct DeviceInstance
*devInst
;
1592 LIST_FOR_EACH_ENTRY(devInst
, &list
->devices
,
1593 struct DeviceInstance
, entry
)
1597 *info
= devInst
->data
;
1604 SetLastError(ERROR_INVALID_USER_BUFFER
);
1607 SetLastError(ERROR_NO_MORE_ITEMS
);
1610 SetLastError(ERROR_INVALID_HANDLE
);
1613 SetLastError(ERROR_INVALID_HANDLE
);
1617 /***********************************************************************
1618 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1620 BOOL WINAPI
SetupDiGetDeviceInstanceIdA(
1621 HDEVINFO DeviceInfoSet
,
1622 PSP_DEVINFO_DATA DeviceInfoData
,
1623 PSTR DeviceInstanceId
,
1624 DWORD DeviceInstanceIdSize
,
1625 PDWORD RequiredSize
)
1631 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1632 DeviceInstanceIdSize
, RequiredSize
);
1634 SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1639 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1641 instanceId
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
1644 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1651 int len
= WideCharToMultiByte(CP_ACP
, 0, instanceId
, -1,
1653 DeviceInstanceIdSize
, NULL
, NULL
);
1659 if (len
> DeviceInstanceIdSize
)
1661 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1665 *RequiredSize
= len
;
1668 HeapFree(GetProcessHeap(), 0, instanceId
);
1673 /***********************************************************************
1674 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1676 BOOL WINAPI
SetupDiGetDeviceInstanceIdW(
1677 HDEVINFO DeviceInfoSet
,
1678 PSP_DEVINFO_DATA DeviceInfoData
,
1679 PWSTR DeviceInstanceId
,
1680 DWORD DeviceInstanceIdSize
,
1681 PDWORD RequiredSize
)
1683 struct DeviceInfoSet
*set
= DeviceInfoSet
;
1684 struct DeviceInfo
*devInfo
;
1686 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1687 DeviceInstanceIdSize
, RequiredSize
);
1689 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1691 SetLastError(ERROR_INVALID_HANDLE
);
1694 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1696 SetLastError(ERROR_INVALID_HANDLE
);
1699 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1700 || !DeviceInfoData
->Reserved
)
1702 SetLastError(ERROR_INVALID_PARAMETER
);
1705 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1706 if (devInfo
->set
!= set
)
1708 SetLastError(ERROR_INVALID_PARAMETER
);
1711 TRACE("instance ID: %s\n", debugstr_w(devInfo
->instanceId
));
1712 if (DeviceInstanceIdSize
< strlenW(devInfo
->instanceId
) + 1)
1714 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1716 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1719 lstrcpyW(DeviceInstanceId
, devInfo
->instanceId
);
1721 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1725 /***********************************************************************
1726 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1728 BOOL WINAPI
SetupDiGetActualSectionToInstallA(
1730 PCSTR InfSectionName
,
1731 PSTR InfSectionWithExt
,
1732 DWORD InfSectionWithExtSize
,
1733 PDWORD RequiredSize
,
1740 /***********************************************************************
1741 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
1743 BOOL WINAPI
SetupDiGetActualSectionToInstallW(
1745 PCWSTR InfSectionName
,
1746 PWSTR InfSectionWithExt
,
1747 DWORD InfSectionWithExtSize
,
1748 PDWORD RequiredSize
,
1751 WCHAR szBuffer
[MAX_PATH
];
1754 LONG lLineCount
= -1;
1756 lstrcpyW(szBuffer
, InfSectionName
);
1757 dwLength
= lstrlenW(szBuffer
);
1759 if (OsVersionInfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
1761 /* Test section name with '.NTx86' extension */
1762 lstrcpyW(&szBuffer
[dwLength
], NtPlatformExtension
);
1763 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1765 if (lLineCount
== -1)
1767 /* Test section name with '.NT' extension */
1768 lstrcpyW(&szBuffer
[dwLength
], NtExtension
);
1769 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1774 /* Test section name with '.Win' extension */
1775 lstrcpyW(&szBuffer
[dwLength
], WinExtension
);
1776 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1779 if (lLineCount
== -1)
1781 /* Test section name without extension */
1782 szBuffer
[dwLength
] = 0;
1783 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1786 if (lLineCount
== -1)
1788 SetLastError(ERROR_INVALID_PARAMETER
);
1792 dwFullLength
= lstrlenW(szBuffer
);
1794 if (InfSectionWithExt
!= NULL
&& InfSectionWithExtSize
!= 0)
1796 if (InfSectionWithExtSize
< (dwFullLength
+ 1))
1798 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1802 lstrcpyW(InfSectionWithExt
, szBuffer
);
1803 if (Extension
!= NULL
)
1805 *Extension
= (dwLength
== dwFullLength
) ? NULL
: &InfSectionWithExt
[dwLength
];
1809 if (RequiredSize
!= NULL
)
1811 *RequiredSize
= dwFullLength
+ 1;
1817 /***********************************************************************
1818 * SetupDiGetClassDescriptionA (SETUPAPI.@)
1820 BOOL WINAPI
SetupDiGetClassDescriptionA(
1821 const GUID
* ClassGuid
,
1822 PSTR ClassDescription
,
1823 DWORD ClassDescriptionSize
,
1824 PDWORD RequiredSize
)
1826 return SetupDiGetClassDescriptionExA(ClassGuid
, ClassDescription
,
1827 ClassDescriptionSize
,
1828 RequiredSize
, NULL
, NULL
);
1831 /***********************************************************************
1832 * SetupDiGetClassDescriptionW (SETUPAPI.@)
1834 BOOL WINAPI
SetupDiGetClassDescriptionW(
1835 const GUID
* ClassGuid
,
1836 PWSTR ClassDescription
,
1837 DWORD ClassDescriptionSize
,
1838 PDWORD RequiredSize
)
1840 return SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescription
,
1841 ClassDescriptionSize
,
1842 RequiredSize
, NULL
, NULL
);
1845 /***********************************************************************
1846 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
1848 BOOL WINAPI
SetupDiGetClassDescriptionExA(
1849 const GUID
* ClassGuid
,
1850 PSTR ClassDescription
,
1851 DWORD ClassDescriptionSize
,
1852 PDWORD RequiredSize
,
1860 hKey
= SetupDiOpenClassRegKeyExA(ClassGuid
,
1865 if (hKey
== INVALID_HANDLE_VALUE
)
1867 WARN("SetupDiOpenClassRegKeyExA() failed (Error %u)\n", GetLastError());
1871 dwLength
= ClassDescriptionSize
;
1872 ret
= !RegQueryValueExA( hKey
, NULL
, NULL
, NULL
,
1873 (LPBYTE
)ClassDescription
, &dwLength
);
1874 if (RequiredSize
) *RequiredSize
= dwLength
;
1879 /***********************************************************************
1880 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
1882 BOOL WINAPI
SetupDiGetClassDescriptionExW(
1883 const GUID
* ClassGuid
,
1884 PWSTR ClassDescription
,
1885 DWORD ClassDescriptionSize
,
1886 PDWORD RequiredSize
,
1894 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1899 if (hKey
== INVALID_HANDLE_VALUE
)
1901 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
1905 dwLength
= ClassDescriptionSize
* sizeof(WCHAR
);
1906 ret
= !RegQueryValueExW( hKey
, NULL
, NULL
, NULL
,
1907 (LPBYTE
)ClassDescription
, &dwLength
);
1908 if (RequiredSize
) *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1913 /***********************************************************************
1914 * SetupDiGetClassDevsA (SETUPAPI.@)
1916 HDEVINFO WINAPI
SetupDiGetClassDevsA(const GUID
*class, LPCSTR enumstr
, HWND parent
, DWORD flags
)
1919 LPWSTR enumstrW
= NULL
;
1923 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1924 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1927 ret
= INVALID_HANDLE_VALUE
;
1930 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1932 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, NULL
, NULL
,
1934 HeapFree(GetProcessHeap(), 0, enumstrW
);
1940 /***********************************************************************
1941 * SetupDiGetClassDevsExA (SETUPAPI.@)
1943 HDEVINFO WINAPI
SetupDiGetClassDevsExA(
1953 LPWSTR enumstrW
= NULL
, machineW
= NULL
;
1957 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1958 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1961 ret
= INVALID_HANDLE_VALUE
;
1964 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1968 int len
= MultiByteToWideChar(CP_ACP
, 0, machine
, -1, NULL
, 0);
1969 machineW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1972 HeapFree(GetProcessHeap(), 0, enumstrW
);
1973 ret
= INVALID_HANDLE_VALUE
;
1976 MultiByteToWideChar(CP_ACP
, 0, machine
, -1, machineW
, len
);
1978 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, deviceset
,
1979 machineW
, reserved
);
1980 HeapFree(GetProcessHeap(), 0, enumstrW
);
1981 HeapFree(GetProcessHeap(), 0, machineW
);
1987 static void SETUPDI_AddDeviceInterfaces(SP_DEVINFO_DATA
*dev
, HKEY key
,
1991 WCHAR subKeyName
[MAX_PATH
];
1992 LONG l
= ERROR_SUCCESS
;
1994 for (i
= 0; !l
; i
++)
1996 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
1997 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2001 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
2003 if (*subKeyName
== '#')
2005 /* The subkey name is the reference string, with a '#' prepended */
2006 SETUPDI_AddInterfaceInstance(dev
, guid
, subKeyName
+ 1, &iface
);
2007 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2010 WCHAR symbolicLink
[MAX_PATH
];
2013 len
= sizeof(symbolicLink
);
2014 l
= RegQueryValueExW(subKey
, SymbolicLink
, NULL
, &dataType
,
2015 (BYTE
*)symbolicLink
, &len
);
2016 if (!l
&& dataType
== REG_SZ
)
2017 SETUPDI_SetInterfaceSymbolicLink(iface
, symbolicLink
);
2018 RegCloseKey(subKey
);
2021 /* Allow enumeration to continue */
2025 /* FIXME: find and add all the device's interfaces to the device */
2028 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet
,
2029 HKEY key
, const GUID
*guid
, LPCWSTR enumstr
)
2031 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2033 WCHAR subKeyName
[MAX_PATH
];
2035 HKEY enumKey
= INVALID_HANDLE_VALUE
;
2037 TRACE("%s\n", debugstr_w(enumstr
));
2039 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2041 for (i
= 0; !l
; i
++)
2043 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2044 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2049 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2052 WCHAR deviceInst
[MAX_PATH
* 3];
2055 len
= sizeof(deviceInst
);
2056 l
= RegQueryValueExW(subKey
, DeviceInstance
, NULL
, &dataType
,
2057 (BYTE
*)deviceInst
, &len
);
2058 if (!l
&& dataType
== REG_SZ
)
2060 TRACE("found instance ID %s\n", debugstr_w(deviceInst
));
2061 if (!enumstr
|| !lstrcmpiW(enumstr
, deviceInst
))
2065 l
= RegOpenKeyExW(enumKey
, deviceInst
, 0, KEY_READ
,
2069 WCHAR deviceClassStr
[40];
2071 len
= sizeof(deviceClassStr
);
2072 l
= RegQueryValueExW(deviceKey
, ClassGUID
, NULL
,
2073 &dataType
, (BYTE
*)deviceClassStr
, &len
);
2074 if (!l
&& dataType
== REG_SZ
&&
2075 deviceClassStr
[0] == '{' &&
2076 deviceClassStr
[37] == '}')
2079 SP_DEVINFO_DATA
*dev
;
2081 deviceClassStr
[37] = 0;
2082 UuidFromStringW(&deviceClassStr
[1],
2084 if (SETUPDI_AddDeviceToSet(set
, &deviceClass
,
2085 0 /* FIXME: DevInst */, deviceInst
,
2087 SETUPDI_AddDeviceInterfaces(dev
, subKey
, guid
);
2089 RegCloseKey(deviceKey
);
2093 RegCloseKey(subKey
);
2095 /* Allow enumeration to continue */
2099 if (enumKey
!= INVALID_HANDLE_VALUE
)
2100 RegCloseKey(enumKey
);
2103 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet
,
2104 const GUID
*guid
, LPCWSTR enumstr
, DWORD flags
)
2106 HKEY interfacesKey
= SetupDiOpenClassRegKeyExW(guid
, KEY_READ
,
2107 DIOCR_INTERFACE
, NULL
, NULL
);
2109 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(guid
),
2110 debugstr_w(enumstr
), flags
);
2112 if (interfacesKey
!= INVALID_HANDLE_VALUE
)
2114 if (flags
& DIGCF_ALLCLASSES
)
2117 WCHAR interfaceGuidStr
[40];
2118 LONG l
= ERROR_SUCCESS
;
2120 for (i
= 0; !l
; i
++)
2122 len
= sizeof(interfaceGuidStr
) / sizeof(interfaceGuidStr
[0]);
2123 l
= RegEnumKeyExW(interfacesKey
, i
, interfaceGuidStr
, &len
,
2124 NULL
, NULL
, NULL
, NULL
);
2127 if (interfaceGuidStr
[0] == '{' &&
2128 interfaceGuidStr
[37] == '}')
2133 interfaceGuidStr
[37] = 0;
2134 UuidFromStringW(&interfaceGuidStr
[1], &interfaceGuid
);
2135 l
= RegOpenKeyExW(interfacesKey
, interfaceGuidStr
, 0,
2136 KEY_READ
, &interfaceKey
);
2139 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2140 interfaceKey
, &interfaceGuid
, enumstr
);
2141 RegCloseKey(interfaceKey
);
2149 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2150 * interface's key, so just pass that long
2152 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2153 interfacesKey
, guid
, enumstr
);
2155 RegCloseKey(interfacesKey
);
2159 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet
*set
,
2160 LPCWSTR enumerator
, LPCWSTR deviceName
, HKEY deviceKey
,
2161 const GUID
*class, DWORD flags
)
2164 WCHAR deviceInstance
[MAX_PATH
];
2165 LONG l
= ERROR_SUCCESS
;
2167 TRACE("%s %s\n", debugstr_w(enumerator
), debugstr_w(deviceName
));
2169 for (i
= 0; !l
; i
++)
2171 len
= sizeof(deviceInstance
) / sizeof(deviceInstance
[0]);
2172 l
= RegEnumKeyExW(deviceKey
, i
, deviceInstance
, &len
, NULL
, NULL
, NULL
,
2178 l
= RegOpenKeyExW(deviceKey
, deviceInstance
, 0, KEY_READ
, &subKey
);
2181 WCHAR classGuid
[40];
2184 len
= sizeof(classGuid
);
2185 l
= RegQueryValueExW(subKey
, ClassGUID
, NULL
, &dataType
,
2186 (BYTE
*)classGuid
, &len
);
2187 if (!l
&& dataType
== REG_SZ
)
2189 if (classGuid
[0] == '{' && classGuid
[37] == '}')
2194 UuidFromStringW(&classGuid
[1], &deviceClass
);
2195 if ((flags
& DIGCF_ALLCLASSES
) ||
2196 IsEqualGUID(class, &deviceClass
))
2198 static const WCHAR fmt
[] =
2199 {'%','s','\\','%','s','\\','%','s',0};
2202 instanceId
= HeapAlloc(GetProcessHeap(), 0,
2203 (lstrlenW(enumerator
) + lstrlenW(deviceName
) +
2204 lstrlenW(deviceInstance
) + 3) * sizeof(WCHAR
));
2207 sprintfW(instanceId
, fmt
, enumerator
,
2208 deviceName
, deviceInstance
);
2209 SETUPDI_AddDeviceToSet(set
, &deviceClass
,
2210 0 /* FIXME: DevInst */, instanceId
,
2212 HeapFree(GetProcessHeap(), 0, instanceId
);
2217 RegCloseKey(subKey
);
2219 /* Allow enumeration to continue */
2225 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet
,
2226 LPCWSTR parent
, HKEY key
, const GUID
*class, DWORD flags
)
2228 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2230 WCHAR subKeyName
[MAX_PATH
];
2231 LONG l
= ERROR_SUCCESS
;
2233 TRACE("%s\n", debugstr_w(parent
));
2235 for (i
= 0; !l
; i
++)
2237 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2238 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2243 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2246 TRACE("%s\n", debugstr_w(subKeyName
));
2247 SETUPDI_EnumerateMatchingDeviceInstances(set
, parent
,
2248 subKeyName
, subKey
, class, flags
);
2249 RegCloseKey(subKey
);
2251 /* Allow enumeration to continue */
2257 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet
, const GUID
*class,
2258 LPCWSTR enumstr
, DWORD flags
)
2263 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(class),
2264 debugstr_w(enumstr
), flags
);
2266 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2268 if (enumKey
!= INVALID_HANDLE_VALUE
)
2274 l
= RegOpenKeyExW(enumKey
, enumstr
, 0, KEY_READ
,
2278 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
, enumstr
,
2279 enumStrKey
, class, flags
);
2280 RegCloseKey(enumStrKey
);
2286 WCHAR subKeyName
[MAX_PATH
];
2289 for (i
= 0; !l
; i
++)
2291 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2292 l
= RegEnumKeyExW(enumKey
, i
, subKeyName
, &len
, NULL
,
2298 l
= RegOpenKeyExW(enumKey
, subKeyName
, 0, KEY_READ
,
2302 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
,
2303 subKeyName
, subKey
, class, flags
);
2304 RegCloseKey(subKey
);
2306 /* Allow enumeration to continue */
2311 RegCloseKey(enumKey
);
2315 /***********************************************************************
2316 * SetupDiGetClassDevsW (SETUPAPI.@)
2318 HDEVINFO WINAPI
SetupDiGetClassDevsW(const GUID
*class, LPCWSTR enumstr
, HWND parent
, DWORD flags
)
2320 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2324 /***********************************************************************
2325 * SetupDiGetClassDevsExW (SETUPAPI.@)
2327 HDEVINFO WINAPI
SetupDiGetClassDevsExW(const GUID
*class, PCWSTR enumstr
, HWND parent
, DWORD flags
,
2328 HDEVINFO deviceset
, PCWSTR machine
, void *reserved
)
2330 static const DWORD unsupportedFlags
= DIGCF_DEFAULT
| DIGCF_PRESENT
|
2334 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2335 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2338 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2340 SetLastError(ERROR_INVALID_PARAMETER
);
2343 if (flags
& unsupportedFlags
)
2344 WARN("unsupported flags %08x\n", flags
& unsupportedFlags
);
2348 set
= SetupDiCreateDeviceInfoListExW(class, parent
, machine
, reserved
);
2351 if (machine
&& *machine
)
2352 FIXME("%s: unimplemented for remote machines\n",
2353 debugstr_w(machine
));
2354 else if (flags
& DIGCF_DEVICEINTERFACE
)
2355 SETUPDI_EnumerateInterfaces(set
, class, enumstr
, flags
);
2357 SETUPDI_EnumerateDevices(set
, class, enumstr
, flags
);
2362 /***********************************************************************
2363 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2365 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2366 HDEVINFO DeviceInfoSet
,
2367 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2369 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2371 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2373 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2375 SetLastError(ERROR_INVALID_HANDLE
);
2378 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2380 SetLastError(ERROR_INVALID_HANDLE
);
2384 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2386 SetLastError(ERROR_INVALID_PARAMETER
);
2389 DevInfoData
->ClassGuid
= set
->ClassGuid
;
2390 DevInfoData
->RemoteMachineHandle
= NULL
;
2391 DevInfoData
->RemoteMachineName
[0] = '\0';
2395 /***********************************************************************
2396 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2398 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2399 HDEVINFO DeviceInfoSet
,
2400 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2402 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2404 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2406 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2408 SetLastError(ERROR_INVALID_HANDLE
);
2411 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2413 SetLastError(ERROR_INVALID_HANDLE
);
2417 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2419 SetLastError(ERROR_INVALID_PARAMETER
);
2422 DevInfoData
->ClassGuid
= set
->ClassGuid
;
2423 DevInfoData
->RemoteMachineHandle
= NULL
;
2424 DevInfoData
->RemoteMachineName
[0] = '\0';
2428 /***********************************************************************
2429 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2431 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2432 HDEVINFO DeviceInfoSet
,
2433 PSP_DEVINFO_DATA DeviceInfoData
,
2434 const GUID
*InterfaceClassGuid
,
2435 PCSTR ReferenceString
,
2436 DWORD CreationFlags
,
2437 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2440 LPWSTR ReferenceStringW
= NULL
;
2442 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2443 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2444 CreationFlags
, DeviceInterfaceData
);
2446 if (ReferenceString
)
2448 ReferenceStringW
= MultiByteToUnicode(ReferenceString
, CP_ACP
);
2449 if (ReferenceStringW
== NULL
) return FALSE
;
2452 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2453 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2454 DeviceInterfaceData
);
2456 MyFree(ReferenceStringW
);
2461 /***********************************************************************
2462 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2464 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2465 HDEVINFO DeviceInfoSet
,
2466 PSP_DEVINFO_DATA DeviceInfoData
,
2467 const GUID
*InterfaceClassGuid
,
2468 PCWSTR ReferenceString
,
2469 DWORD CreationFlags
,
2470 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2472 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2473 struct DeviceInfo
*devInfo
;
2474 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
2477 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2478 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2479 CreationFlags
, DeviceInterfaceData
);
2481 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2483 SetLastError(ERROR_INVALID_HANDLE
);
2486 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2488 SetLastError(ERROR_INVALID_HANDLE
);
2491 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2492 || !DeviceInfoData
->Reserved
)
2494 SetLastError(ERROR_INVALID_PARAMETER
);
2497 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2498 if (devInfo
->set
!= set
)
2500 SetLastError(ERROR_INVALID_PARAMETER
);
2503 if (!InterfaceClassGuid
)
2505 SetLastError(ERROR_INVALID_USER_BUFFER
);
2508 if ((ret
= SETUPDI_AddInterfaceInstance(DeviceInfoData
, InterfaceClassGuid
,
2509 ReferenceString
, &iface
)))
2511 if (DeviceInterfaceData
)
2513 if (DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2515 SetLastError(ERROR_INVALID_USER_BUFFER
);
2519 *DeviceInterfaceData
= *iface
;
2525 /***********************************************************************
2526 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2528 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2529 HDEVINFO DeviceInfoSet
,
2530 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2534 PCSTR InfSectionName
)
2537 PWSTR InfSectionNameW
= NULL
;
2539 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2540 samDesired
, InfHandle
, InfSectionName
);
2543 if (!InfSectionName
)
2545 SetLastError(ERROR_INVALID_PARAMETER
);
2546 return INVALID_HANDLE_VALUE
;
2548 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2549 if (!InfSectionNameW
)
2550 return INVALID_HANDLE_VALUE
;
2552 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2553 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2555 MyFree(InfSectionNameW
);
2559 static PWSTR
SETUPDI_GetInstancePath(struct InterfaceInfo
*ifaceInfo
)
2561 static const WCHAR hash
[] = {'#',0};
2562 PWSTR instancePath
= NULL
;
2564 if (ifaceInfo
->referenceString
)
2566 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2567 (lstrlenW(ifaceInfo
->referenceString
) + 2) * sizeof(WCHAR
));
2570 lstrcpyW(instancePath
, hash
);
2571 lstrcatW(instancePath
, ifaceInfo
->referenceString
);
2574 SetLastError(ERROR_OUTOFMEMORY
);
2578 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2579 (lstrlenW(hash
) + 1) * sizeof(WCHAR
));
2581 lstrcpyW(instancePath
, hash
);
2583 return instancePath
;
2586 /***********************************************************************
2587 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2589 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2590 HDEVINFO DeviceInfoSet
,
2591 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2595 PCWSTR InfSectionName
)
2597 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2598 HKEY key
= INVALID_HANDLE_VALUE
, interfacesKey
;
2601 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2602 samDesired
, InfHandle
, InfSectionName
);
2604 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2605 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2607 SetLastError(ERROR_INVALID_HANDLE
);
2608 return INVALID_HANDLE_VALUE
;
2610 if (!DeviceInterfaceData
||
2611 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2612 !DeviceInterfaceData
->Reserved
)
2614 SetLastError(ERROR_INVALID_PARAMETER
);
2615 return INVALID_HANDLE_VALUE
;
2617 if (InfHandle
&& !InfSectionName
)
2619 SetLastError(ERROR_INVALID_PARAMETER
);
2620 return INVALID_HANDLE_VALUE
;
2622 if (!(l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, DeviceClasses
, 0, NULL
, 0,
2623 samDesired
, NULL
, &interfacesKey
, NULL
)))
2626 WCHAR bracedGuidString
[39];
2628 SETUPDI_GuidToString(&DeviceInterfaceData
->InterfaceClassGuid
,
2630 if (!(l
= RegCreateKeyExW(interfacesKey
, bracedGuidString
, 0, NULL
, 0,
2631 samDesired
, NULL
, &parent
, NULL
)))
2633 struct InterfaceInfo
*ifaceInfo
=
2634 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2635 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2636 PWSTR interfKeyName
= HeapAlloc(GetProcessHeap(), 0,
2637 (lstrlenW(ifaceInfo
->symbolicLink
) + 1) * sizeof(WCHAR
));
2641 lstrcpyW(interfKeyName
, ifaceInfo
->symbolicLink
);
2642 if (lstrlenW(ifaceInfo
->symbolicLink
) > 3)
2644 interfKeyName
[0] = '#';
2645 interfKeyName
[1] = '#';
2646 interfKeyName
[3] = '#';
2648 ptr
= strchrW(interfKeyName
, '\\');
2651 l
= RegCreateKeyExW(parent
, interfKeyName
, 0, NULL
, 0,
2652 samDesired
, NULL
, &interfKey
, NULL
);
2655 struct DeviceInfo
*devInfo
=
2656 (struct DeviceInfo
*)ifaceInfo
->device
->Reserved
;
2658 l
= RegSetValueExW(interfKey
, DeviceInstance
, 0, REG_SZ
,
2659 (BYTE
*)devInfo
->instanceId
,
2660 (lstrlenW(devInfo
->instanceId
) + 1) * sizeof(WCHAR
));
2667 l
= RegCreateKeyExW(interfKey
, instancePath
, 0, NULL
, 0,
2668 samDesired
, NULL
, &key
, NULL
);
2672 key
= INVALID_HANDLE_VALUE
;
2675 FIXME("INF section installation unsupported\n");
2680 RegCloseKey(interfKey
);
2684 HeapFree(GetProcessHeap(), 0, interfKeyName
);
2685 HeapFree(GetProcessHeap(), 0, instancePath
);
2686 RegCloseKey(parent
);
2690 RegCloseKey(interfacesKey
);
2697 /***********************************************************************
2698 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2700 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2701 HDEVINFO DeviceInfoSet
,
2702 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2705 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2709 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2711 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2712 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2714 SetLastError(ERROR_INVALID_HANDLE
);
2717 if (!DeviceInterfaceData
||
2718 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2719 !DeviceInterfaceData
->Reserved
)
2721 SetLastError(ERROR_INVALID_PARAMETER
);
2724 parent
= SetupDiOpenClassRegKeyExW(&DeviceInterfaceData
->InterfaceClassGuid
,
2725 KEY_ALL_ACCESS
, DIOCR_INTERFACE
, NULL
, NULL
);
2726 if (parent
!= INVALID_HANDLE_VALUE
)
2728 struct InterfaceInfo
*ifaceInfo
=
2729 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2730 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2734 LONG l
= RegDeleteKeyW(parent
, instancePath
);
2740 HeapFree(GetProcessHeap(), 0, instancePath
);
2742 RegCloseKey(parent
);
2747 /***********************************************************************
2748 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2751 * DeviceInfoSet [I] Set of devices from which to enumerate
2753 * DeviceInfoData [I] (Optional) If specified, a specific device
2754 * instance from which to enumerate interfaces.
2755 * If it isn't specified, all interfaces for all
2756 * devices in the set are enumerated.
2757 * InterfaceClassGuid [I] The interface class to enumerate.
2758 * MemberIndex [I] An index of the interface instance to enumerate.
2759 * A caller should start with MemberIndex set to 0,
2760 * and continue until the function fails with
2761 * ERROR_NO_MORE_ITEMS.
2762 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2763 * member must be set to
2764 * sizeof(SP_DEVICE_INTERFACE_DATA).
2767 * Success: non-zero value.
2768 * Failure: FALSE. Call GetLastError() for more info.
2770 BOOL WINAPI
SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet
, PSP_DEVINFO_DATA DeviceInfoData
,
2771 const GUID
*InterfaceClassGuid
, DWORD MemberIndex
,
2772 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2774 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2777 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet
, DeviceInfoData
,
2778 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
2780 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2781 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2783 SetLastError(ERROR_INVALID_HANDLE
);
2786 if (DeviceInfoData
&& (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2787 !DeviceInfoData
->Reserved
))
2789 SetLastError(ERROR_INVALID_PARAMETER
);
2792 if (!DeviceInterfaceData
||
2793 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2795 SetLastError(ERROR_INVALID_PARAMETER
);
2799 /* In case application fails to check return value, clear output */
2800 memset(DeviceInterfaceData
, 0, sizeof(*DeviceInterfaceData
));
2801 DeviceInterfaceData
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DATA
);
2805 struct DeviceInfo
*devInfo
=
2806 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2807 struct InterfaceInstances
*iface
;
2809 if ((ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
2811 if (MemberIndex
< iface
->cInstances
)
2812 *DeviceInterfaceData
= iface
->instances
[MemberIndex
];
2815 SetLastError(ERROR_NO_MORE_ITEMS
);
2820 SetLastError(ERROR_NO_MORE_ITEMS
);
2824 struct DeviceInstance
*devInst
;
2825 DWORD cEnumerated
= 0;
2828 LIST_FOR_EACH_ENTRY(devInst
, &set
->devices
, struct DeviceInstance
, entry
)
2830 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)devInst
->data
.Reserved
;
2831 struct InterfaceInstances
*iface
;
2833 if (found
|| cEnumerated
>= MemberIndex
+ 1)
2835 if (SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
))
2837 if (cEnumerated
+ iface
->cInstances
< MemberIndex
+ 1)
2838 cEnumerated
+= iface
->cInstances
;
2841 DWORD instanceIndex
= MemberIndex
- cEnumerated
;
2843 *DeviceInterfaceData
= iface
->instances
[instanceIndex
];
2844 cEnumerated
+= instanceIndex
+ 1;
2851 SetLastError(ERROR_NO_MORE_ITEMS
);
2856 /***********************************************************************
2857 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2859 * Destroy a DeviceInfoList and free all used memory of the list.
2862 * devinfo [I] DeviceInfoList pointer to list to destroy
2865 * Success: non zero value.
2866 * Failure: zero value.
2868 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
2872 TRACE("%p\n", devinfo
);
2873 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
2875 struct DeviceInfoSet
*list
= devinfo
;
2877 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
2879 struct DeviceInstance
*devInst
, *devInst2
;
2881 LIST_FOR_EACH_ENTRY_SAFE(devInst
, devInst2
, &list
->devices
,
2882 struct DeviceInstance
, entry
)
2884 SETUPDI_FreeDeviceInfo( (struct DeviceInfo
*)devInst
->data
.Reserved
);
2885 list_remove(&devInst
->entry
);
2886 HeapFree(GetProcessHeap(), 0, devInst
);
2888 HeapFree(GetProcessHeap(), 0, list
);
2894 SetLastError(ERROR_INVALID_HANDLE
);
2899 /***********************************************************************
2900 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2902 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
2903 HDEVINFO DeviceInfoSet
,
2904 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2905 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
2906 DWORD DeviceInterfaceDetailDataSize
,
2907 PDWORD RequiredSize
,
2908 PSP_DEVINFO_DATA DeviceInfoData
)
2910 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2911 struct InterfaceInfo
*info
;
2912 DWORD bytesNeeded
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
[1]);
2915 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2916 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2917 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2919 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2920 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2922 SetLastError(ERROR_INVALID_HANDLE
);
2925 if (!DeviceInterfaceData
||
2926 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2927 !DeviceInterfaceData
->Reserved
)
2929 SetLastError(ERROR_INVALID_PARAMETER
);
2932 if (DeviceInterfaceDetailData
&&
2933 DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
))
2935 SetLastError(ERROR_INVALID_USER_BUFFER
);
2938 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2940 SetLastError(ERROR_INVALID_USER_BUFFER
);
2943 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2944 if (info
->symbolicLink
)
2945 bytesNeeded
+= WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2946 NULL
, 0, NULL
, NULL
);
2947 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2949 if (info
->symbolicLink
)
2950 WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2951 DeviceInterfaceDetailData
->DevicePath
,
2952 DeviceInterfaceDetailDataSize
-
2953 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
2956 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2957 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2958 *DeviceInfoData
= *info
->device
;
2964 *RequiredSize
= bytesNeeded
;
2965 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2970 /***********************************************************************
2971 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2973 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
2974 HDEVINFO DeviceInfoSet
,
2975 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2976 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
2977 DWORD DeviceInterfaceDetailDataSize
,
2978 PDWORD RequiredSize
,
2979 PSP_DEVINFO_DATA DeviceInfoData
)
2981 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2982 struct InterfaceInfo
*info
;
2983 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
2984 + sizeof(WCHAR
); /* include NULL terminator */
2987 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2988 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2989 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2991 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2992 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2994 SetLastError(ERROR_INVALID_HANDLE
);
2997 if (!DeviceInterfaceData
||
2998 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2999 !DeviceInterfaceData
->Reserved
)
3001 SetLastError(ERROR_INVALID_PARAMETER
);
3004 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
3005 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
) ||
3006 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
)))
3008 SetLastError(ERROR_INVALID_USER_BUFFER
);
3011 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
3013 SetLastError(ERROR_INVALID_USER_BUFFER
);
3016 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
3017 if (info
->symbolicLink
)
3018 bytesNeeded
+= sizeof(WCHAR
)*lstrlenW(info
->symbolicLink
);
3019 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
3021 if (info
->symbolicLink
)
3022 lstrcpyW(DeviceInterfaceDetailData
->DevicePath
, info
->symbolicLink
);
3024 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
3025 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
3026 *DeviceInfoData
= *info
->device
;
3032 *RequiredSize
= bytesNeeded
;
3033 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3038 struct PropertyMapEntry
3045 static const struct PropertyMapEntry PropertyMap
[] = {
3046 { REG_SZ
, "DeviceDesc", DeviceDesc
},
3047 { REG_MULTI_SZ
, "HardwareId", HardwareId
},
3048 { REG_MULTI_SZ
, "CompatibleIDs", CompatibleIDs
},
3049 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
3050 { REG_SZ
, "Service", Service
},
3051 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
3052 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
3053 { REG_SZ
, "Class", Class
},
3054 { REG_SZ
, "ClassGUID", ClassGUID
},
3055 { REG_SZ
, "Driver", Driver
},
3056 { REG_DWORD
, "ConfigFlags", ConfigFlags
},
3057 { REG_SZ
, "Mfg", Mfg
},
3058 { REG_SZ
, "FriendlyName", FriendlyName
},
3059 { REG_SZ
, "LocationInformation", LocationInformation
},
3060 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3061 { REG_DWORD
, "Capabilities", Capabilities
},
3062 { REG_DWORD
, "UINumber", UINumber
},
3063 { REG_MULTI_SZ
, "UpperFilters", UpperFilters
},
3064 { REG_MULTI_SZ
, "LowerFilters", LowerFilters
},
3067 /***********************************************************************
3068 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3070 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
3071 HDEVINFO DeviceInfoSet
,
3072 PSP_DEVINFO_DATA DeviceInfoData
,
3074 PDWORD PropertyRegDataType
,
3075 PBYTE PropertyBuffer
,
3076 DWORD PropertyBufferSize
,
3077 PDWORD RequiredSize
)
3080 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3081 struct DeviceInfo
*devInfo
;
3083 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3084 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3087 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3089 SetLastError(ERROR_INVALID_HANDLE
);
3092 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3094 SetLastError(ERROR_INVALID_HANDLE
);
3097 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3098 || !DeviceInfoData
->Reserved
)
3100 SetLastError(ERROR_INVALID_PARAMETER
);
3103 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
3105 SetLastError(ERROR_INVALID_DATA
);
3108 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3109 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3110 && PropertyMap
[Property
].nameA
)
3112 DWORD size
= PropertyBufferSize
;
3113 LONG l
= RegQueryValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
,
3114 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3116 if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3117 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3123 *RequiredSize
= size
;
3128 /***********************************************************************
3129 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3131 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3132 HDEVINFO DeviceInfoSet
,
3133 PSP_DEVINFO_DATA DeviceInfoData
,
3135 PDWORD PropertyRegDataType
,
3136 PBYTE PropertyBuffer
,
3137 DWORD PropertyBufferSize
,
3138 PDWORD RequiredSize
)
3141 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3142 struct DeviceInfo
*devInfo
;
3144 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3145 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3148 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3150 SetLastError(ERROR_INVALID_HANDLE
);
3153 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3155 SetLastError(ERROR_INVALID_HANDLE
);
3158 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3159 || !DeviceInfoData
->Reserved
)
3161 SetLastError(ERROR_INVALID_PARAMETER
);
3164 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
3166 SetLastError(ERROR_INVALID_DATA
);
3169 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3170 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3171 && PropertyMap
[Property
].nameW
)
3173 DWORD size
= PropertyBufferSize
;
3174 LONG l
= RegQueryValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
,
3175 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3177 if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3178 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3184 *RequiredSize
= size
;
3189 /***********************************************************************
3190 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3192 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3193 HDEVINFO DeviceInfoSet
,
3194 PSP_DEVINFO_DATA DeviceInfoData
,
3196 const BYTE
*PropertyBuffer
,
3197 DWORD PropertyBufferSize
)
3200 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3201 struct DeviceInfo
*devInfo
;
3203 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3204 PropertyBuffer
, PropertyBufferSize
);
3206 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3208 SetLastError(ERROR_INVALID_HANDLE
);
3211 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3213 SetLastError(ERROR_INVALID_HANDLE
);
3216 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3217 || !DeviceInfoData
->Reserved
)
3219 SetLastError(ERROR_INVALID_PARAMETER
);
3222 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3223 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3224 && PropertyMap
[Property
].nameA
)
3226 LONG l
= RegSetValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
, 0,
3227 PropertyMap
[Property
].regType
, PropertyBuffer
,
3228 PropertyBufferSize
);
3237 /***********************************************************************
3238 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3240 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
3241 HDEVINFO DeviceInfoSet
,
3242 PSP_DEVINFO_DATA DeviceInfoData
,
3244 const BYTE
*PropertyBuffer
,
3245 DWORD PropertyBufferSize
)
3248 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3249 struct DeviceInfo
*devInfo
;
3251 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3252 PropertyBuffer
, PropertyBufferSize
);
3254 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3256 SetLastError(ERROR_INVALID_HANDLE
);
3259 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3261 SetLastError(ERROR_INVALID_HANDLE
);
3264 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3265 || !DeviceInfoData
->Reserved
)
3267 SetLastError(ERROR_INVALID_PARAMETER
);
3270 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3271 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3272 && PropertyMap
[Property
].nameW
)
3274 LONG l
= RegSetValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
, 0,
3275 PropertyMap
[Property
].regType
, PropertyBuffer
,
3276 PropertyBufferSize
);
3285 /***********************************************************************
3286 * SetupDiInstallClassA (SETUPAPI.@)
3288 BOOL WINAPI
SetupDiInstallClassA(
3294 UNICODE_STRING FileNameW
;
3299 SetLastError(ERROR_INVALID_PARAMETER
);
3302 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW
, InfFileName
))
3304 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3308 Result
= SetupDiInstallClassW(hwndParent
, FileNameW
.Buffer
, Flags
, FileQueue
);
3310 RtlFreeUnicodeString(&FileNameW
);
3315 static HKEY
CreateClassKey(HINF hInf
)
3317 static const WCHAR slash
[] = { '\\',0 };
3318 WCHAR FullBuffer
[MAX_PATH
];
3319 WCHAR Buffer
[MAX_PATH
];
3323 if (!SetupGetLineTextW(NULL
,
3331 return INVALID_HANDLE_VALUE
;
3334 lstrcpyW(FullBuffer
, ControlClass
);
3335 lstrcatW(FullBuffer
, slash
);
3336 lstrcatW(FullBuffer
, Buffer
);
3338 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3344 if (!SetupGetLineTextW(NULL
,
3352 return INVALID_HANDLE_VALUE
;
3355 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3359 REG_OPTION_NON_VOLATILE
,
3365 return INVALID_HANDLE_VALUE
;
3370 if (RegSetValueExW(hClassKey
,
3375 RequiredSize
* sizeof(WCHAR
)))
3377 RegCloseKey(hClassKey
);
3378 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3380 return INVALID_HANDLE_VALUE
;
3386 /***********************************************************************
3387 * SetupDiInstallClassW (SETUPAPI.@)
3389 BOOL WINAPI
SetupDiInstallClassW(
3395 WCHAR SectionName
[MAX_PATH
];
3396 DWORD SectionNameLength
= 0;
3398 BOOL bFileQueueCreated
= FALSE
;
3406 SetLastError(ERROR_INVALID_PARAMETER
);
3409 if ((Flags
& DI_NOVCP
) && (FileQueue
== NULL
|| FileQueue
== INVALID_HANDLE_VALUE
))
3411 SetLastError(ERROR_INVALID_PARAMETER
);
3415 /* Open the .inf file */
3416 hInf
= SetupOpenInfFileW(InfFileName
,
3420 if (hInf
== INVALID_HANDLE_VALUE
)
3426 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3427 hClassKey
= CreateClassKey(hInf
);
3428 if (hClassKey
== INVALID_HANDLE_VALUE
)
3430 SetupCloseInfFile(hInf
);
3435 /* Try to append a layout file */
3436 SetupOpenAppendInfFileW(NULL
, hInf
, NULL
);
3438 /* Retrieve the actual section name */
3439 SetupDiGetActualSectionToInstallW(hInf
,
3447 if (!(Flags
& DI_NOVCP
))
3449 FileQueue
= SetupOpenFileQueue();
3450 if (FileQueue
== INVALID_HANDLE_VALUE
)
3452 SetupCloseInfFile(hInf
);
3456 bFileQueueCreated
= TRUE
;
3461 SetupInstallFromInfSectionW(NULL
,
3464 SPINST_COPYINF
| SPINST_FILES
| SPINST_REGISTRY
,
3470 INVALID_HANDLE_VALUE
,
3473 /* FIXME: More code! */
3475 if (bFileQueueCreated
)
3476 SetupCloseFileQueue(FileQueue
);
3478 SetupCloseInfFile(hInf
);
3484 /***********************************************************************
3485 * SetupDiOpenClassRegKey (SETUPAPI.@)
3487 HKEY WINAPI
SetupDiOpenClassRegKey(
3488 const GUID
* ClassGuid
,
3491 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3492 DIOCR_INSTALLER
, NULL
, NULL
);
3496 /***********************************************************************
3497 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3499 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3500 const GUID
* ClassGuid
,
3506 PWSTR MachineNameW
= NULL
;
3513 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
3514 if (MachineNameW
== NULL
)
3515 return INVALID_HANDLE_VALUE
;
3518 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3519 Flags
, MachineNameW
, Reserved
);
3521 MyFree(MachineNameW
);
3527 /***********************************************************************
3528 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3530 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3531 const GUID
* ClassGuid
,
3542 if (MachineName
&& *MachineName
)
3544 FIXME("Remote access not supported yet!\n");
3545 return INVALID_HANDLE_VALUE
;
3548 if (Flags
== DIOCR_INSTALLER
)
3550 lpKeyName
= ControlClass
;
3552 else if (Flags
== DIOCR_INTERFACE
)
3554 lpKeyName
= DeviceClasses
;
3558 ERR("Invalid Flags parameter!\n");
3559 SetLastError(ERROR_INVALID_PARAMETER
);
3560 return INVALID_HANDLE_VALUE
;
3565 if ((l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3572 hClassesKey
= INVALID_HANDLE_VALUE
;
3578 WCHAR bracedGuidString
[39];
3580 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3582 if (!(l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3588 if ((l
= RegOpenKeyExW(hClassesKey
,
3595 key
= INVALID_HANDLE_VALUE
;
3597 RegCloseKey(hClassesKey
);
3602 key
= INVALID_HANDLE_VALUE
;
3608 /***********************************************************************
3609 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3611 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3612 HDEVINFO DeviceInfoSet
,
3615 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3617 FIXME("%p %s %08x %p\n",
3618 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3622 /***********************************************************************
3623 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3625 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
3626 HDEVINFO DeviceInfoSet
,
3629 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3631 FIXME("%p %s %08x %p\n", DeviceInfoSet
,
3632 debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3636 /***********************************************************************
3637 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3639 BOOL WINAPI
SetupDiSetClassInstallParamsA(
3640 HDEVINFO DeviceInfoSet
,
3641 PSP_DEVINFO_DATA DeviceInfoData
,
3642 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3643 DWORD ClassInstallParamsSize
)
3645 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3646 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3650 /***********************************************************************
3651 * SetupDiCallClassInstaller (SETUPAPI.@)
3653 BOOL WINAPI
SetupDiCallClassInstaller(
3654 DI_FUNCTION InstallFunction
,
3655 HDEVINFO DeviceInfoSet
,
3656 PSP_DEVINFO_DATA DeviceInfoData
)
3658 FIXME("%d %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3662 /***********************************************************************
3663 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
3665 BOOL WINAPI
SetupDiGetDeviceInstallParamsW(
3666 HDEVINFO DeviceInfoSet
,
3667 PSP_DEVINFO_DATA DeviceInfoData
,
3668 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
3670 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3674 /***********************************************************************
3675 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3677 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
3678 HDEVINFO DeviceInfoSet
,
3679 PSP_DEVINFO_DATA DeviceInfoData
,
3680 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3682 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3686 /***********************************************************************
3687 * SetupDiSetDeviceInstallParamsA (SETUPAPI.@)
3689 BOOL WINAPI
SetupDiSetDeviceInstallParamsA(
3690 HDEVINFO DeviceInfoSet
,
3691 PSP_DEVINFO_DATA DeviceInfoData
,
3692 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3694 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3699 static HKEY
SETUPDI_OpenDevKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3701 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
3704 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3705 NULL
, &enumKey
, NULL
);
3708 RegOpenKeyExW(enumKey
, devInfo
->instanceId
, 0, samDesired
, &key
);
3709 RegCloseKey(enumKey
);
3714 static HKEY
SETUPDI_OpenDrvKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3716 static const WCHAR slash
[] = { '\\',0 };
3717 WCHAR classKeyPath
[MAX_PATH
];
3718 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
3721 lstrcpyW(classKeyPath
, ControlClass
);
3722 lstrcatW(classKeyPath
, slash
);
3723 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3724 classKeyPath
+ lstrlenW(classKeyPath
));
3725 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3726 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3729 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3732 sprintfW(devId
, fmt
, devInfo
->devId
);
3733 l
= RegOpenKeyExW(classKey
, devId
, 0, samDesired
, &key
);
3734 RegCloseKey(classKey
);
3737 SetLastError(ERROR_KEY_DOES_NOT_EXIST
);
3738 return INVALID_HANDLE_VALUE
;
3744 /***********************************************************************
3745 * SetupDiOpenDevRegKey (SETUPAPI.@)
3747 HKEY WINAPI
SetupDiOpenDevRegKey(
3748 HDEVINFO DeviceInfoSet
,
3749 PSP_DEVINFO_DATA DeviceInfoData
,
3755 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3756 struct DeviceInfo
*devInfo
;
3757 HKEY key
= INVALID_HANDLE_VALUE
;
3759 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
3760 Scope
, HwProfile
, KeyType
, samDesired
);
3762 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3764 SetLastError(ERROR_INVALID_HANDLE
);
3765 return INVALID_HANDLE_VALUE
;
3767 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3769 SetLastError(ERROR_INVALID_HANDLE
);
3770 return INVALID_HANDLE_VALUE
;
3772 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3773 || !DeviceInfoData
->Reserved
)
3775 SetLastError(ERROR_INVALID_PARAMETER
);
3776 return INVALID_HANDLE_VALUE
;
3778 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3780 SetLastError(ERROR_INVALID_FLAGS
);
3781 return INVALID_HANDLE_VALUE
;
3783 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
3785 SetLastError(ERROR_INVALID_FLAGS
);
3786 return INVALID_HANDLE_VALUE
;
3788 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3789 if (devInfo
->set
!= set
)
3791 SetLastError(ERROR_INVALID_PARAMETER
);
3792 return INVALID_HANDLE_VALUE
;
3794 if (devInfo
->phantom
)
3796 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3797 return INVALID_HANDLE_VALUE
;
3799 if (Scope
!= DICS_FLAG_GLOBAL
)
3800 FIXME("unimplemented for scope %d\n", Scope
);
3804 key
= SETUPDI_OpenDevKey(devInfo
, samDesired
);
3807 key
= SETUPDI_OpenDrvKey(devInfo
, samDesired
);
3810 WARN("unknown KeyType %d\n", KeyType
);
3815 static BOOL
SETUPDI_DeleteDevKey(struct DeviceInfo
*devInfo
)
3821 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3822 NULL
, &enumKey
, NULL
);
3825 ret
= RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
3826 RegCloseKey(enumKey
);
3833 static BOOL
SETUPDI_DeleteDrvKey(struct DeviceInfo
*devInfo
)
3835 static const WCHAR slash
[] = { '\\',0 };
3836 WCHAR classKeyPath
[MAX_PATH
];
3841 lstrcpyW(classKeyPath
, ControlClass
);
3842 lstrcatW(classKeyPath
, slash
);
3843 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3844 classKeyPath
+ lstrlenW(classKeyPath
));
3845 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3846 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3849 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3852 sprintfW(devId
, fmt
, devInfo
->devId
);
3853 ret
= RegDeleteTreeW(classKey
, devId
);
3854 RegCloseKey(classKey
);
3861 /***********************************************************************
3862 * SetupDiDeleteDevRegKey (SETUPAPI.@)
3864 BOOL WINAPI
SetupDiDeleteDevRegKey(
3865 HDEVINFO DeviceInfoSet
,
3866 PSP_DEVINFO_DATA DeviceInfoData
,
3871 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3872 struct DeviceInfo
*devInfo
;
3875 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
3878 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3880 SetLastError(ERROR_INVALID_HANDLE
);
3883 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3885 SetLastError(ERROR_INVALID_HANDLE
);
3888 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3889 || !DeviceInfoData
->Reserved
)
3891 SetLastError(ERROR_INVALID_PARAMETER
);
3894 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3896 SetLastError(ERROR_INVALID_FLAGS
);
3899 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
3901 SetLastError(ERROR_INVALID_FLAGS
);
3904 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3905 if (devInfo
->set
!= set
)
3907 SetLastError(ERROR_INVALID_PARAMETER
);
3910 if (devInfo
->phantom
)
3912 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3915 if (Scope
!= DICS_FLAG_GLOBAL
)
3916 FIXME("unimplemented for scope %d\n", Scope
);
3920 ret
= SETUPDI_DeleteDevKey(devInfo
);
3923 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3926 ret
= SETUPDI_DeleteDevKey(devInfo
);
3928 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3931 WARN("unknown KeyType %d\n", KeyType
);
3936 /***********************************************************************
3937 * CM_Get_Device_IDA (SETUPAPI.@)
3939 CONFIGRET WINAPI
CM_Get_Device_IDA( DEVINST dnDevInst
, PSTR Buffer
,
3940 ULONG BufferLen
, ULONG ulFlags
)
3942 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
3944 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
3947 return CR_NO_SUCH_DEVINST
;
3949 WideCharToMultiByte(CP_ACP
, 0, devInfo
->instanceId
, -1, Buffer
, BufferLen
, 0, 0);
3950 TRACE("Returning %s\n", debugstr_a(Buffer
));
3954 /***********************************************************************
3955 * CM_Get_Device_IDW (SETUPAPI.@)
3957 CONFIGRET WINAPI
CM_Get_Device_IDW( DEVINST dnDevInst
, LPWSTR Buffer
,
3958 ULONG BufferLen
, ULONG ulFlags
)
3960 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
3962 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
3966 WARN("dev instance %d not found!\n", dnDevInst
);
3967 return CR_NO_SUCH_DEVINST
;
3970 lstrcpynW(Buffer
, devInfo
->instanceId
, BufferLen
);
3971 TRACE("Returning %s\n", debugstr_w(Buffer
));
3972 GlobalUnlock((HANDLE
)dnDevInst
);
3978 /***********************************************************************
3979 * CM_Get_Device_ID_Size (SETUPAPI.@)
3981 CONFIGRET WINAPI
CM_Get_Device_ID_Size( PULONG pulLen
, DEVINST dnDevInst
,
3984 struct DeviceInfo
*ppdevInfo
= GlobalLock((HANDLE
)dnDevInst
);
3986 TRACE("%x->%p, %p, %u\n", dnDevInst
, ppdevInfo
, pulLen
, ulFlags
);
3990 WARN("dev instance %d not found!\n", dnDevInst
);
3991 return CR_NO_SUCH_DEVINST
;
3994 *pulLen
= lstrlenW(ppdevInfo
->instanceId
);
3995 GlobalUnlock((HANDLE
)dnDevInst
);
3999 /***********************************************************************
4000 * SetupDiGetINFClassA (SETUPAPI.@)
4002 BOOL WINAPI
SetupDiGetINFClassA(PCSTR inf
, LPGUID class_guid
, PSTR class_name
,
4003 DWORD size
, PDWORD required_size
)
4006 DWORD required_sizeA
, required_sizeW
;
4007 PWSTR class_nameW
= NULL
;
4008 UNICODE_STRING infW
;
4012 if (!RtlCreateUnicodeStringFromAsciiz(&infW
, inf
))
4014 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4021 if (class_name
&& size
)
4023 if (!(class_nameW
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
))))
4025 RtlFreeUnicodeString(&infW
);
4026 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4031 retval
= SetupDiGetINFClassW(infW
.Buffer
, class_guid
, class_nameW
, size
, &required_sizeW
);
4035 required_sizeA
= WideCharToMultiByte( CP_ACP
, 0, class_nameW
, required_sizeW
,
4036 class_name
, size
, NULL
, NULL
);
4038 if(required_size
) *required_size
= required_sizeA
;
4041 if(required_size
) *required_size
= required_sizeW
;
4043 HeapFree(GetProcessHeap(), 0, class_nameW
);
4044 RtlFreeUnicodeString(&infW
);
4048 /***********************************************************************
4049 * SetupDiGetINFClassW (SETUPAPI.@)
4051 BOOL WINAPI
SetupDiGetINFClassW(PCWSTR inf
, LPGUID class_guid
, PWSTR class_name
,
4052 DWORD size
, PDWORD required_size
)
4054 BOOL have_guid
, have_name
;
4056 WCHAR buffer
[MAX_PATH
];
4060 SetLastError(ERROR_INVALID_PARAMETER
);
4064 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(inf
))
4066 FIXME("%s not found. Searching via DevicePath not implemented\n", debugstr_w(inf
));
4067 SetLastError(ERROR_FILE_NOT_FOUND
);
4071 if (!class_guid
|| !class_name
|| !size
)
4073 SetLastError(ERROR_INVALID_PARAMETER
);
4077 if (!GetPrivateProfileStringW(Version
, Signature
, NULL
, buffer
, MAX_PATH
, inf
))
4080 if (lstrcmpiW(buffer
, Chicago
) && lstrcmpiW(buffer
, WindowsNT
))
4084 have_guid
= 0 < GetPrivateProfileStringW(Version
, ClassGUID
, NULL
, buffer
, MAX_PATH
, inf
);
4087 buffer
[lstrlenW(buffer
)-1] = 0;
4088 if (RPC_S_OK
!= UuidFromStringW(buffer
+ 1, class_guid
))
4090 FIXME("failed to convert \"%s\" into a guid\n", debugstr_w(buffer
));
4091 SetLastError(ERROR_INVALID_PARAMETER
);
4097 dret
= GetPrivateProfileStringW(Version
, Class
, NULL
, buffer
, MAX_PATH
, inf
);
4098 have_name
= 0 < dret
;
4100 if (dret
>= MAX_PATH
-1) FIXME("buffer might be too small\n");
4101 if (have_guid
&& !have_name
) FIXME("class name lookup via guid not implemented\n");
4105 if (dret
< size
) lstrcpyW(class_name
, buffer
);
4108 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4113 if (required_size
) *required_size
= dret
+ ((dret
) ? 1 : 0);
4115 return (have_guid
|| have_name
);