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/heap.h"
37 #include "wine/list.h"
38 #include "wine/unicode.h"
44 #include "setupapi_private.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
49 /* Unicode constants */
50 static const WCHAR Chicago
[] = {'$','C','h','i','c','a','g','o','$',0};
51 static const WCHAR ClassGUID
[] = {'C','l','a','s','s','G','U','I','D',0};
52 static const WCHAR Class
[] = {'C','l','a','s','s',0};
53 static const WCHAR ClassInstall32
[] = {'C','l','a','s','s','I','n','s','t','a','l','l','3','2',0};
54 static const WCHAR NoDisplayClass
[] = {'N','o','D','i','s','p','l','a','y','C','l','a','s','s',0};
55 static const WCHAR NoInstallClass
[] = {'N','o','I','n','s','t','a','l','l','C','l','a','s','s',0};
56 static const WCHAR NoUseClass
[] = {'N','o','U','s','e','C','l','a','s','s',0};
57 static const WCHAR NtExtension
[] = {'.','N','T',0};
58 static const WCHAR NtPlatformExtension
[] = {'.','N','T','x','8','6',0};
59 static const WCHAR Signature
[] = {'S','i','g','n','a','t','u','r','e',0};
60 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
61 static const WCHAR WinExtension
[] = {'.','W','i','n',0};
62 static const WCHAR WindowsNT
[] = {'$','W','i','n','d','o','w','s',' ','N','T','$',0};
64 /* Registry key and value names */
65 static const WCHAR ControlClass
[] = {'S','y','s','t','e','m','\\',
66 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
67 'C','o','n','t','r','o','l','\\',
68 'C','l','a','s','s',0};
70 static const WCHAR DeviceClasses
[] = {'S','y','s','t','e','m','\\',
71 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
72 'C','o','n','t','r','o','l','\\',
73 'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
74 static const WCHAR Enum
[] = {'S','y','s','t','e','m','\\',
75 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
77 static const WCHAR DeviceDesc
[] = {'D','e','v','i','c','e','D','e','s','c',0};
78 static const WCHAR DeviceInstance
[] = {'D','e','v','i','c','e','I','n','s','t','a','n','c','e',0};
79 static const WCHAR DeviceParameters
[] = {'D','e','v','i','c','e',' ','P','a','r','a','m','e','t','e','r','s',0};
80 static const WCHAR HardwareId
[] = {'H','a','r','d','w','a','r','e','I','D',0};
81 static const WCHAR CompatibleIDs
[] = {'C','o','m','p','a','t','i','b','l','e','I','d','s',0};
82 static const WCHAR Service
[] = {'S','e','r','v','i','c','e',0};
83 static const WCHAR Driver
[] = {'D','r','i','v','e','r',0};
84 static const WCHAR ConfigFlags
[] = {'C','o','n','f','i','g','F','l','a','g','s',0};
85 static const WCHAR Mfg
[] = {'M','f','g',0};
86 static const WCHAR FriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
87 static const WCHAR LocationInformation
[] = {'L','o','c','a','t','i','o','n','I','n','f','o','r','m','a','t','i','o','n',0};
88 static const WCHAR Capabilities
[] = {'C','a','p','a','b','i','l','i','t','i','e','s',0};
89 static const WCHAR UINumber
[] = {'U','I','N','u','m','b','e','r',0};
90 static const WCHAR UpperFilters
[] = {'U','p','p','e','r','F','i','l','t','e','r','s',0};
91 static const WCHAR LowerFilters
[] = {'L','o','w','e','r','F','i','l','t','e','r','s',0};
92 static const WCHAR Phantom
[] = {'P','h','a','n','t','o','m',0};
93 static const WCHAR SymbolicLink
[] = {'S','y','m','b','o','l','i','c','L','i','n','k',0};
94 static const WCHAR Control
[] = {'C','o','n','t','r','o','l',0};
95 static const WCHAR Linked
[] = {'L','i','n','k','e','d',0};
97 /* is used to identify if a DeviceInfoSet pointer is
99 #define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff056
103 DWORD magic
; /* if is equal to SETUP_DEVICE_INFO_SET_MAGIC struct is okay */
112 struct DeviceInfoSet
*set
;
116 struct list interfaces
;
126 struct device
*device
;
132 static inline void copy_device_data(SP_DEVINFO_DATA
*data
, const struct device
*device
)
134 data
->ClassGuid
= device
->class;
135 data
->DevInst
= device
->devnode
;
136 data
->Reserved
= (ULONG_PTR
)device
;
139 static inline void copy_device_iface_data(SP_DEVICE_INTERFACE_DATA
*data
,
140 const struct device_iface
*iface
)
142 data
->InterfaceClassGuid
= iface
->class;
143 data
->Flags
= iface
->flags
;
144 data
->Reserved
= (ULONG_PTR
)iface
;
147 static struct device
**devnode_table
;
148 static unsigned int devnode_table_size
;
150 static DEVINST
alloc_devnode(struct device
*device
)
154 for (i
= 0; i
< devnode_table_size
; ++i
)
156 if (!devnode_table
[i
])
160 if (i
== devnode_table_size
)
164 devnode_table_size
*= 2;
165 devnode_table
= heap_realloc_zero(devnode_table
,
166 devnode_table_size
* sizeof(*devnode_table
));
170 devnode_table_size
= 256;
171 devnode_table
= heap_alloc_zero(devnode_table_size
* sizeof(*devnode_table
));
175 devnode_table
[i
] = device
;
179 static void free_devnode(DEVINST devnode
)
181 devnode_table
[devnode
] = NULL
;
184 static struct device
*get_devnode_device(DEVINST devnode
)
186 if (devnode
< devnode_table_size
)
187 return devnode_table
[devnode
];
189 WARN("device node %u not found\n", devnode
);
193 static void SETUPDI_GuidToString(const GUID
*guid
, LPWSTR guidStr
)
195 static const WCHAR fmt
[] = {'{','%','0','8','X','-','%','0','4','X','-',
196 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
197 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
200 sprintfW(guidStr
, fmt
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
201 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
202 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
205 static WCHAR
*get_iface_key_path(struct device_iface
*iface
)
207 const WCHAR slashW
[] = {'\\',0};
209 size_t len
= strlenW(DeviceClasses
) + 1 + 38 + 1 + strlenW(iface
->symlink
);
211 if (!(path
= heap_alloc((len
+ 1) * sizeof(WCHAR
))))
213 SetLastError(ERROR_OUTOFMEMORY
);
217 strcpyW(path
, DeviceClasses
);
218 strcatW(path
, slashW
);
219 SETUPDI_GuidToString(&iface
->class, path
+ strlenW(path
));
220 strcatW(path
, slashW
);
221 ptr
= path
+ strlenW(path
);
222 strcatW(path
, iface
->symlink
);
223 if (strlenW(iface
->symlink
) > 3)
224 ptr
[0] = ptr
[1] = ptr
[3] = '#';
226 ptr
= strchrW(ptr
, '\\');
232 static WCHAR
*get_refstr_key_path(struct device_iface
*iface
)
234 const WCHAR hashW
[] = {'#',0};
235 const WCHAR slashW
[] = {'\\',0};
237 size_t len
= strlenW(DeviceClasses
) + 1 + 38 + 1 + strlenW(iface
->symlink
) + 1 + 1;
240 len
+= strlenW(iface
->refstr
);
242 if (!(path
= heap_alloc((len
+ 1) * sizeof(WCHAR
))))
244 SetLastError(ERROR_OUTOFMEMORY
);
248 strcpyW(path
, DeviceClasses
);
249 strcatW(path
, slashW
);
250 SETUPDI_GuidToString(&iface
->class, path
+ strlenW(path
));
251 strcatW(path
, slashW
);
252 ptr
= path
+ strlenW(path
);
253 strcatW(path
, iface
->symlink
);
254 if (strlenW(iface
->symlink
) > 3)
255 ptr
[0] = ptr
[1] = ptr
[3] = '#';
257 ptr
= strchrW(ptr
, '\\');
260 strcatW(path
, slashW
);
261 strcatW(path
, hashW
);
264 strcatW(path
, iface
->refstr
);
269 static LPWSTR
SETUPDI_CreateSymbolicLinkPath(LPCWSTR instanceId
,
270 const GUID
*InterfaceClassGuid
, LPCWSTR ReferenceString
)
272 static const WCHAR fmt
[] = {'\\','\\','?','\\','%','s','#','%','s',0};
277 SETUPDI_GuidToString(InterfaceClassGuid
, guidStr
);
278 /* omit length of format specifiers, but include NULL terminator: */
279 len
= lstrlenW(fmt
) - 4 + 1;
280 len
+= lstrlenW(instanceId
) + lstrlenW(guidStr
);
281 if (ReferenceString
&& *ReferenceString
)
283 /* space for a hash between string and reference string: */
284 len
+= lstrlenW(ReferenceString
) + 1;
286 ret
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
289 int printed
= sprintfW(ret
, fmt
, instanceId
, guidStr
);
292 /* replace '\\' with '#' after the "\\\\?\\" beginning */
293 for (ptr
= strchrW(ret
+ 4, '\\'); ptr
; ptr
= strchrW(ptr
+ 1, '\\'))
295 if (ReferenceString
&& *ReferenceString
)
298 lstrcpyW(ret
+ printed
+ 1, ReferenceString
);
304 static BOOL
is_linked(HKEY key
)
306 DWORD linked
, type
, size
;
310 if (!RegOpenKeyW(key
, Control
, &control_key
))
312 size
= sizeof(DWORD
);
313 if (!RegQueryValueExW(control_key
, Linked
, NULL
, &type
, (BYTE
*)&linked
, &size
)
314 && type
== REG_DWORD
&& linked
)
317 RegCloseKey(control_key
);
323 static struct device_iface
*SETUPDI_CreateDeviceInterface(struct device
*device
,
324 const GUID
*class, const WCHAR
*refstr
)
326 struct device_iface
*iface
= NULL
;
327 WCHAR
*refstr2
= NULL
, *symlink
= NULL
, *path
= NULL
;
331 TRACE("%p %s %s\n", device
, debugstr_guid(class), debugstr_w(refstr
));
333 /* check if it already exists */
334 LIST_FOR_EACH_ENTRY(iface
, &device
->interfaces
, struct device_iface
, entry
)
336 if (IsEqualGUID(&iface
->class, class) && !lstrcmpiW(iface
->refstr
, refstr
))
340 iface
= heap_alloc(sizeof(*iface
));
341 symlink
= SETUPDI_CreateSymbolicLinkPath(device
->instanceId
, class, refstr
);
343 if (!iface
|| !symlink
)
345 SetLastError(ERROR_OUTOFMEMORY
);
349 if (refstr
&& !(refstr2
= strdupW(refstr
)))
351 SetLastError(ERROR_OUTOFMEMORY
);
354 iface
->refstr
= refstr2
;
355 iface
->symlink
= symlink
;
356 iface
->device
= device
;
357 iface
->class = *class;
360 if (!(path
= get_iface_key_path(iface
)))
362 SetLastError(ERROR_OUTOFMEMORY
);
366 if ((ret
= RegCreateKeyW(HKEY_LOCAL_MACHINE
, path
, &key
)))
371 RegSetValueExW(key
, DeviceInstance
, 0, REG_SZ
, (BYTE
*)device
->instanceId
,
372 lstrlenW(device
->instanceId
) * sizeof(WCHAR
));
376 if (!(path
= get_refstr_key_path(iface
)))
378 SetLastError(ERROR_OUTOFMEMORY
);
382 if ((ret
= RegCreateKeyW(HKEY_LOCAL_MACHINE
, path
, &key
)))
387 RegSetValueExW(key
, SymbolicLink
, 0, REG_SZ
, (BYTE
*)iface
->symlink
,
388 lstrlenW(iface
->symlink
) * sizeof(WCHAR
));
391 iface
->flags
|= SPINT_ACTIVE
;
396 list_add_tail(&device
->interfaces
, &iface
->entry
);
407 static BOOL
SETUPDI_SetInterfaceSymbolicLink(struct device_iface
*iface
,
408 const WCHAR
*symlink
)
410 heap_free(iface
->symlink
);
411 if ((iface
->symlink
= strdupW(symlink
)))
416 static HKEY
SETUPDI_CreateDevKey(struct device
*device
)
418 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
421 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
422 NULL
, &enumKey
, NULL
);
425 RegCreateKeyExW(enumKey
, device
->instanceId
, 0, NULL
, 0,
426 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
427 RegCloseKey(enumKey
);
432 static HKEY
SETUPDI_CreateDrvKey(struct device
*device
)
434 static const WCHAR slash
[] = { '\\',0 };
435 WCHAR classKeyPath
[MAX_PATH
];
436 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
439 lstrcpyW(classKeyPath
, ControlClass
);
440 lstrcatW(classKeyPath
, slash
);
441 SETUPDI_GuidToString(&device
->set
->ClassGuid
,
442 classKeyPath
+ lstrlenW(classKeyPath
));
443 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
444 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
447 static const WCHAR fmt
[] = { '%','0','4','u',0 };
450 sprintfW(devId
, fmt
, device
->devnode
);
451 RegCreateKeyExW(classKey
, devId
, 0, NULL
, 0, KEY_READ
| KEY_WRITE
,
453 RegCloseKey(classKey
);
458 struct PropertyMapEntry
465 static const struct PropertyMapEntry PropertyMap
[] = {
466 { REG_SZ
, "DeviceDesc", DeviceDesc
},
467 { REG_MULTI_SZ
, "HardwareId", HardwareId
},
468 { REG_MULTI_SZ
, "CompatibleIDs", CompatibleIDs
},
469 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
470 { REG_SZ
, "Service", Service
},
471 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
472 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
473 { REG_SZ
, "Class", Class
},
474 { REG_SZ
, "ClassGUID", ClassGUID
},
475 { REG_SZ
, "Driver", Driver
},
476 { REG_DWORD
, "ConfigFlags", ConfigFlags
},
477 { REG_SZ
, "Mfg", Mfg
},
478 { REG_SZ
, "FriendlyName", FriendlyName
},
479 { REG_SZ
, "LocationInformation", LocationInformation
},
480 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
481 { REG_DWORD
, "Capabilities", Capabilities
},
482 { REG_DWORD
, "UINumber", UINumber
},
483 { REG_MULTI_SZ
, "UpperFilters", UpperFilters
},
484 { REG_MULTI_SZ
, "LowerFilters", LowerFilters
},
487 static BOOL
SETUPDI_SetDeviceRegistryPropertyW(struct device
*device
,
488 DWORD prop
, const BYTE
*buffer
, DWORD size
)
490 if (prop
< ARRAY_SIZE(PropertyMap
) && PropertyMap
[prop
].nameW
)
492 LONG ret
= RegSetValueExW(device
->key
, PropertyMap
[prop
].nameW
, 0,
493 PropertyMap
[prop
].regType
, buffer
, size
);
502 static void SETUPDI_RemoveDevice(struct device
*device
)
504 struct device_iface
*iface
, *next
;
507 if (device
->key
!= INVALID_HANDLE_VALUE
)
508 RegCloseKey(device
->key
);
514 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0,
515 KEY_ALL_ACCESS
, NULL
, &enumKey
, NULL
);
518 RegDeleteTreeW(enumKey
, device
->instanceId
);
519 RegCloseKey(enumKey
);
522 heap_free(device
->instanceId
);
523 LIST_FOR_EACH_ENTRY_SAFE(iface
, next
, &device
->interfaces
,
524 struct device_iface
, entry
)
526 list_remove(&iface
->entry
);
527 if ((path
= get_refstr_key_path(iface
)))
529 RegDeleteKeyW(HKEY_LOCAL_MACHINE
, path
);
532 heap_free(iface
->refstr
);
533 heap_free(iface
->symlink
);
536 free_devnode(device
->devnode
);
537 list_remove(&device
->entry
);
541 static struct device
*SETUPDI_CreateDeviceInfo(struct DeviceInfoSet
*set
,
542 const GUID
*class, const WCHAR
*instanceid
, BOOL phantom
)
544 struct device
*device
;
547 TRACE("%p, %s, %s, %d\n", set
, debugstr_guid(class),
548 debugstr_w(instanceid
), phantom
);
550 if (!(device
= heap_alloc(sizeof(*device
))))
552 SetLastError(ERROR_OUTOFMEMORY
);
556 if (!(device
->instanceId
= strdupW(instanceid
)))
558 SetLastError(ERROR_OUTOFMEMORY
);
563 struprW(device
->instanceId
);
565 device
->key
= SETUPDI_CreateDevKey(device
);
566 device
->phantom
= phantom
;
567 list_init(&device
->interfaces
);
568 device
->class = *class;
569 device
->devnode
= alloc_devnode(device
);
570 list_add_tail(&set
->devices
, &device
->entry
);
573 SETUPDI_GuidToString(class, guidstr
);
574 SETUPDI_SetDeviceRegistryPropertyW(device
, SPDRP_CLASSGUID
,
575 (const BYTE
*)guidstr
, sizeof(guidstr
));
579 /***********************************************************************
580 * SetupDiBuildClassInfoList (SETUPAPI.@)
582 * Returns a list of setup class GUIDs that identify the classes
583 * that are installed on a local machine.
586 * Flags [I] control exclusion of classes from the list.
587 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
588 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
589 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
595 BOOL WINAPI
SetupDiBuildClassInfoList(
597 LPGUID ClassGuidList
,
598 DWORD ClassGuidListSize
,
602 return SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
603 ClassGuidListSize
, RequiredSize
,
607 /***********************************************************************
608 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
610 * Returns a list of setup class GUIDs that identify the classes
611 * that are installed on a local or remote machine.
614 * Flags [I] control exclusion of classes from the list.
615 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
616 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
617 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
618 * MachineName [I] name of a remote machine.
619 * Reserved [I] must be NULL.
625 BOOL WINAPI
SetupDiBuildClassInfoListExA(
627 LPGUID ClassGuidList
,
628 DWORD ClassGuidListSize
,
633 LPWSTR MachineNameW
= NULL
;
640 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
641 if (MachineNameW
== NULL
) return FALSE
;
644 bResult
= SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
645 ClassGuidListSize
, RequiredSize
,
646 MachineNameW
, Reserved
);
648 MyFree(MachineNameW
);
653 /***********************************************************************
654 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
656 * Returns a list of setup class GUIDs that identify the classes
657 * that are installed on a local or remote machine.
660 * Flags [I] control exclusion of classes from the list.
661 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
662 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
663 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
664 * MachineName [I] name of a remote machine.
665 * Reserved [I] must be NULL.
671 BOOL WINAPI
SetupDiBuildClassInfoListExW(
673 LPGUID ClassGuidList
,
674 DWORD ClassGuidListSize
,
685 DWORD dwGuidListIndex
= 0;
689 if (RequiredSize
!= NULL
)
692 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
697 if (hClassesKey
== INVALID_HANDLE_VALUE
)
702 for (dwIndex
= 0; ; dwIndex
++)
705 lError
= RegEnumKeyExW(hClassesKey
,
713 TRACE("RegEnumKeyExW() returns %d\n", lError
);
714 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
716 TRACE("Key name: %p\n", szKeyName
);
718 if (RegOpenKeyExW(hClassesKey
,
724 RegCloseKey(hClassesKey
);
728 if (!RegQueryValueExW(hClassKey
,
735 TRACE("'NoUseClass' value found!\n");
736 RegCloseKey(hClassKey
);
740 if ((Flags
& DIBCI_NOINSTALLCLASS
) &&
741 (!RegQueryValueExW(hClassKey
,
748 TRACE("'NoInstallClass' value found!\n");
749 RegCloseKey(hClassKey
);
753 if ((Flags
& DIBCI_NODISPLAYCLASS
) &&
754 (!RegQueryValueExW(hClassKey
,
761 TRACE("'NoDisplayClass' value found!\n");
762 RegCloseKey(hClassKey
);
766 RegCloseKey(hClassKey
);
768 TRACE("Guid: %p\n", szKeyName
);
769 if (dwGuidListIndex
< ClassGuidListSize
)
771 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
775 TRACE("Guid: %p\n", &szKeyName
[1]);
777 UuidFromStringW(&szKeyName
[1],
778 &ClassGuidList
[dwGuidListIndex
]);
784 if (lError
!= ERROR_SUCCESS
)
788 RegCloseKey(hClassesKey
);
790 if (RequiredSize
!= NULL
)
791 *RequiredSize
= dwGuidListIndex
;
793 if (ClassGuidListSize
< dwGuidListIndex
)
795 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
802 /***********************************************************************
803 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
805 BOOL WINAPI
SetupDiClassGuidsFromNameA(
807 LPGUID ClassGuidList
,
808 DWORD ClassGuidListSize
,
811 return SetupDiClassGuidsFromNameExA(ClassName
, ClassGuidList
,
812 ClassGuidListSize
, RequiredSize
,
816 /***********************************************************************
817 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
819 BOOL WINAPI
SetupDiClassGuidsFromNameW(
821 LPGUID ClassGuidList
,
822 DWORD ClassGuidListSize
,
825 return SetupDiClassGuidsFromNameExW(ClassName
, ClassGuidList
,
826 ClassGuidListSize
, RequiredSize
,
830 /***********************************************************************
831 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
833 BOOL WINAPI
SetupDiClassGuidsFromNameExA(
835 LPGUID ClassGuidList
,
836 DWORD ClassGuidListSize
,
841 LPWSTR ClassNameW
= NULL
;
842 LPWSTR MachineNameW
= NULL
;
845 ClassNameW
= MultiByteToUnicode(ClassName
, CP_ACP
);
846 if (ClassNameW
== NULL
)
851 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
852 if (MachineNameW
== NULL
)
859 bResult
= SetupDiClassGuidsFromNameExW(ClassNameW
, ClassGuidList
,
860 ClassGuidListSize
, RequiredSize
,
861 MachineNameW
, Reserved
);
863 MyFree(MachineNameW
);
869 /***********************************************************************
870 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
872 BOOL WINAPI
SetupDiClassGuidsFromNameExW(
874 LPGUID ClassGuidList
,
875 DWORD ClassGuidListSize
,
881 WCHAR szClassName
[256];
887 DWORD dwGuidListIndex
= 0;
889 if (RequiredSize
!= NULL
)
892 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
897 if (hClassesKey
== INVALID_HANDLE_VALUE
)
902 for (dwIndex
= 0; ; dwIndex
++)
904 dwLength
= sizeof(szKeyName
) / sizeof(WCHAR
);
905 lError
= RegEnumKeyExW(hClassesKey
,
913 TRACE("RegEnumKeyExW() returns %d\n", lError
);
914 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
916 TRACE("Key name: %p\n", szKeyName
);
918 if (RegOpenKeyExW(hClassesKey
,
924 RegCloseKey(hClassesKey
);
928 dwLength
= sizeof(szClassName
);
929 if (!RegQueryValueExW(hClassKey
,
936 TRACE("Class name: %p\n", szClassName
);
938 if (strcmpiW(szClassName
, ClassName
) == 0)
940 TRACE("Found matching class name\n");
942 TRACE("Guid: %p\n", szKeyName
);
943 if (dwGuidListIndex
< ClassGuidListSize
)
945 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
949 TRACE("Guid: %p\n", &szKeyName
[1]);
951 UuidFromStringW(&szKeyName
[1],
952 &ClassGuidList
[dwGuidListIndex
]);
959 RegCloseKey(hClassKey
);
962 if (lError
!= ERROR_SUCCESS
)
966 RegCloseKey(hClassesKey
);
968 if (RequiredSize
!= NULL
)
969 *RequiredSize
= dwGuidListIndex
;
971 if (ClassGuidListSize
< dwGuidListIndex
)
973 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
980 /***********************************************************************
981 * SetupDiClassNameFromGuidA (SETUPAPI.@)
983 BOOL WINAPI
SetupDiClassNameFromGuidA(
984 const GUID
* ClassGuid
,
989 return SetupDiClassNameFromGuidExA(ClassGuid
, ClassName
,
990 ClassNameSize
, RequiredSize
,
994 /***********************************************************************
995 * SetupDiClassNameFromGuidW (SETUPAPI.@)
997 BOOL WINAPI
SetupDiClassNameFromGuidW(
998 const GUID
* ClassGuid
,
1000 DWORD ClassNameSize
,
1001 PDWORD RequiredSize
)
1003 return SetupDiClassNameFromGuidExW(ClassGuid
, ClassName
,
1004 ClassNameSize
, RequiredSize
,
1008 /***********************************************************************
1009 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1011 BOOL WINAPI
SetupDiClassNameFromGuidExA(
1012 const GUID
* ClassGuid
,
1014 DWORD ClassNameSize
,
1015 PDWORD RequiredSize
,
1019 WCHAR ClassNameW
[MAX_CLASS_NAME_LEN
];
1020 LPWSTR MachineNameW
= NULL
;
1024 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1025 ret
= SetupDiClassNameFromGuidExW(ClassGuid
, ClassNameW
, MAX_CLASS_NAME_LEN
,
1026 NULL
, MachineNameW
, Reserved
);
1029 int len
= WideCharToMultiByte(CP_ACP
, 0, ClassNameW
, -1, ClassName
,
1030 ClassNameSize
, NULL
, NULL
);
1032 if (!ClassNameSize
&& RequiredSize
)
1033 *RequiredSize
= len
;
1035 MyFree(MachineNameW
);
1039 /***********************************************************************
1040 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1042 BOOL WINAPI
SetupDiClassNameFromGuidExW(
1043 const GUID
* ClassGuid
,
1045 DWORD ClassNameSize
,
1046 PDWORD RequiredSize
,
1053 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1058 if (hKey
== INVALID_HANDLE_VALUE
)
1063 if (RequiredSize
!= NULL
)
1066 if (RegQueryValueExW(hKey
,
1077 *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1080 dwLength
= ClassNameSize
* sizeof(WCHAR
);
1081 if (RegQueryValueExW(hKey
,
1097 /***********************************************************************
1098 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1101 SetupDiCreateDeviceInfoList(const GUID
*ClassGuid
,
1104 return SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
, NULL
, NULL
);
1107 /***********************************************************************
1108 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1111 SetupDiCreateDeviceInfoListExA(const GUID
*ClassGuid
,
1116 LPWSTR MachineNameW
= NULL
;
1123 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1124 if (MachineNameW
== NULL
)
1125 return INVALID_HANDLE_VALUE
;
1128 hDevInfo
= SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
,
1129 MachineNameW
, Reserved
);
1131 MyFree(MachineNameW
);
1136 /***********************************************************************
1137 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1139 * Create an empty DeviceInfoSet list.
1142 * ClassGuid [I] if not NULL only devices with GUID ClassGuid are associated
1144 * hwndParent [I] hwnd needed for interface related actions.
1145 * MachineName [I] name of machine to create empty DeviceInfoSet list, if NULL
1146 * local registry will be used.
1147 * Reserved [I] must be NULL
1150 * Success: empty list.
1151 * Failure: INVALID_HANDLE_VALUE.
1154 SetupDiCreateDeviceInfoListExW(const GUID
*ClassGuid
,
1159 struct DeviceInfoSet
*list
= NULL
;
1160 DWORD size
= sizeof(struct DeviceInfoSet
);
1162 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1163 debugstr_w(MachineName
), Reserved
);
1165 if (MachineName
&& *MachineName
)
1167 FIXME("remote support is not implemented\n");
1168 SetLastError(ERROR_INVALID_MACHINENAME
);
1169 return INVALID_HANDLE_VALUE
;
1172 if (Reserved
!= NULL
)
1174 SetLastError(ERROR_INVALID_PARAMETER
);
1175 return INVALID_HANDLE_VALUE
;
1178 list
= HeapAlloc(GetProcessHeap(), 0, size
);
1181 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1182 return INVALID_HANDLE_VALUE
;
1185 list
->magic
= SETUP_DEVICE_INFO_SET_MAGIC
;
1186 list
->hwndParent
= hwndParent
;
1187 memcpy(&list
->ClassGuid
,
1188 ClassGuid
? ClassGuid
: &GUID_NULL
,
1189 sizeof(list
->ClassGuid
));
1191 list_init(&list
->devices
);
1196 /***********************************************************************
1197 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1199 HKEY WINAPI
SetupDiCreateDevRegKeyA(
1200 HDEVINFO DeviceInfoSet
,
1201 PSP_DEVINFO_DATA DeviceInfoData
,
1206 PCSTR InfSectionName
)
1208 PWSTR InfSectionNameW
= NULL
;
1211 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1212 HwProfile
, KeyType
, InfHandle
, debugstr_a(InfSectionName
));
1216 if (!InfSectionName
)
1218 SetLastError(ERROR_INVALID_PARAMETER
);
1219 return INVALID_HANDLE_VALUE
;
1223 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
1224 if (InfSectionNameW
== NULL
) return INVALID_HANDLE_VALUE
;
1227 key
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, Scope
,
1228 HwProfile
, KeyType
, InfHandle
, InfSectionNameW
);
1229 MyFree(InfSectionNameW
);
1233 /***********************************************************************
1234 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1236 HKEY WINAPI
SetupDiCreateDevRegKeyW(
1237 HDEVINFO DeviceInfoSet
,
1238 PSP_DEVINFO_DATA DeviceInfoData
,
1243 PCWSTR InfSectionName
)
1245 struct DeviceInfoSet
*set
= DeviceInfoSet
;
1246 struct device
*device
;
1247 HKEY key
= INVALID_HANDLE_VALUE
;
1249 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1250 HwProfile
, KeyType
, InfHandle
, debugstr_w(InfSectionName
));
1252 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1254 SetLastError(ERROR_INVALID_HANDLE
);
1255 return INVALID_HANDLE_VALUE
;
1257 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1259 SetLastError(ERROR_INVALID_HANDLE
);
1260 return INVALID_HANDLE_VALUE
;
1262 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1263 || !DeviceInfoData
->Reserved
)
1265 SetLastError(ERROR_INVALID_PARAMETER
);
1266 return INVALID_HANDLE_VALUE
;
1268 device
= (struct device
*)DeviceInfoData
->Reserved
;
1269 if (device
->set
!= set
)
1271 SetLastError(ERROR_INVALID_PARAMETER
);
1272 return INVALID_HANDLE_VALUE
;
1274 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
1276 SetLastError(ERROR_INVALID_FLAGS
);
1277 return INVALID_HANDLE_VALUE
;
1279 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
1281 SetLastError(ERROR_INVALID_FLAGS
);
1282 return INVALID_HANDLE_VALUE
;
1284 if (device
->phantom
)
1286 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
1287 return INVALID_HANDLE_VALUE
;
1289 if (Scope
!= DICS_FLAG_GLOBAL
)
1290 FIXME("unimplemented for scope %d\n", Scope
);
1294 key
= SETUPDI_CreateDevKey(device
);
1297 key
= SETUPDI_CreateDrvKey(device
);
1300 WARN("unknown KeyType %d\n", KeyType
);
1303 SetupInstallFromInfSectionW(NULL
, InfHandle
, InfSectionName
, SPINST_ALL
,
1304 NULL
, NULL
, SP_COPY_NEWER_ONLY
, NULL
, NULL
, DeviceInfoSet
,
1309 /***********************************************************************
1310 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1312 BOOL WINAPI
SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet
, PCSTR DeviceName
,
1313 const GUID
*ClassGuid
, PCSTR DeviceDescription
, HWND hwndParent
, DWORD CreationFlags
,
1314 PSP_DEVINFO_DATA DeviceInfoData
)
1317 LPWSTR DeviceNameW
= NULL
;
1318 LPWSTR DeviceDescriptionW
= NULL
;
1322 DeviceNameW
= MultiByteToUnicode(DeviceName
, CP_ACP
);
1323 if (DeviceNameW
== NULL
) return FALSE
;
1325 if (DeviceDescription
)
1327 DeviceDescriptionW
= MultiByteToUnicode(DeviceDescription
, CP_ACP
);
1328 if (DeviceDescriptionW
== NULL
)
1330 MyFree(DeviceNameW
);
1335 ret
= SetupDiCreateDeviceInfoW(DeviceInfoSet
, DeviceNameW
, ClassGuid
, DeviceDescriptionW
,
1336 hwndParent
, CreationFlags
, DeviceInfoData
);
1338 MyFree(DeviceNameW
);
1339 MyFree(DeviceDescriptionW
);
1344 static DWORD
SETUPDI_DevNameToDevID(LPCWSTR devName
)
1347 int devNameLen
= lstrlenW(devName
);
1351 TRACE("%s\n", debugstr_w(devName
));
1352 for (ptr
= devName
; valid
&& *ptr
&& ptr
- devName
< devNameLen
; )
1357 devInst
|= *ptr
- '0';
1363 TRACE("%d\n", valid
? devInst
: 0xffffffff);
1364 return valid
? devInst
: 0xffffffff;
1367 /***********************************************************************
1368 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1370 BOOL WINAPI
SetupDiCreateDeviceInfoW(HDEVINFO DeviceInfoSet
, PCWSTR DeviceName
,
1371 const GUID
*ClassGuid
, PCWSTR DeviceDescription
, HWND hwndParent
, DWORD CreationFlags
,
1372 SP_DEVINFO_DATA
*device_data
)
1374 struct DeviceInfoSet
*set
= DeviceInfoSet
;
1375 BOOL ret
= FALSE
, allocatedInstanceId
= FALSE
;
1376 LPCWSTR instanceId
= NULL
;
1378 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet
, debugstr_w(DeviceName
),
1379 debugstr_guid(ClassGuid
), debugstr_w(DeviceDescription
),
1380 hwndParent
, CreationFlags
, device_data
);
1384 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1387 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1389 SetLastError(ERROR_INVALID_HANDLE
);
1394 SetLastError(ERROR_INVALID_PARAMETER
);
1397 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1399 SetLastError(ERROR_INVALID_HANDLE
);
1402 if (!IsEqualGUID(&set
->ClassGuid
, &GUID_NULL
) &&
1403 !IsEqualGUID(ClassGuid
, &set
->ClassGuid
))
1405 SetLastError(ERROR_CLASS_MISMATCH
);
1408 if ((CreationFlags
& DICD_GENERATE_ID
))
1410 if (strchrW(DeviceName
, '\\'))
1411 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1414 static const WCHAR newDeviceFmt
[] = {'R','O','O','T','\\','%','s',
1415 '\\','%','0','4','d',0};
1420 DWORD highestDevID
= 0;
1421 struct device
*device
;
1423 LIST_FOR_EACH_ENTRY(device
, &set
->devices
, struct device
, entry
)
1425 const WCHAR
*devName
= strrchrW(device
->instanceId
, '\\');
1431 devName
= device
->instanceId
;
1432 id
= SETUPDI_DevNameToDevID(devName
);
1433 if (id
!= 0xffffffff && id
> highestDevID
)
1436 devId
= highestDevID
+ 1;
1440 /* 17 == lstrlenW(L"Root\\") + lstrlenW("\\") + 1 + %d max size */
1441 instanceId
= HeapAlloc(GetProcessHeap(), 0,
1442 (17 + lstrlenW(DeviceName
)) * sizeof(WCHAR
));
1445 sprintfW((LPWSTR
)instanceId
, newDeviceFmt
, DeviceName
,
1447 allocatedInstanceId
= TRUE
;
1456 struct device
*device
;
1459 instanceId
= DeviceName
;
1460 LIST_FOR_EACH_ENTRY(device
, &set
->devices
, struct device
, entry
)
1462 if (!lstrcmpiW(DeviceName
, device
->instanceId
))
1464 SetLastError(ERROR_DEVINST_ALREADY_EXISTS
);
1471 struct device
*device
= NULL
;
1473 if ((device
= SETUPDI_CreateDeviceInfo(set
, ClassGuid
, instanceId
, TRUE
)))
1475 if (DeviceDescription
)
1476 SETUPDI_SetDeviceRegistryPropertyW(device
, SPDRP_DEVICEDESC
,
1477 (const BYTE
*)DeviceDescription
,
1478 lstrlenW(DeviceDescription
) * sizeof(WCHAR
));
1481 if (device_data
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1483 SetLastError(ERROR_INVALID_USER_BUFFER
);
1487 copy_device_data(device_data
, device
);
1491 if (allocatedInstanceId
)
1492 HeapFree(GetProcessHeap(), 0, (LPWSTR
)instanceId
);
1497 /***********************************************************************
1498 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1500 BOOL WINAPI
SetupDiRegisterDeviceInfo(
1501 HDEVINFO DeviceInfoSet
,
1502 PSP_DEVINFO_DATA DeviceInfoData
,
1504 PSP_DETSIG_CMPPROC CompareProc
,
1505 PVOID CompareContext
,
1506 PSP_DEVINFO_DATA DupDeviceInfoData
)
1508 struct DeviceInfoSet
*set
= DeviceInfoSet
;
1509 struct device
*device
;
1511 TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet
, DeviceInfoData
, Flags
,
1512 CompareProc
, CompareContext
, DupDeviceInfoData
);
1514 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1516 SetLastError(ERROR_INVALID_HANDLE
);
1519 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1521 SetLastError(ERROR_INVALID_HANDLE
);
1524 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1525 || !DeviceInfoData
->Reserved
)
1527 SetLastError(ERROR_INVALID_PARAMETER
);
1530 device
= (struct device
*)DeviceInfoData
->Reserved
;
1531 if (device
->set
!= set
)
1533 SetLastError(ERROR_INVALID_PARAMETER
);
1536 if (device
->phantom
)
1538 device
->phantom
= FALSE
;
1539 RegDeleteValueW(device
->key
, Phantom
);
1544 /***********************************************************************
1545 * SetupDiRemoveDevice (SETUPAPI.@)
1547 BOOL WINAPI
SetupDiRemoveDevice(
1549 PSP_DEVINFO_DATA info
)
1551 FIXME("(%p, %p): stub\n", devinfo
, info
);
1552 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1556 /***********************************************************************
1557 * SetupDiRemoveDeviceInterface (SETUPAPI.@)
1559 BOOL WINAPI
SetupDiRemoveDeviceInterface(HDEVINFO info
, PSP_DEVICE_INTERFACE_DATA data
)
1561 FIXME("(%p, %p): stub\n", info
, data
);
1562 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1566 /***********************************************************************
1567 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1569 BOOL WINAPI
SetupDiEnumDeviceInfo(
1572 PSP_DEVINFO_DATA info
)
1576 TRACE("%p %d %p\n", devinfo
, index
, info
);
1580 SetLastError(ERROR_INVALID_PARAMETER
);
1583 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
1585 struct DeviceInfoSet
*list
= devinfo
;
1586 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
1588 if (index
< list
->cDevices
)
1590 if (info
->cbSize
== sizeof(SP_DEVINFO_DATA
))
1592 struct device
*device
;
1595 LIST_FOR_EACH_ENTRY(device
, &list
->devices
, struct device
, entry
)
1599 copy_device_data(info
, device
);
1606 SetLastError(ERROR_INVALID_USER_BUFFER
);
1609 SetLastError(ERROR_NO_MORE_ITEMS
);
1612 SetLastError(ERROR_INVALID_HANDLE
);
1615 SetLastError(ERROR_INVALID_HANDLE
);
1619 /***********************************************************************
1620 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1622 BOOL WINAPI
SetupDiGetDeviceInstanceIdA(
1623 HDEVINFO DeviceInfoSet
,
1624 PSP_DEVINFO_DATA DeviceInfoData
,
1625 PSTR DeviceInstanceId
,
1626 DWORD DeviceInstanceIdSize
,
1627 PDWORD RequiredSize
)
1633 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1634 DeviceInstanceIdSize
, RequiredSize
);
1636 SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1641 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1643 instanceId
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
1646 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1653 int len
= WideCharToMultiByte(CP_ACP
, 0, instanceId
, -1,
1655 DeviceInstanceIdSize
, NULL
, NULL
);
1661 if (len
> DeviceInstanceIdSize
)
1663 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1667 *RequiredSize
= len
;
1670 HeapFree(GetProcessHeap(), 0, instanceId
);
1675 /***********************************************************************
1676 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1678 BOOL WINAPI
SetupDiGetDeviceInstanceIdW(
1679 HDEVINFO DeviceInfoSet
,
1680 PSP_DEVINFO_DATA DeviceInfoData
,
1681 PWSTR DeviceInstanceId
,
1682 DWORD DeviceInstanceIdSize
,
1683 PDWORD RequiredSize
)
1685 struct DeviceInfoSet
*set
= DeviceInfoSet
;
1686 struct device
*device
;
1688 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1689 DeviceInstanceIdSize
, RequiredSize
);
1691 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1693 SetLastError(ERROR_INVALID_HANDLE
);
1696 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1698 SetLastError(ERROR_INVALID_HANDLE
);
1701 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1702 || !DeviceInfoData
->Reserved
)
1704 SetLastError(ERROR_INVALID_PARAMETER
);
1707 device
= (struct device
*)DeviceInfoData
->Reserved
;
1708 if (device
->set
!= set
)
1710 SetLastError(ERROR_INVALID_PARAMETER
);
1713 TRACE("instance ID: %s\n", debugstr_w(device
->instanceId
));
1714 if (DeviceInstanceIdSize
< strlenW(device
->instanceId
) + 1)
1716 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1718 *RequiredSize
= lstrlenW(device
->instanceId
) + 1;
1721 lstrcpyW(DeviceInstanceId
, device
->instanceId
);
1723 *RequiredSize
= lstrlenW(device
->instanceId
) + 1;
1727 /***********************************************************************
1728 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1730 BOOL WINAPI
SetupDiGetActualSectionToInstallA(
1732 PCSTR InfSectionName
,
1733 PSTR InfSectionWithExt
,
1734 DWORD InfSectionWithExtSize
,
1735 PDWORD RequiredSize
,
1742 /***********************************************************************
1743 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
1745 BOOL WINAPI
SetupDiGetActualSectionToInstallW(
1747 PCWSTR InfSectionName
,
1748 PWSTR InfSectionWithExt
,
1749 DWORD InfSectionWithExtSize
,
1750 PDWORD RequiredSize
,
1753 WCHAR szBuffer
[MAX_PATH
];
1756 LONG lLineCount
= -1;
1758 lstrcpyW(szBuffer
, InfSectionName
);
1759 dwLength
= lstrlenW(szBuffer
);
1761 if (OsVersionInfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
1763 /* Test section name with '.NTx86' extension */
1764 lstrcpyW(&szBuffer
[dwLength
], NtPlatformExtension
);
1765 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1767 if (lLineCount
== -1)
1769 /* Test section name with '.NT' extension */
1770 lstrcpyW(&szBuffer
[dwLength
], NtExtension
);
1771 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1776 /* Test section name with '.Win' extension */
1777 lstrcpyW(&szBuffer
[dwLength
], WinExtension
);
1778 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1781 if (lLineCount
== -1)
1783 /* Test section name without extension */
1784 szBuffer
[dwLength
] = 0;
1785 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
1788 if (lLineCount
== -1)
1790 SetLastError(ERROR_INVALID_PARAMETER
);
1794 dwFullLength
= lstrlenW(szBuffer
);
1796 if (InfSectionWithExt
!= NULL
&& InfSectionWithExtSize
!= 0)
1798 if (InfSectionWithExtSize
< (dwFullLength
+ 1))
1800 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1804 lstrcpyW(InfSectionWithExt
, szBuffer
);
1805 if (Extension
!= NULL
)
1807 *Extension
= (dwLength
== dwFullLength
) ? NULL
: &InfSectionWithExt
[dwLength
];
1811 if (RequiredSize
!= NULL
)
1813 *RequiredSize
= dwFullLength
+ 1;
1819 /***********************************************************************
1820 * SetupDiGetClassDescriptionA (SETUPAPI.@)
1822 BOOL WINAPI
SetupDiGetClassDescriptionA(
1823 const GUID
* ClassGuid
,
1824 PSTR ClassDescription
,
1825 DWORD ClassDescriptionSize
,
1826 PDWORD RequiredSize
)
1828 return SetupDiGetClassDescriptionExA(ClassGuid
, ClassDescription
,
1829 ClassDescriptionSize
,
1830 RequiredSize
, NULL
, NULL
);
1833 /***********************************************************************
1834 * SetupDiGetClassDescriptionW (SETUPAPI.@)
1836 BOOL WINAPI
SetupDiGetClassDescriptionW(
1837 const GUID
* ClassGuid
,
1838 PWSTR ClassDescription
,
1839 DWORD ClassDescriptionSize
,
1840 PDWORD RequiredSize
)
1842 return SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescription
,
1843 ClassDescriptionSize
,
1844 RequiredSize
, NULL
, NULL
);
1847 /***********************************************************************
1848 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
1850 BOOL WINAPI
SetupDiGetClassDescriptionExA(
1851 const GUID
* ClassGuid
,
1852 PSTR ClassDescription
,
1853 DWORD ClassDescriptionSize
,
1854 PDWORD RequiredSize
,
1862 hKey
= SetupDiOpenClassRegKeyExA(ClassGuid
,
1867 if (hKey
== INVALID_HANDLE_VALUE
)
1869 WARN("SetupDiOpenClassRegKeyExA() failed (Error %u)\n", GetLastError());
1873 dwLength
= ClassDescriptionSize
;
1874 ret
= !RegQueryValueExA( hKey
, NULL
, NULL
, NULL
,
1875 (LPBYTE
)ClassDescription
, &dwLength
);
1876 if (RequiredSize
) *RequiredSize
= dwLength
;
1881 /***********************************************************************
1882 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
1884 BOOL WINAPI
SetupDiGetClassDescriptionExW(
1885 const GUID
* ClassGuid
,
1886 PWSTR ClassDescription
,
1887 DWORD ClassDescriptionSize
,
1888 PDWORD RequiredSize
,
1896 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1901 if (hKey
== INVALID_HANDLE_VALUE
)
1903 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
1907 dwLength
= ClassDescriptionSize
* sizeof(WCHAR
);
1908 ret
= !RegQueryValueExW( hKey
, NULL
, NULL
, NULL
,
1909 (LPBYTE
)ClassDescription
, &dwLength
);
1910 if (RequiredSize
) *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1915 /***********************************************************************
1916 * SetupDiGetClassDevsA (SETUPAPI.@)
1918 HDEVINFO WINAPI
SetupDiGetClassDevsA(const GUID
*class, LPCSTR enumstr
, HWND parent
, DWORD flags
)
1921 LPWSTR enumstrW
= NULL
;
1925 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1926 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1929 ret
= INVALID_HANDLE_VALUE
;
1932 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1934 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, NULL
, NULL
,
1936 HeapFree(GetProcessHeap(), 0, enumstrW
);
1942 /***********************************************************************
1943 * SetupDiGetClassDevsExA (SETUPAPI.@)
1945 HDEVINFO WINAPI
SetupDiGetClassDevsExA(
1955 LPWSTR enumstrW
= NULL
, machineW
= NULL
;
1959 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1960 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1963 ret
= INVALID_HANDLE_VALUE
;
1966 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1970 int len
= MultiByteToWideChar(CP_ACP
, 0, machine
, -1, NULL
, 0);
1971 machineW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1974 HeapFree(GetProcessHeap(), 0, enumstrW
);
1975 ret
= INVALID_HANDLE_VALUE
;
1978 MultiByteToWideChar(CP_ACP
, 0, machine
, -1, machineW
, len
);
1980 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, deviceset
,
1981 machineW
, reserved
);
1982 HeapFree(GetProcessHeap(), 0, enumstrW
);
1983 HeapFree(GetProcessHeap(), 0, machineW
);
1989 static void SETUPDI_AddDeviceInterfaces(struct device
*device
, HKEY key
,
1990 const GUID
*guid
, DWORD flags
)
1993 WCHAR subKeyName
[MAX_PATH
];
1994 LONG l
= ERROR_SUCCESS
;
1996 for (i
= 0; !l
; i
++)
1998 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
1999 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2003 struct device_iface
*iface
;
2005 if (*subKeyName
== '#')
2007 /* The subkey name is the reference string, with a '#' prepended */
2008 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2011 WCHAR symbolicLink
[MAX_PATH
];
2014 if (!(flags
& DIGCF_PRESENT
) || is_linked(subKey
))
2016 iface
= SETUPDI_CreateDeviceInterface(device
, guid
, subKeyName
+ 1);
2018 len
= sizeof(symbolicLink
);
2019 l
= RegQueryValueExW(subKey
, SymbolicLink
, NULL
, &dataType
,
2020 (BYTE
*)symbolicLink
, &len
);
2021 if (!l
&& dataType
== REG_SZ
)
2022 SETUPDI_SetInterfaceSymbolicLink(iface
, symbolicLink
);
2023 RegCloseKey(subKey
);
2027 /* Allow enumeration to continue */
2031 /* FIXME: find and add all the device's interfaces to the device */
2034 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet
,
2035 HKEY key
, const GUID
*guid
, const WCHAR
*enumstr
, DWORD flags
)
2037 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2039 WCHAR subKeyName
[MAX_PATH
];
2041 HKEY enumKey
= INVALID_HANDLE_VALUE
;
2043 TRACE("%s\n", debugstr_w(enumstr
));
2045 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2047 for (i
= 0; !l
; i
++)
2049 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2050 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2055 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2058 WCHAR deviceInst
[MAX_PATH
* 3];
2061 len
= sizeof(deviceInst
);
2062 l
= RegQueryValueExW(subKey
, DeviceInstance
, NULL
, &dataType
,
2063 (BYTE
*)deviceInst
, &len
);
2064 if (!l
&& dataType
== REG_SZ
)
2066 TRACE("found instance ID %s\n", debugstr_w(deviceInst
));
2067 if (!enumstr
|| !lstrcmpiW(enumstr
, deviceInst
))
2071 l
= RegOpenKeyExW(enumKey
, deviceInst
, 0, KEY_READ
,
2075 WCHAR deviceClassStr
[40];
2077 len
= sizeof(deviceClassStr
);
2078 l
= RegQueryValueExW(deviceKey
, ClassGUID
, NULL
,
2079 &dataType
, (BYTE
*)deviceClassStr
, &len
);
2080 if (!l
&& dataType
== REG_SZ
&&
2081 deviceClassStr
[0] == '{' &&
2082 deviceClassStr
[37] == '}')
2085 struct device
*device
;
2087 deviceClassStr
[37] = 0;
2088 UuidFromStringW(&deviceClassStr
[1],
2090 if ((device
= SETUPDI_CreateDeviceInfo(set
,
2091 &deviceClass
, deviceInst
, FALSE
)))
2092 SETUPDI_AddDeviceInterfaces(device
, subKey
, guid
, flags
);
2094 RegCloseKey(deviceKey
);
2098 RegCloseKey(subKey
);
2100 /* Allow enumeration to continue */
2104 if (enumKey
!= INVALID_HANDLE_VALUE
)
2105 RegCloseKey(enumKey
);
2108 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet
,
2109 const GUID
*guid
, LPCWSTR enumstr
, DWORD flags
)
2111 HKEY interfacesKey
= SetupDiOpenClassRegKeyExW(guid
, KEY_READ
,
2112 DIOCR_INTERFACE
, NULL
, NULL
);
2114 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(guid
),
2115 debugstr_w(enumstr
), flags
);
2117 if (interfacesKey
!= INVALID_HANDLE_VALUE
)
2119 if (flags
& DIGCF_ALLCLASSES
)
2122 WCHAR interfaceGuidStr
[40];
2123 LONG l
= ERROR_SUCCESS
;
2125 for (i
= 0; !l
; i
++)
2127 len
= sizeof(interfaceGuidStr
) / sizeof(interfaceGuidStr
[0]);
2128 l
= RegEnumKeyExW(interfacesKey
, i
, interfaceGuidStr
, &len
,
2129 NULL
, NULL
, NULL
, NULL
);
2132 if (interfaceGuidStr
[0] == '{' &&
2133 interfaceGuidStr
[37] == '}')
2138 interfaceGuidStr
[37] = 0;
2139 UuidFromStringW(&interfaceGuidStr
[1], &interfaceGuid
);
2140 interfaceGuidStr
[37] = '}';
2141 interfaceGuidStr
[38] = 0;
2142 l
= RegOpenKeyExW(interfacesKey
, interfaceGuidStr
, 0,
2143 KEY_READ
, &interfaceKey
);
2146 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2147 interfaceKey
, &interfaceGuid
, enumstr
, flags
);
2148 RegCloseKey(interfaceKey
);
2156 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2157 * interface's key, so just pass that long
2159 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet
,
2160 interfacesKey
, guid
, enumstr
, flags
);
2162 RegCloseKey(interfacesKey
);
2166 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet
*set
,
2167 LPCWSTR enumerator
, LPCWSTR deviceName
, HKEY deviceKey
,
2168 const GUID
*class, DWORD flags
)
2171 WCHAR deviceInstance
[MAX_PATH
];
2172 LONG l
= ERROR_SUCCESS
;
2174 TRACE("%s %s\n", debugstr_w(enumerator
), debugstr_w(deviceName
));
2176 for (i
= 0; !l
; i
++)
2178 len
= sizeof(deviceInstance
) / sizeof(deviceInstance
[0]);
2179 l
= RegEnumKeyExW(deviceKey
, i
, deviceInstance
, &len
, NULL
, NULL
, NULL
,
2185 l
= RegOpenKeyExW(deviceKey
, deviceInstance
, 0, KEY_READ
, &subKey
);
2188 WCHAR classGuid
[40];
2191 len
= sizeof(classGuid
);
2192 l
= RegQueryValueExW(subKey
, ClassGUID
, NULL
, &dataType
,
2193 (BYTE
*)classGuid
, &len
);
2194 if (!l
&& dataType
== REG_SZ
)
2196 if (classGuid
[0] == '{' && classGuid
[37] == '}')
2201 UuidFromStringW(&classGuid
[1], &deviceClass
);
2202 if ((flags
& DIGCF_ALLCLASSES
) ||
2203 IsEqualGUID(class, &deviceClass
))
2205 static const WCHAR fmt
[] =
2206 {'%','s','\\','%','s','\\','%','s',0};
2209 instanceId
= HeapAlloc(GetProcessHeap(), 0,
2210 (lstrlenW(enumerator
) + lstrlenW(deviceName
) +
2211 lstrlenW(deviceInstance
) + 3) * sizeof(WCHAR
));
2214 sprintfW(instanceId
, fmt
, enumerator
,
2215 deviceName
, deviceInstance
);
2216 SETUPDI_CreateDeviceInfo(set
, &deviceClass
,
2218 HeapFree(GetProcessHeap(), 0, instanceId
);
2223 RegCloseKey(subKey
);
2225 /* Allow enumeration to continue */
2231 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet
,
2232 LPCWSTR parent
, HKEY key
, const GUID
*class, DWORD flags
)
2234 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2236 WCHAR subKeyName
[MAX_PATH
];
2237 LONG l
= ERROR_SUCCESS
;
2239 TRACE("%s\n", debugstr_w(parent
));
2241 for (i
= 0; !l
; i
++)
2243 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2244 l
= RegEnumKeyExW(key
, i
, subKeyName
, &len
, NULL
, NULL
, NULL
, NULL
);
2249 l
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
2252 TRACE("%s\n", debugstr_w(subKeyName
));
2253 SETUPDI_EnumerateMatchingDeviceInstances(set
, parent
,
2254 subKeyName
, subKey
, class, flags
);
2255 RegCloseKey(subKey
);
2257 /* Allow enumeration to continue */
2263 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet
, const GUID
*class,
2264 LPCWSTR enumstr
, DWORD flags
)
2269 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet
, debugstr_guid(class),
2270 debugstr_w(enumstr
), flags
);
2272 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_READ
, NULL
,
2274 if (enumKey
!= INVALID_HANDLE_VALUE
)
2280 l
= RegOpenKeyExW(enumKey
, enumstr
, 0, KEY_READ
,
2284 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
, enumstr
,
2285 enumStrKey
, class, flags
);
2286 RegCloseKey(enumStrKey
);
2292 WCHAR subKeyName
[MAX_PATH
];
2295 for (i
= 0; !l
; i
++)
2297 len
= sizeof(subKeyName
) / sizeof(subKeyName
[0]);
2298 l
= RegEnumKeyExW(enumKey
, i
, subKeyName
, &len
, NULL
,
2304 l
= RegOpenKeyExW(enumKey
, subKeyName
, 0, KEY_READ
,
2308 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet
,
2309 subKeyName
, subKey
, class, flags
);
2310 RegCloseKey(subKey
);
2312 /* Allow enumeration to continue */
2317 RegCloseKey(enumKey
);
2321 /***********************************************************************
2322 * SetupDiGetClassDevsW (SETUPAPI.@)
2324 HDEVINFO WINAPI
SetupDiGetClassDevsW(const GUID
*class, LPCWSTR enumstr
, HWND parent
, DWORD flags
)
2326 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2330 /***********************************************************************
2331 * SetupDiGetClassDevsExW (SETUPAPI.@)
2333 HDEVINFO WINAPI
SetupDiGetClassDevsExW(const GUID
*class, PCWSTR enumstr
, HWND parent
, DWORD flags
,
2334 HDEVINFO deviceset
, PCWSTR machine
, void *reserved
)
2336 static const DWORD unsupportedFlags
= DIGCF_DEFAULT
| DIGCF_PROFILE
;
2339 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2340 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2343 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2345 SetLastError(ERROR_INVALID_PARAMETER
);
2346 return INVALID_HANDLE_VALUE
;
2348 if (flags
& unsupportedFlags
)
2349 WARN("unsupported flags %08x\n", flags
& unsupportedFlags
);
2353 set
= SetupDiCreateDeviceInfoListExW(class, parent
, machine
, reserved
);
2354 if (set
!= INVALID_HANDLE_VALUE
)
2356 if (machine
&& *machine
)
2357 FIXME("%s: unimplemented for remote machines\n",
2358 debugstr_w(machine
));
2359 else if (flags
& DIGCF_DEVICEINTERFACE
)
2360 SETUPDI_EnumerateInterfaces(set
, class, enumstr
, flags
);
2362 SETUPDI_EnumerateDevices(set
, class, enumstr
, flags
);
2367 /***********************************************************************
2368 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2370 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2371 HDEVINFO DeviceInfoSet
,
2372 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2374 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2376 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2378 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2380 SetLastError(ERROR_INVALID_HANDLE
);
2383 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2385 SetLastError(ERROR_INVALID_HANDLE
);
2389 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2391 SetLastError(ERROR_INVALID_PARAMETER
);
2394 DevInfoData
->ClassGuid
= set
->ClassGuid
;
2395 DevInfoData
->RemoteMachineHandle
= NULL
;
2396 DevInfoData
->RemoteMachineName
[0] = '\0';
2400 /***********************************************************************
2401 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2403 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2404 HDEVINFO DeviceInfoSet
,
2405 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2407 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2409 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2411 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2413 SetLastError(ERROR_INVALID_HANDLE
);
2416 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2418 SetLastError(ERROR_INVALID_HANDLE
);
2422 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2424 SetLastError(ERROR_INVALID_PARAMETER
);
2427 DevInfoData
->ClassGuid
= set
->ClassGuid
;
2428 DevInfoData
->RemoteMachineHandle
= NULL
;
2429 DevInfoData
->RemoteMachineName
[0] = '\0';
2433 /***********************************************************************
2434 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2436 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2437 HDEVINFO DeviceInfoSet
,
2438 PSP_DEVINFO_DATA DeviceInfoData
,
2439 const GUID
*InterfaceClassGuid
,
2440 PCSTR ReferenceString
,
2441 DWORD CreationFlags
,
2442 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2445 LPWSTR ReferenceStringW
= NULL
;
2447 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2448 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2449 CreationFlags
, DeviceInterfaceData
);
2451 if (ReferenceString
)
2453 ReferenceStringW
= MultiByteToUnicode(ReferenceString
, CP_ACP
);
2454 if (ReferenceStringW
== NULL
) return FALSE
;
2457 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2458 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2459 DeviceInterfaceData
);
2461 MyFree(ReferenceStringW
);
2466 /***********************************************************************
2467 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2469 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2470 HDEVINFO DeviceInfoSet
,
2471 PSP_DEVINFO_DATA DeviceInfoData
,
2472 const GUID
*InterfaceClassGuid
,
2473 PCWSTR ReferenceString
,
2474 DWORD CreationFlags
,
2475 SP_DEVICE_INTERFACE_DATA
*iface_data
)
2477 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2478 struct device
*device
;
2479 struct device_iface
*iface
;
2481 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2482 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2483 CreationFlags
, iface_data
);
2485 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2487 SetLastError(ERROR_INVALID_HANDLE
);
2490 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2492 SetLastError(ERROR_INVALID_HANDLE
);
2495 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2496 || !DeviceInfoData
->Reserved
)
2498 SetLastError(ERROR_INVALID_PARAMETER
);
2501 device
= (struct device
*)DeviceInfoData
->Reserved
;
2502 if (device
->set
!= set
)
2504 SetLastError(ERROR_INVALID_PARAMETER
);
2507 if (!InterfaceClassGuid
)
2509 SetLastError(ERROR_INVALID_USER_BUFFER
);
2512 if (!(iface
= SETUPDI_CreateDeviceInterface(device
, InterfaceClassGuid
,
2518 if (iface_data
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2520 SetLastError(ERROR_INVALID_USER_BUFFER
);
2524 copy_device_iface_data(iface_data
, iface
);
2529 /***********************************************************************
2530 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2532 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2533 HDEVINFO DeviceInfoSet
,
2534 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2538 PCSTR InfSectionName
)
2541 PWSTR InfSectionNameW
= NULL
;
2543 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2544 samDesired
, InfHandle
, InfSectionName
);
2547 if (!InfSectionName
)
2549 SetLastError(ERROR_INVALID_PARAMETER
);
2550 return INVALID_HANDLE_VALUE
;
2552 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2553 if (!InfSectionNameW
)
2554 return INVALID_HANDLE_VALUE
;
2556 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2557 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2559 MyFree(InfSectionNameW
);
2563 /***********************************************************************
2564 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2566 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(HDEVINFO devinfo
,
2567 SP_DEVICE_INTERFACE_DATA
*iface_data
, DWORD reserved
, REGSAM access
,
2568 HINF hinf
, const WCHAR
*section
)
2570 struct DeviceInfoSet
*set
= devinfo
;
2571 struct device_iface
*iface
;
2572 HKEY refstr_key
, params_key
;
2576 TRACE("%p %p %d %#x %p %s\n", devinfo
, iface_data
, reserved
, access
, hinf
,
2577 debugstr_w(section
));
2579 if (!devinfo
|| devinfo
== INVALID_HANDLE_VALUE
||
2580 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2582 SetLastError(ERROR_INVALID_HANDLE
);
2583 return INVALID_HANDLE_VALUE
;
2585 if (!iface_data
|| iface_data
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2586 !iface_data
->Reserved
)
2588 SetLastError(ERROR_INVALID_PARAMETER
);
2589 return INVALID_HANDLE_VALUE
;
2591 if (hinf
&& !section
)
2593 SetLastError(ERROR_INVALID_PARAMETER
);
2594 return INVALID_HANDLE_VALUE
;
2597 iface
= (struct device_iface
*)iface_data
->Reserved
;
2598 if (!(path
= get_refstr_key_path(iface
)))
2600 SetLastError(ERROR_OUTOFMEMORY
);
2601 return INVALID_HANDLE_VALUE
;
2604 ret
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, path
, 0, NULL
, 0, 0, NULL
,
2610 return INVALID_HANDLE_VALUE
;
2613 ret
= RegCreateKeyExW(refstr_key
, DeviceParameters
, 0, NULL
, 0, access
,
2614 NULL
, ¶ms_key
, NULL
);
2615 RegCloseKey(refstr_key
);
2619 return INVALID_HANDLE_VALUE
;
2625 /***********************************************************************
2626 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2628 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(HDEVINFO devinfo
,
2629 SP_DEVICE_INTERFACE_DATA
*iface_data
, DWORD reserved
)
2631 struct DeviceInfoSet
*set
= devinfo
;
2632 struct device_iface
*iface
;
2637 TRACE("%p %p %d\n", devinfo
, iface_data
, reserved
);
2639 if (!devinfo
|| devinfo
== INVALID_HANDLE_VALUE
||
2640 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2642 SetLastError(ERROR_INVALID_HANDLE
);
2645 if (!iface_data
|| iface_data
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2646 !iface_data
->Reserved
)
2648 SetLastError(ERROR_INVALID_PARAMETER
);
2652 iface
= (struct device_iface
*)iface_data
->Reserved
;
2653 if (!(path
= get_refstr_key_path(iface
)))
2655 SetLastError(ERROR_OUTOFMEMORY
);
2659 ret
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, path
, 0, NULL
, 0, 0, NULL
,
2668 ret
= RegDeleteKeyW(refstr_key
, DeviceParameters
);
2669 RegCloseKey(refstr_key
);
2679 /***********************************************************************
2680 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2683 * DeviceInfoSet [I] Set of devices from which to enumerate
2685 * DeviceInfoData [I] (Optional) If specified, a specific device
2686 * instance from which to enumerate interfaces.
2687 * If it isn't specified, all interfaces for all
2688 * devices in the set are enumerated.
2689 * InterfaceClassGuid [I] The interface class to enumerate.
2690 * MemberIndex [I] An index of the interface instance to enumerate.
2691 * A caller should start with MemberIndex set to 0,
2692 * and continue until the function fails with
2693 * ERROR_NO_MORE_ITEMS.
2694 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2695 * member must be set to
2696 * sizeof(SP_DEVICE_INTERFACE_DATA).
2699 * Success: non-zero value.
2700 * Failure: FALSE. Call GetLastError() for more info.
2702 BOOL WINAPI
SetupDiEnumDeviceInterfaces(HDEVINFO devinfo
,
2703 SP_DEVINFO_DATA
*device_data
, const GUID
*class, DWORD index
,
2704 SP_DEVICE_INTERFACE_DATA
*iface_data
)
2706 struct DeviceInfoSet
*set
= devinfo
;
2707 struct device
*device
;
2708 struct device_iface
*iface
;
2711 TRACE("%p, %p, %s, %u, %p\n", devinfo
, device_data
, debugstr_guid(class),
2714 if (!devinfo
|| devinfo
== INVALID_HANDLE_VALUE
||
2715 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2717 SetLastError(ERROR_INVALID_HANDLE
);
2720 if (device_data
&& (device_data
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2721 !device_data
->Reserved
))
2723 SetLastError(ERROR_INVALID_PARAMETER
);
2726 if (!iface_data
|| iface_data
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2728 SetLastError(ERROR_INVALID_PARAMETER
);
2732 /* In case application fails to check return value, clear output */
2733 memset(iface_data
, 0, sizeof(*iface_data
));
2734 iface_data
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DATA
);
2738 device
= (struct device
*)device_data
->Reserved
;
2740 LIST_FOR_EACH_ENTRY(iface
, &device
->interfaces
, struct device_iface
, entry
)
2742 if (IsEqualGUID(&iface
->class, class))
2746 copy_device_iface_data(iface_data
, iface
);
2755 LIST_FOR_EACH_ENTRY(device
, &set
->devices
, struct device
, entry
)
2757 LIST_FOR_EACH_ENTRY(iface
, &device
->interfaces
, struct device_iface
, entry
)
2759 if (IsEqualGUID(&iface
->class, class))
2763 copy_device_iface_data(iface_data
, iface
);
2772 SetLastError(ERROR_NO_MORE_ITEMS
);
2776 /***********************************************************************
2777 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2779 * Destroy a DeviceInfoList and free all used memory of the list.
2782 * devinfo [I] DeviceInfoList pointer to list to destroy
2785 * Success: non zero value.
2786 * Failure: zero value.
2788 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
2792 TRACE("%p\n", devinfo
);
2793 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
2795 struct DeviceInfoSet
*list
= devinfo
;
2797 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
2799 struct device
*device
, *device2
;
2801 LIST_FOR_EACH_ENTRY_SAFE(device
, device2
, &list
->devices
,
2802 struct device
, entry
)
2804 SETUPDI_RemoveDevice(device
);
2806 HeapFree(GetProcessHeap(), 0, list
);
2812 SetLastError(ERROR_INVALID_HANDLE
);
2817 /***********************************************************************
2818 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2820 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
2821 HDEVINFO DeviceInfoSet
,
2822 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2823 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
2824 DWORD DeviceInterfaceDetailDataSize
,
2825 PDWORD RequiredSize
,
2826 SP_DEVINFO_DATA
*device_data
)
2828 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2829 struct device_iface
*iface
;
2830 DWORD bytesNeeded
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
[1]);
2833 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2834 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2835 DeviceInterfaceDetailDataSize
, RequiredSize
, device_data
);
2837 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2838 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2840 SetLastError(ERROR_INVALID_HANDLE
);
2843 if (!DeviceInterfaceData
||
2844 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2845 !DeviceInterfaceData
->Reserved
)
2847 SetLastError(ERROR_INVALID_PARAMETER
);
2850 if (DeviceInterfaceDetailData
&&
2851 DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
))
2853 SetLastError(ERROR_INVALID_USER_BUFFER
);
2856 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2858 SetLastError(ERROR_INVALID_USER_BUFFER
);
2861 iface
= (struct device_iface
*)DeviceInterfaceData
->Reserved
;
2863 bytesNeeded
+= WideCharToMultiByte(CP_ACP
, 0, iface
->symlink
, -1,
2864 NULL
, 0, NULL
, NULL
);
2865 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2868 WideCharToMultiByte(CP_ACP
, 0, iface
->symlink
, -1,
2869 DeviceInterfaceDetailData
->DevicePath
,
2870 DeviceInterfaceDetailDataSize
-
2871 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
2874 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2876 if (device_data
&& device_data
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2877 copy_device_data(device_data
, iface
->device
);
2884 *RequiredSize
= bytesNeeded
;
2885 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2890 /***********************************************************************
2891 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2893 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
2894 HDEVINFO DeviceInfoSet
,
2895 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2896 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
2897 DWORD DeviceInterfaceDetailDataSize
,
2898 PDWORD RequiredSize
,
2899 SP_DEVINFO_DATA
*device_data
)
2901 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2902 struct device_iface
*iface
;
2903 DWORD bytesNeeded
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
2904 + sizeof(WCHAR
); /* include NULL terminator */
2907 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2908 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2909 DeviceInterfaceDetailDataSize
, RequiredSize
, device_data
);
2911 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2912 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2914 SetLastError(ERROR_INVALID_HANDLE
);
2917 if (!DeviceInterfaceData
||
2918 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2919 !DeviceInterfaceData
->Reserved
)
2921 SetLastError(ERROR_INVALID_PARAMETER
);
2924 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
2925 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
) ||
2926 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
)))
2928 SetLastError(ERROR_INVALID_USER_BUFFER
);
2931 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2933 SetLastError(ERROR_INVALID_USER_BUFFER
);
2936 iface
= (struct device_iface
*)DeviceInterfaceData
->Reserved
;
2938 bytesNeeded
+= sizeof(WCHAR
) * lstrlenW(iface
->symlink
);
2939 if (DeviceInterfaceDetailDataSize
>= bytesNeeded
)
2942 lstrcpyW(DeviceInterfaceDetailData
->DevicePath
, iface
->symlink
);
2944 DeviceInterfaceDetailData
->DevicePath
[0] = '\0';
2946 if (device_data
&& device_data
->cbSize
== sizeof(SP_DEVINFO_DATA
))
2947 copy_device_data(device_data
, iface
->device
);
2954 *RequiredSize
= bytesNeeded
;
2955 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2960 /***********************************************************************
2961 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
2963 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
2964 HDEVINFO DeviceInfoSet
,
2965 PSP_DEVINFO_DATA DeviceInfoData
,
2967 PDWORD PropertyRegDataType
,
2968 PBYTE PropertyBuffer
,
2969 DWORD PropertyBufferSize
,
2970 PDWORD RequiredSize
)
2973 struct DeviceInfoSet
*set
= DeviceInfoSet
;
2974 struct device
*device
;
2976 TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
,
2977 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
2980 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2982 SetLastError(ERROR_INVALID_HANDLE
);
2985 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2987 SetLastError(ERROR_INVALID_HANDLE
);
2990 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2991 || !DeviceInfoData
->Reserved
)
2993 SetLastError(ERROR_INVALID_PARAMETER
);
2996 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
2998 SetLastError(ERROR_INVALID_DATA
);
3001 device
= (struct device
*)DeviceInfoData
->Reserved
;
3002 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3003 && PropertyMap
[Property
].nameA
)
3005 DWORD size
= PropertyBufferSize
;
3006 LONG l
= RegQueryValueExA(device
->key
, PropertyMap
[Property
].nameA
,
3007 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3009 if (l
== ERROR_FILE_NOT_FOUND
)
3010 SetLastError(ERROR_INVALID_DATA
);
3011 else if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3012 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3018 *RequiredSize
= size
;
3023 /***********************************************************************
3024 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3026 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3027 HDEVINFO DeviceInfoSet
,
3028 PSP_DEVINFO_DATA DeviceInfoData
,
3030 PDWORD PropertyRegDataType
,
3031 PBYTE PropertyBuffer
,
3032 DWORD PropertyBufferSize
,
3033 PDWORD RequiredSize
)
3036 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3037 struct device
*device
;
3039 TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
,
3040 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3043 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3045 SetLastError(ERROR_INVALID_HANDLE
);
3048 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3050 SetLastError(ERROR_INVALID_HANDLE
);
3053 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3054 || !DeviceInfoData
->Reserved
)
3056 SetLastError(ERROR_INVALID_PARAMETER
);
3059 if (PropertyBufferSize
&& PropertyBuffer
== NULL
)
3061 SetLastError(ERROR_INVALID_DATA
);
3064 device
= (struct device
*)DeviceInfoData
->Reserved
;
3065 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3066 && PropertyMap
[Property
].nameW
)
3068 DWORD size
= PropertyBufferSize
;
3069 LONG l
= RegQueryValueExW(device
->key
, PropertyMap
[Property
].nameW
,
3070 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3072 if (l
== ERROR_FILE_NOT_FOUND
)
3073 SetLastError(ERROR_INVALID_DATA
);
3074 else if (l
== ERROR_MORE_DATA
|| !PropertyBufferSize
)
3075 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3081 *RequiredSize
= size
;
3086 /***********************************************************************
3087 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3089 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3090 HDEVINFO DeviceInfoSet
,
3091 PSP_DEVINFO_DATA DeviceInfoData
,
3093 const BYTE
*PropertyBuffer
,
3094 DWORD PropertyBufferSize
)
3097 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3098 struct device
*device
;
3100 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3101 PropertyBuffer
, PropertyBufferSize
);
3103 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3105 SetLastError(ERROR_INVALID_HANDLE
);
3108 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3110 SetLastError(ERROR_INVALID_HANDLE
);
3113 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3114 || !DeviceInfoData
->Reserved
)
3116 SetLastError(ERROR_INVALID_PARAMETER
);
3119 device
= (struct device
*)DeviceInfoData
->Reserved
;
3120 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3121 && PropertyMap
[Property
].nameA
)
3123 LONG l
= RegSetValueExA(device
->key
, PropertyMap
[Property
].nameA
, 0,
3124 PropertyMap
[Property
].regType
, PropertyBuffer
,
3125 PropertyBufferSize
);
3134 /***********************************************************************
3135 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3137 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(HDEVINFO devinfo
,
3138 SP_DEVINFO_DATA
*device_data
, DWORD prop
, const BYTE
*buffer
, DWORD size
)
3140 struct DeviceInfoSet
*set
= devinfo
;
3141 struct device
*device
;
3143 TRACE("%p %p %d %p %d\n", devinfo
, device_data
, prop
, buffer
, size
);
3145 if (!devinfo
|| devinfo
== INVALID_HANDLE_VALUE
)
3147 SetLastError(ERROR_INVALID_HANDLE
);
3150 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3152 SetLastError(ERROR_INVALID_HANDLE
);
3155 if (!device_data
|| device_data
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3156 || !device_data
->Reserved
)
3158 SetLastError(ERROR_INVALID_PARAMETER
);
3162 device
= (struct device
*)device_data
->Reserved
;
3163 return SETUPDI_SetDeviceRegistryPropertyW(device
, prop
, buffer
, size
);
3166 /***********************************************************************
3167 * SetupDiInstallClassA (SETUPAPI.@)
3169 BOOL WINAPI
SetupDiInstallClassA(
3175 UNICODE_STRING FileNameW
;
3180 SetLastError(ERROR_INVALID_PARAMETER
);
3183 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW
, InfFileName
))
3185 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3189 Result
= SetupDiInstallClassW(hwndParent
, FileNameW
.Buffer
, Flags
, FileQueue
);
3191 RtlFreeUnicodeString(&FileNameW
);
3196 static HKEY
CreateClassKey(HINF hInf
)
3198 static const WCHAR slash
[] = { '\\',0 };
3199 WCHAR FullBuffer
[MAX_PATH
];
3200 WCHAR Buffer
[MAX_PATH
];
3204 if (!SetupGetLineTextW(NULL
,
3212 return INVALID_HANDLE_VALUE
;
3215 lstrcpyW(FullBuffer
, ControlClass
);
3216 lstrcatW(FullBuffer
, slash
);
3217 lstrcatW(FullBuffer
, Buffer
);
3219 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3225 if (!SetupGetLineTextW(NULL
,
3233 return INVALID_HANDLE_VALUE
;
3236 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3240 REG_OPTION_NON_VOLATILE
,
3246 return INVALID_HANDLE_VALUE
;
3251 if (RegSetValueExW(hClassKey
,
3256 RequiredSize
* sizeof(WCHAR
)))
3258 RegCloseKey(hClassKey
);
3259 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3261 return INVALID_HANDLE_VALUE
;
3267 /***********************************************************************
3268 * SetupDiInstallClassW (SETUPAPI.@)
3270 BOOL WINAPI
SetupDiInstallClassW(
3276 WCHAR SectionName
[MAX_PATH
];
3277 DWORD SectionNameLength
= 0;
3279 BOOL bFileQueueCreated
= FALSE
;
3287 SetLastError(ERROR_INVALID_PARAMETER
);
3290 if ((Flags
& DI_NOVCP
) && (FileQueue
== NULL
|| FileQueue
== INVALID_HANDLE_VALUE
))
3292 SetLastError(ERROR_INVALID_PARAMETER
);
3296 /* Open the .inf file */
3297 hInf
= SetupOpenInfFileW(InfFileName
,
3301 if (hInf
== INVALID_HANDLE_VALUE
)
3307 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3308 hClassKey
= CreateClassKey(hInf
);
3309 if (hClassKey
== INVALID_HANDLE_VALUE
)
3311 SetupCloseInfFile(hInf
);
3316 /* Try to append a layout file */
3317 SetupOpenAppendInfFileW(NULL
, hInf
, NULL
);
3319 /* Retrieve the actual section name */
3320 SetupDiGetActualSectionToInstallW(hInf
,
3328 if (!(Flags
& DI_NOVCP
))
3330 FileQueue
= SetupOpenFileQueue();
3331 if (FileQueue
== INVALID_HANDLE_VALUE
)
3333 SetupCloseInfFile(hInf
);
3337 bFileQueueCreated
= TRUE
;
3342 SetupInstallFromInfSectionW(NULL
,
3345 SPINST_COPYINF
| SPINST_FILES
| SPINST_REGISTRY
,
3351 INVALID_HANDLE_VALUE
,
3354 /* FIXME: More code! */
3356 if (bFileQueueCreated
)
3357 SetupCloseFileQueue(FileQueue
);
3359 SetupCloseInfFile(hInf
);
3365 /***********************************************************************
3366 * SetupDiOpenClassRegKey (SETUPAPI.@)
3368 HKEY WINAPI
SetupDiOpenClassRegKey(
3369 const GUID
* ClassGuid
,
3372 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3373 DIOCR_INSTALLER
, NULL
, NULL
);
3377 /***********************************************************************
3378 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3380 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3381 const GUID
* ClassGuid
,
3387 PWSTR MachineNameW
= NULL
;
3394 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
3395 if (MachineNameW
== NULL
)
3396 return INVALID_HANDLE_VALUE
;
3399 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3400 Flags
, MachineNameW
, Reserved
);
3402 MyFree(MachineNameW
);
3408 /***********************************************************************
3409 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3411 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3412 const GUID
* ClassGuid
,
3423 if (MachineName
&& *MachineName
)
3425 FIXME("Remote access not supported yet!\n");
3426 return INVALID_HANDLE_VALUE
;
3429 if (Flags
== DIOCR_INSTALLER
)
3431 lpKeyName
= ControlClass
;
3433 else if (Flags
== DIOCR_INTERFACE
)
3435 lpKeyName
= DeviceClasses
;
3439 ERR("Invalid Flags parameter!\n");
3440 SetLastError(ERROR_INVALID_PARAMETER
);
3441 return INVALID_HANDLE_VALUE
;
3446 if ((l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3453 hClassesKey
= INVALID_HANDLE_VALUE
;
3459 WCHAR bracedGuidString
[39];
3461 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3463 if (!(l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3469 if ((l
= RegOpenKeyExW(hClassesKey
,
3476 key
= INVALID_HANDLE_VALUE
;
3478 RegCloseKey(hClassesKey
);
3483 key
= INVALID_HANDLE_VALUE
;
3489 /***********************************************************************
3490 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3492 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3493 HDEVINFO DeviceInfoSet
,
3496 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3498 FIXME("%p %s %08x %p\n",
3499 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3503 /***********************************************************************
3504 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3506 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
3507 HDEVINFO DeviceInfoSet
,
3510 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3512 FIXME("%p %s %08x %p\n", DeviceInfoSet
,
3513 debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3517 /***********************************************************************
3518 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3520 BOOL WINAPI
SetupDiSetClassInstallParamsA(
3521 HDEVINFO DeviceInfoSet
,
3522 PSP_DEVINFO_DATA DeviceInfoData
,
3523 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3524 DWORD ClassInstallParamsSize
)
3526 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3527 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3531 /***********************************************************************
3532 * SetupDiSetClassInstallParamsW (SETUPAPI.@)
3534 BOOL WINAPI
SetupDiSetClassInstallParamsW(
3535 HDEVINFO DeviceInfoSet
,
3536 PSP_DEVINFO_DATA DeviceInfoData
,
3537 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3538 DWORD ClassInstallParamsSize
)
3540 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3541 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3545 /***********************************************************************
3546 * SetupDiCallClassInstaller (SETUPAPI.@)
3548 BOOL WINAPI
SetupDiCallClassInstaller(
3549 DI_FUNCTION InstallFunction
,
3550 HDEVINFO DeviceInfoSet
,
3551 PSP_DEVINFO_DATA DeviceInfoData
)
3553 FIXME("%d %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3557 /***********************************************************************
3558 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
3560 BOOL WINAPI
SetupDiGetDeviceInstallParamsW(
3561 HDEVINFO DeviceInfoSet
,
3562 PSP_DEVINFO_DATA DeviceInfoData
,
3563 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
3565 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3569 /***********************************************************************
3570 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3572 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
3573 HDEVINFO DeviceInfoSet
,
3574 PSP_DEVINFO_DATA DeviceInfoData
,
3575 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3577 FIXME("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3581 /***********************************************************************
3582 * SetupDiSetDeviceInstallParamsA (SETUPAPI.@)
3584 BOOL WINAPI
SetupDiSetDeviceInstallParamsA(
3585 HDEVINFO DeviceInfoSet
,
3586 PSP_DEVINFO_DATA DeviceInfoData
,
3587 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3589 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3594 /***********************************************************************
3595 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
3597 BOOL WINAPI
SetupDiSetDeviceInstallParamsW(
3598 HDEVINFO DeviceInfoSet
,
3599 PSP_DEVINFO_DATA DeviceInfoData
,
3600 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
3602 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3607 static HKEY
SETUPDI_OpenDevKey(struct device
*device
, REGSAM samDesired
)
3609 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
3612 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3613 NULL
, &enumKey
, NULL
);
3616 RegOpenKeyExW(enumKey
, device
->instanceId
, 0, samDesired
, &key
);
3617 RegCloseKey(enumKey
);
3622 static HKEY
SETUPDI_OpenDrvKey(struct device
*device
, REGSAM samDesired
)
3624 static const WCHAR slash
[] = { '\\',0 };
3625 WCHAR classKeyPath
[MAX_PATH
];
3626 HKEY classKey
, key
= INVALID_HANDLE_VALUE
;
3629 lstrcpyW(classKeyPath
, ControlClass
);
3630 lstrcatW(classKeyPath
, slash
);
3631 SETUPDI_GuidToString(&device
->set
->ClassGuid
,
3632 classKeyPath
+ lstrlenW(classKeyPath
));
3633 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3634 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3637 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3640 sprintfW(devId
, fmt
, device
->devnode
);
3641 l
= RegOpenKeyExW(classKey
, devId
, 0, samDesired
, &key
);
3642 RegCloseKey(classKey
);
3645 SetLastError(ERROR_KEY_DOES_NOT_EXIST
);
3646 return INVALID_HANDLE_VALUE
;
3652 /***********************************************************************
3653 * SetupDiOpenDevRegKey (SETUPAPI.@)
3655 HKEY WINAPI
SetupDiOpenDevRegKey(
3656 HDEVINFO DeviceInfoSet
,
3657 PSP_DEVINFO_DATA DeviceInfoData
,
3663 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3664 struct device
*device
;
3665 HKEY key
= INVALID_HANDLE_VALUE
;
3667 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
3668 Scope
, HwProfile
, KeyType
, samDesired
);
3670 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3672 SetLastError(ERROR_INVALID_HANDLE
);
3673 return INVALID_HANDLE_VALUE
;
3675 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3677 SetLastError(ERROR_INVALID_HANDLE
);
3678 return INVALID_HANDLE_VALUE
;
3680 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3681 || !DeviceInfoData
->Reserved
)
3683 SetLastError(ERROR_INVALID_PARAMETER
);
3684 return INVALID_HANDLE_VALUE
;
3686 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3688 SetLastError(ERROR_INVALID_FLAGS
);
3689 return INVALID_HANDLE_VALUE
;
3691 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
3693 SetLastError(ERROR_INVALID_FLAGS
);
3694 return INVALID_HANDLE_VALUE
;
3696 device
= (struct device
*)DeviceInfoData
->Reserved
;
3697 if (device
->set
!= set
)
3699 SetLastError(ERROR_INVALID_PARAMETER
);
3700 return INVALID_HANDLE_VALUE
;
3702 if (device
->phantom
)
3704 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3705 return INVALID_HANDLE_VALUE
;
3707 if (Scope
!= DICS_FLAG_GLOBAL
)
3708 FIXME("unimplemented for scope %d\n", Scope
);
3712 key
= SETUPDI_OpenDevKey(device
, samDesired
);
3715 key
= SETUPDI_OpenDrvKey(device
, samDesired
);
3718 WARN("unknown KeyType %d\n", KeyType
);
3723 static BOOL
SETUPDI_DeleteDevKey(struct device
*device
)
3729 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, Enum
, 0, NULL
, 0, KEY_ALL_ACCESS
,
3730 NULL
, &enumKey
, NULL
);
3733 ret
= RegDeleteTreeW(enumKey
, device
->instanceId
);
3734 RegCloseKey(enumKey
);
3741 static BOOL
SETUPDI_DeleteDrvKey(struct device
*device
)
3743 static const WCHAR slash
[] = { '\\',0 };
3744 WCHAR classKeyPath
[MAX_PATH
];
3749 lstrcpyW(classKeyPath
, ControlClass
);
3750 lstrcatW(classKeyPath
, slash
);
3751 SETUPDI_GuidToString(&device
->set
->ClassGuid
,
3752 classKeyPath
+ lstrlenW(classKeyPath
));
3753 l
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, classKeyPath
, 0, NULL
, 0,
3754 KEY_ALL_ACCESS
, NULL
, &classKey
, NULL
);
3757 static const WCHAR fmt
[] = { '%','0','4','u',0 };
3760 sprintfW(devId
, fmt
, device
->devnode
);
3761 ret
= RegDeleteTreeW(classKey
, devId
);
3762 RegCloseKey(classKey
);
3769 /***********************************************************************
3770 * SetupDiDeleteDevRegKey (SETUPAPI.@)
3772 BOOL WINAPI
SetupDiDeleteDevRegKey(
3773 HDEVINFO DeviceInfoSet
,
3774 PSP_DEVINFO_DATA DeviceInfoData
,
3779 struct DeviceInfoSet
*set
= DeviceInfoSet
;
3780 struct device
*device
;
3783 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
3786 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3788 SetLastError(ERROR_INVALID_HANDLE
);
3791 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3793 SetLastError(ERROR_INVALID_HANDLE
);
3796 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3797 || !DeviceInfoData
->Reserved
)
3799 SetLastError(ERROR_INVALID_PARAMETER
);
3802 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3804 SetLastError(ERROR_INVALID_FLAGS
);
3807 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
3809 SetLastError(ERROR_INVALID_FLAGS
);
3812 device
= (struct device
*)DeviceInfoData
->Reserved
;
3813 if (device
->set
!= set
)
3815 SetLastError(ERROR_INVALID_PARAMETER
);
3818 if (device
->phantom
)
3820 SetLastError(ERROR_DEVINFO_NOT_REGISTERED
);
3823 if (Scope
!= DICS_FLAG_GLOBAL
)
3824 FIXME("unimplemented for scope %d\n", Scope
);
3828 ret
= SETUPDI_DeleteDevKey(device
);
3831 ret
= SETUPDI_DeleteDrvKey(device
);
3834 ret
= SETUPDI_DeleteDevKey(device
);
3836 ret
= SETUPDI_DeleteDrvKey(device
);
3839 WARN("unknown KeyType %d\n", KeyType
);
3844 /***********************************************************************
3845 * CM_Get_Device_IDA (SETUPAPI.@)
3847 CONFIGRET WINAPI
CM_Get_Device_IDA(DEVINST devnode
, char *buffer
, ULONG len
, ULONG flags
)
3849 struct device
*device
= get_devnode_device(devnode
);
3851 TRACE("%u, %p, %u, %#x\n", devnode
, buffer
, len
, flags
);
3854 return CR_NO_SUCH_DEVINST
;
3856 WideCharToMultiByte(CP_ACP
, 0, device
->instanceId
, -1, buffer
, len
, 0, 0);
3857 TRACE("Returning %s\n", debugstr_a(buffer
));
3861 /***********************************************************************
3862 * CM_Get_Device_IDW (SETUPAPI.@)
3864 CONFIGRET WINAPI
CM_Get_Device_IDW(DEVINST devnode
, WCHAR
*buffer
, ULONG len
, ULONG flags
)
3866 struct device
*device
= get_devnode_device(devnode
);
3868 TRACE("%u, %p, %u, %#x\n", devnode
, buffer
, len
, flags
);
3871 return CR_NO_SUCH_DEVINST
;
3873 lstrcpynW(buffer
, device
->instanceId
, len
);
3874 TRACE("Returning %s\n", debugstr_w(buffer
));
3878 /***********************************************************************
3879 * CM_Get_Device_ID_Size (SETUPAPI.@)
3881 CONFIGRET WINAPI
CM_Get_Device_ID_Size(ULONG
*len
, DEVINST devnode
, ULONG flags
)
3883 struct device
*device
= get_devnode_device(devnode
);
3885 TRACE("%p, %u, %#x\n", len
, devnode
, flags
);
3888 return CR_NO_SUCH_DEVINST
;
3890 *len
= lstrlenW(device
->instanceId
);
3894 /***********************************************************************
3895 * SetupDiGetINFClassA (SETUPAPI.@)
3897 BOOL WINAPI
SetupDiGetINFClassA(PCSTR inf
, LPGUID class_guid
, PSTR class_name
,
3898 DWORD size
, PDWORD required_size
)
3901 DWORD required_sizeA
, required_sizeW
;
3902 PWSTR class_nameW
= NULL
;
3903 UNICODE_STRING infW
;
3907 if (!RtlCreateUnicodeStringFromAsciiz(&infW
, inf
))
3909 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3916 if (class_name
&& size
)
3918 if (!(class_nameW
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
))))
3920 RtlFreeUnicodeString(&infW
);
3921 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3926 retval
= SetupDiGetINFClassW(infW
.Buffer
, class_guid
, class_nameW
, size
, &required_sizeW
);
3930 required_sizeA
= WideCharToMultiByte( CP_ACP
, 0, class_nameW
, required_sizeW
,
3931 class_name
, size
, NULL
, NULL
);
3933 if(required_size
) *required_size
= required_sizeA
;
3936 if(required_size
) *required_size
= required_sizeW
;
3938 HeapFree(GetProcessHeap(), 0, class_nameW
);
3939 RtlFreeUnicodeString(&infW
);
3943 /***********************************************************************
3944 * SetupDiGetINFClassW (SETUPAPI.@)
3946 BOOL WINAPI
SetupDiGetINFClassW(PCWSTR inf
, LPGUID class_guid
, PWSTR class_name
,
3947 DWORD size
, PDWORD required_size
)
3949 BOOL have_guid
, have_name
;
3951 WCHAR buffer
[MAX_PATH
];
3955 SetLastError(ERROR_INVALID_PARAMETER
);
3959 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(inf
))
3961 FIXME("%s not found. Searching via DevicePath not implemented\n", debugstr_w(inf
));
3962 SetLastError(ERROR_FILE_NOT_FOUND
);
3966 if (!class_guid
|| !class_name
|| !size
)
3968 SetLastError(ERROR_INVALID_PARAMETER
);
3972 if (!GetPrivateProfileStringW(Version
, Signature
, NULL
, buffer
, MAX_PATH
, inf
))
3975 if (lstrcmpiW(buffer
, Chicago
) && lstrcmpiW(buffer
, WindowsNT
))
3979 have_guid
= 0 < GetPrivateProfileStringW(Version
, ClassGUID
, NULL
, buffer
, MAX_PATH
, inf
);
3982 buffer
[lstrlenW(buffer
)-1] = 0;
3983 if (RPC_S_OK
!= UuidFromStringW(buffer
+ 1, class_guid
))
3985 FIXME("failed to convert \"%s\" into a guid\n", debugstr_w(buffer
));
3986 SetLastError(ERROR_INVALID_PARAMETER
);
3992 dret
= GetPrivateProfileStringW(Version
, Class
, NULL
, buffer
, MAX_PATH
, inf
);
3993 have_name
= 0 < dret
;
3995 if (dret
>= MAX_PATH
-1) FIXME("buffer might be too small\n");
3996 if (have_guid
&& !have_name
) FIXME("class name lookup via guid not implemented\n");
4000 if (dret
< size
) lstrcpyW(class_name
, buffer
);
4003 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4008 if (required_size
) *required_size
= dret
+ ((dret
) ? 1 : 0);
4010 return (have_guid
|| have_name
);
4013 /***********************************************************************
4014 * SetupDiGetDevicePropertyW (SETUPAPI.@)
4016 BOOL WINAPI
SetupDiGetDevicePropertyW(HDEVINFO info_set
, PSP_DEVINFO_DATA info_data
,
4017 const DEVPROPKEY
*prop_key
, DEVPROPTYPE
*prop_type
, BYTE
*prop_buff
,
4018 DWORD prop_buff_size
, DWORD
*required_size
, DWORD flags
)
4020 FIXME("%p, %p, %p, %p, %p, %d, %p, 0x%08x stub\n", info_set
, info_data
, prop_key
,
4021 prop_type
, prop_buff
, prop_buff_size
, required_size
, flags
);
4023 SetLastError(ERROR_NOT_FOUND
);