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 /* Unicode constants */
25 static const WCHAR BackSlash
[] = {'\\',0};
26 static const WCHAR ClassGUID
[] = {'C','l','a','s','s','G','U','I','D',0};
27 static const WCHAR Class
[] = {'C','l','a','s','s',0};
28 static const WCHAR DateFormat
[] = {'%','u','-','%','u','-','%','u',0};
29 static const WCHAR DotCoInstallers
[] = {'.','C','o','I','n','s','t','a','l','l','e','r','s',0};
30 static const WCHAR DotHW
[] = {'.','H','W',0};
31 static const WCHAR DotServices
[] = {'.','S','e','r','v','i','c','e','s',0};
32 static const WCHAR InfDirectory
[] = {'i','n','f','\\',0};
33 static const WCHAR InstanceKeyFormat
[] = {'%','0','4','l','u',0};
34 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
35 static const WCHAR VersionFormat
[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
37 static const WCHAR REGSTR_DRIVER_DATE
[] = {'D','r','i','v','e','r','D','a','t','e',0};
38 static const WCHAR REGSTR_DRIVER_DATE_DATA
[] = {'D','r','i','v','e','r','D','a','t','e','D','a','t','a',0};
39 static const WCHAR REGSTR_DRIVER_VERSION
[] = {'D','r','i','v','e','r','V','e','r','s','i','o','n',0};
40 static const WCHAR REGSTR_SECURITY
[] = {'S','e','c','u','r','i','t','y',0};
41 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};
44 (CALLBACK
* CLASS_INSTALL_PROC
) (
45 IN DI_FUNCTION InstallFunction
,
46 IN HDEVINFO DeviceInfoSet
,
47 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
);
49 (WINAPI
* DEFAULT_CLASS_INSTALL_PROC
) (
50 IN HDEVINFO DeviceInfoSet
,
51 IN OUT PSP_DEVINFO_DATA DeviceInfoData
);
53 (CALLBACK
* COINSTALLER_PROC
) (
54 IN DI_FUNCTION InstallFunction
,
55 IN HDEVINFO DeviceInfoSet
,
56 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
57 IN OUT PCOINSTALLER_CONTEXT_DATA Context
);
59 struct CoInstallerElement
64 COINSTALLER_PROC Function
;
65 BOOL DoPostProcessing
;
69 struct GetSectionCallbackInfo
71 PSP_ALTPLATFORM_INFO PlatformInfo
;
75 WCHAR BestSection
[LINE_LEN
+ 1];
76 DWORD BestScore1
, BestScore2
, BestScore3
, BestScore4
, BestScore5
;
81 static void SETUPDI_GuidToString(const GUID
*guid
, LPWSTR guidStr
)
83 static const WCHAR fmt
[] = {'{','%','0','8','X','-','%','0','4','X','-',
84 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
85 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
88 sprintfW(guidStr
, fmt
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
89 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
90 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
94 GetErrorCodeFromCrCode(const IN CONFIGRET cr
)
98 case CR_ACCESS_DENIED
: return ERROR_ACCESS_DENIED
;
99 case CR_BUFFER_SMALL
: return ERROR_INSUFFICIENT_BUFFER
;
100 case CR_CALL_NOT_IMPLEMENTED
: return ERROR_CALL_NOT_IMPLEMENTED
;
101 case CR_FAILURE
: return ERROR_GEN_FAILURE
;
102 case CR_INVALID_DATA
: return ERROR_INVALID_USER_BUFFER
;
103 case CR_INVALID_DEVICE_ID
: return ERROR_INVALID_PARAMETER
;
104 case CR_INVALID_MACHINENAME
: return ERROR_INVALID_COMPUTERNAME
;
105 case CR_INVALID_DEVNODE
: return ERROR_INVALID_PARAMETER
;
106 case CR_INVALID_FLAG
: return ERROR_INVALID_FLAGS
;
107 case CR_INVALID_POINTER
: return ERROR_INVALID_PARAMETER
;
108 case CR_INVALID_PROPERTY
: return ERROR_INVALID_PARAMETER
;
109 case CR_NO_SUCH_DEVNODE
: return ERROR_FILE_NOT_FOUND
;
110 case CR_NO_SUCH_REGISTRY_KEY
: return ERROR_FILE_NOT_FOUND
;
111 case CR_NO_SUCH_VALUE
: return ERROR_FILE_NOT_FOUND
;
112 case CR_OUT_OF_MEMORY
: return ERROR_NOT_ENOUGH_MEMORY
;
113 case CR_REGISTRY_ERROR
: return ERROR_GEN_FAILURE
;
114 case CR_ALREADY_SUCH_DEVINST
: return ERROR_DEVINST_ALREADY_EXISTS
;
115 case CR_SUCCESS
: return ERROR_SUCCESS
;
116 default: return ERROR_GEN_FAILURE
;
119 /* Does not happen */
122 /* Lower scores are best ones */
125 IN LPCWSTR SectionName
,
126 IN PSP_ALTPLATFORM_INFO PlatformInfo
,
129 OUT PDWORD ScorePlatform
,
130 OUT PDWORD ScoreMajorVersion
,
131 OUT PDWORD ScoreMinorVersion
,
132 OUT PDWORD ScoreProductType
,
133 OUT PDWORD ScoreSuiteMask
)
135 LPWSTR Section
= NULL
;
136 //LPCWSTR pExtensionPlatform;
137 LPCWSTR 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
= pSetupDuplicateString(SectionName
);
162 TRACE("pSetupDuplicateString() 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: these 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
= pSetupMultiByteToUnicode(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
= pSetupMultiByteToUnicode(ClassName
, CP_ACP
);
914 if (ClassNameW
== NULL
)
919 MachineNameW
= pSetupMultiByteToUnicode(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
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
1105 ret
= SetupDiClassNameFromGuidExW(ClassGuid
, ClassNameW
, MAX_CLASS_NAME_LEN
,
1106 RequiredSize
, 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
);
1117 MyFree(MachineNameW
);
1121 /***********************************************************************
1122 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1124 BOOL WINAPI
SetupDiClassNameFromGuidExW(
1125 const GUID
* ClassGuid
,
1127 DWORD ClassNameSize
,
1128 PDWORD RequiredSize
,
1138 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassName
,
1139 ClassNameSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
1141 /* Make sure there's a GUID */
1142 if (ClassGuid
== NULL
)
1144 SetLastError(ERROR_INVALID_CLASS
); /* On Vista: ERROR_INVALID_USER_BUFFER */
1148 /* Make sure there's a real buffer when there's a size */
1149 if ((ClassNameSize
> 0) && (ClassName
== NULL
))
1151 SetLastError(ERROR_INVALID_PARAMETER
); /* On Vista: ERROR_INVALID_USER_BUFFER */
1155 /* Open the key for the GUID */
1156 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, KEY_QUERY_VALUE
, DIOCR_INSTALLER
, MachineName
, Reserved
);
1158 if (hKey
== INVALID_HANDLE_VALUE
)
1161 /* Retrieve the class name data and close the key */
1162 rc
= QueryRegistryValue(hKey
, Class
, (LPBYTE
*) &Buffer
, &dwRegType
, &dwLength
);
1165 /* Make sure we got the data */
1166 if (rc
!= ERROR_SUCCESS
)
1172 /* Make sure the data is a string */
1173 if (dwRegType
!= REG_SZ
)
1176 SetLastError(ERROR_GEN_FAILURE
);
1180 /* Determine the length of the class name */
1181 dwLength
/= sizeof(WCHAR
);
1183 if ((dwLength
== 0) || (Buffer
[dwLength
- 1] != UNICODE_NULL
))
1184 /* Count the null-terminator */
1187 /* Inform the caller about the class name */
1188 if ((ClassName
!= NULL
) && (dwLength
<= ClassNameSize
))
1190 memcpy(ClassName
, Buffer
, (dwLength
- 1) * sizeof(WCHAR
));
1191 ClassName
[dwLength
- 1] = UNICODE_NULL
;
1194 /* Inform the caller about the required size */
1195 if (RequiredSize
!= NULL
)
1196 *RequiredSize
= dwLength
;
1198 /* Clean up the buffer */
1201 /* Make sure the buffer was large enough */
1202 if ((ClassName
== NULL
) || (dwLength
> ClassNameSize
))
1204 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1211 /***********************************************************************
1212 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1215 SetupDiCreateDeviceInfoList(const GUID
*ClassGuid
,
1218 return SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
, NULL
, NULL
);
1221 /***********************************************************************
1222 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1225 SetupDiCreateDeviceInfoListExA(const GUID
*ClassGuid
,
1230 LPWSTR MachineNameW
= NULL
;
1233 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1234 debugstr_a(MachineName
), Reserved
);
1238 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
1239 if (MachineNameW
== NULL
)
1240 return INVALID_HANDLE_VALUE
;
1243 hDevInfo
= SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
,
1244 MachineNameW
, Reserved
);
1246 MyFree(MachineNameW
);
1251 /***********************************************************************
1252 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1254 * Create an empty DeviceInfoSet list.
1257 * ClassGuid [I] if not NULL only devices with GUID ClcassGuid are associated
1259 * hwndParent [I] hwnd needed for interface related actions.
1260 * MachineName [I] name of machine to create emtpy DeviceInfoSet list, if NULL
1261 * local registry will be used.
1262 * Reserved [I] must be NULL
1265 * Success: empty list.
1266 * Failure: INVALID_HANDLE_VALUE.
1269 SetupDiCreateDeviceInfoListExW(const GUID
*ClassGuid
,
1274 struct DeviceInfoSet
*list
= NULL
;
1275 DWORD size
= FIELD_OFFSET(struct DeviceInfoSet
, szData
);
1278 HDEVINFO ret
= INVALID_HANDLE_VALUE
;
1280 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1281 debugstr_w(MachineName
), Reserved
);
1283 if (MachineName
!= NULL
)
1285 SIZE_T len
= strlenW(MachineName
);
1286 if (len
>= SP_MAX_MACHINENAME_LENGTH
- 4)
1288 SetLastError(ERROR_INVALID_MACHINENAME
);
1292 size
+= (len
+ 3) * sizeof(WCHAR
);
1297 if (Reserved
!= NULL
)
1299 SetLastError(ERROR_INVALID_PARAMETER
);
1300 return INVALID_HANDLE_VALUE
;
1303 list
= MyMalloc(size
);
1306 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1307 return INVALID_HANDLE_VALUE
;
1309 ZeroMemory(list
, FIELD_OFFSET(struct DeviceInfoSet
, szData
));
1311 list
->magic
= SETUP_DEVICE_INFO_SET_MAGIC
;
1312 memcpy(&list
->ClassGuid
,
1313 ClassGuid
? ClassGuid
: &GUID_NULL
,
1314 sizeof(list
->ClassGuid
));
1315 list
->InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
1316 list
->InstallParams
.Flags
|= DI_CLASSINSTALLPARAMS
;
1317 list
->InstallParams
.hwndParent
= hwndParent
;
1320 rc
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &list
->HKLM
);
1321 if (rc
!= ERROR_SUCCESS
)
1323 SetLastError(ERROR_INVALID_MACHINENAME
);
1327 list
->szData
[0] = list
->szData
[1] = '\\';
1328 strcpyW(list
->szData
+ 2, MachineName
);
1329 list
->MachineName
= list
->szData
;
1333 list
->HKLM
= HKEY_LOCAL_MACHINE
;
1334 list
->MachineName
= NULL
;
1336 cr
= CM_Connect_MachineW(list
->MachineName
, &list
->hMachine
);
1337 if (cr
!= CR_SUCCESS
)
1339 SetLastError(GetErrorCodeFromCrCode(cr
));
1342 InitializeListHead(&list
->DriverListHead
);
1343 InitializeListHead(&list
->ListHead
);
1345 return (HDEVINFO
)list
;
1348 if (ret
== INVALID_HANDLE_VALUE
)
1352 if (list
->HKLM
!= NULL
&& list
->HKLM
!= HKEY_LOCAL_MACHINE
)
1353 RegCloseKey(list
->HKLM
);
1360 /***********************************************************************
1361 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1363 HKEY WINAPI
SetupDiCreateDevRegKeyA(
1364 HDEVINFO DeviceInfoSet
,
1365 PSP_DEVINFO_DATA DeviceInfoData
,
1370 PCSTR InfSectionName
)
1372 PWSTR InfSectionNameW
= NULL
;
1375 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1376 HwProfile
, KeyType
, InfHandle
, debugstr_a(InfSectionName
));
1380 if (!InfSectionName
)
1382 SetLastError(ERROR_INVALID_PARAMETER
);
1383 return INVALID_HANDLE_VALUE
;
1387 InfSectionNameW
= pSetupMultiByteToUnicode(InfSectionName
, CP_ACP
);
1388 if (InfSectionNameW
== NULL
) return INVALID_HANDLE_VALUE
;
1391 key
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, Scope
,
1392 HwProfile
, KeyType
, InfHandle
, InfSectionNameW
);
1393 MyFree(InfSectionNameW
);
1398 OpenHardwareProfileKey(
1401 IN DWORD samDesired
);
1403 /***********************************************************************
1404 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1406 HKEY WINAPI
SetupDiCreateDevRegKeyW(
1407 HDEVINFO DeviceInfoSet
,
1408 PSP_DEVINFO_DATA DeviceInfoData
,
1413 PCWSTR InfSectionName
)
1415 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1416 HKEY key
= INVALID_HANDLE_VALUE
;
1417 LPWSTR lpGuidString
= NULL
;
1418 LPWSTR DriverKey
= NULL
; /* {GUID}\Index */
1419 LPWSTR pDeviceInstance
; /* Points into DriverKey, on the Index field */
1420 DWORD Index
; /* Index used in the DriverKey name */
1424 HKEY hHWProfileKey
= INVALID_HANDLE_VALUE
;
1425 HKEY hEnumKey
= NULL
;
1426 HKEY hClassKey
= NULL
;
1427 HKEY hDeviceKey
= INVALID_HANDLE_VALUE
;
1431 TRACE("%p %p %lu %lu %lu %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1432 HwProfile
, KeyType
, InfHandle
, debugstr_w(InfSectionName
));
1434 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1436 SetLastError(ERROR_INVALID_HANDLE
);
1437 return INVALID_HANDLE_VALUE
;
1439 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1441 SetLastError(ERROR_INVALID_HANDLE
);
1442 return INVALID_HANDLE_VALUE
;
1444 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1445 || !DeviceInfoData
->Reserved
)
1447 SetLastError(ERROR_INVALID_PARAMETER
);
1448 return INVALID_HANDLE_VALUE
;
1450 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
1452 SetLastError(ERROR_INVALID_FLAGS
);
1453 return INVALID_HANDLE_VALUE
;
1455 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
1457 SetLastError(ERROR_INVALID_FLAGS
);
1458 return INVALID_HANDLE_VALUE
;
1460 if (InfHandle
&& !InfSectionName
)
1462 SetLastError(ERROR_INVALID_PARAMETER
);
1463 return INVALID_HANDLE_VALUE
;
1465 if (!InfHandle
&& InfSectionName
)
1467 SetLastError(ERROR_INVALID_PARAMETER
);
1468 return INVALID_HANDLE_VALUE
;
1471 if (Scope
== DICS_FLAG_GLOBAL
)
1472 RootKey
= set
->HKLM
;
1473 else /* Scope == DICS_FLAG_CONFIGSPECIFIC */
1475 hHWProfileKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, KEY_CREATE_SUB_KEY
);
1476 if (hHWProfileKey
== INVALID_HANDLE_VALUE
)
1478 RootKey
= hHWProfileKey
;
1481 if (KeyType
== DIREG_DEV
)
1483 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1485 rc
= RegCreateKeyExW(
1487 REGSTR_PATH_SYSTEMENUM
,
1490 REG_OPTION_NON_VOLATILE
,
1495 if (rc
!= ERROR_SUCCESS
)
1500 rc
= RegCreateKeyExW(
1502 deviceInfo
->instanceId
,
1505 REG_OPTION_NON_VOLATILE
,
1506 #if _WIN32_WINNT >= 0x502
1507 KEY_READ
| KEY_WRITE
,
1514 if (rc
!= ERROR_SUCCESS
)
1520 else /* KeyType == DIREG_DRV */
1522 /* Open device key, to read Driver value */
1523 hDeviceKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
, DIREG_DEV
, KEY_QUERY_VALUE
| KEY_SET_VALUE
);
1524 if (hDeviceKey
== INVALID_HANDLE_VALUE
)
1527 rc
= RegOpenKeyExW(RootKey
, REGSTR_PATH_CLASS_NT
, 0, KEY_CREATE_SUB_KEY
, &hClassKey
);
1528 if (rc
!= ERROR_SUCCESS
)
1534 rc
= RegQueryValueExW(hDeviceKey
, REGSTR_VAL_DRIVER
, NULL
, NULL
, NULL
, &dwSize
);
1535 if (rc
!= ERROR_SUCCESS
)
1537 /* Create a new driver key */
1539 if (UuidToStringW((UUID
*)&DeviceInfoData
->ClassGuid
, &lpGuidString
) != RPC_S_OK
)
1542 /* The driver key is in \System\CurrentControlSet\Control\Class\{GUID}\Index */
1543 DriverKey
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpGuidString
) + 7) * sizeof(WCHAR
) + sizeof(UNICODE_NULL
));
1546 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1551 strcpyW(&DriverKey
[1], lpGuidString
);
1552 pDeviceInstance
= &DriverKey
[strlenW(DriverKey
)];
1553 *pDeviceInstance
++ = '}';
1554 *pDeviceInstance
++ = '\\';
1556 /* Try all values for Index between 0 and 9999 */
1558 while (Index
<= 9999)
1560 sprintfW(pDeviceInstance
, InstanceKeyFormat
, Index
);
1561 rc
= RegCreateKeyExW(hClassKey
,
1565 REG_OPTION_NON_VOLATILE
,
1566 #if _WIN32_WINNT >= 0x502
1567 KEY_READ
| KEY_WRITE
,
1574 if (rc
!= ERROR_SUCCESS
)
1579 if (Disposition
== REG_CREATED_NEW_KEY
)
1588 /* Unable to create more than 9999 devices within the same class */
1589 SetLastError(ERROR_GEN_FAILURE
);
1593 /* Write the new Driver value */
1594 rc
= RegSetValueExW(hDeviceKey
, REGSTR_VAL_DRIVER
, 0, REG_SZ
, (const BYTE
*)DriverKey
, (strlenW(DriverKey
) + 1) * sizeof(WCHAR
));
1595 if (rc
!= ERROR_SUCCESS
)
1604 /* Open the existing driver key */
1606 DriverKey
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
1609 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1613 rc
= RegQueryValueExW(hDeviceKey
, REGSTR_VAL_DRIVER
, NULL
, NULL
, (LPBYTE
)DriverKey
, &dwSize
);
1614 if (rc
!= ERROR_SUCCESS
)
1620 rc
= RegCreateKeyExW(hClassKey
,
1624 REG_OPTION_NON_VOLATILE
,
1625 #if _WIN32_WINNT >= 0x502
1626 KEY_READ
| KEY_WRITE
,
1633 if (rc
!= ERROR_SUCCESS
)
1641 /* Do installation of the specified section */
1644 FIXME("Need to install section %s in file %p\n",
1645 debugstr_w(InfSectionName
), InfHandle
);
1651 RpcStringFreeW(&lpGuidString
);
1652 HeapFree(GetProcessHeap(), 0, DriverKey
);
1653 if (hHWProfileKey
!= INVALID_HANDLE_VALUE
)
1654 RegCloseKey(hHWProfileKey
);
1655 if (hEnumKey
!= NULL
)
1656 RegCloseKey(hEnumKey
);
1657 if (hClassKey
!= NULL
)
1658 RegCloseKey(hClassKey
);
1659 if (hDeviceKey
!= INVALID_HANDLE_VALUE
)
1660 RegCloseKey(hDeviceKey
);
1661 if (hKey
!= NULL
&& hKey
!= key
)
1664 TRACE("Returning 0x%p\n", key
);
1668 /***********************************************************************
1669 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1671 BOOL WINAPI
SetupDiCreateDeviceInfoA(
1672 HDEVINFO DeviceInfoSet
,
1674 CONST GUID
*ClassGuid
,
1675 PCSTR DeviceDescription
,
1677 DWORD CreationFlags
,
1678 PSP_DEVINFO_DATA DeviceInfoData
)
1681 LPWSTR DeviceNameW
= NULL
;
1682 LPWSTR DeviceDescriptionW
= NULL
;
1688 DeviceNameW
= pSetupMultiByteToUnicode(DeviceName
, CP_ACP
);
1689 if (DeviceNameW
== NULL
) return FALSE
;
1691 if (DeviceDescription
)
1693 DeviceDescriptionW
= pSetupMultiByteToUnicode(DeviceDescription
, CP_ACP
);
1694 if (DeviceDescriptionW
== NULL
)
1696 MyFree(DeviceNameW
);
1701 ret
= SetupDiCreateDeviceInfoW(DeviceInfoSet
, DeviceNameW
, ClassGuid
, DeviceDescriptionW
,
1702 hwndParent
, CreationFlags
, DeviceInfoData
);
1704 MyFree(DeviceNameW
);
1705 MyFree(DeviceDescriptionW
);
1710 /***********************************************************************
1711 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1713 BOOL WINAPI
SetupDiCreateDeviceInfoW(
1714 HDEVINFO DeviceInfoSet
,
1716 CONST GUID
*ClassGuid
,
1717 PCWSTR DeviceDescription
,
1719 DWORD CreationFlags
,
1720 PSP_DEVINFO_DATA DeviceInfoData
)
1722 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1723 struct DeviceInfo
*deviceInfo
= NULL
;
1726 DEVINST RootDevInst
;
1728 WCHAR GenInstanceId
[MAX_DEVICE_ID_LEN
];
1730 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet
, debugstr_w(DeviceName
),
1731 debugstr_guid(ClassGuid
), debugstr_w(DeviceDescription
),
1732 hwndParent
, CreationFlags
, DeviceInfoData
);
1736 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1739 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1741 SetLastError(ERROR_INVALID_HANDLE
);
1746 SetLastError(ERROR_INVALID_PARAMETER
);
1749 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1751 SetLastError(ERROR_INVALID_HANDLE
);
1754 if (!IsEqualGUID(&set
->ClassGuid
, &GUID_NULL
) &&
1755 !IsEqualGUID(ClassGuid
, &set
->ClassGuid
))
1757 SetLastError(ERROR_CLASS_MISMATCH
);
1760 if (CreationFlags
& ~(DICD_GENERATE_ID
| DICD_INHERIT_CLASSDRVS
))
1762 TRACE("Unknown flags: 0x%08lx\n", CreationFlags
& ~(DICD_GENERATE_ID
| DICD_INHERIT_CLASSDRVS
));
1763 SetLastError(ERROR_INVALID_FLAGS
);
1767 /* Get the root device instance */
1768 cr
= CM_Locate_DevInst_ExW(&RootDevInst
,
1770 CM_LOCATE_DEVINST_NORMAL
,
1772 if (cr
!= CR_SUCCESS
)
1774 SetLastError(ERROR_INVALID_DATA
);
1778 /* Create the new device instance */
1779 cr
= CM_Create_DevInst_ExW(&DevInst
,
1780 (DEVINSTID
)DeviceName
,
1782 (CreationFlags
& DICD_GENERATE_ID
) ?
1783 CM_CREATE_DEVINST_GENERATE_ID
: 0,
1785 if (cr
!= CR_SUCCESS
)
1787 SetLastError(GetErrorCodeFromCrCode(cr
));
1791 if (CreationFlags
& DICD_GENERATE_ID
)
1793 /* Grab the actual instance ID that was created */
1794 cr
= CM_Get_Device_ID_Ex(DevInst
,
1799 if (cr
!= CR_SUCCESS
)
1801 SetLastError(GetErrorCodeFromCrCode(cr
));
1805 DeviceName
= GenInstanceId
;
1806 TRACE("Using generated instance ID: %s\n", debugstr_w(DeviceName
));
1809 if (CreateDeviceInfo(set
, DeviceName
, ClassGuid
, &deviceInfo
))
1811 InsertTailList(&set
->ListHead
, &deviceInfo
->ListEntry
);
1813 if (!DeviceInfoData
)
1817 if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1819 SetLastError(ERROR_INVALID_USER_BUFFER
);
1823 memcpy(&DeviceInfoData
->ClassGuid
, ClassGuid
, sizeof(GUID
));
1824 DeviceInfoData
->DevInst
= deviceInfo
->dnDevInst
;
1825 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInfo
;
1833 if (deviceInfo
!= NULL
)
1835 /* Remove deviceInfo from List */
1836 RemoveEntryList(&deviceInfo
->ListEntry
);
1838 /* Destroy deviceInfo */
1839 DestroyDeviceInfo(deviceInfo
);
1843 TRACE("Returning %d\n", ret
);
1847 /***********************************************************************
1848 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1850 BOOL WINAPI
SetupDiRegisterDeviceInfo(
1851 HDEVINFO DeviceInfoSet
,
1852 PSP_DEVINFO_DATA DeviceInfoData
,
1854 PSP_DETSIG_CMPPROC CompareProc
,
1855 PVOID CompareContext
,
1856 PSP_DEVINFO_DATA DupDeviceInfoData
)
1858 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1859 WCHAR DevInstId
[MAX_DEVICE_ID_LEN
];
1860 DEVINST ParentDevInst
;
1862 DWORD dwError
= ERROR_SUCCESS
;
1864 TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet
, DeviceInfoData
, Flags
,
1865 CompareProc
, CompareContext
, DupDeviceInfoData
);
1867 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1869 SetLastError(ERROR_INVALID_HANDLE
);
1872 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1874 SetLastError(ERROR_INVALID_HANDLE
);
1877 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1878 || !DeviceInfoData
->Reserved
)
1880 SetLastError(ERROR_INVALID_PARAMETER
);
1884 if (Flags
& ~SPRDI_FIND_DUPS
)
1886 TRACE("Unknown flags: 0x%08lx\n", Flags
& ~SPRDI_FIND_DUPS
);
1887 SetLastError(ERROR_INVALID_FLAGS
);
1891 if (Flags
& SPRDI_FIND_DUPS
)
1893 FIXME("Unimplemented codepath!\n");
1896 CM_Get_Device_ID_Ex(DeviceInfoData
->DevInst
,
1902 CM_Get_Parent_Ex(&ParentDevInst
,
1903 DeviceInfoData
->DevInst
,
1907 cr
= CM_Create_DevInst_Ex(&DeviceInfoData
->DevInst
,
1910 CM_CREATE_DEVINST_NORMAL
| CM_CREATE_DEVINST_DO_NOT_INSTALL
,
1912 if (cr
!= CR_SUCCESS
&&
1913 cr
!= CR_ALREADY_SUCH_DEVINST
)
1915 dwError
= ERROR_NO_SUCH_DEVINST
;
1918 SetLastError(dwError
);
1920 return (dwError
== ERROR_SUCCESS
);
1923 /***********************************************************************
1924 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1926 BOOL WINAPI
SetupDiEnumDeviceInfo(
1929 PSP_DEVINFO_DATA info
)
1933 TRACE("%p %d %p\n", devinfo
, index
, info
);
1937 SetLastError(ERROR_INVALID_PARAMETER
);
1940 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
1942 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
1943 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
1945 if (info
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1946 SetLastError(ERROR_INVALID_USER_BUFFER
);
1949 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
1950 while (ItemList
!= &list
->ListHead
&& index
-- > 0)
1951 ItemList
= ItemList
->Flink
;
1952 if (ItemList
== &list
->ListHead
)
1953 SetLastError(ERROR_NO_MORE_ITEMS
);
1956 struct DeviceInfo
*DevInfo
= CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
1957 memcpy(&info
->ClassGuid
,
1958 &DevInfo
->ClassGuid
,
1960 info
->DevInst
= DevInfo
->dnDevInst
;
1961 info
->Reserved
= (ULONG_PTR
)DevInfo
;
1967 SetLastError(ERROR_INVALID_HANDLE
);
1970 SetLastError(ERROR_INVALID_HANDLE
);
1974 /***********************************************************************
1975 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1977 BOOL WINAPI
SetupDiGetDeviceInstanceIdA(
1978 HDEVINFO DeviceInfoSet
,
1979 PSP_DEVINFO_DATA DeviceInfoData
,
1980 PSTR DeviceInstanceId
,
1981 DWORD DeviceInstanceIdSize
,
1982 PDWORD RequiredSize
)
1988 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1989 DeviceInstanceIdSize
, RequiredSize
);
1991 if (!DeviceInstanceId
&& DeviceInstanceIdSize
> 0)
1993 SetLastError(ERROR_INVALID_PARAMETER
);
1997 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
2002 if (!ret
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
2004 instanceId
= MyMalloc(size
* sizeof(WCHAR
));
2007 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
2014 int len
= WideCharToMultiByte(CP_ACP
, 0, instanceId
, -1,
2016 DeviceInstanceIdSize
, NULL
, NULL
);
2022 if (len
> DeviceInstanceIdSize
)
2024 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2028 *RequiredSize
= len
;
2036 *RequiredSize
= size
;
2037 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2043 /***********************************************************************
2044 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
2046 BOOL WINAPI
SetupDiGetDeviceInstanceIdW(
2047 HDEVINFO DeviceInfoSet
,
2048 PSP_DEVINFO_DATA DeviceInfoData
,
2049 PWSTR DeviceInstanceId
,
2050 DWORD DeviceInstanceIdSize
,
2051 PDWORD RequiredSize
)
2053 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2054 struct DeviceInfo
*devInfo
;
2056 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
2057 DeviceInstanceIdSize
, RequiredSize
);
2059 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2061 SetLastError(ERROR_INVALID_HANDLE
);
2064 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2066 SetLastError(ERROR_INVALID_HANDLE
);
2069 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2070 || !DeviceInfoData
->Reserved
)
2072 SetLastError(ERROR_INVALID_PARAMETER
);
2075 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2076 if (!DeviceInstanceId
&& DeviceInstanceIdSize
> 0)
2078 SetLastError(ERROR_INVALID_PARAMETER
);
2081 if (DeviceInstanceId
&& DeviceInstanceIdSize
== 0)
2083 SetLastError(ERROR_INVALID_PARAMETER
);
2086 TRACE("instance ID: %s\n", debugstr_w(devInfo
->instanceId
));
2087 if (DeviceInstanceIdSize
< lstrlenW(devInfo
->instanceId
) + 1)
2089 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2091 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
2094 lstrcpyW(DeviceInstanceId
, devInfo
->instanceId
);
2096 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
2100 /***********************************************************************
2101 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
2103 BOOL WINAPI
SetupDiGetActualSectionToInstallA(
2105 PCSTR InfSectionName
,
2106 PSTR InfSectionWithExt
,
2107 DWORD InfSectionWithExtSize
,
2108 PDWORD RequiredSize
,
2111 return SetupDiGetActualSectionToInstallExA(InfHandle
, InfSectionName
,
2112 NULL
, InfSectionWithExt
, InfSectionWithExtSize
, RequiredSize
,
2116 /***********************************************************************
2117 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
2119 BOOL WINAPI
SetupDiGetActualSectionToInstallW(
2121 PCWSTR InfSectionName
,
2122 PWSTR InfSectionWithExt
,
2123 DWORD InfSectionWithExtSize
,
2124 PDWORD RequiredSize
,
2127 return SetupDiGetActualSectionToInstallExW(InfHandle
, InfSectionName
,
2128 NULL
, InfSectionWithExt
, InfSectionWithExtSize
, RequiredSize
,
2132 /***********************************************************************
2133 * SetupDiGetActualSectionToInstallExA (SETUPAPI.@)
2136 SetupDiGetActualSectionToInstallExA(
2138 IN PCSTR InfSectionName
,
2139 IN PSP_ALTPLATFORM_INFO AlternatePlatformInfo OPTIONAL
,
2140 OUT PSTR InfSectionWithExt OPTIONAL
,
2141 IN DWORD InfSectionWithExtSize
,
2142 OUT PDWORD RequiredSize OPTIONAL
,
2143 OUT PSTR
* Extension OPTIONAL
,
2146 LPWSTR InfSectionNameW
= NULL
;
2147 LPWSTR InfSectionWithExtW
= NULL
;
2149 BOOL bResult
= FALSE
;
2155 InfSectionNameW
= pSetupMultiByteToUnicode(InfSectionName
, CP_ACP
);
2156 if (InfSectionNameW
== NULL
)
2159 if (InfSectionWithExt
)
2161 InfSectionWithExtW
= MyMalloc(InfSectionWithExtSize
* sizeof(WCHAR
));
2162 if (InfSectionWithExtW
== NULL
)
2166 bResult
= SetupDiGetActualSectionToInstallExW(
2167 InfHandle
, InfSectionNameW
, AlternatePlatformInfo
,
2168 InfSectionWithExt
? InfSectionWithExtW
: NULL
,
2169 InfSectionWithExtSize
,
2171 Extension
? &ExtensionW
: NULL
,
2174 if (bResult
&& InfSectionWithExt
)
2176 bResult
= WideCharToMultiByte(CP_ACP
, 0, InfSectionWithExtW
, -1, InfSectionWithExt
,
2177 InfSectionWithExtSize
, NULL
, NULL
) != 0;
2179 if (bResult
&& Extension
)
2181 if (ExtensionW
== NULL
)
2184 *Extension
= &InfSectionWithExt
[ExtensionW
- InfSectionWithExtW
];
2188 MyFree(InfSectionNameW
);
2189 MyFree(InfSectionWithExtW
);
2194 /***********************************************************************
2195 * SetupDiGetClassDescriptionA (SETUPAPI.@)
2197 BOOL WINAPI
SetupDiGetClassDescriptionA(
2198 const GUID
* ClassGuid
,
2199 PSTR ClassDescription
,
2200 DWORD ClassDescriptionSize
,
2201 PDWORD RequiredSize
)
2203 return SetupDiGetClassDescriptionExA(ClassGuid
, ClassDescription
,
2204 ClassDescriptionSize
,
2205 RequiredSize
, NULL
, NULL
);
2208 /***********************************************************************
2209 * SetupDiGetClassDescriptionW (SETUPAPI.@)
2211 BOOL WINAPI
SetupDiGetClassDescriptionW(
2212 const GUID
* ClassGuid
,
2213 PWSTR ClassDescription
,
2214 DWORD ClassDescriptionSize
,
2215 PDWORD RequiredSize
)
2217 return SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescription
,
2218 ClassDescriptionSize
,
2219 RequiredSize
, NULL
, NULL
);
2222 /***********************************************************************
2223 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
2225 BOOL WINAPI
SetupDiGetClassDescriptionExA(
2226 const GUID
* ClassGuid
,
2227 PSTR ClassDescription
,
2228 DWORD ClassDescriptionSize
,
2229 PDWORD RequiredSize
,
2233 PWCHAR ClassDescriptionW
= NULL
;
2234 LPWSTR MachineNameW
= NULL
;
2237 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassDescription
,
2238 ClassDescriptionSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
2240 if (ClassDescriptionSize
> 0)
2242 ClassDescriptionW
= MyMalloc(ClassDescriptionSize
* sizeof(WCHAR
));
2243 if (!ClassDescriptionW
)
2245 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2252 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
2255 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2260 ret
= SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescriptionW
,
2261 ClassDescriptionSize
* sizeof(WCHAR
), RequiredSize
, MachineNameW
, Reserved
);
2264 DWORD len
= (DWORD
)WideCharToMultiByte(CP_ACP
, 0, ClassDescriptionW
, -1, ClassDescription
,
2265 ClassDescriptionSize
, NULL
, NULL
);
2266 if (len
== 0 || len
> ClassDescriptionSize
)
2268 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2274 MyFree(ClassDescriptionW
);
2275 MyFree(MachineNameW
);
2279 /***********************************************************************
2280 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
2282 BOOL WINAPI
SetupDiGetClassDescriptionExW(
2283 const GUID
* ClassGuid
,
2284 PWSTR ClassDescription
,
2285 DWORD ClassDescriptionSize
,
2286 PDWORD RequiredSize
,
2296 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassDescription
,
2297 ClassDescriptionSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
2299 /* Make sure there's a GUID */
2302 SetLastError(ERROR_INVALID_PARAMETER
);
2306 /* Make sure there's a real buffer when there's a size */
2307 if (!ClassDescription
&& ClassDescriptionSize
> 0)
2309 SetLastError(ERROR_INVALID_PARAMETER
);
2313 /* Open the key for the GUID */
2314 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
2319 if (hKey
== INVALID_HANDLE_VALUE
)
2322 /* Retrieve the class description data and close the key */
2323 rc
= QueryRegistryValue(hKey
, NULL
, (LPBYTE
*) &Buffer
, &dwRegType
, &dwLength
);
2326 /* Make sure we got the data */
2327 if (rc
!= ERROR_SUCCESS
)
2333 /* Make sure the data is a string */
2334 if (dwRegType
!= REG_SZ
)
2337 SetLastError(ERROR_GEN_FAILURE
);
2341 /* Determine the length of the class description */
2342 dwLength
/= sizeof(WCHAR
);
2344 /* Count the null-terminator if none is present */
2345 if ((dwLength
== 0) || (Buffer
[dwLength
- 1] != UNICODE_NULL
))
2348 /* Inform the caller about the class description */
2349 if ((ClassDescription
!= NULL
) && (dwLength
<= ClassDescriptionSize
))
2351 memcpy(ClassDescription
, Buffer
, (dwLength
- 1) * sizeof(WCHAR
));
2352 ClassDescription
[dwLength
- 1] = UNICODE_NULL
;
2355 /* Inform the caller about the required size */
2356 if (RequiredSize
!= NULL
)
2357 *RequiredSize
= dwLength
;
2359 /* Clean up the buffer */
2362 /* Make sure the buffer was large enough */
2363 if ((ClassDescription
== NULL
) || (dwLength
> ClassDescriptionSize
))
2365 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2372 /***********************************************************************
2373 * SetupDiGetClassDevsA (SETUPAPI.@)
2375 HDEVINFO WINAPI
SetupDiGetClassDevsA(
2381 return SetupDiGetClassDevsExA(class, enumstr
, parent
,
2382 flags
, NULL
, NULL
, NULL
);
2385 /***********************************************************************
2386 * SetupDiGetClassDevsExA (SETUPAPI.@)
2388 HDEVINFO WINAPI
SetupDiGetClassDevsExA(
2398 LPWSTR enumstrW
= NULL
, machineW
= NULL
;
2402 enumstrW
= pSetupMultiByteToUnicode(enumstr
, CP_ACP
);
2405 ret
= INVALID_HANDLE_VALUE
;
2411 machineW
= pSetupMultiByteToUnicode(machine
, CP_ACP
);
2415 ret
= INVALID_HANDLE_VALUE
;
2419 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, deviceset
,
2420 machineW
, reserved
);
2428 /***********************************************************************
2429 * SetupDiGetClassDevsW (SETUPAPI.@)
2431 HDEVINFO WINAPI
SetupDiGetClassDevsW(
2437 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2441 /***********************************************************************
2442 * SetupDiGetClassDevsExW (SETUPAPI.@)
2444 HDEVINFO WINAPI
SetupDiGetClassDevsExW(
2453 HDEVINFO hDeviceInfo
= INVALID_HANDLE_VALUE
;
2454 struct DeviceInfoSet
*list
;
2455 CONST GUID
*pClassGuid
;
2457 HDEVINFO set
= INVALID_HANDLE_VALUE
;
2459 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2460 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2463 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2465 SetLastError(ERROR_INVALID_PARAMETER
);
2466 return INVALID_HANDLE_VALUE
;
2469 /* Create the deviceset if not set */
2472 list
= (struct DeviceInfoSet
*)deviceset
;
2473 if (list
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2475 SetLastError(ERROR_INVALID_HANDLE
);
2478 hDeviceInfo
= deviceset
;
2482 hDeviceInfo
= SetupDiCreateDeviceInfoListExW(
2483 flags
& (DIGCF_DEVICEINTERFACE
| DIGCF_ALLCLASSES
) ? NULL
: class,
2484 NULL
, machine
, NULL
);
2485 if (hDeviceInfo
== INVALID_HANDLE_VALUE
)
2487 list
= (struct DeviceInfoSet
*)hDeviceInfo
;
2490 if (flags
& DIGCF_PROFILE
)
2491 FIXME(": flag DIGCF_PROFILE ignored\n");
2493 if (flags
& DIGCF_DEVICEINTERFACE
)
2497 SetLastError(ERROR_INVALID_PARAMETER
);
2500 rc
= SETUP_CreateInterfaceList(list
, machine
, class, enumstr
, flags
& DIGCF_PRESENT
);
2504 /* Determine which class(es) should be included in the deviceset */
2505 if (flags
& DIGCF_ALLCLASSES
)
2507 /* The caller wants all classes. Check if
2508 * the deviceset limits us to one class */
2509 if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2512 pClassGuid
= &list
->ClassGuid
;
2516 /* The caller wants one class. Check if it matches deviceset class */
2517 if (IsEqualIID(&list
->ClassGuid
, class)
2518 || IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2524 SetLastError(ERROR_INVALID_PARAMETER
);
2528 else if (!IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2530 /* No class specified. Try to use the one of the deviceset */
2531 if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2532 pClassGuid
= &list
->ClassGuid
;
2535 SetLastError(ERROR_INVALID_PARAMETER
);
2541 SetLastError(ERROR_INVALID_PARAMETER
);
2544 rc
= SETUP_CreateDevicesList(list
, machine
, pClassGuid
, enumstr
);
2546 if (rc
!= ERROR_SUCCESS
)
2554 if (!deviceset
&& hDeviceInfo
!= INVALID_HANDLE_VALUE
&& hDeviceInfo
!= set
)
2555 SetupDiDestroyDeviceInfoList(hDeviceInfo
);
2559 /***********************************************************************
2560 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2562 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2563 HDEVINFO DeviceInfoSet
,
2564 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2566 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2568 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2570 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2572 SetLastError(ERROR_INVALID_HANDLE
);
2575 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2577 SetLastError(ERROR_INVALID_HANDLE
);
2581 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2583 SetLastError(ERROR_INVALID_PARAMETER
);
2586 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2587 DevInfoData
->RemoteMachineHandle
= set
->hMachine
;
2588 if (set
->MachineName
)
2591 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2595 DevInfoData
->RemoteMachineName
[0] = 0;
2600 /***********************************************************************
2601 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2603 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2604 HDEVINFO DeviceInfoSet
,
2605 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2607 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2609 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2611 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2613 SetLastError(ERROR_INVALID_HANDLE
);
2616 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2618 SetLastError(ERROR_INVALID_HANDLE
);
2622 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2624 SetLastError(ERROR_INVALID_PARAMETER
);
2627 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2628 DevInfoData
->RemoteMachineHandle
= set
->hMachine
;
2629 if (set
->MachineName
)
2630 strcpyW(DevInfoData
->RemoteMachineName
, set
->MachineName
+ 2);
2632 DevInfoData
->RemoteMachineName
[0] = 0;
2637 /***********************************************************************
2638 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2640 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2641 HDEVINFO DeviceInfoSet
,
2642 PSP_DEVINFO_DATA DeviceInfoData
,
2643 const GUID
*InterfaceClassGuid
,
2644 PCSTR ReferenceString
,
2645 DWORD CreationFlags
,
2646 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2649 LPWSTR ReferenceStringW
= NULL
;
2651 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2652 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2653 CreationFlags
, DeviceInterfaceData
);
2655 if (ReferenceString
)
2657 ReferenceStringW
= pSetupMultiByteToUnicode(ReferenceString
, CP_ACP
);
2658 if (ReferenceStringW
== NULL
) return FALSE
;
2661 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2662 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2663 DeviceInterfaceData
);
2665 MyFree(ReferenceStringW
);
2670 /***********************************************************************
2671 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2673 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2674 HDEVINFO DeviceInfoSet
,
2675 PSP_DEVINFO_DATA DeviceInfoData
,
2676 const GUID
*InterfaceClassGuid
,
2677 PCWSTR ReferenceString
,
2678 DWORD CreationFlags
,
2679 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2681 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2682 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2683 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2684 CreationFlags
, DeviceInterfaceData
);
2686 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2688 SetLastError(ERROR_INVALID_HANDLE
);
2691 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2693 SetLastError(ERROR_INVALID_HANDLE
);
2696 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2697 || !DeviceInfoData
->Reserved
)
2699 SetLastError(ERROR_INVALID_PARAMETER
);
2702 if (!InterfaceClassGuid
)
2704 SetLastError(ERROR_INVALID_USER_BUFFER
);
2708 FIXME("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2709 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2710 CreationFlags
, DeviceInterfaceData
);
2711 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2715 /***********************************************************************
2716 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2718 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2719 HDEVINFO DeviceInfoSet
,
2720 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2724 PCSTR InfSectionName
)
2727 PWSTR InfSectionNameW
= NULL
;
2729 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2730 samDesired
, InfHandle
, InfSectionName
);
2733 if (!InfSectionName
)
2735 SetLastError(ERROR_INVALID_PARAMETER
);
2736 return INVALID_HANDLE_VALUE
;
2738 InfSectionNameW
= pSetupMultiByteToUnicode(InfSectionName
, CP_ACP
);
2739 if (!InfSectionNameW
)
2740 return INVALID_HANDLE_VALUE
;
2742 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2743 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2745 MyFree(InfSectionNameW
);
2749 /***********************************************************************
2750 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2752 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2753 HDEVINFO DeviceInfoSet
,
2754 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2758 PCWSTR InfSectionName
)
2761 LPWSTR SymbolicLink
;
2762 DWORD Length
, Index
;
2764 WCHAR bracedGuidString
[39];
2765 struct DeviceInterface
*DevItf
;
2766 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2768 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2769 samDesired
, InfHandle
, InfSectionName
);
2771 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2772 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2774 SetLastError(ERROR_INVALID_HANDLE
);
2775 return INVALID_HANDLE_VALUE
;
2777 if (!DeviceInterfaceData
||
2778 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2779 !DeviceInterfaceData
->Reserved
)
2781 SetLastError(ERROR_INVALID_PARAMETER
);
2782 return INVALID_HANDLE_VALUE
;
2784 if (InfHandle
&& !InfSectionName
)
2786 SetLastError(ERROR_INVALID_PARAMETER
);
2787 return INVALID_HANDLE_VALUE
;
2790 hKey
= SetupDiOpenClassRegKeyExW(&DeviceInterfaceData
->InterfaceClassGuid
, samDesired
, DIOCR_INTERFACE
, NULL
, NULL
);
2791 if (hKey
== INVALID_HANDLE_VALUE
)
2793 hKey
= SetupDiOpenClassRegKeyExW(NULL
, samDesired
, DIOCR_INTERFACE
, NULL
, NULL
);
2794 if (hKey
== INVALID_HANDLE_VALUE
)
2796 SetLastError(ERROR_INVALID_PARAMETER
);
2797 return INVALID_HANDLE_VALUE
;
2799 SETUPDI_GuidToString(&DeviceInterfaceData
->InterfaceClassGuid
, bracedGuidString
);
2801 if (RegCreateKeyExW(hKey
, bracedGuidString
, 0, NULL
, 0, samDesired
, NULL
, &hDevKey
, NULL
) != ERROR_SUCCESS
)
2803 SetLastError(ERROR_INVALID_PARAMETER
);
2804 return INVALID_HANDLE_VALUE
;
2810 DevItf
= (struct DeviceInterface
*)DeviceInterfaceData
->Reserved
;
2812 Length
= (wcslen(DevItf
->SymbolicLink
)+1) * sizeof(WCHAR
);
2813 SymbolicLink
= HeapAlloc(GetProcessHeap(), 0, Length
);
2817 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2818 return INVALID_HANDLE_VALUE
;
2821 wcscpy(SymbolicLink
, DevItf
->SymbolicLink
);
2824 while(SymbolicLink
[Index
])
2826 if (SymbolicLink
[Index
] == L
'\\')
2828 SymbolicLink
[Index
] = L
'#';
2833 rc
= RegCreateKeyExW(hKey
, SymbolicLink
, 0, NULL
, 0, samDesired
, NULL
, &hDevKey
, NULL
);
2836 HeapFree(GetProcessHeap(), 0, SymbolicLink
);
2838 if (rc
== ERROR_SUCCESS
)
2840 if (InfHandle
&& InfSectionName
)
2842 if (!SetupInstallFromInfSection(NULL
/*FIXME */,
2845 SPINST_INIFILES
| SPINST_REGISTRY
| SPINST_INI2REG
| SPINST_FILES
| SPINST_BITREG
| SPINST_REGSVR
| SPINST_UNREGSVR
| SPINST_PROFILEITEMS
| SPINST_COPYINF
,
2849 set
->SelectedDevice
->InstallParams
.InstallMsgHandler
,
2850 set
->SelectedDevice
->InstallParams
.InstallMsgHandlerContext
,
2851 INVALID_HANDLE_VALUE
,
2854 RegCloseKey(hDevKey
);
2855 return INVALID_HANDLE_VALUE
;
2864 /***********************************************************************
2865 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2867 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2868 HDEVINFO DeviceInfoSet
,
2869 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2872 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2875 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
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
);
2891 FIXME("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2892 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2896 /***********************************************************************
2897 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2900 * DeviceInfoSet [I] Set of devices from which to enumerate
2902 * DeviceInfoData [I] (Optional) If specified, a specific device
2903 * instance from which to enumerate interfaces.
2904 * If it isn't specified, all interfaces for all
2905 * devices in the set are enumerated.
2906 * InterfaceClassGuid [I] The interface class to enumerate.
2907 * MemberIndex [I] An index of the interface instance to enumerate.
2908 * A caller should start with MemberIndex set to 0,
2909 * and continue until the function fails with
2910 * ERROR_NO_MORE_ITEMS.
2911 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2912 * member must be set to
2913 * sizeof(SP_DEVICE_INTERFACE_DATA).
2916 * Success: non-zero value.
2917 * Failure: FALSE. Call GetLastError() for more info.
2919 BOOL WINAPI
SetupDiEnumDeviceInterfaces(
2920 HDEVINFO DeviceInfoSet
,
2921 PSP_DEVINFO_DATA DeviceInfoData
,
2922 CONST GUID
* InterfaceClassGuid
,
2924 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2926 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2929 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet
, DeviceInfoData
,
2930 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
2932 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2933 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2935 SetLastError(ERROR_INVALID_HANDLE
);
2938 if (DeviceInfoData
&& (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2939 !DeviceInfoData
->Reserved
))
2941 SetLastError(ERROR_INVALID_PARAMETER
);
2944 if (!DeviceInterfaceData
||
2945 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2947 SetLastError(ERROR_INVALID_PARAMETER
);
2952 struct DeviceInfo
*devInfo
=
2953 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2955 PLIST_ENTRY InterfaceListEntry
= devInfo
->InterfaceListHead
.Flink
;
2956 while (InterfaceListEntry
!= &devInfo
->InterfaceListHead
&& !found
)
2958 struct DeviceInterface
*DevItf
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
2959 if (!IsEqualIID(&DevItf
->InterfaceClassGuid
, InterfaceClassGuid
))
2961 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2964 if (MemberIndex
-- == 0)
2966 /* return this item */
2967 memcpy(&DeviceInterfaceData
->InterfaceClassGuid
,
2968 &DevItf
->InterfaceClassGuid
,
2970 DeviceInterfaceData
->Flags
= DevItf
->Flags
;
2971 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)DevItf
;
2975 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2978 SetLastError(ERROR_NO_MORE_ITEMS
);
2983 PLIST_ENTRY ItemList
= set
->ListHead
.Flink
;
2984 while (ItemList
!= &set
->ListHead
&& !found
)
2986 PLIST_ENTRY InterfaceListEntry
;
2987 struct DeviceInfo
*devInfo
=
2988 CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
2989 InterfaceListEntry
= devInfo
->InterfaceListHead
.Flink
;
2990 while (InterfaceListEntry
!= &devInfo
->InterfaceListHead
&& !found
)
2992 struct DeviceInterface
*DevItf
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
2993 if (!IsEqualIID(&DevItf
->InterfaceClassGuid
, InterfaceClassGuid
))
2995 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2998 if (MemberIndex
-- == 0)
3000 /* return this item */
3001 memcpy(&DeviceInterfaceData
->InterfaceClassGuid
,
3002 &DevItf
->InterfaceClassGuid
,
3004 DeviceInterfaceData
->Flags
= DevItf
->Flags
;
3005 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)DevItf
;
3009 InterfaceListEntry
= InterfaceListEntry
->Flink
;
3011 ItemList
= ItemList
->Flink
;
3015 SetLastError(ERROR_NO_MORE_ITEMS
);
3020 /***********************************************************************
3021 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
3023 * Destroy a DeviceInfoList and free all used memory of the list.
3026 * devinfo [I] DeviceInfoList pointer to list to destroy
3029 * Success: non zero value.
3030 * Failure: zero value.
3032 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
3036 TRACE("%p\n", devinfo
);
3037 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
3039 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
3041 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
3043 ret
= DestroyDeviceInfoSet(list
);
3048 SetLastError(ERROR_INVALID_HANDLE
);
3053 /***********************************************************************
3054 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
3056 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
3057 HDEVINFO DeviceInfoSet
,
3058 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
3059 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
3060 DWORD DeviceInterfaceDetailDataSize
,
3061 PDWORD RequiredSize
,
3062 PSP_DEVINFO_DATA DeviceInfoData
)
3064 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3065 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailDataW
= NULL
;
3066 DWORD sizeW
= 0, bytesNeeded
;
3069 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
3070 DeviceInterfaceData
, DeviceInterfaceDetailData
,
3071 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
3073 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
3074 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3076 SetLastError(ERROR_INVALID_HANDLE
);
3079 if (!DeviceInterfaceData
||
3080 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
3081 !DeviceInterfaceData
->Reserved
)
3083 SetLastError(ERROR_INVALID_PARAMETER
);
3086 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
)))
3088 SetLastError(ERROR_INVALID_USER_BUFFER
);
3092 if((DeviceInterfaceDetailDataSize
!= 0) &&
3093 (DeviceInterfaceDetailDataSize
< (FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + sizeof(CHAR
))))
3095 SetLastError(ERROR_INVALID_USER_BUFFER
);
3099 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
3101 SetLastError(ERROR_INVALID_USER_BUFFER
);
3106 if (DeviceInterfaceDetailData
!= NULL
)
3108 sizeW
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
3109 + (DeviceInterfaceDetailDataSize
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
)) * sizeof(WCHAR
);
3110 DeviceInterfaceDetailDataW
= (PSP_DEVICE_INTERFACE_DETAIL_DATA_W
)MyMalloc(sizeW
);
3111 if (!DeviceInterfaceDetailDataW
)
3113 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3115 DeviceInterfaceDetailDataW
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
);
3117 if (!DeviceInterfaceDetailData
|| (DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataW
))
3119 ret
= SetupDiGetDeviceInterfaceDetailW(
3121 DeviceInterfaceData
,
3122 DeviceInterfaceDetailDataW
,
3126 bytesNeeded
= (sizeW
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)) / sizeof(WCHAR
)
3127 + FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
);
3129 *RequiredSize
= bytesNeeded
;
3130 if (ret
&& DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
>= bytesNeeded
)
3132 if (!WideCharToMultiByte(
3134 DeviceInterfaceDetailDataW
->DevicePath
, -1,
3135 DeviceInterfaceDetailData
->DevicePath
, DeviceInterfaceDetailDataSize
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
3142 MyFree(DeviceInterfaceDetailDataW
);
3147 /***********************************************************************
3148 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
3150 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
3151 HDEVINFO DeviceInfoSet
,
3152 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
3153 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
3154 DWORD DeviceInterfaceDetailDataSize
,
3155 PDWORD RequiredSize
,
3156 PSP_DEVINFO_DATA DeviceInfoData
)
3158 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3161 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
3162 DeviceInterfaceData
, DeviceInterfaceDetailData
,
3163 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
3165 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
3166 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3168 SetLastError(ERROR_INVALID_HANDLE
);
3171 if (!DeviceInterfaceData
||
3172 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
3173 !DeviceInterfaceData
->Reserved
)
3175 SetLastError(ERROR_INVALID_PARAMETER
);
3178 if (DeviceInterfaceDetailData
&& DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
))
3180 SetLastError(ERROR_INVALID_USER_BUFFER
);
3183 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
3185 SetLastError(ERROR_INVALID_USER_BUFFER
);
3188 if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
3190 SetLastError(ERROR_INVALID_PARAMETER
);
3193 if ((DeviceInterfaceDetailData
!= NULL
)
3194 && (DeviceInterfaceDetailDataSize
< (FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)) + sizeof(WCHAR
)))
3196 SetLastError(ERROR_INVALID_PARAMETER
);
3201 struct DeviceInterface
*deviceInterface
= (struct DeviceInterface
*)DeviceInterfaceData
->Reserved
;
3202 LPCWSTR devName
= deviceInterface
->SymbolicLink
;
3203 DWORD sizeRequired
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
) +
3204 (lstrlenW(devName
) + 1) * sizeof(WCHAR
);
3206 if (sizeRequired
> DeviceInterfaceDetailDataSize
)
3208 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3210 *RequiredSize
= sizeRequired
;
3214 strcpyW(DeviceInterfaceDetailData
->DevicePath
, devName
);
3215 TRACE("DevicePath is %s\n", debugstr_w(DeviceInterfaceDetailData
->DevicePath
));
3218 memcpy(&DeviceInfoData
->ClassGuid
,
3219 &deviceInterface
->DeviceInfo
->ClassGuid
,
3221 DeviceInfoData
->DevInst
= deviceInterface
->DeviceInfo
->dnDevInst
;
3222 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInterface
->DeviceInfo
;
3230 struct PropertyMapEntry
3237 static struct PropertyMapEntry PropertyMap
[] = {
3238 { REG_SZ
, "DeviceDesc", REGSTR_VAL_DEVDESC
},
3239 { REG_MULTI_SZ
, "HardwareId", REGSTR_VAL_HARDWAREID
},
3240 { REG_MULTI_SZ
, "CompatibleIDs", REGSTR_VAL_COMPATIBLEIDS
},
3241 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
3242 { REG_SZ
, "Service", REGSTR_VAL_SERVICE
},
3243 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
3244 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
3245 { REG_SZ
, "Class", REGSTR_VAL_CLASS
},
3246 { REG_SZ
, "ClassGUID", REGSTR_VAL_CLASSGUID
},
3247 { REG_SZ
, "Driver", REGSTR_VAL_DRIVER
},
3248 { REG_DWORD
, "ConfigFlags", REGSTR_VAL_CONFIGFLAGS
},
3249 { REG_SZ
, "Mfg", REGSTR_VAL_MFG
},
3250 { REG_SZ
, "FriendlyName", REGSTR_VAL_FRIENDLYNAME
},
3251 { REG_SZ
, "LocationInformation", REGSTR_VAL_LOCATION_INFORMATION
},
3252 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3253 { REG_DWORD
, "Capabilities", REGSTR_VAL_CAPABILITIES
},
3254 { REG_DWORD
, "UINumber", REGSTR_VAL_UI_NUMBER
},
3255 { REG_MULTI_SZ
, "UpperFilters", REGSTR_VAL_UPPERFILTERS
},
3256 { REG_MULTI_SZ
, "LowerFilters", REGSTR_VAL_LOWERFILTERS
},
3257 { 0, NULL
, NULL
}, /* SPDRP_BUSTYPEGUID */
3258 { 0, NULL
, NULL
}, /* SPDRP_LEGACYBUSTYPE */
3259 { 0, NULL
, NULL
}, /* SPDRP_BUSNUMBER */
3260 { 0, NULL
, NULL
}, /* SPDRP_ENUMERATOR_NAME */
3261 { REG_BINARY
, "Security", REGSTR_SECURITY
},
3262 { 0, NULL
, NULL
}, /* SPDRP_SECURITY_SDS */
3263 { 0, NULL
, NULL
}, /* SPDRP_DEVTYPE */
3264 { 0, NULL
, NULL
}, /* SPDRP_EXCLUSIVE */
3265 { 0, NULL
, NULL
}, /* SPDRP_CHARACTERISTICS */
3266 { 0, NULL
, NULL
}, /* SPDRP_ADDRESS */
3267 { REG_SZ
, "UINumberDescFormat", REGSTR_UI_NUMBER_DESC_FORMAT
},
3268 { 0, NULL
, NULL
}, /* SPDRP_DEVICE_POWER_DATA */
3269 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY */
3270 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY_HW_DEFAULT */
3271 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY_OVERRIDE */
3272 { 0, NULL
, NULL
}, /* SPDRP_INSTALL_STATE */
3275 /***********************************************************************
3276 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3278 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
3279 HDEVINFO DeviceInfoSet
,
3280 PSP_DEVINFO_DATA DeviceInfoData
,
3282 PDWORD PropertyRegDataType
,
3283 PBYTE PropertyBuffer
,
3284 DWORD PropertyBufferSize
,
3285 PDWORD RequiredSize
)
3288 BOOL bIsStringProperty
;
3290 DWORD RequiredSizeA
, RequiredSizeW
;
3291 DWORD PropertyBufferSizeW
= 0;
3292 PBYTE PropertyBufferW
= NULL
;
3294 TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
,
3295 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3298 if (PropertyBufferSize
!= 0)
3300 PropertyBufferSizeW
= PropertyBufferSize
* 2;
3301 PropertyBufferW
= HeapAlloc(GetProcessHeap(), 0, PropertyBufferSizeW
);
3302 if (!PropertyBufferW
)
3304 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3309 ret
= SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet
,
3314 PropertyBufferSizeW
,
3317 if (ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
3319 bIsStringProperty
= (RegType
== REG_SZ
|| RegType
== REG_MULTI_SZ
|| RegType
== REG_EXPAND_SZ
);
3321 if (bIsStringProperty
)
3322 RequiredSizeA
= RequiredSizeW
/ sizeof(WCHAR
);
3324 RequiredSizeA
= RequiredSizeW
;
3326 *RequiredSize
= RequiredSizeA
;
3327 if (PropertyRegDataType
)
3328 *PropertyRegDataType
= RegType
;
3333 HeapFree(GetProcessHeap(), 0, PropertyBufferW
);
3337 if (RequiredSizeA
<= PropertyBufferSize
)
3339 if (bIsStringProperty
&& PropertyBufferSize
> 0)
3341 if (WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)PropertyBufferW
, RequiredSizeW
/ sizeof(WCHAR
), (LPSTR
)PropertyBuffer
, PropertyBufferSize
, NULL
, NULL
) == 0)
3343 /* Last error is already set by WideCharToMultiByte */
3348 memcpy(PropertyBuffer
, PropertyBufferW
, RequiredSizeA
);
3352 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3356 HeapFree(GetProcessHeap(), 0, PropertyBufferW
);
3360 /***********************************************************************
3361 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3363 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3364 HDEVINFO DeviceInfoSet
,
3365 PSP_DEVINFO_DATA DeviceInfoData
,
3367 PDWORD PropertyRegDataType
,
3368 PBYTE PropertyBuffer
,
3369 DWORD PropertyBufferSize
,
3370 PDWORD RequiredSize
)
3373 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3374 struct DeviceInfo
*devInfo
;
3376 TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
,
3377 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3380 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3382 SetLastError(ERROR_INVALID_HANDLE
);
3385 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3387 SetLastError(ERROR_INVALID_HANDLE
);
3390 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3391 || !DeviceInfoData
->Reserved
)
3393 SetLastError(ERROR_INVALID_PARAMETER
);
3396 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3397 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3398 && PropertyMap
[Property
].nameW
)
3400 DWORD size
= PropertyBufferSize
;
3403 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_QUERY_VALUE
);
3404 if (hKey
== INVALID_HANDLE_VALUE
)
3406 l
= RegQueryValueExW(hKey
, PropertyMap
[Property
].nameW
,
3407 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3411 *RequiredSize
= size
;
3414 if (PropertyBuffer
!= NULL
|| size
== 0)
3417 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3419 case ERROR_MORE_DATA
:
3420 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3426 else if (Property
== SPDRP_PHYSICAL_DEVICE_OBJECT_NAME
)
3428 DWORD required
= (strlenW(devInfo
->Data
) + 1) * sizeof(WCHAR
);
3430 if (PropertyRegDataType
)
3431 *PropertyRegDataType
= REG_SZ
;
3433 *RequiredSize
= required
;
3434 if (PropertyBufferSize
>= required
)
3436 strcpyW((LPWSTR
)PropertyBuffer
, devInfo
->Data
);
3440 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3444 ERR("Property 0x%lx not implemented\n", Property
);
3445 SetLastError(ERROR_NOT_SUPPORTED
);
3450 /***********************************************************************
3451 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3453 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3454 HDEVINFO DeviceInfoSet
,
3455 PSP_DEVINFO_DATA DeviceInfoData
,
3457 const BYTE
*PropertyBuffer
,
3458 DWORD PropertyBufferSize
)
3461 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3463 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3464 PropertyBuffer
, PropertyBufferSize
);
3466 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3468 SetLastError(ERROR_INVALID_HANDLE
);
3471 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3473 SetLastError(ERROR_INVALID_HANDLE
);
3476 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3477 || !DeviceInfoData
->Reserved
)
3479 SetLastError(ERROR_INVALID_PARAMETER
);
3483 FIXME("%p %p 0x%lx %p 0x%lx\n", DeviceInfoSet
, DeviceInfoData
,
3484 Property
, PropertyBuffer
, PropertyBufferSize
);
3485 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3489 /***********************************************************************
3490 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3492 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
3493 HDEVINFO DeviceInfoSet
,
3494 PSP_DEVINFO_DATA DeviceInfoData
,
3496 const BYTE
*PropertyBuffer
,
3497 DWORD PropertyBufferSize
)
3500 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3502 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3503 PropertyBuffer
, PropertyBufferSize
);
3505 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3507 SetLastError(ERROR_INVALID_HANDLE
);
3510 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3512 SetLastError(ERROR_INVALID_HANDLE
);
3515 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3516 || !DeviceInfoData
->Reserved
)
3518 SetLastError(ERROR_INVALID_PARAMETER
);
3521 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3522 && PropertyMap
[Property
].nameW
)
3526 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_SET_VALUE
);
3527 if (hKey
== INVALID_HANDLE_VALUE
)
3529 /* Write new data */
3531 hKey
, PropertyMap
[Property
].nameW
, 0,
3532 PropertyMap
[Property
].regType
, PropertyBuffer
,
3533 PropertyBufferSize
);
3542 ERR("Property 0x%lx not implemented\n", Property
);
3543 SetLastError(ERROR_NOT_SUPPORTED
);
3546 TRACE("Returning %d\n", ret
);
3550 /***********************************************************************
3551 * SetupDiInstallClassA (SETUPAPI.@)
3553 BOOL WINAPI
SetupDiInstallClassA(
3559 return SetupDiInstallClassExA(hwndParent
, InfFileName
, Flags
, FileQueue
, NULL
, NULL
, NULL
);
3562 /***********************************************************************
3563 * SetupDiInstallClassExA (SETUPAPI.@)
3566 SetupDiInstallClassExA(
3567 IN HWND hwndParent OPTIONAL
,
3568 IN PCSTR InfFileName OPTIONAL
,
3570 IN HSPFILEQ FileQueue OPTIONAL
,
3571 IN CONST GUID
*InterfaceClassGuid OPTIONAL
,
3575 PWSTR InfFileNameW
= NULL
;
3580 SetLastError(ERROR_INVALID_PARAMETER
);
3585 InfFileNameW
= pSetupMultiByteToUnicode(InfFileName
, CP_ACP
);
3586 if (InfFileNameW
== NULL
)
3588 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3593 Result
= SetupDiInstallClassExW(hwndParent
, InfFileNameW
, Flags
,
3594 FileQueue
, InterfaceClassGuid
, Reserved1
, Reserved2
);
3596 MyFree(InfFileNameW
);
3601 HKEY
SETUP_CreateClassKey(HINF hInf
)
3603 static const WCHAR slash
[] = { '\\',0 };
3604 WCHAR FullBuffer
[MAX_PATH
];
3605 WCHAR Buffer
[MAX_PATH
];
3609 if (!SetupGetLineTextW(NULL
,
3617 return INVALID_HANDLE_VALUE
;
3620 lstrcpyW(FullBuffer
, REGSTR_PATH_CLASS_NT
);
3621 lstrcatW(FullBuffer
, slash
);
3622 lstrcatW(FullBuffer
, Buffer
);
3624 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3630 if (!SetupGetLineTextW(NULL
,
3638 return INVALID_HANDLE_VALUE
;
3641 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3645 REG_OPTION_NON_VOLATILE
,
3651 return INVALID_HANDLE_VALUE
;
3655 if (RegSetValueExW(hClassKey
,
3660 RequiredSize
* sizeof(WCHAR
)))
3662 RegCloseKey(hClassKey
);
3663 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3665 return INVALID_HANDLE_VALUE
;
3671 /***********************************************************************
3672 * SetupDiInstallClassW (SETUPAPI.@)
3674 BOOL WINAPI
SetupDiInstallClassW(
3680 return SetupDiInstallClassExW(hwndParent
, InfFileName
, Flags
, FileQueue
, NULL
, NULL
, NULL
);
3684 /***********************************************************************
3685 * SetupDiOpenClassRegKey (SETUPAPI.@)
3687 HKEY WINAPI
SetupDiOpenClassRegKey(
3688 const GUID
* ClassGuid
,
3691 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3692 DIOCR_INSTALLER
, NULL
, NULL
);
3696 /***********************************************************************
3697 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3699 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3700 const GUID
* ClassGuid
,
3706 PWSTR MachineNameW
= NULL
;
3709 TRACE("%s 0x%lx 0x%lx %s %p\n", debugstr_guid(ClassGuid
), samDesired
,
3710 Flags
, debugstr_a(MachineName
), Reserved
);
3714 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
3715 if (MachineNameW
== NULL
)
3716 return INVALID_HANDLE_VALUE
;
3719 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3720 Flags
, MachineNameW
, Reserved
);
3722 MyFree(MachineNameW
);
3728 /***********************************************************************
3729 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3731 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3732 const GUID
* ClassGuid
,
3744 TRACE("%s 0x%lx 0x%lx %s %p\n", debugstr_guid(ClassGuid
), samDesired
,
3745 Flags
, debugstr_w(MachineName
), Reserved
);
3747 if (MachineName
!= NULL
)
3749 l
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &HKLM
);
3750 if (l
!= ERROR_SUCCESS
)
3753 return INVALID_HANDLE_VALUE
;
3757 HKLM
= HKEY_LOCAL_MACHINE
;
3759 if (Flags
== DIOCR_INSTALLER
)
3761 lpKeyName
= REGSTR_PATH_CLASS_NT
;
3763 else if (Flags
== DIOCR_INTERFACE
)
3765 lpKeyName
= REGSTR_PATH_DEVICE_CLASSES
;
3769 ERR("Invalid Flags parameter!\n");
3770 SetLastError(ERROR_INVALID_FLAGS
);
3771 if (MachineName
!= NULL
) RegCloseKey(HKLM
);
3772 return INVALID_HANDLE_VALUE
;
3777 if ((l
= RegOpenKeyExW(HKLM
,
3783 SetLastError(ERROR_INVALID_CLASS
);
3784 hClassesKey
= INVALID_HANDLE_VALUE
;
3786 if (MachineName
!= NULL
)
3792 WCHAR bracedGuidString
[39];
3794 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3796 if (!(l
= RegOpenKeyExW(HKLM
,
3802 if (MachineName
!= NULL
)
3805 if ((l
= RegOpenKeyExW(hClassesKey
,
3812 key
= INVALID_HANDLE_VALUE
;
3814 RegCloseKey(hClassesKey
);
3818 if (MachineName
!= NULL
) RegCloseKey(HKLM
);
3820 key
= INVALID_HANDLE_VALUE
;
3827 /***********************************************************************
3828 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3830 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3831 HDEVINFO DeviceInfoSet
,
3834 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3836 struct DeviceInfoSet
* list
;
3838 DWORD dwLength
, dwError
, dwIndex
, dwKeyName
, dwSubIndex
;
3840 WCHAR Buffer
[MAX_PATH
+ 1];
3841 WCHAR SymBuffer
[MAX_PATH
+ 1];
3842 WCHAR InstancePath
[MAX_PATH
+ 1];
3843 HKEY hKey
, hDevKey
, hSymKey
;
3844 struct DeviceInfo
* deviceInfo
;
3845 struct DeviceInterface
*deviceInterface
;
3847 PLIST_ENTRY ItemList
;
3848 PLIST_ENTRY InterfaceListEntry
;
3850 TRACE("%p %s %08x %p\n",
3851 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3854 if (DeviceInterfaceData
&& DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
3856 SetLastError(ERROR_INVALID_PARAMETER
);
3860 if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3862 SetLastError(ERROR_INVALID_HANDLE
);
3866 list
= (struct DeviceInfoSet
* )DeviceInfoSet
;
3868 dwLength
= wcslen(DevicePath
);
3871 /* path must be at least a guid length + L'\0' */
3872 SetLastError(ERROR_BAD_PATHNAME
);
3876 if (DevicePath
[0] != L
'\\' ||
3877 DevicePath
[1] != L
'\\' ||
3878 (DevicePath
[2] != L
'?' && DevicePath
[2] != L
'.') ||
3879 DevicePath
[3] != L
'\\')
3881 /* invalid formatted path */
3882 SetLastError(ERROR_BAD_PATHNAME
);
3886 /* check for reference strings */
3887 pEnd
= wcschr(&DevicePath
[4], L
'\\');
3890 /* no reference string */
3891 pEnd
= DevicePath
+ dwLength
;
3895 wcscpy(Buffer
, pEnd
- 37);
3898 dwError
= UuidFromStringW(Buffer
, &ClassId
);
3899 if (dwError
!= NOERROR
)
3901 /* invalid formatted path */
3902 SetLastError(ERROR_BAD_PATHNAME
);
3906 hKey
= SetupDiOpenClassRegKeyExW(&ClassId
, KEY_READ
, DIOCR_INTERFACE
, list
->MachineName
, NULL
);
3908 if (hKey
== INVALID_HANDLE_VALUE
)
3910 /* invalid device class */
3914 ItemList
= list
->ListHead
.Flink
;
3915 while (ItemList
!= &list
->ListHead
)
3917 deviceInfo
= CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
3918 InterfaceListEntry
= deviceInfo
->InterfaceListHead
.Flink
;
3919 while (InterfaceListEntry
!= &deviceInfo
->InterfaceListHead
)
3921 deviceInterface
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
3922 if (!IsEqualIID(&deviceInterface
->InterfaceClassGuid
, &ClassId
))
3924 InterfaceListEntry
= InterfaceListEntry
->Flink
;
3928 if (!wcsicmp(deviceInterface
->SymbolicLink
, DevicePath
))
3930 if (DeviceInterfaceData
)
3932 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)deviceInterface
;
3933 DeviceInterfaceData
->Flags
= deviceInterface
->Flags
;
3934 CopyMemory(&DeviceInterfaceData
->InterfaceClassGuid
, &ClassId
, sizeof(GUID
));
3948 dwKeyName
= sizeof(Buffer
) / sizeof(WCHAR
);
3949 dwError
= RegEnumKeyExW(hKey
, dwIndex
, Buffer
, &dwKeyName
, NULL
, NULL
, NULL
, NULL
);
3951 if (dwError
!= ERROR_SUCCESS
)
3954 if (RegOpenKeyExW(hKey
, Buffer
, 0, KEY_READ
, &hDevKey
) != ERROR_SUCCESS
)
3958 InstancePath
[0] = 0;
3959 dwKeyName
= sizeof(InstancePath
);
3961 dwError
= RegQueryValueExW(hDevKey
, L
"DeviceInstance", NULL
, NULL
, (LPBYTE
)InstancePath
, &dwKeyName
);
3966 dwKeyName
= sizeof(Buffer
) / sizeof(WCHAR
);
3967 dwError
= RegEnumKeyExW(hDevKey
, dwSubIndex
, Buffer
, &dwKeyName
, NULL
, NULL
, NULL
, NULL
);
3969 if (dwError
!= ERROR_SUCCESS
)
3972 dwError
= RegOpenKeyExW(hDevKey
, Buffer
, 0, KEY_READ
, &hSymKey
);
3973 if (dwError
!= ERROR_SUCCESS
)
3976 /* query for symbolic link */
3977 dwKeyName
= sizeof(SymBuffer
);
3978 SymBuffer
[0] = L
'\0';
3979 dwError
= RegQueryValueExW(hSymKey
, L
"SymbolicLink", NULL
, NULL
, (LPBYTE
)SymBuffer
, &dwKeyName
);
3981 if (dwError
!= ERROR_SUCCESS
)
3983 RegCloseKey(hSymKey
);
3987 if (!wcsicmp(SymBuffer
, DevicePath
))
3989 Ret
= CreateDeviceInfo(list
, InstancePath
, &ClassId
, &deviceInfo
);
3990 RegCloseKey(hSymKey
);
3991 RegCloseKey(hDevKey
);
3996 deviceInterface
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct DeviceInterface
) + (wcslen(SymBuffer
) + 1) * sizeof(WCHAR
));
3997 if (deviceInterface
)
4000 CopyMemory(&deviceInterface
->InterfaceClassGuid
, &ClassId
, sizeof(GUID
));
4001 deviceInterface
->DeviceInfo
= deviceInfo
;
4002 deviceInterface
->Flags
= SPINT_ACTIVE
; //FIXME
4004 wcscpy(deviceInterface
->SymbolicLink
, SymBuffer
);
4006 InsertTailList(&deviceInfo
->InterfaceListHead
, &deviceInterface
->ListEntry
);
4007 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
4010 if (DeviceInterfaceData
)
4012 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)deviceInterface
;
4013 DeviceInterfaceData
->Flags
= deviceInterface
->Flags
;
4014 CopyMemory(&DeviceInterfaceData
->InterfaceClassGuid
, &ClassId
, sizeof(GUID
));
4019 SetLastError(ERROR_INVALID_USER_BUFFER
);
4025 HeapFree(GetProcessHeap(), 0, deviceInfo
);
4030 RegCloseKey(hSymKey
);
4034 RegCloseKey(hDevKey
);
4042 /***********************************************************************
4043 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
4045 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
4046 HDEVINFO DeviceInfoSet
,
4049 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
4051 LPWSTR DevicePathW
= NULL
;
4054 TRACE("%p %s %08lx %p\n", DeviceInfoSet
, debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
4056 DevicePathW
= pSetupMultiByteToUnicode(DevicePath
, CP_ACP
);
4057 if (DevicePathW
== NULL
)
4060 bResult
= SetupDiOpenDeviceInterfaceW(DeviceInfoSet
,
4061 DevicePathW
, OpenFlags
, DeviceInterfaceData
);
4063 MyFree(DevicePathW
);
4068 /***********************************************************************
4069 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
4071 BOOL WINAPI
SetupDiSetClassInstallParamsA(
4072 HDEVINFO DeviceInfoSet
,
4073 PSP_DEVINFO_DATA DeviceInfoData
,
4074 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
4075 DWORD ClassInstallParamsSize
)
4077 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
4078 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
4083 IntSetupDiRegisterDeviceInfo(
4084 IN HDEVINFO DeviceInfoSet
,
4085 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
4087 return SetupDiRegisterDeviceInfo(DeviceInfoSet
, DeviceInfoData
, 0, NULL
, NULL
, NULL
);
4090 /***********************************************************************
4091 * SetupDiCallClassInstaller (SETUPAPI.@)
4093 BOOL WINAPI
SetupDiCallClassInstaller(
4094 DI_FUNCTION InstallFunction
,
4095 HDEVINFO DeviceInfoSet
,
4096 PSP_DEVINFO_DATA DeviceInfoData
)
4100 TRACE("%u %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
4103 SetLastError(ERROR_INVALID_PARAMETER
);
4104 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
4105 SetLastError(ERROR_INVALID_HANDLE
);
4106 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4107 SetLastError(ERROR_INVALID_HANDLE
);
4108 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->HKLM
!= HKEY_LOCAL_MACHINE
)
4109 SetLastError(ERROR_INVALID_HANDLE
);
4110 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4111 SetLastError(ERROR_INVALID_USER_BUFFER
);
4114 SP_DEVINSTALL_PARAMS_W InstallParams
;
4115 #define CLASS_COINSTALLER 0x1
4116 #define DEVICE_COINSTALLER 0x2
4117 #define CLASS_INSTALLER 0x4
4118 UCHAR CanHandle
= 0;
4119 DEFAULT_CLASS_INSTALL_PROC DefaultHandler
= NULL
;
4121 switch (InstallFunction
)
4123 case DIF_ADDPROPERTYPAGE_ADVANCED
:
4124 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4126 case DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
4127 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4129 case DIF_ALLOW_INSTALL
:
4130 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4133 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4135 case DIF_DESTROYPRIVATEDATA
:
4136 CanHandle
= CLASS_INSTALLER
;
4138 case DIF_INSTALLDEVICE
:
4139 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4140 DefaultHandler
= SetupDiInstallDevice
;
4142 case DIF_INSTALLDEVICEFILES
:
4143 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4144 DefaultHandler
= SetupDiInstallDriverFiles
;
4146 case DIF_INSTALLINTERFACES
:
4147 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4148 DefaultHandler
= SetupDiInstallDeviceInterfaces
;
4150 case DIF_NEWDEVICEWIZARD_FINISHINSTALL
:
4151 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4153 case DIF_NEWDEVICEWIZARD_POSTANALYZE
:
4154 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4156 case DIF_NEWDEVICEWIZARD_PREANALYZE
:
4157 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4159 case DIF_NEWDEVICEWIZARD_PRESELECT
:
4160 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4162 case DIF_NEWDEVICEWIZARD_SELECT
:
4163 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4165 case DIF_POWERMESSAGEWAKE
:
4166 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4168 case DIF_PROPERTYCHANGE
:
4169 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4170 DefaultHandler
= SetupDiChangeState
;
4172 case DIF_REGISTER_COINSTALLERS
:
4173 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4174 DefaultHandler
= SetupDiRegisterCoDeviceInstallers
;
4176 case DIF_REGISTERDEVICE
:
4177 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4178 DefaultHandler
= IntSetupDiRegisterDeviceInfo
;
4181 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4182 DefaultHandler
= SetupDiRemoveDevice
;
4184 case DIF_SELECTBESTCOMPATDRV
:
4185 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4186 DefaultHandler
= SetupDiSelectBestCompatDrv
;
4188 case DIF_SELECTDEVICE
:
4189 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4190 DefaultHandler
= SetupDiSelectDevice
;
4192 case DIF_TROUBLESHOOTER
:
4193 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4196 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4197 DefaultHandler
= SetupDiUnremoveDevice
;
4200 ERR("Install function %u not supported\n", InstallFunction
);
4201 SetLastError(ERROR_NOT_SUPPORTED
);
4204 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4205 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
))
4206 /* Don't process this call, as a parameter is invalid */
4211 LIST_ENTRY ClassCoInstallersListHead
;
4212 LIST_ENTRY DeviceCoInstallersListHead
;
4213 HMODULE ClassInstallerLibrary
= NULL
;
4214 CLASS_INSTALL_PROC ClassInstaller
= NULL
;
4215 COINSTALLER_CONTEXT_DATA Context
;
4216 PLIST_ENTRY ListEntry
;
4218 DWORD dwRegType
, dwLength
;
4219 DWORD rc
= NO_ERROR
;
4221 InitializeListHead(&ClassCoInstallersListHead
);
4222 InitializeListHead(&DeviceCoInstallersListHead
);
4224 if (CanHandle
& DEVICE_COINSTALLER
)
4226 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_QUERY_VALUE
);
4227 if (hKey
!= INVALID_HANDLE_VALUE
)
4229 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_COINSTALLERS_32
, NULL
, &dwRegType
, NULL
, &dwLength
);
4230 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_MULTI_SZ
)
4232 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
4233 if (KeyBuffer
!= NULL
)
4235 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_COINSTALLERS_32
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
4236 if (rc
== ERROR_SUCCESS
)
4239 for (ptr
= KeyBuffer
; *ptr
; ptr
+= strlenW(ptr
) + 1)
4241 /* Add coinstaller to DeviceCoInstallersListHead list */
4242 struct CoInstallerElement
*coinstaller
;
4243 TRACE("Got device coinstaller '%s'\n", debugstr_w(ptr
));
4244 coinstaller
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CoInstallerElement
));
4247 ZeroMemory(coinstaller
, sizeof(struct CoInstallerElement
));
4248 if (GetFunctionPointer(ptr
, &coinstaller
->Module
, (PVOID
*)&coinstaller
->Function
) == ERROR_SUCCESS
)
4249 InsertTailList(&DeviceCoInstallersListHead
, &coinstaller
->ListEntry
);
4251 HeapFree(GetProcessHeap(), 0, coinstaller
);
4254 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
4260 if (CanHandle
& CLASS_COINSTALLER
)
4264 REGSTR_PATH_CODEVICEINSTALLERS
,
4268 if (rc
== ERROR_SUCCESS
)
4270 LPWSTR lpGuidString
;
4271 if (UuidToStringW((UUID
*)&DeviceInfoData
->ClassGuid
, &lpGuidString
) == RPC_S_OK
)
4273 rc
= RegQueryValueExW(hKey
, lpGuidString
, NULL
, &dwRegType
, NULL
, &dwLength
);
4274 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_MULTI_SZ
)
4276 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
4277 if (KeyBuffer
!= NULL
)
4279 rc
= RegQueryValueExW(hKey
, lpGuidString
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
4280 if (rc
== ERROR_SUCCESS
)
4283 for (ptr
= KeyBuffer
; *ptr
; ptr
+= strlenW(ptr
) + 1)
4285 /* Add coinstaller to ClassCoInstallersListHead list */
4286 struct CoInstallerElement
*coinstaller
;
4287 TRACE("Got class coinstaller '%s'\n", debugstr_w(ptr
));
4288 coinstaller
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CoInstallerElement
));
4291 ZeroMemory(coinstaller
, sizeof(struct CoInstallerElement
));
4292 if (GetFunctionPointer(ptr
, &coinstaller
->Module
, (PVOID
*)&coinstaller
->Function
) == ERROR_SUCCESS
)
4293 InsertTailList(&ClassCoInstallersListHead
, &coinstaller
->ListEntry
);
4295 HeapFree(GetProcessHeap(), 0, coinstaller
);
4298 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
4301 RpcStringFreeW(&lpGuidString
);
4306 if ((CanHandle
& CLASS_INSTALLER
) && !(InstallParams
.FlagsEx
& DI_FLAGSEX_CI_FAILED
))
4308 hKey
= SetupDiOpenClassRegKey(&DeviceInfoData
->ClassGuid
, KEY_QUERY_VALUE
);
4309 if (hKey
!= INVALID_HANDLE_VALUE
)
4311 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_INSTALLER_32
, NULL
, &dwRegType
, NULL
, &dwLength
);
4312 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_SZ
)
4314 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
4315 if (KeyBuffer
!= NULL
)
4317 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_INSTALLER_32
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
4318 if (rc
== ERROR_SUCCESS
)
4320 /* Get ClassInstaller function pointer */
4321 TRACE("Got class installer '%s'\n", debugstr_w(KeyBuffer
));
4322 if (GetFunctionPointer(KeyBuffer
, &ClassInstallerLibrary
, (PVOID
*)&ClassInstaller
) != ERROR_SUCCESS
)
4324 InstallParams
.FlagsEx
|= DI_FLAGSEX_CI_FAILED
;
4325 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
4328 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
4335 /* Call Class co-installers */
4336 Context
.PostProcessing
= FALSE
;
4338 ListEntry
= ClassCoInstallersListHead
.Flink
;
4339 while (rc
== NO_ERROR
&& ListEntry
!= &ClassCoInstallersListHead
)
4341 struct CoInstallerElement
*coinstaller
;
4342 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4343 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4344 coinstaller
->PrivateData
= Context
.PrivateData
;
4345 if (rc
== ERROR_DI_POSTPROCESSING_REQUIRED
)
4347 coinstaller
->DoPostProcessing
= TRUE
;
4350 ListEntry
= ListEntry
->Flink
;
4353 /* Call Device co-installers */
4354 ListEntry
= DeviceCoInstallersListHead
.Flink
;
4355 while (rc
== NO_ERROR
&& ListEntry
!= &DeviceCoInstallersListHead
)
4357 struct CoInstallerElement
*coinstaller
;
4358 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4359 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4360 coinstaller
->PrivateData
= Context
.PrivateData
;
4361 if (rc
== ERROR_DI_POSTPROCESSING_REQUIRED
)
4363 coinstaller
->DoPostProcessing
= TRUE
;
4366 ListEntry
= ListEntry
->Flink
;
4369 /* Call Class installer */
4372 rc
= (*ClassInstaller
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
4373 FreeFunctionPointer(ClassInstallerLibrary
, ClassInstaller
);
4376 rc
= ERROR_DI_DO_DEFAULT
;
4378 /* Call default handler */
4379 if (rc
== ERROR_DI_DO_DEFAULT
)
4381 if (DefaultHandler
&& !(InstallParams
.Flags
& DI_NODI_DEFAULTACTION
))
4383 if ((*DefaultHandler
)(DeviceInfoSet
, DeviceInfoData
))
4386 rc
= GetLastError();
4392 /* Call Class co-installers that required postprocessing */
4393 Context
.PostProcessing
= TRUE
;
4394 ListEntry
= ClassCoInstallersListHead
.Flink
;
4395 while (ListEntry
!= &ClassCoInstallersListHead
)
4397 struct CoInstallerElement
*coinstaller
;
4398 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4399 if (coinstaller
->DoPostProcessing
)
4401 Context
.InstallResult
= rc
;
4402 Context
.PrivateData
= coinstaller
->PrivateData
;
4403 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4405 FreeFunctionPointer(coinstaller
->Module
, coinstaller
->Function
);
4406 ListEntry
= ListEntry
->Flink
;
4409 /* Call Device co-installers that required postprocessing */
4410 ListEntry
= DeviceCoInstallersListHead
.Flink
;
4411 while (ListEntry
!= &DeviceCoInstallersListHead
)
4413 struct CoInstallerElement
*coinstaller
;
4414 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4415 if (coinstaller
->DoPostProcessing
)
4417 Context
.InstallResult
= rc
;
4418 Context
.PrivateData
= coinstaller
->PrivateData
;
4419 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4421 FreeFunctionPointer(coinstaller
->Module
, coinstaller
->Function
);
4422 ListEntry
= ListEntry
->Flink
;
4425 /* Free allocated memory */
4426 while (!IsListEmpty(&ClassCoInstallersListHead
))
4428 ListEntry
= RemoveHeadList(&ClassCoInstallersListHead
);
4429 HeapFree(GetProcessHeap(), 0, CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
));
4431 while (!IsListEmpty(&DeviceCoInstallersListHead
))
4433 ListEntry
= RemoveHeadList(&DeviceCoInstallersListHead
);
4434 HeapFree(GetProcessHeap(), 0, CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
));
4437 ret
= (rc
== NO_ERROR
);
4441 TRACE("Returning %d\n", ret
);
4445 /***********************************************************************
4446 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
4448 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
4449 HDEVINFO DeviceInfoSet
,
4450 PSP_DEVINFO_DATA DeviceInfoData
,
4451 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
4453 SP_DEVINSTALL_PARAMS_W deviceInstallParamsW
;
4456 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4458 if (DeviceInstallParams
== NULL
)
4459 SetLastError(ERROR_INVALID_PARAMETER
);
4460 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_A
))
4461 SetLastError(ERROR_INVALID_USER_BUFFER
);
4464 deviceInstallParamsW
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4465 ret
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &deviceInstallParamsW
);
4469 /* Do W->A conversion */
4471 DeviceInstallParams
,
4472 &deviceInstallParamsW
,
4473 FIELD_OFFSET(SP_DEVINSTALL_PARAMS_W
, DriverPath
));
4474 if (WideCharToMultiByte(CP_ACP
, 0, deviceInstallParamsW
.DriverPath
, -1,
4475 DeviceInstallParams
->DriverPath
, MAX_PATH
, NULL
, NULL
) == 0)
4477 DeviceInstallParams
->DriverPath
[0] = '\0';
4483 TRACE("Returning %d\n", ret
);
4487 /***********************************************************************
4488 * SetupDiGetDeviceInfoListClass (SETUPAPI.@)
4491 SetupDiGetDeviceInfoListClass(
4492 IN HDEVINFO DeviceInfoSet
,
4493 OUT LPGUID ClassGuid
)
4495 struct DeviceInfoSet
*list
;
4498 TRACE("%p %p\n", DeviceInfoSet
, ClassGuid
);
4501 SetLastError(ERROR_INVALID_HANDLE
);
4502 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4503 SetLastError(ERROR_INVALID_HANDLE
);
4504 else if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
4505 SetLastError(ERROR_NO_ASSOCIATED_CLASS
);
4508 memcpy(&ClassGuid
, &list
->ClassGuid
, sizeof(GUID
));
4513 TRACE("Returning %d\n", ret
);
4517 /***********************************************************************
4518 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
4521 SetupDiGetDeviceInstallParamsW(
4522 IN HDEVINFO DeviceInfoSet
,
4523 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4524 OUT PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4526 struct DeviceInfoSet
*list
;
4529 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4532 SetLastError(ERROR_INVALID_HANDLE
);
4533 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4534 SetLastError(ERROR_INVALID_HANDLE
);
4535 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4536 SetLastError(ERROR_INVALID_USER_BUFFER
);
4537 else if (!DeviceInstallParams
)
4538 SetLastError(ERROR_INVALID_PARAMETER
);
4539 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_W
))
4540 SetLastError(ERROR_INVALID_USER_BUFFER
);
4543 PSP_DEVINSTALL_PARAMS_W Source
;
4546 Source
= &((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->InstallParams
;
4548 Source
= &list
->InstallParams
;
4554 memcpy(DeviceInstallParams
, Source
, Source
->cbSize
);
4556 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4558 SetLastError(RtlNtStatusToDosError(_SEH2_GetExceptionCode()));
4564 TRACE("Returning %d\n", ret
);
4569 CheckDeviceInstallParameters(
4570 IN PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4572 DWORD SupportedFlags
=
4573 DI_NOVCP
| /* 0x00000008 */
4574 DI_DIDCOMPAT
| /* 0x00000010 */
4575 DI_DIDCLASS
| /* 0x00000020 */
4576 DI_NEEDRESTART
| /* 0x00000080 */
4577 DI_NEEDREBOOT
| /* 0x00000100 */
4578 DI_RESOURCEPAGE_ADDED
| /* 0x00002000 */
4579 DI_PROPERTIES_CHANGE
| /* 0x00004000 */
4580 DI_ENUMSINGLEINF
| /* 0x00010000 */
4581 DI_DONOTCALLCONFIGMG
| /* 0x00020000 */
4582 DI_CLASSINSTALLPARAMS
| /* 0x00100000 */
4583 DI_NODI_DEFAULTACTION
| /* 0x00200000 */
4584 DI_QUIETINSTALL
| /* 0x00800000 */
4585 DI_NOFILECOPY
| /* 0x01000000 */
4586 DI_DRIVERPAGE_ADDED
; /* 0x04000000 */
4587 DWORD SupportedFlagsEx
=
4588 DI_FLAGSEX_CI_FAILED
| /* 0x00000004 */
4589 DI_FLAGSEX_DIDINFOLIST
| /* 0x00000010 */
4590 DI_FLAGSEX_DIDCOMPATINFO
| /* 0x00000020 */
4591 DI_FLAGSEX_ALLOWEXCLUDEDDRVS
| /* 0x00000800 */
4592 DI_FLAGSEX_NO_DRVREG_MODIFY
| /* 0x00008000 */
4593 DI_FLAGSEX_INSTALLEDDRIVER
; /* 0x04000000 */
4596 /* FIXME: add support for more flags */
4598 /* FIXME: DI_CLASSINSTALLPARAMS flag is not correctly used.
4599 * It should be checked before accessing to other values
4600 * of the SP_DEVINSTALL_PARAMS structure */
4602 if (DeviceInstallParams
->Flags
& ~SupportedFlags
)
4604 FIXME("Unknown Flags: 0x%08lx\n", DeviceInstallParams
->Flags
& ~SupportedFlags
);
4605 SetLastError(ERROR_INVALID_FLAGS
);
4607 else if (DeviceInstallParams
->FlagsEx
& ~SupportedFlagsEx
)
4609 FIXME("Unknown FlagsEx: 0x%08lx\n", DeviceInstallParams
->FlagsEx
& ~SupportedFlagsEx
);
4610 SetLastError(ERROR_INVALID_FLAGS
);
4612 else if ((DeviceInstallParams
->Flags
& DI_NOVCP
)
4613 && (DeviceInstallParams
->FileQueue
== NULL
|| DeviceInstallParams
->FileQueue
== (HSPFILEQ
)INVALID_HANDLE_VALUE
))
4614 SetLastError(ERROR_INVALID_USER_BUFFER
);
4617 /* FIXME: check Reserved field */
4624 /***********************************************************************
4625 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
4628 SetupDiSetDeviceInstallParamsW(
4629 IN HDEVINFO DeviceInfoSet
,
4630 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4631 IN PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4633 struct DeviceInfoSet
*list
;
4636 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4639 SetLastError(ERROR_INVALID_HANDLE
);
4640 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4641 SetLastError(ERROR_INVALID_HANDLE
);
4642 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4643 SetLastError(ERROR_INVALID_USER_BUFFER
);
4644 else if (!DeviceInstallParams
)
4645 SetLastError(ERROR_INVALID_PARAMETER
);
4646 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_W
))
4647 SetLastError(ERROR_INVALID_USER_BUFFER
);
4648 else if (CheckDeviceInstallParameters(DeviceInstallParams
))
4650 PSP_DEVINSTALL_PARAMS_W Destination
;
4653 Destination
= &((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->InstallParams
;
4655 Destination
= &list
->InstallParams
;
4656 memcpy(Destination
, DeviceInstallParams
, DeviceInstallParams
->cbSize
);
4660 TRACE("Returning %d\n", ret
);
4664 /***********************************************************************
4665 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
4668 SetupDiSetDeviceInstallParamsA(
4669 HDEVINFO DeviceInfoSet
,
4670 PSP_DEVINFO_DATA DeviceInfoData
,
4671 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
4673 SP_DEVINSTALL_PARAMS_W deviceInstallParamsW
;
4677 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4679 if (DeviceInstallParams
== NULL
)
4680 SetLastError(ERROR_INVALID_PARAMETER
);
4681 else if (DeviceInstallParams
->cbSize
< sizeof(SP_DEVINSTALL_PARAMS_A
))
4682 SetLastError(ERROR_INVALID_USER_BUFFER
);
4685 memcpy(&deviceInstallParamsW
, DeviceInstallParams
, FIELD_OFFSET(SP_DEVINSTALL_PARAMS_A
, DriverPath
));
4686 deviceInstallParamsW
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4687 len
= MultiByteToWideChar(CP_ACP
, 0, DeviceInstallParams
->DriverPath
, -1, NULL
, 0);
4690 ERR("DrivePath is NULL\n");
4695 MultiByteToWideChar(CP_ACP
, 0, DeviceInstallParams
->DriverPath
, -1, deviceInstallParamsW
.DriverPath
, len
);
4696 ret
= SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &deviceInstallParamsW
);
4700 TRACE("Returning %d\n", ret
);
4705 OpenHardwareProfileKey(
4708 IN DWORD samDesired
)
4710 HKEY hHWProfilesKey
= NULL
;
4711 HKEY hHWProfileKey
= NULL
;
4712 HKEY ret
= INVALID_HANDLE_VALUE
;
4715 rc
= RegOpenKeyExW(HKLM
,
4716 REGSTR_PATH_HWPROFILES
,
4720 if (rc
!= ERROR_SUCCESS
)
4727 rc
= RegOpenKeyExW(hHWProfilesKey
,
4736 snprintfW(subKey
, 4, InstanceKeyFormat
, HwProfile
);
4738 rc
= RegOpenKeyExW(hHWProfilesKey
,
4744 if (rc
!= ERROR_SUCCESS
)
4749 ret
= hHWProfileKey
;
4752 if (hHWProfilesKey
!= NULL
)
4753 RegCloseKey(hHWProfilesKey
);
4754 if (hHWProfileKey
!= NULL
&& hHWProfileKey
!= ret
)
4755 RegCloseKey(hHWProfileKey
);
4760 IsDeviceInfoInDeviceInfoSet(
4761 struct DeviceInfoSet
*deviceInfoSet
,
4762 struct DeviceInfo
*deviceInfo
)
4764 PLIST_ENTRY ListEntry
;
4766 ListEntry
= deviceInfoSet
->ListHead
.Flink
;
4767 while (ListEntry
!= &deviceInfoSet
->ListHead
)
4769 if (deviceInfo
== CONTAINING_RECORD(ListEntry
, struct DeviceInfo
, ListEntry
))
4772 ListEntry
= ListEntry
->Flink
;
4778 /***********************************************************************
4779 * SetupDiDeleteDeviceInfo (SETUPAPI.@)
4782 SetupDiDeleteDeviceInfo(
4783 IN HDEVINFO DeviceInfoSet
,
4784 IN PSP_DEVINFO_DATA DeviceInfoData
)
4786 struct DeviceInfoSet
*deviceInfoSet
;
4787 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
;
4790 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4793 SetLastError(ERROR_INVALID_HANDLE
);
4794 else if ((deviceInfoSet
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4795 SetLastError(ERROR_INVALID_HANDLE
);
4796 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4797 SetLastError(ERROR_INVALID_USER_BUFFER
);
4798 else if (!IsDeviceInfoInDeviceInfoSet(deviceInfoSet
, deviceInfo
))
4799 SetLastError(ERROR_INVALID_PARAMETER
);
4802 RemoveEntryList(&deviceInfo
->ListEntry
);
4803 DestroyDeviceInfo(deviceInfo
);
4811 /***********************************************************************
4812 * SetupDiOpenDeviceInfoA (SETUPAPI.@)
4815 SetupDiOpenDeviceInfoA(
4816 IN HDEVINFO DeviceInfoSet
,
4817 IN PCSTR DeviceInstanceId
,
4818 IN HWND hwndParent OPTIONAL
,
4820 OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4822 LPWSTR DeviceInstanceIdW
= NULL
;
4825 TRACE("%p %s %p %lx %p\n", DeviceInfoSet
, DeviceInstanceId
, hwndParent
, OpenFlags
, DeviceInfoData
);
4827 DeviceInstanceIdW
= pSetupMultiByteToUnicode(DeviceInstanceId
, CP_ACP
);
4828 if (DeviceInstanceIdW
== NULL
)
4831 bResult
= SetupDiOpenDeviceInfoW(DeviceInfoSet
,
4832 DeviceInstanceIdW
, hwndParent
, OpenFlags
, DeviceInfoData
);
4834 MyFree(DeviceInstanceIdW
);
4840 /***********************************************************************
4841 * SetupDiOpenDeviceInfoW (SETUPAPI.@)
4844 SetupDiOpenDeviceInfoW(
4845 IN HDEVINFO DeviceInfoSet
,
4846 IN PCWSTR DeviceInstanceId
,
4847 IN HWND hwndParent OPTIONAL
,
4849 OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4851 struct DeviceInfoSet
*list
;
4852 HKEY hEnumKey
, hKey
= NULL
;
4856 TRACE("%p %s %p %lx %p\n",
4857 DeviceInfoSet
, debugstr_w(DeviceInstanceId
),
4858 hwndParent
, OpenFlags
, DeviceInfoData
);
4860 if (OpenFlags
& DIOD_CANCEL_REMOVE
)
4861 FIXME("DIOD_CANCEL_REMOVE flag not implemented\n");
4864 SetLastError(ERROR_INVALID_HANDLE
);
4865 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4866 SetLastError(ERROR_INVALID_HANDLE
);
4867 else if (!DeviceInstanceId
)
4868 SetLastError(ERROR_INVALID_PARAMETER
);
4869 else if (OpenFlags
& ~(DIOD_CANCEL_REMOVE
| DIOD_INHERIT_CLASSDRVS
))
4871 TRACE("Unknown flags: 0x%08lx\n", OpenFlags
& ~(DIOD_CANCEL_REMOVE
| DIOD_INHERIT_CLASSDRVS
));
4872 SetLastError(ERROR_INVALID_FLAGS
);
4874 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4875 SetLastError(ERROR_INVALID_USER_BUFFER
);
4878 struct DeviceInfo
*deviceInfo
= NULL
;
4879 /* Search if device already exists in DeviceInfoSet.
4880 * If yes, return the existing element
4881 * If no, create a new element using information in registry
4883 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
4884 while (ItemList
!= &list
->ListHead
)
4886 deviceInfo
= CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
4887 if (!wcscmp(deviceInfo
->instanceId
, DeviceInstanceId
))
4890 ItemList
= ItemList
->Flink
;
4895 /* good one found */
4901 WCHAR szClassGuid
[MAX_GUID_STRING_LEN
];
4903 /* Open supposed registry key */
4906 REGSTR_PATH_SYSTEMENUM
,
4910 if (rc
!= ERROR_SUCCESS
)
4921 RegCloseKey(hEnumKey
);
4922 if (rc
!= ERROR_SUCCESS
)
4924 if (rc
== ERROR_FILE_NOT_FOUND
)
4925 rc
= ERROR_NO_SUCH_DEVINST
;
4930 ClassGUID
= GUID_NULL
;
4931 dwSize
= MAX_GUID_STRING_LEN
* sizeof(WCHAR
);
4933 if (RegQueryValueExW(hKey
,
4934 REGSTR_VAL_CLASSGUID
,
4937 (LPBYTE
)szClassGuid
,
4938 &dwSize
) == ERROR_SUCCESS
)
4940 szClassGuid
[MAX_GUID_STRING_LEN
- 2] = UNICODE_NULL
;
4942 /* Convert a string to a ClassGuid */
4943 UuidFromStringW(&szClassGuid
[1], &ClassGUID
);
4946 if (!CreateDeviceInfo(list
, DeviceInstanceId
, &ClassGUID
, &deviceInfo
))
4949 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
4954 if (ret
&& deviceInfo
&& DeviceInfoData
)
4956 memcpy(&DeviceInfoData
->ClassGuid
, &deviceInfo
->ClassGuid
, sizeof(GUID
));
4957 DeviceInfoData
->DevInst
= deviceInfo
->dnDevInst
;
4958 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInfo
;
4969 /***********************************************************************
4970 * SetupDiGetSelectedDevice (SETUPAPI.@)
4973 SetupDiGetSelectedDevice(
4974 IN HDEVINFO DeviceInfoSet
,
4975 OUT PSP_DEVINFO_DATA DeviceInfoData
)
4977 struct DeviceInfoSet
*list
;
4980 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4983 SetLastError(ERROR_INVALID_HANDLE
);
4984 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4985 SetLastError(ERROR_INVALID_HANDLE
);
4986 else if (list
->SelectedDevice
== NULL
)
4987 SetLastError(ERROR_NO_DEVICE_SELECTED
);
4988 else if (!DeviceInfoData
)
4989 SetLastError(ERROR_INVALID_PARAMETER
);
4990 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4991 SetLastError(ERROR_INVALID_USER_BUFFER
);
4994 memcpy(&DeviceInfoData
->ClassGuid
,
4995 &list
->SelectedDevice
->ClassGuid
,
4997 DeviceInfoData
->DevInst
= list
->SelectedDevice
->dnDevInst
;
4998 DeviceInfoData
->Reserved
= (ULONG_PTR
)list
->SelectedDevice
;
5002 TRACE("Returning %d\n", ret
);
5007 /***********************************************************************
5008 * SetupDiSetSelectedDevice (SETUPAPI.@)
5011 SetupDiSetSelectedDevice(
5012 IN HDEVINFO DeviceInfoSet
,
5013 IN PSP_DEVINFO_DATA DeviceInfoData
)
5015 struct DeviceInfoSet
*list
;
5018 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5021 SetLastError(ERROR_INVALID_HANDLE
);
5022 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5023 SetLastError(ERROR_INVALID_HANDLE
);
5024 else if (!DeviceInfoData
)
5025 SetLastError(ERROR_INVALID_PARAMETER
);
5026 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5027 SetLastError(ERROR_INVALID_USER_BUFFER
);
5028 else if (DeviceInfoData
->Reserved
== 0)
5029 SetLastError(ERROR_INVALID_USER_BUFFER
);
5032 list
->SelectedDevice
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5036 TRACE("Returning %d\n", ret
);
5041 /* Return the current hardware profile id, or -1 if error */
5043 SETUPAPI_GetCurrentHwProfile(
5044 IN HDEVINFO DeviceInfoSet
)
5047 DWORD dwRegType
, dwLength
;
5050 DWORD ret
= (DWORD
)-1;
5052 rc
= RegOpenKeyExW(((struct DeviceInfoSet
*)DeviceInfoSet
)->HKLM
,
5053 REGSTR_PATH_IDCONFIGDB
,
5057 if (rc
!= ERROR_SUCCESS
)
5063 dwLength
= sizeof(DWORD
);
5064 rc
= RegQueryValueExW(hKey
,
5065 REGSTR_VAL_CURRENTCONFIG
,
5068 (LPBYTE
)&hwProfile
, &dwLength
);
5069 if (rc
!= ERROR_SUCCESS
)
5074 else if (dwRegType
!= REG_DWORD
|| dwLength
!= sizeof(DWORD
))
5076 SetLastError(ERROR_GEN_FAILURE
);
5091 IN HDEVINFO DeviceInfoSet
,
5092 IN PSP_DEVINFO_DATA DeviceInfoData
)
5095 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
5096 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5099 cr
= CM_Enable_DevNode_Ex(deviceInfo
->dnDevInst
, 0, set
->hMachine
);
5100 if (cr
!= CR_SUCCESS
)
5102 SetLastError(GetErrorCodeFromCrCode(cr
));
5108 FIXME("Stub: ResetDevice(%p %p)\n", DeviceInfoSet
, DeviceInfoData
);
5113 static BOOL
StopDevice(
5114 IN HDEVINFO DeviceInfoSet
,
5115 IN PSP_DEVINFO_DATA DeviceInfoData
)
5117 FIXME("Stub: StopDevice(%p %p)\n", DeviceInfoSet
, DeviceInfoData
);
5121 /***********************************************************************
5122 * SetupDiChangeState (SETUPAPI.@)
5126 IN HDEVINFO DeviceInfoSet
,
5127 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
5129 PSP_PROPCHANGE_PARAMS PropChange
;
5130 HKEY hKey
= INVALID_HANDLE_VALUE
;
5131 LPCWSTR RegistryValueName
;
5132 DWORD dwConfigFlags
, dwLength
, dwRegType
;
5136 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5138 if (!DeviceInfoData
)
5139 PropChange
= ((struct DeviceInfoSet
*)DeviceInfoSet
)->ClassInstallParams
.PropChangeParams
;
5141 PropChange
= ((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->ClassInstallParams
.PropChangeParams
;
5144 SetLastError(ERROR_INVALID_PARAMETER
);
5148 if (PropChange
->Scope
== DICS_FLAG_GLOBAL
)
5149 RegistryValueName
= REGSTR_VAL_CONFIGFLAGS
;
5151 RegistryValueName
= REGSTR_VAL_CSCONFIGFLAGS
;
5153 switch (PropChange
->StateChange
)
5158 /* Enable/disable device in registry */
5159 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, PropChange
->Scope
, PropChange
->HwProfile
, DIREG_DEV
, KEY_QUERY_VALUE
| KEY_SET_VALUE
);
5160 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5161 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, PropChange
->Scope
, PropChange
->HwProfile
, DIREG_DEV
, NULL
, NULL
);
5162 if (hKey
== INVALID_HANDLE_VALUE
)
5164 dwLength
= sizeof(DWORD
);
5165 rc
= RegQueryValueExW(
5170 (LPBYTE
)&dwConfigFlags
, &dwLength
);
5171 if (rc
== ERROR_FILE_NOT_FOUND
)
5173 else if (rc
!= ERROR_SUCCESS
)
5178 else if (dwRegType
!= REG_DWORD
|| dwLength
!= sizeof(DWORD
))
5180 SetLastError(ERROR_GEN_FAILURE
);
5183 if (PropChange
->StateChange
== DICS_ENABLE
)
5184 dwConfigFlags
&= ~(PropChange
->Scope
== DICS_FLAG_GLOBAL
? CONFIGFLAG_DISABLED
: CSCONFIGFLAG_DISABLED
);
5186 dwConfigFlags
|= (PropChange
->Scope
== DICS_FLAG_GLOBAL
? CONFIGFLAG_DISABLED
: CSCONFIGFLAG_DISABLED
);
5187 rc
= RegSetValueExW(
5192 (LPBYTE
)&dwConfigFlags
, sizeof(DWORD
));
5193 if (rc
!= ERROR_SUCCESS
)
5199 /* Enable/disable device if needed */
5200 if (PropChange
->Scope
== DICS_FLAG_GLOBAL
5201 || PropChange
->HwProfile
== 0
5202 || PropChange
->HwProfile
== SETUPAPI_GetCurrentHwProfile(DeviceInfoSet
))
5204 if (PropChange
->StateChange
== DICS_ENABLE
)
5205 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
5207 ret
= StopDevice(DeviceInfoSet
, DeviceInfoData
);
5213 case DICS_PROPCHANGE
:
5215 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
5220 ERR("Unknown StateChange 0x%lx\n", PropChange
->StateChange
);
5221 SetLastError(ERROR_NOT_SUPPORTED
);
5226 if (hKey
!= INVALID_HANDLE_VALUE
)
5229 TRACE("Returning %d\n", ret
);
5233 /***********************************************************************
5234 * SetupDiSelectDevice (SETUPAPI.@)
5237 SetupDiSelectDevice(
5238 IN HDEVINFO DeviceInfoSet
,
5239 IN OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
5241 FIXME("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5242 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
5247 /***********************************************************************
5248 * SetupDiRegisterCoDeviceInstallers (SETUPAPI.@)
5251 SetupDiRegisterCoDeviceInstallers(
5252 IN HDEVINFO DeviceInfoSet
,
5253 IN PSP_DEVINFO_DATA DeviceInfoData
)
5255 BOOL ret
= FALSE
; /* Return value */
5257 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5260 SetLastError(ERROR_INVALID_PARAMETER
);
5261 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
5262 SetLastError(ERROR_INVALID_HANDLE
);
5263 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5264 SetLastError(ERROR_INVALID_HANDLE
);
5265 else if (!DeviceInfoData
)
5266 SetLastError(ERROR_INVALID_PARAMETER
);
5267 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5268 SetLastError(ERROR_INVALID_USER_BUFFER
);
5271 SP_DEVINSTALL_PARAMS_W InstallParams
;
5272 struct DriverInfoElement
*SelectedDriver
;
5275 WCHAR SectionName
[MAX_PATH
];
5276 DWORD SectionNameLength
= 0;
5277 HKEY hKey
= INVALID_HANDLE_VALUE
;
5278 PVOID Context
= NULL
;
5280 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
5281 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5285 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
5286 if (SelectedDriver
== NULL
)
5288 SetLastError(ERROR_NO_DRIVER_SELECTED
);
5292 /* Get .CoInstallers section name */
5293 Result
= SetupDiGetActualSectionToInstallW(
5294 SelectedDriver
->InfFileDetails
->hInf
,
5295 SelectedDriver
->Details
.SectionName
,
5296 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
5297 if (!Result
|| SectionNameLength
> MAX_PATH
- strlenW(DotCoInstallers
) - 1)
5299 lstrcatW(SectionName
, DotCoInstallers
);
5301 /* Open/Create driver key information */
5302 #if _WIN32_WINNT >= 0x502
5303 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_READ
| KEY_WRITE
);
5305 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_ALL_ACCESS
);
5307 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5308 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, NULL
, NULL
);
5309 if (hKey
== INVALID_HANDLE_VALUE
)
5312 /* Install .CoInstallers section */
5313 DoAction
= SPINST_REGISTRY
;
5314 if (!(InstallParams
.Flags
& DI_NOFILECOPY
))
5316 DoAction
|= SPINST_FILES
;
5317 Context
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
5321 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5322 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5323 DoAction
, hKey
, SelectedDriver
->InfFileDetails
->DirectoryName
, SP_COPY_NEWER
,
5324 SetupDefaultQueueCallbackW
, Context
,
5325 DeviceInfoSet
, DeviceInfoData
);
5333 SetupTermDefaultQueueCallback(Context
);
5334 if (hKey
!= INVALID_HANDLE_VALUE
)
5338 TRACE("Returning %d\n", ret
);
5343 InfIsFromOEMLocation(
5345 OUT LPBOOL IsOEMLocation
)
5349 last
= strrchrW(FullName
, '\\');
5352 /* No directory specified */
5353 *IsOEMLocation
= FALSE
;
5360 Windir
= MyMalloc((MAX_PATH
+ 1 + strlenW(InfDirectory
)) * sizeof(WCHAR
));
5363 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5367 ret
= GetSystemWindowsDirectoryW(Windir
, MAX_PATH
);
5368 if (ret
== 0 || ret
> MAX_PATH
)
5371 SetLastError(ERROR_GEN_FAILURE
);
5374 if (*Windir
&& Windir
[strlenW(Windir
) - 1] != '\\')
5375 strcatW(Windir
, BackSlash
);
5376 strcatW(Windir
, InfDirectory
);
5378 if (strncmpiW(FullName
, Windir
, last
- FullName
) == 0)
5380 /* The path is %SYSTEMROOT%\Inf */
5381 *IsOEMLocation
= FALSE
;
5385 /* The file is in another place */
5386 *IsOEMLocation
= TRUE
;
5393 /***********************************************************************
5394 * SetupDiInstallDevice (SETUPAPI.@)
5397 SetupDiInstallDevice(
5398 IN HDEVINFO DeviceInfoSet
,
5399 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
5401 SP_DEVINSTALL_PARAMS_W InstallParams
;
5402 struct DriverInfoElement
*SelectedDriver
;
5403 SYSTEMTIME DriverDate
;
5404 WCHAR SectionName
[MAX_PATH
];
5406 DWORD SectionNameLength
= 0;
5407 BOOL Result
= FALSE
;
5410 LPWSTR pSectionName
= NULL
;
5411 WCHAR ClassName
[MAX_CLASS_NAME_LEN
];
5413 LPWSTR lpGuidString
= NULL
, lpFullGuidString
= NULL
;
5414 BOOL RebootRequired
= FALSE
;
5415 HKEY hKey
= INVALID_HANDLE_VALUE
;
5416 BOOL NeedtoCopyFile
;
5417 LARGE_INTEGER fullVersion
;
5419 PVOID Context
= NULL
;
5420 BOOL ret
= FALSE
; /* Return value */
5422 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5425 SetLastError(ERROR_INVALID_PARAMETER
);
5426 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
5427 SetLastError(ERROR_INVALID_HANDLE
);
5428 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5429 SetLastError(ERROR_INVALID_HANDLE
);
5430 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5431 SetLastError(ERROR_INVALID_USER_BUFFER
);
5437 /* One parameter is bad */
5441 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
5442 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5446 if (InstallParams
.FlagsEx
& DI_FLAGSEX_SETFAILEDINSTALL
)
5448 /* Set FAILEDINSTALL in ConfigFlags registry value */
5449 DWORD ConfigFlags
, regType
;
5450 Result
= SetupDiGetDeviceRegistryPropertyW(
5455 (PBYTE
)&ConfigFlags
,
5456 sizeof(ConfigFlags
),
5458 if (!Result
|| regType
!= REG_DWORD
)
5460 SetLastError(ERROR_GEN_FAILURE
);
5463 ConfigFlags
|= DNF_DISABLED
;
5464 Result
= SetupDiSetDeviceRegistryPropertyW(
5468 (PBYTE
)&ConfigFlags
,
5469 sizeof(ConfigFlags
));
5472 SetLastError(ERROR_GEN_FAILURE
);
5480 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
5481 if (SelectedDriver
== NULL
)
5483 SetLastError(ERROR_NO_DRIVER_SELECTED
);
5487 FileTimeToSystemTime(&SelectedDriver
->Info
.DriverDate
, &DriverDate
);
5489 Result
= SetupDiGetActualSectionToInstallW(
5490 SelectedDriver
->InfFileDetails
->hInf
,
5491 SelectedDriver
->Details
.SectionName
,
5492 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
5493 if (!Result
|| SectionNameLength
> MAX_PATH
- strlenW(DotServices
))
5495 pSectionName
= &SectionName
[strlenW(SectionName
)];
5497 /* Get information from [Version] section */
5498 if (!SetupDiGetINFClassW(SelectedDriver
->Details
.InfFileName
, &ClassGuid
, ClassName
, MAX_CLASS_NAME_LEN
, &RequiredSize
))
5500 /* Format ClassGuid to a string */
5501 if (UuidToStringW((UUID
*)&ClassGuid
, &lpGuidString
) != RPC_S_OK
)
5503 RequiredSize
= lstrlenW(lpGuidString
);
5504 lpFullGuidString
= HeapAlloc(GetProcessHeap(), 0, (RequiredSize
+ 3) * sizeof(WCHAR
));
5505 if (!lpFullGuidString
)
5507 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5510 lpFullGuidString
[0] = '{';
5511 memcpy(&lpFullGuidString
[1], lpGuidString
, RequiredSize
* sizeof(WCHAR
));
5512 lpFullGuidString
[RequiredSize
+ 1] = '}';
5513 lpFullGuidString
[RequiredSize
+ 2] = '\0';
5515 /* Copy .inf file to Inf\ directory (if needed) */
5516 Result
= InfIsFromOEMLocation(SelectedDriver
->Details
.InfFileName
, &NeedtoCopyFile
);
5521 WCHAR NewFileName
[MAX_PATH
];
5522 struct InfFileDetails
*newInfFileDetails
;
5523 Result
= SetupCopyOEMInfW(
5524 SelectedDriver
->Details
.InfFileName
,
5527 SP_COPY_NOOVERWRITE
,
5528 NewFileName
, MAX_PATH
,
5531 if (!Result
&& GetLastError() != ERROR_FILE_EXISTS
)
5533 /* Create a new struct InfFileDetails, and set it to
5534 * SelectedDriver->InfFileDetails, to release use of
5535 * current InfFile */
5536 newInfFileDetails
= CreateInfFileDetails(NewFileName
);
5537 if (!newInfFileDetails
)
5539 DereferenceInfFile(SelectedDriver
->InfFileDetails
);
5540 SelectedDriver
->InfFileDetails
= newInfFileDetails
;
5541 strcpyW(SelectedDriver
->Details
.InfFileName
, NewFileName
);
5544 /* Open/Create driver key information */
5545 #if _WIN32_WINNT >= 0x502
5546 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_READ
| KEY_WRITE
);
5548 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_ALL_ACCESS
);
5550 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5551 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, NULL
, NULL
);
5552 if (hKey
== INVALID_HANDLE_VALUE
)
5555 /* Install main section */
5557 if (!(InstallParams
.FlagsEx
& DI_FLAGSEX_NO_DRVREG_MODIFY
))
5558 DoAction
|= SPINST_REGISTRY
;
5559 if (!(InstallParams
.Flags
& DI_NOFILECOPY
))
5561 DoAction
|= SPINST_FILES
;
5562 Context
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
5566 *pSectionName
= '\0';
5567 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5568 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5569 DoAction
, hKey
, SelectedDriver
->InfFileDetails
->DirectoryName
, SP_COPY_NEWER
,
5570 SetupDefaultQueueCallbackW
, Context
,
5571 DeviceInfoSet
, DeviceInfoData
);
5574 InstallParams
.Flags
|= DI_NOFILECOPY
;
5575 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5577 /* Write information to driver key */
5578 *pSectionName
= UNICODE_NULL
;
5579 memcpy(&fullVersion
, &SelectedDriver
->Info
.DriverVersion
, sizeof(LARGE_INTEGER
));
5580 TRACE("Write information to driver key\n");
5581 TRACE("DriverDate : '%u-%u-%u'\n", DriverDate
.wMonth
, DriverDate
.wDay
, DriverDate
.wYear
);
5582 TRACE("DriverDesc : '%s'\n", debugstr_w(SelectedDriver
->Info
.Description
));
5583 TRACE("DriverVersion : '%ld.%ld.%lu.%ld'\n", fullVersion
.HighPart
>> 16, fullVersion
.HighPart
& 0xffff, fullVersion
.LowPart
>> 16, fullVersion
.LowPart
& 0xffff);
5584 TRACE("InfPath : '%s'\n", debugstr_w(SelectedDriver
->InfFileDetails
->FileName
));
5585 TRACE("InfSection : '%s'\n", debugstr_w(SelectedDriver
->Details
.SectionName
));
5586 TRACE("InfSectionExt : '%s'\n", debugstr_w(&SectionName
[strlenW(SelectedDriver
->Details
.SectionName
)]));
5587 TRACE("MatchingDeviceId: '%s'\n", debugstr_w(SelectedDriver
->MatchingId
));
5588 TRACE("ProviderName : '%s'\n", debugstr_w(SelectedDriver
->Info
.ProviderName
));
5589 sprintfW(Buffer
, DateFormat
, DriverDate
.wMonth
, DriverDate
.wDay
, DriverDate
.wYear
);
5590 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_DATE
, 0, REG_SZ
, (const BYTE
*)Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
));
5591 if (rc
== ERROR_SUCCESS
)
5592 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_DATE_DATA
, 0, REG_BINARY
, (const BYTE
*)&SelectedDriver
->Info
.DriverDate
, sizeof(FILETIME
));
5593 if (rc
== ERROR_SUCCESS
)
5594 rc
= RegSetValueExW(hKey
, REGSTR_VAL_DRVDESC
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.Description
, (strlenW(SelectedDriver
->Info
.Description
) + 1) * sizeof(WCHAR
));
5595 if (rc
== ERROR_SUCCESS
)
5597 sprintfW(Buffer
, VersionFormat
, fullVersion
.HighPart
>> 16, fullVersion
.HighPart
& 0xffff, fullVersion
.LowPart
>> 16, fullVersion
.LowPart
& 0xffff);
5598 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_VERSION
, 0, REG_SZ
, (const BYTE
*)Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
));
5600 if (rc
== ERROR_SUCCESS
)
5601 rc
= RegSetValueExW(hKey
, REGSTR_VAL_INFPATH
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->InfFileDetails
->FileName
, (strlenW(SelectedDriver
->InfFileDetails
->FileName
) + 1) * sizeof(WCHAR
));
5602 if (rc
== ERROR_SUCCESS
)
5603 rc
= RegSetValueExW(hKey
, REGSTR_VAL_INFSECTION
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Details
.SectionName
, (strlenW(SelectedDriver
->Details
.SectionName
) + 1) * sizeof(WCHAR
));
5604 if (rc
== ERROR_SUCCESS
)
5605 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
));
5606 if (rc
== ERROR_SUCCESS
)
5607 rc
= RegSetValueExW(hKey
, REGSTR_VAL_MATCHINGDEVID
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->MatchingId
, (strlenW(SelectedDriver
->MatchingId
) + 1) * sizeof(WCHAR
));
5608 if (rc
== ERROR_SUCCESS
)
5609 rc
= RegSetValueExW(hKey
, REGSTR_VAL_PROVIDER_NAME
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.ProviderName
, (strlenW(SelectedDriver
->Info
.ProviderName
) + 1) * sizeof(WCHAR
));
5610 if (rc
!= ERROR_SUCCESS
)
5616 hKey
= INVALID_HANDLE_VALUE
;
5618 /* FIXME: Process .LogConfigOverride section */
5620 /* Install .Services section */
5621 strcpyW(pSectionName
, DotServices
);
5622 Result
= SetupInstallServicesFromInfSectionExW(
5623 SelectedDriver
->InfFileDetails
->hInf
,
5632 if (GetLastError() == ERROR_SUCCESS_REBOOT_REQUIRED
)
5633 RebootRequired
= TRUE
;
5635 /* Open device registry key */
5636 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_SET_VALUE
);
5637 if (hKey
== INVALID_HANDLE_VALUE
)
5640 /* Install .HW section */
5642 if (!(InstallParams
.FlagsEx
& DI_FLAGSEX_NO_DRVREG_MODIFY
))
5643 DoAction
|= SPINST_REGISTRY
;
5644 strcpyW(pSectionName
, DotHW
);
5645 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5646 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5647 DoAction
, hKey
, NULL
, 0,
5649 DeviceInfoSet
, DeviceInfoData
);
5653 /* Write information to enum key */
5654 TRACE("Write information to enum key\n");
5655 TRACE("Class : '%s'\n", debugstr_w(ClassName
));
5656 TRACE("ClassGUID : '%s'\n", debugstr_w(lpFullGuidString
));
5657 TRACE("DeviceDesc : '%s'\n", debugstr_w(SelectedDriver
->Info
.Description
));
5658 TRACE("Mfg : '%s'\n", debugstr_w(SelectedDriver
->Info
.MfgName
));
5659 rc
= RegSetValueExW(hKey
, REGSTR_VAL_CLASS
, 0, REG_SZ
, (const BYTE
*)ClassName
, (strlenW(ClassName
) + 1) * sizeof(WCHAR
));
5660 if (rc
== ERROR_SUCCESS
)
5661 rc
= RegSetValueExW(hKey
, REGSTR_VAL_CLASSGUID
, 0, REG_SZ
, (const BYTE
*)lpFullGuidString
, (strlenW(lpFullGuidString
) + 1) * sizeof(WCHAR
));
5662 if (rc
== ERROR_SUCCESS
)
5663 rc
= RegSetValueExW(hKey
, REGSTR_VAL_DEVDESC
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.Description
, (strlenW(SelectedDriver
->Info
.Description
) + 1) * sizeof(WCHAR
));
5664 if (rc
== ERROR_SUCCESS
)
5665 rc
= RegSetValueExW(hKey
, REGSTR_VAL_MFG
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.MfgName
, (strlenW(SelectedDriver
->Info
.MfgName
) + 1) * sizeof(WCHAR
));
5666 if (rc
!= ERROR_SUCCESS
)
5672 /* Start the device */
5673 if (!RebootRequired
&& !(InstallParams
.Flags
& (DI_NEEDRESTART
| DI_NEEDREBOOT
| DI_DONOTCALLCONFIGMG
)))
5674 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
5679 /* End of installation */
5680 if (hKey
!= INVALID_HANDLE_VALUE
)
5683 RpcStringFreeW(&lpGuidString
);
5684 HeapFree(GetProcessHeap(), 0, lpFullGuidString
);
5686 SetupTermDefaultQueueCallback(Context
);
5687 TRACE("Returning %d\n", ret
);
5691 static HKEY
SETUPDI_OpenDevKey(HKEY RootKey
, struct DeviceInfo
*devInfo
, REGSAM samDesired
)
5693 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
5696 l
= RegOpenKeyExW(RootKey
, REGSTR_PATH_SYSTEMENUM
, 0, 0, &enumKey
);
5699 l
= RegOpenKeyExW(enumKey
, devInfo
->instanceId
, 0, samDesired
, &key
);
5700 RegCloseKey(enumKey
);
5707 static HKEY
SETUPDI_OpenDrvKey(HKEY RootKey
, struct DeviceInfo
*devInfo
, REGSAM samDesired
)
5709 LPWSTR DriverKey
= NULL
;
5713 HKEY hEnumKey
= NULL
;
5715 HKEY key
= INVALID_HANDLE_VALUE
;
5717 hKey
= SETUPDI_OpenDevKey(RootKey
, devInfo
, KEY_QUERY_VALUE
);
5718 if (hKey
== INVALID_HANDLE_VALUE
)
5720 /* Read the 'Driver' key */
5721 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_DRIVER
, NULL
, &dwRegType
, NULL
, &dwLength
);
5722 if (rc
!= ERROR_SUCCESS
)
5727 else if (dwRegType
!= REG_SZ
)
5729 SetLastError(ERROR_GEN_FAILURE
);
5732 DriverKey
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
5735 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5738 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_DRIVER
, NULL
, &dwRegType
, (LPBYTE
)DriverKey
, &dwLength
);
5739 if (rc
!= ERROR_SUCCESS
)
5746 /* Need to open the driver key */
5749 REGSTR_PATH_CLASS_NT
,
5753 if (rc
!= ERROR_SUCCESS
)
5764 if (rc
!= ERROR_SUCCESS
)
5772 if (hEnumKey
!= NULL
)
5773 RegCloseKey(hEnumKey
);
5774 if (hKey
!= NULL
&& hKey
!= key
)
5779 /***********************************************************************
5780 * SetupDiOpenDevRegKey (SETUPAPI.@)
5782 HKEY WINAPI
SetupDiOpenDevRegKey(
5783 HDEVINFO DeviceInfoSet
,
5784 PSP_DEVINFO_DATA DeviceInfoData
,
5790 struct DeviceInfoSet
*set
= DeviceInfoSet
;
5791 struct DeviceInfo
*devInfo
;
5792 HKEY key
= INVALID_HANDLE_VALUE
;
5795 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
5796 Scope
, HwProfile
, KeyType
, samDesired
);
5798 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
5800 SetLastError(ERROR_INVALID_HANDLE
);
5801 return INVALID_HANDLE_VALUE
;
5803 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5805 SetLastError(ERROR_INVALID_HANDLE
);
5806 return INVALID_HANDLE_VALUE
;
5808 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
5809 || !DeviceInfoData
->Reserved
)
5811 SetLastError(ERROR_INVALID_PARAMETER
);
5812 return INVALID_HANDLE_VALUE
;
5814 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
5816 SetLastError(ERROR_INVALID_FLAGS
);
5817 return INVALID_HANDLE_VALUE
;
5819 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
5821 SetLastError(ERROR_INVALID_FLAGS
);
5822 return INVALID_HANDLE_VALUE
;
5824 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5825 if (devInfo
->set
!= set
)
5827 SetLastError(ERROR_INVALID_PARAMETER
);
5828 return INVALID_HANDLE_VALUE
;
5830 if (Scope
!= DICS_FLAG_GLOBAL
)
5832 RootKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, 0);
5833 if (RootKey
== INVALID_HANDLE_VALUE
)
5834 return INVALID_HANDLE_VALUE
;
5837 RootKey
= set
->HKLM
;
5841 key
= SETUPDI_OpenDevKey(RootKey
, devInfo
, samDesired
);
5844 key
= SETUPDI_OpenDrvKey(RootKey
, devInfo
, samDesired
);
5847 WARN("unknown KeyType %d\n", KeyType
);
5849 if (RootKey
!= set
->HKLM
)
5850 RegCloseKey(RootKey
);
5854 static BOOL
SETUPDI_DeleteDevKey(HKEY RootKey
, struct DeviceInfo
*devInfo
)
5860 static BOOL
SETUPDI_DeleteDrvKey(HKEY RootKey
, struct DeviceInfo
*devInfo
)
5866 /***********************************************************************
5867 * SetupDiDeleteDevRegKey (SETUPAPI.@)
5869 BOOL WINAPI
SetupDiDeleteDevRegKey(
5870 HDEVINFO DeviceInfoSet
,
5871 PSP_DEVINFO_DATA DeviceInfoData
,
5876 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
5877 struct DeviceInfo
*devInfo
;
5881 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
5884 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
5886 SetLastError(ERROR_INVALID_HANDLE
);
5889 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5891 SetLastError(ERROR_INVALID_HANDLE
);
5894 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
5895 || !DeviceInfoData
->Reserved
)
5897 SetLastError(ERROR_INVALID_PARAMETER
);
5900 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
5902 SetLastError(ERROR_INVALID_FLAGS
);
5905 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
5907 SetLastError(ERROR_INVALID_FLAGS
);
5910 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5911 if (devInfo
->set
!= set
)
5913 SetLastError(ERROR_INVALID_PARAMETER
);
5916 if (Scope
!= DICS_FLAG_GLOBAL
)
5918 RootKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, 0);
5919 if (RootKey
== INVALID_HANDLE_VALUE
)
5923 RootKey
= set
->HKLM
;
5927 ret
= SETUPDI_DeleteDevKey(RootKey
, devInfo
);
5930 ret
= SETUPDI_DeleteDrvKey(RootKey
, devInfo
);
5933 ret
= SETUPDI_DeleteDevKey(RootKey
, devInfo
);
5935 ret
= SETUPDI_DeleteDrvKey(RootKey
, devInfo
);
5938 WARN("unknown KeyType %d\n", KeyType
);
5940 if (RootKey
!= set
->HKLM
)
5941 RegCloseKey(RootKey
);