mshtml: Use get_elem_attr_value helper in npplugin.c.
[wine.git] / dlls / setupapi / devinst.c
blobef56d2be30085457a6e00dc1c420edcac2744659
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 devInst,
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), devInst,
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 l = RegOpenKeyExW(interfacesKey, interfaceGuidStr, 0,
2136 KEY_READ, &interfaceKey);
2137 if (!l)
2139 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
2140 interfaceKey, &interfaceGuid, enumstr);
2141 RegCloseKey(interfaceKey);
2147 else
2149 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2150 * interface's key, so just pass that long
2152 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
2153 interfacesKey, guid, enumstr);
2155 RegCloseKey(interfacesKey);
2159 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet *set,
2160 LPCWSTR enumerator, LPCWSTR deviceName, HKEY deviceKey,
2161 const GUID *class, DWORD flags)
2163 DWORD i, len;
2164 WCHAR deviceInstance[MAX_PATH];
2165 LONG l = ERROR_SUCCESS;
2167 TRACE("%s %s\n", debugstr_w(enumerator), debugstr_w(deviceName));
2169 for (i = 0; !l; i++)
2171 len = sizeof(deviceInstance) / sizeof(deviceInstance[0]);
2172 l = RegEnumKeyExW(deviceKey, i, deviceInstance, &len, NULL, NULL, NULL,
2173 NULL);
2174 if (!l)
2176 HKEY subKey;
2178 l = RegOpenKeyExW(deviceKey, deviceInstance, 0, KEY_READ, &subKey);
2179 if (!l)
2181 WCHAR classGuid[40];
2182 DWORD dataType;
2184 len = sizeof(classGuid);
2185 l = RegQueryValueExW(subKey, ClassGUID, NULL, &dataType,
2186 (BYTE *)classGuid, &len);
2187 if (!l && dataType == REG_SZ)
2189 if (classGuid[0] == '{' && classGuid[37] == '}')
2191 GUID deviceClass;
2193 classGuid[37] = 0;
2194 UuidFromStringW(&classGuid[1], &deviceClass);
2195 if ((flags & DIGCF_ALLCLASSES) ||
2196 IsEqualGUID(class, &deviceClass))
2198 static const WCHAR fmt[] =
2199 {'%','s','\\','%','s','\\','%','s',0};
2200 LPWSTR instanceId;
2202 instanceId = HeapAlloc(GetProcessHeap(), 0,
2203 (lstrlenW(enumerator) + lstrlenW(deviceName) +
2204 lstrlenW(deviceInstance) + 3) * sizeof(WCHAR));
2205 if (instanceId)
2207 sprintfW(instanceId, fmt, enumerator,
2208 deviceName, deviceInstance);
2209 SETUPDI_AddDeviceToSet(set, &deviceClass,
2210 0 /* FIXME: DevInst */, instanceId,
2211 FALSE, NULL);
2212 HeapFree(GetProcessHeap(), 0, instanceId);
2217 RegCloseKey(subKey);
2219 /* Allow enumeration to continue */
2220 l = ERROR_SUCCESS;
2225 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet,
2226 LPCWSTR parent, HKEY key, const GUID *class, DWORD flags)
2228 struct DeviceInfoSet *set = DeviceInfoSet;
2229 DWORD i, len;
2230 WCHAR subKeyName[MAX_PATH];
2231 LONG l = ERROR_SUCCESS;
2233 TRACE("%s\n", debugstr_w(parent));
2235 for (i = 0; !l; i++)
2237 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2238 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2239 if (!l)
2241 HKEY subKey;
2243 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2244 if (!l)
2246 TRACE("%s\n", debugstr_w(subKeyName));
2247 SETUPDI_EnumerateMatchingDeviceInstances(set, parent,
2248 subKeyName, subKey, class, flags);
2249 RegCloseKey(subKey);
2251 /* Allow enumeration to continue */
2252 l = ERROR_SUCCESS;
2257 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet, const GUID *class,
2258 LPCWSTR enumstr, DWORD flags)
2260 HKEY enumKey;
2261 LONG l;
2263 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(class),
2264 debugstr_w(enumstr), flags);
2266 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
2267 &enumKey, NULL);
2268 if (enumKey != INVALID_HANDLE_VALUE)
2270 if (enumstr)
2272 HKEY enumStrKey;
2274 l = RegOpenKeyExW(enumKey, enumstr, 0, KEY_READ,
2275 &enumStrKey);
2276 if (!l)
2278 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet, enumstr,
2279 enumStrKey, class, flags);
2280 RegCloseKey(enumStrKey);
2283 else
2285 DWORD i, len;
2286 WCHAR subKeyName[MAX_PATH];
2288 l = ERROR_SUCCESS;
2289 for (i = 0; !l; i++)
2291 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2292 l = RegEnumKeyExW(enumKey, i, subKeyName, &len, NULL,
2293 NULL, NULL, NULL);
2294 if (!l)
2296 HKEY subKey;
2298 l = RegOpenKeyExW(enumKey, subKeyName, 0, KEY_READ,
2299 &subKey);
2300 if (!l)
2302 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet,
2303 subKeyName, subKey, class, flags);
2304 RegCloseKey(subKey);
2306 /* Allow enumeration to continue */
2307 l = ERROR_SUCCESS;
2311 RegCloseKey(enumKey);
2315 /***********************************************************************
2316 * SetupDiGetClassDevsW (SETUPAPI.@)
2318 HDEVINFO WINAPI SetupDiGetClassDevsW(const GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
2320 return SetupDiGetClassDevsExW(class, enumstr, parent, flags, NULL, NULL,
2321 NULL);
2324 /***********************************************************************
2325 * SetupDiGetClassDevsExW (SETUPAPI.@)
2327 HDEVINFO WINAPI SetupDiGetClassDevsExW(const GUID *class, PCWSTR enumstr, HWND parent, DWORD flags,
2328 HDEVINFO deviceset, PCWSTR machine, void *reserved)
2330 static const DWORD unsupportedFlags = DIGCF_DEFAULT | DIGCF_PRESENT |
2331 DIGCF_PROFILE;
2332 HDEVINFO set;
2334 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2335 debugstr_w(enumstr), parent, flags, deviceset, debugstr_w(machine),
2336 reserved);
2338 if (!(flags & DIGCF_ALLCLASSES) && !class)
2340 SetLastError(ERROR_INVALID_PARAMETER);
2341 return NULL;
2343 if (flags & unsupportedFlags)
2344 WARN("unsupported flags %08x\n", flags & unsupportedFlags);
2345 if (deviceset)
2346 set = deviceset;
2347 else
2348 set = SetupDiCreateDeviceInfoListExW(class, parent, machine, reserved);
2349 if (set)
2351 if (machine && *machine)
2352 FIXME("%s: unimplemented for remote machines\n",
2353 debugstr_w(machine));
2354 else if (flags & DIGCF_DEVICEINTERFACE)
2355 SETUPDI_EnumerateInterfaces(set, class, enumstr, flags);
2356 else
2357 SETUPDI_EnumerateDevices(set, class, enumstr, flags);
2359 return set;
2362 /***********************************************************************
2363 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2365 BOOL WINAPI SetupDiGetDeviceInfoListDetailA(
2366 HDEVINFO DeviceInfoSet,
2367 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData )
2369 struct DeviceInfoSet *set = DeviceInfoSet;
2371 TRACE("%p %p\n", DeviceInfoSet, DevInfoData);
2373 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2375 SetLastError(ERROR_INVALID_HANDLE);
2376 return FALSE;
2378 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2380 SetLastError(ERROR_INVALID_HANDLE);
2381 return FALSE;
2383 if (!DevInfoData ||
2384 DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A))
2386 SetLastError(ERROR_INVALID_PARAMETER);
2387 return FALSE;
2389 DevInfoData->ClassGuid = set->ClassGuid;
2390 DevInfoData->RemoteMachineHandle = NULL;
2391 DevInfoData->RemoteMachineName[0] = '\0';
2392 return TRUE;
2395 /***********************************************************************
2396 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2398 BOOL WINAPI SetupDiGetDeviceInfoListDetailW(
2399 HDEVINFO DeviceInfoSet,
2400 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData )
2402 struct DeviceInfoSet *set = DeviceInfoSet;
2404 TRACE("%p %p\n", DeviceInfoSet, DevInfoData);
2406 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2408 SetLastError(ERROR_INVALID_HANDLE);
2409 return FALSE;
2411 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2413 SetLastError(ERROR_INVALID_HANDLE);
2414 return FALSE;
2416 if (!DevInfoData ||
2417 DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W))
2419 SetLastError(ERROR_INVALID_PARAMETER);
2420 return FALSE;
2422 DevInfoData->ClassGuid = set->ClassGuid;
2423 DevInfoData->RemoteMachineHandle = NULL;
2424 DevInfoData->RemoteMachineName[0] = '\0';
2425 return TRUE;
2428 /***********************************************************************
2429 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2431 BOOL WINAPI SetupDiCreateDeviceInterfaceA(
2432 HDEVINFO DeviceInfoSet,
2433 PSP_DEVINFO_DATA DeviceInfoData,
2434 const GUID *InterfaceClassGuid,
2435 PCSTR ReferenceString,
2436 DWORD CreationFlags,
2437 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2439 BOOL ret;
2440 LPWSTR ReferenceStringW = NULL;
2442 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
2443 debugstr_guid(InterfaceClassGuid), debugstr_a(ReferenceString),
2444 CreationFlags, DeviceInterfaceData);
2446 if (ReferenceString)
2448 ReferenceStringW = MultiByteToUnicode(ReferenceString, CP_ACP);
2449 if (ReferenceStringW == NULL) return FALSE;
2452 ret = SetupDiCreateDeviceInterfaceW(DeviceInfoSet, DeviceInfoData,
2453 InterfaceClassGuid, ReferenceStringW, CreationFlags,
2454 DeviceInterfaceData);
2456 MyFree(ReferenceStringW);
2458 return ret;
2461 /***********************************************************************
2462 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2464 BOOL WINAPI SetupDiCreateDeviceInterfaceW(
2465 HDEVINFO DeviceInfoSet,
2466 PSP_DEVINFO_DATA DeviceInfoData,
2467 const GUID *InterfaceClassGuid,
2468 PCWSTR ReferenceString,
2469 DWORD CreationFlags,
2470 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2472 struct DeviceInfoSet *set = DeviceInfoSet;
2473 struct DeviceInfo *devInfo;
2474 SP_DEVICE_INTERFACE_DATA *iface = NULL;
2475 BOOL ret;
2477 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
2478 debugstr_guid(InterfaceClassGuid), debugstr_w(ReferenceString),
2479 CreationFlags, DeviceInterfaceData);
2481 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2483 SetLastError(ERROR_INVALID_HANDLE);
2484 return FALSE;
2486 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2488 SetLastError(ERROR_INVALID_HANDLE);
2489 return FALSE;
2491 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
2492 || !DeviceInfoData->Reserved)
2494 SetLastError(ERROR_INVALID_PARAMETER);
2495 return FALSE;
2497 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
2498 if (devInfo->set != set)
2500 SetLastError(ERROR_INVALID_PARAMETER);
2501 return FALSE;
2503 if (!InterfaceClassGuid)
2505 SetLastError(ERROR_INVALID_USER_BUFFER);
2506 return FALSE;
2508 if ((ret = SETUPDI_AddInterfaceInstance(DeviceInfoData, InterfaceClassGuid,
2509 ReferenceString, &iface)))
2511 if (DeviceInterfaceData)
2513 if (DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
2515 SetLastError(ERROR_INVALID_USER_BUFFER);
2516 ret = FALSE;
2518 else
2519 *DeviceInterfaceData = *iface;
2522 return ret;
2525 /***********************************************************************
2526 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2528 HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyA(
2529 HDEVINFO DeviceInfoSet,
2530 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2531 DWORD Reserved,
2532 REGSAM samDesired,
2533 HINF InfHandle,
2534 PCSTR InfSectionName)
2536 HKEY key;
2537 PWSTR InfSectionNameW = NULL;
2539 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
2540 samDesired, InfHandle, InfSectionName);
2541 if (InfHandle)
2543 if (!InfSectionName)
2545 SetLastError(ERROR_INVALID_PARAMETER);
2546 return INVALID_HANDLE_VALUE;
2548 InfSectionNameW = MultiByteToUnicode(InfSectionName, CP_ACP);
2549 if (!InfSectionNameW)
2550 return INVALID_HANDLE_VALUE;
2552 key = SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet,
2553 DeviceInterfaceData, Reserved, samDesired, InfHandle,
2554 InfSectionNameW);
2555 MyFree(InfSectionNameW);
2556 return key;
2559 static PWSTR SETUPDI_GetInstancePath(struct InterfaceInfo *ifaceInfo)
2561 static const WCHAR hash[] = {'#',0};
2562 PWSTR instancePath = NULL;
2564 if (ifaceInfo->referenceString)
2566 instancePath = HeapAlloc(GetProcessHeap(), 0,
2567 (lstrlenW(ifaceInfo->referenceString) + 2) * sizeof(WCHAR));
2568 if (instancePath)
2570 lstrcpyW(instancePath, hash);
2571 lstrcatW(instancePath, ifaceInfo->referenceString);
2573 else
2574 SetLastError(ERROR_OUTOFMEMORY);
2576 else
2578 instancePath = HeapAlloc(GetProcessHeap(), 0,
2579 (lstrlenW(hash) + 1) * sizeof(WCHAR));
2580 if (instancePath)
2581 lstrcpyW(instancePath, hash);
2583 return instancePath;
2586 /***********************************************************************
2587 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2589 HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyW(
2590 HDEVINFO DeviceInfoSet,
2591 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2592 DWORD Reserved,
2593 REGSAM samDesired,
2594 HINF InfHandle,
2595 PCWSTR InfSectionName)
2597 struct DeviceInfoSet *set = DeviceInfoSet;
2598 HKEY key = INVALID_HANDLE_VALUE, interfacesKey;
2599 LONG l;
2601 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
2602 samDesired, InfHandle, InfSectionName);
2604 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2605 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2607 SetLastError(ERROR_INVALID_HANDLE);
2608 return INVALID_HANDLE_VALUE;
2610 if (!DeviceInterfaceData ||
2611 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2612 !DeviceInterfaceData->Reserved)
2614 SetLastError(ERROR_INVALID_PARAMETER);
2615 return INVALID_HANDLE_VALUE;
2617 if (InfHandle && !InfSectionName)
2619 SetLastError(ERROR_INVALID_PARAMETER);
2620 return INVALID_HANDLE_VALUE;
2622 if (!(l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, DeviceClasses, 0, NULL, 0,
2623 samDesired, NULL, &interfacesKey, NULL)))
2625 HKEY parent;
2626 WCHAR bracedGuidString[39];
2628 SETUPDI_GuidToString(&DeviceInterfaceData->InterfaceClassGuid,
2629 bracedGuidString);
2630 if (!(l = RegCreateKeyExW(interfacesKey, bracedGuidString, 0, NULL, 0,
2631 samDesired, NULL, &parent, NULL)))
2633 struct InterfaceInfo *ifaceInfo =
2634 (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2635 PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo);
2636 PWSTR interfKeyName = HeapAlloc(GetProcessHeap(), 0,
2637 (lstrlenW(ifaceInfo->symbolicLink) + 1) * sizeof(WCHAR));
2638 HKEY interfKey;
2639 WCHAR *ptr;
2641 lstrcpyW(interfKeyName, ifaceInfo->symbolicLink);
2642 if (lstrlenW(ifaceInfo->symbolicLink) > 3)
2644 interfKeyName[0] = '#';
2645 interfKeyName[1] = '#';
2646 interfKeyName[3] = '#';
2648 ptr = strchrW(interfKeyName, '\\');
2649 if (ptr)
2650 *ptr = 0;
2651 l = RegCreateKeyExW(parent, interfKeyName, 0, NULL, 0,
2652 samDesired, NULL, &interfKey, NULL);
2653 if (!l)
2655 struct DeviceInfo *devInfo =
2656 (struct DeviceInfo *)ifaceInfo->device->Reserved;
2658 l = RegSetValueExW(interfKey, DeviceInstance, 0, REG_SZ,
2659 (BYTE *)devInfo->instanceId,
2660 (lstrlenW(devInfo->instanceId) + 1) * sizeof(WCHAR));
2661 if (!l)
2663 if (instancePath)
2665 LONG l;
2667 l = RegCreateKeyExW(interfKey, instancePath, 0, NULL, 0,
2668 samDesired, NULL, &key, NULL);
2669 if (l)
2671 SetLastError(l);
2672 key = INVALID_HANDLE_VALUE;
2674 else if (InfHandle)
2675 FIXME("INF section installation unsupported\n");
2678 else
2679 SetLastError(l);
2680 RegCloseKey(interfKey);
2682 else
2683 SetLastError(l);
2684 HeapFree(GetProcessHeap(), 0, interfKeyName);
2685 HeapFree(GetProcessHeap(), 0, instancePath);
2686 RegCloseKey(parent);
2688 else
2689 SetLastError(l);
2690 RegCloseKey(interfacesKey);
2692 else
2693 SetLastError(l);
2694 return key;
2697 /***********************************************************************
2698 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2700 BOOL WINAPI SetupDiDeleteDeviceInterfaceRegKey(
2701 HDEVINFO DeviceInfoSet,
2702 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2703 DWORD Reserved)
2705 struct DeviceInfoSet *set = DeviceInfoSet;
2706 HKEY parent;
2707 BOOL ret = FALSE;
2709 TRACE("%p %p %d\n", DeviceInfoSet, DeviceInterfaceData, Reserved);
2711 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2712 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2714 SetLastError(ERROR_INVALID_HANDLE);
2715 return FALSE;
2717 if (!DeviceInterfaceData ||
2718 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2719 !DeviceInterfaceData->Reserved)
2721 SetLastError(ERROR_INVALID_PARAMETER);
2722 return FALSE;
2724 parent = SetupDiOpenClassRegKeyExW(&DeviceInterfaceData->InterfaceClassGuid,
2725 KEY_ALL_ACCESS, DIOCR_INTERFACE, NULL, NULL);
2726 if (parent != INVALID_HANDLE_VALUE)
2728 struct InterfaceInfo *ifaceInfo =
2729 (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2730 PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo);
2732 if (instancePath)
2734 LONG l = RegDeleteKeyW(parent, instancePath);
2736 if (l)
2737 SetLastError(l);
2738 else
2739 ret = TRUE;
2740 HeapFree(GetProcessHeap(), 0, instancePath);
2742 RegCloseKey(parent);
2744 return ret;
2747 /***********************************************************************
2748 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2750 * PARAMS
2751 * DeviceInfoSet [I] Set of devices from which to enumerate
2752 * interfaces
2753 * DeviceInfoData [I] (Optional) If specified, a specific device
2754 * instance from which to enumerate interfaces.
2755 * If it isn't specified, all interfaces for all
2756 * devices in the set are enumerated.
2757 * InterfaceClassGuid [I] The interface class to enumerate.
2758 * MemberIndex [I] An index of the interface instance to enumerate.
2759 * A caller should start with MemberIndex set to 0,
2760 * and continue until the function fails with
2761 * ERROR_NO_MORE_ITEMS.
2762 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2763 * member must be set to
2764 * sizeof(SP_DEVICE_INTERFACE_DATA).
2766 * RETURNS
2767 * Success: non-zero value.
2768 * Failure: FALSE. Call GetLastError() for more info.
2770 BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData,
2771 const GUID *InterfaceClassGuid, DWORD MemberIndex,
2772 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2774 struct DeviceInfoSet *set = DeviceInfoSet;
2775 BOOL ret = FALSE;
2777 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet, DeviceInfoData,
2778 debugstr_guid(InterfaceClassGuid), MemberIndex, DeviceInterfaceData);
2780 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2781 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2783 SetLastError(ERROR_INVALID_HANDLE);
2784 return FALSE;
2786 if (DeviceInfoData && (DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) ||
2787 !DeviceInfoData->Reserved))
2789 SetLastError(ERROR_INVALID_PARAMETER);
2790 return FALSE;
2792 if (!DeviceInterfaceData ||
2793 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
2795 SetLastError(ERROR_INVALID_PARAMETER);
2796 return FALSE;
2799 /* In case application fails to check return value, clear output */
2800 memset(DeviceInterfaceData, 0, sizeof(*DeviceInterfaceData));
2801 DeviceInterfaceData->cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
2803 if (DeviceInfoData)
2805 struct DeviceInfo *devInfo =
2806 (struct DeviceInfo *)DeviceInfoData->Reserved;
2807 struct InterfaceInstances *iface;
2809 if ((ret = SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface)))
2811 if (MemberIndex < iface->cInstances)
2812 *DeviceInterfaceData = iface->instances[MemberIndex];
2813 else
2815 SetLastError(ERROR_NO_MORE_ITEMS);
2816 ret = FALSE;
2819 else
2820 SetLastError(ERROR_NO_MORE_ITEMS);
2822 else
2824 struct DeviceInstance *devInst;
2825 DWORD cEnumerated = 0;
2826 BOOL found = FALSE;
2828 LIST_FOR_EACH_ENTRY(devInst, &set->devices, struct DeviceInstance, entry)
2830 struct DeviceInfo *devInfo = (struct DeviceInfo *)devInst->data.Reserved;
2831 struct InterfaceInstances *iface;
2833 if (found || cEnumerated >= MemberIndex + 1)
2834 break;
2835 if (SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface))
2837 if (cEnumerated + iface->cInstances < MemberIndex + 1)
2838 cEnumerated += iface->cInstances;
2839 else
2841 DWORD instanceIndex = MemberIndex - cEnumerated;
2843 *DeviceInterfaceData = iface->instances[instanceIndex];
2844 cEnumerated += instanceIndex + 1;
2845 found = TRUE;
2846 ret = TRUE;
2850 if (!found)
2851 SetLastError(ERROR_NO_MORE_ITEMS);
2853 return ret;
2856 /***********************************************************************
2857 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2859 * Destroy a DeviceInfoList and free all used memory of the list.
2861 * PARAMS
2862 * devinfo [I] DeviceInfoList pointer to list to destroy
2864 * RETURNS
2865 * Success: non zero value.
2866 * Failure: zero value.
2868 BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
2870 BOOL ret = FALSE;
2872 TRACE("%p\n", devinfo);
2873 if (devinfo && devinfo != INVALID_HANDLE_VALUE)
2875 struct DeviceInfoSet *list = devinfo;
2877 if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC)
2879 struct DeviceInstance *devInst, *devInst2;
2881 LIST_FOR_EACH_ENTRY_SAFE(devInst, devInst2, &list->devices,
2882 struct DeviceInstance, entry)
2884 SETUPDI_FreeDeviceInfo( (struct DeviceInfo *)devInst->data.Reserved );
2885 list_remove(&devInst->entry);
2886 HeapFree(GetProcessHeap(), 0, devInst);
2888 HeapFree(GetProcessHeap(), 0, list);
2889 ret = TRUE;
2893 if (!ret)
2894 SetLastError(ERROR_INVALID_HANDLE);
2896 return ret;
2899 /***********************************************************************
2900 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2902 BOOL WINAPI SetupDiGetDeviceInterfaceDetailA(
2903 HDEVINFO DeviceInfoSet,
2904 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2905 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData,
2906 DWORD DeviceInterfaceDetailDataSize,
2907 PDWORD RequiredSize,
2908 PSP_DEVINFO_DATA DeviceInfoData)
2910 struct DeviceInfoSet *set = DeviceInfoSet;
2911 struct InterfaceInfo *info;
2912 DWORD bytesNeeded = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath[1]);
2913 BOOL ret = FALSE;
2915 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet,
2916 DeviceInterfaceData, DeviceInterfaceDetailData,
2917 DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
2919 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2920 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2922 SetLastError(ERROR_INVALID_HANDLE);
2923 return FALSE;
2925 if (!DeviceInterfaceData ||
2926 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2927 !DeviceInterfaceData->Reserved)
2929 SetLastError(ERROR_INVALID_PARAMETER);
2930 return FALSE;
2932 if (DeviceInterfaceDetailData &&
2933 DeviceInterfaceDetailData->cbSize != sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A))
2935 SetLastError(ERROR_INVALID_USER_BUFFER);
2936 return FALSE;
2938 if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
2940 SetLastError(ERROR_INVALID_USER_BUFFER);
2941 return FALSE;
2943 info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2944 if (info->symbolicLink)
2945 bytesNeeded += WideCharToMultiByte(CP_ACP, 0, info->symbolicLink, -1,
2946 NULL, 0, NULL, NULL);
2947 if (DeviceInterfaceDetailDataSize >= bytesNeeded)
2949 if (info->symbolicLink)
2950 WideCharToMultiByte(CP_ACP, 0, info->symbolicLink, -1,
2951 DeviceInterfaceDetailData->DevicePath,
2952 DeviceInterfaceDetailDataSize -
2953 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath),
2954 NULL, NULL);
2955 else
2956 DeviceInterfaceDetailData->DevicePath[0] = '\0';
2957 if (DeviceInfoData && DeviceInfoData->cbSize == sizeof(SP_DEVINFO_DATA))
2958 *DeviceInfoData = *info->device;
2959 ret = TRUE;
2961 else
2963 if (RequiredSize)
2964 *RequiredSize = bytesNeeded;
2965 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2967 return ret;
2970 /***********************************************************************
2971 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2973 BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(
2974 HDEVINFO DeviceInfoSet,
2975 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2976 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData,
2977 DWORD DeviceInterfaceDetailDataSize,
2978 PDWORD RequiredSize,
2979 PSP_DEVINFO_DATA DeviceInfoData)
2981 struct DeviceInfoSet *set = DeviceInfoSet;
2982 struct InterfaceInfo *info;
2983 DWORD bytesNeeded = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath)
2984 + sizeof(WCHAR); /* include NULL terminator */
2985 BOOL ret = FALSE;
2987 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet,
2988 DeviceInterfaceData, DeviceInterfaceDetailData,
2989 DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
2991 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2992 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2994 SetLastError(ERROR_INVALID_HANDLE);
2995 return FALSE;
2997 if (!DeviceInterfaceData ||
2998 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2999 !DeviceInterfaceData->Reserved)
3001 SetLastError(ERROR_INVALID_PARAMETER);
3002 return FALSE;
3004 if (DeviceInterfaceDetailData && (DeviceInterfaceDetailData->cbSize <
3005 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR) ||
3006 DeviceInterfaceDetailData->cbSize > sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W)))
3008 SetLastError(ERROR_INVALID_USER_BUFFER);
3009 return FALSE;
3011 if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
3013 SetLastError(ERROR_INVALID_USER_BUFFER);
3014 return FALSE;
3016 info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
3017 if (info->symbolicLink)
3018 bytesNeeded += sizeof(WCHAR)*lstrlenW(info->symbolicLink);
3019 if (DeviceInterfaceDetailDataSize >= bytesNeeded)
3021 if (info->symbolicLink)
3022 lstrcpyW(DeviceInterfaceDetailData->DevicePath, info->symbolicLink);
3023 else
3024 DeviceInterfaceDetailData->DevicePath[0] = '\0';
3025 if (DeviceInfoData && DeviceInfoData->cbSize == sizeof(SP_DEVINFO_DATA))
3026 *DeviceInfoData = *info->device;
3027 ret = TRUE;
3029 else
3031 if (RequiredSize)
3032 *RequiredSize = bytesNeeded;
3033 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3035 return ret;
3038 struct PropertyMapEntry
3040 DWORD regType;
3041 LPCSTR nameA;
3042 LPCWSTR nameW;
3045 static const struct PropertyMapEntry PropertyMap[] = {
3046 { REG_SZ, "DeviceDesc", DeviceDesc },
3047 { REG_MULTI_SZ, "HardwareId", HardwareId },
3048 { REG_MULTI_SZ, "CompatibleIDs", CompatibleIDs },
3049 { 0, NULL, NULL }, /* SPDRP_UNUSED0 */
3050 { REG_SZ, "Service", Service },
3051 { 0, NULL, NULL }, /* SPDRP_UNUSED1 */
3052 { 0, NULL, NULL }, /* SPDRP_UNUSED2 */
3053 { REG_SZ, "Class", Class },
3054 { REG_SZ, "ClassGUID", ClassGUID },
3055 { REG_SZ, "Driver", Driver },
3056 { REG_DWORD, "ConfigFlags", ConfigFlags },
3057 { REG_SZ, "Mfg", Mfg },
3058 { REG_SZ, "FriendlyName", FriendlyName },
3059 { REG_SZ, "LocationInformation", LocationInformation },
3060 { 0, NULL, NULL }, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3061 { REG_DWORD, "Capabilities", Capabilities },
3062 { REG_DWORD, "UINumber", UINumber },
3063 { REG_MULTI_SZ, "UpperFilters", UpperFilters },
3064 { REG_MULTI_SZ, "LowerFilters", LowerFilters },
3067 /***********************************************************************
3068 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3070 BOOL WINAPI SetupDiGetDeviceRegistryPropertyA(
3071 HDEVINFO DeviceInfoSet,
3072 PSP_DEVINFO_DATA DeviceInfoData,
3073 DWORD Property,
3074 PDWORD PropertyRegDataType,
3075 PBYTE PropertyBuffer,
3076 DWORD PropertyBufferSize,
3077 PDWORD RequiredSize)
3079 BOOL ret = FALSE;
3080 struct DeviceInfoSet *set = DeviceInfoSet;
3081 struct DeviceInfo *devInfo;
3083 TRACE("%04x %p %d %p %p %d %p\n", (DWORD)DeviceInfoSet, DeviceInfoData,
3084 Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize,
3085 RequiredSize);
3087 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3089 SetLastError(ERROR_INVALID_HANDLE);
3090 return FALSE;
3092 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3094 SetLastError(ERROR_INVALID_HANDLE);
3095 return FALSE;
3097 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3098 || !DeviceInfoData->Reserved)
3100 SetLastError(ERROR_INVALID_PARAMETER);
3101 return FALSE;
3103 if (PropertyBufferSize && PropertyBuffer == NULL)
3105 SetLastError(ERROR_INVALID_DATA);
3106 return FALSE;
3108 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3109 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3110 && PropertyMap[Property].nameA)
3112 DWORD size = PropertyBufferSize;
3113 LONG l = RegQueryValueExA(devInfo->key, PropertyMap[Property].nameA,
3114 NULL, PropertyRegDataType, PropertyBuffer, &size);
3116 if (l == ERROR_MORE_DATA || !PropertyBufferSize)
3117 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3118 else if (!l)
3119 ret = TRUE;
3120 else
3121 SetLastError(l);
3122 if (RequiredSize)
3123 *RequiredSize = size;
3125 return ret;
3128 /***********************************************************************
3129 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3131 BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(
3132 HDEVINFO DeviceInfoSet,
3133 PSP_DEVINFO_DATA DeviceInfoData,
3134 DWORD Property,
3135 PDWORD PropertyRegDataType,
3136 PBYTE PropertyBuffer,
3137 DWORD PropertyBufferSize,
3138 PDWORD RequiredSize)
3140 BOOL ret = FALSE;
3141 struct DeviceInfoSet *set = DeviceInfoSet;
3142 struct DeviceInfo *devInfo;
3144 TRACE("%04x %p %d %p %p %d %p\n", (DWORD)DeviceInfoSet, DeviceInfoData,
3145 Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize,
3146 RequiredSize);
3148 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3150 SetLastError(ERROR_INVALID_HANDLE);
3151 return FALSE;
3153 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3155 SetLastError(ERROR_INVALID_HANDLE);
3156 return FALSE;
3158 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3159 || !DeviceInfoData->Reserved)
3161 SetLastError(ERROR_INVALID_PARAMETER);
3162 return FALSE;
3164 if (PropertyBufferSize && PropertyBuffer == NULL)
3166 SetLastError(ERROR_INVALID_DATA);
3167 return FALSE;
3169 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3170 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3171 && PropertyMap[Property].nameW)
3173 DWORD size = PropertyBufferSize;
3174 LONG l = RegQueryValueExW(devInfo->key, PropertyMap[Property].nameW,
3175 NULL, PropertyRegDataType, PropertyBuffer, &size);
3177 if (l == ERROR_MORE_DATA || !PropertyBufferSize)
3178 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3179 else if (!l)
3180 ret = TRUE;
3181 else
3182 SetLastError(l);
3183 if (RequiredSize)
3184 *RequiredSize = size;
3186 return ret;
3189 /***********************************************************************
3190 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3192 BOOL WINAPI SetupDiSetDeviceRegistryPropertyA(
3193 HDEVINFO DeviceInfoSet,
3194 PSP_DEVINFO_DATA DeviceInfoData,
3195 DWORD Property,
3196 const BYTE *PropertyBuffer,
3197 DWORD PropertyBufferSize)
3199 BOOL ret = FALSE;
3200 struct DeviceInfoSet *set = DeviceInfoSet;
3201 struct DeviceInfo *devInfo;
3203 TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property,
3204 PropertyBuffer, PropertyBufferSize);
3206 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3208 SetLastError(ERROR_INVALID_HANDLE);
3209 return FALSE;
3211 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3213 SetLastError(ERROR_INVALID_HANDLE);
3214 return FALSE;
3216 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3217 || !DeviceInfoData->Reserved)
3219 SetLastError(ERROR_INVALID_PARAMETER);
3220 return FALSE;
3222 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3223 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3224 && PropertyMap[Property].nameA)
3226 LONG l = RegSetValueExA(devInfo->key, PropertyMap[Property].nameA, 0,
3227 PropertyMap[Property].regType, PropertyBuffer,
3228 PropertyBufferSize);
3229 if (!l)
3230 ret = TRUE;
3231 else
3232 SetLastError(l);
3234 return ret;
3237 /***********************************************************************
3238 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3240 BOOL WINAPI SetupDiSetDeviceRegistryPropertyW(
3241 HDEVINFO DeviceInfoSet,
3242 PSP_DEVINFO_DATA DeviceInfoData,
3243 DWORD Property,
3244 const BYTE *PropertyBuffer,
3245 DWORD PropertyBufferSize)
3247 BOOL ret = FALSE;
3248 struct DeviceInfoSet *set = DeviceInfoSet;
3249 struct DeviceInfo *devInfo;
3251 TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property,
3252 PropertyBuffer, PropertyBufferSize);
3254 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3256 SetLastError(ERROR_INVALID_HANDLE);
3257 return FALSE;
3259 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3261 SetLastError(ERROR_INVALID_HANDLE);
3262 return FALSE;
3264 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3265 || !DeviceInfoData->Reserved)
3267 SetLastError(ERROR_INVALID_PARAMETER);
3268 return FALSE;
3270 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3271 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3272 && PropertyMap[Property].nameW)
3274 LONG l = RegSetValueExW(devInfo->key, PropertyMap[Property].nameW, 0,
3275 PropertyMap[Property].regType, PropertyBuffer,
3276 PropertyBufferSize);
3277 if (!l)
3278 ret = TRUE;
3279 else
3280 SetLastError(l);
3282 return ret;
3285 /***********************************************************************
3286 * SetupDiInstallClassA (SETUPAPI.@)
3288 BOOL WINAPI SetupDiInstallClassA(
3289 HWND hwndParent,
3290 PCSTR InfFileName,
3291 DWORD Flags,
3292 HSPFILEQ FileQueue)
3294 UNICODE_STRING FileNameW;
3295 BOOL Result;
3297 if (!InfFileName)
3299 SetLastError(ERROR_INVALID_PARAMETER);
3300 return FALSE;
3302 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW, InfFileName))
3304 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
3305 return FALSE;
3308 Result = SetupDiInstallClassW(hwndParent, FileNameW.Buffer, Flags, FileQueue);
3310 RtlFreeUnicodeString(&FileNameW);
3312 return Result;
3315 static HKEY CreateClassKey(HINF hInf)
3317 static const WCHAR slash[] = { '\\',0 };
3318 WCHAR FullBuffer[MAX_PATH];
3319 WCHAR Buffer[MAX_PATH];
3320 DWORD RequiredSize;
3321 HKEY hClassKey;
3323 if (!SetupGetLineTextW(NULL,
3324 hInf,
3325 Version,
3326 ClassGUID,
3327 Buffer,
3328 MAX_PATH,
3329 &RequiredSize))
3331 return INVALID_HANDLE_VALUE;
3334 lstrcpyW(FullBuffer, ControlClass);
3335 lstrcatW(FullBuffer, slash);
3336 lstrcatW(FullBuffer, Buffer);
3338 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3339 FullBuffer,
3341 KEY_ALL_ACCESS,
3342 &hClassKey))
3344 if (!SetupGetLineTextW(NULL,
3345 hInf,
3346 Version,
3347 Class,
3348 Buffer,
3349 MAX_PATH,
3350 &RequiredSize))
3352 return INVALID_HANDLE_VALUE;
3355 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,
3356 FullBuffer,
3358 NULL,
3359 REG_OPTION_NON_VOLATILE,
3360 KEY_ALL_ACCESS,
3361 NULL,
3362 &hClassKey,
3363 NULL))
3365 return INVALID_HANDLE_VALUE;
3370 if (RegSetValueExW(hClassKey,
3371 Class,
3373 REG_SZ,
3374 (LPBYTE)Buffer,
3375 RequiredSize * sizeof(WCHAR)))
3377 RegCloseKey(hClassKey);
3378 RegDeleteKeyW(HKEY_LOCAL_MACHINE,
3379 FullBuffer);
3380 return INVALID_HANDLE_VALUE;
3383 return hClassKey;
3386 /***********************************************************************
3387 * SetupDiInstallClassW (SETUPAPI.@)
3389 BOOL WINAPI SetupDiInstallClassW(
3390 HWND hwndParent,
3391 PCWSTR InfFileName,
3392 DWORD Flags,
3393 HSPFILEQ FileQueue)
3395 WCHAR SectionName[MAX_PATH];
3396 DWORD SectionNameLength = 0;
3397 HINF hInf;
3398 BOOL bFileQueueCreated = FALSE;
3399 HKEY hClassKey;
3402 FIXME("\n");
3404 if (!InfFileName)
3406 SetLastError(ERROR_INVALID_PARAMETER);
3407 return FALSE;
3409 if ((Flags & DI_NOVCP) && (FileQueue == NULL || FileQueue == INVALID_HANDLE_VALUE))
3411 SetLastError(ERROR_INVALID_PARAMETER);
3412 return FALSE;
3415 /* Open the .inf file */
3416 hInf = SetupOpenInfFileW(InfFileName,
3417 NULL,
3418 INF_STYLE_WIN4,
3419 NULL);
3420 if (hInf == INVALID_HANDLE_VALUE)
3423 return FALSE;
3426 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3427 hClassKey = CreateClassKey(hInf);
3428 if (hClassKey == INVALID_HANDLE_VALUE)
3430 SetupCloseInfFile(hInf);
3431 return FALSE;
3435 /* Try to append a layout file */
3436 SetupOpenAppendInfFileW(NULL, hInf, NULL);
3438 /* Retrieve the actual section name */
3439 SetupDiGetActualSectionToInstallW(hInf,
3440 ClassInstall32,
3441 SectionName,
3442 MAX_PATH,
3443 &SectionNameLength,
3444 NULL);
3446 #if 0
3447 if (!(Flags & DI_NOVCP))
3449 FileQueue = SetupOpenFileQueue();
3450 if (FileQueue == INVALID_HANDLE_VALUE)
3452 SetupCloseInfFile(hInf);
3453 return FALSE;
3456 bFileQueueCreated = TRUE;
3459 #endif
3461 SetupInstallFromInfSectionW(NULL,
3462 hInf,
3463 SectionName,
3464 SPINST_COPYINF | SPINST_FILES | SPINST_REGISTRY,
3465 hClassKey,
3466 NULL,
3468 NULL,
3469 NULL,
3470 INVALID_HANDLE_VALUE,
3471 NULL);
3473 /* FIXME: More code! */
3475 if (bFileQueueCreated)
3476 SetupCloseFileQueue(FileQueue);
3478 SetupCloseInfFile(hInf);
3480 return TRUE;
3484 /***********************************************************************
3485 * SetupDiOpenClassRegKey (SETUPAPI.@)
3487 HKEY WINAPI SetupDiOpenClassRegKey(
3488 const GUID* ClassGuid,
3489 REGSAM samDesired)
3491 return SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
3492 DIOCR_INSTALLER, NULL, NULL);
3496 /***********************************************************************
3497 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3499 HKEY WINAPI SetupDiOpenClassRegKeyExA(
3500 const GUID* ClassGuid,
3501 REGSAM samDesired,
3502 DWORD Flags,
3503 PCSTR MachineName,
3504 PVOID Reserved)
3506 PWSTR MachineNameW = NULL;
3507 HKEY hKey;
3509 TRACE("\n");
3511 if (MachineName)
3513 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
3514 if (MachineNameW == NULL)
3515 return INVALID_HANDLE_VALUE;
3518 hKey = SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
3519 Flags, MachineNameW, Reserved);
3521 MyFree(MachineNameW);
3523 return hKey;
3527 /***********************************************************************
3528 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3530 HKEY WINAPI SetupDiOpenClassRegKeyExW(
3531 const GUID* ClassGuid,
3532 REGSAM samDesired,
3533 DWORD Flags,
3534 PCWSTR MachineName,
3535 PVOID Reserved)
3537 HKEY hClassesKey;
3538 HKEY key;
3539 LPCWSTR lpKeyName;
3540 LONG l;
3542 if (MachineName && *MachineName)
3544 FIXME("Remote access not supported yet!\n");
3545 return INVALID_HANDLE_VALUE;
3548 if (Flags == DIOCR_INSTALLER)
3550 lpKeyName = ControlClass;
3552 else if (Flags == DIOCR_INTERFACE)
3554 lpKeyName = DeviceClasses;
3556 else
3558 ERR("Invalid Flags parameter!\n");
3559 SetLastError(ERROR_INVALID_PARAMETER);
3560 return INVALID_HANDLE_VALUE;
3563 if (!ClassGuid)
3565 if ((l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3566 lpKeyName,
3568 samDesired,
3569 &hClassesKey)))
3571 SetLastError(l);
3572 hClassesKey = INVALID_HANDLE_VALUE;
3574 key = hClassesKey;
3576 else
3578 WCHAR bracedGuidString[39];
3580 SETUPDI_GuidToString(ClassGuid, bracedGuidString);
3582 if (!(l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3583 lpKeyName,
3585 samDesired,
3586 &hClassesKey)))
3588 if ((l = RegOpenKeyExW(hClassesKey,
3589 bracedGuidString,
3591 samDesired,
3592 &key)))
3594 SetLastError(l);
3595 key = INVALID_HANDLE_VALUE;
3597 RegCloseKey(hClassesKey);
3599 else
3601 SetLastError(l);
3602 key = INVALID_HANDLE_VALUE;
3605 return key;
3608 /***********************************************************************
3609 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3611 BOOL WINAPI SetupDiOpenDeviceInterfaceW(
3612 HDEVINFO DeviceInfoSet,
3613 PCWSTR DevicePath,
3614 DWORD OpenFlags,
3615 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
3617 FIXME("%p %s %08x %p\n",
3618 DeviceInfoSet, debugstr_w(DevicePath), OpenFlags, DeviceInterfaceData);
3619 return FALSE;
3622 /***********************************************************************
3623 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3625 BOOL WINAPI SetupDiOpenDeviceInterfaceA(
3626 HDEVINFO DeviceInfoSet,
3627 PCSTR DevicePath,
3628 DWORD OpenFlags,
3629 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
3631 FIXME("%p %s %08x %p\n", DeviceInfoSet,
3632 debugstr_a(DevicePath), OpenFlags, DeviceInterfaceData);
3633 return FALSE;
3636 /***********************************************************************
3637 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3639 BOOL WINAPI SetupDiSetClassInstallParamsA(
3640 HDEVINFO DeviceInfoSet,
3641 PSP_DEVINFO_DATA DeviceInfoData,
3642 PSP_CLASSINSTALL_HEADER ClassInstallParams,
3643 DWORD ClassInstallParamsSize)
3645 FIXME("%p %p %x %u\n",DeviceInfoSet, DeviceInfoData,
3646 ClassInstallParams->InstallFunction, ClassInstallParamsSize);
3647 return FALSE;
3650 /***********************************************************************
3651 * SetupDiCallClassInstaller (SETUPAPI.@)
3653 BOOL WINAPI SetupDiCallClassInstaller(
3654 DI_FUNCTION InstallFunction,
3655 HDEVINFO DeviceInfoSet,
3656 PSP_DEVINFO_DATA DeviceInfoData)
3658 FIXME("%d %p %p\n", InstallFunction, DeviceInfoSet, DeviceInfoData);
3659 return FALSE;
3662 /***********************************************************************
3663 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
3665 BOOL WINAPI SetupDiGetDeviceInstallParamsW(
3666 HDEVINFO DeviceInfoSet,
3667 PSP_DEVINFO_DATA DeviceInfoData,
3668 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
3670 FIXME("%p %p %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3671 return FALSE;
3674 /***********************************************************************
3675 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3677 BOOL WINAPI SetupDiGetDeviceInstallParamsA(
3678 HDEVINFO DeviceInfoSet,
3679 PSP_DEVINFO_DATA DeviceInfoData,
3680 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams)
3682 FIXME("%p %p %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3683 return FALSE;
3686 /***********************************************************************
3687 * SetupDiSetDeviceInstallParamsA (SETUPAPI.@)
3689 BOOL WINAPI SetupDiSetDeviceInstallParamsA(
3690 HDEVINFO DeviceInfoSet,
3691 PSP_DEVINFO_DATA DeviceInfoData,
3692 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams)
3694 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3696 return TRUE;
3699 static HKEY SETUPDI_OpenDevKey(struct DeviceInfo *devInfo, REGSAM samDesired)
3701 HKEY enumKey, key = INVALID_HANDLE_VALUE;
3702 LONG l;
3704 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
3705 NULL, &enumKey, NULL);
3706 if (!l)
3708 RegOpenKeyExW(enumKey, devInfo->instanceId, 0, samDesired, &key);
3709 RegCloseKey(enumKey);
3711 return key;
3714 static HKEY SETUPDI_OpenDrvKey(struct DeviceInfo *devInfo, REGSAM samDesired)
3716 static const WCHAR slash[] = { '\\',0 };
3717 WCHAR classKeyPath[MAX_PATH];
3718 HKEY classKey, key = INVALID_HANDLE_VALUE;
3719 LONG l;
3721 lstrcpyW(classKeyPath, ControlClass);
3722 lstrcatW(classKeyPath, slash);
3723 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
3724 classKeyPath + lstrlenW(classKeyPath));
3725 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
3726 KEY_ALL_ACCESS, NULL, &classKey, NULL);
3727 if (!l)
3729 static const WCHAR fmt[] = { '%','0','4','u',0 };
3730 WCHAR devId[10];
3732 sprintfW(devId, fmt, devInfo->devId);
3733 l = RegOpenKeyExW(classKey, devId, 0, samDesired, &key);
3734 RegCloseKey(classKey);
3735 if (l)
3737 SetLastError(ERROR_KEY_DOES_NOT_EXIST);
3738 return INVALID_HANDLE_VALUE;
3741 return key;
3744 /***********************************************************************
3745 * SetupDiOpenDevRegKey (SETUPAPI.@)
3747 HKEY WINAPI SetupDiOpenDevRegKey(
3748 HDEVINFO DeviceInfoSet,
3749 PSP_DEVINFO_DATA DeviceInfoData,
3750 DWORD Scope,
3751 DWORD HwProfile,
3752 DWORD KeyType,
3753 REGSAM samDesired)
3755 struct DeviceInfoSet *set = DeviceInfoSet;
3756 struct DeviceInfo *devInfo;
3757 HKEY key = INVALID_HANDLE_VALUE;
3759 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet, DeviceInfoData,
3760 Scope, HwProfile, KeyType, samDesired);
3762 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3764 SetLastError(ERROR_INVALID_HANDLE);
3765 return INVALID_HANDLE_VALUE;
3767 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3769 SetLastError(ERROR_INVALID_HANDLE);
3770 return INVALID_HANDLE_VALUE;
3772 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3773 || !DeviceInfoData->Reserved)
3775 SetLastError(ERROR_INVALID_PARAMETER);
3776 return INVALID_HANDLE_VALUE;
3778 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
3780 SetLastError(ERROR_INVALID_FLAGS);
3781 return INVALID_HANDLE_VALUE;
3783 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV)
3785 SetLastError(ERROR_INVALID_FLAGS);
3786 return INVALID_HANDLE_VALUE;
3788 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3789 if (devInfo->set != set)
3791 SetLastError(ERROR_INVALID_PARAMETER);
3792 return INVALID_HANDLE_VALUE;
3794 if (devInfo->phantom)
3796 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
3797 return INVALID_HANDLE_VALUE;
3799 if (Scope != DICS_FLAG_GLOBAL)
3800 FIXME("unimplemented for scope %d\n", Scope);
3801 switch (KeyType)
3803 case DIREG_DEV:
3804 key = SETUPDI_OpenDevKey(devInfo, samDesired);
3805 break;
3806 case DIREG_DRV:
3807 key = SETUPDI_OpenDrvKey(devInfo, samDesired);
3808 break;
3809 default:
3810 WARN("unknown KeyType %d\n", KeyType);
3812 return key;
3815 static BOOL SETUPDI_DeleteDevKey(struct DeviceInfo *devInfo)
3817 HKEY enumKey;
3818 BOOL ret = FALSE;
3819 LONG l;
3821 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
3822 NULL, &enumKey, NULL);
3823 if (!l)
3825 ret = RegDeleteTreeW(enumKey, devInfo->instanceId);
3826 RegCloseKey(enumKey);
3828 else
3829 SetLastError(l);
3830 return ret;
3833 static BOOL SETUPDI_DeleteDrvKey(struct DeviceInfo *devInfo)
3835 static const WCHAR slash[] = { '\\',0 };
3836 WCHAR classKeyPath[MAX_PATH];
3837 HKEY classKey;
3838 LONG l;
3839 BOOL ret = FALSE;
3841 lstrcpyW(classKeyPath, ControlClass);
3842 lstrcatW(classKeyPath, slash);
3843 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
3844 classKeyPath + lstrlenW(classKeyPath));
3845 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
3846 KEY_ALL_ACCESS, NULL, &classKey, NULL);
3847 if (!l)
3849 static const WCHAR fmt[] = { '%','0','4','u',0 };
3850 WCHAR devId[10];
3852 sprintfW(devId, fmt, devInfo->devId);
3853 ret = RegDeleteTreeW(classKey, devId);
3854 RegCloseKey(classKey);
3856 else
3857 SetLastError(l);
3858 return ret;
3861 /***********************************************************************
3862 * SetupDiDeleteDevRegKey (SETUPAPI.@)
3864 BOOL WINAPI SetupDiDeleteDevRegKey(
3865 HDEVINFO DeviceInfoSet,
3866 PSP_DEVINFO_DATA DeviceInfoData,
3867 DWORD Scope,
3868 DWORD HwProfile,
3869 DWORD KeyType)
3871 struct DeviceInfoSet *set = DeviceInfoSet;
3872 struct DeviceInfo *devInfo;
3873 BOOL ret = FALSE;
3875 TRACE("%p %p %d %d %d\n", DeviceInfoSet, DeviceInfoData, Scope, HwProfile,
3876 KeyType);
3878 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3880 SetLastError(ERROR_INVALID_HANDLE);
3881 return FALSE;
3883 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3885 SetLastError(ERROR_INVALID_HANDLE);
3886 return FALSE;
3888 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3889 || !DeviceInfoData->Reserved)
3891 SetLastError(ERROR_INVALID_PARAMETER);
3892 return FALSE;
3894 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
3896 SetLastError(ERROR_INVALID_FLAGS);
3897 return FALSE;
3899 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV && KeyType != DIREG_BOTH)
3901 SetLastError(ERROR_INVALID_FLAGS);
3902 return FALSE;
3904 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3905 if (devInfo->set != set)
3907 SetLastError(ERROR_INVALID_PARAMETER);
3908 return FALSE;
3910 if (devInfo->phantom)
3912 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
3913 return FALSE;
3915 if (Scope != DICS_FLAG_GLOBAL)
3916 FIXME("unimplemented for scope %d\n", Scope);
3917 switch (KeyType)
3919 case DIREG_DEV:
3920 ret = SETUPDI_DeleteDevKey(devInfo);
3921 break;
3922 case DIREG_DRV:
3923 ret = SETUPDI_DeleteDrvKey(devInfo);
3924 break;
3925 case DIREG_BOTH:
3926 ret = SETUPDI_DeleteDevKey(devInfo);
3927 if (ret)
3928 ret = SETUPDI_DeleteDrvKey(devInfo);
3929 break;
3930 default:
3931 WARN("unknown KeyType %d\n", KeyType);
3933 return ret;
3936 /***********************************************************************
3937 * CM_Get_Device_IDA (SETUPAPI.@)
3939 CONFIGRET WINAPI CM_Get_Device_IDA( DEVINST dnDevInst, PSTR Buffer,
3940 ULONG BufferLen, ULONG ulFlags)
3942 struct DeviceInfo *devInfo = GlobalLock((HANDLE)dnDevInst);
3944 TRACE("%x->%p, %p, %u %u\n", dnDevInst, devInfo, Buffer, BufferLen, ulFlags);
3946 if (!devInfo)
3947 return CR_NO_SUCH_DEVINST;
3949 WideCharToMultiByte(CP_ACP, 0, devInfo->instanceId, -1, Buffer, BufferLen, 0, 0);
3950 TRACE("Returning %s\n", debugstr_a(Buffer));
3951 return CR_SUCCESS;
3954 /***********************************************************************
3955 * CM_Get_Device_IDW (SETUPAPI.@)
3957 CONFIGRET WINAPI CM_Get_Device_IDW( DEVINST dnDevInst, LPWSTR Buffer,
3958 ULONG BufferLen, ULONG ulFlags)
3960 struct DeviceInfo *devInfo = GlobalLock((HANDLE)dnDevInst);
3962 TRACE("%x->%p, %p, %u %u\n", dnDevInst, devInfo, Buffer, BufferLen, ulFlags);
3964 if (!devInfo)
3966 WARN("dev instance %d not found!\n", dnDevInst);
3967 return CR_NO_SUCH_DEVINST;
3970 lstrcpynW(Buffer, devInfo->instanceId, BufferLen);
3971 TRACE("Returning %s\n", debugstr_w(Buffer));
3972 GlobalUnlock((HANDLE)dnDevInst);
3973 return CR_SUCCESS;
3978 /***********************************************************************
3979 * CM_Get_Device_ID_Size (SETUPAPI.@)
3981 CONFIGRET WINAPI CM_Get_Device_ID_Size( PULONG pulLen, DEVINST dnDevInst,
3982 ULONG ulFlags)
3984 struct DeviceInfo *ppdevInfo = GlobalLock((HANDLE)dnDevInst);
3986 TRACE("%x->%p, %p, %u\n", dnDevInst, ppdevInfo, pulLen, ulFlags);
3988 if (!ppdevInfo)
3990 WARN("dev instance %d not found!\n", dnDevInst);
3991 return CR_NO_SUCH_DEVINST;
3994 *pulLen = lstrlenW(ppdevInfo->instanceId);
3995 GlobalUnlock((HANDLE)dnDevInst);
3996 return CR_SUCCESS;
3999 /***********************************************************************
4000 * SetupDiGetINFClassA (SETUPAPI.@)
4002 BOOL WINAPI SetupDiGetINFClassA(PCSTR inf, LPGUID class_guid, PSTR class_name,
4003 DWORD size, PDWORD required_size)
4005 BOOL retval;
4006 DWORD required_sizeA, required_sizeW;
4007 PWSTR class_nameW = NULL;
4008 UNICODE_STRING infW;
4010 if (inf)
4012 if (!RtlCreateUnicodeStringFromAsciiz(&infW, inf))
4014 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
4015 return FALSE;
4018 else
4019 infW.Buffer = NULL;
4021 if (class_name && size)
4023 if (!(class_nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR))))
4025 RtlFreeUnicodeString(&infW);
4026 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
4027 return FALSE;
4031 retval = SetupDiGetINFClassW(infW.Buffer, class_guid, class_nameW, size, &required_sizeW);
4033 if (retval)
4035 required_sizeA = WideCharToMultiByte( CP_ACP, 0, class_nameW, required_sizeW,
4036 class_name, size, NULL, NULL);
4038 if(required_size) *required_size = required_sizeA;
4040 else
4041 if(required_size) *required_size = required_sizeW;
4043 HeapFree(GetProcessHeap(), 0, class_nameW);
4044 RtlFreeUnicodeString(&infW);
4045 return retval;
4048 /***********************************************************************
4049 * SetupDiGetINFClassW (SETUPAPI.@)
4051 BOOL WINAPI SetupDiGetINFClassW(PCWSTR inf, LPGUID class_guid, PWSTR class_name,
4052 DWORD size, PDWORD required_size)
4054 BOOL have_guid, have_name;
4055 DWORD dret;
4056 WCHAR buffer[MAX_PATH];
4058 if (!inf)
4060 SetLastError(ERROR_INVALID_PARAMETER);
4061 return FALSE;
4064 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(inf))
4066 FIXME("%s not found. Searching via DevicePath not implemented\n", debugstr_w(inf));
4067 SetLastError(ERROR_FILE_NOT_FOUND);
4068 return FALSE;
4071 if (!class_guid || !class_name || !size)
4073 SetLastError(ERROR_INVALID_PARAMETER);
4074 return FALSE;
4077 if (!GetPrivateProfileStringW(Version, Signature, NULL, buffer, MAX_PATH, inf))
4078 return FALSE;
4080 if (lstrcmpiW(buffer, Chicago) && lstrcmpiW(buffer, WindowsNT))
4081 return FALSE;
4083 buffer[0] = '\0';
4084 have_guid = 0 < GetPrivateProfileStringW(Version, ClassGUID, NULL, buffer, MAX_PATH, inf);
4085 if (have_guid)
4087 buffer[lstrlenW(buffer)-1] = 0;
4088 if (RPC_S_OK != UuidFromStringW(buffer + 1, class_guid))
4090 FIXME("failed to convert \"%s\" into a guid\n", debugstr_w(buffer));
4091 SetLastError(ERROR_INVALID_PARAMETER);
4092 return FALSE;
4096 buffer[0] = '\0';
4097 dret = GetPrivateProfileStringW(Version, Class, NULL, buffer, MAX_PATH, inf);
4098 have_name = 0 < dret;
4100 if (dret >= MAX_PATH -1) FIXME("buffer might be too small\n");
4101 if (have_guid && !have_name) FIXME("class name lookup via guid not implemented\n");
4103 if (have_name)
4105 if (dret < size) lstrcpyW(class_name, buffer);
4106 else
4108 SetLastError(ERROR_INSUFFICIENT_BUFFER);
4109 have_name = FALSE;
4113 if (required_size) *required_size = dret + ((dret) ? 1 : 0);
4115 return (have_guid || have_name);