wined3d: Store sub-resource map counts in the sub-resource structure.
[wine.git] / dlls / setupapi / devinst.c
blob2669544bd9f8c18635e22f403111b7834015d9e7
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 = 40;
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 = 256 * sizeof(WCHAR);
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 emtpy 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 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1566 BOOL WINAPI SetupDiEnumDeviceInfo(
1567 HDEVINFO devinfo,
1568 DWORD index,
1569 PSP_DEVINFO_DATA info)
1571 BOOL ret = FALSE;
1573 TRACE("%p %d %p\n", devinfo, index, info);
1575 if(info==NULL)
1577 SetLastError(ERROR_INVALID_PARAMETER);
1578 return FALSE;
1580 if (devinfo && devinfo != INVALID_HANDLE_VALUE)
1582 struct DeviceInfoSet *list = devinfo;
1583 if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC)
1585 if (index < list->cDevices)
1587 if (info->cbSize == sizeof(SP_DEVINFO_DATA))
1589 struct DeviceInstance *devInst;
1590 DWORD i = 0;
1592 LIST_FOR_EACH_ENTRY(devInst, &list->devices,
1593 struct DeviceInstance, entry)
1595 if (i++ == index)
1597 *info = devInst->data;
1598 break;
1601 ret = TRUE;
1603 else
1604 SetLastError(ERROR_INVALID_USER_BUFFER);
1606 else
1607 SetLastError(ERROR_NO_MORE_ITEMS);
1609 else
1610 SetLastError(ERROR_INVALID_HANDLE);
1612 else
1613 SetLastError(ERROR_INVALID_HANDLE);
1614 return ret;
1617 /***********************************************************************
1618 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1620 BOOL WINAPI SetupDiGetDeviceInstanceIdA(
1621 HDEVINFO DeviceInfoSet,
1622 PSP_DEVINFO_DATA DeviceInfoData,
1623 PSTR DeviceInstanceId,
1624 DWORD DeviceInstanceIdSize,
1625 PDWORD RequiredSize)
1627 BOOL ret = FALSE;
1628 DWORD size;
1629 PWSTR instanceId;
1631 TRACE("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId,
1632 DeviceInstanceIdSize, RequiredSize);
1634 SetupDiGetDeviceInstanceIdW(DeviceInfoSet,
1635 DeviceInfoData,
1636 NULL,
1638 &size);
1639 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
1640 return FALSE;
1641 instanceId = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
1642 if (instanceId)
1644 ret = SetupDiGetDeviceInstanceIdW(DeviceInfoSet,
1645 DeviceInfoData,
1646 instanceId,
1647 size,
1648 &size);
1649 if (ret)
1651 int len = WideCharToMultiByte(CP_ACP, 0, instanceId, -1,
1652 DeviceInstanceId,
1653 DeviceInstanceIdSize, NULL, NULL);
1655 if (!len)
1656 ret = FALSE;
1657 else
1659 if (len > DeviceInstanceIdSize)
1661 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1662 ret = FALSE;
1664 if (RequiredSize)
1665 *RequiredSize = len;
1668 HeapFree(GetProcessHeap(), 0, instanceId);
1670 return ret;
1673 /***********************************************************************
1674 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1676 BOOL WINAPI SetupDiGetDeviceInstanceIdW(
1677 HDEVINFO DeviceInfoSet,
1678 PSP_DEVINFO_DATA DeviceInfoData,
1679 PWSTR DeviceInstanceId,
1680 DWORD DeviceInstanceIdSize,
1681 PDWORD RequiredSize)
1683 struct DeviceInfoSet *set = DeviceInfoSet;
1684 struct DeviceInfo *devInfo;
1686 TRACE("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId,
1687 DeviceInstanceIdSize, RequiredSize);
1689 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
1691 SetLastError(ERROR_INVALID_HANDLE);
1692 return FALSE;
1694 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1696 SetLastError(ERROR_INVALID_HANDLE);
1697 return FALSE;
1699 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
1700 || !DeviceInfoData->Reserved)
1702 SetLastError(ERROR_INVALID_PARAMETER);
1703 return FALSE;
1705 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1706 if (devInfo->set != set)
1708 SetLastError(ERROR_INVALID_PARAMETER);
1709 return FALSE;
1711 TRACE("instance ID: %s\n", debugstr_w(devInfo->instanceId));
1712 if (DeviceInstanceIdSize < strlenW(devInfo->instanceId) + 1)
1714 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1715 if (RequiredSize)
1716 *RequiredSize = lstrlenW(devInfo->instanceId) + 1;
1717 return FALSE;
1719 lstrcpyW(DeviceInstanceId, devInfo->instanceId);
1720 if (RequiredSize)
1721 *RequiredSize = lstrlenW(devInfo->instanceId) + 1;
1722 return TRUE;
1725 /***********************************************************************
1726 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1728 BOOL WINAPI SetupDiGetActualSectionToInstallA(
1729 HINF InfHandle,
1730 PCSTR InfSectionName,
1731 PSTR InfSectionWithExt,
1732 DWORD InfSectionWithExtSize,
1733 PDWORD RequiredSize,
1734 PSTR *Extension)
1736 FIXME("\n");
1737 return FALSE;
1740 /***********************************************************************
1741 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
1743 BOOL WINAPI SetupDiGetActualSectionToInstallW(
1744 HINF InfHandle,
1745 PCWSTR InfSectionName,
1746 PWSTR InfSectionWithExt,
1747 DWORD InfSectionWithExtSize,
1748 PDWORD RequiredSize,
1749 PWSTR *Extension)
1751 WCHAR szBuffer[MAX_PATH];
1752 DWORD dwLength;
1753 DWORD dwFullLength;
1754 LONG lLineCount = -1;
1756 lstrcpyW(szBuffer, InfSectionName);
1757 dwLength = lstrlenW(szBuffer);
1759 if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
1761 /* Test section name with '.NTx86' extension */
1762 lstrcpyW(&szBuffer[dwLength], NtPlatformExtension);
1763 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1765 if (lLineCount == -1)
1767 /* Test section name with '.NT' extension */
1768 lstrcpyW(&szBuffer[dwLength], NtExtension);
1769 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1772 else
1774 /* Test section name with '.Win' extension */
1775 lstrcpyW(&szBuffer[dwLength], WinExtension);
1776 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1779 if (lLineCount == -1)
1781 /* Test section name without extension */
1782 szBuffer[dwLength] = 0;
1783 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1786 if (lLineCount == -1)
1788 SetLastError(ERROR_INVALID_PARAMETER);
1789 return FALSE;
1792 dwFullLength = lstrlenW(szBuffer);
1794 if (InfSectionWithExt != NULL && InfSectionWithExtSize != 0)
1796 if (InfSectionWithExtSize < (dwFullLength + 1))
1798 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1799 return FALSE;
1802 lstrcpyW(InfSectionWithExt, szBuffer);
1803 if (Extension != NULL)
1805 *Extension = (dwLength == dwFullLength) ? NULL : &InfSectionWithExt[dwLength];
1809 if (RequiredSize != NULL)
1811 *RequiredSize = dwFullLength + 1;
1814 return TRUE;
1817 /***********************************************************************
1818 * SetupDiGetClassDescriptionA (SETUPAPI.@)
1820 BOOL WINAPI SetupDiGetClassDescriptionA(
1821 const GUID* ClassGuid,
1822 PSTR ClassDescription,
1823 DWORD ClassDescriptionSize,
1824 PDWORD RequiredSize)
1826 return SetupDiGetClassDescriptionExA(ClassGuid, ClassDescription,
1827 ClassDescriptionSize,
1828 RequiredSize, NULL, NULL);
1831 /***********************************************************************
1832 * SetupDiGetClassDescriptionW (SETUPAPI.@)
1834 BOOL WINAPI SetupDiGetClassDescriptionW(
1835 const GUID* ClassGuid,
1836 PWSTR ClassDescription,
1837 DWORD ClassDescriptionSize,
1838 PDWORD RequiredSize)
1840 return SetupDiGetClassDescriptionExW(ClassGuid, ClassDescription,
1841 ClassDescriptionSize,
1842 RequiredSize, NULL, NULL);
1845 /***********************************************************************
1846 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
1848 BOOL WINAPI SetupDiGetClassDescriptionExA(
1849 const GUID* ClassGuid,
1850 PSTR ClassDescription,
1851 DWORD ClassDescriptionSize,
1852 PDWORD RequiredSize,
1853 PCSTR MachineName,
1854 PVOID Reserved)
1856 HKEY hKey;
1857 DWORD dwLength;
1858 BOOL ret;
1860 hKey = SetupDiOpenClassRegKeyExA(ClassGuid,
1861 KEY_ALL_ACCESS,
1862 DIOCR_INSTALLER,
1863 MachineName,
1864 Reserved);
1865 if (hKey == INVALID_HANDLE_VALUE)
1867 WARN("SetupDiOpenClassRegKeyExA() failed (Error %u)\n", GetLastError());
1868 return FALSE;
1871 dwLength = ClassDescriptionSize;
1872 ret = !RegQueryValueExA( hKey, NULL, NULL, NULL,
1873 (LPBYTE)ClassDescription, &dwLength );
1874 if (RequiredSize) *RequiredSize = dwLength;
1875 RegCloseKey(hKey);
1876 return ret;
1879 /***********************************************************************
1880 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
1882 BOOL WINAPI SetupDiGetClassDescriptionExW(
1883 const GUID* ClassGuid,
1884 PWSTR ClassDescription,
1885 DWORD ClassDescriptionSize,
1886 PDWORD RequiredSize,
1887 PCWSTR MachineName,
1888 PVOID Reserved)
1890 HKEY hKey;
1891 DWORD dwLength;
1892 BOOL ret;
1894 hKey = SetupDiOpenClassRegKeyExW(ClassGuid,
1895 KEY_ALL_ACCESS,
1896 DIOCR_INSTALLER,
1897 MachineName,
1898 Reserved);
1899 if (hKey == INVALID_HANDLE_VALUE)
1901 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
1902 return FALSE;
1905 dwLength = ClassDescriptionSize * sizeof(WCHAR);
1906 ret = !RegQueryValueExW( hKey, NULL, NULL, NULL,
1907 (LPBYTE)ClassDescription, &dwLength );
1908 if (RequiredSize) *RequiredSize = dwLength / sizeof(WCHAR);
1909 RegCloseKey(hKey);
1910 return ret;
1913 /***********************************************************************
1914 * SetupDiGetClassDevsA (SETUPAPI.@)
1916 HDEVINFO WINAPI SetupDiGetClassDevsA(const GUID *class, LPCSTR enumstr, HWND parent, DWORD flags)
1918 HDEVINFO ret;
1919 LPWSTR enumstrW = NULL;
1921 if (enumstr)
1923 int len = MultiByteToWideChar(CP_ACP, 0, enumstr, -1, NULL, 0);
1924 enumstrW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1925 if (!enumstrW)
1927 ret = INVALID_HANDLE_VALUE;
1928 goto end;
1930 MultiByteToWideChar(CP_ACP, 0, enumstr, -1, enumstrW, len);
1932 ret = SetupDiGetClassDevsExW(class, enumstrW, parent, flags, NULL, NULL,
1933 NULL);
1934 HeapFree(GetProcessHeap(), 0, enumstrW);
1936 end:
1937 return ret;
1940 /***********************************************************************
1941 * SetupDiGetClassDevsExA (SETUPAPI.@)
1943 HDEVINFO WINAPI SetupDiGetClassDevsExA(
1944 const GUID *class,
1945 PCSTR enumstr,
1946 HWND parent,
1947 DWORD flags,
1948 HDEVINFO deviceset,
1949 PCSTR machine,
1950 PVOID reserved)
1952 HDEVINFO ret;
1953 LPWSTR enumstrW = NULL, machineW = NULL;
1955 if (enumstr)
1957 int len = MultiByteToWideChar(CP_ACP, 0, enumstr, -1, NULL, 0);
1958 enumstrW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1959 if (!enumstrW)
1961 ret = INVALID_HANDLE_VALUE;
1962 goto end;
1964 MultiByteToWideChar(CP_ACP, 0, enumstr, -1, enumstrW, len);
1966 if (machine)
1968 int len = MultiByteToWideChar(CP_ACP, 0, machine, -1, NULL, 0);
1969 machineW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1970 if (!machineW)
1972 HeapFree(GetProcessHeap(), 0, enumstrW);
1973 ret = INVALID_HANDLE_VALUE;
1974 goto end;
1976 MultiByteToWideChar(CP_ACP, 0, machine, -1, machineW, len);
1978 ret = SetupDiGetClassDevsExW(class, enumstrW, parent, flags, deviceset,
1979 machineW, reserved);
1980 HeapFree(GetProcessHeap(), 0, enumstrW);
1981 HeapFree(GetProcessHeap(), 0, machineW);
1983 end:
1984 return ret;
1987 static void SETUPDI_AddDeviceInterfaces(SP_DEVINFO_DATA *dev, HKEY key,
1988 const GUID *guid)
1990 DWORD i, len;
1991 WCHAR subKeyName[MAX_PATH];
1992 LONG l = ERROR_SUCCESS;
1994 for (i = 0; !l; i++)
1996 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
1997 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
1998 if (!l)
2000 HKEY subKey;
2001 SP_DEVICE_INTERFACE_DATA *iface = NULL;
2003 if (*subKeyName == '#')
2005 /* The subkey name is the reference string, with a '#' prepended */
2006 SETUPDI_AddInterfaceInstance(dev, guid, subKeyName + 1, &iface);
2007 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2008 if (!l)
2010 WCHAR symbolicLink[MAX_PATH];
2011 DWORD dataType;
2013 len = sizeof(symbolicLink);
2014 l = RegQueryValueExW(subKey, SymbolicLink, NULL, &dataType,
2015 (BYTE *)symbolicLink, &len);
2016 if (!l && dataType == REG_SZ)
2017 SETUPDI_SetInterfaceSymbolicLink(iface, symbolicLink);
2018 RegCloseKey(subKey);
2021 /* Allow enumeration to continue */
2022 l = ERROR_SUCCESS;
2025 /* FIXME: find and add all the device's interfaces to the device */
2028 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet,
2029 HKEY key, const GUID *guid, LPCWSTR enumstr)
2031 struct DeviceInfoSet *set = DeviceInfoSet;
2032 DWORD i, len;
2033 WCHAR subKeyName[MAX_PATH];
2034 LONG l;
2035 HKEY enumKey = INVALID_HANDLE_VALUE;
2037 TRACE("%s\n", debugstr_w(enumstr));
2039 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
2040 &enumKey, NULL);
2041 for (i = 0; !l; i++)
2043 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2044 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2045 if (!l)
2047 HKEY subKey;
2049 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2050 if (!l)
2052 WCHAR deviceInst[MAX_PATH * 3];
2053 DWORD dataType;
2055 len = sizeof(deviceInst);
2056 l = RegQueryValueExW(subKey, DeviceInstance, NULL, &dataType,
2057 (BYTE *)deviceInst, &len);
2058 if (!l && dataType == REG_SZ)
2060 TRACE("found instance ID %s\n", debugstr_w(deviceInst));
2061 if (!enumstr || !lstrcmpiW(enumstr, deviceInst))
2063 HKEY deviceKey;
2065 l = RegOpenKeyExW(enumKey, deviceInst, 0, KEY_READ,
2066 &deviceKey);
2067 if (!l)
2069 WCHAR deviceClassStr[40];
2071 len = sizeof(deviceClassStr);
2072 l = RegQueryValueExW(deviceKey, ClassGUID, NULL,
2073 &dataType, (BYTE *)deviceClassStr, &len);
2074 if (!l && dataType == REG_SZ &&
2075 deviceClassStr[0] == '{' &&
2076 deviceClassStr[37] == '}')
2078 GUID deviceClass;
2079 SP_DEVINFO_DATA *dev;
2081 deviceClassStr[37] = 0;
2082 UuidFromStringW(&deviceClassStr[1],
2083 &deviceClass);
2084 if (SETUPDI_AddDeviceToSet(set, &deviceClass,
2085 0 /* FIXME: DevInst */, deviceInst,
2086 FALSE, &dev))
2087 SETUPDI_AddDeviceInterfaces(dev, subKey, guid);
2089 RegCloseKey(deviceKey);
2093 RegCloseKey(subKey);
2095 /* Allow enumeration to continue */
2096 l = ERROR_SUCCESS;
2099 if (enumKey != INVALID_HANDLE_VALUE)
2100 RegCloseKey(enumKey);
2103 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet,
2104 const GUID *guid, LPCWSTR enumstr, DWORD flags)
2106 HKEY interfacesKey = SetupDiOpenClassRegKeyExW(guid, KEY_READ,
2107 DIOCR_INTERFACE, NULL, NULL);
2109 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(guid),
2110 debugstr_w(enumstr), flags);
2112 if (interfacesKey != INVALID_HANDLE_VALUE)
2114 if (flags & DIGCF_ALLCLASSES)
2116 DWORD i, len;
2117 WCHAR interfaceGuidStr[40];
2118 LONG l = ERROR_SUCCESS;
2120 for (i = 0; !l; i++)
2122 len = sizeof(interfaceGuidStr) / sizeof(interfaceGuidStr[0]);
2123 l = RegEnumKeyExW(interfacesKey, i, interfaceGuidStr, &len,
2124 NULL, NULL, NULL, NULL);
2125 if (!l)
2127 if (interfaceGuidStr[0] == '{' &&
2128 interfaceGuidStr[37] == '}')
2130 HKEY interfaceKey;
2131 GUID interfaceGuid;
2133 interfaceGuidStr[37] = 0;
2134 UuidFromStringW(&interfaceGuidStr[1], &interfaceGuid);
2135 interfaceGuidStr[37] = '}';
2136 interfaceGuidStr[38] = 0;
2137 l = RegOpenKeyExW(interfacesKey, interfaceGuidStr, 0,
2138 KEY_READ, &interfaceKey);
2139 if (!l)
2141 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
2142 interfaceKey, &interfaceGuid, enumstr);
2143 RegCloseKey(interfaceKey);
2149 else
2151 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2152 * interface's key, so just pass that long
2154 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
2155 interfacesKey, guid, enumstr);
2157 RegCloseKey(interfacesKey);
2161 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet *set,
2162 LPCWSTR enumerator, LPCWSTR deviceName, HKEY deviceKey,
2163 const GUID *class, DWORD flags)
2165 DWORD i, len;
2166 WCHAR deviceInstance[MAX_PATH];
2167 LONG l = ERROR_SUCCESS;
2169 TRACE("%s %s\n", debugstr_w(enumerator), debugstr_w(deviceName));
2171 for (i = 0; !l; i++)
2173 len = sizeof(deviceInstance) / sizeof(deviceInstance[0]);
2174 l = RegEnumKeyExW(deviceKey, i, deviceInstance, &len, NULL, NULL, NULL,
2175 NULL);
2176 if (!l)
2178 HKEY subKey;
2180 l = RegOpenKeyExW(deviceKey, deviceInstance, 0, KEY_READ, &subKey);
2181 if (!l)
2183 WCHAR classGuid[40];
2184 DWORD dataType;
2186 len = sizeof(classGuid);
2187 l = RegQueryValueExW(subKey, ClassGUID, NULL, &dataType,
2188 (BYTE *)classGuid, &len);
2189 if (!l && dataType == REG_SZ)
2191 if (classGuid[0] == '{' && classGuid[37] == '}')
2193 GUID deviceClass;
2195 classGuid[37] = 0;
2196 UuidFromStringW(&classGuid[1], &deviceClass);
2197 if ((flags & DIGCF_ALLCLASSES) ||
2198 IsEqualGUID(class, &deviceClass))
2200 static const WCHAR fmt[] =
2201 {'%','s','\\','%','s','\\','%','s',0};
2202 LPWSTR instanceId;
2204 instanceId = HeapAlloc(GetProcessHeap(), 0,
2205 (lstrlenW(enumerator) + lstrlenW(deviceName) +
2206 lstrlenW(deviceInstance) + 3) * sizeof(WCHAR));
2207 if (instanceId)
2209 sprintfW(instanceId, fmt, enumerator,
2210 deviceName, deviceInstance);
2211 SETUPDI_AddDeviceToSet(set, &deviceClass,
2212 0 /* FIXME: DevInst */, instanceId,
2213 FALSE, NULL);
2214 HeapFree(GetProcessHeap(), 0, instanceId);
2219 RegCloseKey(subKey);
2221 /* Allow enumeration to continue */
2222 l = ERROR_SUCCESS;
2227 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet,
2228 LPCWSTR parent, HKEY key, const GUID *class, DWORD flags)
2230 struct DeviceInfoSet *set = DeviceInfoSet;
2231 DWORD i, len;
2232 WCHAR subKeyName[MAX_PATH];
2233 LONG l = ERROR_SUCCESS;
2235 TRACE("%s\n", debugstr_w(parent));
2237 for (i = 0; !l; i++)
2239 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2240 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2241 if (!l)
2243 HKEY subKey;
2245 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2246 if (!l)
2248 TRACE("%s\n", debugstr_w(subKeyName));
2249 SETUPDI_EnumerateMatchingDeviceInstances(set, parent,
2250 subKeyName, subKey, class, flags);
2251 RegCloseKey(subKey);
2253 /* Allow enumeration to continue */
2254 l = ERROR_SUCCESS;
2259 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet, const GUID *class,
2260 LPCWSTR enumstr, DWORD flags)
2262 HKEY enumKey;
2263 LONG l;
2265 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(class),
2266 debugstr_w(enumstr), flags);
2268 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
2269 &enumKey, NULL);
2270 if (enumKey != INVALID_HANDLE_VALUE)
2272 if (enumstr)
2274 HKEY enumStrKey;
2276 l = RegOpenKeyExW(enumKey, enumstr, 0, KEY_READ,
2277 &enumStrKey);
2278 if (!l)
2280 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet, enumstr,
2281 enumStrKey, class, flags);
2282 RegCloseKey(enumStrKey);
2285 else
2287 DWORD i, len;
2288 WCHAR subKeyName[MAX_PATH];
2290 l = ERROR_SUCCESS;
2291 for (i = 0; !l; i++)
2293 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2294 l = RegEnumKeyExW(enumKey, i, subKeyName, &len, NULL,
2295 NULL, NULL, NULL);
2296 if (!l)
2298 HKEY subKey;
2300 l = RegOpenKeyExW(enumKey, subKeyName, 0, KEY_READ,
2301 &subKey);
2302 if (!l)
2304 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet,
2305 subKeyName, subKey, class, flags);
2306 RegCloseKey(subKey);
2308 /* Allow enumeration to continue */
2309 l = ERROR_SUCCESS;
2313 RegCloseKey(enumKey);
2317 /***********************************************************************
2318 * SetupDiGetClassDevsW (SETUPAPI.@)
2320 HDEVINFO WINAPI SetupDiGetClassDevsW(const GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
2322 return SetupDiGetClassDevsExW(class, enumstr, parent, flags, NULL, NULL,
2323 NULL);
2326 /***********************************************************************
2327 * SetupDiGetClassDevsExW (SETUPAPI.@)
2329 HDEVINFO WINAPI SetupDiGetClassDevsExW(const GUID *class, PCWSTR enumstr, HWND parent, DWORD flags,
2330 HDEVINFO deviceset, PCWSTR machine, void *reserved)
2332 static const DWORD unsupportedFlags = DIGCF_DEFAULT | DIGCF_PRESENT |
2333 DIGCF_PROFILE;
2334 HDEVINFO set;
2336 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2337 debugstr_w(enumstr), parent, flags, deviceset, debugstr_w(machine),
2338 reserved);
2340 if (!(flags & DIGCF_ALLCLASSES) && !class)
2342 SetLastError(ERROR_INVALID_PARAMETER);
2343 return INVALID_HANDLE_VALUE;
2345 if (flags & unsupportedFlags)
2346 WARN("unsupported flags %08x\n", flags & unsupportedFlags);
2347 if (deviceset)
2348 set = deviceset;
2349 else
2350 set = SetupDiCreateDeviceInfoListExW(class, parent, machine, reserved);
2351 if (set != INVALID_HANDLE_VALUE)
2353 if (machine && *machine)
2354 FIXME("%s: unimplemented for remote machines\n",
2355 debugstr_w(machine));
2356 else if (flags & DIGCF_DEVICEINTERFACE)
2357 SETUPDI_EnumerateInterfaces(set, class, enumstr, flags);
2358 else
2359 SETUPDI_EnumerateDevices(set, class, enumstr, flags);
2361 return set;
2364 /***********************************************************************
2365 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2367 BOOL WINAPI SetupDiGetDeviceInfoListDetailA(
2368 HDEVINFO DeviceInfoSet,
2369 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData )
2371 struct DeviceInfoSet *set = DeviceInfoSet;
2373 TRACE("%p %p\n", DeviceInfoSet, DevInfoData);
2375 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2377 SetLastError(ERROR_INVALID_HANDLE);
2378 return FALSE;
2380 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2382 SetLastError(ERROR_INVALID_HANDLE);
2383 return FALSE;
2385 if (!DevInfoData ||
2386 DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A))
2388 SetLastError(ERROR_INVALID_PARAMETER);
2389 return FALSE;
2391 DevInfoData->ClassGuid = set->ClassGuid;
2392 DevInfoData->RemoteMachineHandle = NULL;
2393 DevInfoData->RemoteMachineName[0] = '\0';
2394 return TRUE;
2397 /***********************************************************************
2398 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2400 BOOL WINAPI SetupDiGetDeviceInfoListDetailW(
2401 HDEVINFO DeviceInfoSet,
2402 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData )
2404 struct DeviceInfoSet *set = DeviceInfoSet;
2406 TRACE("%p %p\n", DeviceInfoSet, DevInfoData);
2408 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2410 SetLastError(ERROR_INVALID_HANDLE);
2411 return FALSE;
2413 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2415 SetLastError(ERROR_INVALID_HANDLE);
2416 return FALSE;
2418 if (!DevInfoData ||
2419 DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W))
2421 SetLastError(ERROR_INVALID_PARAMETER);
2422 return FALSE;
2424 DevInfoData->ClassGuid = set->ClassGuid;
2425 DevInfoData->RemoteMachineHandle = NULL;
2426 DevInfoData->RemoteMachineName[0] = '\0';
2427 return TRUE;
2430 /***********************************************************************
2431 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2433 BOOL WINAPI SetupDiCreateDeviceInterfaceA(
2434 HDEVINFO DeviceInfoSet,
2435 PSP_DEVINFO_DATA DeviceInfoData,
2436 const GUID *InterfaceClassGuid,
2437 PCSTR ReferenceString,
2438 DWORD CreationFlags,
2439 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2441 BOOL ret;
2442 LPWSTR ReferenceStringW = NULL;
2444 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
2445 debugstr_guid(InterfaceClassGuid), debugstr_a(ReferenceString),
2446 CreationFlags, DeviceInterfaceData);
2448 if (ReferenceString)
2450 ReferenceStringW = MultiByteToUnicode(ReferenceString, CP_ACP);
2451 if (ReferenceStringW == NULL) return FALSE;
2454 ret = SetupDiCreateDeviceInterfaceW(DeviceInfoSet, DeviceInfoData,
2455 InterfaceClassGuid, ReferenceStringW, CreationFlags,
2456 DeviceInterfaceData);
2458 MyFree(ReferenceStringW);
2460 return ret;
2463 /***********************************************************************
2464 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2466 BOOL WINAPI SetupDiCreateDeviceInterfaceW(
2467 HDEVINFO DeviceInfoSet,
2468 PSP_DEVINFO_DATA DeviceInfoData,
2469 const GUID *InterfaceClassGuid,
2470 PCWSTR ReferenceString,
2471 DWORD CreationFlags,
2472 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2474 struct DeviceInfoSet *set = DeviceInfoSet;
2475 struct DeviceInfo *devInfo;
2476 SP_DEVICE_INTERFACE_DATA *iface = NULL;
2477 BOOL ret;
2479 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
2480 debugstr_guid(InterfaceClassGuid), debugstr_w(ReferenceString),
2481 CreationFlags, DeviceInterfaceData);
2483 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2485 SetLastError(ERROR_INVALID_HANDLE);
2486 return FALSE;
2488 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2490 SetLastError(ERROR_INVALID_HANDLE);
2491 return FALSE;
2493 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
2494 || !DeviceInfoData->Reserved)
2496 SetLastError(ERROR_INVALID_PARAMETER);
2497 return FALSE;
2499 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
2500 if (devInfo->set != set)
2502 SetLastError(ERROR_INVALID_PARAMETER);
2503 return FALSE;
2505 if (!InterfaceClassGuid)
2507 SetLastError(ERROR_INVALID_USER_BUFFER);
2508 return FALSE;
2510 if ((ret = SETUPDI_AddInterfaceInstance(DeviceInfoData, InterfaceClassGuid,
2511 ReferenceString, &iface)))
2513 if (DeviceInterfaceData)
2515 if (DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
2517 SetLastError(ERROR_INVALID_USER_BUFFER);
2518 ret = FALSE;
2520 else
2521 *DeviceInterfaceData = *iface;
2524 return ret;
2527 /***********************************************************************
2528 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2530 HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyA(
2531 HDEVINFO DeviceInfoSet,
2532 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2533 DWORD Reserved,
2534 REGSAM samDesired,
2535 HINF InfHandle,
2536 PCSTR InfSectionName)
2538 HKEY key;
2539 PWSTR InfSectionNameW = NULL;
2541 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
2542 samDesired, InfHandle, InfSectionName);
2543 if (InfHandle)
2545 if (!InfSectionName)
2547 SetLastError(ERROR_INVALID_PARAMETER);
2548 return INVALID_HANDLE_VALUE;
2550 InfSectionNameW = MultiByteToUnicode(InfSectionName, CP_ACP);
2551 if (!InfSectionNameW)
2552 return INVALID_HANDLE_VALUE;
2554 key = SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet,
2555 DeviceInterfaceData, Reserved, samDesired, InfHandle,
2556 InfSectionNameW);
2557 MyFree(InfSectionNameW);
2558 return key;
2561 static PWSTR SETUPDI_GetInstancePath(struct InterfaceInfo *ifaceInfo)
2563 static const WCHAR hash[] = {'#',0};
2564 PWSTR instancePath = NULL;
2566 if (ifaceInfo->referenceString)
2568 instancePath = HeapAlloc(GetProcessHeap(), 0,
2569 (lstrlenW(ifaceInfo->referenceString) + 2) * sizeof(WCHAR));
2570 if (instancePath)
2572 lstrcpyW(instancePath, hash);
2573 lstrcatW(instancePath, ifaceInfo->referenceString);
2575 else
2576 SetLastError(ERROR_OUTOFMEMORY);
2578 else
2580 instancePath = HeapAlloc(GetProcessHeap(), 0,
2581 (lstrlenW(hash) + 1) * sizeof(WCHAR));
2582 if (instancePath)
2583 lstrcpyW(instancePath, hash);
2585 return instancePath;
2588 /***********************************************************************
2589 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2591 HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyW(
2592 HDEVINFO DeviceInfoSet,
2593 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2594 DWORD Reserved,
2595 REGSAM samDesired,
2596 HINF InfHandle,
2597 PCWSTR InfSectionName)
2599 struct DeviceInfoSet *set = DeviceInfoSet;
2600 HKEY key = INVALID_HANDLE_VALUE, interfacesKey;
2601 LONG l;
2603 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
2604 samDesired, InfHandle, InfSectionName);
2606 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2607 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2609 SetLastError(ERROR_INVALID_HANDLE);
2610 return INVALID_HANDLE_VALUE;
2612 if (!DeviceInterfaceData ||
2613 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2614 !DeviceInterfaceData->Reserved)
2616 SetLastError(ERROR_INVALID_PARAMETER);
2617 return INVALID_HANDLE_VALUE;
2619 if (InfHandle && !InfSectionName)
2621 SetLastError(ERROR_INVALID_PARAMETER);
2622 return INVALID_HANDLE_VALUE;
2624 if (!(l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, DeviceClasses, 0, NULL, 0,
2625 samDesired, NULL, &interfacesKey, NULL)))
2627 HKEY parent;
2628 WCHAR bracedGuidString[39];
2630 SETUPDI_GuidToString(&DeviceInterfaceData->InterfaceClassGuid,
2631 bracedGuidString);
2632 if (!(l = RegCreateKeyExW(interfacesKey, bracedGuidString, 0, NULL, 0,
2633 samDesired, NULL, &parent, NULL)))
2635 struct InterfaceInfo *ifaceInfo =
2636 (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2637 PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo);
2638 PWSTR interfKeyName = HeapAlloc(GetProcessHeap(), 0,
2639 (lstrlenW(ifaceInfo->symbolicLink) + 1) * sizeof(WCHAR));
2640 HKEY interfKey;
2641 WCHAR *ptr;
2643 lstrcpyW(interfKeyName, ifaceInfo->symbolicLink);
2644 if (lstrlenW(ifaceInfo->symbolicLink) > 3)
2646 interfKeyName[0] = '#';
2647 interfKeyName[1] = '#';
2648 interfKeyName[3] = '#';
2650 ptr = strchrW(interfKeyName, '\\');
2651 if (ptr)
2652 *ptr = 0;
2653 l = RegCreateKeyExW(parent, interfKeyName, 0, NULL, 0,
2654 samDesired, NULL, &interfKey, NULL);
2655 if (!l)
2657 struct DeviceInfo *devInfo =
2658 (struct DeviceInfo *)ifaceInfo->device->Reserved;
2660 l = RegSetValueExW(interfKey, DeviceInstance, 0, REG_SZ,
2661 (BYTE *)devInfo->instanceId,
2662 (lstrlenW(devInfo->instanceId) + 1) * sizeof(WCHAR));
2663 if (!l)
2665 if (instancePath)
2667 LONG l;
2669 l = RegCreateKeyExW(interfKey, instancePath, 0, NULL, 0,
2670 samDesired, NULL, &key, NULL);
2671 if (l)
2673 SetLastError(l);
2674 key = INVALID_HANDLE_VALUE;
2676 else if (InfHandle)
2677 FIXME("INF section installation unsupported\n");
2680 else
2681 SetLastError(l);
2682 RegCloseKey(interfKey);
2684 else
2685 SetLastError(l);
2686 HeapFree(GetProcessHeap(), 0, interfKeyName);
2687 HeapFree(GetProcessHeap(), 0, instancePath);
2688 RegCloseKey(parent);
2690 else
2691 SetLastError(l);
2692 RegCloseKey(interfacesKey);
2694 else
2695 SetLastError(l);
2696 return key;
2699 /***********************************************************************
2700 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2702 BOOL WINAPI SetupDiDeleteDeviceInterfaceRegKey(
2703 HDEVINFO DeviceInfoSet,
2704 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2705 DWORD Reserved)
2707 struct DeviceInfoSet *set = DeviceInfoSet;
2708 HKEY parent;
2709 BOOL ret = FALSE;
2711 TRACE("%p %p %d\n", DeviceInfoSet, DeviceInterfaceData, Reserved);
2713 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2714 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2716 SetLastError(ERROR_INVALID_HANDLE);
2717 return FALSE;
2719 if (!DeviceInterfaceData ||
2720 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2721 !DeviceInterfaceData->Reserved)
2723 SetLastError(ERROR_INVALID_PARAMETER);
2724 return FALSE;
2726 parent = SetupDiOpenClassRegKeyExW(&DeviceInterfaceData->InterfaceClassGuid,
2727 KEY_ALL_ACCESS, DIOCR_INTERFACE, NULL, NULL);
2728 if (parent != INVALID_HANDLE_VALUE)
2730 struct InterfaceInfo *ifaceInfo =
2731 (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2732 PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo);
2734 if (instancePath)
2736 LONG l = RegDeleteKeyW(parent, instancePath);
2738 if (l)
2739 SetLastError(l);
2740 else
2741 ret = TRUE;
2742 HeapFree(GetProcessHeap(), 0, instancePath);
2744 RegCloseKey(parent);
2746 return ret;
2749 /***********************************************************************
2750 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2752 * PARAMS
2753 * DeviceInfoSet [I] Set of devices from which to enumerate
2754 * interfaces
2755 * DeviceInfoData [I] (Optional) If specified, a specific device
2756 * instance from which to enumerate interfaces.
2757 * If it isn't specified, all interfaces for all
2758 * devices in the set are enumerated.
2759 * InterfaceClassGuid [I] The interface class to enumerate.
2760 * MemberIndex [I] An index of the interface instance to enumerate.
2761 * A caller should start with MemberIndex set to 0,
2762 * and continue until the function fails with
2763 * ERROR_NO_MORE_ITEMS.
2764 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2765 * member must be set to
2766 * sizeof(SP_DEVICE_INTERFACE_DATA).
2768 * RETURNS
2769 * Success: non-zero value.
2770 * Failure: FALSE. Call GetLastError() for more info.
2772 BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData,
2773 const GUID *InterfaceClassGuid, DWORD MemberIndex,
2774 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2776 struct DeviceInfoSet *set = DeviceInfoSet;
2777 BOOL ret = FALSE;
2779 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet, DeviceInfoData,
2780 debugstr_guid(InterfaceClassGuid), MemberIndex, DeviceInterfaceData);
2782 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2783 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2785 SetLastError(ERROR_INVALID_HANDLE);
2786 return FALSE;
2788 if (DeviceInfoData && (DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) ||
2789 !DeviceInfoData->Reserved))
2791 SetLastError(ERROR_INVALID_PARAMETER);
2792 return FALSE;
2794 if (!DeviceInterfaceData ||
2795 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
2797 SetLastError(ERROR_INVALID_PARAMETER);
2798 return FALSE;
2801 /* In case application fails to check return value, clear output */
2802 memset(DeviceInterfaceData, 0, sizeof(*DeviceInterfaceData));
2803 DeviceInterfaceData->cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
2805 if (DeviceInfoData)
2807 struct DeviceInfo *devInfo =
2808 (struct DeviceInfo *)DeviceInfoData->Reserved;
2809 struct InterfaceInstances *iface;
2811 if ((ret = SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface)))
2813 if (MemberIndex < iface->cInstances)
2814 *DeviceInterfaceData = iface->instances[MemberIndex];
2815 else
2817 SetLastError(ERROR_NO_MORE_ITEMS);
2818 ret = FALSE;
2821 else
2822 SetLastError(ERROR_NO_MORE_ITEMS);
2824 else
2826 struct DeviceInstance *devInst;
2827 DWORD cEnumerated = 0;
2828 BOOL found = FALSE;
2830 LIST_FOR_EACH_ENTRY(devInst, &set->devices, struct DeviceInstance, entry)
2832 struct DeviceInfo *devInfo = (struct DeviceInfo *)devInst->data.Reserved;
2833 struct InterfaceInstances *iface;
2835 if (found || cEnumerated >= MemberIndex + 1)
2836 break;
2837 if (SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface))
2839 if (cEnumerated + iface->cInstances < MemberIndex + 1)
2840 cEnumerated += iface->cInstances;
2841 else
2843 DWORD instanceIndex = MemberIndex - cEnumerated;
2845 *DeviceInterfaceData = iface->instances[instanceIndex];
2846 cEnumerated += instanceIndex + 1;
2847 found = TRUE;
2848 ret = TRUE;
2852 if (!found)
2853 SetLastError(ERROR_NO_MORE_ITEMS);
2855 return ret;
2858 /***********************************************************************
2859 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2861 * Destroy a DeviceInfoList and free all used memory of the list.
2863 * PARAMS
2864 * devinfo [I] DeviceInfoList pointer to list to destroy
2866 * RETURNS
2867 * Success: non zero value.
2868 * Failure: zero value.
2870 BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
2872 BOOL ret = FALSE;
2874 TRACE("%p\n", devinfo);
2875 if (devinfo && devinfo != INVALID_HANDLE_VALUE)
2877 struct DeviceInfoSet *list = devinfo;
2879 if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC)
2881 struct DeviceInstance *devInst, *devInst2;
2883 LIST_FOR_EACH_ENTRY_SAFE(devInst, devInst2, &list->devices,
2884 struct DeviceInstance, entry)
2886 SETUPDI_FreeDeviceInfo( (struct DeviceInfo *)devInst->data.Reserved );
2887 list_remove(&devInst->entry);
2888 HeapFree(GetProcessHeap(), 0, devInst);
2890 HeapFree(GetProcessHeap(), 0, list);
2891 ret = TRUE;
2895 if (!ret)
2896 SetLastError(ERROR_INVALID_HANDLE);
2898 return ret;
2901 /***********************************************************************
2902 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2904 BOOL WINAPI SetupDiGetDeviceInterfaceDetailA(
2905 HDEVINFO DeviceInfoSet,
2906 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2907 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData,
2908 DWORD DeviceInterfaceDetailDataSize,
2909 PDWORD RequiredSize,
2910 PSP_DEVINFO_DATA DeviceInfoData)
2912 struct DeviceInfoSet *set = DeviceInfoSet;
2913 struct InterfaceInfo *info;
2914 DWORD bytesNeeded = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath[1]);
2915 BOOL ret = FALSE;
2917 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet,
2918 DeviceInterfaceData, DeviceInterfaceDetailData,
2919 DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
2921 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2922 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2924 SetLastError(ERROR_INVALID_HANDLE);
2925 return FALSE;
2927 if (!DeviceInterfaceData ||
2928 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2929 !DeviceInterfaceData->Reserved)
2931 SetLastError(ERROR_INVALID_PARAMETER);
2932 return FALSE;
2934 if (DeviceInterfaceDetailData &&
2935 DeviceInterfaceDetailData->cbSize != sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A))
2937 SetLastError(ERROR_INVALID_USER_BUFFER);
2938 return FALSE;
2940 if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
2942 SetLastError(ERROR_INVALID_USER_BUFFER);
2943 return FALSE;
2945 info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2946 if (info->symbolicLink)
2947 bytesNeeded += WideCharToMultiByte(CP_ACP, 0, info->symbolicLink, -1,
2948 NULL, 0, NULL, NULL);
2949 if (DeviceInterfaceDetailDataSize >= bytesNeeded)
2951 if (info->symbolicLink)
2952 WideCharToMultiByte(CP_ACP, 0, info->symbolicLink, -1,
2953 DeviceInterfaceDetailData->DevicePath,
2954 DeviceInterfaceDetailDataSize -
2955 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath),
2956 NULL, NULL);
2957 else
2958 DeviceInterfaceDetailData->DevicePath[0] = '\0';
2959 if (DeviceInfoData && DeviceInfoData->cbSize == sizeof(SP_DEVINFO_DATA))
2960 *DeviceInfoData = *info->device;
2961 ret = TRUE;
2963 else
2965 if (RequiredSize)
2966 *RequiredSize = bytesNeeded;
2967 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2969 return ret;
2972 /***********************************************************************
2973 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2975 BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(
2976 HDEVINFO DeviceInfoSet,
2977 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2978 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData,
2979 DWORD DeviceInterfaceDetailDataSize,
2980 PDWORD RequiredSize,
2981 PSP_DEVINFO_DATA DeviceInfoData)
2983 struct DeviceInfoSet *set = DeviceInfoSet;
2984 struct InterfaceInfo *info;
2985 DWORD bytesNeeded = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath)
2986 + sizeof(WCHAR); /* include NULL terminator */
2987 BOOL ret = FALSE;
2989 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet,
2990 DeviceInterfaceData, DeviceInterfaceDetailData,
2991 DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
2993 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2994 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2996 SetLastError(ERROR_INVALID_HANDLE);
2997 return FALSE;
2999 if (!DeviceInterfaceData ||
3000 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
3001 !DeviceInterfaceData->Reserved)
3003 SetLastError(ERROR_INVALID_PARAMETER);
3004 return FALSE;
3006 if (DeviceInterfaceDetailData && (DeviceInterfaceDetailData->cbSize <
3007 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR) ||
3008 DeviceInterfaceDetailData->cbSize > sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W)))
3010 SetLastError(ERROR_INVALID_USER_BUFFER);
3011 return FALSE;
3013 if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
3015 SetLastError(ERROR_INVALID_USER_BUFFER);
3016 return FALSE;
3018 info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
3019 if (info->symbolicLink)
3020 bytesNeeded += sizeof(WCHAR)*lstrlenW(info->symbolicLink);
3021 if (DeviceInterfaceDetailDataSize >= bytesNeeded)
3023 if (info->symbolicLink)
3024 lstrcpyW(DeviceInterfaceDetailData->DevicePath, info->symbolicLink);
3025 else
3026 DeviceInterfaceDetailData->DevicePath[0] = '\0';
3027 if (DeviceInfoData && DeviceInfoData->cbSize == sizeof(SP_DEVINFO_DATA))
3028 *DeviceInfoData = *info->device;
3029 ret = TRUE;
3031 else
3033 if (RequiredSize)
3034 *RequiredSize = bytesNeeded;
3035 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3037 return ret;
3040 struct PropertyMapEntry
3042 DWORD regType;
3043 LPCSTR nameA;
3044 LPCWSTR nameW;
3047 static const struct PropertyMapEntry PropertyMap[] = {
3048 { REG_SZ, "DeviceDesc", DeviceDesc },
3049 { REG_MULTI_SZ, "HardwareId", HardwareId },
3050 { REG_MULTI_SZ, "CompatibleIDs", CompatibleIDs },
3051 { 0, NULL, NULL }, /* SPDRP_UNUSED0 */
3052 { REG_SZ, "Service", Service },
3053 { 0, NULL, NULL }, /* SPDRP_UNUSED1 */
3054 { 0, NULL, NULL }, /* SPDRP_UNUSED2 */
3055 { REG_SZ, "Class", Class },
3056 { REG_SZ, "ClassGUID", ClassGUID },
3057 { REG_SZ, "Driver", Driver },
3058 { REG_DWORD, "ConfigFlags", ConfigFlags },
3059 { REG_SZ, "Mfg", Mfg },
3060 { REG_SZ, "FriendlyName", FriendlyName },
3061 { REG_SZ, "LocationInformation", LocationInformation },
3062 { 0, NULL, NULL }, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3063 { REG_DWORD, "Capabilities", Capabilities },
3064 { REG_DWORD, "UINumber", UINumber },
3065 { REG_MULTI_SZ, "UpperFilters", UpperFilters },
3066 { REG_MULTI_SZ, "LowerFilters", LowerFilters },
3069 /***********************************************************************
3070 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3072 BOOL WINAPI SetupDiGetDeviceRegistryPropertyA(
3073 HDEVINFO DeviceInfoSet,
3074 PSP_DEVINFO_DATA DeviceInfoData,
3075 DWORD Property,
3076 PDWORD PropertyRegDataType,
3077 PBYTE PropertyBuffer,
3078 DWORD PropertyBufferSize,
3079 PDWORD RequiredSize)
3081 BOOL ret = FALSE;
3082 struct DeviceInfoSet *set = DeviceInfoSet;
3083 struct DeviceInfo *devInfo;
3085 TRACE("%04x %p %d %p %p %d %p\n", (DWORD)DeviceInfoSet, DeviceInfoData,
3086 Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize,
3087 RequiredSize);
3089 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3091 SetLastError(ERROR_INVALID_HANDLE);
3092 return FALSE;
3094 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3096 SetLastError(ERROR_INVALID_HANDLE);
3097 return FALSE;
3099 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3100 || !DeviceInfoData->Reserved)
3102 SetLastError(ERROR_INVALID_PARAMETER);
3103 return FALSE;
3105 if (PropertyBufferSize && PropertyBuffer == NULL)
3107 SetLastError(ERROR_INVALID_DATA);
3108 return FALSE;
3110 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3111 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3112 && PropertyMap[Property].nameA)
3114 DWORD size = PropertyBufferSize;
3115 LONG l = RegQueryValueExA(devInfo->key, PropertyMap[Property].nameA,
3116 NULL, PropertyRegDataType, PropertyBuffer, &size);
3118 if (l == ERROR_MORE_DATA || !PropertyBufferSize)
3119 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3120 else if (!l)
3121 ret = TRUE;
3122 else
3123 SetLastError(l);
3124 if (RequiredSize)
3125 *RequiredSize = size;
3127 return ret;
3130 /***********************************************************************
3131 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3133 BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(
3134 HDEVINFO DeviceInfoSet,
3135 PSP_DEVINFO_DATA DeviceInfoData,
3136 DWORD Property,
3137 PDWORD PropertyRegDataType,
3138 PBYTE PropertyBuffer,
3139 DWORD PropertyBufferSize,
3140 PDWORD RequiredSize)
3142 BOOL ret = FALSE;
3143 struct DeviceInfoSet *set = DeviceInfoSet;
3144 struct DeviceInfo *devInfo;
3146 TRACE("%04x %p %d %p %p %d %p\n", (DWORD)DeviceInfoSet, DeviceInfoData,
3147 Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize,
3148 RequiredSize);
3150 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3152 SetLastError(ERROR_INVALID_HANDLE);
3153 return FALSE;
3155 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3157 SetLastError(ERROR_INVALID_HANDLE);
3158 return FALSE;
3160 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3161 || !DeviceInfoData->Reserved)
3163 SetLastError(ERROR_INVALID_PARAMETER);
3164 return FALSE;
3166 if (PropertyBufferSize && PropertyBuffer == NULL)
3168 SetLastError(ERROR_INVALID_DATA);
3169 return FALSE;
3171 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3172 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3173 && PropertyMap[Property].nameW)
3175 DWORD size = PropertyBufferSize;
3176 LONG l = RegQueryValueExW(devInfo->key, PropertyMap[Property].nameW,
3177 NULL, PropertyRegDataType, PropertyBuffer, &size);
3179 if (l == ERROR_MORE_DATA || !PropertyBufferSize)
3180 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3181 else if (!l)
3182 ret = TRUE;
3183 else
3184 SetLastError(l);
3185 if (RequiredSize)
3186 *RequiredSize = size;
3188 return ret;
3191 /***********************************************************************
3192 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3194 BOOL WINAPI SetupDiSetDeviceRegistryPropertyA(
3195 HDEVINFO DeviceInfoSet,
3196 PSP_DEVINFO_DATA DeviceInfoData,
3197 DWORD Property,
3198 const BYTE *PropertyBuffer,
3199 DWORD PropertyBufferSize)
3201 BOOL ret = FALSE;
3202 struct DeviceInfoSet *set = DeviceInfoSet;
3203 struct DeviceInfo *devInfo;
3205 TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property,
3206 PropertyBuffer, PropertyBufferSize);
3208 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3210 SetLastError(ERROR_INVALID_HANDLE);
3211 return FALSE;
3213 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3215 SetLastError(ERROR_INVALID_HANDLE);
3216 return FALSE;
3218 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3219 || !DeviceInfoData->Reserved)
3221 SetLastError(ERROR_INVALID_PARAMETER);
3222 return FALSE;
3224 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3225 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3226 && PropertyMap[Property].nameA)
3228 LONG l = RegSetValueExA(devInfo->key, PropertyMap[Property].nameA, 0,
3229 PropertyMap[Property].regType, PropertyBuffer,
3230 PropertyBufferSize);
3231 if (!l)
3232 ret = TRUE;
3233 else
3234 SetLastError(l);
3236 return ret;
3239 /***********************************************************************
3240 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3242 BOOL WINAPI SetupDiSetDeviceRegistryPropertyW(
3243 HDEVINFO DeviceInfoSet,
3244 PSP_DEVINFO_DATA DeviceInfoData,
3245 DWORD Property,
3246 const BYTE *PropertyBuffer,
3247 DWORD PropertyBufferSize)
3249 BOOL ret = FALSE;
3250 struct DeviceInfoSet *set = DeviceInfoSet;
3251 struct DeviceInfo *devInfo;
3253 TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property,
3254 PropertyBuffer, PropertyBufferSize);
3256 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3258 SetLastError(ERROR_INVALID_HANDLE);
3259 return FALSE;
3261 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3263 SetLastError(ERROR_INVALID_HANDLE);
3264 return FALSE;
3266 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3267 || !DeviceInfoData->Reserved)
3269 SetLastError(ERROR_INVALID_PARAMETER);
3270 return FALSE;
3272 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3273 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3274 && PropertyMap[Property].nameW)
3276 LONG l = RegSetValueExW(devInfo->key, PropertyMap[Property].nameW, 0,
3277 PropertyMap[Property].regType, PropertyBuffer,
3278 PropertyBufferSize);
3279 if (!l)
3280 ret = TRUE;
3281 else
3282 SetLastError(l);
3284 return ret;
3287 /***********************************************************************
3288 * SetupDiInstallClassA (SETUPAPI.@)
3290 BOOL WINAPI SetupDiInstallClassA(
3291 HWND hwndParent,
3292 PCSTR InfFileName,
3293 DWORD Flags,
3294 HSPFILEQ FileQueue)
3296 UNICODE_STRING FileNameW;
3297 BOOL Result;
3299 if (!InfFileName)
3301 SetLastError(ERROR_INVALID_PARAMETER);
3302 return FALSE;
3304 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW, InfFileName))
3306 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
3307 return FALSE;
3310 Result = SetupDiInstallClassW(hwndParent, FileNameW.Buffer, Flags, FileQueue);
3312 RtlFreeUnicodeString(&FileNameW);
3314 return Result;
3317 static HKEY CreateClassKey(HINF hInf)
3319 static const WCHAR slash[] = { '\\',0 };
3320 WCHAR FullBuffer[MAX_PATH];
3321 WCHAR Buffer[MAX_PATH];
3322 DWORD RequiredSize;
3323 HKEY hClassKey;
3325 if (!SetupGetLineTextW(NULL,
3326 hInf,
3327 Version,
3328 ClassGUID,
3329 Buffer,
3330 MAX_PATH,
3331 &RequiredSize))
3333 return INVALID_HANDLE_VALUE;
3336 lstrcpyW(FullBuffer, ControlClass);
3337 lstrcatW(FullBuffer, slash);
3338 lstrcatW(FullBuffer, Buffer);
3340 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3341 FullBuffer,
3343 KEY_ALL_ACCESS,
3344 &hClassKey))
3346 if (!SetupGetLineTextW(NULL,
3347 hInf,
3348 Version,
3349 Class,
3350 Buffer,
3351 MAX_PATH,
3352 &RequiredSize))
3354 return INVALID_HANDLE_VALUE;
3357 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,
3358 FullBuffer,
3360 NULL,
3361 REG_OPTION_NON_VOLATILE,
3362 KEY_ALL_ACCESS,
3363 NULL,
3364 &hClassKey,
3365 NULL))
3367 return INVALID_HANDLE_VALUE;
3372 if (RegSetValueExW(hClassKey,
3373 Class,
3375 REG_SZ,
3376 (LPBYTE)Buffer,
3377 RequiredSize * sizeof(WCHAR)))
3379 RegCloseKey(hClassKey);
3380 RegDeleteKeyW(HKEY_LOCAL_MACHINE,
3381 FullBuffer);
3382 return INVALID_HANDLE_VALUE;
3385 return hClassKey;
3388 /***********************************************************************
3389 * SetupDiInstallClassW (SETUPAPI.@)
3391 BOOL WINAPI SetupDiInstallClassW(
3392 HWND hwndParent,
3393 PCWSTR InfFileName,
3394 DWORD Flags,
3395 HSPFILEQ FileQueue)
3397 WCHAR SectionName[MAX_PATH];
3398 DWORD SectionNameLength = 0;
3399 HINF hInf;
3400 BOOL bFileQueueCreated = FALSE;
3401 HKEY hClassKey;
3404 FIXME("\n");
3406 if (!InfFileName)
3408 SetLastError(ERROR_INVALID_PARAMETER);
3409 return FALSE;
3411 if ((Flags & DI_NOVCP) && (FileQueue == NULL || FileQueue == INVALID_HANDLE_VALUE))
3413 SetLastError(ERROR_INVALID_PARAMETER);
3414 return FALSE;
3417 /* Open the .inf file */
3418 hInf = SetupOpenInfFileW(InfFileName,
3419 NULL,
3420 INF_STYLE_WIN4,
3421 NULL);
3422 if (hInf == INVALID_HANDLE_VALUE)
3425 return FALSE;
3428 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3429 hClassKey = CreateClassKey(hInf);
3430 if (hClassKey == INVALID_HANDLE_VALUE)
3432 SetupCloseInfFile(hInf);
3433 return FALSE;
3437 /* Try to append a layout file */
3438 SetupOpenAppendInfFileW(NULL, hInf, NULL);
3440 /* Retrieve the actual section name */
3441 SetupDiGetActualSectionToInstallW(hInf,
3442 ClassInstall32,
3443 SectionName,
3444 MAX_PATH,
3445 &SectionNameLength,
3446 NULL);
3448 #if 0
3449 if (!(Flags & DI_NOVCP))
3451 FileQueue = SetupOpenFileQueue();
3452 if (FileQueue == INVALID_HANDLE_VALUE)
3454 SetupCloseInfFile(hInf);
3455 return FALSE;
3458 bFileQueueCreated = TRUE;
3461 #endif
3463 SetupInstallFromInfSectionW(NULL,
3464 hInf,
3465 SectionName,
3466 SPINST_COPYINF | SPINST_FILES | SPINST_REGISTRY,
3467 hClassKey,
3468 NULL,
3470 NULL,
3471 NULL,
3472 INVALID_HANDLE_VALUE,
3473 NULL);
3475 /* FIXME: More code! */
3477 if (bFileQueueCreated)
3478 SetupCloseFileQueue(FileQueue);
3480 SetupCloseInfFile(hInf);
3482 return TRUE;
3486 /***********************************************************************
3487 * SetupDiOpenClassRegKey (SETUPAPI.@)
3489 HKEY WINAPI SetupDiOpenClassRegKey(
3490 const GUID* ClassGuid,
3491 REGSAM samDesired)
3493 return SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
3494 DIOCR_INSTALLER, NULL, NULL);
3498 /***********************************************************************
3499 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3501 HKEY WINAPI SetupDiOpenClassRegKeyExA(
3502 const GUID* ClassGuid,
3503 REGSAM samDesired,
3504 DWORD Flags,
3505 PCSTR MachineName,
3506 PVOID Reserved)
3508 PWSTR MachineNameW = NULL;
3509 HKEY hKey;
3511 TRACE("\n");
3513 if (MachineName)
3515 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
3516 if (MachineNameW == NULL)
3517 return INVALID_HANDLE_VALUE;
3520 hKey = SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
3521 Flags, MachineNameW, Reserved);
3523 MyFree(MachineNameW);
3525 return hKey;
3529 /***********************************************************************
3530 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3532 HKEY WINAPI SetupDiOpenClassRegKeyExW(
3533 const GUID* ClassGuid,
3534 REGSAM samDesired,
3535 DWORD Flags,
3536 PCWSTR MachineName,
3537 PVOID Reserved)
3539 HKEY hClassesKey;
3540 HKEY key;
3541 LPCWSTR lpKeyName;
3542 LONG l;
3544 if (MachineName && *MachineName)
3546 FIXME("Remote access not supported yet!\n");
3547 return INVALID_HANDLE_VALUE;
3550 if (Flags == DIOCR_INSTALLER)
3552 lpKeyName = ControlClass;
3554 else if (Flags == DIOCR_INTERFACE)
3556 lpKeyName = DeviceClasses;
3558 else
3560 ERR("Invalid Flags parameter!\n");
3561 SetLastError(ERROR_INVALID_PARAMETER);
3562 return INVALID_HANDLE_VALUE;
3565 if (!ClassGuid)
3567 if ((l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3568 lpKeyName,
3570 samDesired,
3571 &hClassesKey)))
3573 SetLastError(l);
3574 hClassesKey = INVALID_HANDLE_VALUE;
3576 key = hClassesKey;
3578 else
3580 WCHAR bracedGuidString[39];
3582 SETUPDI_GuidToString(ClassGuid, bracedGuidString);
3584 if (!(l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3585 lpKeyName,
3587 samDesired,
3588 &hClassesKey)))
3590 if ((l = RegOpenKeyExW(hClassesKey,
3591 bracedGuidString,
3593 samDesired,
3594 &key)))
3596 SetLastError(l);
3597 key = INVALID_HANDLE_VALUE;
3599 RegCloseKey(hClassesKey);
3601 else
3603 SetLastError(l);
3604 key = INVALID_HANDLE_VALUE;
3607 return key;
3610 /***********************************************************************
3611 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3613 BOOL WINAPI SetupDiOpenDeviceInterfaceW(
3614 HDEVINFO DeviceInfoSet,
3615 PCWSTR DevicePath,
3616 DWORD OpenFlags,
3617 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
3619 FIXME("%p %s %08x %p\n",
3620 DeviceInfoSet, debugstr_w(DevicePath), OpenFlags, DeviceInterfaceData);
3621 return FALSE;
3624 /***********************************************************************
3625 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3627 BOOL WINAPI SetupDiOpenDeviceInterfaceA(
3628 HDEVINFO DeviceInfoSet,
3629 PCSTR DevicePath,
3630 DWORD OpenFlags,
3631 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
3633 FIXME("%p %s %08x %p\n", DeviceInfoSet,
3634 debugstr_a(DevicePath), OpenFlags, DeviceInterfaceData);
3635 return FALSE;
3638 /***********************************************************************
3639 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3641 BOOL WINAPI SetupDiSetClassInstallParamsA(
3642 HDEVINFO DeviceInfoSet,
3643 PSP_DEVINFO_DATA DeviceInfoData,
3644 PSP_CLASSINSTALL_HEADER ClassInstallParams,
3645 DWORD ClassInstallParamsSize)
3647 FIXME("%p %p %x %u\n",DeviceInfoSet, DeviceInfoData,
3648 ClassInstallParams->InstallFunction, ClassInstallParamsSize);
3649 return FALSE;
3652 /***********************************************************************
3653 * SetupDiSetClassInstallParamsW (SETUPAPI.@)
3655 BOOL WINAPI SetupDiSetClassInstallParamsW(
3656 HDEVINFO DeviceInfoSet,
3657 PSP_DEVINFO_DATA DeviceInfoData,
3658 PSP_CLASSINSTALL_HEADER ClassInstallParams,
3659 DWORD ClassInstallParamsSize)
3661 FIXME("%p %p %x %u\n",DeviceInfoSet, DeviceInfoData,
3662 ClassInstallParams->InstallFunction, ClassInstallParamsSize);
3663 return FALSE;
3666 /***********************************************************************
3667 * SetupDiCallClassInstaller (SETUPAPI.@)
3669 BOOL WINAPI SetupDiCallClassInstaller(
3670 DI_FUNCTION InstallFunction,
3671 HDEVINFO DeviceInfoSet,
3672 PSP_DEVINFO_DATA DeviceInfoData)
3674 FIXME("%d %p %p\n", InstallFunction, DeviceInfoSet, DeviceInfoData);
3675 return FALSE;
3678 /***********************************************************************
3679 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
3681 BOOL WINAPI SetupDiGetDeviceInstallParamsW(
3682 HDEVINFO DeviceInfoSet,
3683 PSP_DEVINFO_DATA DeviceInfoData,
3684 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
3686 FIXME("%p %p %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3687 return FALSE;
3690 /***********************************************************************
3691 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3693 BOOL WINAPI SetupDiGetDeviceInstallParamsA(
3694 HDEVINFO DeviceInfoSet,
3695 PSP_DEVINFO_DATA DeviceInfoData,
3696 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams)
3698 FIXME("%p %p %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3699 return FALSE;
3702 /***********************************************************************
3703 * SetupDiSetDeviceInstallParamsA (SETUPAPI.@)
3705 BOOL WINAPI SetupDiSetDeviceInstallParamsA(
3706 HDEVINFO DeviceInfoSet,
3707 PSP_DEVINFO_DATA DeviceInfoData,
3708 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams)
3710 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3712 return TRUE;
3715 /***********************************************************************
3716 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
3718 BOOL WINAPI SetupDiSetDeviceInstallParamsW(
3719 HDEVINFO DeviceInfoSet,
3720 PSP_DEVINFO_DATA DeviceInfoData,
3721 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
3723 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3725 return TRUE;
3728 static HKEY SETUPDI_OpenDevKey(struct DeviceInfo *devInfo, REGSAM samDesired)
3730 HKEY enumKey, key = INVALID_HANDLE_VALUE;
3731 LONG l;
3733 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
3734 NULL, &enumKey, NULL);
3735 if (!l)
3737 RegOpenKeyExW(enumKey, devInfo->instanceId, 0, samDesired, &key);
3738 RegCloseKey(enumKey);
3740 return key;
3743 static HKEY SETUPDI_OpenDrvKey(struct DeviceInfo *devInfo, REGSAM samDesired)
3745 static const WCHAR slash[] = { '\\',0 };
3746 WCHAR classKeyPath[MAX_PATH];
3747 HKEY classKey, key = INVALID_HANDLE_VALUE;
3748 LONG l;
3750 lstrcpyW(classKeyPath, ControlClass);
3751 lstrcatW(classKeyPath, slash);
3752 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
3753 classKeyPath + lstrlenW(classKeyPath));
3754 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
3755 KEY_ALL_ACCESS, NULL, &classKey, NULL);
3756 if (!l)
3758 static const WCHAR fmt[] = { '%','0','4','u',0 };
3759 WCHAR devId[10];
3761 sprintfW(devId, fmt, devInfo->devId);
3762 l = RegOpenKeyExW(classKey, devId, 0, samDesired, &key);
3763 RegCloseKey(classKey);
3764 if (l)
3766 SetLastError(ERROR_KEY_DOES_NOT_EXIST);
3767 return INVALID_HANDLE_VALUE;
3770 return key;
3773 /***********************************************************************
3774 * SetupDiOpenDevRegKey (SETUPAPI.@)
3776 HKEY WINAPI SetupDiOpenDevRegKey(
3777 HDEVINFO DeviceInfoSet,
3778 PSP_DEVINFO_DATA DeviceInfoData,
3779 DWORD Scope,
3780 DWORD HwProfile,
3781 DWORD KeyType,
3782 REGSAM samDesired)
3784 struct DeviceInfoSet *set = DeviceInfoSet;
3785 struct DeviceInfo *devInfo;
3786 HKEY key = INVALID_HANDLE_VALUE;
3788 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet, DeviceInfoData,
3789 Scope, HwProfile, KeyType, samDesired);
3791 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3793 SetLastError(ERROR_INVALID_HANDLE);
3794 return INVALID_HANDLE_VALUE;
3796 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3798 SetLastError(ERROR_INVALID_HANDLE);
3799 return INVALID_HANDLE_VALUE;
3801 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3802 || !DeviceInfoData->Reserved)
3804 SetLastError(ERROR_INVALID_PARAMETER);
3805 return INVALID_HANDLE_VALUE;
3807 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
3809 SetLastError(ERROR_INVALID_FLAGS);
3810 return INVALID_HANDLE_VALUE;
3812 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV)
3814 SetLastError(ERROR_INVALID_FLAGS);
3815 return INVALID_HANDLE_VALUE;
3817 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3818 if (devInfo->set != set)
3820 SetLastError(ERROR_INVALID_PARAMETER);
3821 return INVALID_HANDLE_VALUE;
3823 if (devInfo->phantom)
3825 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
3826 return INVALID_HANDLE_VALUE;
3828 if (Scope != DICS_FLAG_GLOBAL)
3829 FIXME("unimplemented for scope %d\n", Scope);
3830 switch (KeyType)
3832 case DIREG_DEV:
3833 key = SETUPDI_OpenDevKey(devInfo, samDesired);
3834 break;
3835 case DIREG_DRV:
3836 key = SETUPDI_OpenDrvKey(devInfo, samDesired);
3837 break;
3838 default:
3839 WARN("unknown KeyType %d\n", KeyType);
3841 return key;
3844 static BOOL SETUPDI_DeleteDevKey(struct DeviceInfo *devInfo)
3846 HKEY enumKey;
3847 BOOL ret = FALSE;
3848 LONG l;
3850 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
3851 NULL, &enumKey, NULL);
3852 if (!l)
3854 ret = RegDeleteTreeW(enumKey, devInfo->instanceId);
3855 RegCloseKey(enumKey);
3857 else
3858 SetLastError(l);
3859 return ret;
3862 static BOOL SETUPDI_DeleteDrvKey(struct DeviceInfo *devInfo)
3864 static const WCHAR slash[] = { '\\',0 };
3865 WCHAR classKeyPath[MAX_PATH];
3866 HKEY classKey;
3867 LONG l;
3868 BOOL ret = FALSE;
3870 lstrcpyW(classKeyPath, ControlClass);
3871 lstrcatW(classKeyPath, slash);
3872 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
3873 classKeyPath + lstrlenW(classKeyPath));
3874 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
3875 KEY_ALL_ACCESS, NULL, &classKey, NULL);
3876 if (!l)
3878 static const WCHAR fmt[] = { '%','0','4','u',0 };
3879 WCHAR devId[10];
3881 sprintfW(devId, fmt, devInfo->devId);
3882 ret = RegDeleteTreeW(classKey, devId);
3883 RegCloseKey(classKey);
3885 else
3886 SetLastError(l);
3887 return ret;
3890 /***********************************************************************
3891 * SetupDiDeleteDevRegKey (SETUPAPI.@)
3893 BOOL WINAPI SetupDiDeleteDevRegKey(
3894 HDEVINFO DeviceInfoSet,
3895 PSP_DEVINFO_DATA DeviceInfoData,
3896 DWORD Scope,
3897 DWORD HwProfile,
3898 DWORD KeyType)
3900 struct DeviceInfoSet *set = DeviceInfoSet;
3901 struct DeviceInfo *devInfo;
3902 BOOL ret = FALSE;
3904 TRACE("%p %p %d %d %d\n", DeviceInfoSet, DeviceInfoData, Scope, HwProfile,
3905 KeyType);
3907 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3909 SetLastError(ERROR_INVALID_HANDLE);
3910 return FALSE;
3912 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3914 SetLastError(ERROR_INVALID_HANDLE);
3915 return FALSE;
3917 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3918 || !DeviceInfoData->Reserved)
3920 SetLastError(ERROR_INVALID_PARAMETER);
3921 return FALSE;
3923 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
3925 SetLastError(ERROR_INVALID_FLAGS);
3926 return FALSE;
3928 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV && KeyType != DIREG_BOTH)
3930 SetLastError(ERROR_INVALID_FLAGS);
3931 return FALSE;
3933 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3934 if (devInfo->set != set)
3936 SetLastError(ERROR_INVALID_PARAMETER);
3937 return FALSE;
3939 if (devInfo->phantom)
3941 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
3942 return FALSE;
3944 if (Scope != DICS_FLAG_GLOBAL)
3945 FIXME("unimplemented for scope %d\n", Scope);
3946 switch (KeyType)
3948 case DIREG_DEV:
3949 ret = SETUPDI_DeleteDevKey(devInfo);
3950 break;
3951 case DIREG_DRV:
3952 ret = SETUPDI_DeleteDrvKey(devInfo);
3953 break;
3954 case DIREG_BOTH:
3955 ret = SETUPDI_DeleteDevKey(devInfo);
3956 if (ret)
3957 ret = SETUPDI_DeleteDrvKey(devInfo);
3958 break;
3959 default:
3960 WARN("unknown KeyType %d\n", KeyType);
3962 return ret;
3965 /***********************************************************************
3966 * CM_Get_Device_IDA (SETUPAPI.@)
3968 CONFIGRET WINAPI CM_Get_Device_IDA( DEVINST dnDevInst, PSTR Buffer,
3969 ULONG BufferLen, ULONG ulFlags)
3971 struct DeviceInfo *devInfo = GlobalLock((HANDLE)dnDevInst);
3973 TRACE("%x->%p, %p, %u %u\n", dnDevInst, devInfo, Buffer, BufferLen, ulFlags);
3975 if (!devInfo)
3976 return CR_NO_SUCH_DEVINST;
3978 WideCharToMultiByte(CP_ACP, 0, devInfo->instanceId, -1, Buffer, BufferLen, 0, 0);
3979 TRACE("Returning %s\n", debugstr_a(Buffer));
3980 return CR_SUCCESS;
3983 /***********************************************************************
3984 * CM_Get_Device_IDW (SETUPAPI.@)
3986 CONFIGRET WINAPI CM_Get_Device_IDW( DEVINST dnDevInst, LPWSTR Buffer,
3987 ULONG BufferLen, ULONG ulFlags)
3989 struct DeviceInfo *devInfo = GlobalLock((HANDLE)dnDevInst);
3991 TRACE("%x->%p, %p, %u %u\n", dnDevInst, devInfo, Buffer, BufferLen, ulFlags);
3993 if (!devInfo)
3995 WARN("dev instance %d not found!\n", dnDevInst);
3996 return CR_NO_SUCH_DEVINST;
3999 lstrcpynW(Buffer, devInfo->instanceId, BufferLen);
4000 TRACE("Returning %s\n", debugstr_w(Buffer));
4001 GlobalUnlock((HANDLE)dnDevInst);
4002 return CR_SUCCESS;
4007 /***********************************************************************
4008 * CM_Get_Device_ID_Size (SETUPAPI.@)
4010 CONFIGRET WINAPI CM_Get_Device_ID_Size( PULONG pulLen, DEVINST dnDevInst,
4011 ULONG ulFlags)
4013 struct DeviceInfo *ppdevInfo = GlobalLock((HANDLE)dnDevInst);
4015 TRACE("%x->%p, %p, %u\n", dnDevInst, ppdevInfo, pulLen, ulFlags);
4017 if (!ppdevInfo)
4019 WARN("dev instance %d not found!\n", dnDevInst);
4020 return CR_NO_SUCH_DEVINST;
4023 *pulLen = lstrlenW(ppdevInfo->instanceId);
4024 GlobalUnlock((HANDLE)dnDevInst);
4025 return CR_SUCCESS;
4028 /***********************************************************************
4029 * SetupDiGetINFClassA (SETUPAPI.@)
4031 BOOL WINAPI SetupDiGetINFClassA(PCSTR inf, LPGUID class_guid, PSTR class_name,
4032 DWORD size, PDWORD required_size)
4034 BOOL retval;
4035 DWORD required_sizeA, required_sizeW;
4036 PWSTR class_nameW = NULL;
4037 UNICODE_STRING infW;
4039 if (inf)
4041 if (!RtlCreateUnicodeStringFromAsciiz(&infW, inf))
4043 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
4044 return FALSE;
4047 else
4048 infW.Buffer = NULL;
4050 if (class_name && size)
4052 if (!(class_nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR))))
4054 RtlFreeUnicodeString(&infW);
4055 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
4056 return FALSE;
4060 retval = SetupDiGetINFClassW(infW.Buffer, class_guid, class_nameW, size, &required_sizeW);
4062 if (retval)
4064 required_sizeA = WideCharToMultiByte( CP_ACP, 0, class_nameW, required_sizeW,
4065 class_name, size, NULL, NULL);
4067 if(required_size) *required_size = required_sizeA;
4069 else
4070 if(required_size) *required_size = required_sizeW;
4072 HeapFree(GetProcessHeap(), 0, class_nameW);
4073 RtlFreeUnicodeString(&infW);
4074 return retval;
4077 /***********************************************************************
4078 * SetupDiGetINFClassW (SETUPAPI.@)
4080 BOOL WINAPI SetupDiGetINFClassW(PCWSTR inf, LPGUID class_guid, PWSTR class_name,
4081 DWORD size, PDWORD required_size)
4083 BOOL have_guid, have_name;
4084 DWORD dret;
4085 WCHAR buffer[MAX_PATH];
4087 if (!inf)
4089 SetLastError(ERROR_INVALID_PARAMETER);
4090 return FALSE;
4093 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(inf))
4095 FIXME("%s not found. Searching via DevicePath not implemented\n", debugstr_w(inf));
4096 SetLastError(ERROR_FILE_NOT_FOUND);
4097 return FALSE;
4100 if (!class_guid || !class_name || !size)
4102 SetLastError(ERROR_INVALID_PARAMETER);
4103 return FALSE;
4106 if (!GetPrivateProfileStringW(Version, Signature, NULL, buffer, MAX_PATH, inf))
4107 return FALSE;
4109 if (lstrcmpiW(buffer, Chicago) && lstrcmpiW(buffer, WindowsNT))
4110 return FALSE;
4112 buffer[0] = '\0';
4113 have_guid = 0 < GetPrivateProfileStringW(Version, ClassGUID, NULL, buffer, MAX_PATH, inf);
4114 if (have_guid)
4116 buffer[lstrlenW(buffer)-1] = 0;
4117 if (RPC_S_OK != UuidFromStringW(buffer + 1, class_guid))
4119 FIXME("failed to convert \"%s\" into a guid\n", debugstr_w(buffer));
4120 SetLastError(ERROR_INVALID_PARAMETER);
4121 return FALSE;
4125 buffer[0] = '\0';
4126 dret = GetPrivateProfileStringW(Version, Class, NULL, buffer, MAX_PATH, inf);
4127 have_name = 0 < dret;
4129 if (dret >= MAX_PATH -1) FIXME("buffer might be too small\n");
4130 if (have_guid && !have_name) FIXME("class name lookup via guid not implemented\n");
4132 if (have_name)
4134 if (dret < size) lstrcpyW(class_name, buffer);
4135 else
4137 SetLastError(ERROR_INSUFFICIENT_BUFFER);
4138 have_name = FALSE;
4142 if (required_size) *required_size = dret + ((dret) ? 1 : 0);
4144 return (have_guid || have_name);