2 * SetupAPI device installer
4 * Copyright 2000 Andreas Mohr for CodeWeavers
5 * 2005-2006 Hervé Poussineau (hpoussin@reactos.org)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "setupapi_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
26 /* Unicode constants */
27 static const WCHAR BackSlash
[] = {'\\',0};
28 static const WCHAR ClassGUID
[] = {'C','l','a','s','s','G','U','I','D',0};
29 static const WCHAR Class
[] = {'C','l','a','s','s',0};
30 static const WCHAR DateFormat
[] = {'%','u','-','%','u','-','%','u',0};
31 static const WCHAR DotCoInstallers
[] = {'.','C','o','I','n','s','t','a','l','l','e','r','s',0};
32 static const WCHAR DotHW
[] = {'.','H','W',0};
33 static const WCHAR DotServices
[] = {'.','S','e','r','v','i','c','e','s',0};
34 static const WCHAR InfDirectory
[] = {'i','n','f','\\',0};
35 static const WCHAR InstanceKeyFormat
[] = {'%','0','4','l','u',0};
36 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
37 static const WCHAR VersionFormat
[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
39 static const WCHAR REGSTR_DRIVER_DATE
[] = {'D','r','i','v','e','r','D','a','t','e',0};
40 static const WCHAR REGSTR_DRIVER_DATE_DATA
[] = {'D','r','i','v','e','r','D','a','t','e','D','a','t','a',0};
41 static const WCHAR REGSTR_DRIVER_VERSION
[] = {'D','r','i','v','e','r','V','e','r','s','i','o','n',0};
42 static const WCHAR REGSTR_SECURITY
[] = {'S','e','c','u','r','i','t','y',0};
43 static const WCHAR REGSTR_UI_NUMBER_DESC_FORMAT
[] = {'U','I','N','u','m','b','e','r','D','e','s','c','F','o','r','m','a','t',0};
46 (CALLBACK
* CLASS_INSTALL_PROC
) (
47 IN DI_FUNCTION InstallFunction
,
48 IN HDEVINFO DeviceInfoSet
,
49 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
);
51 (WINAPI
* DEFAULT_CLASS_INSTALL_PROC
) (
52 IN HDEVINFO DeviceInfoSet
,
53 IN OUT PSP_DEVINFO_DATA DeviceInfoData
);
55 (CALLBACK
* COINSTALLER_PROC
) (
56 IN DI_FUNCTION InstallFunction
,
57 IN HDEVINFO DeviceInfoSet
,
58 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
59 IN OUT PCOINSTALLER_CONTEXT_DATA Context
);
61 struct CoInstallerElement
66 COINSTALLER_PROC Function
;
67 BOOL DoPostProcessing
;
71 struct GetSectionCallbackInfo
73 PSP_ALTPLATFORM_INFO PlatformInfo
;
77 WCHAR BestSection
[LINE_LEN
+ 1];
78 DWORD BestScore1
, BestScore2
, BestScore3
, BestScore4
, BestScore5
;
83 static void SETUPDI_GuidToString(const GUID
*guid
, LPWSTR guidStr
)
85 static const WCHAR fmt
[] = {'{','%','0','8','X','-','%','0','4','X','-',
86 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
87 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
90 sprintfW(guidStr
, fmt
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
91 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
92 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
96 GetErrorCodeFromCrCode(const IN CONFIGRET cr
)
100 case CR_ACCESS_DENIED
: return ERROR_ACCESS_DENIED
;
101 case CR_BUFFER_SMALL
: return ERROR_INSUFFICIENT_BUFFER
;
102 case CR_CALL_NOT_IMPLEMENTED
: return ERROR_CALL_NOT_IMPLEMENTED
;
103 case CR_FAILURE
: return ERROR_GEN_FAILURE
;
104 case CR_INVALID_DATA
: return ERROR_INVALID_USER_BUFFER
;
105 case CR_INVALID_DEVICE_ID
: return ERROR_INVALID_PARAMETER
;
106 case CR_INVALID_MACHINENAME
: return ERROR_INVALID_COMPUTERNAME
;
107 case CR_INVALID_DEVNODE
: return ERROR_INVALID_PARAMETER
;
108 case CR_INVALID_FLAG
: return ERROR_INVALID_FLAGS
;
109 case CR_INVALID_POINTER
: return ERROR_INVALID_PARAMETER
;
110 case CR_INVALID_PROPERTY
: return ERROR_INVALID_PARAMETER
;
111 case CR_NO_SUCH_DEVNODE
: return ERROR_FILE_NOT_FOUND
;
112 case CR_NO_SUCH_REGISTRY_KEY
: return ERROR_FILE_NOT_FOUND
;
113 case CR_NO_SUCH_VALUE
: return ERROR_FILE_NOT_FOUND
;
114 case CR_OUT_OF_MEMORY
: return ERROR_NOT_ENOUGH_MEMORY
;
115 case CR_REGISTRY_ERROR
: return ERROR_GEN_FAILURE
;
116 case CR_SUCCESS
: return ERROR_SUCCESS
;
117 default: return ERROR_GEN_FAILURE
;
120 /* Does not happen */
123 /* Lower scores are best ones */
126 IN LPCWSTR SectionName
,
127 IN PSP_ALTPLATFORM_INFO PlatformInfo
,
130 OUT PDWORD ScorePlatform
,
131 OUT PDWORD ScoreMajorVersion
,
132 OUT PDWORD ScoreMinorVersion
,
133 OUT PDWORD ScoreProductType
,
134 OUT PDWORD ScoreSuiteMask
)
136 LPWSTR Section
= NULL
;
137 LPCWSTR pExtensionPlatform
, pExtensionArchitecture
;
142 static const WCHAR ExtensionPlatformNone
[] = {'.',0};
143 static const WCHAR ExtensionPlatformNT
[] = {'.','N','T',0};
144 static const WCHAR ExtensionPlatformWindows
[] = {'.','W','i','n',0};
146 static const WCHAR ExtensionArchitectureNone
[] = {0};
147 static const WCHAR ExtensionArchitecturealpha
[] = {'a','l','p','h','a',0};
148 static const WCHAR ExtensionArchitectureamd64
[] = {'A','M','D','6','4',0};
149 static const WCHAR ExtensionArchitectureia64
[] = {'I','A','6','4',0};
150 static const WCHAR ExtensionArchitecturemips
[] = {'m','i','p','s',0};
151 static const WCHAR ExtensionArchitectureppc
[] = {'p','p','c',0};
152 static const WCHAR ExtensionArchitecturex86
[] = {'x','8','6',0};
154 TRACE("%s %p 0x%x 0x%x\n",
155 debugstr_w(SectionName
), PlatformInfo
, ProductType
, SuiteMask
);
157 *ScorePlatform
= *ScoreMajorVersion
= *ScoreMinorVersion
= *ScoreProductType
= *ScoreSuiteMask
= 0;
159 Section
= DuplicateString(SectionName
);
162 TRACE("DuplicateString() failed\n");
166 /* Set various extensions values */
167 switch (PlatformInfo
->Platform
)
169 case VER_PLATFORM_WIN32_WINDOWS
:
170 pExtensionPlatform
= ExtensionPlatformWindows
;
172 case VER_PLATFORM_WIN32_NT
:
173 pExtensionPlatform
= ExtensionPlatformNT
;
176 ERR("Unknown platform 0x%lx\n", PlatformInfo
->Platform
);
177 pExtensionPlatform
= ExtensionPlatformNone
;
180 switch (PlatformInfo
->ProcessorArchitecture
)
182 case PROCESSOR_ARCHITECTURE_ALPHA
:
183 pExtensionArchitecture
= ExtensionArchitecturealpha
;
185 case PROCESSOR_ARCHITECTURE_AMD64
:
186 pExtensionArchitecture
= ExtensionArchitectureamd64
;
188 case PROCESSOR_ARCHITECTURE_IA64
:
189 pExtensionArchitecture
= ExtensionArchitectureia64
;
191 case PROCESSOR_ARCHITECTURE_INTEL
:
192 pExtensionArchitecture
= ExtensionArchitecturex86
;
194 case PROCESSOR_ARCHITECTURE_MIPS
:
195 pExtensionArchitecture
= ExtensionArchitecturemips
;
197 case PROCESSOR_ARCHITECTURE_PPC
:
198 pExtensionArchitecture
= ExtensionArchitectureppc
;
201 ERR("Unknown processor architecture 0x%x\n", PlatformInfo
->ProcessorArchitecture
);
202 case PROCESSOR_ARCHITECTURE_UNKNOWN
:
203 pExtensionArchitecture
= ExtensionArchitectureNone
;
209 * Field[1] Architecture
210 * Field[2] Major version
211 * Field[3] Minor version
212 * Field[4] Product type
213 * Field[5] Suite mask
214 * Remark: lastests fields may be NULL if the information is not provided
217 if (Fields
[0] == NULL
)
219 TRACE("No extension found\n");
220 *ScorePlatform
= *ScoreMajorVersion
= *ScoreMinorVersion
= *ScoreProductType
= *ScoreSuiteMask
= ULONG_MAX
;
224 Fields
[1] = Fields
[0] + 1;
225 Fields
[2] = Fields
[3] = Fields
[4] = Fields
[5] = NULL
;
226 for (i
= 2; Fields
[i
- 1] != NULL
&& i
< 6; i
++)
228 Fields
[i
] = wcschr(Fields
[i
- 1], '.');
232 *(Fields
[i
] - 1) = UNICODE_NULL
;
235 /* Take care of first 2 fields */
236 if (strncmpiW(Fields
[0], ExtensionPlatformWindows
, strlenW(ExtensionPlatformWindows
)) == 0)
238 if (PlatformInfo
->Platform
!= VER_PLATFORM_WIN32_WINDOWS
)
240 TRACE("Mismatch on platform field\n");
243 Fields
[1] += wcslen(ExtensionPlatformWindows
) - 1;
245 else if (strncmpiW(Fields
[0], ExtensionPlatformNT
, strlenW(ExtensionPlatformNT
)) == 0)
247 if (PlatformInfo
->Platform
!= VER_PLATFORM_WIN32_NT
)
249 TRACE("Mismatch on platform field\n");
252 Fields
[1] += wcslen(ExtensionPlatformNT
) - 1;
256 /* No platform specified */
257 *ScorePlatform
|= 0x02;
259 if (strcmpiW(Fields
[1], ExtensionArchitectureNone
) == 0)
261 /* No architecture specified */
262 *ScorePlatform
|= 0x01;
264 else if (strcmpiW(Fields
[1], pExtensionArchitecture
) != 0)
266 TRACE("Mismatch on architecture field ('%s' and '%s')\n",
267 debugstr_w(Fields
[1]), debugstr_w(pExtensionArchitecture
));
271 /* Check if informations are matching */
272 if (Fields
[2] && *Fields
[2])
274 DWORD MajorVersion
, MinorVersion
= 0;
275 MajorVersion
= strtoulW(Fields
[2], NULL
, 0);
276 if ((MajorVersion
== 0 || MajorVersion
== ULONG_MAX
) &&
277 (errno
== ERANGE
|| errno
== EINVAL
))
279 TRACE("Wrong MajorVersion ('%s')\n", debugstr_w(Fields
[2]));
282 if (Fields
[3] && *Fields
[3])
284 MinorVersion
= strtoulW(Fields
[3], NULL
, 0);
285 if ((MinorVersion
== 0 || MinorVersion
== ULONG_MAX
) &&
286 (errno
== ERANGE
|| errno
== EINVAL
))
288 TRACE("Wrong MinorVersion ('%s')\n", debugstr_w(Fields
[3]));
292 if (PlatformInfo
->MajorVersion
< MajorVersion
||
293 (PlatformInfo
->MajorVersion
== MajorVersion
&& PlatformInfo
->MinorVersion
< MinorVersion
))
295 TRACE("Mismatch on version field (%lu.%lu and %lu.%lu)\n",
296 MajorVersion
, MinorVersion
, PlatformInfo
->MajorVersion
, PlatformInfo
->MinorVersion
);
299 *ScoreMajorVersion
= MajorVersion
- PlatformInfo
->MajorVersion
;
300 if (MajorVersion
== PlatformInfo
->MajorVersion
)
301 *ScoreMinorVersion
= MinorVersion
- PlatformInfo
->MinorVersion
;
303 *ScoreMinorVersion
= MinorVersion
;
305 else if (Fields
[3] && *Fields
[3])
307 TRACE("Minor version found without major version\n");
312 *ScoreMajorVersion
= PlatformInfo
->MajorVersion
;
313 *ScoreMinorVersion
= PlatformInfo
->MinorVersion
;
316 if (Fields
[4] && *Fields
[4])
318 DWORD CurrentProductType
;
319 CurrentProductType
= strtoulW(Fields
[4], NULL
, 0);
320 if ((CurrentProductType
== 0 || CurrentProductType
== ULONG_MAX
) &&
321 (errno
== ERANGE
|| errno
== EINVAL
))
323 TRACE("Wrong Product type ('%s')\n", debugstr_w(Fields
[4]));
326 if (CurrentProductType
!= ProductType
)
328 TRACE("Mismatch on product type (0x%08lx and 0x%08x)\n",
329 CurrentProductType
, ProductType
);
334 *ScoreProductType
= 1;
336 if (Fields
[5] && *Fields
[5])
338 DWORD CurrentSuiteMask
;
339 CurrentSuiteMask
= strtoulW(Fields
[5], NULL
, 0);
340 if ((CurrentSuiteMask
== 0 || CurrentSuiteMask
== ULONG_MAX
) &&
341 (errno
== ERANGE
|| errno
== EINVAL
))
343 TRACE("Wrong Suite mask ('%s')\n", debugstr_w(Fields
[5]));
346 if ((CurrentSuiteMask
& ~SuiteMask
) != 0)
348 TRACE("Mismatch on suite mask (0x%08lx and 0x%08x)\n",
349 CurrentSuiteMask
, SuiteMask
);
352 *ScoreSuiteMask
= SuiteMask
& ~CurrentSuiteMask
;
355 *ScoreSuiteMask
= SuiteMask
;
366 IN LPCWSTR SectionName
,
369 struct GetSectionCallbackInfo
*info
= Context
;
370 DWORD Score1
, Score2
, Score3
, Score4
, Score5
;
373 if (SectionName
[info
->PrefixLength
] != '.')
376 ret
= CheckSectionValid(
377 &SectionName
[info
->PrefixLength
],
381 &Score1
, &Score2
, &Score3
, &Score4
, &Score5
);
384 TRACE("Section %s not compatible\n", debugstr_w(SectionName
));
387 if (Score1
> info
->BestScore1
) goto done
;
388 if (Score1
< info
->BestScore1
) goto bettersection
;
389 if (Score2
> info
->BestScore2
) goto done
;
390 if (Score2
< info
->BestScore2
) goto bettersection
;
391 if (Score3
> info
->BestScore3
) goto done
;
392 if (Score3
< info
->BestScore3
) goto bettersection
;
393 if (Score4
> info
->BestScore4
) goto done
;
394 if (Score4
< info
->BestScore4
) goto bettersection
;
395 if (Score5
> info
->BestScore5
) goto done
;
396 if (Score5
< info
->BestScore5
) goto bettersection
;
400 strcpyW(info
->BestSection
, SectionName
);
401 info
->BestScore1
= Score1
;
402 info
->BestScore2
= Score2
;
403 info
->BestScore3
= Score3
;
404 info
->BestScore4
= Score4
;
405 info
->BestScore5
= Score5
;
411 /***********************************************************************
412 * SetupDiGetActualSectionToInstallExW (SETUPAPI.@)
415 SetupDiGetActualSectionToInstallExW(
417 IN PCWSTR InfSectionName
,
418 IN PSP_ALTPLATFORM_INFO AlternatePlatformInfo OPTIONAL
,
419 OUT PWSTR InfSectionWithExt OPTIONAL
,
420 IN DWORD InfSectionWithExtSize
,
421 OUT PDWORD RequiredSize OPTIONAL
,
422 OUT PWSTR
* Extension OPTIONAL
,
427 TRACE("%p %s %p %p %lu %p %p %p\n", InfHandle
, debugstr_w(InfSectionName
),
428 AlternatePlatformInfo
, InfSectionWithExt
, InfSectionWithExtSize
,
429 RequiredSize
, Extension
, Reserved
);
431 if (!InfHandle
|| InfHandle
== (HINF
)INVALID_HANDLE_VALUE
)
432 SetLastError(ERROR_INVALID_HANDLE
);
433 else if (!InfSectionName
)
434 SetLastError(ERROR_INVALID_PARAMETER
);
435 else if (AlternatePlatformInfo
&& AlternatePlatformInfo
->cbSize
!= sizeof(SP_ALTPLATFORM_INFO
))
436 SetLastError(ERROR_INVALID_USER_BUFFER
);
437 else if (Reserved
!= NULL
)
438 SetLastError(ERROR_INVALID_PARAMETER
);
441 static SP_ALTPLATFORM_INFO CurrentPlatform
= { 0, };
442 static BYTE CurrentProductType
= 0;
443 static WORD CurrentSuiteMask
= 0;
444 PSP_ALTPLATFORM_INFO pPlatformInfo
= &CurrentPlatform
;
445 struct GetSectionCallbackInfo CallbackInfo
;
450 /* Fill platform info if needed */
451 if (AlternatePlatformInfo
)
453 pPlatformInfo
= AlternatePlatformInfo
;
459 if (CurrentPlatform
.cbSize
!= sizeof(SP_ALTPLATFORM_INFO
))
461 /* That's the first time we go here. We need to fill in the structure */
462 OSVERSIONINFOEX VersionInfo
;
463 SYSTEM_INFO SystemInfo
;
464 VersionInfo
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
465 ret
= GetVersionExW((OSVERSIONINFO
*)&VersionInfo
);
468 GetSystemInfo(&SystemInfo
);
469 CurrentPlatform
.cbSize
= sizeof(SP_ALTPLATFORM_INFO
);
470 CurrentPlatform
.Platform
= VersionInfo
.dwPlatformId
;
471 CurrentPlatform
.MajorVersion
= VersionInfo
.dwMajorVersion
;
472 CurrentPlatform
.MinorVersion
= VersionInfo
.dwMinorVersion
;
473 CurrentPlatform
.ProcessorArchitecture
= SystemInfo
.wProcessorArchitecture
;
474 CurrentPlatform
.Reserved
= 0;
475 CurrentProductType
= VersionInfo
.wProductType
;
476 CurrentSuiteMask
= VersionInfo
.wSuiteMask
;
478 ProductType
= CurrentProductType
;
479 SuiteMask
= CurrentSuiteMask
;
482 CallbackInfo
.PlatformInfo
= pPlatformInfo
;
483 CallbackInfo
.ProductType
= ProductType
;
484 CallbackInfo
.SuiteMask
= SuiteMask
;
485 CallbackInfo
.PrefixLength
= strlenW(InfSectionName
);
486 CallbackInfo
.BestScore1
= ULONG_MAX
;
487 CallbackInfo
.BestScore2
= ULONG_MAX
;
488 CallbackInfo
.BestScore3
= ULONG_MAX
;
489 CallbackInfo
.BestScore4
= ULONG_MAX
;
490 CallbackInfo
.BestScore5
= ULONG_MAX
;
491 strcpyW(CallbackInfo
.BestSection
, InfSectionName
);
492 if (!EnumerateSectionsStartingWith(
498 SetLastError(ERROR_GEN_FAILURE
);
502 dwFullLength
= lstrlenW(CallbackInfo
.BestSection
);
503 if (RequiredSize
!= NULL
)
504 *RequiredSize
= dwFullLength
+ 1;
506 if (InfSectionWithExtSize
> 0)
508 if (InfSectionWithExtSize
< dwFullLength
+ 1)
510 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
513 strcpyW(InfSectionWithExt
, CallbackInfo
.BestSection
);
516 DWORD dwLength
= lstrlenW(InfSectionName
);
517 *Extension
= (dwLength
== dwFullLength
) ? NULL
: &InfSectionWithExt
[dwLength
];
525 TRACE("Returning %d\n", ret
);
532 IN
struct DeviceInfoSet
*list
,
533 IN LPCWSTR InstancePath
,
534 IN LPCGUID pClassGuid
,
535 OUT
struct DeviceInfo
**pDeviceInfo
)
539 struct DeviceInfo
*deviceInfo
;
543 size
= FIELD_OFFSET(struct DeviceInfo
, Data
) + (strlenW(InstancePath
) + 1) * sizeof(WCHAR
);
544 deviceInfo
= HeapAlloc(GetProcessHeap(), 0, size
);
547 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
550 ZeroMemory(deviceInfo
, size
);
552 cr
= CM_Locate_DevNode_ExW(&deviceInfo
->dnDevInst
, (DEVINSTID_W
)InstancePath
, CM_LOCATE_DEVNODE_PHANTOM
, list
->hMachine
);
553 if (cr
!= CR_SUCCESS
)
555 SetLastError(GetErrorCodeFromCrCode(cr
));
559 deviceInfo
->set
= list
;
560 deviceInfo
->InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
561 strcpyW(deviceInfo
->Data
, InstancePath
);
562 deviceInfo
->instanceId
= deviceInfo
->Data
;
563 deviceInfo
->UniqueId
= strrchrW(deviceInfo
->Data
, '\\');
564 deviceInfo
->DeviceDescription
= NULL
;
565 memcpy(&deviceInfo
->ClassGuid
, pClassGuid
, sizeof(GUID
));
566 deviceInfo
->CreationFlags
= 0;
567 InitializeListHead(&deviceInfo
->DriverListHead
);
568 InitializeListHead(&deviceInfo
->InterfaceListHead
);
570 *pDeviceInfo
= deviceInfo
;
576 DestroyClassInstallParams(struct ClassInstallParams
* installParams
)
578 HeapFree(GetProcessHeap(), 0, installParams
->PropChangeParams
);
579 HeapFree(GetProcessHeap(), 0, installParams
->AddPropertyPageData
);
584 DestroyDeviceInfo(struct DeviceInfo
*deviceInfo
)
586 PLIST_ENTRY ListEntry
;
587 struct DriverInfoElement
*driverInfo
;
588 struct DeviceInterface
*deviceInterface
;
590 while (!IsListEmpty(&deviceInfo
->DriverListHead
))
592 ListEntry
= RemoveHeadList(&deviceInfo
->DriverListHead
);
593 driverInfo
= CONTAINING_RECORD(ListEntry
, struct DriverInfoElement
, ListEntry
);
594 if (!DestroyDriverInfoElement(driverInfo
))
597 while (!IsListEmpty(&deviceInfo
->InterfaceListHead
))
599 ListEntry
= RemoveHeadList(&deviceInfo
->InterfaceListHead
);
600 deviceInterface
= CONTAINING_RECORD(ListEntry
, struct DeviceInterface
, ListEntry
);
601 if (!DestroyDeviceInterface(deviceInterface
))
604 DestroyClassInstallParams(&deviceInfo
->ClassInstallParams
);
605 return HeapFree(GetProcessHeap(), 0, deviceInfo
);
609 DestroyDeviceInfoSet(struct DeviceInfoSet
* list
)
611 PLIST_ENTRY ListEntry
;
612 struct DeviceInfo
*deviceInfo
;
614 while (!IsListEmpty(&list
->ListHead
))
616 ListEntry
= RemoveHeadList(&list
->ListHead
);
617 deviceInfo
= CONTAINING_RECORD(ListEntry
, struct DeviceInfo
, ListEntry
);
618 if (!DestroyDeviceInfo(deviceInfo
))
621 if (list
->HKLM
!= HKEY_LOCAL_MACHINE
)
622 RegCloseKey(list
->HKLM
);
623 CM_Disconnect_Machine(list
->hMachine
);
624 DestroyClassInstallParams(&list
->ClassInstallParams
);
625 return HeapFree(GetProcessHeap(), 0, list
);
628 /***********************************************************************
629 * SetupDiBuildClassInfoList (SETUPAPI.@)
631 * Returns a list of setup class GUIDs that identify the classes
632 * that are installed on a local machine.
635 * Flags [I] control exclusion of classes from the list.
636 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
637 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
638 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
644 BOOL WINAPI
SetupDiBuildClassInfoList(
646 LPGUID ClassGuidList
,
647 DWORD ClassGuidListSize
,
651 return SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
652 ClassGuidListSize
, RequiredSize
,
656 /***********************************************************************
657 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
659 * Returns a list of setup class GUIDs that identify the classes
660 * that are installed on a local or remote macine.
663 * Flags [I] control exclusion of classes from the list.
664 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
665 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
666 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
667 * MachineName [I] name of a remote machine.
668 * Reserved [I] must be NULL.
674 BOOL WINAPI
SetupDiBuildClassInfoListExA(
676 LPGUID ClassGuidList
,
677 DWORD ClassGuidListSize
,
682 LPWSTR MachineNameW
= NULL
;
685 TRACE("0x%lx %p %lu %p %s %p\n", Flags
, ClassGuidList
,
686 ClassGuidListSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
690 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
691 if (MachineNameW
== NULL
) return FALSE
;
694 bResult
= SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
695 ClassGuidListSize
, RequiredSize
,
696 MachineNameW
, Reserved
);
698 MyFree(MachineNameW
);
703 /***********************************************************************
704 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
706 * Returns a list of setup class GUIDs that identify the classes
707 * that are installed on a local or remote macine.
710 * Flags [I] control exclusion of classes from the list.
711 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
712 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
713 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
714 * MachineName [I] name of a remote machine.
715 * Reserved [I] must be NULL.
721 BOOL WINAPI
SetupDiBuildClassInfoListExW(
723 LPGUID ClassGuidList
,
724 DWORD ClassGuidListSize
,
730 HKEY hClassesKey
= INVALID_HANDLE_VALUE
;
735 DWORD dwGuidListIndex
= 0;
737 TRACE("0x%lx %p %lu %p %s %p\n", Flags
, ClassGuidList
,
738 ClassGuidListSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
742 SetLastError(ERROR_INVALID_PARAMETER
);
745 else if (!ClassGuidList
&& ClassGuidListSize
> 0)
747 SetLastError(ERROR_INVALID_PARAMETER
);
751 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
752 KEY_ENUMERATE_SUB_KEYS
,
756 if (hClassesKey
== INVALID_HANDLE_VALUE
)
761 for (dwIndex
= 0; ; dwIndex
++)
764 lError
= RegEnumKeyExW(hClassesKey
,
772 TRACE("RegEnumKeyExW() returns %d\n", lError
);
773 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
775 TRACE("Key name: %s\n", debugstr_w(szKeyName
));
777 if (RegOpenKeyExW(hClassesKey
,
783 RegCloseKey(hClassesKey
);
787 if (!RegQueryValueExW(hClassKey
,
788 REGSTR_VAL_NOUSECLASS
,
794 TRACE("'NoUseClass' value found!\n");
795 RegCloseKey(hClassKey
);
799 if ((Flags
& DIBCI_NOINSTALLCLASS
) &&
800 (!RegQueryValueExW(hClassKey
,
801 REGSTR_VAL_NOINSTALLCLASS
,
807 TRACE("'NoInstallClass' value found!\n");
808 RegCloseKey(hClassKey
);
812 if ((Flags
& DIBCI_NODISPLAYCLASS
) &&
813 (!RegQueryValueExW(hClassKey
,
814 REGSTR_VAL_NODISPLAYCLASS
,
820 TRACE("'NoDisplayClass' value found!\n");
821 RegCloseKey(hClassKey
);
825 RegCloseKey(hClassKey
);
827 TRACE("Guid: %s\n", debugstr_w(szKeyName
));
828 if (dwGuidListIndex
< ClassGuidListSize
)
830 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
834 TRACE("Guid: %p\n", &szKeyName
[1]);
836 UuidFromStringW(&szKeyName
[1],
837 &ClassGuidList
[dwGuidListIndex
]);
843 if (lError
!= ERROR_SUCCESS
)
847 RegCloseKey(hClassesKey
);
849 if (RequiredSize
!= NULL
)
850 *RequiredSize
= dwGuidListIndex
;
852 if (ClassGuidListSize
< dwGuidListIndex
)
854 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
861 /***********************************************************************
862 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
864 BOOL WINAPI
SetupDiClassGuidsFromNameA(
866 LPGUID ClassGuidList
,
867 DWORD ClassGuidListSize
,
870 return SetupDiClassGuidsFromNameExA(ClassName
, ClassGuidList
,
871 ClassGuidListSize
, RequiredSize
,
875 /***********************************************************************
876 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
878 BOOL WINAPI
SetupDiClassGuidsFromNameW(
880 LPGUID ClassGuidList
,
881 DWORD ClassGuidListSize
,
884 return SetupDiClassGuidsFromNameExW(ClassName
, ClassGuidList
,
885 ClassGuidListSize
, RequiredSize
,
889 /***********************************************************************
890 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
892 BOOL WINAPI
SetupDiClassGuidsFromNameExA(
894 LPGUID ClassGuidList
,
895 DWORD ClassGuidListSize
,
900 LPWSTR ClassNameW
= NULL
;
901 LPWSTR MachineNameW
= NULL
;
904 TRACE("%s %p %lu %p %s %p\n", debugstr_a(ClassName
), ClassGuidList
,
905 ClassGuidListSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
909 SetLastError(ERROR_INVALID_PARAMETER
);
913 ClassNameW
= MultiByteToUnicode(ClassName
, CP_ACP
);
914 if (ClassNameW
== NULL
)
919 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
920 if (MachineNameW
== NULL
)
927 bResult
= SetupDiClassGuidsFromNameExW(ClassNameW
, ClassGuidList
,
928 ClassGuidListSize
, RequiredSize
,
929 MachineNameW
, Reserved
);
931 MyFree(MachineNameW
);
937 /***********************************************************************
938 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
940 BOOL WINAPI
SetupDiClassGuidsFromNameExW(
942 LPGUID ClassGuidList
,
943 DWORD ClassGuidListSize
,
949 WCHAR szClassName
[MAX_CLASS_NAME_LEN
];
955 DWORD dwGuidListIndex
= 0;
957 TRACE("%s %p %lu %p %s %p\n", debugstr_w(ClassName
), ClassGuidList
,
958 ClassGuidListSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
960 if (!ClassName
|| !RequiredSize
)
962 SetLastError(ERROR_INVALID_PARAMETER
);
965 if (!ClassGuidList
&& ClassGuidListSize
> 0)
967 SetLastError(ERROR_INVALID_PARAMETER
);
972 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
973 KEY_ENUMERATE_SUB_KEYS
,
977 if (hClassesKey
== INVALID_HANDLE_VALUE
)
982 for (dwIndex
= 0; ; dwIndex
++)
985 lError
= RegEnumKeyExW(hClassesKey
,
993 TRACE("RegEnumKeyExW() returns %d\n", lError
);
994 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
996 TRACE("Key name: %p\n", szKeyName
);
998 if (RegOpenKeyExW(hClassesKey
,
1004 RegCloseKey(hClassesKey
);
1008 dwLength
= MAX_CLASS_NAME_LEN
* sizeof(WCHAR
);
1009 if (!RegQueryValueExW(hClassKey
,
1013 (LPBYTE
)szClassName
,
1016 TRACE("Class name: %p\n", szClassName
);
1018 if (strcmpiW(szClassName
, ClassName
) == 0)
1020 TRACE("Found matching class name\n");
1022 TRACE("Guid: %p\n", szKeyName
);
1023 if (dwGuidListIndex
< ClassGuidListSize
)
1025 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
1029 TRACE("Guid: %p\n", &szKeyName
[1]);
1031 UuidFromStringW(&szKeyName
[1],
1032 &ClassGuidList
[dwGuidListIndex
]);
1039 RegCloseKey(hClassKey
);
1042 if (lError
!= ERROR_SUCCESS
)
1046 RegCloseKey(hClassesKey
);
1048 if (RequiredSize
!= NULL
)
1049 *RequiredSize
= dwGuidListIndex
;
1051 if (ClassGuidListSize
< dwGuidListIndex
)
1053 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1060 /***********************************************************************
1061 * SetupDiClassNameFromGuidA (SETUPAPI.@)
1063 BOOL WINAPI
SetupDiClassNameFromGuidA(
1064 const GUID
* ClassGuid
,
1066 DWORD ClassNameSize
,
1067 PDWORD RequiredSize
)
1069 return SetupDiClassNameFromGuidExA(ClassGuid
, ClassName
,
1070 ClassNameSize
, RequiredSize
,
1074 /***********************************************************************
1075 * SetupDiClassNameFromGuidW (SETUPAPI.@)
1077 BOOL WINAPI
SetupDiClassNameFromGuidW(
1078 const GUID
* ClassGuid
,
1080 DWORD ClassNameSize
,
1081 PDWORD RequiredSize
)
1083 return SetupDiClassNameFromGuidExW(ClassGuid
, ClassName
,
1084 ClassNameSize
, RequiredSize
,
1088 /***********************************************************************
1089 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1091 BOOL WINAPI
SetupDiClassNameFromGuidExA(
1092 const GUID
* ClassGuid
,
1094 DWORD ClassNameSize
,
1095 PDWORD RequiredSize
,
1099 WCHAR ClassNameW
[MAX_CLASS_NAME_LEN
];
1100 LPWSTR MachineNameW
= NULL
;
1104 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1105 ret
= SetupDiClassNameFromGuidExW(ClassGuid
, ClassNameW
, MAX_CLASS_NAME_LEN
,
1106 NULL
, MachineNameW
, Reserved
);
1109 int len
= WideCharToMultiByte(CP_ACP
, 0, ClassNameW
, -1, ClassName
,
1110 ClassNameSize
, NULL
, NULL
);
1111 if (len
== 0 || len
> ClassNameSize
)
1113 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1116 else if (RequiredSize
)
1117 *RequiredSize
= len
;
1119 MyFree(MachineNameW
);
1123 /***********************************************************************
1124 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1126 BOOL WINAPI
SetupDiClassNameFromGuidExW(
1127 const GUID
* ClassGuid
,
1129 DWORD ClassNameSize
,
1130 PDWORD RequiredSize
,
1139 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassName
,
1140 ClassNameSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
1142 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1147 if (hKey
== INVALID_HANDLE_VALUE
)
1152 if (RequiredSize
!= NULL
)
1155 if (RegQueryValueExW(hKey
,
1166 *RequiredSize
= dwLength
/ sizeof(WCHAR
) + 1;
1171 SetLastError(ERROR_INVALID_CLASS
);
1175 if (!ClassName
&& ClassNameSize
> 0)
1177 SetLastError(ERROR_INVALID_PARAMETER
);
1182 dwLength
= ClassNameSize
* sizeof(WCHAR
) - sizeof(UNICODE_NULL
);
1183 rc
= RegQueryValueExW(hKey
,
1189 if (rc
!= ERROR_SUCCESS
)
1195 if (dwRegType
!= REG_SZ
)
1197 SetLastError(ERROR_GEN_FAILURE
);
1202 if (ClassNameSize
> 1)
1203 ClassName
[ClassNameSize
] = UNICODE_NULL
;
1209 /***********************************************************************
1210 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1213 SetupDiCreateDeviceInfoList(const GUID
*ClassGuid
,
1216 return SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
, NULL
, NULL
);
1219 /***********************************************************************
1220 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1223 SetupDiCreateDeviceInfoListExA(const GUID
*ClassGuid
,
1228 LPWSTR MachineNameW
= NULL
;
1231 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1232 debugstr_a(MachineName
), Reserved
);
1236 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1237 if (MachineNameW
== NULL
)
1238 return INVALID_HANDLE_VALUE
;
1241 hDevInfo
= SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
,
1242 MachineNameW
, Reserved
);
1244 MyFree(MachineNameW
);
1249 /***********************************************************************
1250 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1252 * Create an empty DeviceInfoSet list.
1255 * ClassGuid [I] if not NULL only devices with GUID ClcassGuid are associated
1257 * hwndParent [I] hwnd needed for interface related actions.
1258 * MachineName [I] name of machine to create emtpy DeviceInfoSet list, if NULL
1259 * local registry will be used.
1260 * Reserved [I] must be NULL
1263 * Success: empty list.
1264 * Failure: INVALID_HANDLE_VALUE.
1267 SetupDiCreateDeviceInfoListExW(const GUID
*ClassGuid
,
1272 struct DeviceInfoSet
*list
= NULL
;
1273 DWORD size
= FIELD_OFFSET(struct DeviceInfoSet
, szData
);
1276 HDEVINFO ret
= INVALID_HANDLE_VALUE
;
1278 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1279 debugstr_w(MachineName
), Reserved
);
1281 if (MachineName
!= NULL
)
1283 SIZE_T len
= strlenW(MachineName
);
1284 if (len
>= SP_MAX_MACHINENAME_LENGTH
- 4)
1286 SetLastError(ERROR_INVALID_MACHINENAME
);
1289 size
+= (len
+ 3) * sizeof(WCHAR
);
1292 if (Reserved
!= NULL
)
1294 SetLastError(ERROR_INVALID_PARAMETER
);
1295 return INVALID_HANDLE_VALUE
;
1298 list
= MyMalloc(size
);
1301 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1302 return INVALID_HANDLE_VALUE
;
1304 ZeroMemory(list
, FIELD_OFFSET(struct DeviceInfoSet
, szData
));
1306 list
->magic
= SETUP_DEVICE_INFO_SET_MAGIC
;
1307 memcpy(&list
->ClassGuid
,
1308 ClassGuid
? ClassGuid
: &GUID_NULL
,
1309 sizeof(list
->ClassGuid
));
1310 list
->InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
1311 list
->InstallParams
.Flags
|= DI_CLASSINSTALLPARAMS
;
1312 list
->InstallParams
.hwndParent
= hwndParent
;
1315 rc
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &list
->HKLM
);
1316 if (rc
!= ERROR_SUCCESS
)
1318 SetLastError(ERROR_INVALID_MACHINENAME
);
1322 list
->szData
[0] = list
->szData
[1] = '\\';
1323 strcpyW(list
->szData
+ 2, MachineName
);
1324 list
->MachineName
= list
->szData
;
1328 list
->HKLM
= HKEY_LOCAL_MACHINE
;
1329 list
->MachineName
= NULL
;
1331 cr
= CM_Connect_MachineW(list
->MachineName
, &list
->hMachine
);
1332 if (cr
!= CR_SUCCESS
)
1334 SetLastError(GetErrorCodeFromCrCode(cr
));
1337 InitializeListHead(&list
->DriverListHead
);
1338 InitializeListHead(&list
->ListHead
);
1340 return (HDEVINFO
)list
;
1343 if (ret
== INVALID_HANDLE_VALUE
)
1347 if (list
->HKLM
!= NULL
&& list
->HKLM
!= HKEY_LOCAL_MACHINE
)
1348 RegCloseKey(list
->HKLM
);
1355 /***********************************************************************
1356 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1358 HKEY WINAPI
SetupDiCreateDevRegKeyA(
1359 HDEVINFO DeviceInfoSet
,
1360 PSP_DEVINFO_DATA DeviceInfoData
,
1365 PCSTR InfSectionName
)
1367 PWSTR InfSectionNameW
= NULL
;
1370 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1371 HwProfile
, KeyType
, InfHandle
, debugstr_a(InfSectionName
));
1375 if (!InfSectionName
)
1377 SetLastError(ERROR_INVALID_PARAMETER
);
1378 return INVALID_HANDLE_VALUE
;
1382 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
1383 if (InfSectionNameW
== NULL
) return INVALID_HANDLE_VALUE
;
1386 key
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, Scope
,
1387 HwProfile
, KeyType
, InfHandle
, InfSectionNameW
);
1388 MyFree(InfSectionNameW
);
1393 OpenHardwareProfileKey(
1396 IN DWORD samDesired
);
1398 /***********************************************************************
1399 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1401 HKEY WINAPI
SetupDiCreateDevRegKeyW(
1402 HDEVINFO DeviceInfoSet
,
1403 PSP_DEVINFO_DATA DeviceInfoData
,
1408 PCWSTR InfSectionName
)
1410 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1411 HKEY key
= INVALID_HANDLE_VALUE
;
1413 TRACE("%p %p %lu %lu %lu %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1414 HwProfile
, KeyType
, InfHandle
, debugstr_w(InfSectionName
));
1416 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1418 SetLastError(ERROR_INVALID_HANDLE
);
1419 return INVALID_HANDLE_VALUE
;
1421 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1423 SetLastError(ERROR_INVALID_HANDLE
);
1424 return INVALID_HANDLE_VALUE
;
1426 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1427 || !DeviceInfoData
->Reserved
)
1429 SetLastError(ERROR_INVALID_PARAMETER
);
1430 return INVALID_HANDLE_VALUE
;
1432 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
1434 SetLastError(ERROR_INVALID_FLAGS
);
1435 return INVALID_HANDLE_VALUE
;
1437 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
1439 SetLastError(ERROR_INVALID_FLAGS
);
1440 return INVALID_HANDLE_VALUE
;
1442 if (InfHandle
&& !InfSectionName
)
1444 SetLastError(ERROR_INVALID_PARAMETER
);
1445 return INVALID_HANDLE_VALUE
;
1447 if (!InfHandle
&& InfSectionName
)
1449 SetLastError(ERROR_INVALID_PARAMETER
);
1450 return INVALID_HANDLE_VALUE
;
1453 LPWSTR lpGuidString
= NULL
;
1454 LPWSTR DriverKey
= NULL
; /* {GUID}\Index */
1455 LPWSTR pDeviceInstance
; /* Points into DriverKey, on the Index field */
1456 DWORD Index
; /* Index used in the DriverKey name */
1458 HKEY hHWProfileKey
= INVALID_HANDLE_VALUE
;
1459 HKEY hEnumKey
= NULL
;
1460 HKEY hClassKey
= NULL
;
1461 HKEY hDeviceKey
= INVALID_HANDLE_VALUE
;
1465 if (Scope
== DICS_FLAG_GLOBAL
)
1466 RootKey
= set
->HKLM
;
1467 else /* Scope == DICS_FLAG_CONFIGSPECIFIC */
1469 hHWProfileKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, KEY_CREATE_SUB_KEY
);
1470 if (hHWProfileKey
== INVALID_HANDLE_VALUE
)
1472 RootKey
= hHWProfileKey
;
1475 if (KeyType
== DIREG_DEV
)
1477 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1479 rc
= RegCreateKeyExW(
1481 REGSTR_PATH_SYSTEMENUM
,
1484 REG_OPTION_NON_VOLATILE
,
1489 if (rc
!= ERROR_SUCCESS
)
1494 rc
= RegCreateKeyExW(
1496 deviceInfo
->instanceId
,
1499 REG_OPTION_NON_VOLATILE
,
1500 #if _WIN32_WINNT >= 0x502
1501 KEY_READ
| KEY_WRITE
,
1508 if (rc
!= ERROR_SUCCESS
)
1514 else /* KeyType == DIREG_DRV */
1516 if (UuidToStringW((UUID
*)&DeviceInfoData
->ClassGuid
, &lpGuidString
) != RPC_S_OK
)
1518 /* The driver key is in \System\CurrentControlSet\Control\Class\{GUID}\Index */
1519 DriverKey
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpGuidString
) + 7) * sizeof(WCHAR
) + sizeof(UNICODE_NULL
));
1522 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1526 strcpyW(&DriverKey
[1], lpGuidString
);
1527 pDeviceInstance
= &DriverKey
[strlenW(DriverKey
)];
1528 *pDeviceInstance
++ = '}';
1529 *pDeviceInstance
++ = '\\';
1530 rc
= RegOpenKeyExW(RootKey
,
1531 REGSTR_PATH_CLASS_NT
,
1535 if (rc
!= ERROR_SUCCESS
)
1541 /* Try all values for Index between 0 and 9999 */
1543 while (Index
<= 9999)
1546 sprintfW(pDeviceInstance
, InstanceKeyFormat
, Index
);
1547 rc
= RegCreateKeyExW(hClassKey
,
1551 REG_OPTION_NON_VOLATILE
,
1552 #if _WIN32_WINNT >= 0x502
1553 KEY_READ
| KEY_WRITE
,
1560 if (rc
!= ERROR_SUCCESS
)
1565 if (Disposition
== REG_CREATED_NEW_KEY
)
1573 /* Unable to create more than 9999 devices within the same class */
1574 SetLastError(ERROR_GEN_FAILURE
);
1578 /* Open device key, to write Driver value */
1579 hDeviceKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
, DIREG_DEV
, KEY_SET_VALUE
);
1580 if (hDeviceKey
== INVALID_HANDLE_VALUE
)
1582 rc
= RegSetValueExW(hDeviceKey
, REGSTR_VAL_DRIVER
, 0, REG_SZ
, (const BYTE
*)DriverKey
, (strlenW(DriverKey
) + 1) * sizeof(WCHAR
));
1583 if (rc
!= ERROR_SUCCESS
)
1590 /* Do installation of the specified section */
1593 FIXME("Need to install section %s in file %p\n",
1594 debugstr_w(InfSectionName
), InfHandle
);
1600 RpcStringFreeW(&lpGuidString
);
1601 HeapFree(GetProcessHeap(), 0, DriverKey
);
1602 if (hHWProfileKey
!= INVALID_HANDLE_VALUE
)
1603 RegCloseKey(hHWProfileKey
);
1604 if (hEnumKey
!= NULL
)
1605 RegCloseKey(hEnumKey
);
1606 if (hClassKey
!= NULL
)
1607 RegCloseKey(hClassKey
);
1608 if (hDeviceKey
!= INVALID_HANDLE_VALUE
)
1609 RegCloseKey(hDeviceKey
);
1610 if (hKey
!= NULL
&& hKey
!= key
)
1613 TRACE("Returning 0x%p\n", key
);
1617 /***********************************************************************
1618 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1620 BOOL WINAPI
SetupDiCreateDeviceInfoA(
1621 HDEVINFO DeviceInfoSet
,
1623 CONST GUID
*ClassGuid
,
1624 PCSTR DeviceDescription
,
1626 DWORD CreationFlags
,
1627 PSP_DEVINFO_DATA DeviceInfoData
)
1630 LPWSTR DeviceNameW
= NULL
;
1631 LPWSTR DeviceDescriptionW
= NULL
;
1637 DeviceNameW
= MultiByteToUnicode(DeviceName
, CP_ACP
);
1638 if (DeviceNameW
== NULL
) return FALSE
;
1640 if (DeviceDescription
)
1642 DeviceDescriptionW
= MultiByteToUnicode(DeviceDescription
, CP_ACP
);
1643 if (DeviceDescriptionW
== NULL
)
1645 MyFree(DeviceNameW
);
1650 ret
= SetupDiCreateDeviceInfoW(DeviceInfoSet
, DeviceNameW
, ClassGuid
, DeviceDescriptionW
,
1651 hwndParent
, CreationFlags
, DeviceInfoData
);
1653 MyFree(DeviceNameW
);
1654 MyFree(DeviceDescriptionW
);
1659 /***********************************************************************
1660 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1662 BOOL WINAPI
SetupDiCreateDeviceInfoW(
1663 HDEVINFO DeviceInfoSet
,
1665 CONST GUID
*ClassGuid
,
1666 PCWSTR DeviceDescription
,
1668 DWORD CreationFlags
,
1669 PSP_DEVINFO_DATA DeviceInfoData
)
1671 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1674 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet
, debugstr_w(DeviceName
),
1675 debugstr_guid(ClassGuid
), debugstr_w(DeviceDescription
),
1676 hwndParent
, CreationFlags
, DeviceInfoData
);
1680 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1683 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1685 SetLastError(ERROR_INVALID_HANDLE
);
1690 SetLastError(ERROR_INVALID_PARAMETER
);
1693 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1695 SetLastError(ERROR_INVALID_HANDLE
);
1698 if (!IsEqualGUID(&set
->ClassGuid
, &GUID_NULL
) &&
1699 !IsEqualGUID(ClassGuid
, &set
->ClassGuid
))
1701 SetLastError(ERROR_CLASS_MISMATCH
);
1704 if (CreationFlags
& ~(DICD_GENERATE_ID
| DICD_INHERIT_CLASSDRVS
))
1706 TRACE("Unknown flags: 0x%08lx\n", CreationFlags
& ~(DICD_GENERATE_ID
| DICD_INHERIT_CLASSDRVS
));
1707 SetLastError(ERROR_INVALID_FLAGS
);
1711 SP_DEVINFO_DATA DevInfo
;
1713 if (CreationFlags
& DICD_GENERATE_ID
)
1715 /* Generate a new unique ID for this device */
1716 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1717 FIXME("not implemented\n");
1721 /* Device name is fully qualified. Try to open it */
1724 DevInfo
.cbSize
= sizeof(SP_DEVINFO_DATA
);
1725 rc
= SetupDiOpenDeviceInfoW(
1728 NULL
, /* hwndParent */
1729 CreationFlags
& DICD_INHERIT_CLASSDRVS
? DIOD_INHERIT_CLASSDRVS
: 0,
1734 /* SetupDiOpenDeviceInfoW has already added
1735 * the device info to the device info set
1737 SetLastError(ERROR_DEVINST_ALREADY_EXISTS
);
1739 else if (GetLastError() == ERROR_FILE_NOT_FOUND
)
1741 struct DeviceInfo
*deviceInfo
;
1743 if (CreateDeviceInfo(set
, DeviceName
, ClassGuid
, &deviceInfo
))
1745 InsertTailList(&set
->ListHead
, &deviceInfo
->ListEntry
);
1747 if (!DeviceInfoData
)
1751 if (DeviceInfoData
->cbSize
!= sizeof(PSP_DEVINFO_DATA
))
1753 SetLastError(ERROR_INVALID_USER_BUFFER
);
1757 memcpy(&DeviceInfoData
->ClassGuid
, ClassGuid
, sizeof(GUID
));
1758 DeviceInfoData
->DevInst
= deviceInfo
->dnDevInst
;
1759 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInfo
;
1767 TRACE("Returning %d\n", ret
);
1771 /***********************************************************************
1772 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1774 BOOL WINAPI
SetupDiRegisterDeviceInfo(
1775 HDEVINFO DeviceInfoSet
,
1776 PSP_DEVINFO_DATA DeviceInfoData
,
1778 PSP_DETSIG_CMPPROC CompareProc
,
1779 PVOID CompareContext
,
1780 PSP_DEVINFO_DATA DupDeviceInfoData
)
1782 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1784 TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet
, DeviceInfoData
, Flags
,
1785 CompareProc
, CompareContext
, DupDeviceInfoData
);
1787 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1789 SetLastError(ERROR_INVALID_HANDLE
);
1792 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1794 SetLastError(ERROR_INVALID_HANDLE
);
1797 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1798 || !DeviceInfoData
->Reserved
)
1800 SetLastError(ERROR_INVALID_PARAMETER
);
1803 FIXME("Stub %p %p 0x%lx %p %p %p\n", DeviceInfoSet
, DeviceInfoData
, Flags
,
1804 CompareProc
, CompareContext
, DupDeviceInfoData
);
1805 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1809 /***********************************************************************
1810 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1812 BOOL WINAPI
SetupDiEnumDeviceInfo(
1815 PSP_DEVINFO_DATA info
)
1819 TRACE("%p %d %p\n", devinfo
, index
, info
);
1823 SetLastError(ERROR_INVALID_PARAMETER
);
1826 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
1828 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
1829 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
1831 if (info
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1832 SetLastError(ERROR_INVALID_USER_BUFFER
);
1835 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
1836 while (ItemList
!= &list
->ListHead
&& index
-- > 0)
1837 ItemList
= ItemList
->Flink
;
1838 if (ItemList
== &list
->ListHead
)
1839 SetLastError(ERROR_NO_MORE_ITEMS
);
1842 struct DeviceInfo
*DevInfo
= CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
1843 memcpy(&info
->ClassGuid
,
1844 &DevInfo
->ClassGuid
,
1846 info
->DevInst
= DevInfo
->dnDevInst
;
1847 info
->Reserved
= (ULONG_PTR
)DevInfo
;
1853 SetLastError(ERROR_INVALID_HANDLE
);
1856 SetLastError(ERROR_INVALID_HANDLE
);
1860 /***********************************************************************
1861 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1863 BOOL WINAPI
SetupDiGetDeviceInstanceIdA(
1864 HDEVINFO DeviceInfoSet
,
1865 PSP_DEVINFO_DATA DeviceInfoData
,
1866 PSTR DeviceInstanceId
,
1867 DWORD DeviceInstanceIdSize
,
1868 PDWORD RequiredSize
)
1874 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1875 DeviceInstanceIdSize
, RequiredSize
);
1877 if (!DeviceInstanceId
&& DeviceInstanceIdSize
> 0)
1879 SetLastError(ERROR_INVALID_PARAMETER
);
1883 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1888 if (!ret
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1890 instanceId
= MyMalloc(size
* sizeof(WCHAR
));
1893 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1900 int len
= WideCharToMultiByte(CP_ACP
, 0, instanceId
, -1,
1902 DeviceInstanceIdSize
, NULL
, NULL
);
1908 if (len
> DeviceInstanceIdSize
)
1910 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1914 *RequiredSize
= len
;
1922 *RequiredSize
= size
;
1923 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1929 /***********************************************************************
1930 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1932 BOOL WINAPI
SetupDiGetDeviceInstanceIdW(
1933 HDEVINFO DeviceInfoSet
,
1934 PSP_DEVINFO_DATA DeviceInfoData
,
1935 PWSTR DeviceInstanceId
,
1936 DWORD DeviceInstanceIdSize
,
1937 PDWORD RequiredSize
)
1939 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1940 struct DeviceInfo
*devInfo
;
1942 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1943 DeviceInstanceIdSize
, RequiredSize
);
1945 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1947 SetLastError(ERROR_INVALID_HANDLE
);
1950 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1952 SetLastError(ERROR_INVALID_HANDLE
);
1955 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1956 || !DeviceInfoData
->Reserved
)
1958 SetLastError(ERROR_INVALID_PARAMETER
);
1961 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1962 if (!DeviceInstanceId
&& DeviceInstanceIdSize
> 0)
1964 SetLastError(ERROR_INVALID_PARAMETER
);
1967 if (DeviceInstanceId
&& DeviceInstanceIdSize
== 0)
1969 SetLastError(ERROR_INVALID_PARAMETER
);
1972 TRACE("instance ID: %s\n", debugstr_w(devInfo
->instanceId
));
1973 if (DeviceInstanceIdSize
< lstrlenW(devInfo
->instanceId
) + 1)
1975 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1977 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1980 lstrcpyW(DeviceInstanceId
, devInfo
->instanceId
);
1982 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1986 /***********************************************************************
1987 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1989 BOOL WINAPI
SetupDiGetActualSectionToInstallA(
1991 PCSTR InfSectionName
,
1992 PSTR InfSectionWithExt
,
1993 DWORD InfSectionWithExtSize
,
1994 PDWORD RequiredSize
,
1997 return SetupDiGetActualSectionToInstallExA(InfHandle
, InfSectionName
,
1998 NULL
, InfSectionWithExt
, InfSectionWithExtSize
, RequiredSize
,
2002 /***********************************************************************
2003 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
2005 BOOL WINAPI
SetupDiGetActualSectionToInstallW(
2007 PCWSTR InfSectionName
,
2008 PWSTR InfSectionWithExt
,
2009 DWORD InfSectionWithExtSize
,
2010 PDWORD RequiredSize
,
2013 return SetupDiGetActualSectionToInstallExW(InfHandle
, InfSectionName
,
2014 NULL
, InfSectionWithExt
, InfSectionWithExtSize
, RequiredSize
,
2018 /***********************************************************************
2019 * SetupDiGetActualSectionToInstallExA (SETUPAPI.@)
2022 SetupDiGetActualSectionToInstallExA(
2024 IN PCSTR InfSectionName
,
2025 IN PSP_ALTPLATFORM_INFO AlternatePlatformInfo OPTIONAL
,
2026 OUT PSTR InfSectionWithExt OPTIONAL
,
2027 IN DWORD InfSectionWithExtSize
,
2028 OUT PDWORD RequiredSize OPTIONAL
,
2029 OUT PSTR
* Extension OPTIONAL
,
2032 LPWSTR InfSectionNameW
= NULL
;
2033 LPWSTR InfSectionWithExtW
= NULL
;
2035 BOOL bResult
= FALSE
;
2041 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2042 if (InfSectionNameW
== NULL
)
2045 if (InfSectionWithExt
)
2047 InfSectionWithExtW
= MyMalloc(InfSectionWithExtSize
* sizeof(WCHAR
));
2048 if (InfSectionWithExtW
== NULL
)
2052 bResult
= SetupDiGetActualSectionToInstallExW(
2053 InfHandle
, InfSectionNameW
, AlternatePlatformInfo
,
2054 InfSectionWithExt
? InfSectionWithExtW
: NULL
,
2055 InfSectionWithExtSize
,
2057 Extension
? &ExtensionW
: NULL
,
2060 if (bResult
&& InfSectionWithExt
)
2062 bResult
= WideCharToMultiByte(CP_ACP
, 0, InfSectionWithExtW
, -1, InfSectionWithExt
,
2063 InfSectionWithExtSize
, NULL
, NULL
) != 0;
2065 if (bResult
&& Extension
)
2067 if (ExtensionW
== NULL
)
2070 *Extension
= &InfSectionWithExt
[ExtensionW
- InfSectionWithExtW
];
2074 MyFree(InfSectionNameW
);
2075 MyFree(InfSectionWithExtW
);
2080 /***********************************************************************
2081 * SetupDiGetClassDescriptionA (SETUPAPI.@)
2083 BOOL WINAPI
SetupDiGetClassDescriptionA(
2084 const GUID
* ClassGuid
,
2085 PSTR ClassDescription
,
2086 DWORD ClassDescriptionSize
,
2087 PDWORD RequiredSize
)
2089 return SetupDiGetClassDescriptionExA(ClassGuid
, ClassDescription
,
2090 ClassDescriptionSize
,
2091 RequiredSize
, NULL
, NULL
);
2094 /***********************************************************************
2095 * SetupDiGetClassDescriptionW (SETUPAPI.@)
2097 BOOL WINAPI
SetupDiGetClassDescriptionW(
2098 const GUID
* ClassGuid
,
2099 PWSTR ClassDescription
,
2100 DWORD ClassDescriptionSize
,
2101 PDWORD RequiredSize
)
2103 return SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescription
,
2104 ClassDescriptionSize
,
2105 RequiredSize
, NULL
, NULL
);
2108 /***********************************************************************
2109 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
2111 BOOL WINAPI
SetupDiGetClassDescriptionExA(
2112 const GUID
* ClassGuid
,
2113 PSTR ClassDescription
,
2114 DWORD ClassDescriptionSize
,
2115 PDWORD RequiredSize
,
2119 PWCHAR ClassDescriptionW
= NULL
;
2120 LPWSTR MachineNameW
= NULL
;
2123 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassDescription
,
2124 ClassDescriptionSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
2126 if (ClassDescriptionSize
> 0)
2128 ClassDescriptionW
= MyMalloc(ClassDescriptionSize
* sizeof(WCHAR
));
2129 if (!ClassDescriptionW
)
2131 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2138 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
2141 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2146 ret
= SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescriptionW
,
2147 ClassDescriptionSize
* sizeof(WCHAR
), RequiredSize
, MachineNameW
, Reserved
);
2150 DWORD len
= (DWORD
)WideCharToMultiByte(CP_ACP
, 0, ClassDescriptionW
, -1, ClassDescription
,
2151 ClassDescriptionSize
, NULL
, NULL
);
2152 if (len
== 0 || len
> ClassDescriptionSize
)
2154 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2160 MyFree(ClassDescriptionW
);
2161 MyFree(MachineNameW
);
2165 /***********************************************************************
2166 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
2168 BOOL WINAPI
SetupDiGetClassDescriptionExW(
2169 const GUID
* ClassGuid
,
2170 PWSTR ClassDescription
,
2171 DWORD ClassDescriptionSize
,
2172 PDWORD RequiredSize
,
2181 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassDescription
,
2182 ClassDescriptionSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
2186 SetLastError(ERROR_INVALID_PARAMETER
);
2189 else if (!ClassDescription
&& ClassDescriptionSize
> 0)
2191 SetLastError(ERROR_INVALID_PARAMETER
);
2195 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
2200 if (hKey
== INVALID_HANDLE_VALUE
)
2202 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
2206 if (ClassDescriptionSize
< sizeof(UNICODE_NULL
) || !ClassDescription
)
2209 dwLength
= ClassDescriptionSize
* sizeof(WCHAR
) - sizeof(UNICODE_NULL
);
2211 rc
= RegQueryValueExW(hKey
,
2215 (LPBYTE
)ClassDescription
,
2218 if (rc
!= ERROR_MORE_DATA
&& rc
!= ERROR_SUCCESS
)
2223 else if (dwRegType
!= REG_SZ
)
2225 SetLastError(ERROR_GEN_FAILURE
);
2230 *RequiredSize
= dwLength
/ sizeof(WCHAR
) + 1;
2232 if (ClassDescriptionSize
* sizeof(WCHAR
) >= dwLength
+ sizeof(UNICODE_NULL
))
2234 if (ClassDescriptionSize
> sizeof(UNICODE_NULL
))
2235 ClassDescription
[ClassDescriptionSize
/ sizeof(WCHAR
)] = UNICODE_NULL
;
2240 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2245 /***********************************************************************
2246 * SetupDiGetClassDevsA (SETUPAPI.@)
2248 HDEVINFO WINAPI
SetupDiGetClassDevsA(
2254 return SetupDiGetClassDevsExA(class, enumstr
, parent
,
2255 flags
, NULL
, NULL
, NULL
);
2258 /***********************************************************************
2259 * SetupDiGetClassDevsExA (SETUPAPI.@)
2261 HDEVINFO WINAPI
SetupDiGetClassDevsExA(
2271 LPWSTR enumstrW
= NULL
, machineW
= NULL
;
2275 enumstrW
= MultiByteToUnicode(enumstr
, CP_ACP
);
2278 ret
= INVALID_HANDLE_VALUE
;
2284 machineW
= MultiByteToUnicode(machine
, CP_ACP
);
2288 ret
= INVALID_HANDLE_VALUE
;
2292 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, deviceset
,
2293 machineW
, reserved
);
2301 /***********************************************************************
2302 * SetupDiGetClassDevsW (SETUPAPI.@)
2304 HDEVINFO WINAPI
SetupDiGetClassDevsW(
2310 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2314 /***********************************************************************
2315 * SetupDiGetClassDevsExW (SETUPAPI.@)
2318 SETUP_CreateDevicesList(
2319 IN OUT
struct DeviceInfoSet
*list
,
2320 IN PCWSTR MachineName OPTIONAL
,
2321 IN CONST GUID
*Class OPTIONAL
,
2322 IN PCWSTR Enumerator OPTIONAL
);
2323 HDEVINFO WINAPI
SetupDiGetClassDevsExW(
2332 HDEVINFO hDeviceInfo
= INVALID_HANDLE_VALUE
;
2333 struct DeviceInfoSet
*list
;
2334 CONST GUID
*pClassGuid
;
2336 HDEVINFO set
= INVALID_HANDLE_VALUE
;
2338 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2339 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2342 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2344 SetLastError(ERROR_INVALID_PARAMETER
);
2348 /* Create the deviceset if not set */
2351 list
= (struct DeviceInfoSet
*)deviceset
;
2352 if (list
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2354 SetLastError(ERROR_INVALID_HANDLE
);
2357 hDeviceInfo
= deviceset
;
2361 hDeviceInfo
= SetupDiCreateDeviceInfoListExW(
2362 flags
& (DIGCF_DEVICEINTERFACE
| DIGCF_ALLCLASSES
) ? NULL
: class,
2363 NULL
, machine
, NULL
);
2364 if (hDeviceInfo
== INVALID_HANDLE_VALUE
)
2366 list
= (struct DeviceInfoSet
*)hDeviceInfo
;
2369 if (flags
& DIGCF_PROFILE
)
2370 FIXME(": flag DIGCF_PROFILE ignored\n");
2372 if (flags
& DIGCF_DEVICEINTERFACE
)
2376 SetLastError(ERROR_INVALID_PARAMETER
);
2379 rc
= SETUP_CreateInterfaceList(list
, machine
, class, enumstr
, flags
& DIGCF_PRESENT
);
2383 /* Determine which class(es) should be included in the deviceset */
2384 if (flags
& DIGCF_ALLCLASSES
)
2386 /* The caller wants all classes. Check if
2387 * the deviceset limits us to one class */
2388 if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2391 pClassGuid
= &list
->ClassGuid
;
2395 /* The caller wants one class. Check if it matches deviceset class */
2396 if (IsEqualIID(&list
->ClassGuid
, class)
2397 || IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2403 SetLastError(ERROR_INVALID_PARAMETER
);
2407 else if (!IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2409 /* No class specified. Try to use the one of the deviceset */
2410 if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2411 pClassGuid
= &list
->ClassGuid
;
2414 SetLastError(ERROR_INVALID_PARAMETER
);
2420 SetLastError(ERROR_INVALID_PARAMETER
);
2423 rc
= SETUP_CreateDevicesList(list
, machine
, pClassGuid
, enumstr
);
2425 if (rc
!= ERROR_SUCCESS
)
2433 if (!deviceset
&& hDeviceInfo
!= INVALID_HANDLE_VALUE
&& hDeviceInfo
!= set
)
2434 SetupDiDestroyDeviceInfoList(hDeviceInfo
);
2438 /***********************************************************************
2439 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2441 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2442 HDEVINFO DeviceInfoSet
,
2443 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2445 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2447 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2449 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2451 SetLastError(ERROR_INVALID_HANDLE
);
2454 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2456 SetLastError(ERROR_INVALID_HANDLE
);
2460 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2462 SetLastError(ERROR_INVALID_PARAMETER
);
2465 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2466 DevInfoData
->RemoteMachineHandle
= set
->hMachine
;
2467 if (set
->MachineName
)
2470 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2474 DevInfoData
->RemoteMachineName
[0] = 0;
2479 /***********************************************************************
2480 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2482 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2483 HDEVINFO DeviceInfoSet
,
2484 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2486 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2488 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2490 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2492 SetLastError(ERROR_INVALID_HANDLE
);
2495 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2497 SetLastError(ERROR_INVALID_HANDLE
);
2501 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2503 SetLastError(ERROR_INVALID_PARAMETER
);
2506 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2507 DevInfoData
->RemoteMachineHandle
= set
->hMachine
;
2508 if (set
->MachineName
)
2509 strcpyW(DevInfoData
->RemoteMachineName
, set
->MachineName
+ 2);
2511 DevInfoData
->RemoteMachineName
[0] = 0;
2516 /***********************************************************************
2517 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2519 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2520 HDEVINFO DeviceInfoSet
,
2521 PSP_DEVINFO_DATA DeviceInfoData
,
2522 const GUID
*InterfaceClassGuid
,
2523 PCSTR ReferenceString
,
2524 DWORD CreationFlags
,
2525 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2528 LPWSTR ReferenceStringW
= NULL
;
2530 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2531 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2532 CreationFlags
, DeviceInterfaceData
);
2534 if (ReferenceString
)
2536 ReferenceStringW
= MultiByteToUnicode(ReferenceString
, CP_ACP
);
2537 if (ReferenceStringW
== NULL
) return FALSE
;
2540 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2541 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2542 DeviceInterfaceData
);
2544 MyFree(ReferenceStringW
);
2549 /***********************************************************************
2550 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2552 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2553 HDEVINFO DeviceInfoSet
,
2554 PSP_DEVINFO_DATA DeviceInfoData
,
2555 const GUID
*InterfaceClassGuid
,
2556 PCWSTR ReferenceString
,
2557 DWORD CreationFlags
,
2558 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2560 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2561 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2562 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2563 CreationFlags
, DeviceInterfaceData
);
2565 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2567 SetLastError(ERROR_INVALID_HANDLE
);
2570 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2572 SetLastError(ERROR_INVALID_HANDLE
);
2575 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2576 || !DeviceInfoData
->Reserved
)
2578 SetLastError(ERROR_INVALID_PARAMETER
);
2581 if (!InterfaceClassGuid
)
2583 SetLastError(ERROR_INVALID_USER_BUFFER
);
2587 FIXME("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2588 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2589 CreationFlags
, DeviceInterfaceData
);
2590 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2594 /***********************************************************************
2595 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2597 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2598 HDEVINFO DeviceInfoSet
,
2599 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2603 PCSTR InfSectionName
)
2606 PWSTR InfSectionNameW
= NULL
;
2608 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2609 samDesired
, InfHandle
, InfSectionName
);
2612 if (!InfSectionName
)
2614 SetLastError(ERROR_INVALID_PARAMETER
);
2615 return INVALID_HANDLE_VALUE
;
2617 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2618 if (!InfSectionNameW
)
2619 return INVALID_HANDLE_VALUE
;
2621 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2622 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2624 MyFree(InfSectionNameW
);
2628 /***********************************************************************
2629 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2631 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2632 HDEVINFO DeviceInfoSet
,
2633 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2637 PCWSTR InfSectionName
)
2639 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2640 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2641 samDesired
, InfHandle
, InfSectionName
);
2643 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2644 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2646 SetLastError(ERROR_INVALID_HANDLE
);
2647 return INVALID_HANDLE_VALUE
;
2649 if (!DeviceInterfaceData
||
2650 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2651 !DeviceInterfaceData
->Reserved
)
2653 SetLastError(ERROR_INVALID_PARAMETER
);
2654 return INVALID_HANDLE_VALUE
;
2656 if (InfHandle
&& !InfSectionName
)
2658 SetLastError(ERROR_INVALID_PARAMETER
);
2659 return INVALID_HANDLE_VALUE
;
2662 FIXME("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2663 samDesired
, InfHandle
, InfSectionName
);
2664 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2665 return INVALID_HANDLE_VALUE
;
2668 /***********************************************************************
2669 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2671 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2672 HDEVINFO DeviceInfoSet
,
2673 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2676 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2679 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2681 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2682 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2684 SetLastError(ERROR_INVALID_HANDLE
);
2687 if (!DeviceInterfaceData
||
2688 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2689 !DeviceInterfaceData
->Reserved
)
2691 SetLastError(ERROR_INVALID_PARAMETER
);
2695 FIXME("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2696 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2700 /***********************************************************************
2701 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2704 * DeviceInfoSet [I] Set of devices from which to enumerate
2706 * DeviceInfoData [I] (Optional) If specified, a specific device
2707 * instance from which to enumerate interfaces.
2708 * If it isn't specified, all interfaces for all
2709 * devices in the set are enumerated.
2710 * InterfaceClassGuid [I] The interface class to enumerate.
2711 * MemberIndex [I] An index of the interface instance to enumerate.
2712 * A caller should start with MemberIndex set to 0,
2713 * and continue until the function fails with
2714 * ERROR_NO_MORE_ITEMS.
2715 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2716 * member must be set to
2717 * sizeof(SP_DEVICE_INTERFACE_DATA).
2720 * Success: non-zero value.
2721 * Failure: FALSE. Call GetLastError() for more info.
2723 BOOL WINAPI
SetupDiEnumDeviceInterfaces(
2724 HDEVINFO DeviceInfoSet
,
2725 PSP_DEVINFO_DATA DeviceInfoData
,
2726 CONST GUID
* InterfaceClassGuid
,
2728 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2730 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2733 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet
, DeviceInfoData
,
2734 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
2736 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2737 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2739 SetLastError(ERROR_INVALID_HANDLE
);
2742 if (DeviceInfoData
&& (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2743 !DeviceInfoData
->Reserved
))
2745 SetLastError(ERROR_INVALID_PARAMETER
);
2748 if (!DeviceInterfaceData
||
2749 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2751 SetLastError(ERROR_INVALID_PARAMETER
);
2756 struct DeviceInfo
*devInfo
=
2757 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2759 PLIST_ENTRY InterfaceListEntry
= devInfo
->InterfaceListHead
.Flink
;
2760 while (InterfaceListEntry
!= &devInfo
->InterfaceListHead
&& !found
)
2762 struct DeviceInterface
*DevItf
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
2763 if (!IsEqualIID(&DevItf
->InterfaceClassGuid
, InterfaceClassGuid
))
2765 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2768 if (MemberIndex
-- == 0)
2770 /* return this item */
2771 memcpy(&DeviceInterfaceData
->InterfaceClassGuid
,
2772 &DevItf
->InterfaceClassGuid
,
2774 DeviceInterfaceData
->Flags
= DevItf
->Flags
;
2775 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)DevItf
;
2779 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2782 SetLastError(ERROR_NO_MORE_ITEMS
);
2787 PLIST_ENTRY ItemList
= set
->ListHead
.Flink
;
2788 while (ItemList
!= &set
->ListHead
&& !found
)
2790 PLIST_ENTRY InterfaceListEntry
;
2791 struct DeviceInfo
*devInfo
=
2792 CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
2793 InterfaceListEntry
= devInfo
->InterfaceListHead
.Flink
;
2794 while (InterfaceListEntry
!= &devInfo
->InterfaceListHead
&& !found
)
2796 struct DeviceInterface
*DevItf
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
2797 if (!IsEqualIID(&DevItf
->InterfaceClassGuid
, InterfaceClassGuid
))
2799 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2802 if (MemberIndex
-- == 0)
2804 /* return this item */
2805 memcpy(&DeviceInterfaceData
->InterfaceClassGuid
,
2806 &DevItf
->InterfaceClassGuid
,
2808 DeviceInterfaceData
->Flags
= DevItf
->Flags
;
2809 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)DevItf
;
2813 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2815 ItemList
= ItemList
->Flink
;
2819 SetLastError(ERROR_NO_MORE_ITEMS
);
2824 /***********************************************************************
2825 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2827 * Destroy a DeviceInfoList and free all used memory of the list.
2830 * devinfo [I] DeviceInfoList pointer to list to destroy
2833 * Success: non zero value.
2834 * Failure: zero value.
2836 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
2840 TRACE("%p\n", devinfo
);
2841 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
2843 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
2845 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
2847 ret
= DestroyDeviceInfoSet(list
);
2852 SetLastError(ERROR_INVALID_HANDLE
);
2857 /***********************************************************************
2858 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2860 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
2861 HDEVINFO DeviceInfoSet
,
2862 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2863 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
2864 DWORD DeviceInterfaceDetailDataSize
,
2865 PDWORD RequiredSize
,
2866 PSP_DEVINFO_DATA DeviceInfoData
)
2868 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2869 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailDataW
= NULL
;
2870 DWORD sizeW
= 0, bytesNeeded
;
2873 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2874 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2875 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2877 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2878 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2880 SetLastError(ERROR_INVALID_HANDLE
);
2883 if (!DeviceInterfaceData
||
2884 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2885 !DeviceInterfaceData
->Reserved
)
2887 SetLastError(ERROR_INVALID_PARAMETER
);
2890 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
2891 FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + 1 ||
2892 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
)))
2894 SetLastError(ERROR_INVALID_USER_BUFFER
);
2897 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2899 SetLastError(ERROR_INVALID_USER_BUFFER
);
2904 if (DeviceInterfaceDetailData
!= NULL
)
2906 sizeW
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
2907 + (DeviceInterfaceDetailDataSize
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
)) * sizeof(WCHAR
);
2908 DeviceInterfaceDetailDataW
= (PSP_DEVICE_INTERFACE_DETAIL_DATA_W
)MyMalloc(sizeW
);
2909 if (!DeviceInterfaceDetailDataW
)
2911 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2914 if (!DeviceInterfaceDetailData
|| (DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataW
))
2916 DeviceInterfaceDetailDataW
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
);
2917 ret
= SetupDiGetDeviceInterfaceDetailW(
2919 DeviceInterfaceData
,
2920 DeviceInterfaceDetailDataW
,
2924 bytesNeeded
= (sizeW
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)) / sizeof(WCHAR
)
2925 + FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
);
2927 *RequiredSize
= bytesNeeded
;
2928 if (ret
&& DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
<= bytesNeeded
)
2930 if (!WideCharToMultiByte(
2932 DeviceInterfaceDetailDataW
->DevicePath
, -1,
2933 DeviceInterfaceDetailData
->DevicePath
, DeviceInterfaceDetailDataSize
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
2940 MyFree(DeviceInterfaceDetailDataW
);
2945 /***********************************************************************
2946 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2948 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
2949 HDEVINFO DeviceInfoSet
,
2950 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2951 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
2952 DWORD DeviceInterfaceDetailDataSize
,
2953 PDWORD RequiredSize
,
2954 PSP_DEVINFO_DATA DeviceInfoData
)
2956 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2959 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2960 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2961 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2963 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2964 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2966 SetLastError(ERROR_INVALID_HANDLE
);
2969 if (!DeviceInterfaceData
||
2970 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2971 !DeviceInterfaceData
->Reserved
)
2973 SetLastError(ERROR_INVALID_PARAMETER
);
2976 if (DeviceInterfaceDetailData
&& DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
))
2978 SetLastError(ERROR_INVALID_USER_BUFFER
);
2981 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2983 SetLastError(ERROR_INVALID_USER_BUFFER
);
2986 if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
2988 SetLastError(ERROR_INVALID_PARAMETER
);
2991 if (DeviceInterfaceDetailData
!= NULL
&& DeviceInterfaceDetailDataSize
< FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
))
2993 SetLastError(ERROR_INVALID_PARAMETER
);
2998 struct DeviceInterface
*deviceInterface
= (struct DeviceInterface
*)DeviceInterfaceData
->Reserved
;
2999 LPCWSTR devName
= deviceInterface
->SymbolicLink
;
3000 DWORD sizeRequired
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
) +
3001 (lstrlenW(devName
) + 1) * sizeof(WCHAR
);
3003 if (sizeRequired
> DeviceInterfaceDetailDataSize
)
3005 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3007 *RequiredSize
= sizeRequired
;
3011 strcpyW(DeviceInterfaceDetailData
->DevicePath
, devName
);
3012 TRACE("DevicePath is %s\n", debugstr_w(DeviceInterfaceDetailData
->DevicePath
));
3015 memcpy(&DeviceInfoData
->ClassGuid
,
3016 &deviceInterface
->DeviceInfo
->ClassGuid
,
3018 DeviceInfoData
->DevInst
= deviceInterface
->DeviceInfo
->dnDevInst
;
3019 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInterface
->DeviceInfo
;
3027 struct PropertyMapEntry
3034 static struct PropertyMapEntry PropertyMap
[] = {
3035 { REG_SZ
, "DeviceDesc", REGSTR_VAL_DEVDESC
},
3036 { REG_MULTI_SZ
, "HardwareId", REGSTR_VAL_HARDWAREID
},
3037 { REG_MULTI_SZ
, "CompatibleIDs", REGSTR_VAL_COMPATIBLEIDS
},
3038 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
3039 { REG_SZ
, "Service", REGSTR_VAL_SERVICE
},
3040 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
3041 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
3042 { REG_SZ
, "Class", REGSTR_VAL_CLASS
},
3043 { REG_SZ
, "ClassGUID", REGSTR_VAL_CLASSGUID
},
3044 { REG_SZ
, "Driver", REGSTR_VAL_DRIVER
},
3045 { REG_DWORD
, "ConfigFlags", REGSTR_VAL_CONFIGFLAGS
},
3046 { REG_SZ
, "Mfg", REGSTR_VAL_MFG
},
3047 { REG_SZ
, "FriendlyName", REGSTR_VAL_FRIENDLYNAME
},
3048 { REG_SZ
, "LocationInformation", REGSTR_VAL_LOCATION_INFORMATION
},
3049 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3050 { REG_DWORD
, "Capabilities", REGSTR_VAL_CAPABILITIES
},
3051 { REG_DWORD
, "UINumber", REGSTR_VAL_UI_NUMBER
},
3052 { REG_MULTI_SZ
, "UpperFilters", REGSTR_VAL_UPPERFILTERS
},
3053 { REG_MULTI_SZ
, "LowerFilters", REGSTR_VAL_LOWERFILTERS
},
3054 { 0, NULL
, NULL
}, /* SPDRP_BUSTYPEGUID */
3055 { 0, NULL
, NULL
}, /* SPDRP_LEGACYBUSTYPE */
3056 { 0, NULL
, NULL
}, /* SPDRP_BUSNUMBER */
3057 { 0, NULL
, NULL
}, /* SPDRP_ENUMERATOR_NAME */
3058 { REG_BINARY
, "Security", REGSTR_SECURITY
},
3059 { 0, NULL
, NULL
}, /* SPDRP_SECURITY_SDS */
3060 { 0, NULL
, NULL
}, /* SPDRP_DEVTYPE */
3061 { 0, NULL
, NULL
}, /* SPDRP_EXCLUSIVE */
3062 { 0, NULL
, NULL
}, /* SPDRP_CHARACTERISTICS */
3063 { 0, NULL
, NULL
}, /* SPDRP_ADDRESS */
3064 { REG_SZ
, "UINumberDescFormat", REGSTR_UI_NUMBER_DESC_FORMAT
},
3065 { 0, NULL
, NULL
}, /* SPDRP_DEVICE_POWER_DATA */
3066 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY */
3067 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY_HW_DEFAULT */
3068 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY_OVERRIDE */
3069 { 0, NULL
, NULL
}, /* SPDRP_INSTALL_STATE */
3072 /***********************************************************************
3073 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3075 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
3076 HDEVINFO DeviceInfoSet
,
3077 PSP_DEVINFO_DATA DeviceInfoData
,
3079 PDWORD PropertyRegDataType
,
3080 PBYTE PropertyBuffer
,
3081 DWORD PropertyBufferSize
,
3082 PDWORD RequiredSize
)
3085 BOOL bIsStringProperty
;
3087 DWORD RequiredSizeA
, RequiredSizeW
;
3088 DWORD PropertyBufferSizeW
= 0;
3089 PBYTE PropertyBufferW
= NULL
;
3091 TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
,
3092 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3095 if (PropertyBufferSize
!= 0)
3097 PropertyBufferSizeW
= PropertyBufferSize
* 2;
3098 PropertyBufferW
= HeapAlloc(GetProcessHeap(), 0, PropertyBufferSizeW
);
3099 if (!PropertyBufferW
)
3101 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3106 ret
= SetupDiGetDeviceRegistryPropertyW(
3112 PropertyBufferSizeW
,
3115 if (ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
3117 bIsStringProperty
= (RegType
== REG_SZ
|| RegType
== REG_MULTI_SZ
|| RegType
== REG_EXPAND_SZ
);
3119 if (bIsStringProperty
)
3120 RequiredSizeA
= RequiredSizeW
/ sizeof(WCHAR
);
3122 RequiredSizeA
= RequiredSizeW
;
3124 *RequiredSize
= RequiredSizeA
;
3125 if (PropertyRegDataType
)
3126 *PropertyRegDataType
= RegType
;
3131 HeapFree(GetProcessHeap(), 0, PropertyBufferW
);
3135 if (RequiredSizeA
<= PropertyBufferSize
)
3137 if (bIsStringProperty
&& PropertyBufferSize
> 0)
3139 if (WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)PropertyBufferW
, RequiredSizeW
/ sizeof(WCHAR
), (LPSTR
)PropertyBuffer
, PropertyBufferSize
, NULL
, NULL
) == 0)
3141 /* Last error is already set by WideCharToMultiByte */
3146 memcpy(PropertyBuffer
, PropertyBufferW
, RequiredSizeA
);
3150 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3154 HeapFree(GetProcessHeap(), 0, PropertyBufferW
);
3158 /***********************************************************************
3159 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3161 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3162 HDEVINFO DeviceInfoSet
,
3163 PSP_DEVINFO_DATA DeviceInfoData
,
3165 PDWORD PropertyRegDataType
,
3166 PBYTE PropertyBuffer
,
3167 DWORD PropertyBufferSize
,
3168 PDWORD RequiredSize
)
3171 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3172 struct DeviceInfo
*devInfo
;
3174 TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
,
3175 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3178 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3180 SetLastError(ERROR_INVALID_HANDLE
);
3183 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3185 SetLastError(ERROR_INVALID_HANDLE
);
3188 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3189 || !DeviceInfoData
->Reserved
)
3191 SetLastError(ERROR_INVALID_PARAMETER
);
3194 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3195 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3196 && PropertyMap
[Property
].nameW
)
3198 DWORD size
= PropertyBufferSize
;
3201 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_QUERY_VALUE
);
3202 if (hKey
== INVALID_HANDLE_VALUE
)
3204 l
= RegQueryValueExW(hKey
, PropertyMap
[Property
].nameW
,
3205 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3209 *RequiredSize
= size
;
3212 if (PropertyBuffer
!= NULL
|| size
== 0)
3215 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3217 case ERROR_MORE_DATA
:
3218 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3224 else if (Property
== SPDRP_PHYSICAL_DEVICE_OBJECT_NAME
)
3226 DWORD required
= (strlenW(devInfo
->Data
) + 1) * sizeof(WCHAR
);
3228 if (PropertyRegDataType
)
3229 *PropertyRegDataType
= REG_SZ
;
3231 *RequiredSize
= required
;
3232 if (PropertyBufferSize
>= required
)
3234 strcpyW((LPWSTR
)PropertyBuffer
, devInfo
->Data
);
3238 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3242 ERR("Property 0x%lx not implemented\n", Property
);
3243 SetLastError(ERROR_NOT_SUPPORTED
);
3248 /***********************************************************************
3249 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3251 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3252 HDEVINFO DeviceInfoSet
,
3253 PSP_DEVINFO_DATA DeviceInfoData
,
3255 const BYTE
*PropertyBuffer
,
3256 DWORD PropertyBufferSize
)
3259 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3261 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3262 PropertyBuffer
, PropertyBufferSize
);
3264 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3266 SetLastError(ERROR_INVALID_HANDLE
);
3269 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3271 SetLastError(ERROR_INVALID_HANDLE
);
3274 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3275 || !DeviceInfoData
->Reserved
)
3277 SetLastError(ERROR_INVALID_PARAMETER
);
3281 FIXME("%p %p 0x%lx %p 0x%lx\n", DeviceInfoSet
, DeviceInfoData
,
3282 Property
, PropertyBuffer
, PropertyBufferSize
);
3283 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3287 /***********************************************************************
3288 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3290 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
3291 HDEVINFO DeviceInfoSet
,
3292 PSP_DEVINFO_DATA DeviceInfoData
,
3294 const BYTE
*PropertyBuffer
,
3295 DWORD PropertyBufferSize
)
3298 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3300 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3301 PropertyBuffer
, PropertyBufferSize
);
3303 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3305 SetLastError(ERROR_INVALID_HANDLE
);
3308 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3310 SetLastError(ERROR_INVALID_HANDLE
);
3313 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3314 || !DeviceInfoData
->Reserved
)
3316 SetLastError(ERROR_INVALID_PARAMETER
);
3319 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3320 && PropertyMap
[Property
].nameW
)
3324 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_SET_VALUE
);
3325 if (hKey
== INVALID_HANDLE_VALUE
)
3327 /* Write new data */
3329 hKey
, PropertyMap
[Property
].nameW
, 0,
3330 PropertyMap
[Property
].regType
, PropertyBuffer
,
3331 PropertyBufferSize
);
3340 ERR("Property 0x%lx not implemented\n", Property
);
3341 SetLastError(ERROR_NOT_SUPPORTED
);
3344 TRACE("Returning %d\n", ret
);
3348 /***********************************************************************
3349 * SetupDiInstallClassA (SETUPAPI.@)
3351 BOOL WINAPI
SetupDiInstallClassA(
3357 return SetupDiInstallClassExA(hwndParent
, InfFileName
, Flags
, FileQueue
, NULL
, NULL
, NULL
);
3360 /***********************************************************************
3361 * SetupDiInstallClassExA (SETUPAPI.@)
3364 SetupDiInstallClassExA(
3365 IN HWND hwndParent OPTIONAL
,
3366 IN PCSTR InfFileName OPTIONAL
,
3368 IN HSPFILEQ FileQueue OPTIONAL
,
3369 IN CONST GUID
*InterfaceClassGuid OPTIONAL
,
3373 PWSTR InfFileNameW
= NULL
;
3378 InfFileNameW
= MultiByteToUnicode(InfFileName
, CP_ACP
);
3379 if (InfFileNameW
== NULL
)
3381 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3386 Result
= SetupDiInstallClassExW(hwndParent
, InfFileNameW
, Flags
,
3387 FileQueue
, InterfaceClassGuid
, Reserved1
, Reserved2
);
3389 MyFree(InfFileNameW
);
3394 HKEY
SETUP_CreateClassKey(HINF hInf
)
3396 static const WCHAR slash
[] = { '\\',0 };
3397 WCHAR FullBuffer
[MAX_PATH
];
3398 WCHAR Buffer
[MAX_PATH
];
3402 if (!SetupGetLineTextW(NULL
,
3410 return INVALID_HANDLE_VALUE
;
3413 lstrcpyW(FullBuffer
, REGSTR_PATH_CLASS_NT
);
3414 lstrcatW(FullBuffer
, slash
);
3415 lstrcatW(FullBuffer
, Buffer
);
3417 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3423 if (!SetupGetLineTextW(NULL
,
3431 return INVALID_HANDLE_VALUE
;
3434 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3438 REG_OPTION_NON_VOLATILE
,
3444 return INVALID_HANDLE_VALUE
;
3449 if (RegSetValueExW(hClassKey
,
3454 RequiredSize
* sizeof(WCHAR
)))
3456 RegCloseKey(hClassKey
);
3457 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3459 return INVALID_HANDLE_VALUE
;
3465 /***********************************************************************
3466 * SetupDiInstallClassW (SETUPAPI.@)
3468 BOOL WINAPI
SetupDiInstallClassW(
3474 return SetupDiInstallClassExW(hwndParent
, InfFileName
, Flags
, FileQueue
, NULL
, NULL
, NULL
);
3478 /***********************************************************************
3479 * SetupDiOpenClassRegKey (SETUPAPI.@)
3481 HKEY WINAPI
SetupDiOpenClassRegKey(
3482 const GUID
* ClassGuid
,
3485 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3486 DIOCR_INSTALLER
, NULL
, NULL
);
3490 /***********************************************************************
3491 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3493 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3494 const GUID
* ClassGuid
,
3500 PWSTR MachineNameW
= NULL
;
3503 TRACE("%s 0x%lx 0x%lx %s %p\n", debugstr_guid(ClassGuid
), samDesired
,
3504 Flags
, debugstr_a(MachineName
), Reserved
);
3508 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
3509 if (MachineNameW
== NULL
)
3510 return INVALID_HANDLE_VALUE
;
3513 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3514 Flags
, MachineNameW
, Reserved
);
3516 MyFree(MachineNameW
);
3522 /***********************************************************************
3523 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3525 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3526 const GUID
* ClassGuid
,
3538 TRACE("%s 0x%lx 0x%lx %s %p\n", debugstr_guid(ClassGuid
), samDesired
,
3539 Flags
, debugstr_w(MachineName
), Reserved
);
3541 if (MachineName
!= NULL
)
3543 l
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &HKLM
);
3544 if (l
!= ERROR_SUCCESS
)
3547 return INVALID_HANDLE_VALUE
;
3551 HKLM
= HKEY_LOCAL_MACHINE
;
3553 if (Flags
== DIOCR_INSTALLER
)
3555 lpKeyName
= REGSTR_PATH_CLASS_NT
;
3557 else if (Flags
== DIOCR_INTERFACE
)
3559 lpKeyName
= REGSTR_PATH_DEVICE_CLASSES
;
3563 ERR("Invalid Flags parameter!\n");
3564 SetLastError(ERROR_INVALID_PARAMETER
);
3565 if (MachineName
!= NULL
) RegCloseKey(HKLM
);
3566 return INVALID_HANDLE_VALUE
;
3571 if ((l
= RegOpenKeyExW(HKLM
,
3578 hClassesKey
= INVALID_HANDLE_VALUE
;
3580 if (MachineName
!= NULL
)
3586 WCHAR bracedGuidString
[39];
3588 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3590 if (!(l
= RegOpenKeyExW(HKLM
,
3596 if (MachineName
!= NULL
)
3599 if ((l
= RegOpenKeyExW(hClassesKey
,
3606 key
= INVALID_HANDLE_VALUE
;
3608 RegCloseKey(hClassesKey
);
3612 if (MachineName
!= NULL
) RegCloseKey(HKLM
);
3614 key
= INVALID_HANDLE_VALUE
;
3620 /***********************************************************************
3621 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3623 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3624 HDEVINFO DeviceInfoSet
,
3627 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3629 FIXME("%p %s %08x %p\n",
3630 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3634 /***********************************************************************
3635 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3637 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
3638 HDEVINFO DeviceInfoSet
,
3641 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3643 LPWSTR DevicePathW
= NULL
;
3646 TRACE("%p %s %08lx %p\n", DeviceInfoSet
, debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3648 DevicePathW
= MultiByteToUnicode(DevicePath
, CP_ACP
);
3649 if (DevicePathW
== NULL
)
3652 bResult
= SetupDiOpenDeviceInterfaceW(DeviceInfoSet
,
3653 DevicePathW
, OpenFlags
, DeviceInterfaceData
);
3655 MyFree(DevicePathW
);
3660 /***********************************************************************
3661 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3663 BOOL WINAPI
SetupDiSetClassInstallParamsA(
3664 HDEVINFO DeviceInfoSet
,
3665 PSP_DEVINFO_DATA DeviceInfoData
,
3666 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3667 DWORD ClassInstallParamsSize
)
3669 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3670 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3675 IntSetupDiRegisterDeviceInfo(
3676 IN HDEVINFO DeviceInfoSet
,
3677 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
3679 return SetupDiRegisterDeviceInfo(DeviceInfoSet
, DeviceInfoData
, 0, NULL
, NULL
, NULL
);
3682 /***********************************************************************
3683 * SetupDiCallClassInstaller (SETUPAPI.@)
3685 BOOL WINAPI
SetupDiCallClassInstaller(
3686 DI_FUNCTION InstallFunction
,
3687 HDEVINFO DeviceInfoSet
,
3688 PSP_DEVINFO_DATA DeviceInfoData
)
3692 TRACE("%u %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3695 SetLastError(ERROR_INVALID_PARAMETER
);
3696 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
3697 SetLastError(ERROR_INVALID_HANDLE
);
3698 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3699 SetLastError(ERROR_INVALID_HANDLE
);
3700 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->HKLM
!= HKEY_LOCAL_MACHINE
)
3701 SetLastError(ERROR_INVALID_HANDLE
);
3702 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
3703 SetLastError(ERROR_INVALID_USER_BUFFER
);
3706 SP_DEVINSTALL_PARAMS_W InstallParams
;
3707 #define CLASS_COINSTALLER 0x1
3708 #define DEVICE_COINSTALLER 0x2
3709 #define CLASS_INSTALLER 0x4
3710 UCHAR CanHandle
= 0;
3711 DEFAULT_CLASS_INSTALL_PROC DefaultHandler
= NULL
;
3713 switch (InstallFunction
)
3715 case DIF_ADDPROPERTYPAGE_ADVANCED
:
3716 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3718 case DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
3719 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3721 case DIF_ALLOW_INSTALL
:
3722 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3725 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3727 case DIF_DESTROYPRIVATEDATA
:
3728 CanHandle
= CLASS_INSTALLER
;
3730 case DIF_INSTALLDEVICE
:
3731 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3732 DefaultHandler
= SetupDiInstallDevice
;
3734 case DIF_INSTALLDEVICEFILES
:
3735 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3736 DefaultHandler
= SetupDiInstallDriverFiles
;
3738 case DIF_INSTALLINTERFACES
:
3739 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3740 DefaultHandler
= SetupDiInstallDeviceInterfaces
;
3742 case DIF_NEWDEVICEWIZARD_FINISHINSTALL
:
3743 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3745 case DIF_NEWDEVICEWIZARD_POSTANALYZE
:
3746 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3748 case DIF_NEWDEVICEWIZARD_PREANALYZE
:
3749 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3751 case DIF_NEWDEVICEWIZARD_PRESELECT
:
3752 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3754 case DIF_NEWDEVICEWIZARD_SELECT
:
3755 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3757 case DIF_POWERMESSAGEWAKE
:
3758 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3760 case DIF_PROPERTYCHANGE
:
3761 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3762 DefaultHandler
= SetupDiChangeState
;
3764 case DIF_REGISTER_COINSTALLERS
:
3765 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3766 DefaultHandler
= SetupDiRegisterCoDeviceInstallers
;
3768 case DIF_REGISTERDEVICE
:
3769 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3770 DefaultHandler
= IntSetupDiRegisterDeviceInfo
;
3773 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3774 DefaultHandler
= SetupDiRemoveDevice
;
3776 case DIF_SELECTBESTCOMPATDRV
:
3777 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3778 DefaultHandler
= SetupDiSelectBestCompatDrv
;
3780 case DIF_SELECTDEVICE
:
3781 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3782 DefaultHandler
= SetupDiSelectDevice
;
3784 case DIF_TROUBLESHOOTER
:
3785 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3788 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3789 DefaultHandler
= SetupDiUnremoveDevice
;
3792 ERR("Install function %u not supported\n", InstallFunction
);
3793 SetLastError(ERROR_NOT_SUPPORTED
);
3796 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
3797 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
))
3798 /* Don't process this call, as a parameter is invalid */
3803 LIST_ENTRY ClassCoInstallersListHead
;
3804 LIST_ENTRY DeviceCoInstallersListHead
;
3805 HMODULE ClassInstallerLibrary
= NULL
;
3806 CLASS_INSTALL_PROC ClassInstaller
= NULL
;
3807 COINSTALLER_CONTEXT_DATA Context
;
3808 PLIST_ENTRY ListEntry
;
3810 DWORD dwRegType
, dwLength
;
3811 DWORD rc
= NO_ERROR
;
3813 InitializeListHead(&ClassCoInstallersListHead
);
3814 InitializeListHead(&DeviceCoInstallersListHead
);
3816 if (CanHandle
& DEVICE_COINSTALLER
)
3818 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_QUERY_VALUE
);
3819 if (hKey
!= INVALID_HANDLE_VALUE
)
3821 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_COINSTALLERS_32
, NULL
, &dwRegType
, NULL
, &dwLength
);
3822 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_MULTI_SZ
)
3824 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
3825 if (KeyBuffer
!= NULL
)
3827 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_COINSTALLERS_32
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
3828 if (rc
== ERROR_SUCCESS
)
3831 for (ptr
= KeyBuffer
; *ptr
; ptr
+= strlenW(ptr
) + 1)
3833 /* Add coinstaller to DeviceCoInstallersListHead list */
3834 struct CoInstallerElement
*coinstaller
;
3835 TRACE("Got device coinstaller '%s'\n", debugstr_w(ptr
));
3836 coinstaller
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CoInstallerElement
));
3839 ZeroMemory(coinstaller
, sizeof(struct CoInstallerElement
));
3840 if (GetFunctionPointer(ptr
, &coinstaller
->Module
, (PVOID
*)&coinstaller
->Function
) == ERROR_SUCCESS
)
3841 InsertTailList(&DeviceCoInstallersListHead
, &coinstaller
->ListEntry
);
3843 HeapFree(GetProcessHeap(), 0, coinstaller
);
3846 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
3852 if (CanHandle
& CLASS_COINSTALLER
)
3856 REGSTR_PATH_CODEVICEINSTALLERS
,
3860 if (rc
== ERROR_SUCCESS
)
3862 LPWSTR lpGuidString
;
3863 if (UuidToStringW((UUID
*)&DeviceInfoData
->ClassGuid
, &lpGuidString
) == RPC_S_OK
)
3865 rc
= RegQueryValueExW(hKey
, lpGuidString
, NULL
, &dwRegType
, NULL
, &dwLength
);
3866 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_MULTI_SZ
)
3868 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
3869 if (KeyBuffer
!= NULL
)
3871 rc
= RegQueryValueExW(hKey
, lpGuidString
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
3872 if (rc
== ERROR_SUCCESS
)
3875 for (ptr
= KeyBuffer
; *ptr
; ptr
+= strlenW(ptr
) + 1)
3877 /* Add coinstaller to ClassCoInstallersListHead list */
3878 struct CoInstallerElement
*coinstaller
;
3879 TRACE("Got class coinstaller '%s'\n", debugstr_w(ptr
));
3880 coinstaller
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CoInstallerElement
));
3883 ZeroMemory(coinstaller
, sizeof(struct CoInstallerElement
));
3884 if (GetFunctionPointer(ptr
, &coinstaller
->Module
, (PVOID
*)&coinstaller
->Function
) == ERROR_SUCCESS
)
3885 InsertTailList(&ClassCoInstallersListHead
, &coinstaller
->ListEntry
);
3887 HeapFree(GetProcessHeap(), 0, coinstaller
);
3890 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
3893 RpcStringFreeW(&lpGuidString
);
3898 if ((CanHandle
& CLASS_INSTALLER
) && !(InstallParams
.FlagsEx
& DI_FLAGSEX_CI_FAILED
))
3900 hKey
= SetupDiOpenClassRegKey(&DeviceInfoData
->ClassGuid
, KEY_QUERY_VALUE
);
3901 if (hKey
!= INVALID_HANDLE_VALUE
)
3903 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_INSTALLER_32
, NULL
, &dwRegType
, NULL
, &dwLength
);
3904 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_SZ
)
3906 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
3907 if (KeyBuffer
!= NULL
)
3909 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_INSTALLER_32
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
3910 if (rc
== ERROR_SUCCESS
)
3912 /* Get ClassInstaller function pointer */
3913 TRACE("Got class installer '%s'\n", debugstr_w(KeyBuffer
));
3914 if (GetFunctionPointer(KeyBuffer
, &ClassInstallerLibrary
, (PVOID
*)&ClassInstaller
) != ERROR_SUCCESS
)
3916 InstallParams
.FlagsEx
|= DI_FLAGSEX_CI_FAILED
;
3917 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
3920 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
3927 /* Call Class co-installers */
3928 Context
.PostProcessing
= FALSE
;
3930 ListEntry
= ClassCoInstallersListHead
.Flink
;
3931 while (rc
== NO_ERROR
&& ListEntry
!= &ClassCoInstallersListHead
)
3933 struct CoInstallerElement
*coinstaller
;
3934 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
3935 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
3936 coinstaller
->PrivateData
= Context
.PrivateData
;
3937 if (rc
== ERROR_DI_POSTPROCESSING_REQUIRED
)
3939 coinstaller
->DoPostProcessing
= TRUE
;
3942 ListEntry
= ListEntry
->Flink
;
3945 /* Call Device co-installers */
3946 ListEntry
= DeviceCoInstallersListHead
.Flink
;
3947 while (rc
== NO_ERROR
&& ListEntry
!= &DeviceCoInstallersListHead
)
3949 struct CoInstallerElement
*coinstaller
;
3950 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
3951 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
3952 coinstaller
->PrivateData
= Context
.PrivateData
;
3953 if (rc
== ERROR_DI_POSTPROCESSING_REQUIRED
)
3955 coinstaller
->DoPostProcessing
= TRUE
;
3958 ListEntry
= ListEntry
->Flink
;
3961 /* Call Class installer */
3964 rc
= (*ClassInstaller
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3965 FreeFunctionPointer(ClassInstallerLibrary
, ClassInstaller
);
3968 rc
= ERROR_DI_DO_DEFAULT
;
3970 /* Call default handler */
3971 if (rc
== ERROR_DI_DO_DEFAULT
)
3973 if (DefaultHandler
&& !(InstallParams
.Flags
& DI_NODI_DEFAULTACTION
))
3975 if ((*DefaultHandler
)(DeviceInfoSet
, DeviceInfoData
))
3978 rc
= GetLastError();
3984 /* Call Class co-installers that required postprocessing */
3985 Context
.PostProcessing
= TRUE
;
3986 ListEntry
= ClassCoInstallersListHead
.Flink
;
3987 while (ListEntry
!= &ClassCoInstallersListHead
)
3989 struct CoInstallerElement
*coinstaller
;
3990 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
3991 if (coinstaller
->DoPostProcessing
)
3993 Context
.InstallResult
= rc
;
3994 Context
.PrivateData
= coinstaller
->PrivateData
;
3995 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
3997 FreeFunctionPointer(coinstaller
->Module
, coinstaller
->Function
);
3998 ListEntry
= ListEntry
->Flink
;
4001 /* Call Device co-installers that required postprocessing */
4002 ListEntry
= DeviceCoInstallersListHead
.Flink
;
4003 while (ListEntry
!= &DeviceCoInstallersListHead
)
4005 struct CoInstallerElement
*coinstaller
;
4006 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4007 if (coinstaller
->DoPostProcessing
)
4009 Context
.InstallResult
= rc
;
4010 Context
.PrivateData
= coinstaller
->PrivateData
;
4011 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4013 FreeFunctionPointer(coinstaller
->Module
, coinstaller
->Function
);
4014 ListEntry
= ListEntry
->Flink
;
4017 /* Free allocated memory */
4018 while (!IsListEmpty(&ClassCoInstallersListHead
))
4020 ListEntry
= RemoveHeadList(&ClassCoInstallersListHead
);
4021 HeapFree(GetProcessHeap(), 0, CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
));
4023 while (!IsListEmpty(&DeviceCoInstallersListHead
))
4025 ListEntry
= RemoveHeadList(&DeviceCoInstallersListHead
);
4026 HeapFree(GetProcessHeap(), 0, CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
));
4029 ret
= (rc
== NO_ERROR
);
4033 TRACE("Returning %d\n", ret
);
4037 /***********************************************************************
4038 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
4040 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
4041 HDEVINFO DeviceInfoSet
,
4042 PSP_DEVINFO_DATA DeviceInfoData
,
4043 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
4045 SP_DEVINSTALL_PARAMS_W deviceInstallParamsW
;
4048 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4050 if (DeviceInstallParams
== NULL
)
4051 SetLastError(ERROR_INVALID_PARAMETER
);
4052 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_A
))
4053 SetLastError(ERROR_INVALID_USER_BUFFER
);
4056 deviceInstallParamsW
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4057 ret
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &deviceInstallParamsW
);
4061 /* Do W->A conversion */
4063 DeviceInstallParams
,
4064 &deviceInstallParamsW
,
4065 FIELD_OFFSET(SP_DEVINSTALL_PARAMS_W
, DriverPath
));
4066 if (WideCharToMultiByte(CP_ACP
, 0, deviceInstallParamsW
.DriverPath
, -1,
4067 DeviceInstallParams
->DriverPath
, MAX_PATH
, NULL
, NULL
) == 0)
4069 DeviceInstallParams
->DriverPath
[0] = '\0';
4075 TRACE("Returning %d\n", ret
);
4079 /***********************************************************************
4080 * SetupDiGetDeviceInfoListClass (SETUPAPI.@)
4083 SetupDiGetDeviceInfoListClass(
4084 IN HDEVINFO DeviceInfoSet
,
4085 OUT LPGUID ClassGuid
)
4087 struct DeviceInfoSet
*list
;
4090 TRACE("%p %p\n", DeviceInfoSet
, ClassGuid
);
4093 SetLastError(ERROR_INVALID_HANDLE
);
4094 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4095 SetLastError(ERROR_INVALID_HANDLE
);
4096 else if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
4097 SetLastError(ERROR_NO_ASSOCIATED_CLASS
);
4100 memcpy(&ClassGuid
, &list
->ClassGuid
, sizeof(GUID
));
4105 TRACE("Returning %d\n", ret
);
4109 /***********************************************************************
4110 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
4113 SetupDiGetDeviceInstallParamsW(
4114 IN HDEVINFO DeviceInfoSet
,
4115 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4116 OUT PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4118 struct DeviceInfoSet
*list
;
4121 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4124 SetLastError(ERROR_INVALID_HANDLE
);
4125 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4126 SetLastError(ERROR_INVALID_HANDLE
);
4127 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4128 SetLastError(ERROR_INVALID_USER_BUFFER
);
4129 else if (!DeviceInstallParams
)
4130 SetLastError(ERROR_INVALID_PARAMETER
);
4131 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_W
))
4132 SetLastError(ERROR_INVALID_USER_BUFFER
);
4135 PSP_DEVINSTALL_PARAMS_W Source
;
4138 Source
= &((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->InstallParams
;
4140 Source
= &list
->InstallParams
;
4141 memcpy(DeviceInstallParams
, Source
, Source
->cbSize
);
4145 TRACE("Returning %d\n", ret
);
4150 CheckDeviceInstallParameters(
4151 IN PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4153 DWORD SupportedFlags
=
4154 DI_NOVCP
| /* 0x00000008 */
4155 DI_DIDCOMPAT
| /* 0x00000010 */
4156 DI_DIDCLASS
| /* 0x00000020 */
4157 DI_NEEDRESTART
| /* 0x00000080 */
4158 DI_NEEDREBOOT
| /* 0x00000100 */
4159 DI_RESOURCEPAGE_ADDED
| /* 0x00002000 */
4160 DI_PROPERTIES_CHANGE
| /* 0x00004000 */
4161 DI_ENUMSINGLEINF
| /* 0x00010000 */
4162 DI_DONOTCALLCONFIGMG
| /* 0x00020000 */
4163 DI_CLASSINSTALLPARAMS
| /* 0x00100000 */
4164 DI_NODI_DEFAULTACTION
| /* 0x00200000 */
4165 DI_QUIETINSTALL
| /* 0x00800000 */
4166 DI_NOFILECOPY
| /* 0x01000000 */
4167 DI_DRIVERPAGE_ADDED
; /* 0x04000000 */
4168 DWORD SupportedFlagsEx
=
4169 DI_FLAGSEX_CI_FAILED
| /* 0x00000004 */
4170 DI_FLAGSEX_DIDINFOLIST
| /* 0x00000010 */
4171 DI_FLAGSEX_DIDCOMPATINFO
| /* 0x00000020 */
4172 DI_FLAGSEX_ALLOWEXCLUDEDDRVS
| /* 0x00000800 */
4173 DI_FLAGSEX_NO_DRVREG_MODIFY
| /* 0x00008000 */
4174 DI_FLAGSEX_INSTALLEDDRIVER
; /* 0x04000000 */
4177 /* FIXME: add support for more flags */
4179 /* FIXME: DI_CLASSINSTALLPARAMS flag is not correctly used.
4180 * It should be checked before accessing to other values
4181 * of the SP_DEVINSTALL_PARAMS structure */
4183 if (DeviceInstallParams
->Flags
& ~SupportedFlags
)
4185 FIXME("Unknown Flags: 0x%08lx\n", DeviceInstallParams
->Flags
& ~SupportedFlags
);
4186 SetLastError(ERROR_INVALID_FLAGS
);
4188 else if (DeviceInstallParams
->FlagsEx
& ~SupportedFlagsEx
)
4190 FIXME("Unknown FlagsEx: 0x%08lx\n", DeviceInstallParams
->FlagsEx
& ~SupportedFlagsEx
);
4191 SetLastError(ERROR_INVALID_FLAGS
);
4193 else if ((DeviceInstallParams
->Flags
& DI_NOVCP
)
4194 && (DeviceInstallParams
->FileQueue
== NULL
|| DeviceInstallParams
->FileQueue
== (HSPFILEQ
)INVALID_HANDLE_VALUE
))
4195 SetLastError(ERROR_INVALID_USER_BUFFER
);
4198 /* FIXME: check Reserved field */
4205 /***********************************************************************
4206 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
4209 SetupDiSetDeviceInstallParamsW(
4210 IN HDEVINFO DeviceInfoSet
,
4211 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4212 IN PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4214 struct DeviceInfoSet
*list
;
4217 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4220 SetLastError(ERROR_INVALID_HANDLE
);
4221 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4222 SetLastError(ERROR_INVALID_HANDLE
);
4223 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4224 SetLastError(ERROR_INVALID_USER_BUFFER
);
4225 else if (!DeviceInstallParams
)
4226 SetLastError(ERROR_INVALID_PARAMETER
);
4227 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_W
))
4228 SetLastError(ERROR_INVALID_USER_BUFFER
);
4229 else if (CheckDeviceInstallParameters(DeviceInstallParams
))
4231 PSP_DEVINSTALL_PARAMS_W Destination
;
4234 Destination
= &((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->InstallParams
;
4236 Destination
= &list
->InstallParams
;
4237 memcpy(Destination
, DeviceInstallParams
, DeviceInstallParams
->cbSize
);
4241 TRACE("Returning %d\n", ret
);
4246 OpenHardwareProfileKey(
4249 IN DWORD samDesired
)
4251 HKEY hHWProfilesKey
= NULL
;
4252 HKEY hHWProfileKey
= NULL
;
4253 HKEY ret
= INVALID_HANDLE_VALUE
;
4256 rc
= RegOpenKeyExW(HKLM
,
4257 REGSTR_PATH_HWPROFILES
,
4261 if (rc
!= ERROR_SUCCESS
)
4278 snprintfW(subKey
, 4, InstanceKeyFormat
, HwProfile
);
4287 if (rc
!= ERROR_SUCCESS
)
4292 ret
= hHWProfileKey
;
4295 if (hHWProfilesKey
!= NULL
)
4296 RegCloseKey(hHWProfilesKey
);
4297 if (hHWProfileKey
!= NULL
&& hHWProfileKey
!= ret
)
4298 RegCloseKey(hHWProfileKey
);
4302 /***********************************************************************
4303 * SetupDiDeleteDeviceInfo (SETUPAPI.@)
4306 SetupDiDeleteDeviceInfo(
4307 IN HDEVINFO DeviceInfoSet
,
4308 IN PSP_DEVINFO_DATA DeviceInfoData
)
4310 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4312 FIXME("not implemented\n");
4313 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4318 /***********************************************************************
4319 * SetupDiOpenDeviceInfoA (SETUPAPI.@)
4322 SetupDiOpenDeviceInfoA(
4323 IN HDEVINFO DeviceInfoSet
,
4324 IN PCSTR DeviceInstanceId
,
4325 IN HWND hwndParent OPTIONAL
,
4327 OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4329 LPWSTR DeviceInstanceIdW
= NULL
;
4332 TRACE("%p %s %p %lx %p\n", DeviceInfoSet
, DeviceInstanceId
, hwndParent
, OpenFlags
, DeviceInfoData
);
4334 DeviceInstanceIdW
= MultiByteToUnicode(DeviceInstanceId
, CP_ACP
);
4335 if (DeviceInstanceIdW
== NULL
)
4338 bResult
= SetupDiOpenDeviceInfoW(DeviceInfoSet
,
4339 DeviceInstanceIdW
, hwndParent
, OpenFlags
, DeviceInfoData
);
4341 MyFree(DeviceInstanceIdW
);
4347 /***********************************************************************
4348 * SetupDiOpenDeviceInfoW (SETUPAPI.@)
4351 SetupDiOpenDeviceInfoW(
4352 IN HDEVINFO DeviceInfoSet
,
4353 IN PCWSTR DeviceInstanceId
,
4354 IN HWND hwndParent OPTIONAL
,
4356 OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4358 struct DeviceInfoSet
*list
;
4359 HKEY hEnumKey
, hKey
= NULL
;
4363 TRACE("%p %s %p %lx %p\n",
4364 DeviceInfoSet
, debugstr_w(DeviceInstanceId
),
4365 hwndParent
, OpenFlags
, DeviceInfoData
);
4367 if (OpenFlags
& DIOD_CANCEL_REMOVE
)
4368 FIXME("DIOD_CANCEL_REMOVE flag not implemented\n");
4371 SetLastError(ERROR_INVALID_HANDLE
);
4372 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4373 SetLastError(ERROR_INVALID_HANDLE
);
4374 else if (!DeviceInstanceId
)
4375 SetLastError(ERROR_INVALID_PARAMETER
);
4376 else if (OpenFlags
& ~(DIOD_CANCEL_REMOVE
| DIOD_INHERIT_CLASSDRVS
))
4378 TRACE("Unknown flags: 0x%08lx\n", OpenFlags
& ~(DIOD_CANCEL_REMOVE
| DIOD_INHERIT_CLASSDRVS
));
4379 SetLastError(ERROR_INVALID_FLAGS
);
4381 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4382 SetLastError(ERROR_INVALID_USER_BUFFER
);
4385 struct DeviceInfo
*deviceInfo
= NULL
;
4386 /* Search if device already exists in DeviceInfoSet.
4387 * If yes, return the existing element
4388 * If no, create a new element using information in registry
4390 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
4391 while (ItemList
!= &list
->ListHead
)
4396 FIXME("not implemented\n");
4397 ItemList
= ItemList
->Flink
;
4402 /* good one found */
4408 WCHAR szClassGuid
[MAX_GUID_STRING_LEN
];
4410 /* Open supposed registry key */
4413 REGSTR_PATH_SYSTEMENUM
,
4417 if (rc
!= ERROR_SUCCESS
)
4428 RegCloseKey(hEnumKey
);
4429 if (rc
!= ERROR_SUCCESS
)
4431 if (rc
== ERROR_FILE_NOT_FOUND
)
4432 rc
= ERROR_NO_SUCH_DEVINST
;
4437 ClassGUID
= GUID_NULL
;
4438 dwSize
= MAX_GUID_STRING_LEN
* sizeof(WCHAR
);
4440 if (RegQueryValueExW(hKey
,
4441 REGSTR_VAL_CLASSGUID
,
4444 (LPBYTE
)szClassGuid
,
4445 &dwSize
) == ERROR_SUCCESS
)
4447 szClassGuid
[MAX_GUID_STRING_LEN
- 2] = UNICODE_NULL
;
4449 /* Convert a string to a ClassGuid */
4450 UuidFromStringW(&szClassGuid
[1], &ClassGUID
);
4453 if (!CreateDeviceInfo(list
, DeviceInstanceId
, &ClassGUID
, &deviceInfo
))
4456 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
4461 if (ret
&& deviceInfo
&& DeviceInfoData
)
4463 memcpy(&DeviceInfoData
->ClassGuid
, &deviceInfo
->ClassGuid
, sizeof(GUID
));
4464 DeviceInfoData
->DevInst
= deviceInfo
->dnDevInst
;
4465 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInfo
;
4476 /***********************************************************************
4477 * SetupDiGetSelectedDevice (SETUPAPI.@)
4480 SetupDiGetSelectedDevice(
4481 IN HDEVINFO DeviceInfoSet
,
4482 OUT PSP_DEVINFO_DATA DeviceInfoData
)
4484 struct DeviceInfoSet
*list
;
4487 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4490 SetLastError(ERROR_INVALID_HANDLE
);
4491 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4492 SetLastError(ERROR_INVALID_HANDLE
);
4493 else if (list
->SelectedDevice
== NULL
)
4494 SetLastError(ERROR_NO_DEVICE_SELECTED
);
4495 else if (!DeviceInfoData
)
4496 SetLastError(ERROR_INVALID_PARAMETER
);
4497 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4498 SetLastError(ERROR_INVALID_USER_BUFFER
);
4501 memcpy(&DeviceInfoData
->ClassGuid
,
4502 &list
->SelectedDevice
->ClassGuid
,
4504 DeviceInfoData
->DevInst
= list
->SelectedDevice
->dnDevInst
;
4505 DeviceInfoData
->Reserved
= (ULONG_PTR
)list
->SelectedDevice
;
4509 TRACE("Returning %d\n", ret
);
4514 /***********************************************************************
4515 * SetupDiSetSelectedDevice (SETUPAPI.@)
4518 SetupDiSetSelectedDevice(
4519 IN HDEVINFO DeviceInfoSet
,
4520 IN PSP_DEVINFO_DATA DeviceInfoData
)
4522 struct DeviceInfoSet
*list
;
4525 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4528 SetLastError(ERROR_INVALID_HANDLE
);
4529 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4530 SetLastError(ERROR_INVALID_HANDLE
);
4531 else if (!DeviceInfoData
)
4532 SetLastError(ERROR_INVALID_PARAMETER
);
4533 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4534 SetLastError(ERROR_INVALID_USER_BUFFER
);
4535 else if (DeviceInfoData
->Reserved
== 0)
4536 SetLastError(ERROR_INVALID_USER_BUFFER
);
4539 list
->SelectedDevice
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
4543 TRACE("Returning %d\n", ret
);
4548 /* Return the current hardware profile id, or -1 if error */
4550 SETUPAPI_GetCurrentHwProfile(
4551 IN HDEVINFO DeviceInfoSet
)
4554 DWORD dwRegType
, dwLength
;
4557 DWORD ret
= (DWORD
)-1;
4560 ((struct DeviceInfoSet
*)DeviceInfoSet
)->HKLM
,
4561 REGSTR_PATH_IDCONFIGDB
,
4565 if (rc
!= ERROR_SUCCESS
)
4571 dwLength
= sizeof(DWORD
);
4572 rc
= RegQueryValueExW(
4574 REGSTR_VAL_CURRENTCONFIG
,
4577 (LPBYTE
)&hwProfile
, &dwLength
);
4578 if (rc
!= ERROR_SUCCESS
)
4583 else if (dwRegType
!= REG_DWORD
|| dwLength
!= sizeof(DWORD
))
4585 SetLastError(ERROR_GEN_FAILURE
);
4600 IN HDEVINFO DeviceInfoSet
,
4601 IN PSP_DEVINFO_DATA DeviceInfoData
)
4604 PLUGPLAY_CONTROL_RESET_DEVICE_DATA ResetDeviceData
;
4605 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
4608 if (((struct DeviceInfoSet
*)DeviceInfoSet
)->HKLM
!= HKEY_LOCAL_MACHINE
)
4610 /* At the moment, I only know how to start local devices */
4611 SetLastError(ERROR_INVALID_COMPUTERNAME
);
4615 RtlInitUnicodeString(&ResetDeviceData
.DeviceInstance
, deviceInfo
->instanceId
);
4616 Status
= NtPlugPlayControl(PlugPlayControlResetDevice
, &ResetDeviceData
, sizeof(PLUGPLAY_CONTROL_RESET_DEVICE_DATA
));
4617 SetLastError(RtlNtStatusToDosError(Status
));
4618 return NT_SUCCESS(Status
);
4620 FIXME("Stub: ResetDevice(%p %p)\n", DeviceInfoSet
, DeviceInfoData
);
4625 static BOOL
StopDevice(
4626 IN HDEVINFO DeviceInfoSet
,
4627 IN PSP_DEVINFO_DATA DeviceInfoData
)
4629 FIXME("Stub: StopDevice(%p %p)\n", DeviceInfoSet
, DeviceInfoData
);
4633 /***********************************************************************
4634 * SetupDiChangeState (SETUPAPI.@)
4638 IN HDEVINFO DeviceInfoSet
,
4639 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
4641 PSP_PROPCHANGE_PARAMS PropChange
;
4642 HKEY hKey
= INVALID_HANDLE_VALUE
;
4643 LPCWSTR RegistryValueName
;
4644 DWORD dwConfigFlags
, dwLength
, dwRegType
;
4648 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4650 if (!DeviceInfoData
)
4651 PropChange
= ((struct DeviceInfoSet
*)DeviceInfoSet
)->ClassInstallParams
.PropChangeParams
;
4653 PropChange
= ((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->ClassInstallParams
.PropChangeParams
;
4656 SetLastError(ERROR_INVALID_PARAMETER
);
4660 if (PropChange
->Scope
== DICS_FLAG_GLOBAL
)
4661 RegistryValueName
= REGSTR_VAL_CONFIGFLAGS
;
4663 RegistryValueName
= REGSTR_VAL_CSCONFIGFLAGS
;
4665 switch (PropChange
->StateChange
)
4670 /* Enable/disable device in registry */
4671 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, PropChange
->Scope
, PropChange
->HwProfile
, DIREG_DEV
, KEY_QUERY_VALUE
| KEY_SET_VALUE
);
4672 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
4673 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, PropChange
->Scope
, PropChange
->HwProfile
, DIREG_DEV
, NULL
, NULL
);
4674 if (hKey
== INVALID_HANDLE_VALUE
)
4676 dwLength
= sizeof(DWORD
);
4677 rc
= RegQueryValueExW(
4682 (LPBYTE
)&dwConfigFlags
, &dwLength
);
4683 if (rc
== ERROR_FILE_NOT_FOUND
)
4685 else if (rc
!= ERROR_SUCCESS
)
4690 else if (dwRegType
!= REG_DWORD
|| dwLength
!= sizeof(DWORD
))
4692 SetLastError(ERROR_GEN_FAILURE
);
4695 if (PropChange
->StateChange
== DICS_ENABLE
)
4696 dwConfigFlags
&= ~(PropChange
->Scope
== DICS_FLAG_GLOBAL
? CONFIGFLAG_DISABLED
: CSCONFIGFLAG_DISABLED
);
4698 dwConfigFlags
|= (PropChange
->Scope
== DICS_FLAG_GLOBAL
? CONFIGFLAG_DISABLED
: CSCONFIGFLAG_DISABLED
);
4699 rc
= RegSetValueExW(
4704 (LPBYTE
)&dwConfigFlags
, sizeof(DWORD
));
4705 if (rc
!= ERROR_SUCCESS
)
4711 /* Enable/disable device if needed */
4712 if (PropChange
->Scope
== DICS_FLAG_GLOBAL
4713 || PropChange
->HwProfile
== 0
4714 || PropChange
->HwProfile
== SETUPAPI_GetCurrentHwProfile(DeviceInfoSet
))
4716 if (PropChange
->StateChange
== DICS_ENABLE
)
4717 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
4719 ret
= StopDevice(DeviceInfoSet
, DeviceInfoData
);
4725 case DICS_PROPCHANGE
:
4727 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
4732 ERR("Unknown StateChange 0x%lx\n", PropChange
->StateChange
);
4733 SetLastError(ERROR_NOT_SUPPORTED
);
4738 if (hKey
!= INVALID_HANDLE_VALUE
)
4741 TRACE("Returning %d\n", ret
);
4745 /***********************************************************************
4746 * SetupDiSelectDevice (SETUPAPI.@)
4749 SetupDiSelectDevice(
4750 IN HDEVINFO DeviceInfoSet
,
4751 IN OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4753 FIXME("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4754 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4759 /***********************************************************************
4760 * SetupDiRegisterCoDeviceInstallers (SETUPAPI.@)
4763 SetupDiRegisterCoDeviceInstallers(
4764 IN HDEVINFO DeviceInfoSet
,
4765 IN PSP_DEVINFO_DATA DeviceInfoData
)
4767 BOOL ret
= FALSE
; /* Return value */
4769 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4772 SetLastError(ERROR_INVALID_PARAMETER
);
4773 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
4774 SetLastError(ERROR_INVALID_HANDLE
);
4775 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4776 SetLastError(ERROR_INVALID_HANDLE
);
4777 else if (!DeviceInfoData
)
4778 SetLastError(ERROR_INVALID_PARAMETER
);
4779 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4780 SetLastError(ERROR_INVALID_USER_BUFFER
);
4783 SP_DEVINSTALL_PARAMS_W InstallParams
;
4784 struct DriverInfoElement
*SelectedDriver
;
4787 WCHAR SectionName
[MAX_PATH
];
4788 DWORD SectionNameLength
= 0;
4789 HKEY hKey
= INVALID_HANDLE_VALUE
;
4790 PVOID Context
= NULL
;
4792 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4793 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
4797 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
4798 if (SelectedDriver
== NULL
)
4800 SetLastError(ERROR_NO_DRIVER_SELECTED
);
4804 /* Get .CoInstallers section name */
4805 Result
= SetupDiGetActualSectionToInstallW(
4806 SelectedDriver
->InfFileDetails
->hInf
,
4807 SelectedDriver
->Details
.SectionName
,
4808 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
4809 if (!Result
|| SectionNameLength
> MAX_PATH
- strlenW(DotCoInstallers
) - 1)
4811 lstrcatW(SectionName
, DotCoInstallers
);
4813 /* Open/Create driver key information */
4814 #if _WIN32_WINNT >= 0x502
4815 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_READ
| KEY_WRITE
);
4817 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_ALL_ACCESS
);
4819 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
4820 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, NULL
, NULL
);
4821 if (hKey
== INVALID_HANDLE_VALUE
)
4824 /* Install .CoInstallers section */
4825 DoAction
= SPINST_REGISTRY
;
4826 if (!(InstallParams
.Flags
& DI_NOFILECOPY
))
4828 DoAction
|= SPINST_FILES
;
4829 Context
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
4833 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
4834 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
4835 DoAction
, hKey
, SelectedDriver
->InfFileDetails
->DirectoryName
, SP_COPY_NEWER
,
4836 SetupDefaultQueueCallbackW
, Context
,
4837 DeviceInfoSet
, DeviceInfoData
);
4845 SetupTermDefaultQueueCallback(Context
);
4846 if (hKey
!= INVALID_HANDLE_VALUE
)
4850 TRACE("Returning %d\n", ret
);
4855 InfIsFromOEMLocation(
4857 OUT LPBOOL IsOEMLocation
)
4861 last
= strrchrW(FullName
, '\\');
4864 /* No directory specified */
4865 *IsOEMLocation
= FALSE
;
4872 Windir
= MyMalloc((MAX_PATH
+ 1 + strlenW(InfDirectory
)) * sizeof(WCHAR
));
4875 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4879 ret
= GetSystemWindowsDirectoryW(Windir
, MAX_PATH
);
4880 if (ret
== 0 || ret
> MAX_PATH
)
4883 SetLastError(ERROR_GEN_FAILURE
);
4886 if (*Windir
&& Windir
[strlenW(Windir
) - 1] != '\\')
4887 strcatW(Windir
, BackSlash
);
4888 strcatW(Windir
, InfDirectory
);
4890 if (strncmpiW(FullName
, Windir
, last
- FullName
) == 0)
4892 /* The path is %SYSTEMROOT%\Inf */
4893 *IsOEMLocation
= FALSE
;
4897 /* The file is in another place */
4898 *IsOEMLocation
= TRUE
;
4905 /***********************************************************************
4906 * SetupDiInstallDevice (SETUPAPI.@)
4909 SetupDiInstallDevice(
4910 IN HDEVINFO DeviceInfoSet
,
4911 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
4913 SP_DEVINSTALL_PARAMS_W InstallParams
;
4914 struct DriverInfoElement
*SelectedDriver
;
4915 SYSTEMTIME DriverDate
;
4916 WCHAR SectionName
[MAX_PATH
];
4918 DWORD SectionNameLength
= 0;
4919 BOOL Result
= FALSE
;
4922 LPWSTR pSectionName
= NULL
;
4923 WCHAR ClassName
[MAX_CLASS_NAME_LEN
];
4925 LPWSTR lpGuidString
= NULL
, lpFullGuidString
= NULL
;
4926 BOOL RebootRequired
= FALSE
;
4927 HKEY hKey
= INVALID_HANDLE_VALUE
;
4928 BOOL NeedtoCopyFile
;
4929 LARGE_INTEGER fullVersion
;
4931 PVOID Context
= NULL
;
4932 BOOL ret
= FALSE
; /* Return value */
4934 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4937 SetLastError(ERROR_INVALID_PARAMETER
);
4938 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
4939 SetLastError(ERROR_INVALID_HANDLE
);
4940 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4941 SetLastError(ERROR_INVALID_HANDLE
);
4942 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4943 SetLastError(ERROR_INVALID_USER_BUFFER
);
4949 /* One parameter is bad */
4953 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4954 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
4958 if (InstallParams
.FlagsEx
& DI_FLAGSEX_SETFAILEDINSTALL
)
4960 /* Set FAILEDINSTALL in ConfigFlags registry value */
4961 DWORD ConfigFlags
, regType
;
4962 Result
= SetupDiGetDeviceRegistryPropertyW(
4967 (PBYTE
)&ConfigFlags
,
4968 sizeof(ConfigFlags
),
4970 if (!Result
|| regType
!= REG_DWORD
)
4972 SetLastError(ERROR_GEN_FAILURE
);
4975 ConfigFlags
|= DNF_DISABLED
;
4976 Result
= SetupDiSetDeviceRegistryPropertyW(
4980 (PBYTE
)&ConfigFlags
,
4981 sizeof(ConfigFlags
));
4984 SetLastError(ERROR_GEN_FAILURE
);
4992 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
4993 if (SelectedDriver
== NULL
)
4995 SetLastError(ERROR_NO_DRIVER_SELECTED
);
4999 FileTimeToSystemTime(&SelectedDriver
->Info
.DriverDate
, &DriverDate
);
5001 Result
= SetupDiGetActualSectionToInstallW(
5002 SelectedDriver
->InfFileDetails
->hInf
,
5003 SelectedDriver
->Details
.SectionName
,
5004 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
5005 if (!Result
|| SectionNameLength
> MAX_PATH
- strlenW(DotServices
))
5007 pSectionName
= &SectionName
[strlenW(SectionName
)];
5009 /* Get information from [Version] section */
5010 if (!SetupDiGetINFClassW(SelectedDriver
->Details
.InfFileName
, &ClassGuid
, ClassName
, MAX_CLASS_NAME_LEN
, &RequiredSize
))
5012 /* Format ClassGuid to a string */
5013 if (UuidToStringW((UUID
*)&ClassGuid
, &lpGuidString
) != RPC_S_OK
)
5015 RequiredSize
= lstrlenW(lpGuidString
);
5016 lpFullGuidString
= HeapAlloc(GetProcessHeap(), 0, (RequiredSize
+ 3) * sizeof(WCHAR
));
5017 if (!lpFullGuidString
)
5019 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5022 lpFullGuidString
[0] = '{';
5023 memcpy(&lpFullGuidString
[1], lpGuidString
, RequiredSize
* sizeof(WCHAR
));
5024 lpFullGuidString
[RequiredSize
+ 1] = '}';
5025 lpFullGuidString
[RequiredSize
+ 2] = '\0';
5027 /* Copy .inf file to Inf\ directory (if needed) */
5028 Result
= InfIsFromOEMLocation(SelectedDriver
->Details
.InfFileName
, &NeedtoCopyFile
);
5033 WCHAR NewFileName
[MAX_PATH
];
5034 struct InfFileDetails
*newInfFileDetails
;
5035 Result
= SetupCopyOEMInfW(
5036 SelectedDriver
->Details
.InfFileName
,
5039 SP_COPY_NOOVERWRITE
,
5040 NewFileName
, MAX_PATH
,
5045 /* Create a new struct InfFileDetails, and set it to
5046 * SelectedDriver->InfFileDetails, to release use of
5047 * current InfFile */
5048 newInfFileDetails
= CreateInfFileDetails(NewFileName
);
5049 if (!newInfFileDetails
)
5051 DereferenceInfFile(SelectedDriver
->InfFileDetails
);
5052 SelectedDriver
->InfFileDetails
= newInfFileDetails
;
5053 strcpyW(SelectedDriver
->Details
.InfFileName
, NewFileName
);
5056 /* Open/Create driver key information */
5057 #if _WIN32_WINNT >= 0x502
5058 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_READ
| KEY_WRITE
);
5060 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_ALL_ACCESS
);
5062 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5063 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, NULL
, NULL
);
5064 if (hKey
== INVALID_HANDLE_VALUE
)
5067 /* Install main section */
5069 if (!(InstallParams
.FlagsEx
& DI_FLAGSEX_NO_DRVREG_MODIFY
))
5070 DoAction
|= SPINST_REGISTRY
;
5071 if (!(InstallParams
.Flags
& DI_NOFILECOPY
))
5073 DoAction
|= SPINST_FILES
;
5074 Context
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
5078 *pSectionName
= '\0';
5079 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5080 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5081 DoAction
, hKey
, SelectedDriver
->InfFileDetails
->DirectoryName
, SP_COPY_NEWER
,
5082 SetupDefaultQueueCallbackW
, Context
,
5083 DeviceInfoSet
, DeviceInfoData
);
5086 InstallParams
.Flags
|= DI_NOFILECOPY
;
5087 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5089 /* Write information to driver key */
5090 *pSectionName
= UNICODE_NULL
;
5091 memcpy(&fullVersion
, &SelectedDriver
->Info
.DriverVersion
, sizeof(LARGE_INTEGER
));
5092 TRACE("Write information to driver key\n");
5093 TRACE("DriverDate : '%u-%u-%u'\n", DriverDate
.wMonth
, DriverDate
.wDay
, DriverDate
.wYear
);
5094 TRACE("DriverDesc : '%s'\n", debugstr_w(SelectedDriver
->Info
.Description
));
5095 TRACE("DriverVersion : '%ld.%ld.%lu.%ld'\n", fullVersion
.HighPart
>> 16, fullVersion
.HighPart
& 0xffff, fullVersion
.LowPart
>> 16, fullVersion
.LowPart
& 0xffff);
5096 TRACE("InfPath : '%s'\n", debugstr_w(SelectedDriver
->InfFileDetails
->FileName
));
5097 TRACE("InfSection : '%s'\n", debugstr_w(SelectedDriver
->Details
.SectionName
));
5098 TRACE("InfSectionExt : '%s'\n", debugstr_w(&SectionName
[strlenW(SelectedDriver
->Details
.SectionName
)]));
5099 TRACE("MatchingDeviceId: '%s'\n", debugstr_w(SelectedDriver
->MatchingId
));
5100 TRACE("ProviderName : '%s'\n", debugstr_w(SelectedDriver
->Info
.ProviderName
));
5101 sprintfW(Buffer
, DateFormat
, DriverDate
.wMonth
, DriverDate
.wDay
, DriverDate
.wYear
);
5102 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_DATE
, 0, REG_SZ
, (const BYTE
*)Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
));
5103 if (rc
== ERROR_SUCCESS
)
5104 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_DATE_DATA
, 0, REG_BINARY
, (const BYTE
*)&SelectedDriver
->Info
.DriverDate
, sizeof(FILETIME
));
5105 if (rc
== ERROR_SUCCESS
)
5106 rc
= RegSetValueExW(hKey
, REGSTR_VAL_DRVDESC
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.Description
, (strlenW(SelectedDriver
->Info
.Description
) + 1) * sizeof(WCHAR
));
5107 if (rc
== ERROR_SUCCESS
)
5109 sprintfW(Buffer
, VersionFormat
, fullVersion
.HighPart
>> 16, fullVersion
.HighPart
& 0xffff, fullVersion
.LowPart
>> 16, fullVersion
.LowPart
& 0xffff);
5110 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_VERSION
, 0, REG_SZ
, (const BYTE
*)Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
));
5112 if (rc
== ERROR_SUCCESS
)
5113 rc
= RegSetValueExW(hKey
, REGSTR_VAL_INFPATH
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->InfFileDetails
->FileName
, (strlenW(SelectedDriver
->InfFileDetails
->FileName
) + 1) * sizeof(WCHAR
));
5114 if (rc
== ERROR_SUCCESS
)
5115 rc
= RegSetValueExW(hKey
, REGSTR_VAL_INFSECTION
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Details
.SectionName
, (strlenW(SelectedDriver
->Details
.SectionName
) + 1) * sizeof(WCHAR
));
5116 if (rc
== ERROR_SUCCESS
)
5117 rc
= RegSetValueExW(hKey
, REGSTR_VAL_INFSECTIONEXT
, 0, REG_SZ
, (const BYTE
*)&SectionName
[strlenW(SelectedDriver
->Details
.SectionName
)], (strlenW(SectionName
) - strlenW(SelectedDriver
->Details
.SectionName
) + 1) * sizeof(WCHAR
));
5118 if (rc
== ERROR_SUCCESS
)
5119 rc
= RegSetValueExW(hKey
, REGSTR_VAL_MATCHINGDEVID
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->MatchingId
, (strlenW(SelectedDriver
->MatchingId
) + 1) * sizeof(WCHAR
));
5120 if (rc
== ERROR_SUCCESS
)
5121 rc
= RegSetValueExW(hKey
, REGSTR_VAL_PROVIDER_NAME
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.ProviderName
, (strlenW(SelectedDriver
->Info
.ProviderName
) + 1) * sizeof(WCHAR
));
5122 if (rc
!= ERROR_SUCCESS
)
5128 hKey
= INVALID_HANDLE_VALUE
;
5130 /* FIXME: Process .LogConfigOverride section */
5132 /* Install .Services section */
5133 strcpyW(pSectionName
, DotServices
);
5134 Result
= SetupInstallServicesFromInfSectionExW(
5135 SelectedDriver
->InfFileDetails
->hInf
,
5144 if (GetLastError() == ERROR_SUCCESS_REBOOT_REQUIRED
)
5145 RebootRequired
= TRUE
;
5147 /* Open device registry key */
5148 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_SET_VALUE
);
5149 if (hKey
== INVALID_HANDLE_VALUE
)
5152 /* Install .HW section */
5154 if (!(InstallParams
.FlagsEx
& DI_FLAGSEX_NO_DRVREG_MODIFY
))
5155 DoAction
|= SPINST_REGISTRY
;
5156 strcpyW(pSectionName
, DotHW
);
5157 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5158 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5159 DoAction
, hKey
, NULL
, 0,
5161 DeviceInfoSet
, DeviceInfoData
);
5165 /* Write information to enum key */
5166 TRACE("Write information to enum key\n");
5167 TRACE("Class : '%s'\n", debugstr_w(ClassName
));
5168 TRACE("ClassGUID : '%s'\n", debugstr_w(lpFullGuidString
));
5169 TRACE("DeviceDesc : '%s'\n", debugstr_w(SelectedDriver
->Info
.Description
));
5170 TRACE("Mfg : '%s'\n", debugstr_w(SelectedDriver
->Info
.MfgName
));
5171 rc
= RegSetValueExW(hKey
, REGSTR_VAL_CLASS
, 0, REG_SZ
, (const BYTE
*)ClassName
, (strlenW(ClassName
) + 1) * sizeof(WCHAR
));
5172 if (rc
== ERROR_SUCCESS
)
5173 rc
= RegSetValueExW(hKey
, REGSTR_VAL_CLASSGUID
, 0, REG_SZ
, (const BYTE
*)lpFullGuidString
, (strlenW(lpFullGuidString
) + 1) * sizeof(WCHAR
));
5174 if (rc
== ERROR_SUCCESS
)
5175 rc
= RegSetValueExW(hKey
, REGSTR_VAL_DEVDESC
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.Description
, (strlenW(SelectedDriver
->Info
.Description
) + 1) * sizeof(WCHAR
));
5176 if (rc
== ERROR_SUCCESS
)
5177 rc
= RegSetValueExW(hKey
, REGSTR_VAL_MFG
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.MfgName
, (strlenW(SelectedDriver
->Info
.MfgName
) + 1) * sizeof(WCHAR
));
5178 if (rc
!= ERROR_SUCCESS
)
5184 /* Start the device */
5185 if (!RebootRequired
&& !(InstallParams
.Flags
& (DI_NEEDRESTART
| DI_NEEDREBOOT
| DI_DONOTCALLCONFIGMG
)))
5186 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
5191 /* End of installation */
5192 if (hKey
!= INVALID_HANDLE_VALUE
)
5195 RpcStringFreeW(&lpGuidString
);
5196 HeapFree(GetProcessHeap(), 0, lpFullGuidString
);
5198 SetupTermDefaultQueueCallback(Context
);
5199 TRACE("Returning %d\n", ret
);
5203 static HKEY
SETUPDI_OpenDevKey(HKEY RootKey
, struct DeviceInfo
*devInfo
, REGSAM samDesired
)
5205 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
5208 l
= RegOpenKeyExW(RootKey
, REGSTR_PATH_SYSTEMENUM
, 0, 0, &enumKey
);
5211 l
= RegOpenKeyExW(enumKey
, devInfo
->instanceId
, 0, samDesired
, &key
);
5212 RegCloseKey(enumKey
);
5219 static HKEY
SETUPDI_OpenDrvKey(HKEY RootKey
, struct DeviceInfo
*devInfo
, REGSAM samDesired
)
5221 LPWSTR DriverKey
= NULL
;
5225 HKEY hEnumKey
= NULL
;
5227 HKEY key
= INVALID_HANDLE_VALUE
;
5229 hKey
= SETUPDI_OpenDevKey(RootKey
, devInfo
, KEY_QUERY_VALUE
);
5230 if (hKey
== INVALID_HANDLE_VALUE
)
5232 /* Read the 'Driver' key */
5233 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_DRIVER
, NULL
, &dwRegType
, NULL
, &dwLength
);
5234 if (rc
!= ERROR_SUCCESS
)
5239 else if (dwRegType
!= REG_SZ
)
5241 SetLastError(ERROR_GEN_FAILURE
);
5244 DriverKey
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
5247 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5250 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_DRIVER
, NULL
, &dwRegType
, (LPBYTE
)DriverKey
, &dwLength
);
5251 if (rc
!= ERROR_SUCCESS
)
5258 /* Need to open the driver key */
5261 REGSTR_PATH_CLASS_NT
,
5265 if (rc
!= ERROR_SUCCESS
)
5276 if (rc
!= ERROR_SUCCESS
)
5284 if (hEnumKey
!= NULL
)
5285 RegCloseKey(hEnumKey
);
5286 if (hKey
!= NULL
&& hKey
!= key
)
5291 /***********************************************************************
5292 * SetupDiOpenDevRegKey (SETUPAPI.@)
5294 HKEY WINAPI
SetupDiOpenDevRegKey(
5295 HDEVINFO DeviceInfoSet
,
5296 PSP_DEVINFO_DATA DeviceInfoData
,
5302 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
5303 struct DeviceInfo
*devInfo
;
5304 HKEY key
= INVALID_HANDLE_VALUE
;
5307 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
5308 Scope
, HwProfile
, KeyType
, samDesired
);
5310 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
5312 SetLastError(ERROR_INVALID_HANDLE
);
5313 return INVALID_HANDLE_VALUE
;
5315 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5317 SetLastError(ERROR_INVALID_HANDLE
);
5318 return INVALID_HANDLE_VALUE
;
5320 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
5321 || !DeviceInfoData
->Reserved
)
5323 SetLastError(ERROR_INVALID_PARAMETER
);
5324 return INVALID_HANDLE_VALUE
;
5326 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
5328 SetLastError(ERROR_INVALID_FLAGS
);
5329 return INVALID_HANDLE_VALUE
;
5331 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
5333 SetLastError(ERROR_INVALID_FLAGS
);
5334 return INVALID_HANDLE_VALUE
;
5336 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5337 if (devInfo
->set
!= set
)
5339 SetLastError(ERROR_INVALID_PARAMETER
);
5340 return INVALID_HANDLE_VALUE
;
5342 if (Scope
!= DICS_FLAG_GLOBAL
)
5344 RootKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, 0);
5345 if (RootKey
== INVALID_HANDLE_VALUE
)
5346 return INVALID_HANDLE_VALUE
;
5349 RootKey
= set
->HKLM
;
5353 key
= SETUPDI_OpenDevKey(RootKey
, devInfo
, samDesired
);
5356 key
= SETUPDI_OpenDrvKey(RootKey
, devInfo
, samDesired
);
5359 WARN("unknown KeyType %d\n", KeyType
);
5361 if (RootKey
!= set
->HKLM
)
5362 RegCloseKey(RootKey
);
5366 static BOOL
SETUPDI_DeleteDevKey(HKEY RootKey
, struct DeviceInfo
*devInfo
)
5372 static BOOL
SETUPDI_DeleteDrvKey(HKEY RootKey
, struct DeviceInfo
*devInfo
)
5378 /***********************************************************************
5379 * SetupDiDeleteDevRegKey (SETUPAPI.@)
5381 BOOL WINAPI
SetupDiDeleteDevRegKey(
5382 HDEVINFO DeviceInfoSet
,
5383 PSP_DEVINFO_DATA DeviceInfoData
,
5388 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
5389 struct DeviceInfo
*devInfo
;
5393 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
5396 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
5398 SetLastError(ERROR_INVALID_HANDLE
);
5401 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5403 SetLastError(ERROR_INVALID_HANDLE
);
5406 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
5407 || !DeviceInfoData
->Reserved
)
5409 SetLastError(ERROR_INVALID_PARAMETER
);
5412 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
5414 SetLastError(ERROR_INVALID_FLAGS
);
5417 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
5419 SetLastError(ERROR_INVALID_FLAGS
);
5422 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5423 if (devInfo
->set
!= set
)
5425 SetLastError(ERROR_INVALID_PARAMETER
);
5428 if (Scope
!= DICS_FLAG_GLOBAL
)
5430 RootKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, 0);
5431 if (RootKey
== INVALID_HANDLE_VALUE
)
5435 RootKey
= set
->HKLM
;
5439 ret
= SETUPDI_DeleteDevKey(RootKey
, devInfo
);
5442 ret
= SETUPDI_DeleteDrvKey(RootKey
, devInfo
);
5445 ret
= SETUPDI_DeleteDevKey(RootKey
, devInfo
);
5447 ret
= SETUPDI_DeleteDrvKey(RootKey
, devInfo
);
5450 WARN("unknown KeyType %d\n", KeyType
);
5452 if (RootKey
!= set
->HKLM
)
5453 RegCloseKey(RootKey
);