2 * SetupAPI device installer
4 * Copyright 2000 Andreas Mohr for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
35 #include "wine/debug.h"
36 #include "wine/list.h"
37 #include "wine/unicode.h"
43 #include "setupapi_private.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
48 /* Unicode constants */
49 static const WCHAR Chicago
[] = {'$','C','h','i','c','a','g','o','$',0};
50 static const WCHAR ClassGUID
[] = {'C','l','a','s','s','G','U','I','D',0};
51 static const WCHAR Class
[] = {'C','l','a','s','s',0};
52 static const WCHAR ClassInstall32
[] = {'C','l','a','s','s','I','n','s','t','a','l','l','3','2',0};
53 static const WCHAR NoDisplayClass
[] = {'N','o','D','i','s','p','l','a','y','C','l','a','s','s',0};
54 static const WCHAR NoInstallClass
[] = {'N','o','I','n','s','t','a','l','l','C','l','a','s','s',0};
55 static const WCHAR NoUseClass
[] = {'N','o','U','s','e','C','l','a','s','s',0};
56 static const WCHAR NtExtension
[] = {'.','N','T',0};
57 static const WCHAR NtPlatformExtension
[] = {'.','N','T','x','8','6',0};
58 static const WCHAR Signature
[] = {'S','i','g','n','a','t','u','r','e',0};
59 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
60 static const WCHAR WinExtension
[] = {'.','W','i','n',0};
61 static const WCHAR WindowsNT
[] = {'$','W','i','n','d','o','w','s',' ','N','T','$',0};
63 /* Registry key and value names */
64 static const WCHAR ControlClass
[] = {'S','y','s','t','e','m','\\',
65 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
66 'C','o','n','t','r','o','l','\\',
67 'C','l','a','s','s',0};
69 static const WCHAR DeviceClasses
[] = {'S','y','s','t','e','m','\\',
70 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
71 'C','o','n','t','r','o','l','\\',
72 'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
73 static const WCHAR Enum
[] = {'S','y','s','t','e','m','\\',
74 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
76 static const WCHAR DeviceDesc
[] = {'D','e','v','i','c','e','D','e','s','c',0};
77 static const WCHAR DeviceInstance
[] = {'D','e','v','i','c','e','I','n','s','t','a','n','c','e',0};
78 static const WCHAR HardwareId
[] = {'H','a','r','d','w','a','r','e','I','D',0};
79 static const WCHAR CompatibleIDs
[] = {'C','o','m','p','a','t','i','b','l','e','I','d','s',0};
80 static const WCHAR Service
[] = {'S','e','r','v','i','c','e',0};
81 static const WCHAR Driver
[] = {'D','r','i','v','e','r',0};
82 static const WCHAR ConfigFlags
[] = {'C','o','n','f','i','g','F','l','a','g','s',0};
83 static const WCHAR Mfg
[] = {'M','f','g',0};
84 static const WCHAR FriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
85 static const WCHAR LocationInformation
[] = {'L','o','c','a','t','i','o','n','I','n','f','o','r','m','a','t','i','o','n',0};
86 static const WCHAR Capabilities
[] = {'C','a','p','a','b','i','l','i','t','i','e','s',0};
87 static const WCHAR UINumber
[] = {'U','I','N','u','m','b','e','r',0};
88 static const WCHAR UpperFilters
[] = {'U','p','p','e','r','F','i','l','t','e','r','s',0};
89 static const WCHAR LowerFilters
[] = {'L','o','w','e','r','F','i','l','t','e','r','s',0};
90 static const WCHAR Phantom
[] = {'P','h','a','n','t','o','m',0};
91 static const WCHAR SymbolicLink
[] = {'S','y','m','b','o','l','i','c','L','i','n','k',0};
93 /* is used to identify if a DeviceInfoSet pointer is
95 #define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff056
99 DWORD magic
; /* if is equal to SETUP_DEVICE_INFO_SET_MAGIC struct is okay */
106 struct DeviceInstance
109 SP_DEVINFO_DATA data
;
112 /* Pointed to by SP_DEVICE_INTERFACE_DATA's Reserved member */
115 LPWSTR referenceString
;
117 PSP_DEVINFO_DATA device
;
120 /* A device may have multiple instances of the same interface, so this holds
121 * each instance belonging to a particular interface.
123 struct InterfaceInstances
127 DWORD cInstancesAllocated
;
128 SP_DEVICE_INTERFACE_DATA
*instances
;
132 /* Pointed to by SP_DEVINFO_DATA's Reserved member */
135 struct DeviceInfoSet
*set
;
140 struct list interfaces
;
143 static void SETUPDI_GuidToString(const GUID
*guid
, LPWSTR guidStr
)
145 static const WCHAR fmt
[] = {'{','%','0','8','X','-','%','0','4','X','-',
146 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
147 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
150 sprintfW(guidStr
, fmt
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
151 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
152 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
155 static void SETUPDI_FreeInterfaceInstances(struct InterfaceInstances
*instances
)
159 for (i
= 0; i
< instances
->cInstances
; i
++)
161 struct InterfaceInfo
*ifaceInfo
=
162 (struct InterfaceInfo
*)instances
->instances
[i
].Reserved
;
164 if (ifaceInfo
->device
&& ifaceInfo
->device
->Reserved
)
166 struct DeviceInfo
*devInfo
=
167 (struct DeviceInfo
*)ifaceInfo
->device
->Reserved
;
169 if (devInfo
->phantom
)
170 SetupDiDeleteDeviceInterfaceRegKey(devInfo
->set
,
171 &instances
->instances
[i
], 0);
173 HeapFree(GetProcessHeap(), 0, ifaceInfo
->referenceString
);
174 HeapFree(GetProcessHeap(), 0, ifaceInfo
->symbolicLink
);
175 HeapFree(GetProcessHeap(), 0, ifaceInfo
);
177 HeapFree(GetProcessHeap(), 0, instances
->instances
);
180 /* Finds the interface with interface class InterfaceClassGuid in the device.
181 * Returns TRUE if found, and updates *interface to point to device's
182 * interfaces member where the given interface was found.
183 * Returns FALSE if not found.
185 static BOOL
SETUPDI_FindInterface(const struct DeviceInfo
*devInfo
,
186 const GUID
*InterfaceClassGuid
, struct InterfaceInstances
**iface_ret
)
189 struct InterfaceInstances
*iface
;
191 TRACE("%s\n", debugstr_guid(InterfaceClassGuid
));
193 LIST_FOR_EACH_ENTRY(iface
, &devInfo
->interfaces
, struct InterfaceInstances
,
196 if (IsEqualGUID(&iface
->guid
, InterfaceClassGuid
))
203 TRACE("returning %d (%p)\n", found
, found
? *iface_ret
: NULL
);
207 /* Finds the interface instance with reference string ReferenceString in the
208 * interface instance map. Returns TRUE if found, and updates instanceIndex to
209 * the index of the interface instance's instances member
210 * where the given instance was found. Returns FALSE if not found.
212 static BOOL
SETUPDI_FindInterfaceInstance(
213 const struct InterfaceInstances
*instances
,
214 LPCWSTR ReferenceString
, DWORD
*instanceIndex
)
219 TRACE("%s\n", debugstr_w(ReferenceString
));
221 for (i
= 0; !found
&& i
< instances
->cInstances
; i
++)
223 SP_DEVICE_INTERFACE_DATA
*ifaceData
= &instances
->instances
[i
];
224 struct InterfaceInfo
*ifaceInfo
=
225 (struct InterfaceInfo
*)ifaceData
->Reserved
;
227 if (!ReferenceString
&& !ifaceInfo
->referenceString
)
232 else if (ReferenceString
&& ifaceInfo
->referenceString
&&
233 !lstrcmpiW(ifaceInfo
->referenceString
, ReferenceString
))
239 TRACE("returning %d (%d)\n", found
, found
? *instanceIndex
: 0);
243 static LPWSTR
SETUPDI_CreateSymbolicLinkPath(LPCWSTR instanceId
,
244 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
)
246 static const WCHAR fmt
[] = {'\\','\\','?','\\','%','s','#','%','s',0};
251 SETUPDI_GuidToString(InterfaceClassGuid
, guidStr
);
252 /* omit length of format specifiers, but include NULL terminator: */
253 len
= lstrlenW(fmt
) - 4 + 1;
254 len
+= lstrlenW(instanceId
) + lstrlenW(guidStr
);
255 if (ReferenceString
&& *ReferenceString
)
257 /* space for a hash between string and reference string: */
258 len
+= lstrlenW(ReferenceString
) + 1;
260 ret
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
263 int printed
= sprintfW(ret
, fmt
, instanceId
, guidStr
);
266 /* replace '\\' with '#' after the "\\\\?\\" beginning */
267 for (ptr
= strchrW(ret
+ 4, '\\'); ptr
; ptr
= strchrW(ptr
+ 1, '\\'))
269 if (ReferenceString
&& *ReferenceString
)
272 lstrcpyW(ret
+ printed
+ 1, ReferenceString
);
278 /* Adds an interface with the given interface class and reference string to
279 * the device, if it doesn't already exist in the device. If iface is not
280 * NULL, returns a pointer to the newly added (or already existing) interface.
282 static BOOL
SETUPDI_AddInterfaceInstance(PSP_DEVINFO_DATA DeviceInfoData
,
283 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
,
284 SP_DEVICE_INTERFACE_DATA
**ifaceData
)
286 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
287 BOOL newInterface
= FALSE
, ret
;
288 struct InterfaceInstances
*iface
= NULL
;
290 TRACE("%p %s %s %p\n", devInfo
, debugstr_guid(InterfaceClassGuid
),
291 debugstr_w(ReferenceString
), iface
);
293 if (!(ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
295 iface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
296 sizeof(struct InterfaceInstances
));
299 list_add_tail(&devInfo
->interfaces
, &iface
->entry
);
305 DWORD instanceIndex
= 0;
307 if (!(ret
= SETUPDI_FindInterfaceInstance(iface
, ReferenceString
,
310 SP_DEVICE_INTERFACE_DATA
*instance
= NULL
;
312 if (!iface
->cInstancesAllocated
)
314 iface
->instances
= HeapAlloc(GetProcessHeap(), 0,
315 sizeof(SP_DEVICE_INTERFACE_DATA
));
316 if (iface
->instances
)
317 instance
= &iface
->instances
[iface
->cInstancesAllocated
++];
319 else if (iface
->cInstances
== iface
->cInstancesAllocated
)
321 iface
->instances
= HeapReAlloc(GetProcessHeap(), 0,
323 (iface
->cInstancesAllocated
+ 1) *
324 sizeof(SP_DEVICE_INTERFACE_DATA
));
325 if (iface
->instances
)
326 instance
= &iface
->instances
[iface
->cInstancesAllocated
++];
329 instance
= &iface
->instances
[iface
->cInstances
];
332 struct InterfaceInfo
*ifaceInfo
= HeapAlloc(GetProcessHeap(),
333 0, sizeof(struct InterfaceInfo
));
338 ifaceInfo
->device
= DeviceInfoData
;
339 ifaceInfo
->symbolicLink
= SETUPDI_CreateSymbolicLinkPath(
340 devInfo
->instanceId
, InterfaceClassGuid
,
344 ifaceInfo
->referenceString
=
345 HeapAlloc(GetProcessHeap(), 0,
346 (lstrlenW(ReferenceString
) + 1) *
348 if (ifaceInfo
->referenceString
)
349 lstrcpyW(ifaceInfo
->referenceString
,
355 ifaceInfo
->referenceString
= NULL
;
362 sizeof(SP_DEVICE_INTERFACE_DATA
);
363 instance
->InterfaceClassGuid
= *InterfaceClassGuid
;
364 instance
->Flags
= SPINT_ACTIVE
; /* FIXME */
365 instance
->Reserved
= (ULONG_PTR
)ifaceInfo
;
367 iface
->guid
= *InterfaceClassGuid
;
368 key
= SetupDiCreateDeviceInterfaceRegKeyW(devInfo
->set
,
369 instance
, 0, KEY_WRITE
, NULL
, NULL
);
370 if (key
!= INVALID_HANDLE_VALUE
)
372 RegSetValueExW(key
, SymbolicLink
, 0, REG_SZ
,
373 (BYTE
*)ifaceInfo
->symbolicLink
,
374 lstrlenW(ifaceInfo
->symbolicLink
) *
379 *ifaceData
= instance
;
382 HeapFree(GetProcessHeap(), 0, ifaceInfo
);
389 *ifaceData
= &iface
->instances
[instanceIndex
];
394 TRACE("returning %d\n", ret
);
398 static BOOL
SETUPDI_SetInterfaceSymbolicLink(SP_DEVICE_INTERFACE_DATA
*iface
,
399 LPCWSTR symbolicLink
)
401 struct InterfaceInfo
*info
= (struct InterfaceInfo
*)iface
->Reserved
;
406 HeapFree(GetProcessHeap(), 0, info
->symbolicLink
);
407 info
->symbolicLink
= HeapAlloc(GetProcessHeap(), 0,
408 (lstrlenW(symbolicLink
) + 1) * sizeof(WCHAR
));
409 if (info
->symbolicLink
)
411 lstrcpyW(info
->symbolicLink
, symbolicLink
);
418 static HKEY
SETUPDI_CreateDevKey(struct DeviceInfo
*devInfo
)
420 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
423 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
424 NULL
, &enumKey
, NULL
);
427 RegCreateKeyExW(enumKey
, devInfo
->instanceId
, 0, NULL
, 0,
428 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
429 RegCloseKey(enumKey
);
434 static HKEY
SETUPDI_CreateDrvKey(struct DeviceInfo
*devInfo
)
436 static const WCHAR slash
[] = { '\\',0 };
437 WCHAR classKeyPath
[MAX_PATH
];
438 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
441 lstrcpyW(classKeyPath
, ControlClass
);
442 lstrcatW(classKeyPath
, slash
);
443 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
444 classKeyPath
+ lstrlenW(classKeyPath
));
445 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
446 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
449 static const WCHAR fmt
[] = { '%','0','4','u',0 };
452 sprintfW(devId
, fmt
, devInfo
->devId
);
453 RegCreateKeyExW(classKey
, devId
, 0, NULL
, 0, KEY_READ
| KEY_WRITE
,
455 RegCloseKey(classKey
);
460 static struct DeviceInfo
*SETUPDI_AllocateDeviceInfo(struct DeviceInfoSet
*set
,
461 DWORD devId
, LPCWSTR instanceId
, BOOL phantom
)
463 struct DeviceInfo
*devInfo
= NULL
;
464 HANDLE devInst
= GlobalAlloc(GMEM_FIXED
, sizeof(struct DeviceInfo
));
466 devInfo
= GlobalLock(devInst
);
471 devInfo
->devId
= (DWORD
)devInst
;
473 devInfo
->instanceId
= HeapAlloc(GetProcessHeap(), 0,
474 (lstrlenW(instanceId
) + 1) * sizeof(WCHAR
));
475 if (devInfo
->instanceId
)
477 devInfo
->key
= INVALID_HANDLE_VALUE
;
478 devInfo
->phantom
= phantom
;
479 lstrcpyW(devInfo
->instanceId
, instanceId
);
480 struprW(devInfo
->instanceId
);
481 devInfo
->key
= SETUPDI_CreateDevKey(devInfo
);
482 if (devInfo
->key
!= INVALID_HANDLE_VALUE
)
485 RegSetValueExW(devInfo
->key
, Phantom
, 0, REG_DWORD
,
486 (LPBYTE
)&phantom
, sizeof(phantom
));
488 list_init(&devInfo
->interfaces
);
489 GlobalUnlock(devInst
);
493 GlobalUnlock(devInst
);
501 static void SETUPDI_FreeDeviceInfo(struct DeviceInfo
*devInfo
)
503 struct InterfaceInstances
*iface
, *next
;
505 if (devInfo
->key
!= INVALID_HANDLE_VALUE
)
506 RegCloseKey(devInfo
->key
);
507 if (devInfo
->phantom
)
512 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0,
513 KEY_ALL_ACCESS
, NULL
, &enumKey
, NULL
);
516 RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
517 RegCloseKey(enumKey
);
520 HeapFree(GetProcessHeap(), 0, devInfo
->instanceId
);
521 LIST_FOR_EACH_ENTRY_SAFE(iface
, next
, &devInfo
->interfaces
,
522 struct InterfaceInstances
, entry
)
524 list_remove(&iface
->entry
);
525 SETUPDI_FreeInterfaceInstances(iface
);
526 HeapFree(GetProcessHeap(), 0, iface
);
528 GlobalFree((HANDLE
)devInfo
->devId
);
531 /* Adds a device with GUID guid and identifier devInst to set. Allocates a
532 * struct DeviceInfo, and points the returned device info's Reserved member
533 * to it. "Phantom" devices are deleted from the registry when closed.
534 * Returns a pointer to the newly allocated device info.
536 static BOOL
SETUPDI_AddDeviceToSet(struct DeviceInfoSet
*set
,
541 SP_DEVINFO_DATA
**dev
)
544 struct DeviceInfo
*devInfo
= SETUPDI_AllocateDeviceInfo(set
, set
->cDevices
,
545 instanceId
, phantom
);
547 TRACE("%p, %s, %d, %s, %d\n", set
, debugstr_guid(guid
), dev_inst
,
548 debugstr_w(instanceId
), phantom
);
552 struct DeviceInstance
*devInst
=
553 HeapAlloc(GetProcessHeap(), 0, sizeof(struct DeviceInstance
));
557 WCHAR classGuidStr
[39];
559 list_add_tail(&set
->devices
, &devInst
->entry
);
561 devInst
->data
.cbSize
= sizeof(SP_DEVINFO_DATA
);
562 devInst
->data
.ClassGuid
= *guid
;
563 devInst
->data
.DevInst
= devInfo
->devId
;
564 devInst
->data
.Reserved
= (ULONG_PTR
)devInfo
;
565 SETUPDI_GuidToString(guid
, classGuidStr
);
566 SetupDiSetDeviceRegistryPropertyW(set
, &devInst
->data
,
567 SPDRP_CLASSGUID
, (const BYTE
*)classGuidStr
,
568 lstrlenW(classGuidStr
) * sizeof(WCHAR
));
569 if (dev
) *dev
= &devInst
->data
;
574 HeapFree(GetProcessHeap(), 0, devInfo
);
575 SetLastError(ERROR_OUTOFMEMORY
);
581 /***********************************************************************
582 * SetupDiBuildClassInfoList (SETUPAPI.@)
584 * Returns a list of setup class GUIDs that identify the classes
585 * that are installed on a local machine.
588 * Flags [I] control exclusion of classes from the list.
589 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
590 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
591 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
597 BOOL WINAPI
SetupDiBuildClassInfoList(
599 LPGUID ClassGuidList
,
600 DWORD ClassGuidListSize
,
604 return SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
605 ClassGuidListSize
, RequiredSize
,
609 /***********************************************************************
610 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
612 * Returns a list of setup class GUIDs that identify the classes
613 * that are installed on a local or remote machine.
616 * Flags [I] control exclusion of classes from the list.
617 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
618 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
619 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
620 * MachineName [I] name of a remote machine.
621 * Reserved [I] must be NULL.
627 BOOL WINAPI
SetupDiBuildClassInfoListExA(
629 LPGUID ClassGuidList
,
630 DWORD ClassGuidListSize
,
635 LPWSTR MachineNameW
= NULL
;
642 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
643 if (MachineNameW
== NULL
) return FALSE
;
646 bResult
= SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
647 ClassGuidListSize
, RequiredSize
,
648 MachineNameW
, Reserved
);
650 MyFree(MachineNameW
);
655 /***********************************************************************
656 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
658 * Returns a list of setup class GUIDs that identify the classes
659 * that are installed on a local or remote machine.
662 * Flags [I] control exclusion of classes from the list.
663 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
664 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
665 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
666 * MachineName [I] name of a remote machine.
667 * Reserved [I] must be NULL.
673 BOOL WINAPI
SetupDiBuildClassInfoListExW(
675 LPGUID ClassGuidList
,
676 DWORD ClassGuidListSize
,
687 DWORD dwGuidListIndex
= 0;
691 if (RequiredSize
!= NULL
)
694 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
699 if (hClassesKey
== INVALID_HANDLE_VALUE
)
704 for (dwIndex
= 0; ; dwIndex
++)
707 lError
= RegEnumKeyExW(hClassesKey
,
715 TRACE("RegEnumKeyExW() returns %d\n", lError
);
716 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
718 TRACE("Key name: %p\n", szKeyName
);
720 if (RegOpenKeyExW(hClassesKey
,
726 RegCloseKey(hClassesKey
);
730 if (!RegQueryValueExW(hClassKey
,
737 TRACE("'NoUseClass' value found!\n");
738 RegCloseKey(hClassKey
);
742 if ((Flags
& DIBCI_NOINSTALLCLASS
) &&
743 (!RegQueryValueExW(hClassKey
,
750 TRACE("'NoInstallClass' value found!\n");
751 RegCloseKey(hClassKey
);
755 if ((Flags
& DIBCI_NODISPLAYCLASS
) &&
756 (!RegQueryValueExW(hClassKey
,
763 TRACE("'NoDisplayClass' value found!\n");
764 RegCloseKey(hClassKey
);
768 RegCloseKey(hClassKey
);
770 TRACE("Guid: %p\n", szKeyName
);
771 if (dwGuidListIndex
< ClassGuidListSize
)
773 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
777 TRACE("Guid: %p\n", &szKeyName
[1]);
779 UuidFromStringW(&szKeyName
[1],
780 &ClassGuidList
[dwGuidListIndex
]);
786 if (lError
!= ERROR_SUCCESS
)
790 RegCloseKey(hClassesKey
);
792 if (RequiredSize
!= NULL
)
793 *RequiredSize
= dwGuidListIndex
;
795 if (ClassGuidListSize
< dwGuidListIndex
)
797 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
804 /***********************************************************************
805 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
807 BOOL WINAPI
SetupDiClassGuidsFromNameA(
809 LPGUID ClassGuidList
,
810 DWORD ClassGuidListSize
,
813 return SetupDiClassGuidsFromNameExA(ClassName
, ClassGuidList
,
814 ClassGuidListSize
, RequiredSize
,
818 /***********************************************************************
819 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
821 BOOL WINAPI
SetupDiClassGuidsFromNameW(
823 LPGUID ClassGuidList
,
824 DWORD ClassGuidListSize
,
827 return SetupDiClassGuidsFromNameExW(ClassName
, ClassGuidList
,
828 ClassGuidListSize
, RequiredSize
,
832 /***********************************************************************
833 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
835 BOOL WINAPI
SetupDiClassGuidsFromNameExA(
837 LPGUID ClassGuidList
,
838 DWORD ClassGuidListSize
,
843 LPWSTR ClassNameW
= NULL
;
844 LPWSTR MachineNameW
= NULL
;
847 ClassNameW
= MultiByteToUnicode(ClassName
, CP_ACP
);
848 if (ClassNameW
== NULL
)
853 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
854 if (MachineNameW
== NULL
)
861 bResult
= SetupDiClassGuidsFromNameExW(ClassNameW
, ClassGuidList
,
862 ClassGuidListSize
, RequiredSize
,
863 MachineNameW
, Reserved
);
865 MyFree(MachineNameW
);
871 /***********************************************************************
872 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
874 BOOL WINAPI
SetupDiClassGuidsFromNameExW(
876 LPGUID ClassGuidList
,
877 DWORD ClassGuidListSize
,
883 WCHAR szClassName
[256];
889 DWORD dwGuidListIndex
= 0;
891 if (RequiredSize
!= NULL
)
894 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
899 if (hClassesKey
== INVALID_HANDLE_VALUE
)
904 for (dwIndex
= 0; ; dwIndex
++)
907 lError
= RegEnumKeyExW(hClassesKey
,
915 TRACE("RegEnumKeyExW() returns %d\n", lError
);
916 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
918 TRACE("Key name: %p\n", szKeyName
);
920 if (RegOpenKeyExW(hClassesKey
,
926 RegCloseKey(hClassesKey
);
930 dwLength
= 256 * sizeof(WCHAR
);
931 if (!RegQueryValueExW(hClassKey
,
938 TRACE("Class name: %p\n", szClassName
);
940 if (strcmpiW(szClassName
, ClassName
) == 0)
942 TRACE("Found matching class name\n");
944 TRACE("Guid: %p\n", szKeyName
);
945 if (dwGuidListIndex
< ClassGuidListSize
)
947 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
951 TRACE("Guid: %p\n", &szKeyName
[1]);
953 UuidFromStringW(&szKeyName
[1],
954 &ClassGuidList
[dwGuidListIndex
]);
961 RegCloseKey(hClassKey
);
964 if (lError
!= ERROR_SUCCESS
)
968 RegCloseKey(hClassesKey
);
970 if (RequiredSize
!= NULL
)
971 *RequiredSize
= dwGuidListIndex
;
973 if (ClassGuidListSize
< dwGuidListIndex
)
975 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
982 /***********************************************************************
983 * SetupDiClassNameFromGuidA (SETUPAPI.@)
985 BOOL WINAPI
SetupDiClassNameFromGuidA(
986 const GUID
* ClassGuid
,
991 return SetupDiClassNameFromGuidExA(ClassGuid
, ClassName
,
992 ClassNameSize
, RequiredSize
,
996 /***********************************************************************
997 * SetupDiClassNameFromGuidW (SETUPAPI.@)
999 BOOL WINAPI
SetupDiClassNameFromGuidW(
1000 const GUID
* ClassGuid
,
1002 DWORD ClassNameSize
,
1003 PDWORD RequiredSize
)
1005 return SetupDiClassNameFromGuidExW(ClassGuid
, ClassName
,
1006 ClassNameSize
, RequiredSize
,
1010 /***********************************************************************
1011 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1013 BOOL WINAPI
SetupDiClassNameFromGuidExA(
1014 const GUID
* ClassGuid
,
1016 DWORD ClassNameSize
,
1017 PDWORD RequiredSize
,
1021 WCHAR ClassNameW
[MAX_CLASS_NAME_LEN
];
1022 LPWSTR MachineNameW
= NULL
;
1026 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1027 ret
= SetupDiClassNameFromGuidExW(ClassGuid
, ClassNameW
, MAX_CLASS_NAME_LEN
,
1028 NULL
, MachineNameW
, Reserved
);
1031 int len
= WideCharToMultiByte(CP_ACP
, 0, ClassNameW
, -1, ClassName
,
1032 ClassNameSize
, NULL
, NULL
);
1034 if (!ClassNameSize
&& RequiredSize
)
1035 *RequiredSize
= len
;
1037 MyFree(MachineNameW
);
1041 /***********************************************************************
1042 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1044 BOOL WINAPI
SetupDiClassNameFromGuidExW(
1045 const GUID
* ClassGuid
,
1047 DWORD ClassNameSize
,
1048 PDWORD RequiredSize
,
1055 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1060 if (hKey
== INVALID_HANDLE_VALUE
)
1065 if (RequiredSize
!= NULL
)
1068 if (RegQueryValueExW(hKey
,
1079 *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1082 dwLength
= ClassNameSize
* sizeof(WCHAR
);
1083 if (RegQueryValueExW(hKey
,
1099 /***********************************************************************
1100 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1103 SetupDiCreateDeviceInfoList(const GUID
*ClassGuid
,
1106 return SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
, NULL
, NULL
);
1109 /***********************************************************************
1110 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1113 SetupDiCreateDeviceInfoListExA(const GUID
*ClassGuid
,
1118 LPWSTR MachineNameW
= NULL
;
1125 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1126 if (MachineNameW
== NULL
)
1127 return INVALID_HANDLE_VALUE
;
1130 hDevInfo
= SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
,
1131 MachineNameW
, Reserved
);
1133 MyFree(MachineNameW
);
1138 /***********************************************************************
1139 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1141 * Create an empty DeviceInfoSet list.
1144 * ClassGuid [I] if not NULL only devices with GUID ClassGuid are associated
1146 * hwndParent [I] hwnd needed for interface related actions.
1147 * MachineName [I] name of machine to create 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 interfaceGuidStr
[37] = '}';
2136 interfaceGuidStr
[38] = 0;
2137 l
= RegOpenKeyExW(interfacesKey
, interfaceGuidStr
, 0,
2138 KEY_READ
, &interfaceKey
);
2141 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2142 interfaceKey
, &interfaceGuid
, enumstr
);
2143 RegCloseKey(interfaceKey
);
2151 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2152 * interface's key, so just pass that long
2154 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2155 interfacesKey
, guid
, enumstr
);
2157 RegCloseKey(interfacesKey
);
2161 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet
*set
,
2162 LPCWSTR enumerator
, LPCWSTR deviceName
, HKEY deviceKey
,
2163 const GUID
*class, DWORD flags
)
2166 WCHAR deviceInstance
[MAX_PATH
];
2167 LONG l
= ERROR_SUCCESS
;
2169 TRACE("%s %s\n", debugstr_w(enumerator
), debugstr_w(deviceName
));
2171 for (i
= 0; !l
; i
++)
2173 len
= sizeof(deviceInstance
) / sizeof(deviceInstance
[0]);
2174 l
= RegEnumKeyExW(deviceKey
, i
, deviceInstance
, &len
, NULL
, NULL
, NULL
,
2180 l
= RegOpenKeyExW(deviceKey
, deviceInstance
, 0, KEY_READ
, &subKey
);
2183 WCHAR classGuid
[40];
2186 len
= sizeof(classGuid
);
2187 l
= RegQueryValueExW(subKey
, ClassGUID
, NULL
, &dataType
,
2188 (BYTE
*)classGuid
, &len
);
2189 if (!l
&& dataType
== REG_SZ
)
2191 if (classGuid
[0] == '{' && classGuid
[37] == '}')
2196 UuidFromStringW(&classGuid
[1], &deviceClass
);
2197 if ((flags
& DIGCF_ALLCLASSES
) ||
2198 IsEqualGUID(class, &deviceClass
))
2200 static const WCHAR fmt
[] =
2201 {'%','s','\\','%','s','\\','%','s',0};
2204 instanceId
= HeapAlloc(GetProcessHeap(), 0,
2205 (lstrlenW(enumerator
) + lstrlenW(deviceName
) +
2206 lstrlenW(deviceInstance
) + 3) * sizeof(WCHAR
));
2209 sprintfW(instanceId
, fmt
, enumerator
,
2210 deviceName
, deviceInstance
);
2211 SETUPDI_AddDeviceToSet(set
, &deviceClass
,
2212 0 /* FIXME: DevInst */, instanceId
,
2214 HeapFree(GetProcessHeap(), 0, instanceId
);
2219 RegCloseKey(subKey
);
2221 /* Allow enumeration to continue */
2227 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet
,
2228 LPCWSTR parent
, HKEY key
, const GUID
*class, DWORD flags
)
2230 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2232 WCHAR subKeyName
[MAX_PATH
];
2233 LONG l
= ERROR_SUCCESS
;
2235 TRACE("%s\n", debugstr_w(parent
));
2237 for (i
= 0; !l
; i
++)
2239 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2240 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2245 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2248 TRACE("%s\n", debugstr_w(subKeyName
));
2249 SETUPDI_EnumerateMatchingDeviceInstances(set
, parent
,
2250 subKeyName
, subKey
, class, flags
);
2251 RegCloseKey(subKey
);
2253 /* Allow enumeration to continue */
2259 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet
, const GUID
*class,
2260 LPCWSTR enumstr
, DWORD flags
)
2265 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(class),
2266 debugstr_w(enumstr
), flags
);
2268 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2270 if (enumKey
!= INVALID_HANDLE_VALUE
)
2276 l
= RegOpenKeyExW(enumKey
, enumstr
, 0, KEY_READ
,
2280 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
, enumstr
,
2281 enumStrKey
, class, flags
);
2282 RegCloseKey(enumStrKey
);
2288 WCHAR subKeyName
[MAX_PATH
];
2291 for (i
= 0; !l
; i
++)
2293 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2294 l
= RegEnumKeyExW(enumKey
, i
, subKeyName
, &len
, NULL
,
2300 l
= RegOpenKeyExW(enumKey
, subKeyName
, 0, KEY_READ
,
2304 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
,
2305 subKeyName
, subKey
, class, flags
);
2306 RegCloseKey(subKey
);
2308 /* Allow enumeration to continue */
2313 RegCloseKey(enumKey
);
2317 /***********************************************************************
2318 * SetupDiGetClassDevsW (SETUPAPI.@)
2320 HDEVINFO WINAPI
SetupDiGetClassDevsW(const GUID
*class, LPCWSTR enumstr
, HWND parent
, DWORD flags
)
2322 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2326 /***********************************************************************
2327 * SetupDiGetClassDevsExW (SETUPAPI.@)
2329 HDEVINFO WINAPI
SetupDiGetClassDevsExW(const GUID
*class, PCWSTR enumstr
, HWND parent
, DWORD flags
,
2330 HDEVINFO deviceset
, PCWSTR machine
, void *reserved
)
2332 static const DWORD unsupportedFlags
= DIGCF_DEFAULT
| DIGCF_PRESENT
|
2336 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2337 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2340 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2342 SetLastError(ERROR_INVALID_PARAMETER
);
2343 return INVALID_HANDLE_VALUE
;
2345 if (flags
& unsupportedFlags
)
2346 WARN("unsupported flags %08x\n", flags
& unsupportedFlags
);
2350 set
= SetupDiCreateDeviceInfoListExW(class, parent
, machine
, reserved
);
2351 if (set
!= INVALID_HANDLE_VALUE
)
2353 if (machine
&& *machine
)
2354 FIXME("%s: unimplemented for remote machines\n",
2355 debugstr_w(machine
));
2356 else if (flags
& DIGCF_DEVICEINTERFACE
)
2357 SETUPDI_EnumerateInterfaces(set
, class, enumstr
, flags
);
2359 SETUPDI_EnumerateDevices(set
, class, enumstr
, flags
);
2364 /***********************************************************************
2365 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2367 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2368 HDEVINFO DeviceInfoSet
,
2369 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2371 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2373 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2375 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2377 SetLastError(ERROR_INVALID_HANDLE
);
2380 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2382 SetLastError(ERROR_INVALID_HANDLE
);
2386 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2388 SetLastError(ERROR_INVALID_PARAMETER
);
2391 DevInfoData
->ClassGuid
= set
->ClassGuid
;
2392 DevInfoData
->RemoteMachineHandle
= NULL
;
2393 DevInfoData
->RemoteMachineName
[0] = '\0';
2397 /***********************************************************************
2398 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2400 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2401 HDEVINFO DeviceInfoSet
,
2402 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2404 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2406 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2408 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2410 SetLastError(ERROR_INVALID_HANDLE
);
2413 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2415 SetLastError(ERROR_INVALID_HANDLE
);
2419 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2421 SetLastError(ERROR_INVALID_PARAMETER
);
2424 DevInfoData
->ClassGuid
= set
->ClassGuid
;
2425 DevInfoData
->RemoteMachineHandle
= NULL
;
2426 DevInfoData
->RemoteMachineName
[0] = '\0';
2430 /***********************************************************************
2431 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2433 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2434 HDEVINFO DeviceInfoSet
,
2435 PSP_DEVINFO_DATA DeviceInfoData
,
2436 const GUID
*InterfaceClassGuid
,
2437 PCSTR ReferenceString
,
2438 DWORD CreationFlags
,
2439 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2442 LPWSTR ReferenceStringW
= NULL
;
2444 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2445 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2446 CreationFlags
, DeviceInterfaceData
);
2448 if (ReferenceString
)
2450 ReferenceStringW
= MultiByteToUnicode(ReferenceString
, CP_ACP
);
2451 if (ReferenceStringW
== NULL
) return FALSE
;
2454 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2455 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2456 DeviceInterfaceData
);
2458 MyFree(ReferenceStringW
);
2463 /***********************************************************************
2464 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2466 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2467 HDEVINFO DeviceInfoSet
,
2468 PSP_DEVINFO_DATA DeviceInfoData
,
2469 const GUID
*InterfaceClassGuid
,
2470 PCWSTR ReferenceString
,
2471 DWORD CreationFlags
,
2472 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2474 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2475 struct DeviceInfo
*devInfo
;
2476 SP_DEVICE_INTERFACE_DATA
*iface
= NULL
;
2479 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2480 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2481 CreationFlags
, DeviceInterfaceData
);
2483 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2485 SetLastError(ERROR_INVALID_HANDLE
);
2488 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2490 SetLastError(ERROR_INVALID_HANDLE
);
2493 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2494 || !DeviceInfoData
->Reserved
)
2496 SetLastError(ERROR_INVALID_PARAMETER
);
2499 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2500 if (devInfo
->set
!= set
)
2502 SetLastError(ERROR_INVALID_PARAMETER
);
2505 if (!InterfaceClassGuid
)
2507 SetLastError(ERROR_INVALID_USER_BUFFER
);
2510 if ((ret
= SETUPDI_AddInterfaceInstance(DeviceInfoData
, InterfaceClassGuid
,
2511 ReferenceString
, &iface
)))
2513 if (DeviceInterfaceData
)
2515 if (DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2517 SetLastError(ERROR_INVALID_USER_BUFFER
);
2521 *DeviceInterfaceData
= *iface
;
2527 /***********************************************************************
2528 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2530 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2531 HDEVINFO DeviceInfoSet
,
2532 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2536 PCSTR InfSectionName
)
2539 PWSTR InfSectionNameW
= NULL
;
2541 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2542 samDesired
, InfHandle
, InfSectionName
);
2545 if (!InfSectionName
)
2547 SetLastError(ERROR_INVALID_PARAMETER
);
2548 return INVALID_HANDLE_VALUE
;
2550 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2551 if (!InfSectionNameW
)
2552 return INVALID_HANDLE_VALUE
;
2554 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2555 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2557 MyFree(InfSectionNameW
);
2561 static PWSTR
SETUPDI_GetInstancePath(struct InterfaceInfo
*ifaceInfo
)
2563 static const WCHAR hash
[] = {'#',0};
2564 PWSTR instancePath
= NULL
;
2566 if (ifaceInfo
->referenceString
)
2568 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2569 (lstrlenW(ifaceInfo
->referenceString
) + 2) * sizeof(WCHAR
));
2572 lstrcpyW(instancePath
, hash
);
2573 lstrcatW(instancePath
, ifaceInfo
->referenceString
);
2576 SetLastError(ERROR_OUTOFMEMORY
);
2580 instancePath
= HeapAlloc(GetProcessHeap(), 0,
2581 (lstrlenW(hash
) + 1) * sizeof(WCHAR
));
2583 lstrcpyW(instancePath
, hash
);
2585 return instancePath
;
2588 /***********************************************************************
2589 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2591 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2592 HDEVINFO DeviceInfoSet
,
2593 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2597 PCWSTR InfSectionName
)
2599 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2600 HKEY key
= INVALID_HANDLE_VALUE
, interfacesKey
;
2603 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2604 samDesired
, InfHandle
, InfSectionName
);
2606 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2607 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2609 SetLastError(ERROR_INVALID_HANDLE
);
2610 return INVALID_HANDLE_VALUE
;
2612 if (!DeviceInterfaceData
||
2613 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2614 !DeviceInterfaceData
->Reserved
)
2616 SetLastError(ERROR_INVALID_PARAMETER
);
2617 return INVALID_HANDLE_VALUE
;
2619 if (InfHandle
&& !InfSectionName
)
2621 SetLastError(ERROR_INVALID_PARAMETER
);
2622 return INVALID_HANDLE_VALUE
;
2624 if (!(l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, DeviceClasses
, 0, NULL
, 0,
2625 samDesired
, NULL
, &interfacesKey
, NULL
)))
2628 WCHAR bracedGuidString
[39];
2630 SETUPDI_GuidToString(&DeviceInterfaceData
->InterfaceClassGuid
,
2632 if (!(l
= RegCreateKeyExW(interfacesKey
, bracedGuidString
, 0, NULL
, 0,
2633 samDesired
, NULL
, &parent
, NULL
)))
2635 struct InterfaceInfo
*ifaceInfo
=
2636 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2637 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2638 PWSTR interfKeyName
= HeapAlloc(GetProcessHeap(), 0,
2639 (lstrlenW(ifaceInfo
->symbolicLink
) + 1) * sizeof(WCHAR
));
2643 lstrcpyW(interfKeyName
, ifaceInfo
->symbolicLink
);
2644 if (lstrlenW(ifaceInfo
->symbolicLink
) > 3)
2646 interfKeyName
[0] = '#';
2647 interfKeyName
[1] = '#';
2648 interfKeyName
[3] = '#';
2650 ptr
= strchrW(interfKeyName
, '\\');
2653 l
= RegCreateKeyExW(parent
, interfKeyName
, 0, NULL
, 0,
2654 samDesired
, NULL
, &interfKey
, NULL
);
2657 struct DeviceInfo
*devInfo
=
2658 (struct DeviceInfo
*)ifaceInfo
->device
->Reserved
;
2660 l
= RegSetValueExW(interfKey
, DeviceInstance
, 0, REG_SZ
,
2661 (BYTE
*)devInfo
->instanceId
,
2662 (lstrlenW(devInfo
->instanceId
) + 1) * sizeof(WCHAR
));
2669 l
= RegCreateKeyExW(interfKey
, instancePath
, 0, NULL
, 0,
2670 samDesired
, NULL
, &key
, NULL
);
2674 key
= INVALID_HANDLE_VALUE
;
2677 FIXME("INF section installation unsupported\n");
2682 RegCloseKey(interfKey
);
2686 HeapFree(GetProcessHeap(), 0, interfKeyName
);
2687 HeapFree(GetProcessHeap(), 0, instancePath
);
2688 RegCloseKey(parent
);
2692 RegCloseKey(interfacesKey
);
2699 /***********************************************************************
2700 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2702 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2703 HDEVINFO DeviceInfoSet
,
2704 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2707 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2711 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2713 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2714 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2716 SetLastError(ERROR_INVALID_HANDLE
);
2719 if (!DeviceInterfaceData
||
2720 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2721 !DeviceInterfaceData
->Reserved
)
2723 SetLastError(ERROR_INVALID_PARAMETER
);
2726 parent
= SetupDiOpenClassRegKeyExW(&DeviceInterfaceData
->InterfaceClassGuid
,
2727 KEY_ALL_ACCESS
, DIOCR_INTERFACE
, NULL
, NULL
);
2728 if (parent
!= INVALID_HANDLE_VALUE
)
2730 struct InterfaceInfo
*ifaceInfo
=
2731 (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2732 PWSTR instancePath
= SETUPDI_GetInstancePath(ifaceInfo
);
2736 LONG l
= RegDeleteKeyW(parent
, instancePath
);
2742 HeapFree(GetProcessHeap(), 0, instancePath
);
2744 RegCloseKey(parent
);
2749 /***********************************************************************
2750 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2753 * DeviceInfoSet [I] Set of devices from which to enumerate
2755 * DeviceInfoData [I] (Optional) If specified, a specific device
2756 * instance from which to enumerate interfaces.
2757 * If it isn't specified, all interfaces for all
2758 * devices in the set are enumerated.
2759 * InterfaceClassGuid [I] The interface class to enumerate.
2760 * MemberIndex [I] An index of the interface instance to enumerate.
2761 * A caller should start with MemberIndex set to 0,
2762 * and continue until the function fails with
2763 * ERROR_NO_MORE_ITEMS.
2764 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2765 * member must be set to
2766 * sizeof(SP_DEVICE_INTERFACE_DATA).
2769 * Success: non-zero value.
2770 * Failure: FALSE. Call GetLastError() for more info.
2772 BOOL WINAPI
SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet
, PSP_DEVINFO_DATA DeviceInfoData
,
2773 const GUID
*InterfaceClassGuid
, DWORD MemberIndex
,
2774 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2776 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2779 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet
, DeviceInfoData
,
2780 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
2782 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2783 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2785 SetLastError(ERROR_INVALID_HANDLE
);
2788 if (DeviceInfoData
&& (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2789 !DeviceInfoData
->Reserved
))
2791 SetLastError(ERROR_INVALID_PARAMETER
);
2794 if (!DeviceInterfaceData
||
2795 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2797 SetLastError(ERROR_INVALID_PARAMETER
);
2801 /* In case application fails to check return value, clear output */
2802 memset(DeviceInterfaceData
, 0, sizeof(*DeviceInterfaceData
));
2803 DeviceInterfaceData
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DATA
);
2807 struct DeviceInfo
*devInfo
=
2808 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2809 struct InterfaceInstances
*iface
;
2811 if ((ret
= SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
)))
2813 if (MemberIndex
< iface
->cInstances
)
2814 *DeviceInterfaceData
= iface
->instances
[MemberIndex
];
2817 SetLastError(ERROR_NO_MORE_ITEMS
);
2822 SetLastError(ERROR_NO_MORE_ITEMS
);
2826 struct DeviceInstance
*devInst
;
2827 DWORD cEnumerated
= 0;
2830 LIST_FOR_EACH_ENTRY(devInst
, &set
->devices
, struct DeviceInstance
, entry
)
2832 struct DeviceInfo
*devInfo
= (struct DeviceInfo
*)devInst
->data
.Reserved
;
2833 struct InterfaceInstances
*iface
;
2835 if (found
|| cEnumerated
>= MemberIndex
+ 1)
2837 if (SETUPDI_FindInterface(devInfo
, InterfaceClassGuid
, &iface
))
2839 if (cEnumerated
+ iface
->cInstances
< MemberIndex
+ 1)
2840 cEnumerated
+= iface
->cInstances
;
2843 DWORD instanceIndex
= MemberIndex
- cEnumerated
;
2845 *DeviceInterfaceData
= iface
->instances
[instanceIndex
];
2846 cEnumerated
+= instanceIndex
+ 1;
2853 SetLastError(ERROR_NO_MORE_ITEMS
);
2858 /***********************************************************************
2859 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2861 * Destroy a DeviceInfoList and free all used memory of the list.
2864 * devinfo [I] DeviceInfoList pointer to list to destroy
2867 * Success: non zero value.
2868 * Failure: zero value.
2870 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
2874 TRACE("%p\n", devinfo
);
2875 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
2877 struct DeviceInfoSet
*list
= devinfo
;
2879 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
2881 struct DeviceInstance
*devInst
, *devInst2
;
2883 LIST_FOR_EACH_ENTRY_SAFE(devInst
, devInst2
, &list
->devices
,
2884 struct DeviceInstance
, entry
)
2886 SETUPDI_FreeDeviceInfo( (struct DeviceInfo
*)devInst
->data
.Reserved
);
2887 list_remove(&devInst
->entry
);
2888 HeapFree(GetProcessHeap(), 0, devInst
);
2890 HeapFree(GetProcessHeap(), 0, list
);
2896 SetLastError(ERROR_INVALID_HANDLE
);
2901 /***********************************************************************
2902 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2904 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
2905 HDEVINFO DeviceInfoSet
,
2906 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2907 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
2908 DWORD DeviceInterfaceDetailDataSize
,
2909 PDWORD RequiredSize
,
2910 PSP_DEVINFO_DATA DeviceInfoData
)
2912 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2913 struct InterfaceInfo
*info
;
2914 DWORD bytesNeeded
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
[1]);
2917 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2918 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2919 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2921 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2922 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2924 SetLastError(ERROR_INVALID_HANDLE
);
2927 if (!DeviceInterfaceData
||
2928 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2929 !DeviceInterfaceData
->Reserved
)
2931 SetLastError(ERROR_INVALID_PARAMETER
);
2934 if (DeviceInterfaceDetailData
&&
2935 DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
))
2937 SetLastError(ERROR_INVALID_USER_BUFFER
);
2940 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2942 SetLastError(ERROR_INVALID_USER_BUFFER
);
2945 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
2946 if (info
->symbolicLink
)
2947 bytesNeeded
+= WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2948 NULL
, 0, NULL
, NULL
);
2949 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2951 if (info
->symbolicLink
)
2952 WideCharToMultiByte(CP_ACP
, 0, info
->symbolicLink
, -1,
2953 DeviceInterfaceDetailData
->DevicePath
,
2954 DeviceInterfaceDetailDataSize
-
2955 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
2958 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2959 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2960 *DeviceInfoData
= *info
->device
;
2966 *RequiredSize
= bytesNeeded
;
2967 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2972 /***********************************************************************
2973 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2975 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
2976 HDEVINFO DeviceInfoSet
,
2977 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2978 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
2979 DWORD DeviceInterfaceDetailDataSize
,
2980 PDWORD RequiredSize
,
2981 PSP_DEVINFO_DATA DeviceInfoData
)
2983 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2984 struct InterfaceInfo
*info
;
2985 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
2986 + sizeof(WCHAR
); /* include NULL terminator */
2989 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2990 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2991 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2993 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2994 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2996 SetLastError(ERROR_INVALID_HANDLE
);
2999 if (!DeviceInterfaceData
||
3000 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
3001 !DeviceInterfaceData
->Reserved
)
3003 SetLastError(ERROR_INVALID_PARAMETER
);
3006 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
3007 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
) ||
3008 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
)))
3010 SetLastError(ERROR_INVALID_USER_BUFFER
);
3013 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
3015 SetLastError(ERROR_INVALID_USER_BUFFER
);
3018 info
= (struct InterfaceInfo
*)DeviceInterfaceData
->Reserved
;
3019 if (info
->symbolicLink
)
3020 bytesNeeded
+= sizeof(WCHAR
)*lstrlenW(info
->symbolicLink
);
3021 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
3023 if (info
->symbolicLink
)
3024 lstrcpyW(DeviceInterfaceDetailData
->DevicePath
, info
->symbolicLink
);
3026 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
3027 if (DeviceInfoData
&& DeviceInfoData
->cbSize
== sizeof(SP_DEVINFO_DATA
))
3028 *DeviceInfoData
= *info
->device
;
3034 *RequiredSize
= bytesNeeded
;
3035 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3040 struct PropertyMapEntry
3047 static const struct PropertyMapEntry PropertyMap
[] = {
3048 { REG_SZ
, "DeviceDesc", DeviceDesc
},
3049 { REG_MULTI_SZ
, "HardwareId", HardwareId
},
3050 { REG_MULTI_SZ
, "CompatibleIDs", CompatibleIDs
},
3051 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
3052 { REG_SZ
, "Service", Service
},
3053 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
3054 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
3055 { REG_SZ
, "Class", Class
},
3056 { REG_SZ
, "ClassGUID", ClassGUID
},
3057 { REG_SZ
, "Driver", Driver
},
3058 { REG_DWORD
, "ConfigFlags", ConfigFlags
},
3059 { REG_SZ
, "Mfg", Mfg
},
3060 { REG_SZ
, "FriendlyName", FriendlyName
},
3061 { REG_SZ
, "LocationInformation", LocationInformation
},
3062 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3063 { REG_DWORD
, "Capabilities", Capabilities
},
3064 { REG_DWORD
, "UINumber", UINumber
},
3065 { REG_MULTI_SZ
, "UpperFilters", UpperFilters
},
3066 { REG_MULTI_SZ
, "LowerFilters", LowerFilters
},
3069 /***********************************************************************
3070 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3072 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
3073 HDEVINFO DeviceInfoSet
,
3074 PSP_DEVINFO_DATA DeviceInfoData
,
3076 PDWORD PropertyRegDataType
,
3077 PBYTE PropertyBuffer
,
3078 DWORD PropertyBufferSize
,
3079 PDWORD RequiredSize
)
3082 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3083 struct DeviceInfo
*devInfo
;
3085 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3086 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3089 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3091 SetLastError(ERROR_INVALID_HANDLE
);
3094 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3096 SetLastError(ERROR_INVALID_HANDLE
);
3099 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3100 || !DeviceInfoData
->Reserved
)
3102 SetLastError(ERROR_INVALID_PARAMETER
);
3105 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
3107 SetLastError(ERROR_INVALID_DATA
);
3110 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3111 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3112 && PropertyMap
[Property
].nameA
)
3114 DWORD size
= PropertyBufferSize
;
3115 LONG l
= RegQueryValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
,
3116 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3118 if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3119 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3125 *RequiredSize
= size
;
3130 /***********************************************************************
3131 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3133 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3134 HDEVINFO DeviceInfoSet
,
3135 PSP_DEVINFO_DATA DeviceInfoData
,
3137 PDWORD PropertyRegDataType
,
3138 PBYTE PropertyBuffer
,
3139 DWORD PropertyBufferSize
,
3140 PDWORD RequiredSize
)
3143 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3144 struct DeviceInfo
*devInfo
;
3146 TRACE("%04x %p %d %p %p %d %p\n", (DWORD
)DeviceInfoSet
, DeviceInfoData
,
3147 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3150 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3152 SetLastError(ERROR_INVALID_HANDLE
);
3155 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3157 SetLastError(ERROR_INVALID_HANDLE
);
3160 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3161 || !DeviceInfoData
->Reserved
)
3163 SetLastError(ERROR_INVALID_PARAMETER
);
3166 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
3168 SetLastError(ERROR_INVALID_DATA
);
3171 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3172 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3173 && PropertyMap
[Property
].nameW
)
3175 DWORD size
= PropertyBufferSize
;
3176 LONG l
= RegQueryValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
,
3177 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3179 if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3180 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3186 *RequiredSize
= size
;
3191 /***********************************************************************
3192 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3194 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3195 HDEVINFO DeviceInfoSet
,
3196 PSP_DEVINFO_DATA DeviceInfoData
,
3198 const BYTE
*PropertyBuffer
,
3199 DWORD PropertyBufferSize
)
3202 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3203 struct DeviceInfo
*devInfo
;
3205 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3206 PropertyBuffer
, PropertyBufferSize
);
3208 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3210 SetLastError(ERROR_INVALID_HANDLE
);
3213 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3215 SetLastError(ERROR_INVALID_HANDLE
);
3218 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3219 || !DeviceInfoData
->Reserved
)
3221 SetLastError(ERROR_INVALID_PARAMETER
);
3224 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3225 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3226 && PropertyMap
[Property
].nameA
)
3228 LONG l
= RegSetValueExA(devInfo
->key
, PropertyMap
[Property
].nameA
, 0,
3229 PropertyMap
[Property
].regType
, PropertyBuffer
,
3230 PropertyBufferSize
);
3239 /***********************************************************************
3240 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3242 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
3243 HDEVINFO DeviceInfoSet
,
3244 PSP_DEVINFO_DATA DeviceInfoData
,
3246 const BYTE
*PropertyBuffer
,
3247 DWORD PropertyBufferSize
)
3250 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3251 struct DeviceInfo
*devInfo
;
3253 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3254 PropertyBuffer
, PropertyBufferSize
);
3256 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3258 SetLastError(ERROR_INVALID_HANDLE
);
3261 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3263 SetLastError(ERROR_INVALID_HANDLE
);
3266 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3267 || !DeviceInfoData
->Reserved
)
3269 SetLastError(ERROR_INVALID_PARAMETER
);
3272 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3273 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3274 && PropertyMap
[Property
].nameW
)
3276 LONG l
= RegSetValueExW(devInfo
->key
, PropertyMap
[Property
].nameW
, 0,
3277 PropertyMap
[Property
].regType
, PropertyBuffer
,
3278 PropertyBufferSize
);
3287 /***********************************************************************
3288 * SetupDiInstallClassA (SETUPAPI.@)
3290 BOOL WINAPI
SetupDiInstallClassA(
3296 UNICODE_STRING FileNameW
;
3301 SetLastError(ERROR_INVALID_PARAMETER
);
3304 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW
, InfFileName
))
3306 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3310 Result
= SetupDiInstallClassW(hwndParent
, FileNameW
.Buffer
, Flags
, FileQueue
);
3312 RtlFreeUnicodeString(&FileNameW
);
3317 static HKEY
CreateClassKey(HINF hInf
)
3319 static const WCHAR slash
[] = { '\\',0 };
3320 WCHAR FullBuffer
[MAX_PATH
];
3321 WCHAR Buffer
[MAX_PATH
];
3325 if (!SetupGetLineTextW(NULL
,
3333 return INVALID_HANDLE_VALUE
;
3336 lstrcpyW(FullBuffer
, ControlClass
);
3337 lstrcatW(FullBuffer
, slash
);
3338 lstrcatW(FullBuffer
, Buffer
);
3340 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3346 if (!SetupGetLineTextW(NULL
,
3354 return INVALID_HANDLE_VALUE
;
3357 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3361 REG_OPTION_NON_VOLATILE
,
3367 return INVALID_HANDLE_VALUE
;
3372 if (RegSetValueExW(hClassKey
,
3377 RequiredSize
* sizeof(WCHAR
)))
3379 RegCloseKey(hClassKey
);
3380 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3382 return INVALID_HANDLE_VALUE
;
3388 /***********************************************************************
3389 * SetupDiInstallClassW (SETUPAPI.@)
3391 BOOL WINAPI
SetupDiInstallClassW(
3397 WCHAR SectionName
[MAX_PATH
];
3398 DWORD SectionNameLength
= 0;
3400 BOOL bFileQueueCreated
= FALSE
;
3408 SetLastError(ERROR_INVALID_PARAMETER
);
3411 if ((Flags
& DI_NOVCP
) && (FileQueue
== NULL
|| FileQueue
== INVALID_HANDLE_VALUE
))
3413 SetLastError(ERROR_INVALID_PARAMETER
);
3417 /* Open the .inf file */
3418 hInf
= SetupOpenInfFileW(InfFileName
,
3422 if (hInf
== INVALID_HANDLE_VALUE
)
3428 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3429 hClassKey
= CreateClassKey(hInf
);
3430 if (hClassKey
== INVALID_HANDLE_VALUE
)
3432 SetupCloseInfFile(hInf
);
3437 /* Try to append a layout file */
3438 SetupOpenAppendInfFileW(NULL
, hInf
, NULL
);
3440 /* Retrieve the actual section name */
3441 SetupDiGetActualSectionToInstallW(hInf
,
3449 if (!(Flags
& DI_NOVCP
))
3451 FileQueue
= SetupOpenFileQueue();
3452 if (FileQueue
== INVALID_HANDLE_VALUE
)
3454 SetupCloseInfFile(hInf
);
3458 bFileQueueCreated
= TRUE
;
3463 SetupInstallFromInfSectionW(NULL
,
3466 SPINST_COPYINF
| SPINST_FILES
| SPINST_REGISTRY
,
3472 INVALID_HANDLE_VALUE
,
3475 /* FIXME: More code! */
3477 if (bFileQueueCreated
)
3478 SetupCloseFileQueue(FileQueue
);
3480 SetupCloseInfFile(hInf
);
3486 /***********************************************************************
3487 * SetupDiOpenClassRegKey (SETUPAPI.@)
3489 HKEY WINAPI
SetupDiOpenClassRegKey(
3490 const GUID
* ClassGuid
,
3493 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3494 DIOCR_INSTALLER
, NULL
, NULL
);
3498 /***********************************************************************
3499 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3501 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3502 const GUID
* ClassGuid
,
3508 PWSTR MachineNameW
= NULL
;
3515 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
3516 if (MachineNameW
== NULL
)
3517 return INVALID_HANDLE_VALUE
;
3520 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3521 Flags
, MachineNameW
, Reserved
);
3523 MyFree(MachineNameW
);
3529 /***********************************************************************
3530 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3532 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3533 const GUID
* ClassGuid
,
3544 if (MachineName
&& *MachineName
)
3546 FIXME("Remote access not supported yet!\n");
3547 return INVALID_HANDLE_VALUE
;
3550 if (Flags
== DIOCR_INSTALLER
)
3552 lpKeyName
= ControlClass
;
3554 else if (Flags
== DIOCR_INTERFACE
)
3556 lpKeyName
= DeviceClasses
;
3560 ERR("Invalid Flags parameter!\n");
3561 SetLastError(ERROR_INVALID_PARAMETER
);
3562 return INVALID_HANDLE_VALUE
;
3567 if ((l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3574 hClassesKey
= INVALID_HANDLE_VALUE
;
3580 WCHAR bracedGuidString
[39];
3582 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3584 if (!(l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3590 if ((l
= RegOpenKeyExW(hClassesKey
,
3597 key
= INVALID_HANDLE_VALUE
;
3599 RegCloseKey(hClassesKey
);
3604 key
= INVALID_HANDLE_VALUE
;
3610 /***********************************************************************
3611 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3613 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3614 HDEVINFO DeviceInfoSet
,
3617 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3619 FIXME("%p %s %08x %p\n",
3620 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3624 /***********************************************************************
3625 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3627 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
3628 HDEVINFO DeviceInfoSet
,
3631 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3633 FIXME("%p %s %08x %p\n", DeviceInfoSet
,
3634 debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3638 /***********************************************************************
3639 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3641 BOOL WINAPI
SetupDiSetClassInstallParamsA(
3642 HDEVINFO DeviceInfoSet
,
3643 PSP_DEVINFO_DATA DeviceInfoData
,
3644 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3645 DWORD ClassInstallParamsSize
)
3647 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3648 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3652 /***********************************************************************
3653 * SetupDiSetClassInstallParamsW (SETUPAPI.@)
3655 BOOL WINAPI
SetupDiSetClassInstallParamsW(
3656 HDEVINFO DeviceInfoSet
,
3657 PSP_DEVINFO_DATA DeviceInfoData
,
3658 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3659 DWORD ClassInstallParamsSize
)
3661 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3662 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3666 /***********************************************************************
3667 * SetupDiCallClassInstaller (SETUPAPI.@)
3669 BOOL WINAPI
SetupDiCallClassInstaller(
3670 DI_FUNCTION InstallFunction
,
3671 HDEVINFO DeviceInfoSet
,
3672 PSP_DEVINFO_DATA DeviceInfoData
)
3674 FIXME("%d %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3678 /***********************************************************************
3679 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
3681 BOOL WINAPI
SetupDiGetDeviceInstallParamsW(
3682 HDEVINFO DeviceInfoSet
,
3683 PSP_DEVINFO_DATA DeviceInfoData
,
3684 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
3686 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3690 /***********************************************************************
3691 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3693 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
3694 HDEVINFO DeviceInfoSet
,
3695 PSP_DEVINFO_DATA DeviceInfoData
,
3696 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3698 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3702 /***********************************************************************
3703 * SetupDiSetDeviceInstallParamsA (SETUPAPI.@)
3705 BOOL WINAPI
SetupDiSetDeviceInstallParamsA(
3706 HDEVINFO DeviceInfoSet
,
3707 PSP_DEVINFO_DATA DeviceInfoData
,
3708 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3710 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3715 static HKEY
SETUPDI_OpenDevKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3717 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
3720 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3721 NULL
, &enumKey
, NULL
);
3724 RegOpenKeyExW(enumKey
, devInfo
->instanceId
, 0, samDesired
, &key
);
3725 RegCloseKey(enumKey
);
3730 static HKEY
SETUPDI_OpenDrvKey(struct DeviceInfo
*devInfo
, REGSAM samDesired
)
3732 static const WCHAR slash
[] = { '\\',0 };
3733 WCHAR classKeyPath
[MAX_PATH
];
3734 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
3737 lstrcpyW(classKeyPath
, ControlClass
);
3738 lstrcatW(classKeyPath
, slash
);
3739 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3740 classKeyPath
+ lstrlenW(classKeyPath
));
3741 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3742 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3745 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3748 sprintfW(devId
, fmt
, devInfo
->devId
);
3749 l
= RegOpenKeyExW(classKey
, devId
, 0, samDesired
, &key
);
3750 RegCloseKey(classKey
);
3753 SetLastError(ERROR_KEY_DOES_NOT_EXIST
);
3754 return INVALID_HANDLE_VALUE
;
3760 /***********************************************************************
3761 * SetupDiOpenDevRegKey (SETUPAPI.@)
3763 HKEY WINAPI
SetupDiOpenDevRegKey(
3764 HDEVINFO DeviceInfoSet
,
3765 PSP_DEVINFO_DATA DeviceInfoData
,
3771 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3772 struct DeviceInfo
*devInfo
;
3773 HKEY key
= INVALID_HANDLE_VALUE
;
3775 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
3776 Scope
, HwProfile
, KeyType
, samDesired
);
3778 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3780 SetLastError(ERROR_INVALID_HANDLE
);
3781 return INVALID_HANDLE_VALUE
;
3783 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3785 SetLastError(ERROR_INVALID_HANDLE
);
3786 return INVALID_HANDLE_VALUE
;
3788 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3789 || !DeviceInfoData
->Reserved
)
3791 SetLastError(ERROR_INVALID_PARAMETER
);
3792 return INVALID_HANDLE_VALUE
;
3794 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3796 SetLastError(ERROR_INVALID_FLAGS
);
3797 return INVALID_HANDLE_VALUE
;
3799 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
3801 SetLastError(ERROR_INVALID_FLAGS
);
3802 return INVALID_HANDLE_VALUE
;
3804 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3805 if (devInfo
->set
!= set
)
3807 SetLastError(ERROR_INVALID_PARAMETER
);
3808 return INVALID_HANDLE_VALUE
;
3810 if (devInfo
->phantom
)
3812 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3813 return INVALID_HANDLE_VALUE
;
3815 if (Scope
!= DICS_FLAG_GLOBAL
)
3816 FIXME("unimplemented for scope %d\n", Scope
);
3820 key
= SETUPDI_OpenDevKey(devInfo
, samDesired
);
3823 key
= SETUPDI_OpenDrvKey(devInfo
, samDesired
);
3826 WARN("unknown KeyType %d\n", KeyType
);
3831 static BOOL
SETUPDI_DeleteDevKey(struct DeviceInfo
*devInfo
)
3837 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3838 NULL
, &enumKey
, NULL
);
3841 ret
= RegDeleteTreeW(enumKey
, devInfo
->instanceId
);
3842 RegCloseKey(enumKey
);
3849 static BOOL
SETUPDI_DeleteDrvKey(struct DeviceInfo
*devInfo
)
3851 static const WCHAR slash
[] = { '\\',0 };
3852 WCHAR classKeyPath
[MAX_PATH
];
3857 lstrcpyW(classKeyPath
, ControlClass
);
3858 lstrcatW(classKeyPath
, slash
);
3859 SETUPDI_GuidToString(&devInfo
->set
->ClassGuid
,
3860 classKeyPath
+ lstrlenW(classKeyPath
));
3861 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3862 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3865 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3868 sprintfW(devId
, fmt
, devInfo
->devId
);
3869 ret
= RegDeleteTreeW(classKey
, devId
);
3870 RegCloseKey(classKey
);
3877 /***********************************************************************
3878 * SetupDiDeleteDevRegKey (SETUPAPI.@)
3880 BOOL WINAPI
SetupDiDeleteDevRegKey(
3881 HDEVINFO DeviceInfoSet
,
3882 PSP_DEVINFO_DATA DeviceInfoData
,
3887 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3888 struct DeviceInfo
*devInfo
;
3891 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
3894 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3896 SetLastError(ERROR_INVALID_HANDLE
);
3899 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3901 SetLastError(ERROR_INVALID_HANDLE
);
3904 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3905 || !DeviceInfoData
->Reserved
)
3907 SetLastError(ERROR_INVALID_PARAMETER
);
3910 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3912 SetLastError(ERROR_INVALID_FLAGS
);
3915 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
3917 SetLastError(ERROR_INVALID_FLAGS
);
3920 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3921 if (devInfo
->set
!= set
)
3923 SetLastError(ERROR_INVALID_PARAMETER
);
3926 if (devInfo
->phantom
)
3928 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3931 if (Scope
!= DICS_FLAG_GLOBAL
)
3932 FIXME("unimplemented for scope %d\n", Scope
);
3936 ret
= SETUPDI_DeleteDevKey(devInfo
);
3939 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3942 ret
= SETUPDI_DeleteDevKey(devInfo
);
3944 ret
= SETUPDI_DeleteDrvKey(devInfo
);
3947 WARN("unknown KeyType %d\n", KeyType
);
3952 /***********************************************************************
3953 * CM_Get_Device_IDA (SETUPAPI.@)
3955 CONFIGRET WINAPI
CM_Get_Device_IDA( DEVINST dnDevInst
, PSTR Buffer
,
3956 ULONG BufferLen
, ULONG ulFlags
)
3958 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
3960 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
3963 return CR_NO_SUCH_DEVINST
;
3965 WideCharToMultiByte(CP_ACP
, 0, devInfo
->instanceId
, -1, Buffer
, BufferLen
, 0, 0);
3966 TRACE("Returning %s\n", debugstr_a(Buffer
));
3970 /***********************************************************************
3971 * CM_Get_Device_IDW (SETUPAPI.@)
3973 CONFIGRET WINAPI
CM_Get_Device_IDW( DEVINST dnDevInst
, LPWSTR Buffer
,
3974 ULONG BufferLen
, ULONG ulFlags
)
3976 struct DeviceInfo
*devInfo
= GlobalLock((HANDLE
)dnDevInst
);
3978 TRACE("%x->%p, %p, %u %u\n", dnDevInst
, devInfo
, Buffer
, BufferLen
, ulFlags
);
3982 WARN("dev instance %d not found!\n", dnDevInst
);
3983 return CR_NO_SUCH_DEVINST
;
3986 lstrcpynW(Buffer
, devInfo
->instanceId
, BufferLen
);
3987 TRACE("Returning %s\n", debugstr_w(Buffer
));
3988 GlobalUnlock((HANDLE
)dnDevInst
);
3994 /***********************************************************************
3995 * CM_Get_Device_ID_Size (SETUPAPI.@)
3997 CONFIGRET WINAPI
CM_Get_Device_ID_Size( PULONG pulLen
, DEVINST dnDevInst
,
4000 struct DeviceInfo
*ppdevInfo
= GlobalLock((HANDLE
)dnDevInst
);
4002 TRACE("%x->%p, %p, %u\n", dnDevInst
, ppdevInfo
, pulLen
, ulFlags
);
4006 WARN("dev instance %d not found!\n", dnDevInst
);
4007 return CR_NO_SUCH_DEVINST
;
4010 *pulLen
= lstrlenW(ppdevInfo
->instanceId
);
4011 GlobalUnlock((HANDLE
)dnDevInst
);
4015 /***********************************************************************
4016 * SetupDiGetINFClassA (SETUPAPI.@)
4018 BOOL WINAPI
SetupDiGetINFClassA(PCSTR inf
, LPGUID class_guid
, PSTR class_name
,
4019 DWORD size
, PDWORD required_size
)
4022 DWORD required_sizeA
, required_sizeW
;
4023 PWSTR class_nameW
= NULL
;
4024 UNICODE_STRING infW
;
4028 if (!RtlCreateUnicodeStringFromAsciiz(&infW
, inf
))
4030 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4037 if (class_name
&& size
)
4039 if (!(class_nameW
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
))))
4041 RtlFreeUnicodeString(&infW
);
4042 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4047 retval
= SetupDiGetINFClassW(infW
.Buffer
, class_guid
, class_nameW
, size
, &required_sizeW
);
4051 required_sizeA
= WideCharToMultiByte( CP_ACP
, 0, class_nameW
, required_sizeW
,
4052 class_name
, size
, NULL
, NULL
);
4054 if(required_size
) *required_size
= required_sizeA
;
4057 if(required_size
) *required_size
= required_sizeW
;
4059 HeapFree(GetProcessHeap(), 0, class_nameW
);
4060 RtlFreeUnicodeString(&infW
);
4064 /***********************************************************************
4065 * SetupDiGetINFClassW (SETUPAPI.@)
4067 BOOL WINAPI
SetupDiGetINFClassW(PCWSTR inf
, LPGUID class_guid
, PWSTR class_name
,
4068 DWORD size
, PDWORD required_size
)
4070 BOOL have_guid
, have_name
;
4072 WCHAR buffer
[MAX_PATH
];
4076 SetLastError(ERROR_INVALID_PARAMETER
);
4080 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(inf
))
4082 FIXME("%s not found. Searching via DevicePath not implemented\n", debugstr_w(inf
));
4083 SetLastError(ERROR_FILE_NOT_FOUND
);
4087 if (!class_guid
|| !class_name
|| !size
)
4089 SetLastError(ERROR_INVALID_PARAMETER
);
4093 if (!GetPrivateProfileStringW(Version
, Signature
, NULL
, buffer
, MAX_PATH
, inf
))
4096 if (lstrcmpiW(buffer
, Chicago
) && lstrcmpiW(buffer
, WindowsNT
))
4100 have_guid
= 0 < GetPrivateProfileStringW(Version
, ClassGUID
, NULL
, buffer
, MAX_PATH
, inf
);
4103 buffer
[lstrlenW(buffer
)-1] = 0;
4104 if (RPC_S_OK
!= UuidFromStringW(buffer
+ 1, class_guid
))
4106 FIXME("failed to convert \"%s\" into a guid\n", debugstr_w(buffer
));
4107 SetLastError(ERROR_INVALID_PARAMETER
);
4113 dret
= GetPrivateProfileStringW(Version
, Class
, NULL
, buffer
, MAX_PATH
, inf
);
4114 have_name
= 0 < dret
;
4116 if (dret
>= MAX_PATH
-1) FIXME("buffer might be too small\n");
4117 if (have_guid
&& !have_name
) FIXME("class name lookup via guid not implemented\n");
4121 if (dret
< size
) lstrcpyW(class_name
, buffer
);
4124 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4129 if (required_size
) *required_size
= dret
+ ((dret
) ? 1 : 0);
4131 return (have_guid
|| have_name
);