oledb32: Coerce Variant to VT_DATE when converting data.
[wine.git] / dlls / setupapi / devinst.c
blob4a852da18ba649537684bf6442af1d2a8204f797
1 /*
2 * SetupAPI device installer
4 * Copyright 2000 Andreas Mohr for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnt.h"
29 #include "winreg.h"
30 #include "winternl.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34 #include "setupapi.h"
35 #include "wine/debug.h"
36 #include "wine/list.h"
37 #include "wine/unicode.h"
38 #include "cfgmgr32.h"
39 #include "winioctl.h"
40 #include "rpc.h"
41 #include "rpcdce.h"
43 #include "setupapi_private.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
48 /* Unicode constants */
49 static const WCHAR Chicago[] = {'$','C','h','i','c','a','g','o','$',0};
50 static const WCHAR ClassGUID[] = {'C','l','a','s','s','G','U','I','D',0};
51 static const WCHAR Class[] = {'C','l','a','s','s',0};
52 static const WCHAR ClassInstall32[] = {'C','l','a','s','s','I','n','s','t','a','l','l','3','2',0};
53 static const WCHAR NoDisplayClass[] = {'N','o','D','i','s','p','l','a','y','C','l','a','s','s',0};
54 static const WCHAR NoInstallClass[] = {'N','o','I','n','s','t','a','l','l','C','l','a','s','s',0};
55 static const WCHAR NoUseClass[] = {'N','o','U','s','e','C','l','a','s','s',0};
56 static const WCHAR NtExtension[] = {'.','N','T',0};
57 static const WCHAR NtPlatformExtension[] = {'.','N','T','x','8','6',0};
58 static const WCHAR Signature[] = {'S','i','g','n','a','t','u','r','e',0};
59 static const WCHAR Version[] = {'V','e','r','s','i','o','n',0};
60 static const WCHAR WinExtension[] = {'.','W','i','n',0};
61 static const WCHAR WindowsNT[] = {'$','W','i','n','d','o','w','s',' ','N','T','$',0};
63 /* Registry key and value names */
64 static const WCHAR ControlClass[] = {'S','y','s','t','e','m','\\',
65 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
66 'C','o','n','t','r','o','l','\\',
67 'C','l','a','s','s',0};
69 static const WCHAR DeviceClasses[] = {'S','y','s','t','e','m','\\',
70 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
71 'C','o','n','t','r','o','l','\\',
72 'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
73 static const WCHAR Enum[] = {'S','y','s','t','e','m','\\',
74 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
75 'E','n','u','m',0};
76 static const WCHAR DeviceDesc[] = {'D','e','v','i','c','e','D','e','s','c',0};
77 static const WCHAR DeviceInstance[] = {'D','e','v','i','c','e','I','n','s','t','a','n','c','e',0};
78 static const WCHAR HardwareId[] = {'H','a','r','d','w','a','r','e','I','D',0};
79 static const WCHAR CompatibleIDs[] = {'C','o','m','p','a','t','i','b','l','e','I','d','s',0};
80 static const WCHAR Service[] = {'S','e','r','v','i','c','e',0};
81 static const WCHAR Driver[] = {'D','r','i','v','e','r',0};
82 static const WCHAR ConfigFlags[] = {'C','o','n','f','i','g','F','l','a','g','s',0};
83 static const WCHAR Mfg[] = {'M','f','g',0};
84 static const WCHAR FriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
85 static const WCHAR LocationInformation[] = {'L','o','c','a','t','i','o','n','I','n','f','o','r','m','a','t','i','o','n',0};
86 static const WCHAR Capabilities[] = {'C','a','p','a','b','i','l','i','t','i','e','s',0};
87 static const WCHAR UINumber[] = {'U','I','N','u','m','b','e','r',0};
88 static const WCHAR UpperFilters[] = {'U','p','p','e','r','F','i','l','t','e','r','s',0};
89 static const WCHAR LowerFilters[] = {'L','o','w','e','r','F','i','l','t','e','r','s',0};
90 static const WCHAR Phantom[] = {'P','h','a','n','t','o','m',0};
91 static const WCHAR SymbolicLink[] = {'S','y','m','b','o','l','i','c','L','i','n','k',0};
93 /* is used to identify if a DeviceInfoSet pointer is
94 valid or not */
95 #define SETUP_DEVICE_INFO_SET_MAGIC 0xd00ff056
97 struct DeviceInfoSet
99 DWORD magic; /* if is equal to SETUP_DEVICE_INFO_SET_MAGIC struct is okay */
100 GUID ClassGuid;
101 HWND hwndParent;
102 DWORD cDevices;
103 struct list devices;
106 struct DeviceInstance
108 struct list entry;
109 SP_DEVINFO_DATA data;
112 /* Pointed to by SP_DEVICE_INTERFACE_DATA's Reserved member */
113 struct InterfaceInfo
115 LPWSTR referenceString;
116 LPWSTR symbolicLink;
117 PSP_DEVINFO_DATA device;
120 /* A device may have multiple instances of the same interface, so this holds
121 * each instance belonging to a particular interface.
123 struct InterfaceInstances
125 GUID guid;
126 DWORD cInstances;
127 DWORD cInstancesAllocated;
128 SP_DEVICE_INTERFACE_DATA *instances;
129 struct list entry;
132 /* Pointed to by SP_DEVINFO_DATA's Reserved member */
133 struct DeviceInfo
135 struct DeviceInfoSet *set;
136 HKEY key;
137 BOOL phantom;
138 DWORD devId;
139 LPWSTR instanceId;
140 struct list interfaces;
143 static void SETUPDI_GuidToString(const GUID *guid, LPWSTR guidStr)
145 static const WCHAR fmt[] = {'{','%','0','8','X','-','%','0','4','X','-',
146 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
147 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
148 '0','2','X','}',0};
150 sprintfW(guidStr, fmt, guid->Data1, guid->Data2, guid->Data3,
151 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
152 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
155 static void SETUPDI_FreeInterfaceInstances(struct InterfaceInstances *instances)
157 DWORD i;
159 for (i = 0; i < instances->cInstances; i++)
161 struct InterfaceInfo *ifaceInfo =
162 (struct InterfaceInfo *)instances->instances[i].Reserved;
164 if (ifaceInfo->device && ifaceInfo->device->Reserved)
166 struct DeviceInfo *devInfo =
167 (struct DeviceInfo *)ifaceInfo->device->Reserved;
169 if (devInfo->phantom)
170 SetupDiDeleteDeviceInterfaceRegKey(devInfo->set,
171 &instances->instances[i], 0);
173 HeapFree(GetProcessHeap(), 0, ifaceInfo->referenceString);
174 HeapFree(GetProcessHeap(), 0, ifaceInfo->symbolicLink);
175 HeapFree(GetProcessHeap(), 0, ifaceInfo);
177 HeapFree(GetProcessHeap(), 0, instances->instances);
180 /* Finds the interface with interface class InterfaceClassGuid in the device.
181 * Returns TRUE if found, and updates *interface to point to device's
182 * interfaces member where the given interface was found.
183 * Returns FALSE if not found.
185 static BOOL SETUPDI_FindInterface(const struct DeviceInfo *devInfo,
186 const GUID *InterfaceClassGuid, struct InterfaceInstances **iface_ret)
188 BOOL found = FALSE;
189 struct InterfaceInstances *iface;
191 TRACE("%s\n", debugstr_guid(InterfaceClassGuid));
193 LIST_FOR_EACH_ENTRY(iface, &devInfo->interfaces, struct InterfaceInstances,
194 entry)
196 if (IsEqualGUID(&iface->guid, InterfaceClassGuid))
198 *iface_ret = iface;
199 found = TRUE;
200 break;
203 TRACE("returning %d (%p)\n", found, found ? *iface_ret : NULL);
204 return found;
207 /* Finds the interface instance with reference string ReferenceString in the
208 * interface instance map. Returns TRUE if found, and updates instanceIndex to
209 * the index of the interface instance's instances member
210 * where the given instance was found. Returns FALSE if not found.
212 static BOOL SETUPDI_FindInterfaceInstance(
213 const struct InterfaceInstances *instances,
214 LPCWSTR ReferenceString, DWORD *instanceIndex)
216 BOOL found = FALSE;
217 DWORD i;
219 TRACE("%s\n", debugstr_w(ReferenceString));
221 for (i = 0; !found && i < instances->cInstances; i++)
223 SP_DEVICE_INTERFACE_DATA *ifaceData = &instances->instances[i];
224 struct InterfaceInfo *ifaceInfo =
225 (struct InterfaceInfo *)ifaceData->Reserved;
227 if (!ReferenceString && !ifaceInfo->referenceString)
229 *instanceIndex = i;
230 found = TRUE;
232 else if (ReferenceString && ifaceInfo->referenceString &&
233 !lstrcmpiW(ifaceInfo->referenceString, ReferenceString))
235 *instanceIndex = i;
236 found = TRUE;
239 TRACE("returning %d (%d)\n", found, found ? *instanceIndex : 0);
240 return found;
243 static LPWSTR SETUPDI_CreateSymbolicLinkPath(LPCWSTR instanceId,
244 const GUID *InterfaceClassGuid, LPCWSTR ReferenceString)
246 static const WCHAR fmt[] = {'\\','\\','?','\\','%','s','#','%','s',0};
247 WCHAR guidStr[39];
248 DWORD len;
249 LPWSTR ret;
251 SETUPDI_GuidToString(InterfaceClassGuid, guidStr);
252 /* omit length of format specifiers, but include NULL terminator: */
253 len = lstrlenW(fmt) - 4 + 1;
254 len += lstrlenW(instanceId) + lstrlenW(guidStr);
255 if (ReferenceString && *ReferenceString)
257 /* space for a hash between string and reference string: */
258 len += lstrlenW(ReferenceString) + 1;
260 ret = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
261 if (ret)
263 int printed = sprintfW(ret, fmt, instanceId, guidStr);
264 LPWSTR ptr;
266 /* replace '\\' with '#' after the "\\\\?\\" beginning */
267 for (ptr = strchrW(ret + 4, '\\'); ptr; ptr = strchrW(ptr + 1, '\\'))
268 *ptr = '#';
269 if (ReferenceString && *ReferenceString)
271 ret[printed] = '\\';
272 lstrcpyW(ret + printed + 1, ReferenceString);
275 return ret;
278 /* Adds an interface with the given interface class and reference string to
279 * the device, if it doesn't already exist in the device. If iface is not
280 * NULL, returns a pointer to the newly added (or already existing) interface.
282 static BOOL SETUPDI_AddInterfaceInstance(PSP_DEVINFO_DATA DeviceInfoData,
283 const GUID *InterfaceClassGuid, LPCWSTR ReferenceString,
284 SP_DEVICE_INTERFACE_DATA **ifaceData)
286 struct DeviceInfo *devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
287 BOOL newInterface = FALSE, ret;
288 struct InterfaceInstances *iface = NULL;
290 TRACE("%p %s %s %p\n", devInfo, debugstr_guid(InterfaceClassGuid),
291 debugstr_w(ReferenceString), iface);
293 if (!(ret = SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface)))
295 iface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
296 sizeof(struct InterfaceInstances));
297 if (iface)
299 list_add_tail(&devInfo->interfaces, &iface->entry);
300 newInterface = TRUE;
303 if (iface)
305 DWORD instanceIndex = 0;
307 if (!(ret = SETUPDI_FindInterfaceInstance(iface, ReferenceString,
308 &instanceIndex)))
310 SP_DEVICE_INTERFACE_DATA *instance = NULL;
312 if (!iface->cInstancesAllocated)
314 iface->instances = HeapAlloc(GetProcessHeap(), 0,
315 sizeof(SP_DEVICE_INTERFACE_DATA));
316 if (iface->instances)
317 instance = &iface->instances[iface->cInstancesAllocated++];
319 else if (iface->cInstances == iface->cInstancesAllocated)
321 iface->instances = HeapReAlloc(GetProcessHeap(), 0,
322 iface->instances,
323 (iface->cInstancesAllocated + 1) *
324 sizeof(SP_DEVICE_INTERFACE_DATA));
325 if (iface->instances)
326 instance = &iface->instances[iface->cInstancesAllocated++];
328 else
329 instance = &iface->instances[iface->cInstances];
330 if (instance)
332 struct InterfaceInfo *ifaceInfo = HeapAlloc(GetProcessHeap(),
333 0, sizeof(struct InterfaceInfo));
335 if (ifaceInfo)
337 ret = TRUE;
338 ifaceInfo->device = DeviceInfoData;
339 ifaceInfo->symbolicLink = SETUPDI_CreateSymbolicLinkPath(
340 devInfo->instanceId, InterfaceClassGuid,
341 ReferenceString);
342 if (ReferenceString)
344 ifaceInfo->referenceString =
345 HeapAlloc(GetProcessHeap(), 0,
346 (lstrlenW(ReferenceString) + 1) *
347 sizeof(WCHAR));
348 if (ifaceInfo->referenceString)
349 lstrcpyW(ifaceInfo->referenceString,
350 ReferenceString);
351 else
352 ret = FALSE;
354 else
355 ifaceInfo->referenceString = NULL;
356 if (ret)
358 HKEY key;
360 iface->cInstances++;
361 instance->cbSize =
362 sizeof(SP_DEVICE_INTERFACE_DATA);
363 instance->InterfaceClassGuid = *InterfaceClassGuid;
364 instance->Flags = SPINT_ACTIVE; /* FIXME */
365 instance->Reserved = (ULONG_PTR)ifaceInfo;
366 if (newInterface)
367 iface->guid = *InterfaceClassGuid;
368 key = SetupDiCreateDeviceInterfaceRegKeyW(devInfo->set,
369 instance, 0, KEY_WRITE, NULL, NULL);
370 if (key != INVALID_HANDLE_VALUE)
372 RegSetValueExW(key, SymbolicLink, 0, REG_SZ,
373 (BYTE *)ifaceInfo->symbolicLink,
374 lstrlenW(ifaceInfo->symbolicLink) *
375 sizeof(WCHAR));
376 RegCloseKey(key);
378 if (ifaceData)
379 *ifaceData = instance;
381 else
382 HeapFree(GetProcessHeap(), 0, ifaceInfo);
386 else
388 if (ifaceData)
389 *ifaceData = &iface->instances[instanceIndex];
392 else
393 ret = FALSE;
394 TRACE("returning %d\n", ret);
395 return ret;
398 static BOOL SETUPDI_SetInterfaceSymbolicLink(SP_DEVICE_INTERFACE_DATA *iface,
399 LPCWSTR symbolicLink)
401 struct InterfaceInfo *info = (struct InterfaceInfo *)iface->Reserved;
402 BOOL ret = FALSE;
404 if (info)
406 HeapFree(GetProcessHeap(), 0, info->symbolicLink);
407 info->symbolicLink = HeapAlloc(GetProcessHeap(), 0,
408 (lstrlenW(symbolicLink) + 1) * sizeof(WCHAR));
409 if (info->symbolicLink)
411 lstrcpyW(info->symbolicLink, symbolicLink);
412 ret = TRUE;
415 return ret;
418 static HKEY SETUPDI_CreateDevKey(struct DeviceInfo *devInfo)
420 HKEY enumKey, key = INVALID_HANDLE_VALUE;
421 LONG l;
423 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
424 NULL, &enumKey, NULL);
425 if (!l)
427 RegCreateKeyExW(enumKey, devInfo->instanceId, 0, NULL, 0,
428 KEY_READ | KEY_WRITE, NULL, &key, NULL);
429 RegCloseKey(enumKey);
431 return key;
434 static HKEY SETUPDI_CreateDrvKey(struct DeviceInfo *devInfo)
436 static const WCHAR slash[] = { '\\',0 };
437 WCHAR classKeyPath[MAX_PATH];
438 HKEY classKey, key = INVALID_HANDLE_VALUE;
439 LONG l;
441 lstrcpyW(classKeyPath, ControlClass);
442 lstrcatW(classKeyPath, slash);
443 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
444 classKeyPath + lstrlenW(classKeyPath));
445 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
446 KEY_ALL_ACCESS, NULL, &classKey, NULL);
447 if (!l)
449 static const WCHAR fmt[] = { '%','0','4','u',0 };
450 WCHAR devId[10];
452 sprintfW(devId, fmt, devInfo->devId);
453 RegCreateKeyExW(classKey, devId, 0, NULL, 0, KEY_READ | KEY_WRITE,
454 NULL, &key, NULL);
455 RegCloseKey(classKey);
457 return key;
460 static struct DeviceInfo *SETUPDI_AllocateDeviceInfo(struct DeviceInfoSet *set,
461 DWORD devId, LPCWSTR instanceId, BOOL phantom)
463 struct DeviceInfo *devInfo = NULL;
464 HANDLE devInst = GlobalAlloc(GMEM_FIXED, sizeof(struct DeviceInfo));
465 if (devInst)
466 devInfo = GlobalLock(devInst);
468 if (devInfo)
470 devInfo->set = set;
471 devInfo->devId = (DWORD)devInst;
473 devInfo->instanceId = HeapAlloc(GetProcessHeap(), 0,
474 (lstrlenW(instanceId) + 1) * sizeof(WCHAR));
475 if (devInfo->instanceId)
477 devInfo->key = INVALID_HANDLE_VALUE;
478 devInfo->phantom = phantom;
479 lstrcpyW(devInfo->instanceId, instanceId);
480 struprW(devInfo->instanceId);
481 devInfo->key = SETUPDI_CreateDevKey(devInfo);
482 if (devInfo->key != INVALID_HANDLE_VALUE)
484 if (phantom)
485 RegSetValueExW(devInfo->key, Phantom, 0, REG_DWORD,
486 (LPBYTE)&phantom, sizeof(phantom));
488 list_init(&devInfo->interfaces);
489 GlobalUnlock(devInst);
491 else
493 GlobalUnlock(devInst);
494 GlobalFree(devInst);
495 devInfo = NULL;
498 return devInfo;
501 static void SETUPDI_FreeDeviceInfo(struct DeviceInfo *devInfo)
503 struct InterfaceInstances *iface, *next;
505 if (devInfo->key != INVALID_HANDLE_VALUE)
506 RegCloseKey(devInfo->key);
507 if (devInfo->phantom)
509 HKEY enumKey;
510 LONG l;
512 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0,
513 KEY_ALL_ACCESS, NULL, &enumKey, NULL);
514 if (!l)
516 RegDeleteTreeW(enumKey, devInfo->instanceId);
517 RegCloseKey(enumKey);
520 HeapFree(GetProcessHeap(), 0, devInfo->instanceId);
521 LIST_FOR_EACH_ENTRY_SAFE(iface, next, &devInfo->interfaces,
522 struct InterfaceInstances, entry)
524 list_remove(&iface->entry);
525 SETUPDI_FreeInterfaceInstances(iface);
526 HeapFree(GetProcessHeap(), 0, iface);
528 GlobalFree((HANDLE)devInfo->devId);
531 /* Adds a device with GUID guid and identifier devInst to set. Allocates a
532 * struct DeviceInfo, and points the returned device info's Reserved member
533 * to it. "Phantom" devices are deleted from the registry when closed.
534 * Returns a pointer to the newly allocated device info.
536 static BOOL SETUPDI_AddDeviceToSet(struct DeviceInfoSet *set,
537 const GUID *guid,
538 DWORD dev_inst,
539 LPCWSTR instanceId,
540 BOOL phantom,
541 SP_DEVINFO_DATA **dev)
543 BOOL ret = FALSE;
544 struct DeviceInfo *devInfo = SETUPDI_AllocateDeviceInfo(set, set->cDevices,
545 instanceId, phantom);
547 TRACE("%p, %s, %d, %s, %d\n", set, debugstr_guid(guid), dev_inst,
548 debugstr_w(instanceId), phantom);
550 if (devInfo)
552 struct DeviceInstance *devInst =
553 HeapAlloc(GetProcessHeap(), 0, sizeof(struct DeviceInstance));
555 if (devInst)
557 WCHAR classGuidStr[39];
559 list_add_tail(&set->devices, &devInst->entry);
560 set->cDevices++;
561 devInst->data.cbSize = sizeof(SP_DEVINFO_DATA);
562 devInst->data.ClassGuid = *guid;
563 devInst->data.DevInst = devInfo->devId;
564 devInst->data.Reserved = (ULONG_PTR)devInfo;
565 SETUPDI_GuidToString(guid, classGuidStr);
566 SetupDiSetDeviceRegistryPropertyW(set, &devInst->data,
567 SPDRP_CLASSGUID, (const BYTE *)classGuidStr,
568 lstrlenW(classGuidStr) * sizeof(WCHAR));
569 if (dev) *dev = &devInst->data;
570 ret = TRUE;
572 else
574 HeapFree(GetProcessHeap(), 0, devInfo);
575 SetLastError(ERROR_OUTOFMEMORY);
578 return ret;
581 /***********************************************************************
582 * SetupDiBuildClassInfoList (SETUPAPI.@)
584 * Returns a list of setup class GUIDs that identify the classes
585 * that are installed on a local machine.
587 * PARAMS
588 * Flags [I] control exclusion of classes from the list.
589 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
590 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
591 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
593 * RETURNS
594 * Success: TRUE.
595 * Failure: FALSE.
597 BOOL WINAPI SetupDiBuildClassInfoList(
598 DWORD Flags,
599 LPGUID ClassGuidList,
600 DWORD ClassGuidListSize,
601 PDWORD RequiredSize)
603 TRACE("\n");
604 return SetupDiBuildClassInfoListExW(Flags, ClassGuidList,
605 ClassGuidListSize, RequiredSize,
606 NULL, NULL);
609 /***********************************************************************
610 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
612 * Returns a list of setup class GUIDs that identify the classes
613 * that are installed on a local or remote machine.
615 * PARAMS
616 * Flags [I] control exclusion of classes from the list.
617 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
618 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
619 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
620 * MachineName [I] name of a remote machine.
621 * Reserved [I] must be NULL.
623 * RETURNS
624 * Success: TRUE.
625 * Failure: FALSE.
627 BOOL WINAPI SetupDiBuildClassInfoListExA(
628 DWORD Flags,
629 LPGUID ClassGuidList,
630 DWORD ClassGuidListSize,
631 PDWORD RequiredSize,
632 LPCSTR MachineName,
633 PVOID Reserved)
635 LPWSTR MachineNameW = NULL;
636 BOOL bResult;
638 TRACE("\n");
640 if (MachineName)
642 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
643 if (MachineNameW == NULL) return FALSE;
646 bResult = SetupDiBuildClassInfoListExW(Flags, ClassGuidList,
647 ClassGuidListSize, RequiredSize,
648 MachineNameW, Reserved);
650 MyFree(MachineNameW);
652 return bResult;
655 /***********************************************************************
656 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
658 * Returns a list of setup class GUIDs that identify the classes
659 * that are installed on a local or remote machine.
661 * PARAMS
662 * Flags [I] control exclusion of classes from the list.
663 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
664 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
665 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
666 * MachineName [I] name of a remote machine.
667 * Reserved [I] must be NULL.
669 * RETURNS
670 * Success: TRUE.
671 * Failure: FALSE.
673 BOOL WINAPI SetupDiBuildClassInfoListExW(
674 DWORD Flags,
675 LPGUID ClassGuidList,
676 DWORD ClassGuidListSize,
677 PDWORD RequiredSize,
678 LPCWSTR MachineName,
679 PVOID Reserved)
681 WCHAR szKeyName[40];
682 HKEY hClassesKey;
683 HKEY hClassKey;
684 DWORD dwLength;
685 DWORD dwIndex;
686 LONG lError;
687 DWORD dwGuidListIndex = 0;
689 TRACE("\n");
691 if (RequiredSize != NULL)
692 *RequiredSize = 0;
694 hClassesKey = SetupDiOpenClassRegKeyExW(NULL,
695 KEY_ALL_ACCESS,
696 DIOCR_INSTALLER,
697 MachineName,
698 Reserved);
699 if (hClassesKey == INVALID_HANDLE_VALUE)
701 return FALSE;
704 for (dwIndex = 0; ; dwIndex++)
706 dwLength = 40;
707 lError = RegEnumKeyExW(hClassesKey,
708 dwIndex,
709 szKeyName,
710 &dwLength,
711 NULL,
712 NULL,
713 NULL,
714 NULL);
715 TRACE("RegEnumKeyExW() returns %d\n", lError);
716 if (lError == ERROR_SUCCESS || lError == ERROR_MORE_DATA)
718 TRACE("Key name: %p\n", szKeyName);
720 if (RegOpenKeyExW(hClassesKey,
721 szKeyName,
723 KEY_ALL_ACCESS,
724 &hClassKey))
726 RegCloseKey(hClassesKey);
727 return FALSE;
730 if (!RegQueryValueExW(hClassKey,
731 NoUseClass,
732 NULL,
733 NULL,
734 NULL,
735 NULL))
737 TRACE("'NoUseClass' value found!\n");
738 RegCloseKey(hClassKey);
739 continue;
742 if ((Flags & DIBCI_NOINSTALLCLASS) &&
743 (!RegQueryValueExW(hClassKey,
744 NoInstallClass,
745 NULL,
746 NULL,
747 NULL,
748 NULL)))
750 TRACE("'NoInstallClass' value found!\n");
751 RegCloseKey(hClassKey);
752 continue;
755 if ((Flags & DIBCI_NODISPLAYCLASS) &&
756 (!RegQueryValueExW(hClassKey,
757 NoDisplayClass,
758 NULL,
759 NULL,
760 NULL,
761 NULL)))
763 TRACE("'NoDisplayClass' value found!\n");
764 RegCloseKey(hClassKey);
765 continue;
768 RegCloseKey(hClassKey);
770 TRACE("Guid: %p\n", szKeyName);
771 if (dwGuidListIndex < ClassGuidListSize)
773 if (szKeyName[0] == '{' && szKeyName[37] == '}')
775 szKeyName[37] = 0;
777 TRACE("Guid: %p\n", &szKeyName[1]);
779 UuidFromStringW(&szKeyName[1],
780 &ClassGuidList[dwGuidListIndex]);
783 dwGuidListIndex++;
786 if (lError != ERROR_SUCCESS)
787 break;
790 RegCloseKey(hClassesKey);
792 if (RequiredSize != NULL)
793 *RequiredSize = dwGuidListIndex;
795 if (ClassGuidListSize < dwGuidListIndex)
797 SetLastError(ERROR_INSUFFICIENT_BUFFER);
798 return FALSE;
801 return TRUE;
804 /***********************************************************************
805 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
807 BOOL WINAPI SetupDiClassGuidsFromNameA(
808 LPCSTR ClassName,
809 LPGUID ClassGuidList,
810 DWORD ClassGuidListSize,
811 PDWORD RequiredSize)
813 return SetupDiClassGuidsFromNameExA(ClassName, ClassGuidList,
814 ClassGuidListSize, RequiredSize,
815 NULL, NULL);
818 /***********************************************************************
819 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
821 BOOL WINAPI SetupDiClassGuidsFromNameW(
822 LPCWSTR ClassName,
823 LPGUID ClassGuidList,
824 DWORD ClassGuidListSize,
825 PDWORD RequiredSize)
827 return SetupDiClassGuidsFromNameExW(ClassName, ClassGuidList,
828 ClassGuidListSize, RequiredSize,
829 NULL, NULL);
832 /***********************************************************************
833 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
835 BOOL WINAPI SetupDiClassGuidsFromNameExA(
836 LPCSTR ClassName,
837 LPGUID ClassGuidList,
838 DWORD ClassGuidListSize,
839 PDWORD RequiredSize,
840 LPCSTR MachineName,
841 PVOID Reserved)
843 LPWSTR ClassNameW = NULL;
844 LPWSTR MachineNameW = NULL;
845 BOOL bResult;
847 ClassNameW = MultiByteToUnicode(ClassName, CP_ACP);
848 if (ClassNameW == NULL)
849 return FALSE;
851 if (MachineName)
853 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
854 if (MachineNameW == NULL)
856 MyFree(ClassNameW);
857 return FALSE;
861 bResult = SetupDiClassGuidsFromNameExW(ClassNameW, ClassGuidList,
862 ClassGuidListSize, RequiredSize,
863 MachineNameW, Reserved);
865 MyFree(MachineNameW);
866 MyFree(ClassNameW);
868 return bResult;
871 /***********************************************************************
872 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
874 BOOL WINAPI SetupDiClassGuidsFromNameExW(
875 LPCWSTR ClassName,
876 LPGUID ClassGuidList,
877 DWORD ClassGuidListSize,
878 PDWORD RequiredSize,
879 LPCWSTR MachineName,
880 PVOID Reserved)
882 WCHAR szKeyName[40];
883 WCHAR szClassName[256];
884 HKEY hClassesKey;
885 HKEY hClassKey;
886 DWORD dwLength;
887 DWORD dwIndex;
888 LONG lError;
889 DWORD dwGuidListIndex = 0;
891 if (RequiredSize != NULL)
892 *RequiredSize = 0;
894 hClassesKey = SetupDiOpenClassRegKeyExW(NULL,
895 KEY_ALL_ACCESS,
896 DIOCR_INSTALLER,
897 MachineName,
898 Reserved);
899 if (hClassesKey == INVALID_HANDLE_VALUE)
901 return FALSE;
904 for (dwIndex = 0; ; dwIndex++)
906 dwLength = sizeof(szKeyName) / sizeof(WCHAR);
907 lError = RegEnumKeyExW(hClassesKey,
908 dwIndex,
909 szKeyName,
910 &dwLength,
911 NULL,
912 NULL,
913 NULL,
914 NULL);
915 TRACE("RegEnumKeyExW() returns %d\n", lError);
916 if (lError == ERROR_SUCCESS || lError == ERROR_MORE_DATA)
918 TRACE("Key name: %p\n", szKeyName);
920 if (RegOpenKeyExW(hClassesKey,
921 szKeyName,
923 KEY_ALL_ACCESS,
924 &hClassKey))
926 RegCloseKey(hClassesKey);
927 return FALSE;
930 dwLength = sizeof(szClassName);
931 if (!RegQueryValueExW(hClassKey,
932 Class,
933 NULL,
934 NULL,
935 (LPBYTE)szClassName,
936 &dwLength))
938 TRACE("Class name: %p\n", szClassName);
940 if (strcmpiW(szClassName, ClassName) == 0)
942 TRACE("Found matching class name\n");
944 TRACE("Guid: %p\n", szKeyName);
945 if (dwGuidListIndex < ClassGuidListSize)
947 if (szKeyName[0] == '{' && szKeyName[37] == '}')
949 szKeyName[37] = 0;
951 TRACE("Guid: %p\n", &szKeyName[1]);
953 UuidFromStringW(&szKeyName[1],
954 &ClassGuidList[dwGuidListIndex]);
957 dwGuidListIndex++;
961 RegCloseKey(hClassKey);
964 if (lError != ERROR_SUCCESS)
965 break;
968 RegCloseKey(hClassesKey);
970 if (RequiredSize != NULL)
971 *RequiredSize = dwGuidListIndex;
973 if (ClassGuidListSize < dwGuidListIndex)
975 SetLastError(ERROR_INSUFFICIENT_BUFFER);
976 return FALSE;
979 return TRUE;
982 /***********************************************************************
983 * SetupDiClassNameFromGuidA (SETUPAPI.@)
985 BOOL WINAPI SetupDiClassNameFromGuidA(
986 const GUID* ClassGuid,
987 PSTR ClassName,
988 DWORD ClassNameSize,
989 PDWORD RequiredSize)
991 return SetupDiClassNameFromGuidExA(ClassGuid, ClassName,
992 ClassNameSize, RequiredSize,
993 NULL, NULL);
996 /***********************************************************************
997 * SetupDiClassNameFromGuidW (SETUPAPI.@)
999 BOOL WINAPI SetupDiClassNameFromGuidW(
1000 const GUID* ClassGuid,
1001 PWSTR ClassName,
1002 DWORD ClassNameSize,
1003 PDWORD RequiredSize)
1005 return SetupDiClassNameFromGuidExW(ClassGuid, ClassName,
1006 ClassNameSize, RequiredSize,
1007 NULL, NULL);
1010 /***********************************************************************
1011 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1013 BOOL WINAPI SetupDiClassNameFromGuidExA(
1014 const GUID* ClassGuid,
1015 PSTR ClassName,
1016 DWORD ClassNameSize,
1017 PDWORD RequiredSize,
1018 PCSTR MachineName,
1019 PVOID Reserved)
1021 WCHAR ClassNameW[MAX_CLASS_NAME_LEN];
1022 LPWSTR MachineNameW = NULL;
1023 BOOL ret;
1025 if (MachineName)
1026 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
1027 ret = SetupDiClassNameFromGuidExW(ClassGuid, ClassNameW, MAX_CLASS_NAME_LEN,
1028 NULL, MachineNameW, Reserved);
1029 if (ret)
1031 int len = WideCharToMultiByte(CP_ACP, 0, ClassNameW, -1, ClassName,
1032 ClassNameSize, NULL, NULL);
1034 if (!ClassNameSize && RequiredSize)
1035 *RequiredSize = len;
1037 MyFree(MachineNameW);
1038 return ret;
1041 /***********************************************************************
1042 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1044 BOOL WINAPI SetupDiClassNameFromGuidExW(
1045 const GUID* ClassGuid,
1046 PWSTR ClassName,
1047 DWORD ClassNameSize,
1048 PDWORD RequiredSize,
1049 PCWSTR MachineName,
1050 PVOID Reserved)
1052 HKEY hKey;
1053 DWORD dwLength;
1055 hKey = SetupDiOpenClassRegKeyExW(ClassGuid,
1056 KEY_ALL_ACCESS,
1057 DIOCR_INSTALLER,
1058 MachineName,
1059 Reserved);
1060 if (hKey == INVALID_HANDLE_VALUE)
1062 return FALSE;
1065 if (RequiredSize != NULL)
1067 dwLength = 0;
1068 if (RegQueryValueExW(hKey,
1069 Class,
1070 NULL,
1071 NULL,
1072 NULL,
1073 &dwLength))
1075 RegCloseKey(hKey);
1076 return FALSE;
1079 *RequiredSize = dwLength / sizeof(WCHAR);
1082 dwLength = ClassNameSize * sizeof(WCHAR);
1083 if (RegQueryValueExW(hKey,
1084 Class,
1085 NULL,
1086 NULL,
1087 (LPBYTE)ClassName,
1088 &dwLength))
1090 RegCloseKey(hKey);
1091 return FALSE;
1094 RegCloseKey(hKey);
1096 return TRUE;
1099 /***********************************************************************
1100 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1102 HDEVINFO WINAPI
1103 SetupDiCreateDeviceInfoList(const GUID *ClassGuid,
1104 HWND hwndParent)
1106 return SetupDiCreateDeviceInfoListExW(ClassGuid, hwndParent, NULL, NULL);
1109 /***********************************************************************
1110 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1112 HDEVINFO WINAPI
1113 SetupDiCreateDeviceInfoListExA(const GUID *ClassGuid,
1114 HWND hwndParent,
1115 PCSTR MachineName,
1116 PVOID Reserved)
1118 LPWSTR MachineNameW = NULL;
1119 HDEVINFO hDevInfo;
1121 TRACE("\n");
1123 if (MachineName)
1125 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
1126 if (MachineNameW == NULL)
1127 return INVALID_HANDLE_VALUE;
1130 hDevInfo = SetupDiCreateDeviceInfoListExW(ClassGuid, hwndParent,
1131 MachineNameW, Reserved);
1133 MyFree(MachineNameW);
1135 return hDevInfo;
1138 /***********************************************************************
1139 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1141 * Create an empty DeviceInfoSet list.
1143 * PARAMS
1144 * ClassGuid [I] if not NULL only devices with GUID ClassGuid are associated
1145 * with this list.
1146 * hwndParent [I] hwnd needed for interface related actions.
1147 * MachineName [I] name of machine to create empty DeviceInfoSet list, if NULL
1148 * local registry will be used.
1149 * Reserved [I] must be NULL
1151 * RETURNS
1152 * Success: empty list.
1153 * Failure: INVALID_HANDLE_VALUE.
1155 HDEVINFO WINAPI
1156 SetupDiCreateDeviceInfoListExW(const GUID *ClassGuid,
1157 HWND hwndParent,
1158 PCWSTR MachineName,
1159 PVOID Reserved)
1161 struct DeviceInfoSet *list = NULL;
1162 DWORD size = sizeof(struct DeviceInfoSet);
1164 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid), hwndParent,
1165 debugstr_w(MachineName), Reserved);
1167 if (MachineName && *MachineName)
1169 FIXME("remote support is not implemented\n");
1170 SetLastError(ERROR_INVALID_MACHINENAME);
1171 return INVALID_HANDLE_VALUE;
1174 if (Reserved != NULL)
1176 SetLastError(ERROR_INVALID_PARAMETER);
1177 return INVALID_HANDLE_VALUE;
1180 list = HeapAlloc(GetProcessHeap(), 0, size);
1181 if (!list)
1183 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1184 return INVALID_HANDLE_VALUE;
1187 list->magic = SETUP_DEVICE_INFO_SET_MAGIC;
1188 list->hwndParent = hwndParent;
1189 memcpy(&list->ClassGuid,
1190 ClassGuid ? ClassGuid : &GUID_NULL,
1191 sizeof(list->ClassGuid));
1192 list->cDevices = 0;
1193 list_init(&list->devices);
1195 return list;
1198 /***********************************************************************
1199 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1201 HKEY WINAPI SetupDiCreateDevRegKeyA(
1202 HDEVINFO DeviceInfoSet,
1203 PSP_DEVINFO_DATA DeviceInfoData,
1204 DWORD Scope,
1205 DWORD HwProfile,
1206 DWORD KeyType,
1207 HINF InfHandle,
1208 PCSTR InfSectionName)
1210 PWSTR InfSectionNameW = NULL;
1211 HKEY key;
1213 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet, DeviceInfoData, Scope,
1214 HwProfile, KeyType, InfHandle, debugstr_a(InfSectionName));
1216 if (InfHandle)
1218 if (!InfSectionName)
1220 SetLastError(ERROR_INVALID_PARAMETER);
1221 return INVALID_HANDLE_VALUE;
1223 else
1225 InfSectionNameW = MultiByteToUnicode(InfSectionName, CP_ACP);
1226 if (InfSectionNameW == NULL) return INVALID_HANDLE_VALUE;
1229 key = SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, Scope,
1230 HwProfile, KeyType, InfHandle, InfSectionNameW);
1231 MyFree(InfSectionNameW);
1232 return key;
1235 /***********************************************************************
1236 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1238 HKEY WINAPI SetupDiCreateDevRegKeyW(
1239 HDEVINFO DeviceInfoSet,
1240 PSP_DEVINFO_DATA DeviceInfoData,
1241 DWORD Scope,
1242 DWORD HwProfile,
1243 DWORD KeyType,
1244 HINF InfHandle,
1245 PCWSTR InfSectionName)
1247 struct DeviceInfoSet *set = DeviceInfoSet;
1248 struct DeviceInfo *devInfo;
1249 HKEY key = INVALID_HANDLE_VALUE;
1251 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet, DeviceInfoData, Scope,
1252 HwProfile, KeyType, InfHandle, debugstr_w(InfSectionName));
1254 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
1256 SetLastError(ERROR_INVALID_HANDLE);
1257 return INVALID_HANDLE_VALUE;
1259 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1261 SetLastError(ERROR_INVALID_HANDLE);
1262 return INVALID_HANDLE_VALUE;
1264 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
1265 || !DeviceInfoData->Reserved)
1267 SetLastError(ERROR_INVALID_PARAMETER);
1268 return INVALID_HANDLE_VALUE;
1270 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1271 if (devInfo->set != set)
1273 SetLastError(ERROR_INVALID_PARAMETER);
1274 return INVALID_HANDLE_VALUE;
1276 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
1278 SetLastError(ERROR_INVALID_FLAGS);
1279 return INVALID_HANDLE_VALUE;
1281 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV)
1283 SetLastError(ERROR_INVALID_FLAGS);
1284 return INVALID_HANDLE_VALUE;
1286 if (devInfo->phantom)
1288 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
1289 return INVALID_HANDLE_VALUE;
1291 if (Scope != DICS_FLAG_GLOBAL)
1292 FIXME("unimplemented for scope %d\n", Scope);
1293 switch (KeyType)
1295 case DIREG_DEV:
1296 key = SETUPDI_CreateDevKey(devInfo);
1297 break;
1298 case DIREG_DRV:
1299 key = SETUPDI_CreateDrvKey(devInfo);
1300 break;
1301 default:
1302 WARN("unknown KeyType %d\n", KeyType);
1304 if (InfHandle)
1305 SetupInstallFromInfSectionW(NULL, InfHandle, InfSectionName, SPINST_ALL,
1306 NULL, NULL, SP_COPY_NEWER_ONLY, NULL, NULL, DeviceInfoSet,
1307 DeviceInfoData);
1308 return key;
1311 /***********************************************************************
1312 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1314 BOOL WINAPI SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet, PCSTR DeviceName,
1315 const GUID *ClassGuid, PCSTR DeviceDescription, HWND hwndParent, DWORD CreationFlags,
1316 PSP_DEVINFO_DATA DeviceInfoData)
1318 BOOL ret = FALSE;
1319 LPWSTR DeviceNameW = NULL;
1320 LPWSTR DeviceDescriptionW = NULL;
1322 if (DeviceName)
1324 DeviceNameW = MultiByteToUnicode(DeviceName, CP_ACP);
1325 if (DeviceNameW == NULL) return FALSE;
1327 if (DeviceDescription)
1329 DeviceDescriptionW = MultiByteToUnicode(DeviceDescription, CP_ACP);
1330 if (DeviceDescriptionW == NULL)
1332 MyFree(DeviceNameW);
1333 return FALSE;
1337 ret = SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceNameW, ClassGuid, DeviceDescriptionW,
1338 hwndParent, CreationFlags, DeviceInfoData);
1340 MyFree(DeviceNameW);
1341 MyFree(DeviceDescriptionW);
1343 return ret;
1346 static DWORD SETUPDI_DevNameToDevID(LPCWSTR devName)
1348 LPCWSTR ptr;
1349 int devNameLen = lstrlenW(devName);
1350 DWORD devInst = 0;
1351 BOOL valid = TRUE;
1353 TRACE("%s\n", debugstr_w(devName));
1354 for (ptr = devName; valid && *ptr && ptr - devName < devNameLen; )
1356 if (isdigitW(*ptr))
1358 devInst *= 10;
1359 devInst |= *ptr - '0';
1360 ptr++;
1362 else
1363 valid = FALSE;
1365 TRACE("%d\n", valid ? devInst : 0xffffffff);
1366 return valid ? devInst : 0xffffffff;
1369 /***********************************************************************
1370 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1372 BOOL WINAPI SetupDiCreateDeviceInfoW(HDEVINFO DeviceInfoSet, PCWSTR DeviceName,
1373 const GUID *ClassGuid, PCWSTR DeviceDescription, HWND hwndParent, DWORD CreationFlags,
1374 PSP_DEVINFO_DATA DeviceInfoData)
1376 struct DeviceInfoSet *set = DeviceInfoSet;
1377 BOOL ret = FALSE, allocatedInstanceId = FALSE;
1378 LPCWSTR instanceId = NULL;
1380 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet, debugstr_w(DeviceName),
1381 debugstr_guid(ClassGuid), debugstr_w(DeviceDescription),
1382 hwndParent, CreationFlags, DeviceInfoData);
1384 if (!DeviceName)
1386 SetLastError(ERROR_INVALID_DEVINST_NAME);
1387 return FALSE;
1389 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
1391 SetLastError(ERROR_INVALID_HANDLE);
1392 return FALSE;
1394 if (!ClassGuid)
1396 SetLastError(ERROR_INVALID_PARAMETER);
1397 return FALSE;
1399 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1401 SetLastError(ERROR_INVALID_HANDLE);
1402 return FALSE;
1404 if (!IsEqualGUID(&set->ClassGuid, &GUID_NULL) &&
1405 !IsEqualGUID(ClassGuid, &set->ClassGuid))
1407 SetLastError(ERROR_CLASS_MISMATCH);
1408 return FALSE;
1410 if ((CreationFlags & DICD_GENERATE_ID))
1412 if (strchrW(DeviceName, '\\'))
1413 SetLastError(ERROR_INVALID_DEVINST_NAME);
1414 else
1416 static const WCHAR newDeviceFmt[] = {'R','O','O','T','\\','%','s',
1417 '\\','%','0','4','d',0};
1418 DWORD devId;
1420 if (set->cDevices)
1422 DWORD highestDevID = 0;
1423 struct DeviceInstance *devInst;
1425 LIST_FOR_EACH_ENTRY(devInst, &set->devices, struct DeviceInstance, entry)
1427 struct DeviceInfo *devInfo = (struct DeviceInfo *)devInst->data.Reserved;
1428 LPCWSTR devName = strrchrW(devInfo->instanceId, '\\');
1429 DWORD id;
1431 if (devName)
1432 devName++;
1433 else
1434 devName = devInfo->instanceId;
1435 id = SETUPDI_DevNameToDevID(devName);
1436 if (id != 0xffffffff && id > highestDevID)
1437 highestDevID = id;
1439 devId = highestDevID + 1;
1441 else
1442 devId = 0;
1443 /* 17 == lstrlenW(L"Root\\") + lstrlenW("\\") + 1 + %d max size */
1444 instanceId = HeapAlloc(GetProcessHeap(), 0,
1445 (17 + lstrlenW(DeviceName)) * sizeof(WCHAR));
1446 if (instanceId)
1448 sprintfW((LPWSTR)instanceId, newDeviceFmt, DeviceName,
1449 devId);
1450 allocatedInstanceId = TRUE;
1451 ret = TRUE;
1453 else
1454 ret = FALSE;
1457 else
1459 struct DeviceInstance *devInst;
1461 ret = TRUE;
1462 instanceId = DeviceName;
1463 LIST_FOR_EACH_ENTRY(devInst, &set->devices, struct DeviceInstance, entry)
1465 struct DeviceInfo *devInfo = (struct DeviceInfo *)devInst->data.Reserved;
1467 if (!lstrcmpiW(DeviceName, devInfo->instanceId))
1469 SetLastError(ERROR_DEVINST_ALREADY_EXISTS);
1470 ret = FALSE;
1474 if (ret)
1476 SP_DEVINFO_DATA *dev = NULL;
1478 ret = SETUPDI_AddDeviceToSet(set, ClassGuid, 0 /* FIXME: DevInst */,
1479 instanceId, TRUE, &dev);
1480 if (ret)
1482 if (DeviceDescription)
1483 SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet,
1484 dev, SPDRP_DEVICEDESC, (const BYTE *)DeviceDescription,
1485 lstrlenW(DeviceDescription) * sizeof(WCHAR));
1486 if (DeviceInfoData)
1488 if (DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA))
1490 SetLastError(ERROR_INVALID_USER_BUFFER);
1491 ret = FALSE;
1493 else
1494 *DeviceInfoData = *dev;
1498 if (allocatedInstanceId)
1499 HeapFree(GetProcessHeap(), 0, (LPWSTR)instanceId);
1501 return ret;
1504 /***********************************************************************
1505 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1507 BOOL WINAPI SetupDiRegisterDeviceInfo(
1508 HDEVINFO DeviceInfoSet,
1509 PSP_DEVINFO_DATA DeviceInfoData,
1510 DWORD Flags,
1511 PSP_DETSIG_CMPPROC CompareProc,
1512 PVOID CompareContext,
1513 PSP_DEVINFO_DATA DupDeviceInfoData)
1515 struct DeviceInfoSet *set = DeviceInfoSet;
1516 struct DeviceInfo *devInfo;
1518 TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet, DeviceInfoData, Flags,
1519 CompareProc, CompareContext, DupDeviceInfoData);
1521 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
1523 SetLastError(ERROR_INVALID_HANDLE);
1524 return FALSE;
1526 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1528 SetLastError(ERROR_INVALID_HANDLE);
1529 return FALSE;
1531 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
1532 || !DeviceInfoData->Reserved)
1534 SetLastError(ERROR_INVALID_PARAMETER);
1535 return FALSE;
1537 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1538 if (devInfo->set != set)
1540 SetLastError(ERROR_INVALID_PARAMETER);
1541 return FALSE;
1543 if (devInfo->phantom)
1545 devInfo->phantom = FALSE;
1546 RegDeleteValueW(devInfo->key, Phantom);
1548 return TRUE;
1551 /***********************************************************************
1552 * SetupDiRemoveDevice (SETUPAPI.@)
1554 BOOL WINAPI SetupDiRemoveDevice(
1555 HDEVINFO devinfo,
1556 PSP_DEVINFO_DATA info)
1558 FIXME("(%p, %p): stub\n", devinfo, info);
1559 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1560 return FALSE;
1563 /***********************************************************************
1564 * SetupDiRemoveDeviceInterface (SETUPAPI.@)
1566 BOOL WINAPI SetupDiRemoveDeviceInterface(HDEVINFO info, PSP_DEVICE_INTERFACE_DATA data)
1568 FIXME("(%p, %p): stub\n", info, data);
1569 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1570 return FALSE;
1573 /***********************************************************************
1574 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1576 BOOL WINAPI SetupDiEnumDeviceInfo(
1577 HDEVINFO devinfo,
1578 DWORD index,
1579 PSP_DEVINFO_DATA info)
1581 BOOL ret = FALSE;
1583 TRACE("%p %d %p\n", devinfo, index, info);
1585 if(info==NULL)
1587 SetLastError(ERROR_INVALID_PARAMETER);
1588 return FALSE;
1590 if (devinfo && devinfo != INVALID_HANDLE_VALUE)
1592 struct DeviceInfoSet *list = devinfo;
1593 if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC)
1595 if (index < list->cDevices)
1597 if (info->cbSize == sizeof(SP_DEVINFO_DATA))
1599 struct DeviceInstance *devInst;
1600 DWORD i = 0;
1602 LIST_FOR_EACH_ENTRY(devInst, &list->devices,
1603 struct DeviceInstance, entry)
1605 if (i++ == index)
1607 *info = devInst->data;
1608 break;
1611 ret = TRUE;
1613 else
1614 SetLastError(ERROR_INVALID_USER_BUFFER);
1616 else
1617 SetLastError(ERROR_NO_MORE_ITEMS);
1619 else
1620 SetLastError(ERROR_INVALID_HANDLE);
1622 else
1623 SetLastError(ERROR_INVALID_HANDLE);
1624 return ret;
1627 /***********************************************************************
1628 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1630 BOOL WINAPI SetupDiGetDeviceInstanceIdA(
1631 HDEVINFO DeviceInfoSet,
1632 PSP_DEVINFO_DATA DeviceInfoData,
1633 PSTR DeviceInstanceId,
1634 DWORD DeviceInstanceIdSize,
1635 PDWORD RequiredSize)
1637 BOOL ret = FALSE;
1638 DWORD size;
1639 PWSTR instanceId;
1641 TRACE("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId,
1642 DeviceInstanceIdSize, RequiredSize);
1644 SetupDiGetDeviceInstanceIdW(DeviceInfoSet,
1645 DeviceInfoData,
1646 NULL,
1648 &size);
1649 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
1650 return FALSE;
1651 instanceId = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
1652 if (instanceId)
1654 ret = SetupDiGetDeviceInstanceIdW(DeviceInfoSet,
1655 DeviceInfoData,
1656 instanceId,
1657 size,
1658 &size);
1659 if (ret)
1661 int len = WideCharToMultiByte(CP_ACP, 0, instanceId, -1,
1662 DeviceInstanceId,
1663 DeviceInstanceIdSize, NULL, NULL);
1665 if (!len)
1666 ret = FALSE;
1667 else
1669 if (len > DeviceInstanceIdSize)
1671 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1672 ret = FALSE;
1674 if (RequiredSize)
1675 *RequiredSize = len;
1678 HeapFree(GetProcessHeap(), 0, instanceId);
1680 return ret;
1683 /***********************************************************************
1684 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1686 BOOL WINAPI SetupDiGetDeviceInstanceIdW(
1687 HDEVINFO DeviceInfoSet,
1688 PSP_DEVINFO_DATA DeviceInfoData,
1689 PWSTR DeviceInstanceId,
1690 DWORD DeviceInstanceIdSize,
1691 PDWORD RequiredSize)
1693 struct DeviceInfoSet *set = DeviceInfoSet;
1694 struct DeviceInfo *devInfo;
1696 TRACE("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId,
1697 DeviceInstanceIdSize, RequiredSize);
1699 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
1701 SetLastError(ERROR_INVALID_HANDLE);
1702 return FALSE;
1704 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
1706 SetLastError(ERROR_INVALID_HANDLE);
1707 return FALSE;
1709 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
1710 || !DeviceInfoData->Reserved)
1712 SetLastError(ERROR_INVALID_PARAMETER);
1713 return FALSE;
1715 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
1716 if (devInfo->set != set)
1718 SetLastError(ERROR_INVALID_PARAMETER);
1719 return FALSE;
1721 TRACE("instance ID: %s\n", debugstr_w(devInfo->instanceId));
1722 if (DeviceInstanceIdSize < strlenW(devInfo->instanceId) + 1)
1724 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1725 if (RequiredSize)
1726 *RequiredSize = lstrlenW(devInfo->instanceId) + 1;
1727 return FALSE;
1729 lstrcpyW(DeviceInstanceId, devInfo->instanceId);
1730 if (RequiredSize)
1731 *RequiredSize = lstrlenW(devInfo->instanceId) + 1;
1732 return TRUE;
1735 /***********************************************************************
1736 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1738 BOOL WINAPI SetupDiGetActualSectionToInstallA(
1739 HINF InfHandle,
1740 PCSTR InfSectionName,
1741 PSTR InfSectionWithExt,
1742 DWORD InfSectionWithExtSize,
1743 PDWORD RequiredSize,
1744 PSTR *Extension)
1746 FIXME("\n");
1747 return FALSE;
1750 /***********************************************************************
1751 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
1753 BOOL WINAPI SetupDiGetActualSectionToInstallW(
1754 HINF InfHandle,
1755 PCWSTR InfSectionName,
1756 PWSTR InfSectionWithExt,
1757 DWORD InfSectionWithExtSize,
1758 PDWORD RequiredSize,
1759 PWSTR *Extension)
1761 WCHAR szBuffer[MAX_PATH];
1762 DWORD dwLength;
1763 DWORD dwFullLength;
1764 LONG lLineCount = -1;
1766 lstrcpyW(szBuffer, InfSectionName);
1767 dwLength = lstrlenW(szBuffer);
1769 if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
1771 /* Test section name with '.NTx86' extension */
1772 lstrcpyW(&szBuffer[dwLength], NtPlatformExtension);
1773 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1775 if (lLineCount == -1)
1777 /* Test section name with '.NT' extension */
1778 lstrcpyW(&szBuffer[dwLength], NtExtension);
1779 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1782 else
1784 /* Test section name with '.Win' extension */
1785 lstrcpyW(&szBuffer[dwLength], WinExtension);
1786 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1789 if (lLineCount == -1)
1791 /* Test section name without extension */
1792 szBuffer[dwLength] = 0;
1793 lLineCount = SetupGetLineCountW(InfHandle, szBuffer);
1796 if (lLineCount == -1)
1798 SetLastError(ERROR_INVALID_PARAMETER);
1799 return FALSE;
1802 dwFullLength = lstrlenW(szBuffer);
1804 if (InfSectionWithExt != NULL && InfSectionWithExtSize != 0)
1806 if (InfSectionWithExtSize < (dwFullLength + 1))
1808 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1809 return FALSE;
1812 lstrcpyW(InfSectionWithExt, szBuffer);
1813 if (Extension != NULL)
1815 *Extension = (dwLength == dwFullLength) ? NULL : &InfSectionWithExt[dwLength];
1819 if (RequiredSize != NULL)
1821 *RequiredSize = dwFullLength + 1;
1824 return TRUE;
1827 /***********************************************************************
1828 * SetupDiGetClassDescriptionA (SETUPAPI.@)
1830 BOOL WINAPI SetupDiGetClassDescriptionA(
1831 const GUID* ClassGuid,
1832 PSTR ClassDescription,
1833 DWORD ClassDescriptionSize,
1834 PDWORD RequiredSize)
1836 return SetupDiGetClassDescriptionExA(ClassGuid, ClassDescription,
1837 ClassDescriptionSize,
1838 RequiredSize, NULL, NULL);
1841 /***********************************************************************
1842 * SetupDiGetClassDescriptionW (SETUPAPI.@)
1844 BOOL WINAPI SetupDiGetClassDescriptionW(
1845 const GUID* ClassGuid,
1846 PWSTR ClassDescription,
1847 DWORD ClassDescriptionSize,
1848 PDWORD RequiredSize)
1850 return SetupDiGetClassDescriptionExW(ClassGuid, ClassDescription,
1851 ClassDescriptionSize,
1852 RequiredSize, NULL, NULL);
1855 /***********************************************************************
1856 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
1858 BOOL WINAPI SetupDiGetClassDescriptionExA(
1859 const GUID* ClassGuid,
1860 PSTR ClassDescription,
1861 DWORD ClassDescriptionSize,
1862 PDWORD RequiredSize,
1863 PCSTR MachineName,
1864 PVOID Reserved)
1866 HKEY hKey;
1867 DWORD dwLength;
1868 BOOL ret;
1870 hKey = SetupDiOpenClassRegKeyExA(ClassGuid,
1871 KEY_ALL_ACCESS,
1872 DIOCR_INSTALLER,
1873 MachineName,
1874 Reserved);
1875 if (hKey == INVALID_HANDLE_VALUE)
1877 WARN("SetupDiOpenClassRegKeyExA() failed (Error %u)\n", GetLastError());
1878 return FALSE;
1881 dwLength = ClassDescriptionSize;
1882 ret = !RegQueryValueExA( hKey, NULL, NULL, NULL,
1883 (LPBYTE)ClassDescription, &dwLength );
1884 if (RequiredSize) *RequiredSize = dwLength;
1885 RegCloseKey(hKey);
1886 return ret;
1889 /***********************************************************************
1890 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
1892 BOOL WINAPI SetupDiGetClassDescriptionExW(
1893 const GUID* ClassGuid,
1894 PWSTR ClassDescription,
1895 DWORD ClassDescriptionSize,
1896 PDWORD RequiredSize,
1897 PCWSTR MachineName,
1898 PVOID Reserved)
1900 HKEY hKey;
1901 DWORD dwLength;
1902 BOOL ret;
1904 hKey = SetupDiOpenClassRegKeyExW(ClassGuid,
1905 KEY_ALL_ACCESS,
1906 DIOCR_INSTALLER,
1907 MachineName,
1908 Reserved);
1909 if (hKey == INVALID_HANDLE_VALUE)
1911 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
1912 return FALSE;
1915 dwLength = ClassDescriptionSize * sizeof(WCHAR);
1916 ret = !RegQueryValueExW( hKey, NULL, NULL, NULL,
1917 (LPBYTE)ClassDescription, &dwLength );
1918 if (RequiredSize) *RequiredSize = dwLength / sizeof(WCHAR);
1919 RegCloseKey(hKey);
1920 return ret;
1923 /***********************************************************************
1924 * SetupDiGetClassDevsA (SETUPAPI.@)
1926 HDEVINFO WINAPI SetupDiGetClassDevsA(const GUID *class, LPCSTR enumstr, HWND parent, DWORD flags)
1928 HDEVINFO ret;
1929 LPWSTR enumstrW = NULL;
1931 if (enumstr)
1933 int len = MultiByteToWideChar(CP_ACP, 0, enumstr, -1, NULL, 0);
1934 enumstrW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1935 if (!enumstrW)
1937 ret = INVALID_HANDLE_VALUE;
1938 goto end;
1940 MultiByteToWideChar(CP_ACP, 0, enumstr, -1, enumstrW, len);
1942 ret = SetupDiGetClassDevsExW(class, enumstrW, parent, flags, NULL, NULL,
1943 NULL);
1944 HeapFree(GetProcessHeap(), 0, enumstrW);
1946 end:
1947 return ret;
1950 /***********************************************************************
1951 * SetupDiGetClassDevsExA (SETUPAPI.@)
1953 HDEVINFO WINAPI SetupDiGetClassDevsExA(
1954 const GUID *class,
1955 PCSTR enumstr,
1956 HWND parent,
1957 DWORD flags,
1958 HDEVINFO deviceset,
1959 PCSTR machine,
1960 PVOID reserved)
1962 HDEVINFO ret;
1963 LPWSTR enumstrW = NULL, machineW = NULL;
1965 if (enumstr)
1967 int len = MultiByteToWideChar(CP_ACP, 0, enumstr, -1, NULL, 0);
1968 enumstrW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1969 if (!enumstrW)
1971 ret = INVALID_HANDLE_VALUE;
1972 goto end;
1974 MultiByteToWideChar(CP_ACP, 0, enumstr, -1, enumstrW, len);
1976 if (machine)
1978 int len = MultiByteToWideChar(CP_ACP, 0, machine, -1, NULL, 0);
1979 machineW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1980 if (!machineW)
1982 HeapFree(GetProcessHeap(), 0, enumstrW);
1983 ret = INVALID_HANDLE_VALUE;
1984 goto end;
1986 MultiByteToWideChar(CP_ACP, 0, machine, -1, machineW, len);
1988 ret = SetupDiGetClassDevsExW(class, enumstrW, parent, flags, deviceset,
1989 machineW, reserved);
1990 HeapFree(GetProcessHeap(), 0, enumstrW);
1991 HeapFree(GetProcessHeap(), 0, machineW);
1993 end:
1994 return ret;
1997 static void SETUPDI_AddDeviceInterfaces(SP_DEVINFO_DATA *dev, HKEY key,
1998 const GUID *guid)
2000 DWORD i, len;
2001 WCHAR subKeyName[MAX_PATH];
2002 LONG l = ERROR_SUCCESS;
2004 for (i = 0; !l; i++)
2006 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2007 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2008 if (!l)
2010 HKEY subKey;
2011 SP_DEVICE_INTERFACE_DATA *iface = NULL;
2013 if (*subKeyName == '#')
2015 /* The subkey name is the reference string, with a '#' prepended */
2016 SETUPDI_AddInterfaceInstance(dev, guid, subKeyName + 1, &iface);
2017 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2018 if (!l)
2020 WCHAR symbolicLink[MAX_PATH];
2021 DWORD dataType;
2023 len = sizeof(symbolicLink);
2024 l = RegQueryValueExW(subKey, SymbolicLink, NULL, &dataType,
2025 (BYTE *)symbolicLink, &len);
2026 if (!l && dataType == REG_SZ)
2027 SETUPDI_SetInterfaceSymbolicLink(iface, symbolicLink);
2028 RegCloseKey(subKey);
2031 /* Allow enumeration to continue */
2032 l = ERROR_SUCCESS;
2035 /* FIXME: find and add all the device's interfaces to the device */
2038 static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet,
2039 HKEY key, const GUID *guid, LPCWSTR enumstr)
2041 struct DeviceInfoSet *set = DeviceInfoSet;
2042 DWORD i, len;
2043 WCHAR subKeyName[MAX_PATH];
2044 LONG l;
2045 HKEY enumKey = INVALID_HANDLE_VALUE;
2047 TRACE("%s\n", debugstr_w(enumstr));
2049 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
2050 &enumKey, NULL);
2051 for (i = 0; !l; i++)
2053 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2054 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2055 if (!l)
2057 HKEY subKey;
2059 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2060 if (!l)
2062 WCHAR deviceInst[MAX_PATH * 3];
2063 DWORD dataType;
2065 len = sizeof(deviceInst);
2066 l = RegQueryValueExW(subKey, DeviceInstance, NULL, &dataType,
2067 (BYTE *)deviceInst, &len);
2068 if (!l && dataType == REG_SZ)
2070 TRACE("found instance ID %s\n", debugstr_w(deviceInst));
2071 if (!enumstr || !lstrcmpiW(enumstr, deviceInst))
2073 HKEY deviceKey;
2075 l = RegOpenKeyExW(enumKey, deviceInst, 0, KEY_READ,
2076 &deviceKey);
2077 if (!l)
2079 WCHAR deviceClassStr[40];
2081 len = sizeof(deviceClassStr);
2082 l = RegQueryValueExW(deviceKey, ClassGUID, NULL,
2083 &dataType, (BYTE *)deviceClassStr, &len);
2084 if (!l && dataType == REG_SZ &&
2085 deviceClassStr[0] == '{' &&
2086 deviceClassStr[37] == '}')
2088 GUID deviceClass;
2089 SP_DEVINFO_DATA *dev;
2091 deviceClassStr[37] = 0;
2092 UuidFromStringW(&deviceClassStr[1],
2093 &deviceClass);
2094 if (SETUPDI_AddDeviceToSet(set, &deviceClass,
2095 0 /* FIXME: DevInst */, deviceInst,
2096 FALSE, &dev))
2097 SETUPDI_AddDeviceInterfaces(dev, subKey, guid);
2099 RegCloseKey(deviceKey);
2103 RegCloseKey(subKey);
2105 /* Allow enumeration to continue */
2106 l = ERROR_SUCCESS;
2109 if (enumKey != INVALID_HANDLE_VALUE)
2110 RegCloseKey(enumKey);
2113 static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet,
2114 const GUID *guid, LPCWSTR enumstr, DWORD flags)
2116 HKEY interfacesKey = SetupDiOpenClassRegKeyExW(guid, KEY_READ,
2117 DIOCR_INTERFACE, NULL, NULL);
2119 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(guid),
2120 debugstr_w(enumstr), flags);
2122 if (interfacesKey != INVALID_HANDLE_VALUE)
2124 if (flags & DIGCF_ALLCLASSES)
2126 DWORD i, len;
2127 WCHAR interfaceGuidStr[40];
2128 LONG l = ERROR_SUCCESS;
2130 for (i = 0; !l; i++)
2132 len = sizeof(interfaceGuidStr) / sizeof(interfaceGuidStr[0]);
2133 l = RegEnumKeyExW(interfacesKey, i, interfaceGuidStr, &len,
2134 NULL, NULL, NULL, NULL);
2135 if (!l)
2137 if (interfaceGuidStr[0] == '{' &&
2138 interfaceGuidStr[37] == '}')
2140 HKEY interfaceKey;
2141 GUID interfaceGuid;
2143 interfaceGuidStr[37] = 0;
2144 UuidFromStringW(&interfaceGuidStr[1], &interfaceGuid);
2145 interfaceGuidStr[37] = '}';
2146 interfaceGuidStr[38] = 0;
2147 l = RegOpenKeyExW(interfacesKey, interfaceGuidStr, 0,
2148 KEY_READ, &interfaceKey);
2149 if (!l)
2151 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
2152 interfaceKey, &interfaceGuid, enumstr);
2153 RegCloseKey(interfaceKey);
2159 else
2161 /* In this case, SetupDiOpenClassRegKeyExW opened the specific
2162 * interface's key, so just pass that long
2164 SETUPDI_EnumerateMatchingInterfaces(DeviceInfoSet,
2165 interfacesKey, guid, enumstr);
2167 RegCloseKey(interfacesKey);
2171 static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet *set,
2172 LPCWSTR enumerator, LPCWSTR deviceName, HKEY deviceKey,
2173 const GUID *class, DWORD flags)
2175 DWORD i, len;
2176 WCHAR deviceInstance[MAX_PATH];
2177 LONG l = ERROR_SUCCESS;
2179 TRACE("%s %s\n", debugstr_w(enumerator), debugstr_w(deviceName));
2181 for (i = 0; !l; i++)
2183 len = sizeof(deviceInstance) / sizeof(deviceInstance[0]);
2184 l = RegEnumKeyExW(deviceKey, i, deviceInstance, &len, NULL, NULL, NULL,
2185 NULL);
2186 if (!l)
2188 HKEY subKey;
2190 l = RegOpenKeyExW(deviceKey, deviceInstance, 0, KEY_READ, &subKey);
2191 if (!l)
2193 WCHAR classGuid[40];
2194 DWORD dataType;
2196 len = sizeof(classGuid);
2197 l = RegQueryValueExW(subKey, ClassGUID, NULL, &dataType,
2198 (BYTE *)classGuid, &len);
2199 if (!l && dataType == REG_SZ)
2201 if (classGuid[0] == '{' && classGuid[37] == '}')
2203 GUID deviceClass;
2205 classGuid[37] = 0;
2206 UuidFromStringW(&classGuid[1], &deviceClass);
2207 if ((flags & DIGCF_ALLCLASSES) ||
2208 IsEqualGUID(class, &deviceClass))
2210 static const WCHAR fmt[] =
2211 {'%','s','\\','%','s','\\','%','s',0};
2212 LPWSTR instanceId;
2214 instanceId = HeapAlloc(GetProcessHeap(), 0,
2215 (lstrlenW(enumerator) + lstrlenW(deviceName) +
2216 lstrlenW(deviceInstance) + 3) * sizeof(WCHAR));
2217 if (instanceId)
2219 sprintfW(instanceId, fmt, enumerator,
2220 deviceName, deviceInstance);
2221 SETUPDI_AddDeviceToSet(set, &deviceClass,
2222 0 /* FIXME: DevInst */, instanceId,
2223 FALSE, NULL);
2224 HeapFree(GetProcessHeap(), 0, instanceId);
2229 RegCloseKey(subKey);
2231 /* Allow enumeration to continue */
2232 l = ERROR_SUCCESS;
2237 static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet,
2238 LPCWSTR parent, HKEY key, const GUID *class, DWORD flags)
2240 struct DeviceInfoSet *set = DeviceInfoSet;
2241 DWORD i, len;
2242 WCHAR subKeyName[MAX_PATH];
2243 LONG l = ERROR_SUCCESS;
2245 TRACE("%s\n", debugstr_w(parent));
2247 for (i = 0; !l; i++)
2249 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2250 l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
2251 if (!l)
2253 HKEY subKey;
2255 l = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
2256 if (!l)
2258 TRACE("%s\n", debugstr_w(subKeyName));
2259 SETUPDI_EnumerateMatchingDeviceInstances(set, parent,
2260 subKeyName, subKey, class, flags);
2261 RegCloseKey(subKey);
2263 /* Allow enumeration to continue */
2264 l = ERROR_SUCCESS;
2269 static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet, const GUID *class,
2270 LPCWSTR enumstr, DWORD flags)
2272 HKEY enumKey;
2273 LONG l;
2275 TRACE("%p, %s, %s, %08x\n", DeviceInfoSet, debugstr_guid(class),
2276 debugstr_w(enumstr), flags);
2278 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL,
2279 &enumKey, NULL);
2280 if (enumKey != INVALID_HANDLE_VALUE)
2282 if (enumstr)
2284 HKEY enumStrKey;
2286 l = RegOpenKeyExW(enumKey, enumstr, 0, KEY_READ,
2287 &enumStrKey);
2288 if (!l)
2290 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet, enumstr,
2291 enumStrKey, class, flags);
2292 RegCloseKey(enumStrKey);
2295 else
2297 DWORD i, len;
2298 WCHAR subKeyName[MAX_PATH];
2300 l = ERROR_SUCCESS;
2301 for (i = 0; !l; i++)
2303 len = sizeof(subKeyName) / sizeof(subKeyName[0]);
2304 l = RegEnumKeyExW(enumKey, i, subKeyName, &len, NULL,
2305 NULL, NULL, NULL);
2306 if (!l)
2308 HKEY subKey;
2310 l = RegOpenKeyExW(enumKey, subKeyName, 0, KEY_READ,
2311 &subKey);
2312 if (!l)
2314 SETUPDI_EnumerateMatchingDevices(DeviceInfoSet,
2315 subKeyName, subKey, class, flags);
2316 RegCloseKey(subKey);
2318 /* Allow enumeration to continue */
2319 l = ERROR_SUCCESS;
2323 RegCloseKey(enumKey);
2327 /***********************************************************************
2328 * SetupDiGetClassDevsW (SETUPAPI.@)
2330 HDEVINFO WINAPI SetupDiGetClassDevsW(const GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
2332 return SetupDiGetClassDevsExW(class, enumstr, parent, flags, NULL, NULL,
2333 NULL);
2336 /***********************************************************************
2337 * SetupDiGetClassDevsExW (SETUPAPI.@)
2339 HDEVINFO WINAPI SetupDiGetClassDevsExW(const GUID *class, PCWSTR enumstr, HWND parent, DWORD flags,
2340 HDEVINFO deviceset, PCWSTR machine, void *reserved)
2342 static const DWORD unsupportedFlags = DIGCF_DEFAULT | DIGCF_PRESENT |
2343 DIGCF_PROFILE;
2344 HDEVINFO set;
2346 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2347 debugstr_w(enumstr), parent, flags, deviceset, debugstr_w(machine),
2348 reserved);
2350 if (!(flags & DIGCF_ALLCLASSES) && !class)
2352 SetLastError(ERROR_INVALID_PARAMETER);
2353 return INVALID_HANDLE_VALUE;
2355 if (flags & unsupportedFlags)
2356 WARN("unsupported flags %08x\n", flags & unsupportedFlags);
2357 if (deviceset)
2358 set = deviceset;
2359 else
2360 set = SetupDiCreateDeviceInfoListExW(class, parent, machine, reserved);
2361 if (set != INVALID_HANDLE_VALUE)
2363 if (machine && *machine)
2364 FIXME("%s: unimplemented for remote machines\n",
2365 debugstr_w(machine));
2366 else if (flags & DIGCF_DEVICEINTERFACE)
2367 SETUPDI_EnumerateInterfaces(set, class, enumstr, flags);
2368 else
2369 SETUPDI_EnumerateDevices(set, class, enumstr, flags);
2371 return set;
2374 /***********************************************************************
2375 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2377 BOOL WINAPI SetupDiGetDeviceInfoListDetailA(
2378 HDEVINFO DeviceInfoSet,
2379 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData )
2381 struct DeviceInfoSet *set = DeviceInfoSet;
2383 TRACE("%p %p\n", DeviceInfoSet, DevInfoData);
2385 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2387 SetLastError(ERROR_INVALID_HANDLE);
2388 return FALSE;
2390 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2392 SetLastError(ERROR_INVALID_HANDLE);
2393 return FALSE;
2395 if (!DevInfoData ||
2396 DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A))
2398 SetLastError(ERROR_INVALID_PARAMETER);
2399 return FALSE;
2401 DevInfoData->ClassGuid = set->ClassGuid;
2402 DevInfoData->RemoteMachineHandle = NULL;
2403 DevInfoData->RemoteMachineName[0] = '\0';
2404 return TRUE;
2407 /***********************************************************************
2408 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2410 BOOL WINAPI SetupDiGetDeviceInfoListDetailW(
2411 HDEVINFO DeviceInfoSet,
2412 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData )
2414 struct DeviceInfoSet *set = DeviceInfoSet;
2416 TRACE("%p %p\n", DeviceInfoSet, DevInfoData);
2418 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2420 SetLastError(ERROR_INVALID_HANDLE);
2421 return FALSE;
2423 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2425 SetLastError(ERROR_INVALID_HANDLE);
2426 return FALSE;
2428 if (!DevInfoData ||
2429 DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W))
2431 SetLastError(ERROR_INVALID_PARAMETER);
2432 return FALSE;
2434 DevInfoData->ClassGuid = set->ClassGuid;
2435 DevInfoData->RemoteMachineHandle = NULL;
2436 DevInfoData->RemoteMachineName[0] = '\0';
2437 return TRUE;
2440 /***********************************************************************
2441 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2443 BOOL WINAPI SetupDiCreateDeviceInterfaceA(
2444 HDEVINFO DeviceInfoSet,
2445 PSP_DEVINFO_DATA DeviceInfoData,
2446 const GUID *InterfaceClassGuid,
2447 PCSTR ReferenceString,
2448 DWORD CreationFlags,
2449 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2451 BOOL ret;
2452 LPWSTR ReferenceStringW = NULL;
2454 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
2455 debugstr_guid(InterfaceClassGuid), debugstr_a(ReferenceString),
2456 CreationFlags, DeviceInterfaceData);
2458 if (ReferenceString)
2460 ReferenceStringW = MultiByteToUnicode(ReferenceString, CP_ACP);
2461 if (ReferenceStringW == NULL) return FALSE;
2464 ret = SetupDiCreateDeviceInterfaceW(DeviceInfoSet, DeviceInfoData,
2465 InterfaceClassGuid, ReferenceStringW, CreationFlags,
2466 DeviceInterfaceData);
2468 MyFree(ReferenceStringW);
2470 return ret;
2473 /***********************************************************************
2474 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2476 BOOL WINAPI SetupDiCreateDeviceInterfaceW(
2477 HDEVINFO DeviceInfoSet,
2478 PSP_DEVINFO_DATA DeviceInfoData,
2479 const GUID *InterfaceClassGuid,
2480 PCWSTR ReferenceString,
2481 DWORD CreationFlags,
2482 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2484 struct DeviceInfoSet *set = DeviceInfoSet;
2485 struct DeviceInfo *devInfo;
2486 SP_DEVICE_INTERFACE_DATA *iface = NULL;
2487 BOOL ret;
2489 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData,
2490 debugstr_guid(InterfaceClassGuid), debugstr_w(ReferenceString),
2491 CreationFlags, DeviceInterfaceData);
2493 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
2495 SetLastError(ERROR_INVALID_HANDLE);
2496 return FALSE;
2498 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2500 SetLastError(ERROR_INVALID_HANDLE);
2501 return FALSE;
2503 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
2504 || !DeviceInfoData->Reserved)
2506 SetLastError(ERROR_INVALID_PARAMETER);
2507 return FALSE;
2509 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
2510 if (devInfo->set != set)
2512 SetLastError(ERROR_INVALID_PARAMETER);
2513 return FALSE;
2515 if (!InterfaceClassGuid)
2517 SetLastError(ERROR_INVALID_USER_BUFFER);
2518 return FALSE;
2520 if ((ret = SETUPDI_AddInterfaceInstance(DeviceInfoData, InterfaceClassGuid,
2521 ReferenceString, &iface)))
2523 if (DeviceInterfaceData)
2525 if (DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
2527 SetLastError(ERROR_INVALID_USER_BUFFER);
2528 ret = FALSE;
2530 else
2531 *DeviceInterfaceData = *iface;
2534 return ret;
2537 /***********************************************************************
2538 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2540 HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyA(
2541 HDEVINFO DeviceInfoSet,
2542 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2543 DWORD Reserved,
2544 REGSAM samDesired,
2545 HINF InfHandle,
2546 PCSTR InfSectionName)
2548 HKEY key;
2549 PWSTR InfSectionNameW = NULL;
2551 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
2552 samDesired, InfHandle, InfSectionName);
2553 if (InfHandle)
2555 if (!InfSectionName)
2557 SetLastError(ERROR_INVALID_PARAMETER);
2558 return INVALID_HANDLE_VALUE;
2560 InfSectionNameW = MultiByteToUnicode(InfSectionName, CP_ACP);
2561 if (!InfSectionNameW)
2562 return INVALID_HANDLE_VALUE;
2564 key = SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet,
2565 DeviceInterfaceData, Reserved, samDesired, InfHandle,
2566 InfSectionNameW);
2567 MyFree(InfSectionNameW);
2568 return key;
2571 static PWSTR SETUPDI_GetInstancePath(struct InterfaceInfo *ifaceInfo)
2573 static const WCHAR hash[] = {'#',0};
2574 PWSTR instancePath = NULL;
2576 if (ifaceInfo->referenceString)
2578 instancePath = HeapAlloc(GetProcessHeap(), 0,
2579 (lstrlenW(ifaceInfo->referenceString) + 2) * sizeof(WCHAR));
2580 if (instancePath)
2582 lstrcpyW(instancePath, hash);
2583 lstrcatW(instancePath, ifaceInfo->referenceString);
2585 else
2586 SetLastError(ERROR_OUTOFMEMORY);
2588 else
2590 instancePath = HeapAlloc(GetProcessHeap(), 0,
2591 (lstrlenW(hash) + 1) * sizeof(WCHAR));
2592 if (instancePath)
2593 lstrcpyW(instancePath, hash);
2595 return instancePath;
2598 /***********************************************************************
2599 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2601 HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyW(
2602 HDEVINFO DeviceInfoSet,
2603 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2604 DWORD Reserved,
2605 REGSAM samDesired,
2606 HINF InfHandle,
2607 PCWSTR InfSectionName)
2609 struct DeviceInfoSet *set = DeviceInfoSet;
2610 HKEY key = INVALID_HANDLE_VALUE, interfacesKey;
2611 LONG l;
2613 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet, DeviceInterfaceData, Reserved,
2614 samDesired, InfHandle, InfSectionName);
2616 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2617 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2619 SetLastError(ERROR_INVALID_HANDLE);
2620 return INVALID_HANDLE_VALUE;
2622 if (!DeviceInterfaceData ||
2623 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2624 !DeviceInterfaceData->Reserved)
2626 SetLastError(ERROR_INVALID_PARAMETER);
2627 return INVALID_HANDLE_VALUE;
2629 if (InfHandle && !InfSectionName)
2631 SetLastError(ERROR_INVALID_PARAMETER);
2632 return INVALID_HANDLE_VALUE;
2634 if (!(l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, DeviceClasses, 0, NULL, 0,
2635 samDesired, NULL, &interfacesKey, NULL)))
2637 HKEY parent;
2638 WCHAR bracedGuidString[39];
2640 SETUPDI_GuidToString(&DeviceInterfaceData->InterfaceClassGuid,
2641 bracedGuidString);
2642 if (!(l = RegCreateKeyExW(interfacesKey, bracedGuidString, 0, NULL, 0,
2643 samDesired, NULL, &parent, NULL)))
2645 struct InterfaceInfo *ifaceInfo =
2646 (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2647 PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo);
2648 PWSTR interfKeyName = HeapAlloc(GetProcessHeap(), 0,
2649 (lstrlenW(ifaceInfo->symbolicLink) + 1) * sizeof(WCHAR));
2650 HKEY interfKey;
2651 WCHAR *ptr;
2653 lstrcpyW(interfKeyName, ifaceInfo->symbolicLink);
2654 if (lstrlenW(ifaceInfo->symbolicLink) > 3)
2656 interfKeyName[0] = '#';
2657 interfKeyName[1] = '#';
2658 interfKeyName[3] = '#';
2660 ptr = strchrW(interfKeyName, '\\');
2661 if (ptr)
2662 *ptr = 0;
2663 l = RegCreateKeyExW(parent, interfKeyName, 0, NULL, 0,
2664 samDesired, NULL, &interfKey, NULL);
2665 if (!l)
2667 struct DeviceInfo *devInfo =
2668 (struct DeviceInfo *)ifaceInfo->device->Reserved;
2670 l = RegSetValueExW(interfKey, DeviceInstance, 0, REG_SZ,
2671 (BYTE *)devInfo->instanceId,
2672 (lstrlenW(devInfo->instanceId) + 1) * sizeof(WCHAR));
2673 if (!l)
2675 if (instancePath)
2677 LONG l;
2679 l = RegCreateKeyExW(interfKey, instancePath, 0, NULL, 0,
2680 samDesired, NULL, &key, NULL);
2681 if (l)
2683 SetLastError(l);
2684 key = INVALID_HANDLE_VALUE;
2686 else if (InfHandle)
2687 FIXME("INF section installation unsupported\n");
2690 else
2691 SetLastError(l);
2692 RegCloseKey(interfKey);
2694 else
2695 SetLastError(l);
2696 HeapFree(GetProcessHeap(), 0, interfKeyName);
2697 HeapFree(GetProcessHeap(), 0, instancePath);
2698 RegCloseKey(parent);
2700 else
2701 SetLastError(l);
2702 RegCloseKey(interfacesKey);
2704 else
2705 SetLastError(l);
2706 return key;
2709 /***********************************************************************
2710 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2712 BOOL WINAPI SetupDiDeleteDeviceInterfaceRegKey(
2713 HDEVINFO DeviceInfoSet,
2714 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2715 DWORD Reserved)
2717 struct DeviceInfoSet *set = DeviceInfoSet;
2718 HKEY parent;
2719 BOOL ret = FALSE;
2721 TRACE("%p %p %d\n", DeviceInfoSet, DeviceInterfaceData, Reserved);
2723 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2724 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2726 SetLastError(ERROR_INVALID_HANDLE);
2727 return FALSE;
2729 if (!DeviceInterfaceData ||
2730 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2731 !DeviceInterfaceData->Reserved)
2733 SetLastError(ERROR_INVALID_PARAMETER);
2734 return FALSE;
2736 parent = SetupDiOpenClassRegKeyExW(&DeviceInterfaceData->InterfaceClassGuid,
2737 KEY_ALL_ACCESS, DIOCR_INTERFACE, NULL, NULL);
2738 if (parent != INVALID_HANDLE_VALUE)
2740 struct InterfaceInfo *ifaceInfo =
2741 (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2742 PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo);
2744 if (instancePath)
2746 LONG l = RegDeleteKeyW(parent, instancePath);
2748 if (l)
2749 SetLastError(l);
2750 else
2751 ret = TRUE;
2752 HeapFree(GetProcessHeap(), 0, instancePath);
2754 RegCloseKey(parent);
2756 return ret;
2759 /***********************************************************************
2760 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2762 * PARAMS
2763 * DeviceInfoSet [I] Set of devices from which to enumerate
2764 * interfaces
2765 * DeviceInfoData [I] (Optional) If specified, a specific device
2766 * instance from which to enumerate interfaces.
2767 * If it isn't specified, all interfaces for all
2768 * devices in the set are enumerated.
2769 * InterfaceClassGuid [I] The interface class to enumerate.
2770 * MemberIndex [I] An index of the interface instance to enumerate.
2771 * A caller should start with MemberIndex set to 0,
2772 * and continue until the function fails with
2773 * ERROR_NO_MORE_ITEMS.
2774 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2775 * member must be set to
2776 * sizeof(SP_DEVICE_INTERFACE_DATA).
2778 * RETURNS
2779 * Success: non-zero value.
2780 * Failure: FALSE. Call GetLastError() for more info.
2782 BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData,
2783 const GUID *InterfaceClassGuid, DWORD MemberIndex,
2784 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
2786 struct DeviceInfoSet *set = DeviceInfoSet;
2787 BOOL ret = FALSE;
2789 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet, DeviceInfoData,
2790 debugstr_guid(InterfaceClassGuid), MemberIndex, DeviceInterfaceData);
2792 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2793 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2795 SetLastError(ERROR_INVALID_HANDLE);
2796 return FALSE;
2798 if (DeviceInfoData && (DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) ||
2799 !DeviceInfoData->Reserved))
2801 SetLastError(ERROR_INVALID_PARAMETER);
2802 return FALSE;
2804 if (!DeviceInterfaceData ||
2805 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA))
2807 SetLastError(ERROR_INVALID_PARAMETER);
2808 return FALSE;
2811 /* In case application fails to check return value, clear output */
2812 memset(DeviceInterfaceData, 0, sizeof(*DeviceInterfaceData));
2813 DeviceInterfaceData->cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
2815 if (DeviceInfoData)
2817 struct DeviceInfo *devInfo =
2818 (struct DeviceInfo *)DeviceInfoData->Reserved;
2819 struct InterfaceInstances *iface;
2821 if ((ret = SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface)))
2823 if (MemberIndex < iface->cInstances)
2824 *DeviceInterfaceData = iface->instances[MemberIndex];
2825 else
2827 SetLastError(ERROR_NO_MORE_ITEMS);
2828 ret = FALSE;
2831 else
2832 SetLastError(ERROR_NO_MORE_ITEMS);
2834 else
2836 struct DeviceInstance *devInst;
2837 DWORD cEnumerated = 0;
2838 BOOL found = FALSE;
2840 LIST_FOR_EACH_ENTRY(devInst, &set->devices, struct DeviceInstance, entry)
2842 struct DeviceInfo *devInfo = (struct DeviceInfo *)devInst->data.Reserved;
2843 struct InterfaceInstances *iface;
2845 if (found || cEnumerated >= MemberIndex + 1)
2846 break;
2847 if (SETUPDI_FindInterface(devInfo, InterfaceClassGuid, &iface))
2849 if (cEnumerated + iface->cInstances < MemberIndex + 1)
2850 cEnumerated += iface->cInstances;
2851 else
2853 DWORD instanceIndex = MemberIndex - cEnumerated;
2855 *DeviceInterfaceData = iface->instances[instanceIndex];
2856 cEnumerated += instanceIndex + 1;
2857 found = TRUE;
2858 ret = TRUE;
2862 if (!found)
2863 SetLastError(ERROR_NO_MORE_ITEMS);
2865 return ret;
2868 /***********************************************************************
2869 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2871 * Destroy a DeviceInfoList and free all used memory of the list.
2873 * PARAMS
2874 * devinfo [I] DeviceInfoList pointer to list to destroy
2876 * RETURNS
2877 * Success: non zero value.
2878 * Failure: zero value.
2880 BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
2882 BOOL ret = FALSE;
2884 TRACE("%p\n", devinfo);
2885 if (devinfo && devinfo != INVALID_HANDLE_VALUE)
2887 struct DeviceInfoSet *list = devinfo;
2889 if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC)
2891 struct DeviceInstance *devInst, *devInst2;
2893 LIST_FOR_EACH_ENTRY_SAFE(devInst, devInst2, &list->devices,
2894 struct DeviceInstance, entry)
2896 SETUPDI_FreeDeviceInfo( (struct DeviceInfo *)devInst->data.Reserved );
2897 list_remove(&devInst->entry);
2898 HeapFree(GetProcessHeap(), 0, devInst);
2900 HeapFree(GetProcessHeap(), 0, list);
2901 ret = TRUE;
2905 if (!ret)
2906 SetLastError(ERROR_INVALID_HANDLE);
2908 return ret;
2911 /***********************************************************************
2912 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2914 BOOL WINAPI SetupDiGetDeviceInterfaceDetailA(
2915 HDEVINFO DeviceInfoSet,
2916 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2917 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData,
2918 DWORD DeviceInterfaceDetailDataSize,
2919 PDWORD RequiredSize,
2920 PSP_DEVINFO_DATA DeviceInfoData)
2922 struct DeviceInfoSet *set = DeviceInfoSet;
2923 struct InterfaceInfo *info;
2924 DWORD bytesNeeded = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath[1]);
2925 BOOL ret = FALSE;
2927 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet,
2928 DeviceInterfaceData, DeviceInterfaceDetailData,
2929 DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
2931 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
2932 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
2934 SetLastError(ERROR_INVALID_HANDLE);
2935 return FALSE;
2937 if (!DeviceInterfaceData ||
2938 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
2939 !DeviceInterfaceData->Reserved)
2941 SetLastError(ERROR_INVALID_PARAMETER);
2942 return FALSE;
2944 if (DeviceInterfaceDetailData &&
2945 DeviceInterfaceDetailData->cbSize != sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A))
2947 SetLastError(ERROR_INVALID_USER_BUFFER);
2948 return FALSE;
2950 if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
2952 SetLastError(ERROR_INVALID_USER_BUFFER);
2953 return FALSE;
2955 info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
2956 if (info->symbolicLink)
2957 bytesNeeded += WideCharToMultiByte(CP_ACP, 0, info->symbolicLink, -1,
2958 NULL, 0, NULL, NULL);
2959 if (DeviceInterfaceDetailDataSize >= bytesNeeded)
2961 if (info->symbolicLink)
2962 WideCharToMultiByte(CP_ACP, 0, info->symbolicLink, -1,
2963 DeviceInterfaceDetailData->DevicePath,
2964 DeviceInterfaceDetailDataSize -
2965 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath),
2966 NULL, NULL);
2967 else
2968 DeviceInterfaceDetailData->DevicePath[0] = '\0';
2969 if (DeviceInfoData && DeviceInfoData->cbSize == sizeof(SP_DEVINFO_DATA))
2970 *DeviceInfoData = *info->device;
2971 ret = TRUE;
2973 else
2975 if (RequiredSize)
2976 *RequiredSize = bytesNeeded;
2977 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2979 return ret;
2982 /***********************************************************************
2983 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2985 BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(
2986 HDEVINFO DeviceInfoSet,
2987 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
2988 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData,
2989 DWORD DeviceInterfaceDetailDataSize,
2990 PDWORD RequiredSize,
2991 PSP_DEVINFO_DATA DeviceInfoData)
2993 struct DeviceInfoSet *set = DeviceInfoSet;
2994 struct InterfaceInfo *info;
2995 DWORD bytesNeeded = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath)
2996 + sizeof(WCHAR); /* include NULL terminator */
2997 BOOL ret = FALSE;
2999 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet,
3000 DeviceInterfaceData, DeviceInterfaceDetailData,
3001 DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
3003 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE ||
3004 set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3006 SetLastError(ERROR_INVALID_HANDLE);
3007 return FALSE;
3009 if (!DeviceInterfaceData ||
3010 DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) ||
3011 !DeviceInterfaceData->Reserved)
3013 SetLastError(ERROR_INVALID_PARAMETER);
3014 return FALSE;
3016 if (DeviceInterfaceDetailData && (DeviceInterfaceDetailData->cbSize <
3017 offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR) ||
3018 DeviceInterfaceDetailData->cbSize > sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W)))
3020 SetLastError(ERROR_INVALID_USER_BUFFER);
3021 return FALSE;
3023 if (!DeviceInterfaceDetailData && DeviceInterfaceDetailDataSize)
3025 SetLastError(ERROR_INVALID_USER_BUFFER);
3026 return FALSE;
3028 info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
3029 if (info->symbolicLink)
3030 bytesNeeded += sizeof(WCHAR)*lstrlenW(info->symbolicLink);
3031 if (DeviceInterfaceDetailDataSize >= bytesNeeded)
3033 if (info->symbolicLink)
3034 lstrcpyW(DeviceInterfaceDetailData->DevicePath, info->symbolicLink);
3035 else
3036 DeviceInterfaceDetailData->DevicePath[0] = '\0';
3037 if (DeviceInfoData && DeviceInfoData->cbSize == sizeof(SP_DEVINFO_DATA))
3038 *DeviceInfoData = *info->device;
3039 ret = TRUE;
3041 else
3043 if (RequiredSize)
3044 *RequiredSize = bytesNeeded;
3045 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3047 return ret;
3050 struct PropertyMapEntry
3052 DWORD regType;
3053 LPCSTR nameA;
3054 LPCWSTR nameW;
3057 static const struct PropertyMapEntry PropertyMap[] = {
3058 { REG_SZ, "DeviceDesc", DeviceDesc },
3059 { REG_MULTI_SZ, "HardwareId", HardwareId },
3060 { REG_MULTI_SZ, "CompatibleIDs", CompatibleIDs },
3061 { 0, NULL, NULL }, /* SPDRP_UNUSED0 */
3062 { REG_SZ, "Service", Service },
3063 { 0, NULL, NULL }, /* SPDRP_UNUSED1 */
3064 { 0, NULL, NULL }, /* SPDRP_UNUSED2 */
3065 { REG_SZ, "Class", Class },
3066 { REG_SZ, "ClassGUID", ClassGUID },
3067 { REG_SZ, "Driver", Driver },
3068 { REG_DWORD, "ConfigFlags", ConfigFlags },
3069 { REG_SZ, "Mfg", Mfg },
3070 { REG_SZ, "FriendlyName", FriendlyName },
3071 { REG_SZ, "LocationInformation", LocationInformation },
3072 { 0, NULL, NULL }, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3073 { REG_DWORD, "Capabilities", Capabilities },
3074 { REG_DWORD, "UINumber", UINumber },
3075 { REG_MULTI_SZ, "UpperFilters", UpperFilters },
3076 { REG_MULTI_SZ, "LowerFilters", LowerFilters },
3079 /***********************************************************************
3080 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3082 BOOL WINAPI SetupDiGetDeviceRegistryPropertyA(
3083 HDEVINFO DeviceInfoSet,
3084 PSP_DEVINFO_DATA DeviceInfoData,
3085 DWORD Property,
3086 PDWORD PropertyRegDataType,
3087 PBYTE PropertyBuffer,
3088 DWORD PropertyBufferSize,
3089 PDWORD RequiredSize)
3091 BOOL ret = FALSE;
3092 struct DeviceInfoSet *set = DeviceInfoSet;
3093 struct DeviceInfo *devInfo;
3095 TRACE("%04x %p %d %p %p %d %p\n", (DWORD)DeviceInfoSet, DeviceInfoData,
3096 Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize,
3097 RequiredSize);
3099 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3101 SetLastError(ERROR_INVALID_HANDLE);
3102 return FALSE;
3104 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3106 SetLastError(ERROR_INVALID_HANDLE);
3107 return FALSE;
3109 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3110 || !DeviceInfoData->Reserved)
3112 SetLastError(ERROR_INVALID_PARAMETER);
3113 return FALSE;
3115 if (PropertyBufferSize && PropertyBuffer == NULL)
3117 SetLastError(ERROR_INVALID_DATA);
3118 return FALSE;
3120 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3121 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3122 && PropertyMap[Property].nameA)
3124 DWORD size = PropertyBufferSize;
3125 LONG l = RegQueryValueExA(devInfo->key, PropertyMap[Property].nameA,
3126 NULL, PropertyRegDataType, PropertyBuffer, &size);
3128 if (l == ERROR_FILE_NOT_FOUND)
3129 SetLastError(ERROR_INVALID_DATA);
3130 else if (l == ERROR_MORE_DATA || !PropertyBufferSize)
3131 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3132 else if (!l)
3133 ret = TRUE;
3134 else
3135 SetLastError(l);
3136 if (RequiredSize)
3137 *RequiredSize = size;
3139 return ret;
3142 /***********************************************************************
3143 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3145 BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(
3146 HDEVINFO DeviceInfoSet,
3147 PSP_DEVINFO_DATA DeviceInfoData,
3148 DWORD Property,
3149 PDWORD PropertyRegDataType,
3150 PBYTE PropertyBuffer,
3151 DWORD PropertyBufferSize,
3152 PDWORD RequiredSize)
3154 BOOL ret = FALSE;
3155 struct DeviceInfoSet *set = DeviceInfoSet;
3156 struct DeviceInfo *devInfo;
3158 TRACE("%04x %p %d %p %p %d %p\n", (DWORD)DeviceInfoSet, DeviceInfoData,
3159 Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize,
3160 RequiredSize);
3162 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3164 SetLastError(ERROR_INVALID_HANDLE);
3165 return FALSE;
3167 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3169 SetLastError(ERROR_INVALID_HANDLE);
3170 return FALSE;
3172 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3173 || !DeviceInfoData->Reserved)
3175 SetLastError(ERROR_INVALID_PARAMETER);
3176 return FALSE;
3178 if (PropertyBufferSize && PropertyBuffer == NULL)
3180 SetLastError(ERROR_INVALID_DATA);
3181 return FALSE;
3183 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3184 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3185 && PropertyMap[Property].nameW)
3187 DWORD size = PropertyBufferSize;
3188 LONG l = RegQueryValueExW(devInfo->key, PropertyMap[Property].nameW,
3189 NULL, PropertyRegDataType, PropertyBuffer, &size);
3191 if (l == ERROR_FILE_NOT_FOUND)
3192 SetLastError(ERROR_INVALID_DATA);
3193 else if (l == ERROR_MORE_DATA || !PropertyBufferSize)
3194 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3195 else if (!l)
3196 ret = TRUE;
3197 else
3198 SetLastError(l);
3199 if (RequiredSize)
3200 *RequiredSize = size;
3202 return ret;
3205 /***********************************************************************
3206 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3208 BOOL WINAPI SetupDiSetDeviceRegistryPropertyA(
3209 HDEVINFO DeviceInfoSet,
3210 PSP_DEVINFO_DATA DeviceInfoData,
3211 DWORD Property,
3212 const BYTE *PropertyBuffer,
3213 DWORD PropertyBufferSize)
3215 BOOL ret = FALSE;
3216 struct DeviceInfoSet *set = DeviceInfoSet;
3217 struct DeviceInfo *devInfo;
3219 TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property,
3220 PropertyBuffer, PropertyBufferSize);
3222 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3224 SetLastError(ERROR_INVALID_HANDLE);
3225 return FALSE;
3227 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3229 SetLastError(ERROR_INVALID_HANDLE);
3230 return FALSE;
3232 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3233 || !DeviceInfoData->Reserved)
3235 SetLastError(ERROR_INVALID_PARAMETER);
3236 return FALSE;
3238 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3239 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3240 && PropertyMap[Property].nameA)
3242 LONG l = RegSetValueExA(devInfo->key, PropertyMap[Property].nameA, 0,
3243 PropertyMap[Property].regType, PropertyBuffer,
3244 PropertyBufferSize);
3245 if (!l)
3246 ret = TRUE;
3247 else
3248 SetLastError(l);
3250 return ret;
3253 /***********************************************************************
3254 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3256 BOOL WINAPI SetupDiSetDeviceRegistryPropertyW(
3257 HDEVINFO DeviceInfoSet,
3258 PSP_DEVINFO_DATA DeviceInfoData,
3259 DWORD Property,
3260 const BYTE *PropertyBuffer,
3261 DWORD PropertyBufferSize)
3263 BOOL ret = FALSE;
3264 struct DeviceInfoSet *set = DeviceInfoSet;
3265 struct DeviceInfo *devInfo;
3267 TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property,
3268 PropertyBuffer, PropertyBufferSize);
3270 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3272 SetLastError(ERROR_INVALID_HANDLE);
3273 return FALSE;
3275 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3277 SetLastError(ERROR_INVALID_HANDLE);
3278 return FALSE;
3280 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3281 || !DeviceInfoData->Reserved)
3283 SetLastError(ERROR_INVALID_PARAMETER);
3284 return FALSE;
3286 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3287 if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
3288 && PropertyMap[Property].nameW)
3290 LONG l = RegSetValueExW(devInfo->key, PropertyMap[Property].nameW, 0,
3291 PropertyMap[Property].regType, PropertyBuffer,
3292 PropertyBufferSize);
3293 if (!l)
3294 ret = TRUE;
3295 else
3296 SetLastError(l);
3298 return ret;
3301 /***********************************************************************
3302 * SetupDiInstallClassA (SETUPAPI.@)
3304 BOOL WINAPI SetupDiInstallClassA(
3305 HWND hwndParent,
3306 PCSTR InfFileName,
3307 DWORD Flags,
3308 HSPFILEQ FileQueue)
3310 UNICODE_STRING FileNameW;
3311 BOOL Result;
3313 if (!InfFileName)
3315 SetLastError(ERROR_INVALID_PARAMETER);
3316 return FALSE;
3318 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW, InfFileName))
3320 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
3321 return FALSE;
3324 Result = SetupDiInstallClassW(hwndParent, FileNameW.Buffer, Flags, FileQueue);
3326 RtlFreeUnicodeString(&FileNameW);
3328 return Result;
3331 static HKEY CreateClassKey(HINF hInf)
3333 static const WCHAR slash[] = { '\\',0 };
3334 WCHAR FullBuffer[MAX_PATH];
3335 WCHAR Buffer[MAX_PATH];
3336 DWORD RequiredSize;
3337 HKEY hClassKey;
3339 if (!SetupGetLineTextW(NULL,
3340 hInf,
3341 Version,
3342 ClassGUID,
3343 Buffer,
3344 MAX_PATH,
3345 &RequiredSize))
3347 return INVALID_HANDLE_VALUE;
3350 lstrcpyW(FullBuffer, ControlClass);
3351 lstrcatW(FullBuffer, slash);
3352 lstrcatW(FullBuffer, Buffer);
3354 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3355 FullBuffer,
3357 KEY_ALL_ACCESS,
3358 &hClassKey))
3360 if (!SetupGetLineTextW(NULL,
3361 hInf,
3362 Version,
3363 Class,
3364 Buffer,
3365 MAX_PATH,
3366 &RequiredSize))
3368 return INVALID_HANDLE_VALUE;
3371 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,
3372 FullBuffer,
3374 NULL,
3375 REG_OPTION_NON_VOLATILE,
3376 KEY_ALL_ACCESS,
3377 NULL,
3378 &hClassKey,
3379 NULL))
3381 return INVALID_HANDLE_VALUE;
3386 if (RegSetValueExW(hClassKey,
3387 Class,
3389 REG_SZ,
3390 (LPBYTE)Buffer,
3391 RequiredSize * sizeof(WCHAR)))
3393 RegCloseKey(hClassKey);
3394 RegDeleteKeyW(HKEY_LOCAL_MACHINE,
3395 FullBuffer);
3396 return INVALID_HANDLE_VALUE;
3399 return hClassKey;
3402 /***********************************************************************
3403 * SetupDiInstallClassW (SETUPAPI.@)
3405 BOOL WINAPI SetupDiInstallClassW(
3406 HWND hwndParent,
3407 PCWSTR InfFileName,
3408 DWORD Flags,
3409 HSPFILEQ FileQueue)
3411 WCHAR SectionName[MAX_PATH];
3412 DWORD SectionNameLength = 0;
3413 HINF hInf;
3414 BOOL bFileQueueCreated = FALSE;
3415 HKEY hClassKey;
3418 FIXME("\n");
3420 if (!InfFileName)
3422 SetLastError(ERROR_INVALID_PARAMETER);
3423 return FALSE;
3425 if ((Flags & DI_NOVCP) && (FileQueue == NULL || FileQueue == INVALID_HANDLE_VALUE))
3427 SetLastError(ERROR_INVALID_PARAMETER);
3428 return FALSE;
3431 /* Open the .inf file */
3432 hInf = SetupOpenInfFileW(InfFileName,
3433 NULL,
3434 INF_STYLE_WIN4,
3435 NULL);
3436 if (hInf == INVALID_HANDLE_VALUE)
3439 return FALSE;
3442 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
3443 hClassKey = CreateClassKey(hInf);
3444 if (hClassKey == INVALID_HANDLE_VALUE)
3446 SetupCloseInfFile(hInf);
3447 return FALSE;
3451 /* Try to append a layout file */
3452 SetupOpenAppendInfFileW(NULL, hInf, NULL);
3454 /* Retrieve the actual section name */
3455 SetupDiGetActualSectionToInstallW(hInf,
3456 ClassInstall32,
3457 SectionName,
3458 MAX_PATH,
3459 &SectionNameLength,
3460 NULL);
3462 #if 0
3463 if (!(Flags & DI_NOVCP))
3465 FileQueue = SetupOpenFileQueue();
3466 if (FileQueue == INVALID_HANDLE_VALUE)
3468 SetupCloseInfFile(hInf);
3469 return FALSE;
3472 bFileQueueCreated = TRUE;
3475 #endif
3477 SetupInstallFromInfSectionW(NULL,
3478 hInf,
3479 SectionName,
3480 SPINST_COPYINF | SPINST_FILES | SPINST_REGISTRY,
3481 hClassKey,
3482 NULL,
3484 NULL,
3485 NULL,
3486 INVALID_HANDLE_VALUE,
3487 NULL);
3489 /* FIXME: More code! */
3491 if (bFileQueueCreated)
3492 SetupCloseFileQueue(FileQueue);
3494 SetupCloseInfFile(hInf);
3496 return TRUE;
3500 /***********************************************************************
3501 * SetupDiOpenClassRegKey (SETUPAPI.@)
3503 HKEY WINAPI SetupDiOpenClassRegKey(
3504 const GUID* ClassGuid,
3505 REGSAM samDesired)
3507 return SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
3508 DIOCR_INSTALLER, NULL, NULL);
3512 /***********************************************************************
3513 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3515 HKEY WINAPI SetupDiOpenClassRegKeyExA(
3516 const GUID* ClassGuid,
3517 REGSAM samDesired,
3518 DWORD Flags,
3519 PCSTR MachineName,
3520 PVOID Reserved)
3522 PWSTR MachineNameW = NULL;
3523 HKEY hKey;
3525 TRACE("\n");
3527 if (MachineName)
3529 MachineNameW = MultiByteToUnicode(MachineName, CP_ACP);
3530 if (MachineNameW == NULL)
3531 return INVALID_HANDLE_VALUE;
3534 hKey = SetupDiOpenClassRegKeyExW(ClassGuid, samDesired,
3535 Flags, MachineNameW, Reserved);
3537 MyFree(MachineNameW);
3539 return hKey;
3543 /***********************************************************************
3544 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3546 HKEY WINAPI SetupDiOpenClassRegKeyExW(
3547 const GUID* ClassGuid,
3548 REGSAM samDesired,
3549 DWORD Flags,
3550 PCWSTR MachineName,
3551 PVOID Reserved)
3553 HKEY hClassesKey;
3554 HKEY key;
3555 LPCWSTR lpKeyName;
3556 LONG l;
3558 if (MachineName && *MachineName)
3560 FIXME("Remote access not supported yet!\n");
3561 return INVALID_HANDLE_VALUE;
3564 if (Flags == DIOCR_INSTALLER)
3566 lpKeyName = ControlClass;
3568 else if (Flags == DIOCR_INTERFACE)
3570 lpKeyName = DeviceClasses;
3572 else
3574 ERR("Invalid Flags parameter!\n");
3575 SetLastError(ERROR_INVALID_PARAMETER);
3576 return INVALID_HANDLE_VALUE;
3579 if (!ClassGuid)
3581 if ((l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3582 lpKeyName,
3584 samDesired,
3585 &hClassesKey)))
3587 SetLastError(l);
3588 hClassesKey = INVALID_HANDLE_VALUE;
3590 key = hClassesKey;
3592 else
3594 WCHAR bracedGuidString[39];
3596 SETUPDI_GuidToString(ClassGuid, bracedGuidString);
3598 if (!(l = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
3599 lpKeyName,
3601 samDesired,
3602 &hClassesKey)))
3604 if ((l = RegOpenKeyExW(hClassesKey,
3605 bracedGuidString,
3607 samDesired,
3608 &key)))
3610 SetLastError(l);
3611 key = INVALID_HANDLE_VALUE;
3613 RegCloseKey(hClassesKey);
3615 else
3617 SetLastError(l);
3618 key = INVALID_HANDLE_VALUE;
3621 return key;
3624 /***********************************************************************
3625 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3627 BOOL WINAPI SetupDiOpenDeviceInterfaceW(
3628 HDEVINFO DeviceInfoSet,
3629 PCWSTR DevicePath,
3630 DWORD OpenFlags,
3631 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
3633 FIXME("%p %s %08x %p\n",
3634 DeviceInfoSet, debugstr_w(DevicePath), OpenFlags, DeviceInterfaceData);
3635 return FALSE;
3638 /***********************************************************************
3639 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3641 BOOL WINAPI SetupDiOpenDeviceInterfaceA(
3642 HDEVINFO DeviceInfoSet,
3643 PCSTR DevicePath,
3644 DWORD OpenFlags,
3645 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
3647 FIXME("%p %s %08x %p\n", DeviceInfoSet,
3648 debugstr_a(DevicePath), OpenFlags, DeviceInterfaceData);
3649 return FALSE;
3652 /***********************************************************************
3653 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3655 BOOL WINAPI SetupDiSetClassInstallParamsA(
3656 HDEVINFO DeviceInfoSet,
3657 PSP_DEVINFO_DATA DeviceInfoData,
3658 PSP_CLASSINSTALL_HEADER ClassInstallParams,
3659 DWORD ClassInstallParamsSize)
3661 FIXME("%p %p %x %u\n",DeviceInfoSet, DeviceInfoData,
3662 ClassInstallParams->InstallFunction, ClassInstallParamsSize);
3663 return FALSE;
3666 /***********************************************************************
3667 * SetupDiSetClassInstallParamsW (SETUPAPI.@)
3669 BOOL WINAPI SetupDiSetClassInstallParamsW(
3670 HDEVINFO DeviceInfoSet,
3671 PSP_DEVINFO_DATA DeviceInfoData,
3672 PSP_CLASSINSTALL_HEADER ClassInstallParams,
3673 DWORD ClassInstallParamsSize)
3675 FIXME("%p %p %x %u\n",DeviceInfoSet, DeviceInfoData,
3676 ClassInstallParams->InstallFunction, ClassInstallParamsSize);
3677 return FALSE;
3680 /***********************************************************************
3681 * SetupDiCallClassInstaller (SETUPAPI.@)
3683 BOOL WINAPI SetupDiCallClassInstaller(
3684 DI_FUNCTION InstallFunction,
3685 HDEVINFO DeviceInfoSet,
3686 PSP_DEVINFO_DATA DeviceInfoData)
3688 FIXME("%d %p %p\n", InstallFunction, DeviceInfoSet, DeviceInfoData);
3689 return FALSE;
3692 /***********************************************************************
3693 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
3695 BOOL WINAPI SetupDiGetDeviceInstallParamsW(
3696 HDEVINFO DeviceInfoSet,
3697 PSP_DEVINFO_DATA DeviceInfoData,
3698 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
3700 FIXME("%p %p %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3701 return FALSE;
3704 /***********************************************************************
3705 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3707 BOOL WINAPI SetupDiGetDeviceInstallParamsA(
3708 HDEVINFO DeviceInfoSet,
3709 PSP_DEVINFO_DATA DeviceInfoData,
3710 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams)
3712 FIXME("%p %p %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3713 return FALSE;
3716 /***********************************************************************
3717 * SetupDiSetDeviceInstallParamsA (SETUPAPI.@)
3719 BOOL WINAPI SetupDiSetDeviceInstallParamsA(
3720 HDEVINFO DeviceInfoSet,
3721 PSP_DEVINFO_DATA DeviceInfoData,
3722 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams)
3724 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3726 return TRUE;
3729 /***********************************************************************
3730 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
3732 BOOL WINAPI SetupDiSetDeviceInstallParamsW(
3733 HDEVINFO DeviceInfoSet,
3734 PSP_DEVINFO_DATA DeviceInfoData,
3735 PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
3737 FIXME("(%p, %p, %p) stub\n", DeviceInfoSet, DeviceInfoData, DeviceInstallParams);
3739 return TRUE;
3742 static HKEY SETUPDI_OpenDevKey(struct DeviceInfo *devInfo, REGSAM samDesired)
3744 HKEY enumKey, key = INVALID_HANDLE_VALUE;
3745 LONG l;
3747 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
3748 NULL, &enumKey, NULL);
3749 if (!l)
3751 RegOpenKeyExW(enumKey, devInfo->instanceId, 0, samDesired, &key);
3752 RegCloseKey(enumKey);
3754 return key;
3757 static HKEY SETUPDI_OpenDrvKey(struct DeviceInfo *devInfo, REGSAM samDesired)
3759 static const WCHAR slash[] = { '\\',0 };
3760 WCHAR classKeyPath[MAX_PATH];
3761 HKEY classKey, key = INVALID_HANDLE_VALUE;
3762 LONG l;
3764 lstrcpyW(classKeyPath, ControlClass);
3765 lstrcatW(classKeyPath, slash);
3766 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
3767 classKeyPath + lstrlenW(classKeyPath));
3768 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
3769 KEY_ALL_ACCESS, NULL, &classKey, NULL);
3770 if (!l)
3772 static const WCHAR fmt[] = { '%','0','4','u',0 };
3773 WCHAR devId[10];
3775 sprintfW(devId, fmt, devInfo->devId);
3776 l = RegOpenKeyExW(classKey, devId, 0, samDesired, &key);
3777 RegCloseKey(classKey);
3778 if (l)
3780 SetLastError(ERROR_KEY_DOES_NOT_EXIST);
3781 return INVALID_HANDLE_VALUE;
3784 return key;
3787 /***********************************************************************
3788 * SetupDiOpenDevRegKey (SETUPAPI.@)
3790 HKEY WINAPI SetupDiOpenDevRegKey(
3791 HDEVINFO DeviceInfoSet,
3792 PSP_DEVINFO_DATA DeviceInfoData,
3793 DWORD Scope,
3794 DWORD HwProfile,
3795 DWORD KeyType,
3796 REGSAM samDesired)
3798 struct DeviceInfoSet *set = DeviceInfoSet;
3799 struct DeviceInfo *devInfo;
3800 HKEY key = INVALID_HANDLE_VALUE;
3802 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet, DeviceInfoData,
3803 Scope, HwProfile, KeyType, samDesired);
3805 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3807 SetLastError(ERROR_INVALID_HANDLE);
3808 return INVALID_HANDLE_VALUE;
3810 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3812 SetLastError(ERROR_INVALID_HANDLE);
3813 return INVALID_HANDLE_VALUE;
3815 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3816 || !DeviceInfoData->Reserved)
3818 SetLastError(ERROR_INVALID_PARAMETER);
3819 return INVALID_HANDLE_VALUE;
3821 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
3823 SetLastError(ERROR_INVALID_FLAGS);
3824 return INVALID_HANDLE_VALUE;
3826 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV)
3828 SetLastError(ERROR_INVALID_FLAGS);
3829 return INVALID_HANDLE_VALUE;
3831 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3832 if (devInfo->set != set)
3834 SetLastError(ERROR_INVALID_PARAMETER);
3835 return INVALID_HANDLE_VALUE;
3837 if (devInfo->phantom)
3839 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
3840 return INVALID_HANDLE_VALUE;
3842 if (Scope != DICS_FLAG_GLOBAL)
3843 FIXME("unimplemented for scope %d\n", Scope);
3844 switch (KeyType)
3846 case DIREG_DEV:
3847 key = SETUPDI_OpenDevKey(devInfo, samDesired);
3848 break;
3849 case DIREG_DRV:
3850 key = SETUPDI_OpenDrvKey(devInfo, samDesired);
3851 break;
3852 default:
3853 WARN("unknown KeyType %d\n", KeyType);
3855 return key;
3858 static BOOL SETUPDI_DeleteDevKey(struct DeviceInfo *devInfo)
3860 HKEY enumKey;
3861 BOOL ret = FALSE;
3862 LONG l;
3864 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS,
3865 NULL, &enumKey, NULL);
3866 if (!l)
3868 ret = RegDeleteTreeW(enumKey, devInfo->instanceId);
3869 RegCloseKey(enumKey);
3871 else
3872 SetLastError(l);
3873 return ret;
3876 static BOOL SETUPDI_DeleteDrvKey(struct DeviceInfo *devInfo)
3878 static const WCHAR slash[] = { '\\',0 };
3879 WCHAR classKeyPath[MAX_PATH];
3880 HKEY classKey;
3881 LONG l;
3882 BOOL ret = FALSE;
3884 lstrcpyW(classKeyPath, ControlClass);
3885 lstrcatW(classKeyPath, slash);
3886 SETUPDI_GuidToString(&devInfo->set->ClassGuid,
3887 classKeyPath + lstrlenW(classKeyPath));
3888 l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, classKeyPath, 0, NULL, 0,
3889 KEY_ALL_ACCESS, NULL, &classKey, NULL);
3890 if (!l)
3892 static const WCHAR fmt[] = { '%','0','4','u',0 };
3893 WCHAR devId[10];
3895 sprintfW(devId, fmt, devInfo->devId);
3896 ret = RegDeleteTreeW(classKey, devId);
3897 RegCloseKey(classKey);
3899 else
3900 SetLastError(l);
3901 return ret;
3904 /***********************************************************************
3905 * SetupDiDeleteDevRegKey (SETUPAPI.@)
3907 BOOL WINAPI SetupDiDeleteDevRegKey(
3908 HDEVINFO DeviceInfoSet,
3909 PSP_DEVINFO_DATA DeviceInfoData,
3910 DWORD Scope,
3911 DWORD HwProfile,
3912 DWORD KeyType)
3914 struct DeviceInfoSet *set = DeviceInfoSet;
3915 struct DeviceInfo *devInfo;
3916 BOOL ret = FALSE;
3918 TRACE("%p %p %d %d %d\n", DeviceInfoSet, DeviceInfoData, Scope, HwProfile,
3919 KeyType);
3921 if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE)
3923 SetLastError(ERROR_INVALID_HANDLE);
3924 return FALSE;
3926 if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC)
3928 SetLastError(ERROR_INVALID_HANDLE);
3929 return FALSE;
3931 if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)
3932 || !DeviceInfoData->Reserved)
3934 SetLastError(ERROR_INVALID_PARAMETER);
3935 return FALSE;
3937 if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC)
3939 SetLastError(ERROR_INVALID_FLAGS);
3940 return FALSE;
3942 if (KeyType != DIREG_DEV && KeyType != DIREG_DRV && KeyType != DIREG_BOTH)
3944 SetLastError(ERROR_INVALID_FLAGS);
3945 return FALSE;
3947 devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved;
3948 if (devInfo->set != set)
3950 SetLastError(ERROR_INVALID_PARAMETER);
3951 return FALSE;
3953 if (devInfo->phantom)
3955 SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
3956 return FALSE;
3958 if (Scope != DICS_FLAG_GLOBAL)
3959 FIXME("unimplemented for scope %d\n", Scope);
3960 switch (KeyType)
3962 case DIREG_DEV:
3963 ret = SETUPDI_DeleteDevKey(devInfo);
3964 break;
3965 case DIREG_DRV:
3966 ret = SETUPDI_DeleteDrvKey(devInfo);
3967 break;
3968 case DIREG_BOTH:
3969 ret = SETUPDI_DeleteDevKey(devInfo);
3970 if (ret)
3971 ret = SETUPDI_DeleteDrvKey(devInfo);
3972 break;
3973 default:
3974 WARN("unknown KeyType %d\n", KeyType);
3976 return ret;
3979 /***********************************************************************
3980 * CM_Get_Device_IDA (SETUPAPI.@)
3982 CONFIGRET WINAPI CM_Get_Device_IDA( DEVINST dnDevInst, PSTR Buffer,
3983 ULONG BufferLen, ULONG ulFlags)
3985 struct DeviceInfo *devInfo = GlobalLock((HANDLE)dnDevInst);
3987 TRACE("%x->%p, %p, %u %u\n", dnDevInst, devInfo, Buffer, BufferLen, ulFlags);
3989 if (!devInfo)
3990 return CR_NO_SUCH_DEVINST;
3992 WideCharToMultiByte(CP_ACP, 0, devInfo->instanceId, -1, Buffer, BufferLen, 0, 0);
3993 TRACE("Returning %s\n", debugstr_a(Buffer));
3994 return CR_SUCCESS;
3997 /***********************************************************************
3998 * CM_Get_Device_IDW (SETUPAPI.@)
4000 CONFIGRET WINAPI CM_Get_Device_IDW( DEVINST dnDevInst, LPWSTR Buffer,
4001 ULONG BufferLen, ULONG ulFlags)
4003 struct DeviceInfo *devInfo = GlobalLock((HANDLE)dnDevInst);
4005 TRACE("%x->%p, %p, %u %u\n", dnDevInst, devInfo, Buffer, BufferLen, ulFlags);
4007 if (!devInfo)
4009 WARN("dev instance %d not found!\n", dnDevInst);
4010 return CR_NO_SUCH_DEVINST;
4013 lstrcpynW(Buffer, devInfo->instanceId, BufferLen);
4014 TRACE("Returning %s\n", debugstr_w(Buffer));
4015 GlobalUnlock((HANDLE)dnDevInst);
4016 return CR_SUCCESS;
4021 /***********************************************************************
4022 * CM_Get_Device_ID_Size (SETUPAPI.@)
4024 CONFIGRET WINAPI CM_Get_Device_ID_Size( PULONG pulLen, DEVINST dnDevInst,
4025 ULONG ulFlags)
4027 struct DeviceInfo *ppdevInfo = GlobalLock((HANDLE)dnDevInst);
4029 TRACE("%x->%p, %p, %u\n", dnDevInst, ppdevInfo, pulLen, ulFlags);
4031 if (!ppdevInfo)
4033 WARN("dev instance %d not found!\n", dnDevInst);
4034 return CR_NO_SUCH_DEVINST;
4037 *pulLen = lstrlenW(ppdevInfo->instanceId);
4038 GlobalUnlock((HANDLE)dnDevInst);
4039 return CR_SUCCESS;
4042 /***********************************************************************
4043 * SetupDiGetINFClassA (SETUPAPI.@)
4045 BOOL WINAPI SetupDiGetINFClassA(PCSTR inf, LPGUID class_guid, PSTR class_name,
4046 DWORD size, PDWORD required_size)
4048 BOOL retval;
4049 DWORD required_sizeA, required_sizeW;
4050 PWSTR class_nameW = NULL;
4051 UNICODE_STRING infW;
4053 if (inf)
4055 if (!RtlCreateUnicodeStringFromAsciiz(&infW, inf))
4057 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
4058 return FALSE;
4061 else
4062 infW.Buffer = NULL;
4064 if (class_name && size)
4066 if (!(class_nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR))))
4068 RtlFreeUnicodeString(&infW);
4069 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
4070 return FALSE;
4074 retval = SetupDiGetINFClassW(infW.Buffer, class_guid, class_nameW, size, &required_sizeW);
4076 if (retval)
4078 required_sizeA = WideCharToMultiByte( CP_ACP, 0, class_nameW, required_sizeW,
4079 class_name, size, NULL, NULL);
4081 if(required_size) *required_size = required_sizeA;
4083 else
4084 if(required_size) *required_size = required_sizeW;
4086 HeapFree(GetProcessHeap(), 0, class_nameW);
4087 RtlFreeUnicodeString(&infW);
4088 return retval;
4091 /***********************************************************************
4092 * SetupDiGetINFClassW (SETUPAPI.@)
4094 BOOL WINAPI SetupDiGetINFClassW(PCWSTR inf, LPGUID class_guid, PWSTR class_name,
4095 DWORD size, PDWORD required_size)
4097 BOOL have_guid, have_name;
4098 DWORD dret;
4099 WCHAR buffer[MAX_PATH];
4101 if (!inf)
4103 SetLastError(ERROR_INVALID_PARAMETER);
4104 return FALSE;
4107 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(inf))
4109 FIXME("%s not found. Searching via DevicePath not implemented\n", debugstr_w(inf));
4110 SetLastError(ERROR_FILE_NOT_FOUND);
4111 return FALSE;
4114 if (!class_guid || !class_name || !size)
4116 SetLastError(ERROR_INVALID_PARAMETER);
4117 return FALSE;
4120 if (!GetPrivateProfileStringW(Version, Signature, NULL, buffer, MAX_PATH, inf))
4121 return FALSE;
4123 if (lstrcmpiW(buffer, Chicago) && lstrcmpiW(buffer, WindowsNT))
4124 return FALSE;
4126 buffer[0] = '\0';
4127 have_guid = 0 < GetPrivateProfileStringW(Version, ClassGUID, NULL, buffer, MAX_PATH, inf);
4128 if (have_guid)
4130 buffer[lstrlenW(buffer)-1] = 0;
4131 if (RPC_S_OK != UuidFromStringW(buffer + 1, class_guid))
4133 FIXME("failed to convert \"%s\" into a guid\n", debugstr_w(buffer));
4134 SetLastError(ERROR_INVALID_PARAMETER);
4135 return FALSE;
4139 buffer[0] = '\0';
4140 dret = GetPrivateProfileStringW(Version, Class, NULL, buffer, MAX_PATH, inf);
4141 have_name = 0 < dret;
4143 if (dret >= MAX_PATH -1) FIXME("buffer might be too small\n");
4144 if (have_guid && !have_name) FIXME("class name lookup via guid not implemented\n");
4146 if (have_name)
4148 if (dret < size) lstrcpyW(class_name, buffer);
4149 else
4151 SetLastError(ERROR_INSUFFICIENT_BUFFER);
4152 have_name = FALSE;
4156 if (required_size) *required_size = dret + ((dret) ? 1 : 0);
4158 return (have_guid || have_name);
4161 /***********************************************************************
4162 * SetupDiGetDevicePropertyW (SETUPAPI.@)
4164 BOOL WINAPI SetupDiGetDevicePropertyW(HDEVINFO info_set, PSP_DEVINFO_DATA info_data,
4165 const DEVPROPKEY *prop_key, DEVPROPTYPE *prop_type, BYTE *prop_buff,
4166 DWORD prop_buff_size, DWORD *required_size, DWORD flags)
4168 FIXME("%p, %p, %p, %p, %p, %d, %p, 0x%08x stub\n", info_set, info_data, prop_key,
4169 prop_type, prop_buff, prop_buff_size, required_size, flags);
4171 SetLastError(ERROR_NOT_FOUND);
4172 return FALSE;