2 * SetupAPI device installer
4 * Copyright 2000 Andreas Mohr for CodeWeavers
5 * 2005-2006 Hervé Poussineau (hpoussin@reactos.org)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "setupapi_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
26 /* Unicode constants */
27 static const WCHAR BackSlash
[] = {'\\',0};
28 static const WCHAR ClassGUID
[] = {'C','l','a','s','s','G','U','I','D',0};
29 static const WCHAR Class
[] = {'C','l','a','s','s',0};
30 static const WCHAR DateFormat
[] = {'%','u','-','%','u','-','%','u',0};
31 static const WCHAR DotCoInstallers
[] = {'.','C','o','I','n','s','t','a','l','l','e','r','s',0};
32 static const WCHAR DotHW
[] = {'.','H','W',0};
33 static const WCHAR DotServices
[] = {'.','S','e','r','v','i','c','e','s',0};
34 static const WCHAR InfDirectory
[] = {'i','n','f','\\',0};
35 static const WCHAR InstanceKeyFormat
[] = {'%','0','4','l','u',0};
36 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
37 static const WCHAR VersionFormat
[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
39 static const WCHAR REGSTR_DRIVER_DATE
[] = {'D','r','i','v','e','r','D','a','t','e',0};
40 static const WCHAR REGSTR_DRIVER_DATE_DATA
[] = {'D','r','i','v','e','r','D','a','t','e','D','a','t','a',0};
41 static const WCHAR REGSTR_DRIVER_VERSION
[] = {'D','r','i','v','e','r','V','e','r','s','i','o','n',0};
42 static const WCHAR REGSTR_SECURITY
[] = {'S','e','c','u','r','i','t','y',0};
43 static const WCHAR REGSTR_UI_NUMBER_DESC_FORMAT
[] = {'U','I','N','u','m','b','e','r','D','e','s','c','F','o','r','m','a','t',0};
46 (CALLBACK
* CLASS_INSTALL_PROC
) (
47 IN DI_FUNCTION InstallFunction
,
48 IN HDEVINFO DeviceInfoSet
,
49 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
);
51 (WINAPI
* DEFAULT_CLASS_INSTALL_PROC
) (
52 IN HDEVINFO DeviceInfoSet
,
53 IN OUT PSP_DEVINFO_DATA DeviceInfoData
);
55 (CALLBACK
* COINSTALLER_PROC
) (
56 IN DI_FUNCTION InstallFunction
,
57 IN HDEVINFO DeviceInfoSet
,
58 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
59 IN OUT PCOINSTALLER_CONTEXT_DATA Context
);
61 struct CoInstallerElement
66 COINSTALLER_PROC Function
;
67 BOOL DoPostProcessing
;
71 struct GetSectionCallbackInfo
73 PSP_ALTPLATFORM_INFO PlatformInfo
;
77 WCHAR BestSection
[LINE_LEN
+ 1];
78 DWORD BestScore1
, BestScore2
, BestScore3
, BestScore4
, BestScore5
;
83 static void SETUPDI_GuidToString(const GUID
*guid
, LPWSTR guidStr
)
85 static const WCHAR fmt
[] = {'{','%','0','8','X','-','%','0','4','X','-',
86 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
87 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
90 sprintfW(guidStr
, fmt
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
91 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
92 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
96 GetErrorCodeFromCrCode(const IN CONFIGRET cr
)
100 case CR_ACCESS_DENIED
: return ERROR_ACCESS_DENIED
;
101 case CR_BUFFER_SMALL
: return ERROR_INSUFFICIENT_BUFFER
;
102 case CR_CALL_NOT_IMPLEMENTED
: return ERROR_CALL_NOT_IMPLEMENTED
;
103 case CR_FAILURE
: return ERROR_GEN_FAILURE
;
104 case CR_INVALID_DATA
: return ERROR_INVALID_USER_BUFFER
;
105 case CR_INVALID_DEVICE_ID
: return ERROR_INVALID_PARAMETER
;
106 case CR_INVALID_MACHINENAME
: return ERROR_INVALID_COMPUTERNAME
;
107 case CR_INVALID_DEVNODE
: return ERROR_INVALID_PARAMETER
;
108 case CR_INVALID_FLAG
: return ERROR_INVALID_FLAGS
;
109 case CR_INVALID_POINTER
: return ERROR_INVALID_PARAMETER
;
110 case CR_INVALID_PROPERTY
: return ERROR_INVALID_PARAMETER
;
111 case CR_NO_SUCH_DEVNODE
: return ERROR_FILE_NOT_FOUND
;
112 case CR_NO_SUCH_REGISTRY_KEY
: return ERROR_FILE_NOT_FOUND
;
113 case CR_NO_SUCH_VALUE
: return ERROR_FILE_NOT_FOUND
;
114 case CR_OUT_OF_MEMORY
: return ERROR_NOT_ENOUGH_MEMORY
;
115 case CR_REGISTRY_ERROR
: return ERROR_GEN_FAILURE
;
116 case CR_ALREADY_SUCH_DEVINST
: return ERROR_DEVINST_ALREADY_EXISTS
;
117 case CR_SUCCESS
: return ERROR_SUCCESS
;
118 default: return ERROR_GEN_FAILURE
;
121 /* Does not happen */
124 /* Lower scores are best ones */
127 IN LPCWSTR SectionName
,
128 IN PSP_ALTPLATFORM_INFO PlatformInfo
,
131 OUT PDWORD ScorePlatform
,
132 OUT PDWORD ScoreMajorVersion
,
133 OUT PDWORD ScoreMinorVersion
,
134 OUT PDWORD ScoreProductType
,
135 OUT PDWORD ScoreSuiteMask
)
137 LPWSTR Section
= NULL
;
138 //LPCWSTR pExtensionPlatform;
139 LPCWSTR pExtensionArchitecture
;
144 //static const WCHAR ExtensionPlatformNone[] = {'.',0};
145 static const WCHAR ExtensionPlatformNT
[] = {'.','N','T',0};
146 static const WCHAR ExtensionPlatformWindows
[] = {'.','W','i','n',0};
148 static const WCHAR ExtensionArchitectureNone
[] = {0};
149 static const WCHAR ExtensionArchitecturealpha
[] = {'a','l','p','h','a',0};
150 static const WCHAR ExtensionArchitectureamd64
[] = {'A','M','D','6','4',0};
151 static const WCHAR ExtensionArchitectureia64
[] = {'I','A','6','4',0};
152 static const WCHAR ExtensionArchitecturemips
[] = {'m','i','p','s',0};
153 static const WCHAR ExtensionArchitectureppc
[] = {'p','p','c',0};
154 static const WCHAR ExtensionArchitecturex86
[] = {'x','8','6',0};
156 TRACE("%s %p 0x%x 0x%x\n",
157 debugstr_w(SectionName
), PlatformInfo
, ProductType
, SuiteMask
);
159 *ScorePlatform
= *ScoreMajorVersion
= *ScoreMinorVersion
= *ScoreProductType
= *ScoreSuiteMask
= 0;
161 Section
= pSetupDuplicateString(SectionName
);
164 TRACE("pSetupDuplicateString() failed\n");
168 /* Set various extensions values */
169 switch (PlatformInfo
->Platform
)
171 case VER_PLATFORM_WIN32_WINDOWS
:
172 //pExtensionPlatform = ExtensionPlatformWindows;
174 case VER_PLATFORM_WIN32_NT
:
175 //pExtensionPlatform = ExtensionPlatformNT;
178 ERR("Unknown platform 0x%lx\n", PlatformInfo
->Platform
);
179 //pExtensionPlatform = ExtensionPlatformNone;
182 switch (PlatformInfo
->ProcessorArchitecture
)
184 case PROCESSOR_ARCHITECTURE_ALPHA
:
185 pExtensionArchitecture
= ExtensionArchitecturealpha
;
187 case PROCESSOR_ARCHITECTURE_AMD64
:
188 pExtensionArchitecture
= ExtensionArchitectureamd64
;
190 case PROCESSOR_ARCHITECTURE_IA64
:
191 pExtensionArchitecture
= ExtensionArchitectureia64
;
193 case PROCESSOR_ARCHITECTURE_INTEL
:
194 pExtensionArchitecture
= ExtensionArchitecturex86
;
196 case PROCESSOR_ARCHITECTURE_MIPS
:
197 pExtensionArchitecture
= ExtensionArchitecturemips
;
199 case PROCESSOR_ARCHITECTURE_PPC
:
200 pExtensionArchitecture
= ExtensionArchitectureppc
;
203 ERR("Unknown processor architecture 0x%x\n", PlatformInfo
->ProcessorArchitecture
);
204 case PROCESSOR_ARCHITECTURE_UNKNOWN
:
205 pExtensionArchitecture
= ExtensionArchitectureNone
;
211 * Field[1] Architecture
212 * Field[2] Major version
213 * Field[3] Minor version
214 * Field[4] Product type
215 * Field[5] Suite mask
216 * Remark: lastests fields may be NULL if the information is not provided
219 if (Fields
[0] == NULL
)
221 TRACE("No extension found\n");
222 *ScorePlatform
= *ScoreMajorVersion
= *ScoreMinorVersion
= *ScoreProductType
= *ScoreSuiteMask
= ULONG_MAX
;
226 Fields
[1] = Fields
[0] + 1;
227 Fields
[2] = Fields
[3] = Fields
[4] = Fields
[5] = NULL
;
228 for (i
= 2; Fields
[i
- 1] != NULL
&& i
< 6; i
++)
230 Fields
[i
] = wcschr(Fields
[i
- 1], '.');
234 *(Fields
[i
] - 1) = UNICODE_NULL
;
237 /* Take care of first 2 fields */
238 if (strncmpiW(Fields
[0], ExtensionPlatformWindows
, strlenW(ExtensionPlatformWindows
)) == 0)
240 if (PlatformInfo
->Platform
!= VER_PLATFORM_WIN32_WINDOWS
)
242 TRACE("Mismatch on platform field\n");
245 Fields
[1] += wcslen(ExtensionPlatformWindows
) - 1;
247 else if (strncmpiW(Fields
[0], ExtensionPlatformNT
, strlenW(ExtensionPlatformNT
)) == 0)
249 if (PlatformInfo
->Platform
!= VER_PLATFORM_WIN32_NT
)
251 TRACE("Mismatch on platform field\n");
254 Fields
[1] += wcslen(ExtensionPlatformNT
) - 1;
258 /* No platform specified */
259 *ScorePlatform
|= 0x02;
261 if (strcmpiW(Fields
[1], ExtensionArchitectureNone
) == 0)
263 /* No architecture specified */
264 *ScorePlatform
|= 0x01;
266 else if (strcmpiW(Fields
[1], pExtensionArchitecture
) != 0)
268 TRACE("Mismatch on architecture field ('%s' and '%s')\n",
269 debugstr_w(Fields
[1]), debugstr_w(pExtensionArchitecture
));
273 /* Check if informations are matching */
274 if (Fields
[2] && *Fields
[2])
276 DWORD MajorVersion
, MinorVersion
= 0;
277 MajorVersion
= strtoulW(Fields
[2], NULL
, 0);
278 if ((MajorVersion
== 0 || MajorVersion
== ULONG_MAX
) &&
279 (errno
== ERANGE
|| errno
== EINVAL
))
281 TRACE("Wrong MajorVersion ('%s')\n", debugstr_w(Fields
[2]));
284 if (Fields
[3] && *Fields
[3])
286 MinorVersion
= strtoulW(Fields
[3], NULL
, 0);
287 if ((MinorVersion
== 0 || MinorVersion
== ULONG_MAX
) &&
288 (errno
== ERANGE
|| errno
== EINVAL
))
290 TRACE("Wrong MinorVersion ('%s')\n", debugstr_w(Fields
[3]));
294 if (PlatformInfo
->MajorVersion
< MajorVersion
||
295 (PlatformInfo
->MajorVersion
== MajorVersion
&& PlatformInfo
->MinorVersion
< MinorVersion
))
297 TRACE("Mismatch on version field (%lu.%lu and %lu.%lu)\n",
298 MajorVersion
, MinorVersion
, PlatformInfo
->MajorVersion
, PlatformInfo
->MinorVersion
);
301 *ScoreMajorVersion
= MajorVersion
- PlatformInfo
->MajorVersion
;
302 if (MajorVersion
== PlatformInfo
->MajorVersion
)
303 *ScoreMinorVersion
= MinorVersion
- PlatformInfo
->MinorVersion
;
305 *ScoreMinorVersion
= MinorVersion
;
307 else if (Fields
[3] && *Fields
[3])
309 TRACE("Minor version found without major version\n");
314 *ScoreMajorVersion
= PlatformInfo
->MajorVersion
;
315 *ScoreMinorVersion
= PlatformInfo
->MinorVersion
;
318 if (Fields
[4] && *Fields
[4])
320 DWORD CurrentProductType
;
321 CurrentProductType
= strtoulW(Fields
[4], NULL
, 0);
322 if ((CurrentProductType
== 0 || CurrentProductType
== ULONG_MAX
) &&
323 (errno
== ERANGE
|| errno
== EINVAL
))
325 TRACE("Wrong Product type ('%s')\n", debugstr_w(Fields
[4]));
328 if (CurrentProductType
!= ProductType
)
330 TRACE("Mismatch on product type (0x%08lx and 0x%08x)\n",
331 CurrentProductType
, ProductType
);
336 *ScoreProductType
= 1;
338 if (Fields
[5] && *Fields
[5])
340 DWORD CurrentSuiteMask
;
341 CurrentSuiteMask
= strtoulW(Fields
[5], NULL
, 0);
342 if ((CurrentSuiteMask
== 0 || CurrentSuiteMask
== ULONG_MAX
) &&
343 (errno
== ERANGE
|| errno
== EINVAL
))
345 TRACE("Wrong Suite mask ('%s')\n", debugstr_w(Fields
[5]));
348 if ((CurrentSuiteMask
& ~SuiteMask
) != 0)
350 TRACE("Mismatch on suite mask (0x%08lx and 0x%08x)\n",
351 CurrentSuiteMask
, SuiteMask
);
354 *ScoreSuiteMask
= SuiteMask
& ~CurrentSuiteMask
;
357 *ScoreSuiteMask
= SuiteMask
;
368 IN LPCWSTR SectionName
,
371 struct GetSectionCallbackInfo
*info
= Context
;
372 DWORD Score1
, Score2
, Score3
, Score4
, Score5
;
375 if (SectionName
[info
->PrefixLength
] != '.')
378 ret
= CheckSectionValid(
379 &SectionName
[info
->PrefixLength
],
383 &Score1
, &Score2
, &Score3
, &Score4
, &Score5
);
386 TRACE("Section %s not compatible\n", debugstr_w(SectionName
));
389 if (Score1
> info
->BestScore1
) goto done
;
390 if (Score1
< info
->BestScore1
) goto bettersection
;
391 if (Score2
> info
->BestScore2
) goto done
;
392 if (Score2
< info
->BestScore2
) goto bettersection
;
393 if (Score3
> info
->BestScore3
) goto done
;
394 if (Score3
< info
->BestScore3
) goto bettersection
;
395 if (Score4
> info
->BestScore4
) goto done
;
396 if (Score4
< info
->BestScore4
) goto bettersection
;
397 if (Score5
> info
->BestScore5
) goto done
;
398 if (Score5
< info
->BestScore5
) goto bettersection
;
402 strcpyW(info
->BestSection
, SectionName
);
403 info
->BestScore1
= Score1
;
404 info
->BestScore2
= Score2
;
405 info
->BestScore3
= Score3
;
406 info
->BestScore4
= Score4
;
407 info
->BestScore5
= Score5
;
413 /***********************************************************************
414 * SetupDiGetActualSectionToInstallExW (SETUPAPI.@)
417 SetupDiGetActualSectionToInstallExW(
419 IN PCWSTR InfSectionName
,
420 IN PSP_ALTPLATFORM_INFO AlternatePlatformInfo OPTIONAL
,
421 OUT PWSTR InfSectionWithExt OPTIONAL
,
422 IN DWORD InfSectionWithExtSize
,
423 OUT PDWORD RequiredSize OPTIONAL
,
424 OUT PWSTR
* Extension OPTIONAL
,
429 TRACE("%p %s %p %p %lu %p %p %p\n", InfHandle
, debugstr_w(InfSectionName
),
430 AlternatePlatformInfo
, InfSectionWithExt
, InfSectionWithExtSize
,
431 RequiredSize
, Extension
, Reserved
);
433 if (!InfHandle
|| InfHandle
== (HINF
)INVALID_HANDLE_VALUE
)
434 SetLastError(ERROR_INVALID_HANDLE
);
435 else if (!InfSectionName
)
436 SetLastError(ERROR_INVALID_PARAMETER
);
437 else if (AlternatePlatformInfo
&& AlternatePlatformInfo
->cbSize
!= sizeof(SP_ALTPLATFORM_INFO
))
438 SetLastError(ERROR_INVALID_USER_BUFFER
);
439 else if (Reserved
!= NULL
)
440 SetLastError(ERROR_INVALID_PARAMETER
);
443 static SP_ALTPLATFORM_INFO CurrentPlatform
= { 0, };
444 static BYTE CurrentProductType
= 0;
445 static WORD CurrentSuiteMask
= 0;
446 PSP_ALTPLATFORM_INFO pPlatformInfo
= &CurrentPlatform
;
447 struct GetSectionCallbackInfo CallbackInfo
;
452 /* Fill platform info if needed */
453 if (AlternatePlatformInfo
)
455 pPlatformInfo
= AlternatePlatformInfo
;
461 if (CurrentPlatform
.cbSize
!= sizeof(SP_ALTPLATFORM_INFO
))
463 /* That's the first time we go here. We need to fill in the structure */
464 OSVERSIONINFOEX VersionInfo
;
465 SYSTEM_INFO SystemInfo
;
466 VersionInfo
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
467 ret
= GetVersionExW((OSVERSIONINFO
*)&VersionInfo
);
470 GetSystemInfo(&SystemInfo
);
471 CurrentPlatform
.cbSize
= sizeof(SP_ALTPLATFORM_INFO
);
472 CurrentPlatform
.Platform
= VersionInfo
.dwPlatformId
;
473 CurrentPlatform
.MajorVersion
= VersionInfo
.dwMajorVersion
;
474 CurrentPlatform
.MinorVersion
= VersionInfo
.dwMinorVersion
;
475 CurrentPlatform
.ProcessorArchitecture
= SystemInfo
.wProcessorArchitecture
;
476 CurrentPlatform
.Reserved
= 0;
477 CurrentProductType
= VersionInfo
.wProductType
;
478 CurrentSuiteMask
= VersionInfo
.wSuiteMask
;
480 ProductType
= CurrentProductType
;
481 SuiteMask
= CurrentSuiteMask
;
484 CallbackInfo
.PlatformInfo
= pPlatformInfo
;
485 CallbackInfo
.ProductType
= ProductType
;
486 CallbackInfo
.SuiteMask
= SuiteMask
;
487 CallbackInfo
.PrefixLength
= strlenW(InfSectionName
);
488 CallbackInfo
.BestScore1
= ULONG_MAX
;
489 CallbackInfo
.BestScore2
= ULONG_MAX
;
490 CallbackInfo
.BestScore3
= ULONG_MAX
;
491 CallbackInfo
.BestScore4
= ULONG_MAX
;
492 CallbackInfo
.BestScore5
= ULONG_MAX
;
493 strcpyW(CallbackInfo
.BestSection
, InfSectionName
);
494 if (!EnumerateSectionsStartingWith(
500 SetLastError(ERROR_GEN_FAILURE
);
504 dwFullLength
= lstrlenW(CallbackInfo
.BestSection
);
505 if (RequiredSize
!= NULL
)
506 *RequiredSize
= dwFullLength
+ 1;
508 if (InfSectionWithExtSize
> 0)
510 if (InfSectionWithExtSize
< dwFullLength
+ 1)
512 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
515 strcpyW(InfSectionWithExt
, CallbackInfo
.BestSection
);
518 DWORD dwLength
= lstrlenW(InfSectionName
);
519 *Extension
= (dwLength
== dwFullLength
) ? NULL
: &InfSectionWithExt
[dwLength
];
527 TRACE("Returning %d\n", ret
);
534 IN
struct DeviceInfoSet
*list
,
535 IN LPCWSTR InstancePath
,
536 IN LPCGUID pClassGuid
,
537 OUT
struct DeviceInfo
**pDeviceInfo
)
541 struct DeviceInfo
*deviceInfo
;
545 size
= FIELD_OFFSET(struct DeviceInfo
, Data
) + (strlenW(InstancePath
) + 1) * sizeof(WCHAR
);
546 deviceInfo
= HeapAlloc(GetProcessHeap(), 0, size
);
549 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
552 ZeroMemory(deviceInfo
, size
);
554 cr
= CM_Locate_DevNode_ExW(&deviceInfo
->dnDevInst
, (DEVINSTID_W
)InstancePath
, CM_LOCATE_DEVNODE_PHANTOM
, list
->hMachine
);
555 if (cr
!= CR_SUCCESS
)
557 SetLastError(GetErrorCodeFromCrCode(cr
));
561 deviceInfo
->set
= list
;
562 deviceInfo
->InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
563 strcpyW(deviceInfo
->Data
, InstancePath
);
564 deviceInfo
->instanceId
= deviceInfo
->Data
;
565 deviceInfo
->UniqueId
= strrchrW(deviceInfo
->Data
, '\\');
566 deviceInfo
->DeviceDescription
= NULL
;
567 memcpy(&deviceInfo
->ClassGuid
, pClassGuid
, sizeof(GUID
));
568 deviceInfo
->CreationFlags
= 0;
569 InitializeListHead(&deviceInfo
->DriverListHead
);
570 InitializeListHead(&deviceInfo
->InterfaceListHead
);
572 *pDeviceInfo
= deviceInfo
;
578 DestroyClassInstallParams(struct ClassInstallParams
* installParams
)
580 HeapFree(GetProcessHeap(), 0, installParams
->PropChangeParams
);
581 HeapFree(GetProcessHeap(), 0, installParams
->AddPropertyPageData
);
586 DestroyDeviceInfo(struct DeviceInfo
*deviceInfo
)
588 PLIST_ENTRY ListEntry
;
589 struct DriverInfoElement
*driverInfo
;
590 struct DeviceInterface
*deviceInterface
;
592 while (!IsListEmpty(&deviceInfo
->DriverListHead
))
594 ListEntry
= RemoveHeadList(&deviceInfo
->DriverListHead
);
595 driverInfo
= CONTAINING_RECORD(ListEntry
, struct DriverInfoElement
, ListEntry
);
596 if (!DestroyDriverInfoElement(driverInfo
))
599 while (!IsListEmpty(&deviceInfo
->InterfaceListHead
))
601 ListEntry
= RemoveHeadList(&deviceInfo
->InterfaceListHead
);
602 deviceInterface
= CONTAINING_RECORD(ListEntry
, struct DeviceInterface
, ListEntry
);
603 if (!DestroyDeviceInterface(deviceInterface
))
606 DestroyClassInstallParams(&deviceInfo
->ClassInstallParams
);
607 return HeapFree(GetProcessHeap(), 0, deviceInfo
);
611 DestroyDeviceInfoSet(struct DeviceInfoSet
* list
)
613 PLIST_ENTRY ListEntry
;
614 struct DeviceInfo
*deviceInfo
;
616 while (!IsListEmpty(&list
->ListHead
))
618 ListEntry
= RemoveHeadList(&list
->ListHead
);
619 deviceInfo
= CONTAINING_RECORD(ListEntry
, struct DeviceInfo
, ListEntry
);
620 if (!DestroyDeviceInfo(deviceInfo
))
623 if (list
->HKLM
!= HKEY_LOCAL_MACHINE
)
624 RegCloseKey(list
->HKLM
);
625 CM_Disconnect_Machine(list
->hMachine
);
626 DestroyClassInstallParams(&list
->ClassInstallParams
);
627 return HeapFree(GetProcessHeap(), 0, list
);
630 /***********************************************************************
631 * SetupDiBuildClassInfoList (SETUPAPI.@)
633 * Returns a list of setup class GUIDs that identify the classes
634 * that are installed on a local machine.
637 * Flags [I] control exclusion of classes from the list.
638 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
639 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
640 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
646 BOOL WINAPI
SetupDiBuildClassInfoList(
648 LPGUID ClassGuidList
,
649 DWORD ClassGuidListSize
,
653 return SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
654 ClassGuidListSize
, RequiredSize
,
658 /***********************************************************************
659 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
661 * Returns a list of setup class GUIDs that identify the classes
662 * that are installed on a local or remote macine.
665 * Flags [I] control exclusion of classes from the list.
666 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
667 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
668 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
669 * MachineName [I] name of a remote machine.
670 * Reserved [I] must be NULL.
676 BOOL WINAPI
SetupDiBuildClassInfoListExA(
678 LPGUID ClassGuidList
,
679 DWORD ClassGuidListSize
,
684 LPWSTR MachineNameW
= NULL
;
687 TRACE("0x%lx %p %lu %p %s %p\n", Flags
, ClassGuidList
,
688 ClassGuidListSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
692 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
693 if (MachineNameW
== NULL
) return FALSE
;
696 bResult
= SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
697 ClassGuidListSize
, RequiredSize
,
698 MachineNameW
, Reserved
);
700 MyFree(MachineNameW
);
705 /***********************************************************************
706 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
708 * Returns a list of setup class GUIDs that identify the classes
709 * that are installed on a local or remote macine.
712 * Flags [I] control exclusion of classes from the list.
713 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
714 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
715 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
716 * MachineName [I] name of a remote machine.
717 * Reserved [I] must be NULL.
723 BOOL WINAPI
SetupDiBuildClassInfoListExW(
725 LPGUID ClassGuidList
,
726 DWORD ClassGuidListSize
,
732 HKEY hClassesKey
= INVALID_HANDLE_VALUE
;
737 DWORD dwGuidListIndex
= 0;
739 TRACE("0x%lx %p %lu %p %s %p\n", Flags
, ClassGuidList
,
740 ClassGuidListSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
744 SetLastError(ERROR_INVALID_PARAMETER
);
747 else if (!ClassGuidList
&& ClassGuidListSize
> 0)
749 SetLastError(ERROR_INVALID_PARAMETER
);
753 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
754 KEY_ENUMERATE_SUB_KEYS
,
758 if (hClassesKey
== INVALID_HANDLE_VALUE
)
763 for (dwIndex
= 0; ; dwIndex
++)
766 lError
= RegEnumKeyExW(hClassesKey
,
774 TRACE("RegEnumKeyExW() returns %d\n", lError
);
775 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
777 TRACE("Key name: %s\n", debugstr_w(szKeyName
));
779 if (RegOpenKeyExW(hClassesKey
,
785 RegCloseKey(hClassesKey
);
789 if (!RegQueryValueExW(hClassKey
,
790 REGSTR_VAL_NOUSECLASS
,
796 TRACE("'NoUseClass' value found!\n");
797 RegCloseKey(hClassKey
);
801 if ((Flags
& DIBCI_NOINSTALLCLASS
) &&
802 (!RegQueryValueExW(hClassKey
,
803 REGSTR_VAL_NOINSTALLCLASS
,
809 TRACE("'NoInstallClass' value found!\n");
810 RegCloseKey(hClassKey
);
814 if ((Flags
& DIBCI_NODISPLAYCLASS
) &&
815 (!RegQueryValueExW(hClassKey
,
816 REGSTR_VAL_NODISPLAYCLASS
,
822 TRACE("'NoDisplayClass' value found!\n");
823 RegCloseKey(hClassKey
);
827 RegCloseKey(hClassKey
);
829 TRACE("Guid: %s\n", debugstr_w(szKeyName
));
830 if (dwGuidListIndex
< ClassGuidListSize
)
832 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
836 TRACE("Guid: %p\n", &szKeyName
[1]);
838 UuidFromStringW(&szKeyName
[1],
839 &ClassGuidList
[dwGuidListIndex
]);
845 if (lError
!= ERROR_SUCCESS
)
849 RegCloseKey(hClassesKey
);
851 if (RequiredSize
!= NULL
)
852 *RequiredSize
= dwGuidListIndex
;
854 if (ClassGuidListSize
< dwGuidListIndex
)
856 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
863 /***********************************************************************
864 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
866 BOOL WINAPI
SetupDiClassGuidsFromNameA(
868 LPGUID ClassGuidList
,
869 DWORD ClassGuidListSize
,
872 return SetupDiClassGuidsFromNameExA(ClassName
, ClassGuidList
,
873 ClassGuidListSize
, RequiredSize
,
877 /***********************************************************************
878 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
880 BOOL WINAPI
SetupDiClassGuidsFromNameW(
882 LPGUID ClassGuidList
,
883 DWORD ClassGuidListSize
,
886 return SetupDiClassGuidsFromNameExW(ClassName
, ClassGuidList
,
887 ClassGuidListSize
, RequiredSize
,
891 /***********************************************************************
892 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
894 BOOL WINAPI
SetupDiClassGuidsFromNameExA(
896 LPGUID ClassGuidList
,
897 DWORD ClassGuidListSize
,
902 LPWSTR ClassNameW
= NULL
;
903 LPWSTR MachineNameW
= NULL
;
906 TRACE("%s %p %lu %p %s %p\n", debugstr_a(ClassName
), ClassGuidList
,
907 ClassGuidListSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
911 SetLastError(ERROR_INVALID_PARAMETER
);
915 ClassNameW
= pSetupMultiByteToUnicode(ClassName
, CP_ACP
);
916 if (ClassNameW
== NULL
)
921 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
922 if (MachineNameW
== NULL
)
929 bResult
= SetupDiClassGuidsFromNameExW(ClassNameW
, ClassGuidList
,
930 ClassGuidListSize
, RequiredSize
,
931 MachineNameW
, Reserved
);
933 MyFree(MachineNameW
);
939 /***********************************************************************
940 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
942 BOOL WINAPI
SetupDiClassGuidsFromNameExW(
944 LPGUID ClassGuidList
,
945 DWORD ClassGuidListSize
,
951 WCHAR szClassName
[MAX_CLASS_NAME_LEN
];
957 DWORD dwGuidListIndex
= 0;
959 TRACE("%s %p %lu %p %s %p\n", debugstr_w(ClassName
), ClassGuidList
,
960 ClassGuidListSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
962 if (!ClassName
|| !RequiredSize
)
964 SetLastError(ERROR_INVALID_PARAMETER
);
967 if (!ClassGuidList
&& ClassGuidListSize
> 0)
969 SetLastError(ERROR_INVALID_PARAMETER
);
974 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
975 KEY_ENUMERATE_SUB_KEYS
,
979 if (hClassesKey
== INVALID_HANDLE_VALUE
)
984 for (dwIndex
= 0; ; dwIndex
++)
987 lError
= RegEnumKeyExW(hClassesKey
,
995 TRACE("RegEnumKeyExW() returns %d\n", lError
);
996 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
998 TRACE("Key name: %p\n", szKeyName
);
1000 if (RegOpenKeyExW(hClassesKey
,
1006 RegCloseKey(hClassesKey
);
1010 dwLength
= MAX_CLASS_NAME_LEN
* sizeof(WCHAR
);
1011 if (!RegQueryValueExW(hClassKey
,
1015 (LPBYTE
)szClassName
,
1018 TRACE("Class name: %p\n", szClassName
);
1020 if (strcmpiW(szClassName
, ClassName
) == 0)
1022 TRACE("Found matching class name\n");
1024 TRACE("Guid: %p\n", szKeyName
);
1025 if (dwGuidListIndex
< ClassGuidListSize
)
1027 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
1031 TRACE("Guid: %p\n", &szKeyName
[1]);
1033 UuidFromStringW(&szKeyName
[1],
1034 &ClassGuidList
[dwGuidListIndex
]);
1041 RegCloseKey(hClassKey
);
1044 if (lError
!= ERROR_SUCCESS
)
1048 RegCloseKey(hClassesKey
);
1050 if (RequiredSize
!= NULL
)
1051 *RequiredSize
= dwGuidListIndex
;
1053 if (ClassGuidListSize
< dwGuidListIndex
)
1055 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1062 /***********************************************************************
1063 * SetupDiClassNameFromGuidA (SETUPAPI.@)
1065 BOOL WINAPI
SetupDiClassNameFromGuidA(
1066 const GUID
* ClassGuid
,
1068 DWORD ClassNameSize
,
1069 PDWORD RequiredSize
)
1071 return SetupDiClassNameFromGuidExA(ClassGuid
, ClassName
,
1072 ClassNameSize
, RequiredSize
,
1076 /***********************************************************************
1077 * SetupDiClassNameFromGuidW (SETUPAPI.@)
1079 BOOL WINAPI
SetupDiClassNameFromGuidW(
1080 const GUID
* ClassGuid
,
1082 DWORD ClassNameSize
,
1083 PDWORD RequiredSize
)
1085 return SetupDiClassNameFromGuidExW(ClassGuid
, ClassName
,
1086 ClassNameSize
, RequiredSize
,
1090 /***********************************************************************
1091 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1093 BOOL WINAPI
SetupDiClassNameFromGuidExA(
1094 const GUID
* ClassGuid
,
1096 DWORD ClassNameSize
,
1097 PDWORD RequiredSize
,
1101 WCHAR ClassNameW
[MAX_CLASS_NAME_LEN
];
1102 LPWSTR MachineNameW
= NULL
;
1106 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
1107 ret
= SetupDiClassNameFromGuidExW(ClassGuid
, ClassNameW
, MAX_CLASS_NAME_LEN
,
1108 RequiredSize
, MachineNameW
, Reserved
);
1111 int len
= WideCharToMultiByte(CP_ACP
, 0, ClassNameW
, -1, ClassName
,
1112 ClassNameSize
, NULL
, NULL
);
1113 if (len
== 0 || len
> ClassNameSize
)
1115 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1119 MyFree(MachineNameW
);
1123 /***********************************************************************
1124 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1126 BOOL WINAPI
SetupDiClassNameFromGuidExW(
1127 const GUID
* ClassGuid
,
1129 DWORD ClassNameSize
,
1130 PDWORD RequiredSize
,
1140 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassName
,
1141 ClassNameSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
1143 /* Make sure there's a GUID */
1144 if (ClassGuid
== NULL
)
1146 SetLastError(ERROR_INVALID_CLASS
); /* On Vista: ERROR_INVALID_USER_BUFFER */
1150 /* Make sure there's a real buffer when there's a size */
1151 if ((ClassNameSize
> 0) && (ClassName
== NULL
))
1153 SetLastError(ERROR_INVALID_PARAMETER
); /* On Vista: ERROR_INVALID_USER_BUFFER */
1157 /* Open the key for the GUID */
1158 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, KEY_QUERY_VALUE
, DIOCR_INSTALLER
, MachineName
, Reserved
);
1160 if (hKey
== INVALID_HANDLE_VALUE
)
1163 /* Retrieve the class name data and close the key */
1164 rc
= QueryRegistryValue(hKey
, Class
, (LPBYTE
*) &Buffer
, &dwRegType
, &dwLength
);
1167 /* Make sure we got the data */
1168 if (rc
!= ERROR_SUCCESS
)
1174 /* Make sure the data is a string */
1175 if (dwRegType
!= REG_SZ
)
1178 SetLastError(ERROR_GEN_FAILURE
);
1182 /* Determine the length of the class name */
1183 dwLength
/= sizeof(WCHAR
);
1185 if ((dwLength
== 0) || (Buffer
[dwLength
- 1] != UNICODE_NULL
))
1186 /* Count the null-terminator */
1189 /* Inform the caller about the class name */
1190 if ((ClassName
!= NULL
) && (dwLength
<= ClassNameSize
))
1192 memcpy(ClassName
, Buffer
, (dwLength
- 1) * sizeof(WCHAR
));
1193 ClassName
[dwLength
- 1] = UNICODE_NULL
;
1196 /* Inform the caller about the required size */
1197 if (RequiredSize
!= NULL
)
1198 *RequiredSize
= dwLength
;
1200 /* Clean up the buffer */
1203 /* Make sure the buffer was large enough */
1204 if ((ClassName
== NULL
) || (dwLength
> ClassNameSize
))
1206 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1213 /***********************************************************************
1214 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1217 SetupDiCreateDeviceInfoList(const GUID
*ClassGuid
,
1220 return SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
, NULL
, NULL
);
1223 /***********************************************************************
1224 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1227 SetupDiCreateDeviceInfoListExA(const GUID
*ClassGuid
,
1232 LPWSTR MachineNameW
= NULL
;
1235 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1236 debugstr_a(MachineName
), Reserved
);
1240 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
1241 if (MachineNameW
== NULL
)
1242 return INVALID_HANDLE_VALUE
;
1245 hDevInfo
= SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
,
1246 MachineNameW
, Reserved
);
1248 MyFree(MachineNameW
);
1253 /***********************************************************************
1254 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1256 * Create an empty DeviceInfoSet list.
1259 * ClassGuid [I] if not NULL only devices with GUID ClcassGuid are associated
1261 * hwndParent [I] hwnd needed for interface related actions.
1262 * MachineName [I] name of machine to create emtpy DeviceInfoSet list, if NULL
1263 * local registry will be used.
1264 * Reserved [I] must be NULL
1267 * Success: empty list.
1268 * Failure: INVALID_HANDLE_VALUE.
1271 SetupDiCreateDeviceInfoListExW(const GUID
*ClassGuid
,
1276 struct DeviceInfoSet
*list
= NULL
;
1277 DWORD size
= FIELD_OFFSET(struct DeviceInfoSet
, szData
);
1280 HDEVINFO ret
= INVALID_HANDLE_VALUE
;
1282 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1283 debugstr_w(MachineName
), Reserved
);
1285 if (MachineName
!= NULL
)
1287 SIZE_T len
= strlenW(MachineName
);
1288 if (len
>= SP_MAX_MACHINENAME_LENGTH
- 4)
1290 SetLastError(ERROR_INVALID_MACHINENAME
);
1294 size
+= (len
+ 3) * sizeof(WCHAR
);
1299 if (Reserved
!= NULL
)
1301 SetLastError(ERROR_INVALID_PARAMETER
);
1302 return INVALID_HANDLE_VALUE
;
1305 list
= MyMalloc(size
);
1308 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1309 return INVALID_HANDLE_VALUE
;
1311 ZeroMemory(list
, FIELD_OFFSET(struct DeviceInfoSet
, szData
));
1313 list
->magic
= SETUP_DEVICE_INFO_SET_MAGIC
;
1314 memcpy(&list
->ClassGuid
,
1315 ClassGuid
? ClassGuid
: &GUID_NULL
,
1316 sizeof(list
->ClassGuid
));
1317 list
->InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
1318 list
->InstallParams
.Flags
|= DI_CLASSINSTALLPARAMS
;
1319 list
->InstallParams
.hwndParent
= hwndParent
;
1322 rc
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &list
->HKLM
);
1323 if (rc
!= ERROR_SUCCESS
)
1325 SetLastError(ERROR_INVALID_MACHINENAME
);
1329 list
->szData
[0] = list
->szData
[1] = '\\';
1330 strcpyW(list
->szData
+ 2, MachineName
);
1331 list
->MachineName
= list
->szData
;
1335 list
->HKLM
= HKEY_LOCAL_MACHINE
;
1336 list
->MachineName
= NULL
;
1338 cr
= CM_Connect_MachineW(list
->MachineName
, &list
->hMachine
);
1339 if (cr
!= CR_SUCCESS
)
1341 SetLastError(GetErrorCodeFromCrCode(cr
));
1344 InitializeListHead(&list
->DriverListHead
);
1345 InitializeListHead(&list
->ListHead
);
1347 return (HDEVINFO
)list
;
1350 if (ret
== INVALID_HANDLE_VALUE
)
1354 if (list
->HKLM
!= NULL
&& list
->HKLM
!= HKEY_LOCAL_MACHINE
)
1355 RegCloseKey(list
->HKLM
);
1362 /***********************************************************************
1363 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1365 HKEY WINAPI
SetupDiCreateDevRegKeyA(
1366 HDEVINFO DeviceInfoSet
,
1367 PSP_DEVINFO_DATA DeviceInfoData
,
1372 PCSTR InfSectionName
)
1374 PWSTR InfSectionNameW
= NULL
;
1377 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1378 HwProfile
, KeyType
, InfHandle
, debugstr_a(InfSectionName
));
1382 if (!InfSectionName
)
1384 SetLastError(ERROR_INVALID_PARAMETER
);
1385 return INVALID_HANDLE_VALUE
;
1389 InfSectionNameW
= pSetupMultiByteToUnicode(InfSectionName
, CP_ACP
);
1390 if (InfSectionNameW
== NULL
) return INVALID_HANDLE_VALUE
;
1393 key
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, Scope
,
1394 HwProfile
, KeyType
, InfHandle
, InfSectionNameW
);
1395 MyFree(InfSectionNameW
);
1400 OpenHardwareProfileKey(
1403 IN DWORD samDesired
);
1405 /***********************************************************************
1406 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1408 HKEY WINAPI
SetupDiCreateDevRegKeyW(
1409 HDEVINFO DeviceInfoSet
,
1410 PSP_DEVINFO_DATA DeviceInfoData
,
1415 PCWSTR InfSectionName
)
1417 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1418 HKEY key
= INVALID_HANDLE_VALUE
;
1419 LPWSTR lpGuidString
= NULL
;
1420 LPWSTR DriverKey
= NULL
; /* {GUID}\Index */
1421 LPWSTR pDeviceInstance
; /* Points into DriverKey, on the Index field */
1422 DWORD Index
; /* Index used in the DriverKey name */
1426 HKEY hHWProfileKey
= INVALID_HANDLE_VALUE
;
1427 HKEY hEnumKey
= NULL
;
1428 HKEY hClassKey
= NULL
;
1429 HKEY hDeviceKey
= INVALID_HANDLE_VALUE
;
1433 TRACE("%p %p %lu %lu %lu %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1434 HwProfile
, KeyType
, InfHandle
, debugstr_w(InfSectionName
));
1436 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1438 SetLastError(ERROR_INVALID_HANDLE
);
1439 return INVALID_HANDLE_VALUE
;
1441 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1443 SetLastError(ERROR_INVALID_HANDLE
);
1444 return INVALID_HANDLE_VALUE
;
1446 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1447 || !DeviceInfoData
->Reserved
)
1449 SetLastError(ERROR_INVALID_PARAMETER
);
1450 return INVALID_HANDLE_VALUE
;
1452 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
1454 SetLastError(ERROR_INVALID_FLAGS
);
1455 return INVALID_HANDLE_VALUE
;
1457 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
1459 SetLastError(ERROR_INVALID_FLAGS
);
1460 return INVALID_HANDLE_VALUE
;
1462 if (InfHandle
&& !InfSectionName
)
1464 SetLastError(ERROR_INVALID_PARAMETER
);
1465 return INVALID_HANDLE_VALUE
;
1467 if (!InfHandle
&& InfSectionName
)
1469 SetLastError(ERROR_INVALID_PARAMETER
);
1470 return INVALID_HANDLE_VALUE
;
1473 if (Scope
== DICS_FLAG_GLOBAL
)
1474 RootKey
= set
->HKLM
;
1475 else /* Scope == DICS_FLAG_CONFIGSPECIFIC */
1477 hHWProfileKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, KEY_CREATE_SUB_KEY
);
1478 if (hHWProfileKey
== INVALID_HANDLE_VALUE
)
1480 RootKey
= hHWProfileKey
;
1483 if (KeyType
== DIREG_DEV
)
1485 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1487 rc
= RegCreateKeyExW(
1489 REGSTR_PATH_SYSTEMENUM
,
1492 REG_OPTION_NON_VOLATILE
,
1497 if (rc
!= ERROR_SUCCESS
)
1502 rc
= RegCreateKeyExW(
1504 deviceInfo
->instanceId
,
1507 REG_OPTION_NON_VOLATILE
,
1508 #if _WIN32_WINNT >= 0x502
1509 KEY_READ
| KEY_WRITE
,
1516 if (rc
!= ERROR_SUCCESS
)
1522 else /* KeyType == DIREG_DRV */
1524 /* Open device key, to read Driver value */
1525 hDeviceKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
, DIREG_DEV
, KEY_QUERY_VALUE
| KEY_SET_VALUE
);
1526 if (hDeviceKey
== INVALID_HANDLE_VALUE
)
1529 rc
= RegOpenKeyExW(RootKey
, REGSTR_PATH_CLASS_NT
, 0, KEY_CREATE_SUB_KEY
, &hClassKey
);
1530 if (rc
!= ERROR_SUCCESS
)
1536 rc
= RegQueryValueExW(hDeviceKey
, REGSTR_VAL_DRIVER
, NULL
, NULL
, NULL
, &dwSize
);
1537 if (rc
!= ERROR_SUCCESS
)
1539 /* Create a new driver key */
1541 if (UuidToStringW((UUID
*)&DeviceInfoData
->ClassGuid
, &lpGuidString
) != RPC_S_OK
)
1544 /* The driver key is in \System\CurrentControlSet\Control\Class\{GUID}\Index */
1545 DriverKey
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpGuidString
) + 7) * sizeof(WCHAR
) + sizeof(UNICODE_NULL
));
1548 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1553 strcpyW(&DriverKey
[1], lpGuidString
);
1554 pDeviceInstance
= &DriverKey
[strlenW(DriverKey
)];
1555 *pDeviceInstance
++ = '}';
1556 *pDeviceInstance
++ = '\\';
1558 /* Try all values for Index between 0 and 9999 */
1560 while (Index
<= 9999)
1562 sprintfW(pDeviceInstance
, InstanceKeyFormat
, Index
);
1563 rc
= RegCreateKeyExW(hClassKey
,
1567 REG_OPTION_NON_VOLATILE
,
1568 #if _WIN32_WINNT >= 0x502
1569 KEY_READ
| KEY_WRITE
,
1576 if (rc
!= ERROR_SUCCESS
)
1581 if (Disposition
== REG_CREATED_NEW_KEY
)
1590 /* Unable to create more than 9999 devices within the same class */
1591 SetLastError(ERROR_GEN_FAILURE
);
1595 /* Write the new Driver value */
1596 rc
= RegSetValueExW(hDeviceKey
, REGSTR_VAL_DRIVER
, 0, REG_SZ
, (const BYTE
*)DriverKey
, (strlenW(DriverKey
) + 1) * sizeof(WCHAR
));
1597 if (rc
!= ERROR_SUCCESS
)
1606 /* Open the existing driver key */
1608 DriverKey
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
1611 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1615 rc
= RegQueryValueExW(hDeviceKey
, REGSTR_VAL_DRIVER
, NULL
, NULL
, (LPBYTE
)DriverKey
, &dwSize
);
1616 if (rc
!= ERROR_SUCCESS
)
1622 rc
= RegCreateKeyExW(hClassKey
,
1626 REG_OPTION_NON_VOLATILE
,
1627 #if _WIN32_WINNT >= 0x502
1628 KEY_READ
| KEY_WRITE
,
1635 if (rc
!= ERROR_SUCCESS
)
1643 /* Do installation of the specified section */
1646 FIXME("Need to install section %s in file %p\n",
1647 debugstr_w(InfSectionName
), InfHandle
);
1653 RpcStringFreeW(&lpGuidString
);
1654 HeapFree(GetProcessHeap(), 0, DriverKey
);
1655 if (hHWProfileKey
!= INVALID_HANDLE_VALUE
)
1656 RegCloseKey(hHWProfileKey
);
1657 if (hEnumKey
!= NULL
)
1658 RegCloseKey(hEnumKey
);
1659 if (hClassKey
!= NULL
)
1660 RegCloseKey(hClassKey
);
1661 if (hDeviceKey
!= INVALID_HANDLE_VALUE
)
1662 RegCloseKey(hDeviceKey
);
1663 if (hKey
!= NULL
&& hKey
!= key
)
1666 TRACE("Returning 0x%p\n", key
);
1670 /***********************************************************************
1671 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1673 BOOL WINAPI
SetupDiCreateDeviceInfoA(
1674 HDEVINFO DeviceInfoSet
,
1676 CONST GUID
*ClassGuid
,
1677 PCSTR DeviceDescription
,
1679 DWORD CreationFlags
,
1680 PSP_DEVINFO_DATA DeviceInfoData
)
1683 LPWSTR DeviceNameW
= NULL
;
1684 LPWSTR DeviceDescriptionW
= NULL
;
1690 DeviceNameW
= pSetupMultiByteToUnicode(DeviceName
, CP_ACP
);
1691 if (DeviceNameW
== NULL
) return FALSE
;
1693 if (DeviceDescription
)
1695 DeviceDescriptionW
= pSetupMultiByteToUnicode(DeviceDescription
, CP_ACP
);
1696 if (DeviceDescriptionW
== NULL
)
1698 MyFree(DeviceNameW
);
1703 ret
= SetupDiCreateDeviceInfoW(DeviceInfoSet
, DeviceNameW
, ClassGuid
, DeviceDescriptionW
,
1704 hwndParent
, CreationFlags
, DeviceInfoData
);
1706 MyFree(DeviceNameW
);
1707 MyFree(DeviceDescriptionW
);
1712 /***********************************************************************
1713 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1715 BOOL WINAPI
SetupDiCreateDeviceInfoW(
1716 HDEVINFO DeviceInfoSet
,
1718 CONST GUID
*ClassGuid
,
1719 PCWSTR DeviceDescription
,
1721 DWORD CreationFlags
,
1722 PSP_DEVINFO_DATA DeviceInfoData
)
1724 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1725 struct DeviceInfo
*deviceInfo
= NULL
;
1728 DEVINST RootDevInst
;
1731 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet
, debugstr_w(DeviceName
),
1732 debugstr_guid(ClassGuid
), debugstr_w(DeviceDescription
),
1733 hwndParent
, CreationFlags
, DeviceInfoData
);
1737 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1740 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1742 SetLastError(ERROR_INVALID_HANDLE
);
1747 SetLastError(ERROR_INVALID_PARAMETER
);
1750 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1752 SetLastError(ERROR_INVALID_HANDLE
);
1755 if (!IsEqualGUID(&set
->ClassGuid
, &GUID_NULL
) &&
1756 !IsEqualGUID(ClassGuid
, &set
->ClassGuid
))
1758 SetLastError(ERROR_CLASS_MISMATCH
);
1761 if (CreationFlags
& ~(DICD_GENERATE_ID
| DICD_INHERIT_CLASSDRVS
))
1763 TRACE("Unknown flags: 0x%08lx\n", CreationFlags
& ~(DICD_GENERATE_ID
| DICD_INHERIT_CLASSDRVS
));
1764 SetLastError(ERROR_INVALID_FLAGS
);
1768 /* Get the root device instance */
1769 cr
= CM_Locate_DevInst_ExW(&RootDevInst
,
1771 CM_LOCATE_DEVINST_NORMAL
,
1773 if (cr
!= CR_SUCCESS
)
1775 SetLastError(ERROR_INVALID_DATA
);
1779 /* Create the new device instance */
1780 cr
= CM_Create_DevInst_ExW(&DevInst
,
1781 (DEVINSTID
)DeviceName
,
1785 if (cr
!= CR_SUCCESS
)
1787 SetLastError(GetErrorCodeFromCrCode(cr
));
1791 if (CreateDeviceInfo(set
, DeviceName
, ClassGuid
, &deviceInfo
))
1793 InsertTailList(&set
->ListHead
, &deviceInfo
->ListEntry
);
1795 if (!DeviceInfoData
)
1799 if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1801 SetLastError(ERROR_INVALID_USER_BUFFER
);
1805 memcpy(&DeviceInfoData
->ClassGuid
, ClassGuid
, sizeof(GUID
));
1806 DeviceInfoData
->DevInst
= deviceInfo
->dnDevInst
;
1807 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInfo
;
1815 if (deviceInfo
!= NULL
)
1817 /* Remove deviceInfo from List */
1818 RemoveEntryList(&deviceInfo
->ListEntry
);
1820 /* Destroy deviceInfo */
1821 DestroyDeviceInfo(deviceInfo
);
1825 TRACE("Returning %d\n", ret
);
1829 /***********************************************************************
1830 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1832 BOOL WINAPI
SetupDiRegisterDeviceInfo(
1833 HDEVINFO DeviceInfoSet
,
1834 PSP_DEVINFO_DATA DeviceInfoData
,
1836 PSP_DETSIG_CMPPROC CompareProc
,
1837 PVOID CompareContext
,
1838 PSP_DEVINFO_DATA DupDeviceInfoData
)
1840 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1841 WCHAR DevInstId
[MAX_DEVICE_ID_LEN
];
1842 DEVINST ParentDevInst
;
1844 DWORD dwError
= ERROR_SUCCESS
;
1846 TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet
, DeviceInfoData
, Flags
,
1847 CompareProc
, CompareContext
, DupDeviceInfoData
);
1849 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1851 SetLastError(ERROR_INVALID_HANDLE
);
1854 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1856 SetLastError(ERROR_INVALID_HANDLE
);
1859 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1860 || !DeviceInfoData
->Reserved
)
1862 SetLastError(ERROR_INVALID_PARAMETER
);
1866 if (Flags
& ~SPRDI_FIND_DUPS
)
1868 TRACE("Unknown flags: 0x%08lx\n", Flags
& ~SPRDI_FIND_DUPS
);
1869 SetLastError(ERROR_INVALID_FLAGS
);
1873 if (Flags
& SPRDI_FIND_DUPS
)
1875 FIXME("Unimplemented codepath!\n");
1878 CM_Get_Device_ID_Ex(DeviceInfoData
->DevInst
,
1884 CM_Get_Parent_Ex(&ParentDevInst
,
1885 DeviceInfoData
->DevInst
,
1889 cr
= CM_Create_DevInst_Ex(&DeviceInfoData
->DevInst
,
1892 CM_CREATE_DEVINST_NORMAL
| CM_CREATE_DEVINST_DO_NOT_INSTALL
,
1894 if (cr
!= CR_SUCCESS
)
1896 dwError
= ERROR_NO_SUCH_DEVINST
;
1899 SetLastError(dwError
);
1901 return (dwError
== ERROR_SUCCESS
);
1904 /***********************************************************************
1905 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1907 BOOL WINAPI
SetupDiEnumDeviceInfo(
1910 PSP_DEVINFO_DATA info
)
1914 TRACE("%p %d %p\n", devinfo
, index
, info
);
1918 SetLastError(ERROR_INVALID_PARAMETER
);
1921 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
1923 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
1924 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
1926 if (info
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1927 SetLastError(ERROR_INVALID_USER_BUFFER
);
1930 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
1931 while (ItemList
!= &list
->ListHead
&& index
-- > 0)
1932 ItemList
= ItemList
->Flink
;
1933 if (ItemList
== &list
->ListHead
)
1934 SetLastError(ERROR_NO_MORE_ITEMS
);
1937 struct DeviceInfo
*DevInfo
= CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
1938 memcpy(&info
->ClassGuid
,
1939 &DevInfo
->ClassGuid
,
1941 info
->DevInst
= DevInfo
->dnDevInst
;
1942 info
->Reserved
= (ULONG_PTR
)DevInfo
;
1948 SetLastError(ERROR_INVALID_HANDLE
);
1951 SetLastError(ERROR_INVALID_HANDLE
);
1955 /***********************************************************************
1956 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1958 BOOL WINAPI
SetupDiGetDeviceInstanceIdA(
1959 HDEVINFO DeviceInfoSet
,
1960 PSP_DEVINFO_DATA DeviceInfoData
,
1961 PSTR DeviceInstanceId
,
1962 DWORD DeviceInstanceIdSize
,
1963 PDWORD RequiredSize
)
1969 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1970 DeviceInstanceIdSize
, RequiredSize
);
1972 if (!DeviceInstanceId
&& DeviceInstanceIdSize
> 0)
1974 SetLastError(ERROR_INVALID_PARAMETER
);
1978 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1983 if (!ret
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1985 instanceId
= MyMalloc(size
* sizeof(WCHAR
));
1988 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1995 int len
= WideCharToMultiByte(CP_ACP
, 0, instanceId
, -1,
1997 DeviceInstanceIdSize
, NULL
, NULL
);
2003 if (len
> DeviceInstanceIdSize
)
2005 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2009 *RequiredSize
= len
;
2017 *RequiredSize
= size
;
2018 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2024 /***********************************************************************
2025 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
2027 BOOL WINAPI
SetupDiGetDeviceInstanceIdW(
2028 HDEVINFO DeviceInfoSet
,
2029 PSP_DEVINFO_DATA DeviceInfoData
,
2030 PWSTR DeviceInstanceId
,
2031 DWORD DeviceInstanceIdSize
,
2032 PDWORD RequiredSize
)
2034 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2035 struct DeviceInfo
*devInfo
;
2037 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
2038 DeviceInstanceIdSize
, RequiredSize
);
2040 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2042 SetLastError(ERROR_INVALID_HANDLE
);
2045 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2047 SetLastError(ERROR_INVALID_HANDLE
);
2050 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2051 || !DeviceInfoData
->Reserved
)
2053 SetLastError(ERROR_INVALID_PARAMETER
);
2056 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2057 if (!DeviceInstanceId
&& DeviceInstanceIdSize
> 0)
2059 SetLastError(ERROR_INVALID_PARAMETER
);
2062 if (DeviceInstanceId
&& DeviceInstanceIdSize
== 0)
2064 SetLastError(ERROR_INVALID_PARAMETER
);
2067 TRACE("instance ID: %s\n", debugstr_w(devInfo
->instanceId
));
2068 if (DeviceInstanceIdSize
< lstrlenW(devInfo
->instanceId
) + 1)
2070 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2072 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
2075 lstrcpyW(DeviceInstanceId
, devInfo
->instanceId
);
2077 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
2081 /***********************************************************************
2082 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
2084 BOOL WINAPI
SetupDiGetActualSectionToInstallA(
2086 PCSTR InfSectionName
,
2087 PSTR InfSectionWithExt
,
2088 DWORD InfSectionWithExtSize
,
2089 PDWORD RequiredSize
,
2092 return SetupDiGetActualSectionToInstallExA(InfHandle
, InfSectionName
,
2093 NULL
, InfSectionWithExt
, InfSectionWithExtSize
, RequiredSize
,
2097 /***********************************************************************
2098 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
2100 BOOL WINAPI
SetupDiGetActualSectionToInstallW(
2102 PCWSTR InfSectionName
,
2103 PWSTR InfSectionWithExt
,
2104 DWORD InfSectionWithExtSize
,
2105 PDWORD RequiredSize
,
2108 return SetupDiGetActualSectionToInstallExW(InfHandle
, InfSectionName
,
2109 NULL
, InfSectionWithExt
, InfSectionWithExtSize
, RequiredSize
,
2113 /***********************************************************************
2114 * SetupDiGetActualSectionToInstallExA (SETUPAPI.@)
2117 SetupDiGetActualSectionToInstallExA(
2119 IN PCSTR InfSectionName
,
2120 IN PSP_ALTPLATFORM_INFO AlternatePlatformInfo OPTIONAL
,
2121 OUT PSTR InfSectionWithExt OPTIONAL
,
2122 IN DWORD InfSectionWithExtSize
,
2123 OUT PDWORD RequiredSize OPTIONAL
,
2124 OUT PSTR
* Extension OPTIONAL
,
2127 LPWSTR InfSectionNameW
= NULL
;
2128 LPWSTR InfSectionWithExtW
= NULL
;
2130 BOOL bResult
= FALSE
;
2136 InfSectionNameW
= pSetupMultiByteToUnicode(InfSectionName
, CP_ACP
);
2137 if (InfSectionNameW
== NULL
)
2140 if (InfSectionWithExt
)
2142 InfSectionWithExtW
= MyMalloc(InfSectionWithExtSize
* sizeof(WCHAR
));
2143 if (InfSectionWithExtW
== NULL
)
2147 bResult
= SetupDiGetActualSectionToInstallExW(
2148 InfHandle
, InfSectionNameW
, AlternatePlatformInfo
,
2149 InfSectionWithExt
? InfSectionWithExtW
: NULL
,
2150 InfSectionWithExtSize
,
2152 Extension
? &ExtensionW
: NULL
,
2155 if (bResult
&& InfSectionWithExt
)
2157 bResult
= WideCharToMultiByte(CP_ACP
, 0, InfSectionWithExtW
, -1, InfSectionWithExt
,
2158 InfSectionWithExtSize
, NULL
, NULL
) != 0;
2160 if (bResult
&& Extension
)
2162 if (ExtensionW
== NULL
)
2165 *Extension
= &InfSectionWithExt
[ExtensionW
- InfSectionWithExtW
];
2169 MyFree(InfSectionNameW
);
2170 MyFree(InfSectionWithExtW
);
2175 /***********************************************************************
2176 * SetupDiGetClassDescriptionA (SETUPAPI.@)
2178 BOOL WINAPI
SetupDiGetClassDescriptionA(
2179 const GUID
* ClassGuid
,
2180 PSTR ClassDescription
,
2181 DWORD ClassDescriptionSize
,
2182 PDWORD RequiredSize
)
2184 return SetupDiGetClassDescriptionExA(ClassGuid
, ClassDescription
,
2185 ClassDescriptionSize
,
2186 RequiredSize
, NULL
, NULL
);
2189 /***********************************************************************
2190 * SetupDiGetClassDescriptionW (SETUPAPI.@)
2192 BOOL WINAPI
SetupDiGetClassDescriptionW(
2193 const GUID
* ClassGuid
,
2194 PWSTR ClassDescription
,
2195 DWORD ClassDescriptionSize
,
2196 PDWORD RequiredSize
)
2198 return SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescription
,
2199 ClassDescriptionSize
,
2200 RequiredSize
, NULL
, NULL
);
2203 /***********************************************************************
2204 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
2206 BOOL WINAPI
SetupDiGetClassDescriptionExA(
2207 const GUID
* ClassGuid
,
2208 PSTR ClassDescription
,
2209 DWORD ClassDescriptionSize
,
2210 PDWORD RequiredSize
,
2214 PWCHAR ClassDescriptionW
= NULL
;
2215 LPWSTR MachineNameW
= NULL
;
2218 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassDescription
,
2219 ClassDescriptionSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
2221 if (ClassDescriptionSize
> 0)
2223 ClassDescriptionW
= MyMalloc(ClassDescriptionSize
* sizeof(WCHAR
));
2224 if (!ClassDescriptionW
)
2226 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2233 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
2236 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2241 ret
= SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescriptionW
,
2242 ClassDescriptionSize
* sizeof(WCHAR
), RequiredSize
, MachineNameW
, Reserved
);
2245 DWORD len
= (DWORD
)WideCharToMultiByte(CP_ACP
, 0, ClassDescriptionW
, -1, ClassDescription
,
2246 ClassDescriptionSize
, NULL
, NULL
);
2247 if (len
== 0 || len
> ClassDescriptionSize
)
2249 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2255 MyFree(ClassDescriptionW
);
2256 MyFree(MachineNameW
);
2260 /***********************************************************************
2261 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
2263 BOOL WINAPI
SetupDiGetClassDescriptionExW(
2264 const GUID
* ClassGuid
,
2265 PWSTR ClassDescription
,
2266 DWORD ClassDescriptionSize
,
2267 PDWORD RequiredSize
,
2277 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassDescription
,
2278 ClassDescriptionSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
2280 /* Make sure there's a GUID */
2283 SetLastError(ERROR_INVALID_PARAMETER
);
2287 /* Make sure there's a real buffer when there's a size */
2288 if (!ClassDescription
&& ClassDescriptionSize
> 0)
2290 SetLastError(ERROR_INVALID_PARAMETER
);
2294 /* Open the key for the GUID */
2295 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
2300 if (hKey
== INVALID_HANDLE_VALUE
)
2303 /* Retrieve the class description data and close the key */
2304 rc
= QueryRegistryValue(hKey
, NULL
, (LPBYTE
*) &Buffer
, &dwRegType
, &dwLength
);
2307 /* Make sure we got the data */
2308 if (rc
!= ERROR_SUCCESS
)
2314 /* Make sure the data is a string */
2315 if (dwRegType
!= REG_SZ
)
2318 SetLastError(ERROR_GEN_FAILURE
);
2322 /* Determine the length of the class description */
2323 dwLength
/= sizeof(WCHAR
);
2325 /* Count the null-terminator if none is present */
2326 if ((dwLength
== 0) || (Buffer
[dwLength
- 1] != UNICODE_NULL
))
2329 /* Inform the caller about the class description */
2330 if ((ClassDescription
!= NULL
) && (dwLength
<= ClassDescriptionSize
))
2332 memcpy(ClassDescription
, Buffer
, (dwLength
- 1) * sizeof(WCHAR
));
2333 ClassDescription
[dwLength
- 1] = UNICODE_NULL
;
2336 /* Inform the caller about the required size */
2337 if (RequiredSize
!= NULL
)
2338 *RequiredSize
= dwLength
;
2340 /* Clean up the buffer */
2343 /* Make sure the buffer was large enough */
2344 if ((ClassDescription
== NULL
) || (dwLength
> ClassDescriptionSize
))
2346 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2353 /***********************************************************************
2354 * SetupDiGetClassDevsA (SETUPAPI.@)
2356 HDEVINFO WINAPI
SetupDiGetClassDevsA(
2362 return SetupDiGetClassDevsExA(class, enumstr
, parent
,
2363 flags
, NULL
, NULL
, NULL
);
2366 /***********************************************************************
2367 * SetupDiGetClassDevsExA (SETUPAPI.@)
2369 HDEVINFO WINAPI
SetupDiGetClassDevsExA(
2379 LPWSTR enumstrW
= NULL
, machineW
= NULL
;
2383 enumstrW
= pSetupMultiByteToUnicode(enumstr
, CP_ACP
);
2386 ret
= INVALID_HANDLE_VALUE
;
2392 machineW
= pSetupMultiByteToUnicode(machine
, CP_ACP
);
2396 ret
= INVALID_HANDLE_VALUE
;
2400 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, deviceset
,
2401 machineW
, reserved
);
2409 /***********************************************************************
2410 * SetupDiGetClassDevsW (SETUPAPI.@)
2412 HDEVINFO WINAPI
SetupDiGetClassDevsW(
2418 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2422 /***********************************************************************
2423 * SetupDiGetClassDevsExW (SETUPAPI.@)
2425 HDEVINFO WINAPI
SetupDiGetClassDevsExW(
2434 HDEVINFO hDeviceInfo
= INVALID_HANDLE_VALUE
;
2435 struct DeviceInfoSet
*list
;
2436 CONST GUID
*pClassGuid
;
2438 HDEVINFO set
= INVALID_HANDLE_VALUE
;
2440 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2441 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2444 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2446 SetLastError(ERROR_INVALID_PARAMETER
);
2447 return INVALID_HANDLE_VALUE
;
2450 /* Create the deviceset if not set */
2453 list
= (struct DeviceInfoSet
*)deviceset
;
2454 if (list
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2456 SetLastError(ERROR_INVALID_HANDLE
);
2459 hDeviceInfo
= deviceset
;
2463 hDeviceInfo
= SetupDiCreateDeviceInfoListExW(
2464 flags
& (DIGCF_DEVICEINTERFACE
| DIGCF_ALLCLASSES
) ? NULL
: class,
2465 NULL
, machine
, NULL
);
2466 if (hDeviceInfo
== INVALID_HANDLE_VALUE
)
2468 list
= (struct DeviceInfoSet
*)hDeviceInfo
;
2471 if (flags
& DIGCF_PROFILE
)
2472 FIXME(": flag DIGCF_PROFILE ignored\n");
2474 if (flags
& DIGCF_DEVICEINTERFACE
)
2478 SetLastError(ERROR_INVALID_PARAMETER
);
2481 rc
= SETUP_CreateInterfaceList(list
, machine
, class, enumstr
, flags
& DIGCF_PRESENT
);
2485 /* Determine which class(es) should be included in the deviceset */
2486 if (flags
& DIGCF_ALLCLASSES
)
2488 /* The caller wants all classes. Check if
2489 * the deviceset limits us to one class */
2490 if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2493 pClassGuid
= &list
->ClassGuid
;
2497 /* The caller wants one class. Check if it matches deviceset class */
2498 if (IsEqualIID(&list
->ClassGuid
, class)
2499 || IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2505 SetLastError(ERROR_INVALID_PARAMETER
);
2509 else if (!IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2511 /* No class specified. Try to use the one of the deviceset */
2512 if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2513 pClassGuid
= &list
->ClassGuid
;
2516 SetLastError(ERROR_INVALID_PARAMETER
);
2522 SetLastError(ERROR_INVALID_PARAMETER
);
2525 rc
= SETUP_CreateDevicesList(list
, machine
, pClassGuid
, enumstr
);
2527 if (rc
!= ERROR_SUCCESS
)
2535 if (!deviceset
&& hDeviceInfo
!= INVALID_HANDLE_VALUE
&& hDeviceInfo
!= set
)
2536 SetupDiDestroyDeviceInfoList(hDeviceInfo
);
2540 /***********************************************************************
2541 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2543 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2544 HDEVINFO DeviceInfoSet
,
2545 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2547 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2549 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2551 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2553 SetLastError(ERROR_INVALID_HANDLE
);
2556 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2558 SetLastError(ERROR_INVALID_HANDLE
);
2562 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2564 SetLastError(ERROR_INVALID_PARAMETER
);
2567 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2568 DevInfoData
->RemoteMachineHandle
= set
->hMachine
;
2569 if (set
->MachineName
)
2572 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2576 DevInfoData
->RemoteMachineName
[0] = 0;
2581 /***********************************************************************
2582 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2584 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2585 HDEVINFO DeviceInfoSet
,
2586 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2588 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2590 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2592 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2594 SetLastError(ERROR_INVALID_HANDLE
);
2597 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2599 SetLastError(ERROR_INVALID_HANDLE
);
2603 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2605 SetLastError(ERROR_INVALID_PARAMETER
);
2608 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2609 DevInfoData
->RemoteMachineHandle
= set
->hMachine
;
2610 if (set
->MachineName
)
2611 strcpyW(DevInfoData
->RemoteMachineName
, set
->MachineName
+ 2);
2613 DevInfoData
->RemoteMachineName
[0] = 0;
2618 /***********************************************************************
2619 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2621 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2622 HDEVINFO DeviceInfoSet
,
2623 PSP_DEVINFO_DATA DeviceInfoData
,
2624 const GUID
*InterfaceClassGuid
,
2625 PCSTR ReferenceString
,
2626 DWORD CreationFlags
,
2627 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2630 LPWSTR ReferenceStringW
= NULL
;
2632 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2633 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2634 CreationFlags
, DeviceInterfaceData
);
2636 if (ReferenceString
)
2638 ReferenceStringW
= pSetupMultiByteToUnicode(ReferenceString
, CP_ACP
);
2639 if (ReferenceStringW
== NULL
) return FALSE
;
2642 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2643 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2644 DeviceInterfaceData
);
2646 MyFree(ReferenceStringW
);
2651 /***********************************************************************
2652 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2654 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2655 HDEVINFO DeviceInfoSet
,
2656 PSP_DEVINFO_DATA DeviceInfoData
,
2657 const GUID
*InterfaceClassGuid
,
2658 PCWSTR ReferenceString
,
2659 DWORD CreationFlags
,
2660 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2662 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2663 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2664 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2665 CreationFlags
, DeviceInterfaceData
);
2667 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2669 SetLastError(ERROR_INVALID_HANDLE
);
2672 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2674 SetLastError(ERROR_INVALID_HANDLE
);
2677 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2678 || !DeviceInfoData
->Reserved
)
2680 SetLastError(ERROR_INVALID_PARAMETER
);
2683 if (!InterfaceClassGuid
)
2685 SetLastError(ERROR_INVALID_USER_BUFFER
);
2689 FIXME("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2690 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2691 CreationFlags
, DeviceInterfaceData
);
2692 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2696 /***********************************************************************
2697 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2699 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2700 HDEVINFO DeviceInfoSet
,
2701 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2705 PCSTR InfSectionName
)
2708 PWSTR InfSectionNameW
= NULL
;
2710 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2711 samDesired
, InfHandle
, InfSectionName
);
2714 if (!InfSectionName
)
2716 SetLastError(ERROR_INVALID_PARAMETER
);
2717 return INVALID_HANDLE_VALUE
;
2719 InfSectionNameW
= pSetupMultiByteToUnicode(InfSectionName
, CP_ACP
);
2720 if (!InfSectionNameW
)
2721 return INVALID_HANDLE_VALUE
;
2723 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2724 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2726 MyFree(InfSectionNameW
);
2730 /***********************************************************************
2731 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2733 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2734 HDEVINFO DeviceInfoSet
,
2735 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2739 PCWSTR InfSectionName
)
2742 LPWSTR SymbolicLink
;
2743 DWORD Length
, Index
;
2745 WCHAR bracedGuidString
[39];
2746 struct DeviceInterface
*DevItf
;
2747 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2749 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2750 samDesired
, InfHandle
, InfSectionName
);
2752 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2753 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2755 SetLastError(ERROR_INVALID_HANDLE
);
2756 return INVALID_HANDLE_VALUE
;
2758 if (!DeviceInterfaceData
||
2759 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2760 !DeviceInterfaceData
->Reserved
)
2762 SetLastError(ERROR_INVALID_PARAMETER
);
2763 return INVALID_HANDLE_VALUE
;
2765 if (InfHandle
&& !InfSectionName
)
2767 SetLastError(ERROR_INVALID_PARAMETER
);
2768 return INVALID_HANDLE_VALUE
;
2771 hKey
= SetupDiOpenClassRegKeyExW(&DeviceInterfaceData
->InterfaceClassGuid
, samDesired
, DIOCR_INTERFACE
, NULL
, NULL
);
2772 if (hKey
== INVALID_HANDLE_VALUE
)
2774 hKey
= SetupDiOpenClassRegKeyExW(NULL
, samDesired
, DIOCR_INTERFACE
, NULL
, NULL
);
2775 if (hKey
== INVALID_HANDLE_VALUE
)
2777 SetLastError(ERROR_INVALID_PARAMETER
);
2778 return INVALID_HANDLE_VALUE
;
2780 SETUPDI_GuidToString(&DeviceInterfaceData
->InterfaceClassGuid
, bracedGuidString
);
2782 if (RegCreateKeyExW(hKey
, bracedGuidString
, 0, NULL
, 0, samDesired
, NULL
, &hDevKey
, NULL
) != ERROR_SUCCESS
)
2784 SetLastError(ERROR_INVALID_PARAMETER
);
2785 return INVALID_HANDLE_VALUE
;
2791 DevItf
= (struct DeviceInterface
*)DeviceInterfaceData
->Reserved
;
2793 Length
= (wcslen(DevItf
->SymbolicLink
)+1) * sizeof(WCHAR
);
2794 SymbolicLink
= HeapAlloc(GetProcessHeap(), 0, Length
);
2798 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2799 return INVALID_HANDLE_VALUE
;
2802 wcscpy(SymbolicLink
, DevItf
->SymbolicLink
);
2805 while(SymbolicLink
[Index
])
2807 if (SymbolicLink
[Index
] == L
'\\')
2809 SymbolicLink
[Index
] = L
'#';
2814 rc
= RegCreateKeyExW(hKey
, SymbolicLink
, 0, NULL
, 0, samDesired
, NULL
, &hDevKey
, NULL
);
2817 HeapFree(GetProcessHeap(), 0, SymbolicLink
);
2819 if (rc
== ERROR_SUCCESS
)
2821 if (InfHandle
&& InfSectionName
)
2823 if (!SetupInstallFromInfSection(NULL
/*FIXME */,
2826 SPINST_INIFILES
| SPINST_REGISTRY
| SPINST_INI2REG
| SPINST_FILES
| SPINST_BITREG
| SPINST_REGSVR
| SPINST_UNREGSVR
| SPINST_PROFILEITEMS
| SPINST_COPYINF
,
2830 set
->SelectedDevice
->InstallParams
.InstallMsgHandler
,
2831 set
->SelectedDevice
->InstallParams
.InstallMsgHandlerContext
,
2832 INVALID_HANDLE_VALUE
,
2835 RegCloseKey(hDevKey
);
2836 return INVALID_HANDLE_VALUE
;
2845 /***********************************************************************
2846 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2848 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2849 HDEVINFO DeviceInfoSet
,
2850 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2853 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2856 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2858 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2859 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2861 SetLastError(ERROR_INVALID_HANDLE
);
2864 if (!DeviceInterfaceData
||
2865 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2866 !DeviceInterfaceData
->Reserved
)
2868 SetLastError(ERROR_INVALID_PARAMETER
);
2872 FIXME("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2873 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2877 /***********************************************************************
2878 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2881 * DeviceInfoSet [I] Set of devices from which to enumerate
2883 * DeviceInfoData [I] (Optional) If specified, a specific device
2884 * instance from which to enumerate interfaces.
2885 * If it isn't specified, all interfaces for all
2886 * devices in the set are enumerated.
2887 * InterfaceClassGuid [I] The interface class to enumerate.
2888 * MemberIndex [I] An index of the interface instance to enumerate.
2889 * A caller should start with MemberIndex set to 0,
2890 * and continue until the function fails with
2891 * ERROR_NO_MORE_ITEMS.
2892 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2893 * member must be set to
2894 * sizeof(SP_DEVICE_INTERFACE_DATA).
2897 * Success: non-zero value.
2898 * Failure: FALSE. Call GetLastError() for more info.
2900 BOOL WINAPI
SetupDiEnumDeviceInterfaces(
2901 HDEVINFO DeviceInfoSet
,
2902 PSP_DEVINFO_DATA DeviceInfoData
,
2903 CONST GUID
* InterfaceClassGuid
,
2905 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2907 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2910 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet
, DeviceInfoData
,
2911 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
2913 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2914 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2916 SetLastError(ERROR_INVALID_HANDLE
);
2919 if (DeviceInfoData
&& (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2920 !DeviceInfoData
->Reserved
))
2922 SetLastError(ERROR_INVALID_PARAMETER
);
2925 if (!DeviceInterfaceData
||
2926 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2928 SetLastError(ERROR_INVALID_PARAMETER
);
2933 struct DeviceInfo
*devInfo
=
2934 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2936 PLIST_ENTRY InterfaceListEntry
= devInfo
->InterfaceListHead
.Flink
;
2937 while (InterfaceListEntry
!= &devInfo
->InterfaceListHead
&& !found
)
2939 struct DeviceInterface
*DevItf
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
2940 if (!IsEqualIID(&DevItf
->InterfaceClassGuid
, InterfaceClassGuid
))
2942 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2945 if (MemberIndex
-- == 0)
2947 /* return this item */
2948 memcpy(&DeviceInterfaceData
->InterfaceClassGuid
,
2949 &DevItf
->InterfaceClassGuid
,
2951 DeviceInterfaceData
->Flags
= DevItf
->Flags
;
2952 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)DevItf
;
2956 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2959 SetLastError(ERROR_NO_MORE_ITEMS
);
2964 PLIST_ENTRY ItemList
= set
->ListHead
.Flink
;
2965 while (ItemList
!= &set
->ListHead
&& !found
)
2967 PLIST_ENTRY InterfaceListEntry
;
2968 struct DeviceInfo
*devInfo
=
2969 CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
2970 InterfaceListEntry
= devInfo
->InterfaceListHead
.Flink
;
2971 while (InterfaceListEntry
!= &devInfo
->InterfaceListHead
&& !found
)
2973 struct DeviceInterface
*DevItf
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
2974 if (!IsEqualIID(&DevItf
->InterfaceClassGuid
, InterfaceClassGuid
))
2976 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2979 if (MemberIndex
-- == 0)
2981 /* return this item */
2982 memcpy(&DeviceInterfaceData
->InterfaceClassGuid
,
2983 &DevItf
->InterfaceClassGuid
,
2985 DeviceInterfaceData
->Flags
= DevItf
->Flags
;
2986 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)DevItf
;
2990 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2992 ItemList
= ItemList
->Flink
;
2996 SetLastError(ERROR_NO_MORE_ITEMS
);
3001 /***********************************************************************
3002 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
3004 * Destroy a DeviceInfoList and free all used memory of the list.
3007 * devinfo [I] DeviceInfoList pointer to list to destroy
3010 * Success: non zero value.
3011 * Failure: zero value.
3013 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
3017 TRACE("%p\n", devinfo
);
3018 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
3020 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
3022 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
3024 ret
= DestroyDeviceInfoSet(list
);
3029 SetLastError(ERROR_INVALID_HANDLE
);
3034 /***********************************************************************
3035 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
3037 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
3038 HDEVINFO DeviceInfoSet
,
3039 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
3040 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
3041 DWORD DeviceInterfaceDetailDataSize
,
3042 PDWORD RequiredSize
,
3043 PSP_DEVINFO_DATA DeviceInfoData
)
3045 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3046 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailDataW
= NULL
;
3047 DWORD sizeW
= 0, bytesNeeded
;
3050 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
3051 DeviceInterfaceData
, DeviceInterfaceDetailData
,
3052 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
3054 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
3055 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3057 SetLastError(ERROR_INVALID_HANDLE
);
3060 if (!DeviceInterfaceData
||
3061 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
3062 !DeviceInterfaceData
->Reserved
)
3064 SetLastError(ERROR_INVALID_PARAMETER
);
3067 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
)))
3069 SetLastError(ERROR_INVALID_USER_BUFFER
);
3073 if((DeviceInterfaceDetailDataSize
!= 0) &&
3074 (DeviceInterfaceDetailDataSize
< (FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + sizeof(CHAR
))))
3076 SetLastError(ERROR_INVALID_USER_BUFFER
);
3080 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
3082 SetLastError(ERROR_INVALID_USER_BUFFER
);
3087 if (DeviceInterfaceDetailData
!= NULL
)
3089 sizeW
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
3090 + (DeviceInterfaceDetailDataSize
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
)) * sizeof(WCHAR
);
3091 DeviceInterfaceDetailDataW
= (PSP_DEVICE_INTERFACE_DETAIL_DATA_W
)MyMalloc(sizeW
);
3092 if (!DeviceInterfaceDetailDataW
)
3094 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3096 DeviceInterfaceDetailDataW
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
);
3098 if (!DeviceInterfaceDetailData
|| (DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataW
))
3100 ret
= SetupDiGetDeviceInterfaceDetailW(
3102 DeviceInterfaceData
,
3103 DeviceInterfaceDetailDataW
,
3107 bytesNeeded
= (sizeW
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)) / sizeof(WCHAR
)
3108 + FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
);
3110 *RequiredSize
= bytesNeeded
;
3111 if (ret
&& DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
>= bytesNeeded
)
3113 if (!WideCharToMultiByte(
3115 DeviceInterfaceDetailDataW
->DevicePath
, -1,
3116 DeviceInterfaceDetailData
->DevicePath
, DeviceInterfaceDetailDataSize
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
3123 MyFree(DeviceInterfaceDetailDataW
);
3128 /***********************************************************************
3129 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
3131 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
3132 HDEVINFO DeviceInfoSet
,
3133 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
3134 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
3135 DWORD DeviceInterfaceDetailDataSize
,
3136 PDWORD RequiredSize
,
3137 PSP_DEVINFO_DATA DeviceInfoData
)
3139 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3142 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
3143 DeviceInterfaceData
, DeviceInterfaceDetailData
,
3144 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
3146 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
3147 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3149 SetLastError(ERROR_INVALID_HANDLE
);
3152 if (!DeviceInterfaceData
||
3153 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
3154 !DeviceInterfaceData
->Reserved
)
3156 SetLastError(ERROR_INVALID_PARAMETER
);
3159 if (DeviceInterfaceDetailData
&& DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
))
3161 SetLastError(ERROR_INVALID_USER_BUFFER
);
3164 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
3166 SetLastError(ERROR_INVALID_USER_BUFFER
);
3169 if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
3171 SetLastError(ERROR_INVALID_PARAMETER
);
3174 if ((DeviceInterfaceDetailData
!= NULL
)
3175 && (DeviceInterfaceDetailDataSize
< (FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)) + sizeof(WCHAR
)))
3177 SetLastError(ERROR_INVALID_PARAMETER
);
3182 struct DeviceInterface
*deviceInterface
= (struct DeviceInterface
*)DeviceInterfaceData
->Reserved
;
3183 LPCWSTR devName
= deviceInterface
->SymbolicLink
;
3184 DWORD sizeRequired
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
) +
3185 (lstrlenW(devName
) + 1) * sizeof(WCHAR
);
3187 if (sizeRequired
> DeviceInterfaceDetailDataSize
)
3189 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3191 *RequiredSize
= sizeRequired
;
3195 strcpyW(DeviceInterfaceDetailData
->DevicePath
, devName
);
3196 TRACE("DevicePath is %s\n", debugstr_w(DeviceInterfaceDetailData
->DevicePath
));
3199 memcpy(&DeviceInfoData
->ClassGuid
,
3200 &deviceInterface
->DeviceInfo
->ClassGuid
,
3202 DeviceInfoData
->DevInst
= deviceInterface
->DeviceInfo
->dnDevInst
;
3203 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInterface
->DeviceInfo
;
3211 struct PropertyMapEntry
3218 static struct PropertyMapEntry PropertyMap
[] = {
3219 { REG_SZ
, "DeviceDesc", REGSTR_VAL_DEVDESC
},
3220 { REG_MULTI_SZ
, "HardwareId", REGSTR_VAL_HARDWAREID
},
3221 { REG_MULTI_SZ
, "CompatibleIDs", REGSTR_VAL_COMPATIBLEIDS
},
3222 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
3223 { REG_SZ
, "Service", REGSTR_VAL_SERVICE
},
3224 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
3225 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
3226 { REG_SZ
, "Class", REGSTR_VAL_CLASS
},
3227 { REG_SZ
, "ClassGUID", REGSTR_VAL_CLASSGUID
},
3228 { REG_SZ
, "Driver", REGSTR_VAL_DRIVER
},
3229 { REG_DWORD
, "ConfigFlags", REGSTR_VAL_CONFIGFLAGS
},
3230 { REG_SZ
, "Mfg", REGSTR_VAL_MFG
},
3231 { REG_SZ
, "FriendlyName", REGSTR_VAL_FRIENDLYNAME
},
3232 { REG_SZ
, "LocationInformation", REGSTR_VAL_LOCATION_INFORMATION
},
3233 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3234 { REG_DWORD
, "Capabilities", REGSTR_VAL_CAPABILITIES
},
3235 { REG_DWORD
, "UINumber", REGSTR_VAL_UI_NUMBER
},
3236 { REG_MULTI_SZ
, "UpperFilters", REGSTR_VAL_UPPERFILTERS
},
3237 { REG_MULTI_SZ
, "LowerFilters", REGSTR_VAL_LOWERFILTERS
},
3238 { 0, NULL
, NULL
}, /* SPDRP_BUSTYPEGUID */
3239 { 0, NULL
, NULL
}, /* SPDRP_LEGACYBUSTYPE */
3240 { 0, NULL
, NULL
}, /* SPDRP_BUSNUMBER */
3241 { 0, NULL
, NULL
}, /* SPDRP_ENUMERATOR_NAME */
3242 { REG_BINARY
, "Security", REGSTR_SECURITY
},
3243 { 0, NULL
, NULL
}, /* SPDRP_SECURITY_SDS */
3244 { 0, NULL
, NULL
}, /* SPDRP_DEVTYPE */
3245 { 0, NULL
, NULL
}, /* SPDRP_EXCLUSIVE */
3246 { 0, NULL
, NULL
}, /* SPDRP_CHARACTERISTICS */
3247 { 0, NULL
, NULL
}, /* SPDRP_ADDRESS */
3248 { REG_SZ
, "UINumberDescFormat", REGSTR_UI_NUMBER_DESC_FORMAT
},
3249 { 0, NULL
, NULL
}, /* SPDRP_DEVICE_POWER_DATA */
3250 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY */
3251 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY_HW_DEFAULT */
3252 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY_OVERRIDE */
3253 { 0, NULL
, NULL
}, /* SPDRP_INSTALL_STATE */
3256 /***********************************************************************
3257 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3259 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
3260 HDEVINFO DeviceInfoSet
,
3261 PSP_DEVINFO_DATA DeviceInfoData
,
3263 PDWORD PropertyRegDataType
,
3264 PBYTE PropertyBuffer
,
3265 DWORD PropertyBufferSize
,
3266 PDWORD RequiredSize
)
3269 BOOL bIsStringProperty
;
3271 DWORD RequiredSizeA
, RequiredSizeW
;
3272 DWORD PropertyBufferSizeW
= 0;
3273 PBYTE PropertyBufferW
= NULL
;
3275 TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
,
3276 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3279 if (PropertyBufferSize
!= 0)
3281 PropertyBufferSizeW
= PropertyBufferSize
* 2;
3282 PropertyBufferW
= HeapAlloc(GetProcessHeap(), 0, PropertyBufferSizeW
);
3283 if (!PropertyBufferW
)
3285 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3290 ret
= SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet
,
3295 PropertyBufferSizeW
,
3298 if (ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
3300 bIsStringProperty
= (RegType
== REG_SZ
|| RegType
== REG_MULTI_SZ
|| RegType
== REG_EXPAND_SZ
);
3302 if (bIsStringProperty
)
3303 RequiredSizeA
= RequiredSizeW
/ sizeof(WCHAR
);
3305 RequiredSizeA
= RequiredSizeW
;
3307 *RequiredSize
= RequiredSizeA
;
3308 if (PropertyRegDataType
)
3309 *PropertyRegDataType
= RegType
;
3314 HeapFree(GetProcessHeap(), 0, PropertyBufferW
);
3318 if (RequiredSizeA
<= PropertyBufferSize
)
3320 if (bIsStringProperty
&& PropertyBufferSize
> 0)
3322 if (WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)PropertyBufferW
, RequiredSizeW
/ sizeof(WCHAR
), (LPSTR
)PropertyBuffer
, PropertyBufferSize
, NULL
, NULL
) == 0)
3324 /* Last error is already set by WideCharToMultiByte */
3329 memcpy(PropertyBuffer
, PropertyBufferW
, RequiredSizeA
);
3333 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3337 HeapFree(GetProcessHeap(), 0, PropertyBufferW
);
3341 /***********************************************************************
3342 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3344 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3345 HDEVINFO DeviceInfoSet
,
3346 PSP_DEVINFO_DATA DeviceInfoData
,
3348 PDWORD PropertyRegDataType
,
3349 PBYTE PropertyBuffer
,
3350 DWORD PropertyBufferSize
,
3351 PDWORD RequiredSize
)
3354 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3355 struct DeviceInfo
*devInfo
;
3357 TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
,
3358 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3361 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3363 SetLastError(ERROR_INVALID_HANDLE
);
3366 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3368 SetLastError(ERROR_INVALID_HANDLE
);
3371 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3372 || !DeviceInfoData
->Reserved
)
3374 SetLastError(ERROR_INVALID_PARAMETER
);
3377 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3378 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3379 && PropertyMap
[Property
].nameW
)
3381 DWORD size
= PropertyBufferSize
;
3384 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_QUERY_VALUE
);
3385 if (hKey
== INVALID_HANDLE_VALUE
)
3387 l
= RegQueryValueExW(hKey
, PropertyMap
[Property
].nameW
,
3388 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3392 *RequiredSize
= size
;
3395 if (PropertyBuffer
!= NULL
|| size
== 0)
3398 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3400 case ERROR_MORE_DATA
:
3401 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3407 else if (Property
== SPDRP_PHYSICAL_DEVICE_OBJECT_NAME
)
3409 DWORD required
= (strlenW(devInfo
->Data
) + 1) * sizeof(WCHAR
);
3411 if (PropertyRegDataType
)
3412 *PropertyRegDataType
= REG_SZ
;
3414 *RequiredSize
= required
;
3415 if (PropertyBufferSize
>= required
)
3417 strcpyW((LPWSTR
)PropertyBuffer
, devInfo
->Data
);
3421 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3425 ERR("Property 0x%lx not implemented\n", Property
);
3426 SetLastError(ERROR_NOT_SUPPORTED
);
3431 /***********************************************************************
3432 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3434 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3435 HDEVINFO DeviceInfoSet
,
3436 PSP_DEVINFO_DATA DeviceInfoData
,
3438 const BYTE
*PropertyBuffer
,
3439 DWORD PropertyBufferSize
)
3442 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3444 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3445 PropertyBuffer
, PropertyBufferSize
);
3447 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3449 SetLastError(ERROR_INVALID_HANDLE
);
3452 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3454 SetLastError(ERROR_INVALID_HANDLE
);
3457 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3458 || !DeviceInfoData
->Reserved
)
3460 SetLastError(ERROR_INVALID_PARAMETER
);
3464 FIXME("%p %p 0x%lx %p 0x%lx\n", DeviceInfoSet
, DeviceInfoData
,
3465 Property
, PropertyBuffer
, PropertyBufferSize
);
3466 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3470 /***********************************************************************
3471 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3473 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
3474 HDEVINFO DeviceInfoSet
,
3475 PSP_DEVINFO_DATA DeviceInfoData
,
3477 const BYTE
*PropertyBuffer
,
3478 DWORD PropertyBufferSize
)
3481 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3483 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3484 PropertyBuffer
, PropertyBufferSize
);
3486 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3488 SetLastError(ERROR_INVALID_HANDLE
);
3491 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3493 SetLastError(ERROR_INVALID_HANDLE
);
3496 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3497 || !DeviceInfoData
->Reserved
)
3499 SetLastError(ERROR_INVALID_PARAMETER
);
3502 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3503 && PropertyMap
[Property
].nameW
)
3507 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_SET_VALUE
);
3508 if (hKey
== INVALID_HANDLE_VALUE
)
3510 /* Write new data */
3512 hKey
, PropertyMap
[Property
].nameW
, 0,
3513 PropertyMap
[Property
].regType
, PropertyBuffer
,
3514 PropertyBufferSize
);
3523 ERR("Property 0x%lx not implemented\n", Property
);
3524 SetLastError(ERROR_NOT_SUPPORTED
);
3527 TRACE("Returning %d\n", ret
);
3531 /***********************************************************************
3532 * SetupDiInstallClassA (SETUPAPI.@)
3534 BOOL WINAPI
SetupDiInstallClassA(
3540 return SetupDiInstallClassExA(hwndParent
, InfFileName
, Flags
, FileQueue
, NULL
, NULL
, NULL
);
3543 /***********************************************************************
3544 * SetupDiInstallClassExA (SETUPAPI.@)
3547 SetupDiInstallClassExA(
3548 IN HWND hwndParent OPTIONAL
,
3549 IN PCSTR InfFileName OPTIONAL
,
3551 IN HSPFILEQ FileQueue OPTIONAL
,
3552 IN CONST GUID
*InterfaceClassGuid OPTIONAL
,
3556 PWSTR InfFileNameW
= NULL
;
3561 SetLastError(ERROR_INVALID_PARAMETER
);
3566 InfFileNameW
= pSetupMultiByteToUnicode(InfFileName
, CP_ACP
);
3567 if (InfFileNameW
== NULL
)
3569 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3574 Result
= SetupDiInstallClassExW(hwndParent
, InfFileNameW
, Flags
,
3575 FileQueue
, InterfaceClassGuid
, Reserved1
, Reserved2
);
3577 MyFree(InfFileNameW
);
3582 HKEY
SETUP_CreateClassKey(HINF hInf
)
3584 static const WCHAR slash
[] = { '\\',0 };
3585 WCHAR FullBuffer
[MAX_PATH
];
3586 WCHAR Buffer
[MAX_PATH
];
3590 if (!SetupGetLineTextW(NULL
,
3598 return INVALID_HANDLE_VALUE
;
3601 lstrcpyW(FullBuffer
, REGSTR_PATH_CLASS_NT
);
3602 lstrcatW(FullBuffer
, slash
);
3603 lstrcatW(FullBuffer
, Buffer
);
3605 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3611 if (!SetupGetLineTextW(NULL
,
3619 return INVALID_HANDLE_VALUE
;
3622 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3626 REG_OPTION_NON_VOLATILE
,
3632 return INVALID_HANDLE_VALUE
;
3636 if (RegSetValueExW(hClassKey
,
3641 RequiredSize
* sizeof(WCHAR
)))
3643 RegCloseKey(hClassKey
);
3644 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3646 return INVALID_HANDLE_VALUE
;
3652 /***********************************************************************
3653 * SetupDiInstallClassW (SETUPAPI.@)
3655 BOOL WINAPI
SetupDiInstallClassW(
3661 return SetupDiInstallClassExW(hwndParent
, InfFileName
, Flags
, FileQueue
, NULL
, NULL
, NULL
);
3665 /***********************************************************************
3666 * SetupDiOpenClassRegKey (SETUPAPI.@)
3668 HKEY WINAPI
SetupDiOpenClassRegKey(
3669 const GUID
* ClassGuid
,
3672 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3673 DIOCR_INSTALLER
, NULL
, NULL
);
3677 /***********************************************************************
3678 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3680 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3681 const GUID
* ClassGuid
,
3687 PWSTR MachineNameW
= NULL
;
3690 TRACE("%s 0x%lx 0x%lx %s %p\n", debugstr_guid(ClassGuid
), samDesired
,
3691 Flags
, debugstr_a(MachineName
), Reserved
);
3695 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
3696 if (MachineNameW
== NULL
)
3697 return INVALID_HANDLE_VALUE
;
3700 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3701 Flags
, MachineNameW
, Reserved
);
3703 MyFree(MachineNameW
);
3709 /***********************************************************************
3710 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3712 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3713 const GUID
* ClassGuid
,
3725 TRACE("%s 0x%lx 0x%lx %s %p\n", debugstr_guid(ClassGuid
), samDesired
,
3726 Flags
, debugstr_w(MachineName
), Reserved
);
3728 if (MachineName
!= NULL
)
3730 l
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &HKLM
);
3731 if (l
!= ERROR_SUCCESS
)
3734 return INVALID_HANDLE_VALUE
;
3738 HKLM
= HKEY_LOCAL_MACHINE
;
3740 if (Flags
== DIOCR_INSTALLER
)
3742 lpKeyName
= REGSTR_PATH_CLASS_NT
;
3744 else if (Flags
== DIOCR_INTERFACE
)
3746 lpKeyName
= REGSTR_PATH_DEVICE_CLASSES
;
3750 ERR("Invalid Flags parameter!\n");
3751 SetLastError(ERROR_INVALID_FLAGS
);
3752 if (MachineName
!= NULL
) RegCloseKey(HKLM
);
3753 return INVALID_HANDLE_VALUE
;
3758 if ((l
= RegOpenKeyExW(HKLM
,
3764 SetLastError(ERROR_INVALID_CLASS
);
3765 hClassesKey
= INVALID_HANDLE_VALUE
;
3767 if (MachineName
!= NULL
)
3773 WCHAR bracedGuidString
[39];
3775 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3777 if (!(l
= RegOpenKeyExW(HKLM
,
3783 if (MachineName
!= NULL
)
3786 if ((l
= RegOpenKeyExW(hClassesKey
,
3793 key
= INVALID_HANDLE_VALUE
;
3795 RegCloseKey(hClassesKey
);
3799 if (MachineName
!= NULL
) RegCloseKey(HKLM
);
3801 key
= INVALID_HANDLE_VALUE
;
3808 /***********************************************************************
3809 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3811 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3812 HDEVINFO DeviceInfoSet
,
3815 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3817 struct DeviceInfoSet
* list
;
3819 DWORD dwLength
, dwError
, dwIndex
, dwKeyName
, dwSubIndex
;
3821 WCHAR Buffer
[MAX_PATH
+ 1];
3822 WCHAR SymBuffer
[MAX_PATH
+ 1];
3823 WCHAR InstancePath
[MAX_PATH
+ 1];
3824 HKEY hKey
, hDevKey
, hSymKey
;
3825 struct DeviceInfo
* deviceInfo
;
3826 struct DeviceInterface
*deviceInterface
;
3828 PLIST_ENTRY ItemList
;
3829 PLIST_ENTRY InterfaceListEntry
;
3831 TRACE("%p %s %08x %p\n",
3832 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3835 if (DeviceInterfaceData
&& DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
3837 SetLastError(ERROR_INVALID_PARAMETER
);
3841 if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3843 SetLastError(ERROR_INVALID_HANDLE
);
3847 list
= (struct DeviceInfoSet
* )DeviceInfoSet
;
3849 dwLength
= wcslen(DevicePath
);
3852 /* path must be at least a guid length + L'\0' */
3853 SetLastError(ERROR_BAD_PATHNAME
);
3857 if (DevicePath
[0] != L
'\\' ||
3858 DevicePath
[1] != L
'\\' ||
3859 (DevicePath
[2] != L
'?' && DevicePath
[2] != L
'.') ||
3860 DevicePath
[3] != L
'\\')
3862 /* invalid formatted path */
3863 SetLastError(ERROR_BAD_PATHNAME
);
3867 /* check for reference strings */
3868 pEnd
= wcschr(&DevicePath
[4], L
'\\');
3871 /* no reference string */
3872 pEnd
= DevicePath
+ dwLength
;
3876 wcscpy(Buffer
, pEnd
- 37);
3879 dwError
= UuidFromStringW(Buffer
, &ClassId
);
3880 if (dwError
!= NOERROR
)
3882 /* invalid formatted path */
3883 SetLastError(ERROR_BAD_PATHNAME
);
3887 hKey
= SetupDiOpenClassRegKeyExW(&ClassId
, KEY_READ
, DIOCR_INTERFACE
, list
->MachineName
, NULL
);
3889 if (hKey
== INVALID_HANDLE_VALUE
)
3891 /* invalid device class */
3895 ItemList
= list
->ListHead
.Flink
;
3896 while (ItemList
!= &list
->ListHead
)
3898 deviceInfo
= CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
3899 InterfaceListEntry
= deviceInfo
->InterfaceListHead
.Flink
;
3900 while (InterfaceListEntry
!= &deviceInfo
->InterfaceListHead
)
3902 deviceInterface
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
3903 if (!IsEqualIID(&deviceInterface
->InterfaceClassGuid
, &ClassId
))
3905 InterfaceListEntry
= InterfaceListEntry
->Flink
;
3909 if (!wcsicmp(deviceInterface
->SymbolicLink
, DevicePath
))
3911 if (DeviceInterfaceData
)
3913 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)deviceInterface
;
3914 DeviceInterfaceData
->Flags
= deviceInterface
->Flags
;
3915 CopyMemory(&DeviceInterfaceData
->InterfaceClassGuid
, &ClassId
, sizeof(GUID
));
3929 dwKeyName
= sizeof(Buffer
) / sizeof(WCHAR
);
3930 dwError
= RegEnumKeyExW(hKey
, dwIndex
, Buffer
, &dwKeyName
, NULL
, NULL
, NULL
, NULL
);
3932 if (dwError
!= ERROR_SUCCESS
)
3935 if (RegOpenKeyExW(hKey
, Buffer
, 0, KEY_READ
, &hDevKey
) != ERROR_SUCCESS
)
3939 InstancePath
[0] = 0;
3940 dwKeyName
= sizeof(InstancePath
);
3942 dwError
= RegQueryValueExW(hDevKey
, L
"DeviceInstance", NULL
, NULL
, (LPBYTE
)InstancePath
, &dwKeyName
);
3947 dwKeyName
= sizeof(Buffer
) / sizeof(WCHAR
);
3948 dwError
= RegEnumKeyExW(hDevKey
, dwSubIndex
, Buffer
, &dwKeyName
, NULL
, NULL
, NULL
, NULL
);
3950 if (dwError
!= ERROR_SUCCESS
)
3953 dwError
= RegOpenKeyExW(hDevKey
, Buffer
, 0, KEY_READ
, &hSymKey
);
3954 if (dwError
!= ERROR_SUCCESS
)
3957 /* query for symbolic link */
3958 dwKeyName
= sizeof(SymBuffer
);
3959 SymBuffer
[0] = L
'\0';
3960 dwError
= RegQueryValueExW(hSymKey
, L
"SymbolicLink", NULL
, NULL
, (LPBYTE
)SymBuffer
, &dwKeyName
);
3962 if (dwError
!= ERROR_SUCCESS
)
3964 RegCloseKey(hSymKey
);
3968 if (!wcsicmp(SymBuffer
, DevicePath
))
3970 Ret
= CreateDeviceInfo(list
, InstancePath
, &ClassId
, &deviceInfo
);
3971 RegCloseKey(hSymKey
);
3972 RegCloseKey(hDevKey
);
3977 deviceInterface
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct DeviceInterface
) + (wcslen(SymBuffer
) + 1) * sizeof(WCHAR
));
3978 if (deviceInterface
)
3981 CopyMemory(&deviceInterface
->InterfaceClassGuid
, &ClassId
, sizeof(GUID
));
3982 deviceInterface
->DeviceInfo
= deviceInfo
;
3983 deviceInterface
->Flags
= SPINT_ACTIVE
; //FIXME
3985 wcscpy(deviceInterface
->SymbolicLink
, SymBuffer
);
3987 InsertTailList(&deviceInfo
->InterfaceListHead
, &deviceInterface
->ListEntry
);
3988 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
3991 if (DeviceInterfaceData
)
3993 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)deviceInterface
;
3994 DeviceInterfaceData
->Flags
= deviceInterface
->Flags
;
3995 CopyMemory(&DeviceInterfaceData
->InterfaceClassGuid
, &ClassId
, sizeof(GUID
));
4000 SetLastError(ERROR_INVALID_USER_BUFFER
);
4006 HeapFree(GetProcessHeap(), 0, deviceInfo
);
4011 RegCloseKey(hSymKey
);
4015 RegCloseKey(hDevKey
);
4023 /***********************************************************************
4024 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
4026 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
4027 HDEVINFO DeviceInfoSet
,
4030 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
4032 LPWSTR DevicePathW
= NULL
;
4035 TRACE("%p %s %08lx %p\n", DeviceInfoSet
, debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
4037 DevicePathW
= pSetupMultiByteToUnicode(DevicePath
, CP_ACP
);
4038 if (DevicePathW
== NULL
)
4041 bResult
= SetupDiOpenDeviceInterfaceW(DeviceInfoSet
,
4042 DevicePathW
, OpenFlags
, DeviceInterfaceData
);
4044 MyFree(DevicePathW
);
4049 /***********************************************************************
4050 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
4052 BOOL WINAPI
SetupDiSetClassInstallParamsA(
4053 HDEVINFO DeviceInfoSet
,
4054 PSP_DEVINFO_DATA DeviceInfoData
,
4055 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
4056 DWORD ClassInstallParamsSize
)
4058 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
4059 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
4064 IntSetupDiRegisterDeviceInfo(
4065 IN HDEVINFO DeviceInfoSet
,
4066 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
4068 return SetupDiRegisterDeviceInfo(DeviceInfoSet
, DeviceInfoData
, 0, NULL
, NULL
, NULL
);
4071 /***********************************************************************
4072 * SetupDiCallClassInstaller (SETUPAPI.@)
4074 BOOL WINAPI
SetupDiCallClassInstaller(
4075 DI_FUNCTION InstallFunction
,
4076 HDEVINFO DeviceInfoSet
,
4077 PSP_DEVINFO_DATA DeviceInfoData
)
4081 TRACE("%u %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
4084 SetLastError(ERROR_INVALID_PARAMETER
);
4085 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
4086 SetLastError(ERROR_INVALID_HANDLE
);
4087 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4088 SetLastError(ERROR_INVALID_HANDLE
);
4089 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->HKLM
!= HKEY_LOCAL_MACHINE
)
4090 SetLastError(ERROR_INVALID_HANDLE
);
4091 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4092 SetLastError(ERROR_INVALID_USER_BUFFER
);
4095 SP_DEVINSTALL_PARAMS_W InstallParams
;
4096 #define CLASS_COINSTALLER 0x1
4097 #define DEVICE_COINSTALLER 0x2
4098 #define CLASS_INSTALLER 0x4
4099 UCHAR CanHandle
= 0;
4100 DEFAULT_CLASS_INSTALL_PROC DefaultHandler
= NULL
;
4102 switch (InstallFunction
)
4104 case DIF_ADDPROPERTYPAGE_ADVANCED
:
4105 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4107 case DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
4108 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4110 case DIF_ALLOW_INSTALL
:
4111 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4114 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4116 case DIF_DESTROYPRIVATEDATA
:
4117 CanHandle
= CLASS_INSTALLER
;
4119 case DIF_INSTALLDEVICE
:
4120 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4121 DefaultHandler
= SetupDiInstallDevice
;
4123 case DIF_INSTALLDEVICEFILES
:
4124 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4125 DefaultHandler
= SetupDiInstallDriverFiles
;
4127 case DIF_INSTALLINTERFACES
:
4128 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4129 DefaultHandler
= SetupDiInstallDeviceInterfaces
;
4131 case DIF_NEWDEVICEWIZARD_FINISHINSTALL
:
4132 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4134 case DIF_NEWDEVICEWIZARD_POSTANALYZE
:
4135 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4137 case DIF_NEWDEVICEWIZARD_PREANALYZE
:
4138 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4140 case DIF_NEWDEVICEWIZARD_PRESELECT
:
4141 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4143 case DIF_NEWDEVICEWIZARD_SELECT
:
4144 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4146 case DIF_POWERMESSAGEWAKE
:
4147 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4149 case DIF_PROPERTYCHANGE
:
4150 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4151 DefaultHandler
= SetupDiChangeState
;
4153 case DIF_REGISTER_COINSTALLERS
:
4154 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4155 DefaultHandler
= SetupDiRegisterCoDeviceInstallers
;
4157 case DIF_REGISTERDEVICE
:
4158 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4159 DefaultHandler
= IntSetupDiRegisterDeviceInfo
;
4162 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4163 DefaultHandler
= SetupDiRemoveDevice
;
4165 case DIF_SELECTBESTCOMPATDRV
:
4166 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4167 DefaultHandler
= SetupDiSelectBestCompatDrv
;
4169 case DIF_SELECTDEVICE
:
4170 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4171 DefaultHandler
= SetupDiSelectDevice
;
4173 case DIF_TROUBLESHOOTER
:
4174 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4177 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4178 DefaultHandler
= SetupDiUnremoveDevice
;
4181 ERR("Install function %u not supported\n", InstallFunction
);
4182 SetLastError(ERROR_NOT_SUPPORTED
);
4185 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4186 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
))
4187 /* Don't process this call, as a parameter is invalid */
4192 LIST_ENTRY ClassCoInstallersListHead
;
4193 LIST_ENTRY DeviceCoInstallersListHead
;
4194 HMODULE ClassInstallerLibrary
= NULL
;
4195 CLASS_INSTALL_PROC ClassInstaller
= NULL
;
4196 COINSTALLER_CONTEXT_DATA Context
;
4197 PLIST_ENTRY ListEntry
;
4199 DWORD dwRegType
, dwLength
;
4200 DWORD rc
= NO_ERROR
;
4202 InitializeListHead(&ClassCoInstallersListHead
);
4203 InitializeListHead(&DeviceCoInstallersListHead
);
4205 if (CanHandle
& DEVICE_COINSTALLER
)
4207 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_QUERY_VALUE
);
4208 if (hKey
!= INVALID_HANDLE_VALUE
)
4210 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_COINSTALLERS_32
, NULL
, &dwRegType
, NULL
, &dwLength
);
4211 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_MULTI_SZ
)
4213 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
4214 if (KeyBuffer
!= NULL
)
4216 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_COINSTALLERS_32
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
4217 if (rc
== ERROR_SUCCESS
)
4220 for (ptr
= KeyBuffer
; *ptr
; ptr
+= strlenW(ptr
) + 1)
4222 /* Add coinstaller to DeviceCoInstallersListHead list */
4223 struct CoInstallerElement
*coinstaller
;
4224 TRACE("Got device coinstaller '%s'\n", debugstr_w(ptr
));
4225 coinstaller
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CoInstallerElement
));
4228 ZeroMemory(coinstaller
, sizeof(struct CoInstallerElement
));
4229 if (GetFunctionPointer(ptr
, &coinstaller
->Module
, (PVOID
*)&coinstaller
->Function
) == ERROR_SUCCESS
)
4230 InsertTailList(&DeviceCoInstallersListHead
, &coinstaller
->ListEntry
);
4232 HeapFree(GetProcessHeap(), 0, coinstaller
);
4235 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
4241 if (CanHandle
& CLASS_COINSTALLER
)
4245 REGSTR_PATH_CODEVICEINSTALLERS
,
4249 if (rc
== ERROR_SUCCESS
)
4251 LPWSTR lpGuidString
;
4252 if (UuidToStringW((UUID
*)&DeviceInfoData
->ClassGuid
, &lpGuidString
) == RPC_S_OK
)
4254 rc
= RegQueryValueExW(hKey
, lpGuidString
, NULL
, &dwRegType
, NULL
, &dwLength
);
4255 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_MULTI_SZ
)
4257 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
4258 if (KeyBuffer
!= NULL
)
4260 rc
= RegQueryValueExW(hKey
, lpGuidString
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
4261 if (rc
== ERROR_SUCCESS
)
4264 for (ptr
= KeyBuffer
; *ptr
; ptr
+= strlenW(ptr
) + 1)
4266 /* Add coinstaller to ClassCoInstallersListHead list */
4267 struct CoInstallerElement
*coinstaller
;
4268 TRACE("Got class coinstaller '%s'\n", debugstr_w(ptr
));
4269 coinstaller
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CoInstallerElement
));
4272 ZeroMemory(coinstaller
, sizeof(struct CoInstallerElement
));
4273 if (GetFunctionPointer(ptr
, &coinstaller
->Module
, (PVOID
*)&coinstaller
->Function
) == ERROR_SUCCESS
)
4274 InsertTailList(&ClassCoInstallersListHead
, &coinstaller
->ListEntry
);
4276 HeapFree(GetProcessHeap(), 0, coinstaller
);
4279 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
4282 RpcStringFreeW(&lpGuidString
);
4287 if ((CanHandle
& CLASS_INSTALLER
) && !(InstallParams
.FlagsEx
& DI_FLAGSEX_CI_FAILED
))
4289 hKey
= SetupDiOpenClassRegKey(&DeviceInfoData
->ClassGuid
, KEY_QUERY_VALUE
);
4290 if (hKey
!= INVALID_HANDLE_VALUE
)
4292 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_INSTALLER_32
, NULL
, &dwRegType
, NULL
, &dwLength
);
4293 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_SZ
)
4295 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
4296 if (KeyBuffer
!= NULL
)
4298 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_INSTALLER_32
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
4299 if (rc
== ERROR_SUCCESS
)
4301 /* Get ClassInstaller function pointer */
4302 TRACE("Got class installer '%s'\n", debugstr_w(KeyBuffer
));
4303 if (GetFunctionPointer(KeyBuffer
, &ClassInstallerLibrary
, (PVOID
*)&ClassInstaller
) != ERROR_SUCCESS
)
4305 InstallParams
.FlagsEx
|= DI_FLAGSEX_CI_FAILED
;
4306 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
4309 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
4316 /* Call Class co-installers */
4317 Context
.PostProcessing
= FALSE
;
4319 ListEntry
= ClassCoInstallersListHead
.Flink
;
4320 while (rc
== NO_ERROR
&& ListEntry
!= &ClassCoInstallersListHead
)
4322 struct CoInstallerElement
*coinstaller
;
4323 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4324 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4325 coinstaller
->PrivateData
= Context
.PrivateData
;
4326 if (rc
== ERROR_DI_POSTPROCESSING_REQUIRED
)
4328 coinstaller
->DoPostProcessing
= TRUE
;
4331 ListEntry
= ListEntry
->Flink
;
4334 /* Call Device co-installers */
4335 ListEntry
= DeviceCoInstallersListHead
.Flink
;
4336 while (rc
== NO_ERROR
&& ListEntry
!= &DeviceCoInstallersListHead
)
4338 struct CoInstallerElement
*coinstaller
;
4339 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4340 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4341 coinstaller
->PrivateData
= Context
.PrivateData
;
4342 if (rc
== ERROR_DI_POSTPROCESSING_REQUIRED
)
4344 coinstaller
->DoPostProcessing
= TRUE
;
4347 ListEntry
= ListEntry
->Flink
;
4350 /* Call Class installer */
4353 rc
= (*ClassInstaller
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
4354 FreeFunctionPointer(ClassInstallerLibrary
, ClassInstaller
);
4357 rc
= ERROR_DI_DO_DEFAULT
;
4359 /* Call default handler */
4360 if (rc
== ERROR_DI_DO_DEFAULT
)
4362 if (DefaultHandler
&& !(InstallParams
.Flags
& DI_NODI_DEFAULTACTION
))
4364 if ((*DefaultHandler
)(DeviceInfoSet
, DeviceInfoData
))
4367 rc
= GetLastError();
4373 /* Call Class co-installers that required postprocessing */
4374 Context
.PostProcessing
= TRUE
;
4375 ListEntry
= ClassCoInstallersListHead
.Flink
;
4376 while (ListEntry
!= &ClassCoInstallersListHead
)
4378 struct CoInstallerElement
*coinstaller
;
4379 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4380 if (coinstaller
->DoPostProcessing
)
4382 Context
.InstallResult
= rc
;
4383 Context
.PrivateData
= coinstaller
->PrivateData
;
4384 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4386 FreeFunctionPointer(coinstaller
->Module
, coinstaller
->Function
);
4387 ListEntry
= ListEntry
->Flink
;
4390 /* Call Device co-installers that required postprocessing */
4391 ListEntry
= DeviceCoInstallersListHead
.Flink
;
4392 while (ListEntry
!= &DeviceCoInstallersListHead
)
4394 struct CoInstallerElement
*coinstaller
;
4395 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4396 if (coinstaller
->DoPostProcessing
)
4398 Context
.InstallResult
= rc
;
4399 Context
.PrivateData
= coinstaller
->PrivateData
;
4400 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4402 FreeFunctionPointer(coinstaller
->Module
, coinstaller
->Function
);
4403 ListEntry
= ListEntry
->Flink
;
4406 /* Free allocated memory */
4407 while (!IsListEmpty(&ClassCoInstallersListHead
))
4409 ListEntry
= RemoveHeadList(&ClassCoInstallersListHead
);
4410 HeapFree(GetProcessHeap(), 0, CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
));
4412 while (!IsListEmpty(&DeviceCoInstallersListHead
))
4414 ListEntry
= RemoveHeadList(&DeviceCoInstallersListHead
);
4415 HeapFree(GetProcessHeap(), 0, CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
));
4418 ret
= (rc
== NO_ERROR
);
4422 TRACE("Returning %d\n", ret
);
4426 /***********************************************************************
4427 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
4429 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
4430 HDEVINFO DeviceInfoSet
,
4431 PSP_DEVINFO_DATA DeviceInfoData
,
4432 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
4434 SP_DEVINSTALL_PARAMS_W deviceInstallParamsW
;
4437 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4439 if (DeviceInstallParams
== NULL
)
4440 SetLastError(ERROR_INVALID_PARAMETER
);
4441 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_A
))
4442 SetLastError(ERROR_INVALID_USER_BUFFER
);
4445 deviceInstallParamsW
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4446 ret
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &deviceInstallParamsW
);
4450 /* Do W->A conversion */
4452 DeviceInstallParams
,
4453 &deviceInstallParamsW
,
4454 FIELD_OFFSET(SP_DEVINSTALL_PARAMS_W
, DriverPath
));
4455 if (WideCharToMultiByte(CP_ACP
, 0, deviceInstallParamsW
.DriverPath
, -1,
4456 DeviceInstallParams
->DriverPath
, MAX_PATH
, NULL
, NULL
) == 0)
4458 DeviceInstallParams
->DriverPath
[0] = '\0';
4464 TRACE("Returning %d\n", ret
);
4468 /***********************************************************************
4469 * SetupDiGetDeviceInfoListClass (SETUPAPI.@)
4472 SetupDiGetDeviceInfoListClass(
4473 IN HDEVINFO DeviceInfoSet
,
4474 OUT LPGUID ClassGuid
)
4476 struct DeviceInfoSet
*list
;
4479 TRACE("%p %p\n", DeviceInfoSet
, ClassGuid
);
4482 SetLastError(ERROR_INVALID_HANDLE
);
4483 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4484 SetLastError(ERROR_INVALID_HANDLE
);
4485 else if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
4486 SetLastError(ERROR_NO_ASSOCIATED_CLASS
);
4489 memcpy(&ClassGuid
, &list
->ClassGuid
, sizeof(GUID
));
4494 TRACE("Returning %d\n", ret
);
4498 /***********************************************************************
4499 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
4502 SetupDiGetDeviceInstallParamsW(
4503 IN HDEVINFO DeviceInfoSet
,
4504 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4505 OUT PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4507 struct DeviceInfoSet
*list
;
4510 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4513 SetLastError(ERROR_INVALID_HANDLE
);
4514 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4515 SetLastError(ERROR_INVALID_HANDLE
);
4516 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4517 SetLastError(ERROR_INVALID_USER_BUFFER
);
4518 else if (!DeviceInstallParams
)
4519 SetLastError(ERROR_INVALID_PARAMETER
);
4520 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_W
))
4521 SetLastError(ERROR_INVALID_USER_BUFFER
);
4524 PSP_DEVINSTALL_PARAMS_W Source
;
4527 Source
= &((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->InstallParams
;
4529 Source
= &list
->InstallParams
;
4535 memcpy(DeviceInstallParams
, Source
, Source
->cbSize
);
4537 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4539 SetLastError(RtlNtStatusToDosError(_SEH2_GetExceptionCode()));
4545 TRACE("Returning %d\n", ret
);
4550 CheckDeviceInstallParameters(
4551 IN PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4553 DWORD SupportedFlags
=
4554 DI_NOVCP
| /* 0x00000008 */
4555 DI_DIDCOMPAT
| /* 0x00000010 */
4556 DI_DIDCLASS
| /* 0x00000020 */
4557 DI_NEEDRESTART
| /* 0x00000080 */
4558 DI_NEEDREBOOT
| /* 0x00000100 */
4559 DI_RESOURCEPAGE_ADDED
| /* 0x00002000 */
4560 DI_PROPERTIES_CHANGE
| /* 0x00004000 */
4561 DI_ENUMSINGLEINF
| /* 0x00010000 */
4562 DI_DONOTCALLCONFIGMG
| /* 0x00020000 */
4563 DI_CLASSINSTALLPARAMS
| /* 0x00100000 */
4564 DI_NODI_DEFAULTACTION
| /* 0x00200000 */
4565 DI_QUIETINSTALL
| /* 0x00800000 */
4566 DI_NOFILECOPY
| /* 0x01000000 */
4567 DI_DRIVERPAGE_ADDED
; /* 0x04000000 */
4568 DWORD SupportedFlagsEx
=
4569 DI_FLAGSEX_CI_FAILED
| /* 0x00000004 */
4570 DI_FLAGSEX_DIDINFOLIST
| /* 0x00000010 */
4571 DI_FLAGSEX_DIDCOMPATINFO
| /* 0x00000020 */
4572 DI_FLAGSEX_ALLOWEXCLUDEDDRVS
| /* 0x00000800 */
4573 DI_FLAGSEX_NO_DRVREG_MODIFY
| /* 0x00008000 */
4574 DI_FLAGSEX_INSTALLEDDRIVER
; /* 0x04000000 */
4577 /* FIXME: add support for more flags */
4579 /* FIXME: DI_CLASSINSTALLPARAMS flag is not correctly used.
4580 * It should be checked before accessing to other values
4581 * of the SP_DEVINSTALL_PARAMS structure */
4583 if (DeviceInstallParams
->Flags
& ~SupportedFlags
)
4585 FIXME("Unknown Flags: 0x%08lx\n", DeviceInstallParams
->Flags
& ~SupportedFlags
);
4586 SetLastError(ERROR_INVALID_FLAGS
);
4588 else if (DeviceInstallParams
->FlagsEx
& ~SupportedFlagsEx
)
4590 FIXME("Unknown FlagsEx: 0x%08lx\n", DeviceInstallParams
->FlagsEx
& ~SupportedFlagsEx
);
4591 SetLastError(ERROR_INVALID_FLAGS
);
4593 else if ((DeviceInstallParams
->Flags
& DI_NOVCP
)
4594 && (DeviceInstallParams
->FileQueue
== NULL
|| DeviceInstallParams
->FileQueue
== (HSPFILEQ
)INVALID_HANDLE_VALUE
))
4595 SetLastError(ERROR_INVALID_USER_BUFFER
);
4598 /* FIXME: check Reserved field */
4605 /***********************************************************************
4606 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
4609 SetupDiSetDeviceInstallParamsW(
4610 IN HDEVINFO DeviceInfoSet
,
4611 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4612 IN PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4614 struct DeviceInfoSet
*list
;
4617 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4620 SetLastError(ERROR_INVALID_HANDLE
);
4621 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4622 SetLastError(ERROR_INVALID_HANDLE
);
4623 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4624 SetLastError(ERROR_INVALID_USER_BUFFER
);
4625 else if (!DeviceInstallParams
)
4626 SetLastError(ERROR_INVALID_PARAMETER
);
4627 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_W
))
4628 SetLastError(ERROR_INVALID_USER_BUFFER
);
4629 else if (CheckDeviceInstallParameters(DeviceInstallParams
))
4631 PSP_DEVINSTALL_PARAMS_W Destination
;
4634 Destination
= &((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->InstallParams
;
4636 Destination
= &list
->InstallParams
;
4637 memcpy(Destination
, DeviceInstallParams
, DeviceInstallParams
->cbSize
);
4641 TRACE("Returning %d\n", ret
);
4645 /***********************************************************************
4646 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
4649 SetupDiSetDeviceInstallParamsA(
4650 HDEVINFO DeviceInfoSet
,
4651 PSP_DEVINFO_DATA DeviceInfoData
,
4652 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
4654 SP_DEVINSTALL_PARAMS_W deviceInstallParamsW
;
4658 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4660 if (DeviceInstallParams
== NULL
)
4661 SetLastError(ERROR_INVALID_PARAMETER
);
4662 else if (DeviceInstallParams
->cbSize
< sizeof(SP_DEVINSTALL_PARAMS_A
))
4663 SetLastError(ERROR_INVALID_USER_BUFFER
);
4666 memcpy(&deviceInstallParamsW
, DeviceInstallParams
, FIELD_OFFSET(SP_DEVINSTALL_PARAMS_A
, DriverPath
));
4667 deviceInstallParamsW
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4668 len
= MultiByteToWideChar(CP_ACP
, 0, DeviceInstallParams
->DriverPath
, -1, NULL
, 0);
4671 ERR("DrivePath is NULL\n");
4676 MultiByteToWideChar(CP_ACP
, 0, DeviceInstallParams
->DriverPath
, -1, deviceInstallParamsW
.DriverPath
, len
);
4677 ret
= SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &deviceInstallParamsW
);
4681 TRACE("Returning %d\n", ret
);
4686 OpenHardwareProfileKey(
4689 IN DWORD samDesired
)
4691 HKEY hHWProfilesKey
= NULL
;
4692 HKEY hHWProfileKey
= NULL
;
4693 HKEY ret
= INVALID_HANDLE_VALUE
;
4696 rc
= RegOpenKeyExW(HKLM
,
4697 REGSTR_PATH_HWPROFILES
,
4701 if (rc
!= ERROR_SUCCESS
)
4708 rc
= RegOpenKeyExW(hHWProfilesKey
,
4717 snprintfW(subKey
, 4, InstanceKeyFormat
, HwProfile
);
4719 rc
= RegOpenKeyExW(hHWProfilesKey
,
4725 if (rc
!= ERROR_SUCCESS
)
4730 ret
= hHWProfileKey
;
4733 if (hHWProfilesKey
!= NULL
)
4734 RegCloseKey(hHWProfilesKey
);
4735 if (hHWProfileKey
!= NULL
&& hHWProfileKey
!= ret
)
4736 RegCloseKey(hHWProfileKey
);
4741 IsDeviceInfoInDeviceInfoSet(
4742 struct DeviceInfoSet
*deviceInfoSet
,
4743 struct DeviceInfo
*deviceInfo
)
4745 PLIST_ENTRY ListEntry
;
4747 ListEntry
= deviceInfoSet
->ListHead
.Flink
;
4748 while (ListEntry
!= &deviceInfoSet
->ListHead
)
4750 if (deviceInfo
== CONTAINING_RECORD(ListEntry
, struct DeviceInfo
, ListEntry
))
4753 ListEntry
= ListEntry
->Flink
;
4759 /***********************************************************************
4760 * SetupDiDeleteDeviceInfo (SETUPAPI.@)
4763 SetupDiDeleteDeviceInfo(
4764 IN HDEVINFO DeviceInfoSet
,
4765 IN PSP_DEVINFO_DATA DeviceInfoData
)
4767 struct DeviceInfoSet
*deviceInfoSet
;
4768 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
;
4771 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4774 SetLastError(ERROR_INVALID_HANDLE
);
4775 else if ((deviceInfoSet
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4776 SetLastError(ERROR_INVALID_HANDLE
);
4777 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4778 SetLastError(ERROR_INVALID_USER_BUFFER
);
4779 else if (!IsDeviceInfoInDeviceInfoSet(deviceInfoSet
, deviceInfo
))
4780 SetLastError(ERROR_INVALID_PARAMETER
);
4783 RemoveEntryList(&deviceInfo
->ListEntry
);
4784 DestroyDeviceInfo(deviceInfo
);
4792 /***********************************************************************
4793 * SetupDiOpenDeviceInfoA (SETUPAPI.@)
4796 SetupDiOpenDeviceInfoA(
4797 IN HDEVINFO DeviceInfoSet
,
4798 IN PCSTR DeviceInstanceId
,
4799 IN HWND hwndParent OPTIONAL
,
4801 OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4803 LPWSTR DeviceInstanceIdW
= NULL
;
4806 TRACE("%p %s %p %lx %p\n", DeviceInfoSet
, DeviceInstanceId
, hwndParent
, OpenFlags
, DeviceInfoData
);
4808 DeviceInstanceIdW
= pSetupMultiByteToUnicode(DeviceInstanceId
, CP_ACP
);
4809 if (DeviceInstanceIdW
== NULL
)
4812 bResult
= SetupDiOpenDeviceInfoW(DeviceInfoSet
,
4813 DeviceInstanceIdW
, hwndParent
, OpenFlags
, DeviceInfoData
);
4815 MyFree(DeviceInstanceIdW
);
4821 /***********************************************************************
4822 * SetupDiOpenDeviceInfoW (SETUPAPI.@)
4825 SetupDiOpenDeviceInfoW(
4826 IN HDEVINFO DeviceInfoSet
,
4827 IN PCWSTR DeviceInstanceId
,
4828 IN HWND hwndParent OPTIONAL
,
4830 OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4832 struct DeviceInfoSet
*list
;
4833 HKEY hEnumKey
, hKey
= NULL
;
4837 TRACE("%p %s %p %lx %p\n",
4838 DeviceInfoSet
, debugstr_w(DeviceInstanceId
),
4839 hwndParent
, OpenFlags
, DeviceInfoData
);
4841 if (OpenFlags
& DIOD_CANCEL_REMOVE
)
4842 FIXME("DIOD_CANCEL_REMOVE flag not implemented\n");
4845 SetLastError(ERROR_INVALID_HANDLE
);
4846 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4847 SetLastError(ERROR_INVALID_HANDLE
);
4848 else if (!DeviceInstanceId
)
4849 SetLastError(ERROR_INVALID_PARAMETER
);
4850 else if (OpenFlags
& ~(DIOD_CANCEL_REMOVE
| DIOD_INHERIT_CLASSDRVS
))
4852 TRACE("Unknown flags: 0x%08lx\n", OpenFlags
& ~(DIOD_CANCEL_REMOVE
| DIOD_INHERIT_CLASSDRVS
));
4853 SetLastError(ERROR_INVALID_FLAGS
);
4855 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4856 SetLastError(ERROR_INVALID_USER_BUFFER
);
4859 struct DeviceInfo
*deviceInfo
= NULL
;
4860 /* Search if device already exists in DeviceInfoSet.
4861 * If yes, return the existing element
4862 * If no, create a new element using information in registry
4864 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
4865 while (ItemList
!= &list
->ListHead
)
4867 deviceInfo
= CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
4868 if (!wcscmp(deviceInfo
->instanceId
, DeviceInstanceId
))
4871 ItemList
= ItemList
->Flink
;
4876 /* good one found */
4882 WCHAR szClassGuid
[MAX_GUID_STRING_LEN
];
4884 /* Open supposed registry key */
4887 REGSTR_PATH_SYSTEMENUM
,
4891 if (rc
!= ERROR_SUCCESS
)
4902 RegCloseKey(hEnumKey
);
4903 if (rc
!= ERROR_SUCCESS
)
4905 if (rc
== ERROR_FILE_NOT_FOUND
)
4906 rc
= ERROR_NO_SUCH_DEVINST
;
4911 ClassGUID
= GUID_NULL
;
4912 dwSize
= MAX_GUID_STRING_LEN
* sizeof(WCHAR
);
4914 if (RegQueryValueExW(hKey
,
4915 REGSTR_VAL_CLASSGUID
,
4918 (LPBYTE
)szClassGuid
,
4919 &dwSize
) == ERROR_SUCCESS
)
4921 szClassGuid
[MAX_GUID_STRING_LEN
- 2] = UNICODE_NULL
;
4923 /* Convert a string to a ClassGuid */
4924 UuidFromStringW(&szClassGuid
[1], &ClassGUID
);
4927 if (!CreateDeviceInfo(list
, DeviceInstanceId
, &ClassGUID
, &deviceInfo
))
4930 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
4935 if (ret
&& deviceInfo
&& DeviceInfoData
)
4937 memcpy(&DeviceInfoData
->ClassGuid
, &deviceInfo
->ClassGuid
, sizeof(GUID
));
4938 DeviceInfoData
->DevInst
= deviceInfo
->dnDevInst
;
4939 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInfo
;
4950 /***********************************************************************
4951 * SetupDiGetSelectedDevice (SETUPAPI.@)
4954 SetupDiGetSelectedDevice(
4955 IN HDEVINFO DeviceInfoSet
,
4956 OUT PSP_DEVINFO_DATA DeviceInfoData
)
4958 struct DeviceInfoSet
*list
;
4961 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4964 SetLastError(ERROR_INVALID_HANDLE
);
4965 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4966 SetLastError(ERROR_INVALID_HANDLE
);
4967 else if (list
->SelectedDevice
== NULL
)
4968 SetLastError(ERROR_NO_DEVICE_SELECTED
);
4969 else if (!DeviceInfoData
)
4970 SetLastError(ERROR_INVALID_PARAMETER
);
4971 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4972 SetLastError(ERROR_INVALID_USER_BUFFER
);
4975 memcpy(&DeviceInfoData
->ClassGuid
,
4976 &list
->SelectedDevice
->ClassGuid
,
4978 DeviceInfoData
->DevInst
= list
->SelectedDevice
->dnDevInst
;
4979 DeviceInfoData
->Reserved
= (ULONG_PTR
)list
->SelectedDevice
;
4983 TRACE("Returning %d\n", ret
);
4988 /***********************************************************************
4989 * SetupDiSetSelectedDevice (SETUPAPI.@)
4992 SetupDiSetSelectedDevice(
4993 IN HDEVINFO DeviceInfoSet
,
4994 IN PSP_DEVINFO_DATA DeviceInfoData
)
4996 struct DeviceInfoSet
*list
;
4999 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5002 SetLastError(ERROR_INVALID_HANDLE
);
5003 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5004 SetLastError(ERROR_INVALID_HANDLE
);
5005 else if (!DeviceInfoData
)
5006 SetLastError(ERROR_INVALID_PARAMETER
);
5007 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5008 SetLastError(ERROR_INVALID_USER_BUFFER
);
5009 else if (DeviceInfoData
->Reserved
== 0)
5010 SetLastError(ERROR_INVALID_USER_BUFFER
);
5013 list
->SelectedDevice
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5017 TRACE("Returning %d\n", ret
);
5022 /* Return the current hardware profile id, or -1 if error */
5024 SETUPAPI_GetCurrentHwProfile(
5025 IN HDEVINFO DeviceInfoSet
)
5028 DWORD dwRegType
, dwLength
;
5031 DWORD ret
= (DWORD
)-1;
5033 rc
= RegOpenKeyExW(((struct DeviceInfoSet
*)DeviceInfoSet
)->HKLM
,
5034 REGSTR_PATH_IDCONFIGDB
,
5038 if (rc
!= ERROR_SUCCESS
)
5044 dwLength
= sizeof(DWORD
);
5045 rc
= RegQueryValueExW(hKey
,
5046 REGSTR_VAL_CURRENTCONFIG
,
5049 (LPBYTE
)&hwProfile
, &dwLength
);
5050 if (rc
!= ERROR_SUCCESS
)
5055 else if (dwRegType
!= REG_DWORD
|| dwLength
!= sizeof(DWORD
))
5057 SetLastError(ERROR_GEN_FAILURE
);
5072 IN HDEVINFO DeviceInfoSet
,
5073 IN PSP_DEVINFO_DATA DeviceInfoData
)
5076 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
5077 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5080 cr
= CM_Enable_DevNode_Ex(deviceInfo
->dnDevInst
, 0, set
->hMachine
);
5081 if (cr
!= CR_SUCCESS
)
5083 SetLastError(GetErrorCodeFromCrCode(cr
));
5089 FIXME("Stub: ResetDevice(%p %p)\n", DeviceInfoSet
, DeviceInfoData
);
5094 static BOOL
StopDevice(
5095 IN HDEVINFO DeviceInfoSet
,
5096 IN PSP_DEVINFO_DATA DeviceInfoData
)
5098 FIXME("Stub: StopDevice(%p %p)\n", DeviceInfoSet
, DeviceInfoData
);
5102 /***********************************************************************
5103 * SetupDiChangeState (SETUPAPI.@)
5107 IN HDEVINFO DeviceInfoSet
,
5108 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
5110 PSP_PROPCHANGE_PARAMS PropChange
;
5111 HKEY hKey
= INVALID_HANDLE_VALUE
;
5112 LPCWSTR RegistryValueName
;
5113 DWORD dwConfigFlags
, dwLength
, dwRegType
;
5117 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5119 if (!DeviceInfoData
)
5120 PropChange
= ((struct DeviceInfoSet
*)DeviceInfoSet
)->ClassInstallParams
.PropChangeParams
;
5122 PropChange
= ((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->ClassInstallParams
.PropChangeParams
;
5125 SetLastError(ERROR_INVALID_PARAMETER
);
5129 if (PropChange
->Scope
== DICS_FLAG_GLOBAL
)
5130 RegistryValueName
= REGSTR_VAL_CONFIGFLAGS
;
5132 RegistryValueName
= REGSTR_VAL_CSCONFIGFLAGS
;
5134 switch (PropChange
->StateChange
)
5139 /* Enable/disable device in registry */
5140 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, PropChange
->Scope
, PropChange
->HwProfile
, DIREG_DEV
, KEY_QUERY_VALUE
| KEY_SET_VALUE
);
5141 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5142 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, PropChange
->Scope
, PropChange
->HwProfile
, DIREG_DEV
, NULL
, NULL
);
5143 if (hKey
== INVALID_HANDLE_VALUE
)
5145 dwLength
= sizeof(DWORD
);
5146 rc
= RegQueryValueExW(
5151 (LPBYTE
)&dwConfigFlags
, &dwLength
);
5152 if (rc
== ERROR_FILE_NOT_FOUND
)
5154 else if (rc
!= ERROR_SUCCESS
)
5159 else if (dwRegType
!= REG_DWORD
|| dwLength
!= sizeof(DWORD
))
5161 SetLastError(ERROR_GEN_FAILURE
);
5164 if (PropChange
->StateChange
== DICS_ENABLE
)
5165 dwConfigFlags
&= ~(PropChange
->Scope
== DICS_FLAG_GLOBAL
? CONFIGFLAG_DISABLED
: CSCONFIGFLAG_DISABLED
);
5167 dwConfigFlags
|= (PropChange
->Scope
== DICS_FLAG_GLOBAL
? CONFIGFLAG_DISABLED
: CSCONFIGFLAG_DISABLED
);
5168 rc
= RegSetValueExW(
5173 (LPBYTE
)&dwConfigFlags
, sizeof(DWORD
));
5174 if (rc
!= ERROR_SUCCESS
)
5180 /* Enable/disable device if needed */
5181 if (PropChange
->Scope
== DICS_FLAG_GLOBAL
5182 || PropChange
->HwProfile
== 0
5183 || PropChange
->HwProfile
== SETUPAPI_GetCurrentHwProfile(DeviceInfoSet
))
5185 if (PropChange
->StateChange
== DICS_ENABLE
)
5186 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
5188 ret
= StopDevice(DeviceInfoSet
, DeviceInfoData
);
5194 case DICS_PROPCHANGE
:
5196 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
5201 ERR("Unknown StateChange 0x%lx\n", PropChange
->StateChange
);
5202 SetLastError(ERROR_NOT_SUPPORTED
);
5207 if (hKey
!= INVALID_HANDLE_VALUE
)
5210 TRACE("Returning %d\n", ret
);
5214 /***********************************************************************
5215 * SetupDiSelectDevice (SETUPAPI.@)
5218 SetupDiSelectDevice(
5219 IN HDEVINFO DeviceInfoSet
,
5220 IN OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
5222 FIXME("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5223 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
5228 /***********************************************************************
5229 * SetupDiRegisterCoDeviceInstallers (SETUPAPI.@)
5232 SetupDiRegisterCoDeviceInstallers(
5233 IN HDEVINFO DeviceInfoSet
,
5234 IN PSP_DEVINFO_DATA DeviceInfoData
)
5236 BOOL ret
= FALSE
; /* Return value */
5238 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5241 SetLastError(ERROR_INVALID_PARAMETER
);
5242 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
5243 SetLastError(ERROR_INVALID_HANDLE
);
5244 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5245 SetLastError(ERROR_INVALID_HANDLE
);
5246 else if (!DeviceInfoData
)
5247 SetLastError(ERROR_INVALID_PARAMETER
);
5248 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5249 SetLastError(ERROR_INVALID_USER_BUFFER
);
5252 SP_DEVINSTALL_PARAMS_W InstallParams
;
5253 struct DriverInfoElement
*SelectedDriver
;
5256 WCHAR SectionName
[MAX_PATH
];
5257 DWORD SectionNameLength
= 0;
5258 HKEY hKey
= INVALID_HANDLE_VALUE
;
5259 PVOID Context
= NULL
;
5261 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
5262 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5266 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
5267 if (SelectedDriver
== NULL
)
5269 SetLastError(ERROR_NO_DRIVER_SELECTED
);
5273 /* Get .CoInstallers section name */
5274 Result
= SetupDiGetActualSectionToInstallW(
5275 SelectedDriver
->InfFileDetails
->hInf
,
5276 SelectedDriver
->Details
.SectionName
,
5277 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
5278 if (!Result
|| SectionNameLength
> MAX_PATH
- strlenW(DotCoInstallers
) - 1)
5280 lstrcatW(SectionName
, DotCoInstallers
);
5282 /* Open/Create driver key information */
5283 #if _WIN32_WINNT >= 0x502
5284 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_READ
| KEY_WRITE
);
5286 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_ALL_ACCESS
);
5288 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5289 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, NULL
, NULL
);
5290 if (hKey
== INVALID_HANDLE_VALUE
)
5293 /* Install .CoInstallers section */
5294 DoAction
= SPINST_REGISTRY
;
5295 if (!(InstallParams
.Flags
& DI_NOFILECOPY
))
5297 DoAction
|= SPINST_FILES
;
5298 Context
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
5302 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5303 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5304 DoAction
, hKey
, SelectedDriver
->InfFileDetails
->DirectoryName
, SP_COPY_NEWER
,
5305 SetupDefaultQueueCallbackW
, Context
,
5306 DeviceInfoSet
, DeviceInfoData
);
5314 SetupTermDefaultQueueCallback(Context
);
5315 if (hKey
!= INVALID_HANDLE_VALUE
)
5319 TRACE("Returning %d\n", ret
);
5324 InfIsFromOEMLocation(
5326 OUT LPBOOL IsOEMLocation
)
5330 last
= strrchrW(FullName
, '\\');
5333 /* No directory specified */
5334 *IsOEMLocation
= FALSE
;
5341 Windir
= MyMalloc((MAX_PATH
+ 1 + strlenW(InfDirectory
)) * sizeof(WCHAR
));
5344 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5348 ret
= GetSystemWindowsDirectoryW(Windir
, MAX_PATH
);
5349 if (ret
== 0 || ret
> MAX_PATH
)
5352 SetLastError(ERROR_GEN_FAILURE
);
5355 if (*Windir
&& Windir
[strlenW(Windir
) - 1] != '\\')
5356 strcatW(Windir
, BackSlash
);
5357 strcatW(Windir
, InfDirectory
);
5359 if (strncmpiW(FullName
, Windir
, last
- FullName
) == 0)
5361 /* The path is %SYSTEMROOT%\Inf */
5362 *IsOEMLocation
= FALSE
;
5366 /* The file is in another place */
5367 *IsOEMLocation
= TRUE
;
5374 /***********************************************************************
5375 * SetupDiInstallDevice (SETUPAPI.@)
5378 SetupDiInstallDevice(
5379 IN HDEVINFO DeviceInfoSet
,
5380 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
5382 SP_DEVINSTALL_PARAMS_W InstallParams
;
5383 struct DriverInfoElement
*SelectedDriver
;
5384 SYSTEMTIME DriverDate
;
5385 WCHAR SectionName
[MAX_PATH
];
5387 DWORD SectionNameLength
= 0;
5388 BOOL Result
= FALSE
;
5391 LPWSTR pSectionName
= NULL
;
5392 WCHAR ClassName
[MAX_CLASS_NAME_LEN
];
5394 LPWSTR lpGuidString
= NULL
, lpFullGuidString
= NULL
;
5395 BOOL RebootRequired
= FALSE
;
5396 HKEY hKey
= INVALID_HANDLE_VALUE
;
5397 BOOL NeedtoCopyFile
;
5398 LARGE_INTEGER fullVersion
;
5400 PVOID Context
= NULL
;
5401 BOOL ret
= FALSE
; /* Return value */
5403 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5406 SetLastError(ERROR_INVALID_PARAMETER
);
5407 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
5408 SetLastError(ERROR_INVALID_HANDLE
);
5409 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5410 SetLastError(ERROR_INVALID_HANDLE
);
5411 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5412 SetLastError(ERROR_INVALID_USER_BUFFER
);
5418 /* One parameter is bad */
5422 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
5423 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5427 if (InstallParams
.FlagsEx
& DI_FLAGSEX_SETFAILEDINSTALL
)
5429 /* Set FAILEDINSTALL in ConfigFlags registry value */
5430 DWORD ConfigFlags
, regType
;
5431 Result
= SetupDiGetDeviceRegistryPropertyW(
5436 (PBYTE
)&ConfigFlags
,
5437 sizeof(ConfigFlags
),
5439 if (!Result
|| regType
!= REG_DWORD
)
5441 SetLastError(ERROR_GEN_FAILURE
);
5444 ConfigFlags
|= DNF_DISABLED
;
5445 Result
= SetupDiSetDeviceRegistryPropertyW(
5449 (PBYTE
)&ConfigFlags
,
5450 sizeof(ConfigFlags
));
5453 SetLastError(ERROR_GEN_FAILURE
);
5461 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
5462 if (SelectedDriver
== NULL
)
5464 SetLastError(ERROR_NO_DRIVER_SELECTED
);
5468 FileTimeToSystemTime(&SelectedDriver
->Info
.DriverDate
, &DriverDate
);
5470 Result
= SetupDiGetActualSectionToInstallW(
5471 SelectedDriver
->InfFileDetails
->hInf
,
5472 SelectedDriver
->Details
.SectionName
,
5473 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
5474 if (!Result
|| SectionNameLength
> MAX_PATH
- strlenW(DotServices
))
5476 pSectionName
= &SectionName
[strlenW(SectionName
)];
5478 /* Get information from [Version] section */
5479 if (!SetupDiGetINFClassW(SelectedDriver
->Details
.InfFileName
, &ClassGuid
, ClassName
, MAX_CLASS_NAME_LEN
, &RequiredSize
))
5481 /* Format ClassGuid to a string */
5482 if (UuidToStringW((UUID
*)&ClassGuid
, &lpGuidString
) != RPC_S_OK
)
5484 RequiredSize
= lstrlenW(lpGuidString
);
5485 lpFullGuidString
= HeapAlloc(GetProcessHeap(), 0, (RequiredSize
+ 3) * sizeof(WCHAR
));
5486 if (!lpFullGuidString
)
5488 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5491 lpFullGuidString
[0] = '{';
5492 memcpy(&lpFullGuidString
[1], lpGuidString
, RequiredSize
* sizeof(WCHAR
));
5493 lpFullGuidString
[RequiredSize
+ 1] = '}';
5494 lpFullGuidString
[RequiredSize
+ 2] = '\0';
5496 /* Copy .inf file to Inf\ directory (if needed) */
5497 Result
= InfIsFromOEMLocation(SelectedDriver
->Details
.InfFileName
, &NeedtoCopyFile
);
5502 WCHAR NewFileName
[MAX_PATH
];
5503 struct InfFileDetails
*newInfFileDetails
;
5504 Result
= SetupCopyOEMInfW(
5505 SelectedDriver
->Details
.InfFileName
,
5508 SP_COPY_NOOVERWRITE
,
5509 NewFileName
, MAX_PATH
,
5512 if (!Result
&& GetLastError() != ERROR_FILE_EXISTS
)
5514 /* Create a new struct InfFileDetails, and set it to
5515 * SelectedDriver->InfFileDetails, to release use of
5516 * current InfFile */
5517 newInfFileDetails
= CreateInfFileDetails(NewFileName
);
5518 if (!newInfFileDetails
)
5520 DereferenceInfFile(SelectedDriver
->InfFileDetails
);
5521 SelectedDriver
->InfFileDetails
= newInfFileDetails
;
5522 strcpyW(SelectedDriver
->Details
.InfFileName
, NewFileName
);
5525 /* Open/Create driver key information */
5526 #if _WIN32_WINNT >= 0x502
5527 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_READ
| KEY_WRITE
);
5529 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_ALL_ACCESS
);
5531 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5532 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, NULL
, NULL
);
5533 if (hKey
== INVALID_HANDLE_VALUE
)
5536 /* Install main section */
5538 if (!(InstallParams
.FlagsEx
& DI_FLAGSEX_NO_DRVREG_MODIFY
))
5539 DoAction
|= SPINST_REGISTRY
;
5540 if (!(InstallParams
.Flags
& DI_NOFILECOPY
))
5542 DoAction
|= SPINST_FILES
;
5543 Context
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
5547 *pSectionName
= '\0';
5548 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5549 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5550 DoAction
, hKey
, SelectedDriver
->InfFileDetails
->DirectoryName
, SP_COPY_NEWER
,
5551 SetupDefaultQueueCallbackW
, Context
,
5552 DeviceInfoSet
, DeviceInfoData
);
5555 InstallParams
.Flags
|= DI_NOFILECOPY
;
5556 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5558 /* Write information to driver key */
5559 *pSectionName
= UNICODE_NULL
;
5560 memcpy(&fullVersion
, &SelectedDriver
->Info
.DriverVersion
, sizeof(LARGE_INTEGER
));
5561 TRACE("Write information to driver key\n");
5562 TRACE("DriverDate : '%u-%u-%u'\n", DriverDate
.wMonth
, DriverDate
.wDay
, DriverDate
.wYear
);
5563 TRACE("DriverDesc : '%s'\n", debugstr_w(SelectedDriver
->Info
.Description
));
5564 TRACE("DriverVersion : '%ld.%ld.%lu.%ld'\n", fullVersion
.HighPart
>> 16, fullVersion
.HighPart
& 0xffff, fullVersion
.LowPart
>> 16, fullVersion
.LowPart
& 0xffff);
5565 TRACE("InfPath : '%s'\n", debugstr_w(SelectedDriver
->InfFileDetails
->FileName
));
5566 TRACE("InfSection : '%s'\n", debugstr_w(SelectedDriver
->Details
.SectionName
));
5567 TRACE("InfSectionExt : '%s'\n", debugstr_w(&SectionName
[strlenW(SelectedDriver
->Details
.SectionName
)]));
5568 TRACE("MatchingDeviceId: '%s'\n", debugstr_w(SelectedDriver
->MatchingId
));
5569 TRACE("ProviderName : '%s'\n", debugstr_w(SelectedDriver
->Info
.ProviderName
));
5570 sprintfW(Buffer
, DateFormat
, DriverDate
.wMonth
, DriverDate
.wDay
, DriverDate
.wYear
);
5571 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_DATE
, 0, REG_SZ
, (const BYTE
*)Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
));
5572 if (rc
== ERROR_SUCCESS
)
5573 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_DATE_DATA
, 0, REG_BINARY
, (const BYTE
*)&SelectedDriver
->Info
.DriverDate
, sizeof(FILETIME
));
5574 if (rc
== ERROR_SUCCESS
)
5575 rc
= RegSetValueExW(hKey
, REGSTR_VAL_DRVDESC
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.Description
, (strlenW(SelectedDriver
->Info
.Description
) + 1) * sizeof(WCHAR
));
5576 if (rc
== ERROR_SUCCESS
)
5578 sprintfW(Buffer
, VersionFormat
, fullVersion
.HighPart
>> 16, fullVersion
.HighPart
& 0xffff, fullVersion
.LowPart
>> 16, fullVersion
.LowPart
& 0xffff);
5579 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_VERSION
, 0, REG_SZ
, (const BYTE
*)Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
));
5581 if (rc
== ERROR_SUCCESS
)
5582 rc
= RegSetValueExW(hKey
, REGSTR_VAL_INFPATH
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->InfFileDetails
->FileName
, (strlenW(SelectedDriver
->InfFileDetails
->FileName
) + 1) * sizeof(WCHAR
));
5583 if (rc
== ERROR_SUCCESS
)
5584 rc
= RegSetValueExW(hKey
, REGSTR_VAL_INFSECTION
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Details
.SectionName
, (strlenW(SelectedDriver
->Details
.SectionName
) + 1) * sizeof(WCHAR
));
5585 if (rc
== ERROR_SUCCESS
)
5586 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
));
5587 if (rc
== ERROR_SUCCESS
)
5588 rc
= RegSetValueExW(hKey
, REGSTR_VAL_MATCHINGDEVID
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->MatchingId
, (strlenW(SelectedDriver
->MatchingId
) + 1) * sizeof(WCHAR
));
5589 if (rc
== ERROR_SUCCESS
)
5590 rc
= RegSetValueExW(hKey
, REGSTR_VAL_PROVIDER_NAME
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.ProviderName
, (strlenW(SelectedDriver
->Info
.ProviderName
) + 1) * sizeof(WCHAR
));
5591 if (rc
!= ERROR_SUCCESS
)
5597 hKey
= INVALID_HANDLE_VALUE
;
5599 /* FIXME: Process .LogConfigOverride section */
5601 /* Install .Services section */
5602 strcpyW(pSectionName
, DotServices
);
5603 Result
= SetupInstallServicesFromInfSectionExW(
5604 SelectedDriver
->InfFileDetails
->hInf
,
5613 if (GetLastError() == ERROR_SUCCESS_REBOOT_REQUIRED
)
5614 RebootRequired
= TRUE
;
5616 /* Open device registry key */
5617 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_SET_VALUE
);
5618 if (hKey
== INVALID_HANDLE_VALUE
)
5621 /* Install .HW section */
5623 if (!(InstallParams
.FlagsEx
& DI_FLAGSEX_NO_DRVREG_MODIFY
))
5624 DoAction
|= SPINST_REGISTRY
;
5625 strcpyW(pSectionName
, DotHW
);
5626 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5627 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5628 DoAction
, hKey
, NULL
, 0,
5630 DeviceInfoSet
, DeviceInfoData
);
5634 /* Write information to enum key */
5635 TRACE("Write information to enum key\n");
5636 TRACE("Class : '%s'\n", debugstr_w(ClassName
));
5637 TRACE("ClassGUID : '%s'\n", debugstr_w(lpFullGuidString
));
5638 TRACE("DeviceDesc : '%s'\n", debugstr_w(SelectedDriver
->Info
.Description
));
5639 TRACE("Mfg : '%s'\n", debugstr_w(SelectedDriver
->Info
.MfgName
));
5640 rc
= RegSetValueExW(hKey
, REGSTR_VAL_CLASS
, 0, REG_SZ
, (const BYTE
*)ClassName
, (strlenW(ClassName
) + 1) * sizeof(WCHAR
));
5641 if (rc
== ERROR_SUCCESS
)
5642 rc
= RegSetValueExW(hKey
, REGSTR_VAL_CLASSGUID
, 0, REG_SZ
, (const BYTE
*)lpFullGuidString
, (strlenW(lpFullGuidString
) + 1) * sizeof(WCHAR
));
5643 if (rc
== ERROR_SUCCESS
)
5644 rc
= RegSetValueExW(hKey
, REGSTR_VAL_DEVDESC
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.Description
, (strlenW(SelectedDriver
->Info
.Description
) + 1) * sizeof(WCHAR
));
5645 if (rc
== ERROR_SUCCESS
)
5646 rc
= RegSetValueExW(hKey
, REGSTR_VAL_MFG
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.MfgName
, (strlenW(SelectedDriver
->Info
.MfgName
) + 1) * sizeof(WCHAR
));
5647 if (rc
!= ERROR_SUCCESS
)
5653 /* Start the device */
5654 if (!RebootRequired
&& !(InstallParams
.Flags
& (DI_NEEDRESTART
| DI_NEEDREBOOT
| DI_DONOTCALLCONFIGMG
)))
5655 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
5660 /* End of installation */
5661 if (hKey
!= INVALID_HANDLE_VALUE
)
5664 RpcStringFreeW(&lpGuidString
);
5665 HeapFree(GetProcessHeap(), 0, lpFullGuidString
);
5667 SetupTermDefaultQueueCallback(Context
);
5668 TRACE("Returning %d\n", ret
);
5672 static HKEY
SETUPDI_OpenDevKey(HKEY RootKey
, struct DeviceInfo
*devInfo
, REGSAM samDesired
)
5674 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
5677 l
= RegOpenKeyExW(RootKey
, REGSTR_PATH_SYSTEMENUM
, 0, 0, &enumKey
);
5680 l
= RegOpenKeyExW(enumKey
, devInfo
->instanceId
, 0, samDesired
, &key
);
5681 RegCloseKey(enumKey
);
5688 static HKEY
SETUPDI_OpenDrvKey(HKEY RootKey
, struct DeviceInfo
*devInfo
, REGSAM samDesired
)
5690 LPWSTR DriverKey
= NULL
;
5694 HKEY hEnumKey
= NULL
;
5696 HKEY key
= INVALID_HANDLE_VALUE
;
5698 hKey
= SETUPDI_OpenDevKey(RootKey
, devInfo
, KEY_QUERY_VALUE
);
5699 if (hKey
== INVALID_HANDLE_VALUE
)
5701 /* Read the 'Driver' key */
5702 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_DRIVER
, NULL
, &dwRegType
, NULL
, &dwLength
);
5703 if (rc
!= ERROR_SUCCESS
)
5708 else if (dwRegType
!= REG_SZ
)
5710 SetLastError(ERROR_GEN_FAILURE
);
5713 DriverKey
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
5716 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5719 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_DRIVER
, NULL
, &dwRegType
, (LPBYTE
)DriverKey
, &dwLength
);
5720 if (rc
!= ERROR_SUCCESS
)
5727 /* Need to open the driver key */
5730 REGSTR_PATH_CLASS_NT
,
5734 if (rc
!= ERROR_SUCCESS
)
5745 if (rc
!= ERROR_SUCCESS
)
5753 if (hEnumKey
!= NULL
)
5754 RegCloseKey(hEnumKey
);
5755 if (hKey
!= NULL
&& hKey
!= key
)
5760 /***********************************************************************
5761 * SetupDiOpenDevRegKey (SETUPAPI.@)
5763 HKEY WINAPI
SetupDiOpenDevRegKey(
5764 HDEVINFO DeviceInfoSet
,
5765 PSP_DEVINFO_DATA DeviceInfoData
,
5771 struct DeviceInfoSet
*set
= DeviceInfoSet
;
5772 struct DeviceInfo
*devInfo
;
5773 HKEY key
= INVALID_HANDLE_VALUE
;
5776 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
5777 Scope
, HwProfile
, KeyType
, samDesired
);
5779 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
5781 SetLastError(ERROR_INVALID_HANDLE
);
5782 return INVALID_HANDLE_VALUE
;
5784 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5786 SetLastError(ERROR_INVALID_HANDLE
);
5787 return INVALID_HANDLE_VALUE
;
5789 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
5790 || !DeviceInfoData
->Reserved
)
5792 SetLastError(ERROR_INVALID_PARAMETER
);
5793 return INVALID_HANDLE_VALUE
;
5795 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
5797 SetLastError(ERROR_INVALID_FLAGS
);
5798 return INVALID_HANDLE_VALUE
;
5800 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
5802 SetLastError(ERROR_INVALID_FLAGS
);
5803 return INVALID_HANDLE_VALUE
;
5805 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5806 if (devInfo
->set
!= set
)
5808 SetLastError(ERROR_INVALID_PARAMETER
);
5809 return INVALID_HANDLE_VALUE
;
5811 if (Scope
!= DICS_FLAG_GLOBAL
)
5813 RootKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, 0);
5814 if (RootKey
== INVALID_HANDLE_VALUE
)
5815 return INVALID_HANDLE_VALUE
;
5818 RootKey
= set
->HKLM
;
5822 key
= SETUPDI_OpenDevKey(RootKey
, devInfo
, samDesired
);
5825 key
= SETUPDI_OpenDrvKey(RootKey
, devInfo
, samDesired
);
5828 WARN("unknown KeyType %d\n", KeyType
);
5830 if (RootKey
!= set
->HKLM
)
5831 RegCloseKey(RootKey
);
5835 static BOOL
SETUPDI_DeleteDevKey(HKEY RootKey
, struct DeviceInfo
*devInfo
)
5841 static BOOL
SETUPDI_DeleteDrvKey(HKEY RootKey
, struct DeviceInfo
*devInfo
)
5847 /***********************************************************************
5848 * SetupDiDeleteDevRegKey (SETUPAPI.@)
5850 BOOL WINAPI
SetupDiDeleteDevRegKey(
5851 HDEVINFO DeviceInfoSet
,
5852 PSP_DEVINFO_DATA DeviceInfoData
,
5857 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
5858 struct DeviceInfo
*devInfo
;
5862 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
5865 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
5867 SetLastError(ERROR_INVALID_HANDLE
);
5870 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5872 SetLastError(ERROR_INVALID_HANDLE
);
5875 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
5876 || !DeviceInfoData
->Reserved
)
5878 SetLastError(ERROR_INVALID_PARAMETER
);
5881 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
5883 SetLastError(ERROR_INVALID_FLAGS
);
5886 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
5888 SetLastError(ERROR_INVALID_FLAGS
);
5891 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5892 if (devInfo
->set
!= set
)
5894 SetLastError(ERROR_INVALID_PARAMETER
);
5897 if (Scope
!= DICS_FLAG_GLOBAL
)
5899 RootKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, 0);
5900 if (RootKey
== INVALID_HANDLE_VALUE
)
5904 RootKey
= set
->HKLM
;
5908 ret
= SETUPDI_DeleteDevKey(RootKey
, devInfo
);
5911 ret
= SETUPDI_DeleteDrvKey(RootKey
, devInfo
);
5914 ret
= SETUPDI_DeleteDevKey(RootKey
, devInfo
);
5916 ret
= SETUPDI_DeleteDrvKey(RootKey
, devInfo
);
5919 WARN("unknown KeyType %d\n", KeyType
);
5921 if (RootKey
!= set
->HKLM
)
5922 RegCloseKey(RootKey
);