kernel32/tests: A spelling fix in a comment.
[wine.git] / dlls / setupapi / devinst.c
blobffb5fad1bfd7c6daf171a0206be59c6c0d77fca4
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnt.h"
29 #include "winreg.h"
30 #include "winternl.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34 #include "setupapi.h"
35 #include "wine/debug.h"
36 #include "wine/list.h"
37 #include "wine/unicode.h"
38 #include "cfgmgr32.h"
39 #include "winioctl.h"
40 #include "rpc.h"
41 #include "rpcdce.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','\\',
75 'E','n','u','m',0};
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
94 valid or not */
95 #define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff056
97 struct DeviceInfoSet
99 DWORD magic; /* if is equal to SETUP_DEVICE_INFO_SET_MAGIC struct is okay */
100 GUID ClassGuid;
101 HWND hwndParent;
102 DWORD cDevices;
103 struct list devices;
106 struct DeviceInstance
108 struct list entry;
109 SP_DEVINFO_DATA data;
112 /* Pointed to by SP_DEVICE_INTERFACE_DATA's Reserved member */
113 struct InterfaceInfo
115 LPWSTR referenceString;
116 LPWSTR symbolicLink;
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
125 GUID guid;
126 DWORD cInstances;
127 DWORD cInstancesAllocated;
128 SP_DEVICE_INTERFACE_DATA *instances;
129 struct list entry;
132 /* Pointed to by SP_DEVINFO_DATA's Reserved member */
133 struct DeviceInfo
135 struct DeviceInfoSet *set;
136 HKEY key;
137 BOOL phantom;
138 DWORD devId;
139 LPWSTR instanceId;
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','%',
148 '0','2','X','}',0};
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)
157 DWORD i;
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)
188 BOOL found = FALSE;
189 struct InterfaceInstances *iface;
191 TRACE("%s\n", debugstr_guid(InterfaceClassGuid));
193 LIST_FOR_EACH_ENTRY(iface, &devInfo->interfaces, struct InterfaceInstances,
194 entry)
196 if (IsEqualGUID(&iface->guid, InterfaceClassGuid))
198 *iface_ret = iface;
199 found = TRUE;
200 break;
203 TRACE("returning %d (%p)\n", found, found ? *iface_ret : NULL);
204 return found;
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)
216 BOOL found = FALSE;
217 DWORD i;
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)
229 *instanceIndex = i;
230 found = TRUE;
232 else if (ReferenceString && ifaceInfo->referenceString &&
233 !lstrcmpiW(ifaceInfo->referenceString, ReferenceString))
235 *instanceIndex = i;
236 found = TRUE;
239 TRACE("returning %d (%d)\n", found, found ? *instanceIndex : 0);
240 return found;
243 static LPWSTR SETUPDI_CreateSymbolicLinkPath(LPCWSTR instanceId,
244 const GUID *InterfaceClassGuid, LPCWSTR ReferenceString)
246 static const WCHAR fmt[] = {'\\','\\','?','\\','%','s','#','%','s',0};
247 WCHAR guidStr[39];
248 DWORD len;
249 LPWSTR ret;
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));
261 if (ret)
263 int printed = sprintfW(ret, fmt, instanceId, guidStr);
264 LPWSTR ptr;
266 /* replace '\\' with '#' after the "\\\\?\\" beginning */
267 for (ptr = strchrW(ret + 4, '\\'); ptr; ptr = strchrW(ptr + 1, '\\'))
268 *ptr = '#';
269 if (ReferenceString && *ReferenceString)
271 ret[printed] = '\\';
272 lstrcpyW(ret + printed + 1, ReferenceString);
275 return ret;
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));
297 if (iface)
299 list_add_tail(&devInfo->interfaces, &iface->entry);
300 newInterface = TRUE;
303 if (iface)
305 DWORD instanceIndex = 0;
307 if (!(ret = SETUPDI_FindInterfaceInstance(iface, ReferenceString,
308 &instanceIndex)))
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,
322 iface->instances,
323 (iface->cInstancesAllocated + 1) *
324 sizeof(SP_DEVICE_INTERFACE_DATA));
325 if (iface->instances)
326 instance = &iface->instances[iface->cInstancesAllocated++];
328 else
329 instance = &iface->instances[iface->cInstances];
330 if (instance)
332 struct InterfaceInfo *ifaceInfo = HeapAlloc(GetProcessHeap(),
333 0, sizeof(struct InterfaceInfo));
335 if (ifaceInfo)
337 ret = TRUE;
338 ifaceInfo->device = DeviceInfoData;
339 ifaceInfo->symbolicLink = SETUPDI_CreateSymbolicLinkPath(
340 devInfo->instanceId, InterfaceClassGuid,
341 ReferenceString);
342 if (ReferenceString)
344 ifaceInfo->referenceString =
345 HeapAlloc(GetProcessHeap(), 0,
346 (lstrlenW(ReferenceString) + 1) *
347 sizeof(WCHAR));
348 if (ifaceInfo->referenceString)
349 lstrcpyW(ifaceInfo->referenceString,
350 ReferenceString);
351 else
352 ret = FALSE;
354 else
355 ifaceInfo->referenceString = NULL;
356 if (ret)
358 HKEY key;
360 iface->cInstances++;
361 instance->cbSize =
362 sizeof(SP_DEVICE_INTERFACE_DATA);
363 instance->InterfaceClassGuid = *InterfaceClassGuid;
364 instance->Flags = SPINT_ACTIVE; /* FIXME */
365 instance->Reserved = (ULONG_PTR)ifaceInfo;
366 if (newInterface)
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) *
375 sizeof(WCHAR));
376 RegCloseKey(key);
378 if (ifaceData)
379 *ifaceData = instance;
381 else
382 HeapFree(GetProcessHeap(), 0, ifaceInfo);
386 else
388 if (ifaceData)
389 *ifaceData = &iface->instances[instanceIndex];
392 else
393 ret = FALSE;
394 TRACE("returning %d\n", ret);
395 return ret;
398 static BOOL SETUPDI_SetInterfaceSymbolicLink(SP_DEVICE_INTERFACE_DATA *iface,
399 LPCWSTR symbolicLink)
401 struct InterfaceInfo *info = (struct InterfaceInfo *)iface->Reserved;
402 BOOL ret = FALSE;
404 if (info)
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);
412 ret = TRUE;
415 return ret;
418 static HKEY SETUPDI_CreateDevKey(struct DeviceInfo *devInfo)
420 HKEY enumKey, key = INVALID_HANDLE_VALUE;
421 LONG l;
423 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
424 NULL, &enumKey, NULL);
425 if (!l)
427 RegCreateKeyExW(enumKey, devInfo->instanceId, 0, NULL, 0,
428 KEY_READ | KEY_WRITE, NULL, &key, NULL);
429 RegCloseKey(enumKey);
431 return key;
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;
439 LONG l;
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);
447 if (!l)
449 static const WCHAR fmt[] = { '%','0','4','u',0 };
450 WCHAR devId[10];
452 sprintfW(devId, fmt, devInfo->devId);
453 RegCreateKeyExW(classKey, devId, 0, NULL, 0, KEY_READ | KEY_WRITE,
454 NULL, &key, NULL);
455 RegCloseKey(classKey);
457 return key;
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));
465 if (devInst)
466 devInfo = GlobalLock(devInst);
468 if (devInfo)
470 devInfo->set = set;
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)
484 if (phantom)
485 RegSetValueExW(devInfo->key, Phantom, 0, REG_DWORD,
486 (LPBYTE)&phantom, sizeof(phantom));
488 list_init(&devInfo->interfaces);
489 GlobalUnlock(devInst);
491 else
493 GlobalUnlock(devInst);
494 GlobalFree(devInst);
495 devInfo = NULL;
498 return devInfo;
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)
509 HKEY enumKey;
510 LONG l;
512 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0,
513 KEY_ALL_ACCESS, NULL, &enumKey, NULL);
514 if (!l)
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,
537 const GUID *guid,
538 DWORD dev_inst,
539 LPCWSTR instanceId,
540 BOOL phantom,
541 SP_DEVINFO_DATA **dev)
543 BOOL ret = FALSE;
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);
550 if (devInfo)
552 struct DeviceInstance *devInst =
553 HeapAlloc(GetProcessHeap(), 0, sizeof(struct DeviceInstance));
555 if (devInst)
557 WCHAR classGuidStr[39];
559 list_add_tail(&set->devices, &devInst->entry);
560 set->cDevices++;
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;
570 ret = TRUE;
572 else
574 HeapFree(GetProcessHeap(), 0, devInfo);
575 SetLastError(ERROR_OUTOFMEMORY);
578 return ret;
581 /***********************************************************************
582 * SetupDiBuildClassInfoList (SETUPAPI.@)
584 * Returns a list of setup class GUIDs that identify the classes
585 * that are installed on a local machine.
587 * PARAMS
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.
593 * RETURNS
594 * Success: TRUE.
595 * Failure: FALSE.
597 BOOL WINAPI SetupDiBuildClassInfoList(
598 DWORD Flags,
599 LPGUID ClassGuidList,
600 DWORD ClassGuidListSize,
601 PDWORD RequiredSize)
603 TRACE("\n");
604 return SetupDiBuildClassInfoListExW(Flags, ClassGuidList,
605 ClassGuidListSize, RequiredSize,
606 NULL, NULL);
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.
615 * PARAMS
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.
623 * RETURNS
624 * Success: TRUE.
625 * Failure: FALSE.
627 BOOL WINAPI SetupDiBuildClassInfoListExA(
628 DWORD Flags,
629 LPGUID ClassGuidList,
630 DWORD ClassGuidListSize,
631 PDWORD RequiredSize,
632 LPCSTR MachineName,
633 PVOID Reserved)
635 LPWSTR MachineNameW = NULL;
636 BOOL bResult;
638 TRACE("\n");
640 if (MachineName)
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);
652 return bResult;
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.
661 * PARAMS
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.
669 * RETURNS
670 * Success: TRUE.
671 * Failure: FALSE.
673 BOOL WINAPI SetupDiBuildClassInfoListExW(
674 DWORD Flags,
675 LPGUID ClassGuidList,
676 DWORD ClassGuidListSize,
677 PDWORD RequiredSize,
678 LPCWSTR MachineName,
679 PVOID Reserved)
681 WCHAR szKeyName[40];
682 HKEY hClassesKey;
683 HKEY hClassKey;
684 DWORD dwLength;
685 DWORD dwIndex;
686 LONG lError;
687 DWORD dwGuidListIndex = 0;
689 TRACE("\n");
691 if (RequiredSize != NULL)
692 *RequiredSize = 0;
694 hClassesKey = SetupDiOpenClassRegKeyExW(NULL,
695 KEY_ALL_ACCESS,
696 DIOCR_INSTALLER,
697 MachineName,
698 Reserved);
699 if (hClassesKey == INVALID_HANDLE_VALUE)
701 return FALSE;
704 for (dwIndex = 0; ; dwIndex++)
706 dwLength = 40;
707 lError = RegEnumKeyExW(hClassesKey,
708 dwIndex,
709 szKeyName,
710 &dwLength,
711 NULL,
712 NULL,
713 NULL,
714 NULL);
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,
721 szKeyName,
723 KEY_ALL_ACCESS,
724 &hClassKey))
726 RegCloseKey(hClassesKey);
727 return FALSE;
730 if (!RegQueryValueExW(hClassKey,
731 NoUseClass,
732 NULL,
733 NULL,
734 NULL,
735 NULL))
737 TRACE("'NoUseClass' value found!\n");
738 RegCloseKey(hClassKey);
739 continue;
742 if ((Flags & DIBCI_NOINSTALLCLASS) &&
743 (!RegQueryValueExW(hClassKey,
744 NoInstallClass,
745 NULL,
746 NULL,
747 NULL,
748 NULL)))
750 TRACE("'NoInstallClass' value found!\n");
751 RegCloseKey(hClassKey);
752 continue;
755 if ((Flags & DIBCI_NODISPLAYCLASS) &&
756 (!RegQueryValueExW(hClassKey,
757 NoDisplayClass,
758 NULL,
759 NULL,
760 NULL,
761 NULL)))
763 TRACE("'NoDisplayClass' value found!\n");
764 RegCloseKey(hClassKey);
765 continue;
768 RegCloseKey(hClassKey);
770 TRACE("Guid: %p\n", szKeyName);
771 if (dwGuidListIndex < ClassGuidListSize)
773 if (szKeyName[0] == '{' && szKeyName[37] == '}')
775 szKeyName[37] = 0;
777 TRACE("Guid: %p\n", &szKeyName[1]);
779 UuidFromStringW(&szKeyName[1],
780 &ClassGuidList[dwGuidListIndex]);
783 dwGuidListIndex++;
786 if (lError != ERROR_SUCCESS)
787 break;
790 RegCloseKey(hClassesKey);
792 if (RequiredSize != NULL)
793 *RequiredSize = dwGuidListIndex;
795 if (ClassGuidListSize < dwGuidListIndex)
797 SetLastError(ERROR_INSUFFICIENT_BUFFER);
798 return FALSE;
801 return TRUE;
804 /***********************************************************************
805 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
807 BOOL WINAPI SetupDiClassGuidsFromNameA(
808 LPCSTR ClassName,
809 LPGUID ClassGuidList,
810 DWORD ClassGuidListSize,
811 PDWORD RequiredSize)
813 return SetupDiClassGuidsFromNameExA(ClassName, ClassGuidList,
814 ClassGuidListSize, RequiredSize,
815 NULL, NULL);
818 /***********************************************************************
819 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
821 BOOL WINAPI SetupDiClassGuidsFromNameW(
822 LPCWSTR ClassName,
823 LPGUID ClassGuidList,
824 DWORD ClassGuidListSize,
825 PDWORD RequiredSize)
827 return SetupDiClassGuidsFromNameExW(ClassName, ClassGuidList,
828 ClassGuidListSize, RequiredSize,
829 NULL, NULL);
832 /***********************************************************************
833 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
835 BOOL WINAPI SetupDiClassGuidsFromNameExA(
836 LPCSTR ClassName,
837 LPGUID ClassGuidList,
838 DWORD ClassGuidListSize,
839 PDWORD RequiredSize,
840 LPCSTR MachineName,
841 PVOID Reserved)
843 LPWSTR ClassNameW = NULL;
844 LPWSTR MachineNameW = NULL;
845 BOOL bResult;
847 ClassNameW = MultiByteToUnicode(ClassName, CP_ACP);
848 if (ClassNameW == NULL)
849 return FALSE;
851 if (MachineName)
853 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
854 if (MachineNameW == NULL)
856 MyFree(ClassNameW);
857 return FALSE;
861 bResult = SetupDiClassGuidsFromNameExW(ClassNameW, ClassGuidList,
862 ClassGuidListSize, RequiredSize,
863 MachineNameW, Reserved);
865 MyFree(MachineNameW);
866 MyFree(ClassNameW);
868 return bResult;
871 /***********************************************************************
872 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
874 BOOL WINAPI SetupDiClassGuidsFromNameExW(
875 LPCWSTR ClassName,
876 LPGUID ClassGuidList,
877 DWORD ClassGuidListSize,
878 PDWORD RequiredSize,
879 LPCWSTR MachineName,
880 PVOID Reserved)
882 WCHAR szKeyName[40];
883 WCHAR szClassName[256];
884 HKEY hClassesKey;
885 HKEY hClassKey;
886 DWORD dwLength;
887 DWORD dwIndex;
888 LONG lError;
889 DWORD dwGuidListIndex = 0;
891 if (RequiredSize != NULL)
892 *RequiredSize = 0;
894 hClassesKey = SetupDiOpenClassRegKeyExW(NULL,
895 KEY_ALL_ACCESS,
896 DIOCR_INSTALLER,
897 MachineName,
898 Reserved);
899 if (hClassesKey == INVALID_HANDLE_VALUE)
901 return FALSE;
904 for (dwIndex = 0; ; dwIndex++)
906 dwLength = sizeof(szKeyName) / sizeof(WCHAR);
907 lError = RegEnumKeyExW(hClassesKey,
908 dwIndex,
909 szKeyName,
910 &dwLength,
911 NULL,
912 NULL,
913 NULL,
914 NULL);
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,
921 szKeyName,
923 KEY_ALL_ACCESS,
924 &hClassKey))
926 RegCloseKey(hClassesKey);
927 return FALSE;
930 dwLength = sizeof(szClassName);
931 if (!RegQueryValueExW(hClassKey,
932 Class,
933 NULL,
934 NULL,
935 (LPBYTE)szClassName,
936 &dwLength))
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] == '}')
949 szKeyName[37] = 0;
951 TRACE("Guid: %p\n", &szKeyName[1]);
953 UuidFromStringW(&szKeyName[1],
954 &ClassGuidList[dwGuidListIndex]);
957 dwGuidListIndex++;
961 RegCloseKey(hClassKey);
964 if (lError != ERROR_SUCCESS)
965 break;
968 RegCloseKey(hClassesKey);
970 if (RequiredSize != NULL)
971 *RequiredSize = dwGuidListIndex;
973 if (ClassGuidListSize < dwGuidListIndex)
975 SetLastError(ERROR_INSUFFICIENT_BUFFER);
976 return FALSE;
979 return TRUE;
982 /***********************************************************************
983 * SetupDiClassNameFromGuidA (SETUPAPI.@)
985 BOOL WINAPI SetupDiClassNameFromGuidA(
986 const GUID* ClassGuid,
987 PSTR ClassName,
988 DWORD ClassNameSize,
989 PDWORD RequiredSize)
991 return SetupDiClassNameFromGuidExA(ClassGuid, ClassName,
992 ClassNameSize, RequiredSize,
993 NULL, NULL);
996 /***********************************************************************
997 * SetupDiClassNameFromGuidW (SETUPAPI.@)
999 BOOL WINAPI SetupDiClassNameFromGuidW(
1000 const GUID* ClassGuid,
1001 PWSTR ClassName,
1002 DWORD ClassNameSize,
1003 PDWORD RequiredSize)
1005 return SetupDiClassNameFromGuidExW(ClassGuid, ClassName,
1006 ClassNameSize, RequiredSize,
1007 NULL, NULL);
1010 /***********************************************************************
1011 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1013 BOOL WINAPI SetupDiClassNameFromGuidExA(
1014 const GUID* ClassGuid,
1015 PSTR ClassName,
1016 DWORD ClassNameSize,
1017 PDWORD RequiredSize,
1018 PCSTR MachineName,
1019 PVOID Reserved)
1021 WCHAR ClassNameW[MAX_CLASS_NAME_LEN];
1022 LPWSTR MachineNameW = NULL;
1023 BOOL ret;
1025 if (MachineName)
1026 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
1027 ret = SetupDiClassNameFromGuidExW(ClassGuid, ClassNameW, MAX_CLASS_NAME_LEN,
1028 NULL, MachineNameW, Reserved);
1029 if (ret)
1031 int len = WideCharToMultiByte(CP_ACP, 0, ClassNameW, -1, ClassName,
1032 ClassNameSize, NULL, NULL);
1034 if (!ClassNameSize && RequiredSize)
1035 *RequiredSize = len;
1037 MyFree(MachineNameW);
1038 return ret;
1041 /***********************************************************************
1042 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1044 BOOL WINAPI SetupDiClassNameFromGuidExW(
1045 const GUID* ClassGuid,
1046 PWSTR ClassName,
1047 DWORD ClassNameSize,
1048 PDWORD RequiredSize,
1049 PCWSTR MachineName,
1050 PVOID Reserved)
1052 HKEY hKey;
1053 DWORD dwLength;
1055 hKey = SetupDiOpenClassRegKeyExW(ClassGuid,
1056 KEY_ALL_ACCESS,
1057 DIOCR_INSTALLER,
1058 MachineName,
1059 Reserved);
1060 if (hKey == INVALID_HANDLE_VALUE)
1062 return FALSE;
1065 if (RequiredSize != NULL)
1067 dwLength = 0;
1068 if (RegQueryValueExW(hKey,
1069 Class,
1070 NULL,
1071 NULL,
1072 NULL,
1073 &dwLength))
1075 RegCloseKey(hKey);
1076 return FALSE;
1079 *RequiredSize = dwLength / sizeof(WCHAR);
1082 dwLength = ClassNameSize * sizeof(WCHAR);
1083 if (RegQueryValueExW(hKey,
1084 Class,
1085 NULL,
1086 NULL,
1087 (LPBYTE)ClassName,
1088 &dwLength))
1090 RegCloseKey(hKey);
1091 return FALSE;
1094 RegCloseKey(hKey);
1096 return TRUE;
1099 /***********************************************************************
1100 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1102 HDEVINFO WINAPI
1103 SetupDiCreateDeviceInfoList(const GUID *ClassGuid,
1104 HWND hwndParent)
1106 return SetupDiCreateDeviceInfoListExW(ClassGuid, hwndParent, NULL, NULL);
1109 /***********************************************************************
1110 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1112 HDEVINFO WINAPI
1113 SetupDiCreateDeviceInfoListExA(const GUID *ClassGuid,
1114 HWND hwndParent,
1115 PCSTR MachineName,
1116 PVOID Reserved)
1118 LPWSTR MachineNameW = NULL;
1119 HDEVINFO hDevInfo;
1121 TRACE("\n");
1123 if (MachineName)
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);
1135 return hDevInfo;
1138 /***********************************************************************
1139 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1141 * Create an empty DeviceInfoSet list.
1143 * PARAMS
1144 * ClassGuid [I] if not NULL only devices with GUID ClassGuid are associated
1145 * with this list.
1146 * hwndParent [I] hwnd needed for interface related actions.
1147 * MachineName [I] name of machine to create empty DeviceInfoSet list, if NULL
1148 * local registry will be used.
1149 * Reserved [I] must be NULL
1151 * RETURNS
1152 * Success: empty list.
1153 * Failure: INVALID_HANDLE_VALUE.
1155 HDEVINFO WINAPI
1156 SetupDiCreateDeviceInfoListExW(const GUID *ClassGuid,
1157 HWND hwndParent,
1158 PCWSTR MachineName,
1159 PVOID Reserved)
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);
1181 if (!list)
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));
1192 list->cDevices = 0;
1193 list_init(&list->devices);
1195 return list;
1198 /***********************************************************************
1199 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1201 HKEY WINAPI SetupDiCreateDevRegKeyA(
1202 HDEVINFO DeviceInfoSet,
1203 PSP_DEVINFO_DATA DeviceInfoData,
1204 DWORD Scope,
1205 DWORD HwProfile,
1206 DWORD KeyType,
1207 HINF InfHandle,
1208 PCSTR InfSectionName)
1210 PWSTR InfSectionNameW = NULL;
1211 HKEY key;
1213 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet, DeviceInfoData, Scope,
1214 HwProfile, KeyType, InfHandle, debugstr_a(InfSectionName));
1216 if (InfHandle)
1218 if (!InfSectionName)
1220 SetLastError(ERROR_INVALID_PARAMETER);
1221 return INVALID_HANDLE_VALUE;
1223 else
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);
1232 return key;
1235 /***********************************************************************
1236 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1238 HKEY WINAPI SetupDiCreateDevRegKeyW(
1239 HDEVINFO DeviceInfoSet,
1240 PSP_DEVINFO_DATA DeviceInfoData,
1241 DWORD Scope,
1242 DWORD HwProfile,
1243 DWORD KeyType,
1244 HINF InfHandle,
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);
1293 switch (KeyType)
1295 case DIREG_DEV:
1296 key = SETUPDI_CreateDevKey(devInfo);
1297 break;
1298 case DIREG_DRV:
1299 key = SETUPDI_CreateDrvKey(devInfo);
1300 break;
1301 default:
1302 WARN("unknown KeyType %d\n", KeyType);
1304 if (InfHandle)
1305 SetupInstallFromInfSectionW(NULL, InfHandle, InfSectionName, SPINST_ALL,
1306 NULL, NULL, SP_COPY_NEWER_ONLY, NULL, NULL, DeviceInfoSet,
1307 DeviceInfoData);
1308 return key;
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)
1318 BOOL ret = FALSE;
1319 LPWSTR DeviceNameW = NULL;
1320 LPWSTR DeviceDescriptionW = NULL;
1322 if (DeviceName)
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);
1333 return FALSE;
1337 ret = SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceNameW, ClassGuid, DeviceDescriptionW,
1338 hwndParent, CreationFlags, DeviceInfoData);
1340 MyFree(DeviceNameW);
1341 MyFree(DeviceDescriptionW);
1343 return ret;
1346 static DWORD SETUPDI_DevNameToDevID(LPCWSTR devName)
1348 LPCWSTR ptr;
1349 int devNameLen = lstrlenW(devName);
1350 DWORD devInst = 0;
1351 BOOL valid = TRUE;
1353 TRACE("%s\n", debugstr_w(devName));
1354 for (ptr = devName; valid && *ptr && ptr - devName < devNameLen; )
1356 if (isdigitW(*ptr))
1358 devInst *= 10;
1359 devInst |= *ptr - '0';
1360 ptr++;
1362 else
1363 valid = FALSE;
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);
1384 if (!DeviceName)
1386 SetLastError(ERROR_INVALID_DEVINST_NAME);
1387 return FALSE;
1389 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
1391 SetLastError(ERROR_INVALID_HANDLE);
1392 return FALSE;
1394 if (!ClassGuid)
1396 SetLastError(ERROR_INVALID_PARAMETER);
1397 return FALSE;
1399 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1401 SetLastError(ERROR_INVALID_HANDLE);
1402 return FALSE;
1404 if (!IsEqualGUID(&set->ClassGuid, &GUID_NULL) &&
1405 !IsEqualGUID(ClassGuid, &set->ClassGuid))
1407 SetLastError(ERROR_CLASS_MISMATCH);
1408 return FALSE;
1410 if ((CreationFlags & DICD_GENERATE_ID))
1412 if (strchrW(DeviceName, '\\'))
1413 SetLastError(ERROR_INVALID_DEVINST_NAME);
1414 else
1416 static const WCHAR newDeviceFmt[] = {'R','O','O','T','\\','%','s',
1417 '\\','%','0','4','d',0};
1418 DWORD devId;
1420 if (set->cDevices)
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, '\\');
1429 DWORD id;
1431 if (devName)
1432 devName++;
1433 else
1434 devName = devInfo->instanceId;
1435 id = SETUPDI_DevNameToDevID(devName);
1436 if (id != 0xffffffff && id > highestDevID)
1437 highestDevID = id;
1439 devId = highestDevID + 1;
1441 else
1442 devId = 0;
1443 /* 17 == lstrlenW(L"Root\\") + lstrlenW("\\") + 1 + %d max size */
1444 instanceId = HeapAlloc(GetProcessHeap(), 0,
1445 (17 + lstrlenW(DeviceName)) * sizeof(WCHAR));
1446 if (instanceId)
1448 sprintfW((LPWSTR)instanceId, newDeviceFmt, DeviceName,
1449 devId);
1450 allocatedInstanceId = TRUE;
1451 ret = TRUE;
1453 else
1454 ret = FALSE;
1457 else
1459 struct DeviceInstance *devInst;
1461 ret = TRUE;
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);
1470 ret = FALSE;
1474 if (ret)
1476 SP_DEVINFO_DATA *dev = NULL;
1478 ret = SETUPDI_AddDeviceToSet(set, ClassGuid, 0 /* FIXME: DevInst */,
1479 instanceId, TRUE, &dev);
1480 if (ret)
1482 if (DeviceDescription)
1483 SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet,
1484 dev, SPDRP_DEVICEDESC, (const BYTE *)DeviceDescription,
1485 lstrlenW(DeviceDescription) * sizeof(WCHAR));
1486 if (DeviceInfoData)
1488 if (DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA))
1490 SetLastError(ERROR_INVALID_USER_BUFFER);
1491 ret = FALSE;
1493 else
1494 *DeviceInfoData = *dev;
1498 if (allocatedInstanceId)
1499 HeapFree(GetProcessHeap(), 0, (LPWSTR)instanceId);
1501 return ret;
1504 /***********************************************************************
1505 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1507 BOOL WINAPI SetupDiRegisterDeviceInfo(
1508 HDEVINFO DeviceInfoSet,
1509 PSP_DEVINFO_DATA DeviceInfoData,
1510 DWORD Flags,
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);
1524 return FALSE;
1526 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1528 SetLastError(ERROR_INVALID_HANDLE);
1529 return FALSE;
1531 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
1532 || !DeviceInfoData->Reserved)
1534 SetLastError(ERROR_INVALID_PARAMETER);
1535 return FALSE;
1537 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1538 if (devInfo->set != set)
1540 SetLastError(ERROR_INVALID_PARAMETER);
1541 return FALSE;
1543 if (devInfo->phantom)
1545 devInfo->phantom = FALSE;
1546 RegDeleteValueW(devInfo->key, Phantom);
1548 return TRUE;
1551 /***********************************************************************
1552 * SetupDiRemoveDevice (SETUPAPI.@)
1554 BOOL WINAPI SetupDiRemoveDevice(
1555 HDEVINFO devinfo,
1556 PSP_DEVINFO_DATA info)
1558 FIXME("(%p, %p): stub\n", devinfo, info);
1559 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1560 return FALSE;
1563 /***********************************************************************
1564 * SetupDiRemoveDeviceInterface (SETUPAPI.@)
1566 BOOL WINAPI SetupDiRemoveDeviceInterface(HDEVINFO info, PSP_DEVICE_INTERFACE_DATA data)
1568 FIXME("(%p, %p): stub\n", info, data);
1569 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1570 return FALSE;
1573 /***********************************************************************
1574 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1576 BOOL WINAPI SetupDiEnumDeviceInfo(
1577 HDEVINFO devinfo,
1578 DWORD index,
1579 PSP_DEVINFO_DATA info)
1581 BOOL ret = FALSE;
1583 TRACE("%p %d %p\n", devinfo, index, info);
1585 if(info==NULL)
1587 SetLastError(ERROR_INVALID_PARAMETER);
1588 return FALSE;
1590 if (devinfo && devinfo != INVALID_HANDLE_VALUE)
1592 struct DeviceInfoSet *list = devinfo;
1593 if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC)
1595 if (index < list->cDevices)
1597 if (info->cbSize == sizeof(SP_DEVINFO_DATA))
1599 struct DeviceInstance *devInst;
1600 DWORD i = 0;
1602 LIST_FOR_EACH_ENTRY(devInst, &list->devices,
1603 struct DeviceInstance, entry)
1605 if (i++ == index)
1607 *info = devInst->data;
1608 break;
1611 ret = TRUE;
1613 else
1614 SetLastError(ERROR_INVALID_USER_BUFFER);
1616 else
1617 SetLastError(ERROR_NO_MORE_ITEMS);
1619 else
1620 SetLastError(ERROR_INVALID_HANDLE);
1622 else
1623 SetLastError(ERROR_INVALID_HANDLE);
1624 return ret;
1627 /***********************************************************************
1628 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1630 BOOL WINAPI SetupDiGetDeviceInstanceIdA(
1631 HDEVINFO DeviceInfoSet,
1632 PSP_DEVINFO_DATA DeviceInfoData,
1633 PSTR DeviceInstanceId,
1634 DWORD DeviceInstanceIdSize,
1635 PDWORD RequiredSize)
1637 BOOL ret = FALSE;
1638 DWORD size;
1639 PWSTR instanceId;
1641 TRACE("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId,
1642 DeviceInstanceIdSize, RequiredSize);
1644 SetupDiGetDeviceInstanceIdW(DeviceInfoSet,
1645 DeviceInfoData,
1646 NULL,
1648 &size);
1649 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
1650 return FALSE;
1651 instanceId = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
1652 if (instanceId)
1654 ret = SetupDiGetDeviceInstanceIdW(DeviceInfoSet,
1655 DeviceInfoData,
1656 instanceId,
1657 size,
1658 &size);
1659 if (ret)
1661 int len = WideCharToMultiByte(CP_ACP, 0, instanceId, -1,
1662 DeviceInstanceId,
1663 DeviceInstanceIdSize, NULL, NULL);
1665 if (!len)
1666 ret = FALSE;
1667 else
1669 if (len > DeviceInstanceIdSize)
1671 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1672 ret = FALSE;
1674 if (RequiredSize)
1675 *RequiredSize = len;
1678 HeapFree(GetProcessHeap(), 0, instanceId);
1680 return ret;
1683 /***********************************************************************
1684 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1686 BOOL WINAPI SetupDiGetDeviceInstanceIdW(
1687 HDEVINFO DeviceInfoSet,
1688 PSP_DEVINFO_DATA DeviceInfoData,
1689 PWSTR DeviceInstanceId,
1690 DWORD DeviceInstanceIdSize,
1691 PDWORD RequiredSize)
1693 struct DeviceInfoSet *set = DeviceInfoSet;
1694 struct DeviceInfo *devInfo;
1696 TRACE("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId,
1697 DeviceInstanceIdSize, RequiredSize);
1699 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
1701 SetLastError(ERROR_INVALID_HANDLE);
1702 return FALSE;
1704 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1706 SetLastError(ERROR_INVALID_HANDLE);
1707 return FALSE;
1709 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
1710 || !DeviceInfoData->Reserved)
1712 SetLastError(ERROR_INVALID_PARAMETER);
1713 return FALSE;
1715 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1716 if (devInfo->set != set)
1718 SetLastError(ERROR_INVALID_PARAMETER);
1719 return FALSE;
1721 TRACE("instance ID: %s\n", debugstr_w(devInfo->instanceId));
1722 if (DeviceInstanceIdSize < strlenW(devInfo->instanceId) + 1)
1724 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1725 if (RequiredSize)
1726 *RequiredSize = lstrlenW(devInfo->instanceId) + 1;
1727 return FALSE;
1729 lstrcpyW(DeviceInstanceId, devInfo->instanceId);
1730 if (RequiredSize)
1731 *RequiredSize = lstrlenW(devInfo->instanceId) + 1;
1732 return TRUE;
1735 /***********************************************************************
1736 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1738 BOOL WINAPI SetupDiGetActualSectionToInstallA(
1739 HINF InfHandle,
1740 PCSTR InfSectionName,
1741 PSTR InfSectionWithExt,
1742 DWORD InfSectionWithExtSize,
1743 PDWORD RequiredSize,
1744 PSTR *Extension)
1746 FIXME("\n");
1747 return FALSE;
1750 /***********************************************************************
1751 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
1753 BOOL WINAPI SetupDiGetActualSectionToInstallW(
1754 HINF InfHandle,
1755 PCWSTR InfSectionName,
1756 PWSTR InfSectionWithExt,
1757 DWORD InfSectionWithExtSize,
1758 PDWORD RequiredSize,
1759 PWSTR *Extension)
1761 WCHAR szBuffer[MAX_PATH];
1762 DWORD dwLength;
1763 DWORD dwFullLength;
1764 LONG lLineCount = -1;
1766 lstrcpyW(szBuffer, InfSectionName);
1767 dwLength = lstrlenW(szBuffer);
1769 if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
1771 /* Test section name with '.NTx86' extension */
1772 lstrcpyW(&szBuffer[dwLength], NtPlatformExtension);
1773 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1775 if (lLineCount == -1)
1777 /* Test section name with '.NT' extension */
1778 lstrcpyW(&szBuffer[dwLength], NtExtension);
1779 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1782 else
1784 /* Test section name with '.Win' extension */
1785 lstrcpyW(&szBuffer[dwLength], WinExtension);
1786 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1789 if (lLineCount == -1)
1791 /* Test section name without extension */
1792 szBuffer[dwLength] = 0;
1793 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1796 if (lLineCount == -1)
1798 SetLastError(ERROR_INVALID_PARAMETER);
1799 return FALSE;
1802 dwFullLength = lstrlenW(szBuffer);
1804 if (InfSectionWithExt != NULL && InfSectionWithExtSize != 0)
1806 if (InfSectionWithExtSize < (dwFullLength + 1))
1808 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1809 return FALSE;
1812 lstrcpyW(InfSectionWithExt, szBuffer);
1813 if (Extension != NULL)
1815 *Extension = (dwLength == dwFullLength) ? NULL : &InfSectionWithExt[dwLength];
1819 if (RequiredSize != NULL)
1821 *RequiredSize = dwFullLength + 1;
1824 return TRUE;
1827 /***********************************************************************
1828 * SetupDiGetClassDescriptionA (SETUPAPI.@)
1830 BOOL WINAPI SetupDiGetClassDescriptionA(
1831 const GUID* ClassGuid,
1832 PSTR ClassDescription,
1833 DWORD ClassDescriptionSize,
1834 PDWORD RequiredSize)
1836 return SetupDiGetClassDescriptionExA(ClassGuid, ClassDescription,
1837 ClassDescriptionSize,
1838 RequiredSize, NULL, NULL);
1841 /***********************************************************************
1842 * SetupDiGetClassDescriptionW (SETUPAPI.@)
1844 BOOL WINAPI SetupDiGetClassDescriptionW(
1845 const GUID* ClassGuid,
1846 PWSTR ClassDescription,
1847 DWORD ClassDescriptionSize,
1848 PDWORD RequiredSize)
1850 return SetupDiGetClassDescriptionExW(ClassGuid, ClassDescription,
1851 ClassDescriptionSize,
1852 RequiredSize, NULL, NULL);
1855 /***********************************************************************
1856 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
1858 BOOL WINAPI SetupDiGetClassDescriptionExA(
1859 const GUID* ClassGuid,
1860 PSTR ClassDescription,
1861 DWORD ClassDescriptionSize,
1862 PDWORD RequiredSize,
1863 PCSTR MachineName,
1864 PVOID Reserved)
1866 HKEY hKey;
1867 DWORD dwLength;
1868 BOOL ret;
1870 hKey = SetupDiOpenClassRegKeyExA(ClassGuid,
1871 KEY_ALL_ACCESS,
1872 DIOCR_INSTALLER,
1873 MachineName,
1874 Reserved);
1875 if (hKey == INVALID_HANDLE_VALUE)
1877 WARN("SetupDiOpenClassRegKeyExA() failed (Error %u)\n", GetLastError());
1878 return FALSE;
1881 dwLength = ClassDescriptionSize;
1882 ret = !RegQueryValueExA( hKey, NULL, NULL, NULL,
1883 (LPBYTE)ClassDescription, &dwLength );
1884 if (RequiredSize) *RequiredSize = dwLength;
1885 RegCloseKey(hKey);
1886 return ret;
1889 /***********************************************************************
1890 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
1892 BOOL WINAPI SetupDiGetClassDescriptionExW(
1893 const GUID* ClassGuid,
1894 PWSTR ClassDescription,
1895 DWORD ClassDescriptionSize,
1896 PDWORD RequiredSize,
1897 PCWSTR MachineName,
1898 PVOID Reserved)
1900 HKEY hKey;
1901 DWORD dwLength;
1902 BOOL ret;
1904 hKey = SetupDiOpenClassRegKeyExW(ClassGuid,
1905 KEY_ALL_ACCESS,
1906 DIOCR_INSTALLER,
1907 MachineName,
1908 Reserved);
1909 if (hKey == INVALID_HANDLE_VALUE)
1911 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
1912 return FALSE;
1915 dwLength = ClassDescriptionSize * sizeof(WCHAR);
1916 ret = !RegQueryValueExW( hKey, NULL, NULL, NULL,
1917 (LPBYTE)ClassDescription, &dwLength );
1918 if (RequiredSize) *RequiredSize = dwLength / sizeof(WCHAR);
1919 RegCloseKey(hKey);
1920 return ret;
1923 /***********************************************************************
1924 * SetupDiGetClassDevsA (SETUPAPI.@)
1926 HDEVINFO WINAPI SetupDiGetClassDevsA(const GUID *class, LPCSTR enumstr, HWND parent, DWORD flags)
1928 HDEVINFO ret;
1929 LPWSTR enumstrW = NULL;
1931 if (enumstr)
1933 int len = MultiByteToWideChar(CP_ACP, 0, enumstr, -1, NULL, 0);
1934 enumstrW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1935 if (!enumstrW)
1937 ret = INVALID_HANDLE_VALUE;
1938 goto end;
1940 MultiByteToWideChar(CP_ACP, 0, enumstr, -1, enumstrW, len);
1942 ret = SetupDiGetClassDevsExW(class, enumstrW, parent, flags, NULL, NULL,
1943 NULL);
1944 HeapFree(GetProcessHeap(), 0, enumstrW);
1946 end:
1947 return ret;
1950 /***********************************************************************
1951 * SetupDiGetClassDevsExA (SETUPAPI.@)
1953 HDEVINFO WINAPI SetupDiGetClassDevsExA(
1954 const GUID *class,
1955 PCSTR enumstr,
1956 HWND parent,
1957 DWORD flags,
1958 HDEVINFO deviceset,
1959 PCSTR machine,
1960 PVOID reserved)
1962 HDEVINFO ret;
1963 LPWSTR enumstrW = NULL, machineW = NULL;
1965 if (enumstr)
1967 int len = MultiByteToWideChar(CP_ACP, 0, enumstr, -1, NULL, 0);
1968 enumstrW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1969 if (!enumstrW)
1971 ret = INVALID_HANDLE_VALUE;
1972 goto end;
1974 MultiByteToWideChar(CP_ACP, 0, enumstr, -1, enumstrW, len);
1976 if (machine)
1978 int len = MultiByteToWideChar(CP_ACP, 0, machine, -1, NULL, 0);
1979 machineW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1980 if (!machineW)
1982 HeapFree(GetProcessHeap(), 0, enumstrW);
1983 ret = INVALID_HANDLE_VALUE;
1984 goto end;
1986 MultiByteToWideChar(CP_ACP, 0, machine, -1, machineW, len);
1988 ret = SetupDiGetClassDevsExW(class, enumstrW, parent, flags, deviceset,
1989 machineW, reserved);
1990 HeapFree(GetProcessHeap(), 0, enumstrW);
1991 HeapFree(GetProcessHeap(), 0, machineW);
1993 end:
1994 return ret;
1997 static void SETUPDI_AddDeviceInterfaces(SP_DEVINFO_DATA *dev, HKEY key,
1998 const GUID *guid)
2000 DWORD i, len;
2001 WCHAR subKeyName[MAX_PATH];
2002 LONG l = ERROR_SUCCESS;
2004 for (i = 0; !l; i++)
2006 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2007 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2008 if (!l)
2010 HKEY subKey;
2011 SP_DEVICE_INTERFACE_DATA *iface = NULL;
2013 if (*subKeyName == '#')
2015 /* The subkey name is the reference string, with a '#' prepended */
2016 SETUPDI_AddInterfaceInstance(dev, guid, subKeyName + 1, &iface);
2017 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2018 if (!l)
2020 WCHAR symbolicLink[MAX_PATH];
2021 DWORD dataType;
2023 len = sizeof(symbolicLink);
2024 l = RegQueryValueExW(subKey, SymbolicLink, NULL, &dataType,
2025 (BYTE *)symbolicLink, &len);
2026 if (!l && dataType == REG_SZ)
2027 SETUPDI_SetInterfaceSymbolicLink(iface, symbolicLink);
2028 RegCloseKey(subKey);
2031 /* Allow enumeration to continue */
2032 l = ERROR_SUCCESS;
2035 /* FIXME: find and add all the device's interfaces to the device */
2038 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet,
2039 HKEY key, const GUID *guid, LPCWSTR enumstr)
2041 struct DeviceInfoSet *set = DeviceInfoSet;
2042 DWORD i, len;
2043 WCHAR subKeyName[MAX_PATH];
2044 LONG l;
2045 HKEY enumKey = INVALID_HANDLE_VALUE;
2047 TRACE("%s\n", debugstr_w(enumstr));
2049 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
2050 &enumKey, NULL);
2051 for (i = 0; !l; i++)
2053 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2054 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2055 if (!l)
2057 HKEY subKey;
2059 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2060 if (!l)
2062 WCHAR deviceInst[MAX_PATH * 3];
2063 DWORD dataType;
2065 len = sizeof(deviceInst);
2066 l = RegQueryValueExW(subKey, DeviceInstance, NULL, &dataType,
2067 (BYTE *)deviceInst, &len);
2068 if (!l && dataType == REG_SZ)
2070 TRACE("found instance ID %s\n", debugstr_w(deviceInst));
2071 if (!enumstr || !lstrcmpiW(enumstr, deviceInst))
2073 HKEY deviceKey;
2075 l = RegOpenKeyExW(enumKey, deviceInst, 0, KEY_READ,
2076 &deviceKey);
2077 if (!l)
2079 WCHAR deviceClassStr[40];
2081 len = sizeof(deviceClassStr);
2082 l = RegQueryValueExW(deviceKey, ClassGUID, NULL,
2083 &dataType, (BYTE *)deviceClassStr, &len);
2084 if (!l && dataType == REG_SZ &&
2085 deviceClassStr[0] == '{' &&
2086 deviceClassStr[37] == '}')
2088 GUID deviceClass;
2089 SP_DEVINFO_DATA *dev;
2091 deviceClassStr[37] = 0;
2092 UuidFromStringW(&deviceClassStr[1],
2093 &deviceClass);
2094 if (SETUPDI_AddDeviceToSet(set, &deviceClass,
2095 0 /* FIXME: DevInst */, deviceInst,
2096 FALSE, &dev))
2097 SETUPDI_AddDeviceInterfaces(dev, subKey, guid);
2099 RegCloseKey(deviceKey);
2103 RegCloseKey(subKey);
2105 /* Allow enumeration to continue */
2106 l = ERROR_SUCCESS;
2109 if (enumKey != INVALID_HANDLE_VALUE)
2110 RegCloseKey(enumKey);
2113 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet,
2114 const GUID *guid, LPCWSTR enumstr, DWORD flags)
2116 HKEY interfacesKey = SetupDiOpenClassRegKeyExW(guid, KEY_READ,
2117 DIOCR_INTERFACE, NULL, NULL);
2119 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(guid),
2120 debugstr_w(enumstr), flags);
2122 if (interfacesKey != INVALID_HANDLE_VALUE)
2124 if (flags & DIGCF_ALLCLASSES)
2126 DWORD i, len;
2127 WCHAR interfaceGuidStr[40];
2128 LONG l = ERROR_SUCCESS;
2130 for (i = 0; !l; i++)
2132 len = sizeof(interfaceGuidStr) / sizeof(interfaceGuidStr[0]);
2133 l = RegEnumKeyExW(interfacesKey, i, interfaceGuidStr, &len,
2134 NULL, NULL, NULL, NULL);
2135 if (!l)
2137 if (interfaceGuidStr[0] == '{' &&
2138 interfaceGuidStr[37] == '}')
2140 HKEY interfaceKey;
2141 GUID interfaceGuid;
2143 interfaceGuidStr[37] = 0;
2144 UuidFromStringW(&interfaceGuidStr[1], &interfaceGuid);
2145 interfaceGuidStr[37] = '}';
2146 interfaceGuidStr[38] = 0;
2147 l = RegOpenKeyExW(interfacesKey, interfaceGuidStr, 0,
2148 KEY_READ, &interfaceKey);
2149 if (!l)
2151 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
2152 interfaceKey, &interfaceGuid, enumstr);
2153 RegCloseKey(interfaceKey);
2159 else
2161 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2162 * interface's key, so just pass that long
2164 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
2165 interfacesKey, guid, enumstr);
2167 RegCloseKey(interfacesKey);
2171 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet *set,
2172 LPCWSTR enumerator, LPCWSTR deviceName, HKEY deviceKey,
2173 const GUID *class, DWORD flags)
2175 DWORD i, len;
2176 WCHAR deviceInstance[MAX_PATH];
2177 LONG l = ERROR_SUCCESS;
2179 TRACE("%s %s\n", debugstr_w(enumerator), debugstr_w(deviceName));
2181 for (i = 0; !l; i++)
2183 len = sizeof(deviceInstance) / sizeof(deviceInstance[0]);
2184 l = RegEnumKeyExW(deviceKey, i, deviceInstance, &len, NULL, NULL, NULL,
2185 NULL);
2186 if (!l)
2188 HKEY subKey;
2190 l = RegOpenKeyExW(deviceKey, deviceInstance, 0, KEY_READ, &subKey);
2191 if (!l)
2193 WCHAR classGuid[40];
2194 DWORD dataType;
2196 len = sizeof(classGuid);
2197 l = RegQueryValueExW(subKey, ClassGUID, NULL, &dataType,
2198 (BYTE *)classGuid, &len);
2199 if (!l && dataType == REG_SZ)
2201 if (classGuid[0] == '{' && classGuid[37] == '}')
2203 GUID deviceClass;
2205 classGuid[37] = 0;
2206 UuidFromStringW(&classGuid[1], &deviceClass);
2207 if ((flags & DIGCF_ALLCLASSES) ||
2208 IsEqualGUID(class, &deviceClass))
2210 static const WCHAR fmt[] =
2211 {'%','s','\\','%','s','\\','%','s',0};
2212 LPWSTR instanceId;
2214 instanceId = HeapAlloc(GetProcessHeap(), 0,
2215 (lstrlenW(enumerator) + lstrlenW(deviceName) +
2216 lstrlenW(deviceInstance) + 3) * sizeof(WCHAR));
2217 if (instanceId)
2219 sprintfW(instanceId, fmt, enumerator,
2220 deviceName, deviceInstance);
2221 SETUPDI_AddDeviceToSet(set, &deviceClass,
2222 0 /* FIXME: DevInst */, instanceId,
2223 FALSE, NULL);
2224 HeapFree(GetProcessHeap(), 0, instanceId);
2229 RegCloseKey(subKey);
2231 /* Allow enumeration to continue */
2232 l = ERROR_SUCCESS;
2237 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet,
2238 LPCWSTR parent, HKEY key, const GUID *class, DWORD flags)
2240 struct DeviceInfoSet *set = DeviceInfoSet;
2241 DWORD i, len;
2242 WCHAR subKeyName[MAX_PATH];
2243 LONG l = ERROR_SUCCESS;
2245 TRACE("%s\n", debugstr_w(parent));
2247 for (i = 0; !l; i++)
2249 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2250 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2251 if (!l)
2253 HKEY subKey;
2255 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2256 if (!l)
2258 TRACE("%s\n", debugstr_w(subKeyName));
2259 SETUPDI_EnumerateMatchingDeviceInstances(set, parent,
2260 subKeyName, subKey, class, flags);
2261 RegCloseKey(subKey);
2263 /* Allow enumeration to continue */
2264 l = ERROR_SUCCESS;
2269 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet, const GUID *class,
2270 LPCWSTR enumstr, DWORD flags)
2272 HKEY enumKey;
2273 LONG l;
2275 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(class),
2276 debugstr_w(enumstr), flags);
2278 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
2279 &enumKey, NULL);
2280 if (enumKey != INVALID_HANDLE_VALUE)
2282 if (enumstr)
2284 HKEY enumStrKey;
2286 l = RegOpenKeyExW(enumKey, enumstr, 0, KEY_READ,
2287 &enumStrKey);
2288 if (!l)
2290 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet, enumstr,
2291 enumStrKey, class, flags);
2292 RegCloseKey(enumStrKey);
2295 else
2297 DWORD i, len;
2298 WCHAR subKeyName[MAX_PATH];
2300 l = ERROR_SUCCESS;
2301 for (i = 0; !l; i++)
2303 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2304 l = RegEnumKeyExW(enumKey, i, subKeyName, &len, NULL,
2305 NULL, NULL, NULL);
2306 if (!l)
2308 HKEY subKey;
2310 l = RegOpenKeyExW(enumKey, subKeyName, 0, KEY_READ,
2311 &subKey);
2312 if (!l)
2314 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet,
2315 subKeyName, subKey, class, flags);
2316 RegCloseKey(subKey);
2318 /* Allow enumeration to continue */
2319 l = ERROR_SUCCESS;
2323 RegCloseKey(enumKey);
2327 /***********************************************************************
2328 * SetupDiGetClassDevsW (SETUPAPI.@)
2330 HDEVINFO WINAPI SetupDiGetClassDevsW(const GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
2332 return SetupDiGetClassDevsExW(class, enumstr, parent, flags, NULL, NULL,
2333 NULL);
2336 /***********************************************************************
2337 * SetupDiGetClassDevsExW (SETUPAPI.@)
2339 HDEVINFO WINAPI SetupDiGetClassDevsExW(const GUID *class, PCWSTR enumstr, HWND parent, DWORD flags,
2340 HDEVINFO deviceset, PCWSTR machine, void *reserved)
2342 static const DWORD unsupportedFlags = DIGCF_DEFAULT | DIGCF_PRESENT |
2343 DIGCF_PROFILE;
2344 HDEVINFO set;
2346 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2347 debugstr_w(enumstr), parent, flags, deviceset, debugstr_w(machine),
2348 reserved);
2350 if (!(flags & DIGCF_ALLCLASSES) && !class)
2352 SetLastError(ERROR_INVALID_PARAMETER);
2353 return INVALID_HANDLE_VALUE;
2355 if (flags & unsupportedFlags)
2356 WARN("unsupported flags %08x\n", flags & unsupportedFlags);
2357 if (deviceset)
2358 set = deviceset;
2359 else
2360 set = SetupDiCreateDeviceInfoListExW(class, parent, machine, reserved);
2361 if (set != INVALID_HANDLE_VALUE)
2363 if (machine && *machine)
2364 FIXME("%s: unimplemented for remote machines\n",
2365 debugstr_w(machine));
2366 else if (flags & DIGCF_DEVICEINTERFACE)
2367 SETUPDI_EnumerateInterfaces(set, class, enumstr, flags);
2368 else
2369 SETUPDI_EnumerateDevices(set, class, enumstr, flags);
2371 return set;
2374 /***********************************************************************
2375 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2377 BOOL WINAPI SetupDiGetDeviceInfoListDetailA(
2378 HDEVINFO DeviceInfoSet,
2379 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData )
2381 struct DeviceInfoSet *set = DeviceInfoSet;
2383 TRACE("%p %p\n", DeviceInfoSet, DevInfoData);
2385 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2387 SetLastError(ERROR_INVALID_HANDLE);
2388 return FALSE;
2390 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2392 SetLastError(ERROR_INVALID_HANDLE);
2393 return FALSE;
2395 if (!DevInfoData ||
2396 DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A))
2398 SetLastError(ERROR_INVALID_PARAMETER);
2399 return FALSE;
2401 DevInfoData->ClassGuid = set->ClassGuid;
2402 DevInfoData->RemoteMachineHandle = NULL;
2403 DevInfoData->RemoteMachineName[0] = '\0';
2404 return TRUE;
2407 /***********************************************************************
2408 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2410 BOOL WINAPI SetupDiGetDeviceInfoListDetailW(
2411 HDEVINFO DeviceInfoSet,
2412 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData )
2414 struct DeviceInfoSet *set = DeviceInfoSet;
2416 TRACE("%p %p\n", DeviceInfoSet, DevInfoData);
2418 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2420 SetLastError(ERROR_INVALID_HANDLE);
2421 return FALSE;
2423 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2425 SetLastError(ERROR_INVALID_HANDLE);
2426 return FALSE;
2428 if (!DevInfoData ||
2429 DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W))
2431 SetLastError(ERROR_INVALID_PARAMETER);
2432 return FALSE;
2434 DevInfoData->ClassGuid = set->ClassGuid;
2435 DevInfoData->RemoteMachineHandle = NULL;
2436 DevInfoData->RemoteMachineName[0] = '\0';
2437 return TRUE;
2440 /***********************************************************************
2441 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2443 BOOL WINAPI SetupDiCreateDeviceInterfaceA(
2444 HDEVINFO DeviceInfoSet,
2445 PSP_DEVINFO_DATA DeviceInfoData,
2446 const GUID *InterfaceClassGuid,
2447 PCSTR ReferenceString,
2448 DWORD CreationFlags,
2449 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2451 BOOL ret;
2452 LPWSTR ReferenceStringW = NULL;
2454 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
2455 debugstr_guid(InterfaceClassGuid), debugstr_a(ReferenceString),
2456 CreationFlags, DeviceInterfaceData);
2458 if (ReferenceString)
2460 ReferenceStringW = MultiByteToUnicode(ReferenceString, CP_ACP);
2461 if (ReferenceStringW == NULL) return FALSE;
2464 ret = SetupDiCreateDeviceInterfaceW(DeviceInfoSet, DeviceInfoData,
2465 InterfaceClassGuid, ReferenceStringW, CreationFlags,
2466 DeviceInterfaceData);
2468 MyFree(ReferenceStringW);
2470 return ret;
2473 /***********************************************************************
2474 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2476 BOOL WINAPI SetupDiCreateDeviceInterfaceW(
2477 HDEVINFO DeviceInfoSet,
2478 PSP_DEVINFO_DATA DeviceInfoData,
2479 const GUID *InterfaceClassGuid,
2480 PCWSTR ReferenceString,
2481 DWORD CreationFlags,
2482 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2484 struct DeviceInfoSet *set = DeviceInfoSet;
2485 struct DeviceInfo *devInfo;
2486 SP_DEVICE_INTERFACE_DATA *iface = NULL;
2487 BOOL ret;
2489 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
2490 debugstr_guid(InterfaceClassGuid), debugstr_w(ReferenceString),
2491 CreationFlags, DeviceInterfaceData);
2493 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2495 SetLastError(ERROR_INVALID_HANDLE);
2496 return FALSE;
2498 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2500 SetLastError(ERROR_INVALID_HANDLE);
2501 return FALSE;
2503 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
2504 || !DeviceInfoData->Reserved)
2506 SetLastError(ERROR_INVALID_PARAMETER);
2507 return FALSE;
2509 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
2510 if (devInfo->set != set)
2512 SetLastError(ERROR_INVALID_PARAMETER);
2513 return FALSE;
2515 if (!InterfaceClassGuid)
2517 SetLastError(ERROR_INVALID_USER_BUFFER);
2518 return FALSE;
2520 if ((ret = SETUPDI_AddInterfaceInstance(DeviceInfoData, InterfaceClassGuid,
2521 ReferenceString, &iface)))
2523 if (DeviceInterfaceData)
2525 if (DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
2527 SetLastError(ERROR_INVALID_USER_BUFFER);
2528 ret = FALSE;
2530 else
2531 *DeviceInterfaceData = *iface;
2534 return ret;
2537 /***********************************************************************
2538 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2540 HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyA(
2541 HDEVINFO DeviceInfoSet,
2542 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2543 DWORD Reserved,
2544 REGSAM samDesired,
2545 HINF InfHandle,
2546 PCSTR InfSectionName)
2548 HKEY key;
2549 PWSTR InfSectionNameW = NULL;
2551 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
2552 samDesired, InfHandle, InfSectionName);
2553 if (InfHandle)
2555 if (!InfSectionName)
2557 SetLastError(ERROR_INVALID_PARAMETER);
2558 return INVALID_HANDLE_VALUE;
2560 InfSectionNameW = MultiByteToUnicode(InfSectionName, CP_ACP);
2561 if (!InfSectionNameW)
2562 return INVALID_HANDLE_VALUE;
2564 key = SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet,
2565 DeviceInterfaceData, Reserved, samDesired, InfHandle,
2566 InfSectionNameW);
2567 MyFree(InfSectionNameW);
2568 return key;
2571 static PWSTR SETUPDI_GetInstancePath(struct InterfaceInfo *ifaceInfo)
2573 static const WCHAR hash[] = {'#',0};
2574 PWSTR instancePath = NULL;
2576 if (ifaceInfo->referenceString)
2578 instancePath = HeapAlloc(GetProcessHeap(), 0,
2579 (lstrlenW(ifaceInfo->referenceString) + 2) * sizeof(WCHAR));
2580 if (instancePath)
2582 lstrcpyW(instancePath, hash);
2583 lstrcatW(instancePath, ifaceInfo->referenceString);
2585 else
2586 SetLastError(ERROR_OUTOFMEMORY);
2588 else
2590 instancePath = HeapAlloc(GetProcessHeap(), 0,
2591 (lstrlenW(hash) + 1) * sizeof(WCHAR));
2592 if (instancePath)
2593 lstrcpyW(instancePath, hash);
2595 return instancePath;
2598 /***********************************************************************
2599 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2601 HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyW(
2602 HDEVINFO DeviceInfoSet,
2603 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2604 DWORD Reserved,
2605 REGSAM samDesired,
2606 HINF InfHandle,
2607 PCWSTR InfSectionName)
2609 struct DeviceInfoSet *set = DeviceInfoSet;
2610 HKEY key = INVALID_HANDLE_VALUE, interfacesKey;
2611 LONG l;
2613 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
2614 samDesired, InfHandle, InfSectionName);
2616 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2617 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2619 SetLastError(ERROR_INVALID_HANDLE);
2620 return INVALID_HANDLE_VALUE;
2622 if (!DeviceInterfaceData ||
2623 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2624 !DeviceInterfaceData->Reserved)
2626 SetLastError(ERROR_INVALID_PARAMETER);
2627 return INVALID_HANDLE_VALUE;
2629 if (InfHandle && !InfSectionName)
2631 SetLastError(ERROR_INVALID_PARAMETER);
2632 return INVALID_HANDLE_VALUE;
2634 if (!(l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, DeviceClasses, 0, NULL, 0,
2635 samDesired, NULL, &interfacesKey, NULL)))
2637 HKEY parent;
2638 WCHAR bracedGuidString[39];
2640 SETUPDI_GuidToString(&DeviceInterfaceData->InterfaceClassGuid,
2641 bracedGuidString);
2642 if (!(l = RegCreateKeyExW(interfacesKey, bracedGuidString, 0, NULL, 0,
2643 samDesired, NULL, &parent, NULL)))
2645 struct InterfaceInfo *ifaceInfo =
2646 (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2647 PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo);
2648 PWSTR interfKeyName = HeapAlloc(GetProcessHeap(), 0,
2649 (lstrlenW(ifaceInfo->symbolicLink) + 1) * sizeof(WCHAR));
2650 HKEY interfKey;
2651 WCHAR *ptr;
2653 lstrcpyW(interfKeyName, ifaceInfo->symbolicLink);
2654 if (lstrlenW(ifaceInfo->symbolicLink) > 3)
2656 interfKeyName[0] = '#';
2657 interfKeyName[1] = '#';
2658 interfKeyName[3] = '#';
2660 ptr = strchrW(interfKeyName, '\\');
2661 if (ptr)
2662 *ptr = 0;
2663 l = RegCreateKeyExW(parent, interfKeyName, 0, NULL, 0,
2664 samDesired, NULL, &interfKey, NULL);
2665 if (!l)
2667 struct DeviceInfo *devInfo =
2668 (struct DeviceInfo *)ifaceInfo->device->Reserved;
2670 l = RegSetValueExW(interfKey, DeviceInstance, 0, REG_SZ,
2671 (BYTE *)devInfo->instanceId,
2672 (lstrlenW(devInfo->instanceId) + 1) * sizeof(WCHAR));
2673 if (!l)
2675 if (instancePath)
2677 LONG l;
2679 l = RegCreateKeyExW(interfKey, instancePath, 0, NULL, 0,
2680 samDesired, NULL, &key, NULL);
2681 if (l)
2683 SetLastError(l);
2684 key = INVALID_HANDLE_VALUE;
2686 else if (InfHandle)
2687 FIXME("INF section installation unsupported\n");
2690 else
2691 SetLastError(l);
2692 RegCloseKey(interfKey);
2694 else
2695 SetLastError(l);
2696 HeapFree(GetProcessHeap(), 0, interfKeyName);
2697 HeapFree(GetProcessHeap(), 0, instancePath);
2698 RegCloseKey(parent);
2700 else
2701 SetLastError(l);
2702 RegCloseKey(interfacesKey);
2704 else
2705 SetLastError(l);
2706 return key;
2709 /***********************************************************************
2710 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2712 BOOL WINAPI SetupDiDeleteDeviceInterfaceRegKey(
2713 HDEVINFO DeviceInfoSet,
2714 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2715 DWORD Reserved)
2717 struct DeviceInfoSet *set = DeviceInfoSet;
2718 HKEY parent;
2719 BOOL ret = FALSE;
2721 TRACE("%p %p %d\n", DeviceInfoSet, DeviceInterfaceData, Reserved);
2723 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2724 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2726 SetLastError(ERROR_INVALID_HANDLE);
2727 return FALSE;
2729 if (!DeviceInterfaceData ||
2730 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2731 !DeviceInterfaceData->Reserved)
2733 SetLastError(ERROR_INVALID_PARAMETER);
2734 return FALSE;
2736 parent = SetupDiOpenClassRegKeyExW(&DeviceInterfaceData->InterfaceClassGuid,
2737 KEY_ALL_ACCESS, DIOCR_INTERFACE, NULL, NULL);
2738 if (parent != INVALID_HANDLE_VALUE)
2740 struct InterfaceInfo *ifaceInfo =
2741 (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2742 PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo);
2744 if (instancePath)
2746 LONG l = RegDeleteKeyW(parent, instancePath);
2748 if (l)
2749 SetLastError(l);
2750 else
2751 ret = TRUE;
2752 HeapFree(GetProcessHeap(), 0, instancePath);
2754 RegCloseKey(parent);
2756 return ret;
2759 /***********************************************************************
2760 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2762 * PARAMS
2763 * DeviceInfoSet [I] Set of devices from which to enumerate
2764 * interfaces
2765 * DeviceInfoData [I] (Optional) If specified, a specific device
2766 * instance from which to enumerate interfaces.
2767 * If it isn't specified, all interfaces for all
2768 * devices in the set are enumerated.
2769 * InterfaceClassGuid [I] The interface class to enumerate.
2770 * MemberIndex [I] An index of the interface instance to enumerate.
2771 * A caller should start with MemberIndex set to 0,
2772 * and continue until the function fails with
2773 * ERROR_NO_MORE_ITEMS.
2774 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2775 * member must be set to
2776 * sizeof(SP_DEVICE_INTERFACE_DATA).
2778 * RETURNS
2779 * Success: non-zero value.
2780 * Failure: FALSE. Call GetLastError() for more info.
2782 BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData,
2783 const GUID *InterfaceClassGuid, DWORD MemberIndex,
2784 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2786 struct DeviceInfoSet *set = DeviceInfoSet;
2787 BOOL ret = FALSE;
2789 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet, DeviceInfoData,
2790 debugstr_guid(InterfaceClassGuid), MemberIndex, DeviceInterfaceData);
2792 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2793 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2795 SetLastError(ERROR_INVALID_HANDLE);
2796 return FALSE;
2798 if (DeviceInfoData && (DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) ||
2799 !DeviceInfoData->Reserved))
2801 SetLastError(ERROR_INVALID_PARAMETER);
2802 return FALSE;
2804 if (!DeviceInterfaceData ||
2805 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
2807 SetLastError(ERROR_INVALID_PARAMETER);
2808 return FALSE;
2811 /* In case application fails to check return value, clear output */
2812 memset(DeviceInterfaceData, 0, sizeof(*DeviceInterfaceData));
2813 DeviceInterfaceData->cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
2815 if (DeviceInfoData)
2817 struct DeviceInfo *devInfo =
2818 (struct DeviceInfo *)DeviceInfoData->Reserved;
2819 struct InterfaceInstances *iface;
2821 if ((ret = SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface)))
2823 if (MemberIndex < iface->cInstances)
2824 *DeviceInterfaceData = iface->instances[MemberIndex];
2825 else
2827 SetLastError(ERROR_NO_MORE_ITEMS);
2828 ret = FALSE;
2831 else
2832 SetLastError(ERROR_NO_MORE_ITEMS);
2834 else
2836 struct DeviceInstance *devInst;
2837 DWORD cEnumerated = 0;
2838 BOOL found = FALSE;
2840 LIST_FOR_EACH_ENTRY(devInst, &set->devices, struct DeviceInstance, entry)
2842 struct DeviceInfo *devInfo = (struct DeviceInfo *)devInst->data.Reserved;
2843 struct InterfaceInstances *iface;
2845 if (found || cEnumerated >= MemberIndex + 1)
2846 break;
2847 if (SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface))
2849 if (cEnumerated + iface->cInstances < MemberIndex + 1)
2850 cEnumerated += iface->cInstances;
2851 else
2853 DWORD instanceIndex = MemberIndex - cEnumerated;
2855 *DeviceInterfaceData = iface->instances[instanceIndex];
2856 cEnumerated += instanceIndex + 1;
2857 found = TRUE;
2858 ret = TRUE;
2862 if (!found)
2863 SetLastError(ERROR_NO_MORE_ITEMS);
2865 return ret;
2868 /***********************************************************************
2869 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2871 * Destroy a DeviceInfoList and free all used memory of the list.
2873 * PARAMS
2874 * devinfo [I] DeviceInfoList pointer to list to destroy
2876 * RETURNS
2877 * Success: non zero value.
2878 * Failure: zero value.
2880 BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
2882 BOOL ret = FALSE;
2884 TRACE("%p\n", devinfo);
2885 if (devinfo && devinfo != INVALID_HANDLE_VALUE)
2887 struct DeviceInfoSet *list = devinfo;
2889 if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC)
2891 struct DeviceInstance *devInst, *devInst2;
2893 LIST_FOR_EACH_ENTRY_SAFE(devInst, devInst2, &list->devices,
2894 struct DeviceInstance, entry)
2896 SETUPDI_FreeDeviceInfo( (struct DeviceInfo *)devInst->data.Reserved );
2897 list_remove(&devInst->entry);
2898 HeapFree(GetProcessHeap(), 0, devInst);
2900 HeapFree(GetProcessHeap(), 0, list);
2901 ret = TRUE;
2905 if (!ret)
2906 SetLastError(ERROR_INVALID_HANDLE);
2908 return ret;
2911 /***********************************************************************
2912 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2914 BOOL WINAPI SetupDiGetDeviceInterfaceDetailA(
2915 HDEVINFO DeviceInfoSet,
2916 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2917 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData,
2918 DWORD DeviceInterfaceDetailDataSize,
2919 PDWORD RequiredSize,
2920 PSP_DEVINFO_DATA DeviceInfoData)
2922 struct DeviceInfoSet *set = DeviceInfoSet;
2923 struct InterfaceInfo *info;
2924 DWORD bytesNeeded = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath[1]);
2925 BOOL ret = FALSE;
2927 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet,
2928 DeviceInterfaceData, DeviceInterfaceDetailData,
2929 DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
2931 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2932 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2934 SetLastError(ERROR_INVALID_HANDLE);
2935 return FALSE;
2937 if (!DeviceInterfaceData ||
2938 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2939 !DeviceInterfaceData->Reserved)
2941 SetLastError(ERROR_INVALID_PARAMETER);
2942 return FALSE;
2944 if (DeviceInterfaceDetailData &&
2945 DeviceInterfaceDetailData->cbSize != sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A))
2947 SetLastError(ERROR_INVALID_USER_BUFFER);
2948 return FALSE;
2950 if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
2952 SetLastError(ERROR_INVALID_USER_BUFFER);
2953 return FALSE;
2955 info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2956 if (info->symbolicLink)
2957 bytesNeeded += WideCharToMultiByte(CP_ACP, 0, info->symbolicLink, -1,
2958 NULL, 0, NULL, NULL);
2959 if (DeviceInterfaceDetailDataSize >= bytesNeeded)
2961 if (info->symbolicLink)
2962 WideCharToMultiByte(CP_ACP, 0, info->symbolicLink, -1,
2963 DeviceInterfaceDetailData->DevicePath,
2964 DeviceInterfaceDetailDataSize -
2965 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath),
2966 NULL, NULL);
2967 else
2968 DeviceInterfaceDetailData->DevicePath[0] = '\0';
2969 if (DeviceInfoData && DeviceInfoData->cbSize == sizeof(SP_DEVINFO_DATA))
2970 *DeviceInfoData = *info->device;
2971 ret = TRUE;
2973 else
2975 if (RequiredSize)
2976 *RequiredSize = bytesNeeded;
2977 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2979 return ret;
2982 /***********************************************************************
2983 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2985 BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(
2986 HDEVINFO DeviceInfoSet,
2987 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2988 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData,
2989 DWORD DeviceInterfaceDetailDataSize,
2990 PDWORD RequiredSize,
2991 PSP_DEVINFO_DATA DeviceInfoData)
2993 struct DeviceInfoSet *set = DeviceInfoSet;
2994 struct InterfaceInfo *info;
2995 DWORD bytesNeeded = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath)
2996 + sizeof(WCHAR); /* include NULL terminator */
2997 BOOL ret = FALSE;
2999 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet,
3000 DeviceInterfaceData, DeviceInterfaceDetailData,
3001 DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
3003 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
3004 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3006 SetLastError(ERROR_INVALID_HANDLE);
3007 return FALSE;
3009 if (!DeviceInterfaceData ||
3010 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
3011 !DeviceInterfaceData->Reserved)
3013 SetLastError(ERROR_INVALID_PARAMETER);
3014 return FALSE;
3016 if (DeviceInterfaceDetailData && (DeviceInterfaceDetailData->cbSize <
3017 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR) ||
3018 DeviceInterfaceDetailData->cbSize > sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W)))
3020 SetLastError(ERROR_INVALID_USER_BUFFER);
3021 return FALSE;
3023 if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
3025 SetLastError(ERROR_INVALID_USER_BUFFER);
3026 return FALSE;
3028 info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
3029 if (info->symbolicLink)
3030 bytesNeeded += sizeof(WCHAR)*lstrlenW(info->symbolicLink);
3031 if (DeviceInterfaceDetailDataSize >= bytesNeeded)
3033 if (info->symbolicLink)
3034 lstrcpyW(DeviceInterfaceDetailData->DevicePath, info->symbolicLink);
3035 else
3036 DeviceInterfaceDetailData->DevicePath[0] = '\0';
3037 if (DeviceInfoData && DeviceInfoData->cbSize == sizeof(SP_DEVINFO_DATA))
3038 *DeviceInfoData = *info->device;
3039 ret = TRUE;
3041 else
3043 if (RequiredSize)
3044 *RequiredSize = bytesNeeded;
3045 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3047 return ret;
3050 struct PropertyMapEntry
3052 DWORD regType;
3053 LPCSTR nameA;
3054 LPCWSTR nameW;
3057 static const struct PropertyMapEntry PropertyMap[] = {
3058 { REG_SZ, "DeviceDesc", DeviceDesc },
3059 { REG_MULTI_SZ, "HardwareId", HardwareId },
3060 { REG_MULTI_SZ, "CompatibleIDs", CompatibleIDs },
3061 { 0, NULL, NULL }, /* SPDRP_UNUSED0 */
3062 { REG_SZ, "Service", Service },
3063 { 0, NULL, NULL }, /* SPDRP_UNUSED1 */
3064 { 0, NULL, NULL }, /* SPDRP_UNUSED2 */
3065 { REG_SZ, "Class", Class },
3066 { REG_SZ, "ClassGUID", ClassGUID },
3067 { REG_SZ, "Driver", Driver },
3068 { REG_DWORD, "ConfigFlags", ConfigFlags },
3069 { REG_SZ, "Mfg", Mfg },
3070 { REG_SZ, "FriendlyName", FriendlyName },
3071 { REG_SZ, "LocationInformation", LocationInformation },
3072 { 0, NULL, NULL }, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3073 { REG_DWORD, "Capabilities", Capabilities },
3074 { REG_DWORD, "UINumber", UINumber },
3075 { REG_MULTI_SZ, "UpperFilters", UpperFilters },
3076 { REG_MULTI_SZ, "LowerFilters", LowerFilters },
3079 /***********************************************************************
3080 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3082 BOOL WINAPI SetupDiGetDeviceRegistryPropertyA(
3083 HDEVINFO DeviceInfoSet,
3084 PSP_DEVINFO_DATA DeviceInfoData,
3085 DWORD Property,
3086 PDWORD PropertyRegDataType,
3087 PBYTE PropertyBuffer,
3088 DWORD PropertyBufferSize,
3089 PDWORD RequiredSize)
3091 BOOL ret = FALSE;
3092 struct DeviceInfoSet *set = DeviceInfoSet;
3093 struct DeviceInfo *devInfo;
3095 TRACE("%04x %p %d %p %p %d %p\n", (DWORD)DeviceInfoSet, DeviceInfoData,
3096 Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize,
3097 RequiredSize);
3099 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3101 SetLastError(ERROR_INVALID_HANDLE);
3102 return FALSE;
3104 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3106 SetLastError(ERROR_INVALID_HANDLE);
3107 return FALSE;
3109 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3110 || !DeviceInfoData->Reserved)
3112 SetLastError(ERROR_INVALID_PARAMETER);
3113 return FALSE;
3115 if (PropertyBufferSize && PropertyBuffer == NULL)
3117 SetLastError(ERROR_INVALID_DATA);
3118 return FALSE;
3120 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3121 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3122 && PropertyMap[Property].nameA)
3124 DWORD size = PropertyBufferSize;
3125 LONG l = RegQueryValueExA(devInfo->key, PropertyMap[Property].nameA,
3126 NULL, PropertyRegDataType, PropertyBuffer, &size);
3128 if (l == ERROR_MORE_DATA || !PropertyBufferSize)
3129 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3130 else if (!l)
3131 ret = TRUE;
3132 else
3133 SetLastError(l);
3134 if (RequiredSize)
3135 *RequiredSize = size;
3137 return ret;
3140 /***********************************************************************
3141 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3143 BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(
3144 HDEVINFO DeviceInfoSet,
3145 PSP_DEVINFO_DATA DeviceInfoData,
3146 DWORD Property,
3147 PDWORD PropertyRegDataType,
3148 PBYTE PropertyBuffer,
3149 DWORD PropertyBufferSize,
3150 PDWORD RequiredSize)
3152 BOOL ret = FALSE;
3153 struct DeviceInfoSet *set = DeviceInfoSet;
3154 struct DeviceInfo *devInfo;
3156 TRACE("%04x %p %d %p %p %d %p\n", (DWORD)DeviceInfoSet, DeviceInfoData,
3157 Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize,
3158 RequiredSize);
3160 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3162 SetLastError(ERROR_INVALID_HANDLE);
3163 return FALSE;
3165 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3167 SetLastError(ERROR_INVALID_HANDLE);
3168 return FALSE;
3170 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3171 || !DeviceInfoData->Reserved)
3173 SetLastError(ERROR_INVALID_PARAMETER);
3174 return FALSE;
3176 if (PropertyBufferSize && PropertyBuffer == NULL)
3178 SetLastError(ERROR_INVALID_DATA);
3179 return FALSE;
3181 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3182 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3183 && PropertyMap[Property].nameW)
3185 DWORD size = PropertyBufferSize;
3186 LONG l = RegQueryValueExW(devInfo->key, PropertyMap[Property].nameW,
3187 NULL, PropertyRegDataType, PropertyBuffer, &size);
3189 if (l == ERROR_MORE_DATA || !PropertyBufferSize)
3190 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3191 else if (!l)
3192 ret = TRUE;
3193 else
3194 SetLastError(l);
3195 if (RequiredSize)
3196 *RequiredSize = size;
3198 return ret;
3201 /***********************************************************************
3202 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3204 BOOL WINAPI SetupDiSetDeviceRegistryPropertyA(
3205 HDEVINFO DeviceInfoSet,
3206 PSP_DEVINFO_DATA DeviceInfoData,
3207 DWORD Property,
3208 const BYTE *PropertyBuffer,
3209 DWORD PropertyBufferSize)
3211 BOOL ret = FALSE;
3212 struct DeviceInfoSet *set = DeviceInfoSet;
3213 struct DeviceInfo *devInfo;
3215 TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property,
3216 PropertyBuffer, PropertyBufferSize);
3218 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3220 SetLastError(ERROR_INVALID_HANDLE);
3221 return FALSE;
3223 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3225 SetLastError(ERROR_INVALID_HANDLE);
3226 return FALSE;
3228 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3229 || !DeviceInfoData->Reserved)
3231 SetLastError(ERROR_INVALID_PARAMETER);
3232 return FALSE;
3234 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3235 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3236 && PropertyMap[Property].nameA)
3238 LONG l = RegSetValueExA(devInfo->key, PropertyMap[Property].nameA, 0,
3239 PropertyMap[Property].regType, PropertyBuffer,
3240 PropertyBufferSize);
3241 if (!l)
3242 ret = TRUE;
3243 else
3244 SetLastError(l);
3246 return ret;
3249 /***********************************************************************
3250 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3252 BOOL WINAPI SetupDiSetDeviceRegistryPropertyW(
3253 HDEVINFO DeviceInfoSet,
3254 PSP_DEVINFO_DATA DeviceInfoData,
3255 DWORD Property,
3256 const BYTE *PropertyBuffer,
3257 DWORD PropertyBufferSize)
3259 BOOL ret = FALSE;
3260 struct DeviceInfoSet *set = DeviceInfoSet;
3261 struct DeviceInfo *devInfo;
3263 TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property,
3264 PropertyBuffer, PropertyBufferSize);
3266 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3268 SetLastError(ERROR_INVALID_HANDLE);
3269 return FALSE;
3271 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3273 SetLastError(ERROR_INVALID_HANDLE);
3274 return FALSE;
3276 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3277 || !DeviceInfoData->Reserved)
3279 SetLastError(ERROR_INVALID_PARAMETER);
3280 return FALSE;
3282 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3283 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3284 && PropertyMap[Property].nameW)
3286 LONG l = RegSetValueExW(devInfo->key, PropertyMap[Property].nameW, 0,
3287 PropertyMap[Property].regType, PropertyBuffer,
3288 PropertyBufferSize);
3289 if (!l)
3290 ret = TRUE;
3291 else
3292 SetLastError(l);
3294 return ret;
3297 /***********************************************************************
3298 * SetupDiInstallClassA (SETUPAPI.@)
3300 BOOL WINAPI SetupDiInstallClassA(
3301 HWND hwndParent,
3302 PCSTR InfFileName,
3303 DWORD Flags,
3304 HSPFILEQ FileQueue)
3306 UNICODE_STRING FileNameW;
3307 BOOL Result;
3309 if (!InfFileName)
3311 SetLastError(ERROR_INVALID_PARAMETER);
3312 return FALSE;
3314 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW, InfFileName))
3316 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
3317 return FALSE;
3320 Result = SetupDiInstallClassW(hwndParent, FileNameW.Buffer, Flags, FileQueue);
3322 RtlFreeUnicodeString(&FileNameW);
3324 return Result;
3327 static HKEY CreateClassKey(HINF hInf)
3329 static const WCHAR slash[] = { '\\',0 };
3330 WCHAR FullBuffer[MAX_PATH];
3331 WCHAR Buffer[MAX_PATH];
3332 DWORD RequiredSize;
3333 HKEY hClassKey;
3335 if (!SetupGetLineTextW(NULL,
3336 hInf,
3337 Version,
3338 ClassGUID,
3339 Buffer,
3340 MAX_PATH,
3341 &RequiredSize))
3343 return INVALID_HANDLE_VALUE;
3346 lstrcpyW(FullBuffer, ControlClass);
3347 lstrcatW(FullBuffer, slash);
3348 lstrcatW(FullBuffer, Buffer);
3350 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3351 FullBuffer,
3353 KEY_ALL_ACCESS,
3354 &hClassKey))
3356 if (!SetupGetLineTextW(NULL,
3357 hInf,
3358 Version,
3359 Class,
3360 Buffer,
3361 MAX_PATH,
3362 &RequiredSize))
3364 return INVALID_HANDLE_VALUE;
3367 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,
3368 FullBuffer,
3370 NULL,
3371 REG_OPTION_NON_VOLATILE,
3372 KEY_ALL_ACCESS,
3373 NULL,
3374 &hClassKey,
3375 NULL))
3377 return INVALID_HANDLE_VALUE;
3382 if (RegSetValueExW(hClassKey,
3383 Class,
3385 REG_SZ,
3386 (LPBYTE)Buffer,
3387 RequiredSize * sizeof(WCHAR)))
3389 RegCloseKey(hClassKey);
3390 RegDeleteKeyW(HKEY_LOCAL_MACHINE,
3391 FullBuffer);
3392 return INVALID_HANDLE_VALUE;
3395 return hClassKey;
3398 /***********************************************************************
3399 * SetupDiInstallClassW (SETUPAPI.@)
3401 BOOL WINAPI SetupDiInstallClassW(
3402 HWND hwndParent,
3403 PCWSTR InfFileName,
3404 DWORD Flags,
3405 HSPFILEQ FileQueue)
3407 WCHAR SectionName[MAX_PATH];
3408 DWORD SectionNameLength = 0;
3409 HINF hInf;
3410 BOOL bFileQueueCreated = FALSE;
3411 HKEY hClassKey;
3414 FIXME("\n");
3416 if (!InfFileName)
3418 SetLastError(ERROR_INVALID_PARAMETER);
3419 return FALSE;
3421 if ((Flags & DI_NOVCP) && (FileQueue == NULL || FileQueue == INVALID_HANDLE_VALUE))
3423 SetLastError(ERROR_INVALID_PARAMETER);
3424 return FALSE;
3427 /* Open the .inf file */
3428 hInf = SetupOpenInfFileW(InfFileName,
3429 NULL,
3430 INF_STYLE_WIN4,
3431 NULL);
3432 if (hInf == INVALID_HANDLE_VALUE)
3435 return FALSE;
3438 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3439 hClassKey = CreateClassKey(hInf);
3440 if (hClassKey == INVALID_HANDLE_VALUE)
3442 SetupCloseInfFile(hInf);
3443 return FALSE;
3447 /* Try to append a layout file */
3448 SetupOpenAppendInfFileW(NULL, hInf, NULL);
3450 /* Retrieve the actual section name */
3451 SetupDiGetActualSectionToInstallW(hInf,
3452 ClassInstall32,
3453 SectionName,
3454 MAX_PATH,
3455 &SectionNameLength,
3456 NULL);
3458 #if 0
3459 if (!(Flags & DI_NOVCP))
3461 FileQueue = SetupOpenFileQueue();
3462 if (FileQueue == INVALID_HANDLE_VALUE)
3464 SetupCloseInfFile(hInf);
3465 return FALSE;
3468 bFileQueueCreated = TRUE;
3471 #endif
3473 SetupInstallFromInfSectionW(NULL,
3474 hInf,
3475 SectionName,
3476 SPINST_COPYINF | SPINST_FILES | SPINST_REGISTRY,
3477 hClassKey,
3478 NULL,
3480 NULL,
3481 NULL,
3482 INVALID_HANDLE_VALUE,
3483 NULL);
3485 /* FIXME: More code! */
3487 if (bFileQueueCreated)
3488 SetupCloseFileQueue(FileQueue);
3490 SetupCloseInfFile(hInf);
3492 return TRUE;
3496 /***********************************************************************
3497 * SetupDiOpenClassRegKey (SETUPAPI.@)
3499 HKEY WINAPI SetupDiOpenClassRegKey(
3500 const GUID* ClassGuid,
3501 REGSAM samDesired)
3503 return SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
3504 DIOCR_INSTALLER, NULL, NULL);
3508 /***********************************************************************
3509 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3511 HKEY WINAPI SetupDiOpenClassRegKeyExA(
3512 const GUID* ClassGuid,
3513 REGSAM samDesired,
3514 DWORD Flags,
3515 PCSTR MachineName,
3516 PVOID Reserved)
3518 PWSTR MachineNameW = NULL;
3519 HKEY hKey;
3521 TRACE("\n");
3523 if (MachineName)
3525 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
3526 if (MachineNameW == NULL)
3527 return INVALID_HANDLE_VALUE;
3530 hKey = SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
3531 Flags, MachineNameW, Reserved);
3533 MyFree(MachineNameW);
3535 return hKey;
3539 /***********************************************************************
3540 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3542 HKEY WINAPI SetupDiOpenClassRegKeyExW(
3543 const GUID* ClassGuid,
3544 REGSAM samDesired,
3545 DWORD Flags,
3546 PCWSTR MachineName,
3547 PVOID Reserved)
3549 HKEY hClassesKey;
3550 HKEY key;
3551 LPCWSTR lpKeyName;
3552 LONG l;
3554 if (MachineName && *MachineName)
3556 FIXME("Remote access not supported yet!\n");
3557 return INVALID_HANDLE_VALUE;
3560 if (Flags == DIOCR_INSTALLER)
3562 lpKeyName = ControlClass;
3564 else if (Flags == DIOCR_INTERFACE)
3566 lpKeyName = DeviceClasses;
3568 else
3570 ERR("Invalid Flags parameter!\n");
3571 SetLastError(ERROR_INVALID_PARAMETER);
3572 return INVALID_HANDLE_VALUE;
3575 if (!ClassGuid)
3577 if ((l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3578 lpKeyName,
3580 samDesired,
3581 &hClassesKey)))
3583 SetLastError(l);
3584 hClassesKey = INVALID_HANDLE_VALUE;
3586 key = hClassesKey;
3588 else
3590 WCHAR bracedGuidString[39];
3592 SETUPDI_GuidToString(ClassGuid, bracedGuidString);
3594 if (!(l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3595 lpKeyName,
3597 samDesired,
3598 &hClassesKey)))
3600 if ((l = RegOpenKeyExW(hClassesKey,
3601 bracedGuidString,
3603 samDesired,
3604 &key)))
3606 SetLastError(l);
3607 key = INVALID_HANDLE_VALUE;
3609 RegCloseKey(hClassesKey);
3611 else
3613 SetLastError(l);
3614 key = INVALID_HANDLE_VALUE;
3617 return key;
3620 /***********************************************************************
3621 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3623 BOOL WINAPI SetupDiOpenDeviceInterfaceW(
3624 HDEVINFO DeviceInfoSet,
3625 PCWSTR DevicePath,
3626 DWORD OpenFlags,
3627 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
3629 FIXME("%p %s %08x %p\n",
3630 DeviceInfoSet, debugstr_w(DevicePath), OpenFlags, DeviceInterfaceData);
3631 return FALSE;
3634 /***********************************************************************
3635 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3637 BOOL WINAPI SetupDiOpenDeviceInterfaceA(
3638 HDEVINFO DeviceInfoSet,
3639 PCSTR DevicePath,
3640 DWORD OpenFlags,
3641 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
3643 FIXME("%p %s %08x %p\n", DeviceInfoSet,
3644 debugstr_a(DevicePath), OpenFlags, DeviceInterfaceData);
3645 return FALSE;
3648 /***********************************************************************
3649 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3651 BOOL WINAPI SetupDiSetClassInstallParamsA(
3652 HDEVINFO DeviceInfoSet,
3653 PSP_DEVINFO_DATA DeviceInfoData,
3654 PSP_CLASSINSTALL_HEADER ClassInstallParams,
3655 DWORD ClassInstallParamsSize)
3657 FIXME("%p %p %x %u\n",DeviceInfoSet, DeviceInfoData,
3658 ClassInstallParams->InstallFunction, ClassInstallParamsSize);
3659 return FALSE;
3662 /***********************************************************************
3663 * SetupDiSetClassInstallParamsW (SETUPAPI.@)
3665 BOOL WINAPI SetupDiSetClassInstallParamsW(
3666 HDEVINFO DeviceInfoSet,
3667 PSP_DEVINFO_DATA DeviceInfoData,
3668 PSP_CLASSINSTALL_HEADER ClassInstallParams,
3669 DWORD ClassInstallParamsSize)
3671 FIXME("%p %p %x %u\n",DeviceInfoSet, DeviceInfoData,
3672 ClassInstallParams->InstallFunction, ClassInstallParamsSize);
3673 return FALSE;
3676 /***********************************************************************
3677 * SetupDiCallClassInstaller (SETUPAPI.@)
3679 BOOL WINAPI SetupDiCallClassInstaller(
3680 DI_FUNCTION InstallFunction,
3681 HDEVINFO DeviceInfoSet,
3682 PSP_DEVINFO_DATA DeviceInfoData)
3684 FIXME("%d %p %p\n", InstallFunction, DeviceInfoSet, DeviceInfoData);
3685 return FALSE;
3688 /***********************************************************************
3689 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
3691 BOOL WINAPI SetupDiGetDeviceInstallParamsW(
3692 HDEVINFO DeviceInfoSet,
3693 PSP_DEVINFO_DATA DeviceInfoData,
3694 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
3696 FIXME("%p %p %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3697 return FALSE;
3700 /***********************************************************************
3701 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3703 BOOL WINAPI SetupDiGetDeviceInstallParamsA(
3704 HDEVINFO DeviceInfoSet,
3705 PSP_DEVINFO_DATA DeviceInfoData,
3706 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams)
3708 FIXME("%p %p %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3709 return FALSE;
3712 /***********************************************************************
3713 * SetupDiSetDeviceInstallParamsA (SETUPAPI.@)
3715 BOOL WINAPI SetupDiSetDeviceInstallParamsA(
3716 HDEVINFO DeviceInfoSet,
3717 PSP_DEVINFO_DATA DeviceInfoData,
3718 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams)
3720 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3722 return TRUE;
3725 /***********************************************************************
3726 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
3728 BOOL WINAPI SetupDiSetDeviceInstallParamsW(
3729 HDEVINFO DeviceInfoSet,
3730 PSP_DEVINFO_DATA DeviceInfoData,
3731 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
3733 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3735 return TRUE;
3738 static HKEY SETUPDI_OpenDevKey(struct DeviceInfo *devInfo, REGSAM samDesired)
3740 HKEY enumKey, key = INVALID_HANDLE_VALUE;
3741 LONG l;
3743 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
3744 NULL, &enumKey, NULL);
3745 if (!l)
3747 RegOpenKeyExW(enumKey, devInfo->instanceId, 0, samDesired, &key);
3748 RegCloseKey(enumKey);
3750 return key;
3753 static HKEY SETUPDI_OpenDrvKey(struct DeviceInfo *devInfo, REGSAM samDesired)
3755 static const WCHAR slash[] = { '\\',0 };
3756 WCHAR classKeyPath[MAX_PATH];
3757 HKEY classKey, key = INVALID_HANDLE_VALUE;
3758 LONG l;
3760 lstrcpyW(classKeyPath, ControlClass);
3761 lstrcatW(classKeyPath, slash);
3762 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
3763 classKeyPath + lstrlenW(classKeyPath));
3764 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
3765 KEY_ALL_ACCESS, NULL, &classKey, NULL);
3766 if (!l)
3768 static const WCHAR fmt[] = { '%','0','4','u',0 };
3769 WCHAR devId[10];
3771 sprintfW(devId, fmt, devInfo->devId);
3772 l = RegOpenKeyExW(classKey, devId, 0, samDesired, &key);
3773 RegCloseKey(classKey);
3774 if (l)
3776 SetLastError(ERROR_KEY_DOES_NOT_EXIST);
3777 return INVALID_HANDLE_VALUE;
3780 return key;
3783 /***********************************************************************
3784 * SetupDiOpenDevRegKey (SETUPAPI.@)
3786 HKEY WINAPI SetupDiOpenDevRegKey(
3787 HDEVINFO DeviceInfoSet,
3788 PSP_DEVINFO_DATA DeviceInfoData,
3789 DWORD Scope,
3790 DWORD HwProfile,
3791 DWORD KeyType,
3792 REGSAM samDesired)
3794 struct DeviceInfoSet *set = DeviceInfoSet;
3795 struct DeviceInfo *devInfo;
3796 HKEY key = INVALID_HANDLE_VALUE;
3798 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet, DeviceInfoData,
3799 Scope, HwProfile, KeyType, samDesired);
3801 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3803 SetLastError(ERROR_INVALID_HANDLE);
3804 return INVALID_HANDLE_VALUE;
3806 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3808 SetLastError(ERROR_INVALID_HANDLE);
3809 return INVALID_HANDLE_VALUE;
3811 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3812 || !DeviceInfoData->Reserved)
3814 SetLastError(ERROR_INVALID_PARAMETER);
3815 return INVALID_HANDLE_VALUE;
3817 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
3819 SetLastError(ERROR_INVALID_FLAGS);
3820 return INVALID_HANDLE_VALUE;
3822 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV)
3824 SetLastError(ERROR_INVALID_FLAGS);
3825 return INVALID_HANDLE_VALUE;
3827 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3828 if (devInfo->set != set)
3830 SetLastError(ERROR_INVALID_PARAMETER);
3831 return INVALID_HANDLE_VALUE;
3833 if (devInfo->phantom)
3835 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
3836 return INVALID_HANDLE_VALUE;
3838 if (Scope != DICS_FLAG_GLOBAL)
3839 FIXME("unimplemented for scope %d\n", Scope);
3840 switch (KeyType)
3842 case DIREG_DEV:
3843 key = SETUPDI_OpenDevKey(devInfo, samDesired);
3844 break;
3845 case DIREG_DRV:
3846 key = SETUPDI_OpenDrvKey(devInfo, samDesired);
3847 break;
3848 default:
3849 WARN("unknown KeyType %d\n", KeyType);
3851 return key;
3854 static BOOL SETUPDI_DeleteDevKey(struct DeviceInfo *devInfo)
3856 HKEY enumKey;
3857 BOOL ret = FALSE;
3858 LONG l;
3860 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
3861 NULL, &enumKey, NULL);
3862 if (!l)
3864 ret = RegDeleteTreeW(enumKey, devInfo->instanceId);
3865 RegCloseKey(enumKey);
3867 else
3868 SetLastError(l);
3869 return ret;
3872 static BOOL SETUPDI_DeleteDrvKey(struct DeviceInfo *devInfo)
3874 static const WCHAR slash[] = { '\\',0 };
3875 WCHAR classKeyPath[MAX_PATH];
3876 HKEY classKey;
3877 LONG l;
3878 BOOL ret = FALSE;
3880 lstrcpyW(classKeyPath, ControlClass);
3881 lstrcatW(classKeyPath, slash);
3882 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
3883 classKeyPath + lstrlenW(classKeyPath));
3884 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
3885 KEY_ALL_ACCESS, NULL, &classKey, NULL);
3886 if (!l)
3888 static const WCHAR fmt[] = { '%','0','4','u',0 };
3889 WCHAR devId[10];
3891 sprintfW(devId, fmt, devInfo->devId);
3892 ret = RegDeleteTreeW(classKey, devId);
3893 RegCloseKey(classKey);
3895 else
3896 SetLastError(l);
3897 return ret;
3900 /***********************************************************************
3901 * SetupDiDeleteDevRegKey (SETUPAPI.@)
3903 BOOL WINAPI SetupDiDeleteDevRegKey(
3904 HDEVINFO DeviceInfoSet,
3905 PSP_DEVINFO_DATA DeviceInfoData,
3906 DWORD Scope,
3907 DWORD HwProfile,
3908 DWORD KeyType)
3910 struct DeviceInfoSet *set = DeviceInfoSet;
3911 struct DeviceInfo *devInfo;
3912 BOOL ret = FALSE;
3914 TRACE("%p %p %d %d %d\n", DeviceInfoSet, DeviceInfoData, Scope, HwProfile,
3915 KeyType);
3917 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3919 SetLastError(ERROR_INVALID_HANDLE);
3920 return FALSE;
3922 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3924 SetLastError(ERROR_INVALID_HANDLE);
3925 return FALSE;
3927 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3928 || !DeviceInfoData->Reserved)
3930 SetLastError(ERROR_INVALID_PARAMETER);
3931 return FALSE;
3933 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
3935 SetLastError(ERROR_INVALID_FLAGS);
3936 return FALSE;
3938 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV && KeyType != DIREG_BOTH)
3940 SetLastError(ERROR_INVALID_FLAGS);
3941 return FALSE;
3943 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3944 if (devInfo->set != set)
3946 SetLastError(ERROR_INVALID_PARAMETER);
3947 return FALSE;
3949 if (devInfo->phantom)
3951 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
3952 return FALSE;
3954 if (Scope != DICS_FLAG_GLOBAL)
3955 FIXME("unimplemented for scope %d\n", Scope);
3956 switch (KeyType)
3958 case DIREG_DEV:
3959 ret = SETUPDI_DeleteDevKey(devInfo);
3960 break;
3961 case DIREG_DRV:
3962 ret = SETUPDI_DeleteDrvKey(devInfo);
3963 break;
3964 case DIREG_BOTH:
3965 ret = SETUPDI_DeleteDevKey(devInfo);
3966 if (ret)
3967 ret = SETUPDI_DeleteDrvKey(devInfo);
3968 break;
3969 default:
3970 WARN("unknown KeyType %d\n", KeyType);
3972 return ret;
3975 /***********************************************************************
3976 * CM_Get_Device_IDA (SETUPAPI.@)
3978 CONFIGRET WINAPI CM_Get_Device_IDA( DEVINST dnDevInst, PSTR Buffer,
3979 ULONG BufferLen, ULONG ulFlags)
3981 struct DeviceInfo *devInfo = GlobalLock((HANDLE)dnDevInst);
3983 TRACE("%x->%p, %p, %u %u\n", dnDevInst, devInfo, Buffer, BufferLen, ulFlags);
3985 if (!devInfo)
3986 return CR_NO_SUCH_DEVINST;
3988 WideCharToMultiByte(CP_ACP, 0, devInfo->instanceId, -1, Buffer, BufferLen, 0, 0);
3989 TRACE("Returning %s\n", debugstr_a(Buffer));
3990 return CR_SUCCESS;
3993 /***********************************************************************
3994 * CM_Get_Device_IDW (SETUPAPI.@)
3996 CONFIGRET WINAPI CM_Get_Device_IDW( DEVINST dnDevInst, LPWSTR Buffer,
3997 ULONG BufferLen, ULONG ulFlags)
3999 struct DeviceInfo *devInfo = GlobalLock((HANDLE)dnDevInst);
4001 TRACE("%x->%p, %p, %u %u\n", dnDevInst, devInfo, Buffer, BufferLen, ulFlags);
4003 if (!devInfo)
4005 WARN("dev instance %d not found!\n", dnDevInst);
4006 return CR_NO_SUCH_DEVINST;
4009 lstrcpynW(Buffer, devInfo->instanceId, BufferLen);
4010 TRACE("Returning %s\n", debugstr_w(Buffer));
4011 GlobalUnlock((HANDLE)dnDevInst);
4012 return CR_SUCCESS;
4017 /***********************************************************************
4018 * CM_Get_Device_ID_Size (SETUPAPI.@)
4020 CONFIGRET WINAPI CM_Get_Device_ID_Size( PULONG pulLen, DEVINST dnDevInst,
4021 ULONG ulFlags)
4023 struct DeviceInfo *ppdevInfo = GlobalLock((HANDLE)dnDevInst);
4025 TRACE("%x->%p, %p, %u\n", dnDevInst, ppdevInfo, pulLen, ulFlags);
4027 if (!ppdevInfo)
4029 WARN("dev instance %d not found!\n", dnDevInst);
4030 return CR_NO_SUCH_DEVINST;
4033 *pulLen = lstrlenW(ppdevInfo->instanceId);
4034 GlobalUnlock((HANDLE)dnDevInst);
4035 return CR_SUCCESS;
4038 /***********************************************************************
4039 * SetupDiGetINFClassA (SETUPAPI.@)
4041 BOOL WINAPI SetupDiGetINFClassA(PCSTR inf, LPGUID class_guid, PSTR class_name,
4042 DWORD size, PDWORD required_size)
4044 BOOL retval;
4045 DWORD required_sizeA, required_sizeW;
4046 PWSTR class_nameW = NULL;
4047 UNICODE_STRING infW;
4049 if (inf)
4051 if (!RtlCreateUnicodeStringFromAsciiz(&infW, inf))
4053 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
4054 return FALSE;
4057 else
4058 infW.Buffer = NULL;
4060 if (class_name && size)
4062 if (!(class_nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR))))
4064 RtlFreeUnicodeString(&infW);
4065 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
4066 return FALSE;
4070 retval = SetupDiGetINFClassW(infW.Buffer, class_guid, class_nameW, size, &required_sizeW);
4072 if (retval)
4074 required_sizeA = WideCharToMultiByte( CP_ACP, 0, class_nameW, required_sizeW,
4075 class_name, size, NULL, NULL);
4077 if(required_size) *required_size = required_sizeA;
4079 else
4080 if(required_size) *required_size = required_sizeW;
4082 HeapFree(GetProcessHeap(), 0, class_nameW);
4083 RtlFreeUnicodeString(&infW);
4084 return retval;
4087 /***********************************************************************
4088 * SetupDiGetINFClassW (SETUPAPI.@)
4090 BOOL WINAPI SetupDiGetINFClassW(PCWSTR inf, LPGUID class_guid, PWSTR class_name,
4091 DWORD size, PDWORD required_size)
4093 BOOL have_guid, have_name;
4094 DWORD dret;
4095 WCHAR buffer[MAX_PATH];
4097 if (!inf)
4099 SetLastError(ERROR_INVALID_PARAMETER);
4100 return FALSE;
4103 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(inf))
4105 FIXME("%s not found. Searching via DevicePath not implemented\n", debugstr_w(inf));
4106 SetLastError(ERROR_FILE_NOT_FOUND);
4107 return FALSE;
4110 if (!class_guid || !class_name || !size)
4112 SetLastError(ERROR_INVALID_PARAMETER);
4113 return FALSE;
4116 if (!GetPrivateProfileStringW(Version, Signature, NULL, buffer, MAX_PATH, inf))
4117 return FALSE;
4119 if (lstrcmpiW(buffer, Chicago) && lstrcmpiW(buffer, WindowsNT))
4120 return FALSE;
4122 buffer[0] = '\0';
4123 have_guid = 0 < GetPrivateProfileStringW(Version, ClassGUID, NULL, buffer, MAX_PATH, inf);
4124 if (have_guid)
4126 buffer[lstrlenW(buffer)-1] = 0;
4127 if (RPC_S_OK != UuidFromStringW(buffer + 1, class_guid))
4129 FIXME("failed to convert \"%s\" into a guid\n", debugstr_w(buffer));
4130 SetLastError(ERROR_INVALID_PARAMETER);
4131 return FALSE;
4135 buffer[0] = '\0';
4136 dret = GetPrivateProfileStringW(Version, Class, NULL, buffer, MAX_PATH, inf);
4137 have_name = 0 < dret;
4139 if (dret >= MAX_PATH -1) FIXME("buffer might be too small\n");
4140 if (have_guid && !have_name) FIXME("class name lookup via guid not implemented\n");
4142 if (have_name)
4144 if (dret < size) lstrcpyW(class_name, buffer);
4145 else
4147 SetLastError(ERROR_INSUFFICIENT_BUFFER);
4148 have_name = FALSE;
4152 if (required_size) *required_size = dret + ((dret) ? 1 : 0);
4154 return (have_guid || have_name);
4157 /***********************************************************************
4158 * SetupDiGetDevicePropertyW (SETUPAPI.@)
4160 BOOL WINAPI SetupDiGetDevicePropertyW(HDEVINFO info_set, PSP_DEVINFO_DATA info_data,
4161 const DEVPROPKEY *prop_key, DEVPROPTYPE *prop_type, BYTE *prop_buff,
4162 DWORD prop_buff_size, DWORD *required_size, DWORD flags)
4164 FIXME("%p, %p, %p, %p, %p, %d, %p, 0x%08x stub\n", info_set, info_data, prop_key,
4165 prop_type, prop_buff, prop_buff_size, required_size, flags);
4167 SetLastError(ERROR_NOT_FOUND);
4168 return FALSE;