2 * SetupAPI device installer
4 * Copyright 2000 Andreas Mohr for CodeWeavers
5 * 2005-2006 Hervé Poussineau (hpoussin@reactos.org)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "setupapi_private.h"
24 /* Unicode constants */
25 static const WCHAR BackSlash
[] = {'\\',0};
26 static const WCHAR DateFormat
[] = {'%','u','-','%','u','-','%','u',0};
27 static const WCHAR DotCoInstallers
[] = {'.','C','o','I','n','s','t','a','l','l','e','r','s',0};
28 static const WCHAR DotHW
[] = {'.','H','W',0};
29 static const WCHAR DotServices
[] = {'.','S','e','r','v','i','c','e','s',0};
30 static const WCHAR InfDirectory
[] = {'i','n','f','\\',0};
31 static const WCHAR InstanceKeyFormat
[] = {'%','0','4','l','u',0};
32 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
33 static const WCHAR VersionFormat
[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
35 static const WCHAR REGSTR_DRIVER_DATE
[] = {'D','r','i','v','e','r','D','a','t','e',0};
36 static const WCHAR REGSTR_DRIVER_DATE_DATA
[] = {'D','r','i','v','e','r','D','a','t','e','D','a','t','a',0};
37 static const WCHAR REGSTR_DRIVER_VERSION
[] = {'D','r','i','v','e','r','V','e','r','s','i','o','n',0};
38 static const WCHAR REGSTR_SECURITY
[] = {'S','e','c','u','r','i','t','y',0};
39 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};
42 (CALLBACK
* CLASS_INSTALL_PROC
) (
43 IN DI_FUNCTION InstallFunction
,
44 IN HDEVINFO DeviceInfoSet
,
45 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
);
47 (WINAPI
* DEFAULT_CLASS_INSTALL_PROC
) (
48 IN HDEVINFO DeviceInfoSet
,
49 IN OUT PSP_DEVINFO_DATA DeviceInfoData
);
51 (CALLBACK
* COINSTALLER_PROC
) (
52 IN DI_FUNCTION InstallFunction
,
53 IN HDEVINFO DeviceInfoSet
,
54 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
55 IN OUT PCOINSTALLER_CONTEXT_DATA Context
);
57 struct CoInstallerElement
62 COINSTALLER_PROC Function
;
63 BOOL DoPostProcessing
;
67 struct GetSectionCallbackInfo
69 PSP_ALTPLATFORM_INFO PlatformInfo
;
73 WCHAR BestSection
[LINE_LEN
+ 1];
74 DWORD BestScore1
, BestScore2
, BestScore3
, BestScore4
, BestScore5
;
79 static void SETUPDI_GuidToString(const GUID
*guid
, LPWSTR guidStr
)
81 static const WCHAR fmt
[] = {'{','%','0','8','X','-','%','0','4','X','-',
82 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
83 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
86 sprintfW(guidStr
, fmt
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
87 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
88 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
92 GetErrorCodeFromCrCode(const IN CONFIGRET cr
)
96 case CR_ACCESS_DENIED
: return ERROR_ACCESS_DENIED
;
97 case CR_BUFFER_SMALL
: return ERROR_INSUFFICIENT_BUFFER
;
98 case CR_CALL_NOT_IMPLEMENTED
: return ERROR_CALL_NOT_IMPLEMENTED
;
99 case CR_FAILURE
: return ERROR_GEN_FAILURE
;
100 case CR_INVALID_DATA
: return ERROR_INVALID_USER_BUFFER
;
101 case CR_INVALID_DEVICE_ID
: return ERROR_INVALID_PARAMETER
;
102 case CR_INVALID_MACHINENAME
: return ERROR_INVALID_COMPUTERNAME
;
103 case CR_INVALID_DEVNODE
: return ERROR_INVALID_PARAMETER
;
104 case CR_INVALID_FLAG
: return ERROR_INVALID_FLAGS
;
105 case CR_INVALID_POINTER
: return ERROR_INVALID_PARAMETER
;
106 case CR_INVALID_PROPERTY
: return ERROR_INVALID_PARAMETER
;
107 case CR_NO_SUCH_DEVNODE
: return ERROR_FILE_NOT_FOUND
;
108 case CR_NO_SUCH_REGISTRY_KEY
: return ERROR_FILE_NOT_FOUND
;
109 case CR_NO_SUCH_VALUE
: return ERROR_FILE_NOT_FOUND
;
110 case CR_OUT_OF_MEMORY
: return ERROR_NOT_ENOUGH_MEMORY
;
111 case CR_REGISTRY_ERROR
: return ERROR_GEN_FAILURE
;
112 case CR_ALREADY_SUCH_DEVINST
: return ERROR_DEVINST_ALREADY_EXISTS
;
113 case CR_SUCCESS
: return ERROR_SUCCESS
;
114 default: return ERROR_GEN_FAILURE
;
117 /* Does not happen */
120 /* Lower scores are best ones */
123 IN LPCWSTR SectionName
,
124 IN PSP_ALTPLATFORM_INFO PlatformInfo
,
127 OUT PDWORD ScorePlatform
,
128 OUT PDWORD ScoreMajorVersion
,
129 OUT PDWORD ScoreMinorVersion
,
130 OUT PDWORD ScoreProductType
,
131 OUT PDWORD ScoreSuiteMask
)
133 LPWSTR Section
= NULL
;
134 //LPCWSTR pExtensionPlatform;
135 LPCWSTR pExtensionArchitecture
;
140 //static const WCHAR ExtensionPlatformNone[] = {'.',0};
141 static const WCHAR ExtensionPlatformNT
[] = {'.','N','T',0};
142 static const WCHAR ExtensionPlatformWindows
[] = {'.','W','i','n',0};
144 static const WCHAR ExtensionArchitectureNone
[] = {0};
145 static const WCHAR ExtensionArchitecturealpha
[] = {'a','l','p','h','a',0};
146 static const WCHAR ExtensionArchitectureamd64
[] = {'A','M','D','6','4',0};
147 static const WCHAR ExtensionArchitectureia64
[] = {'I','A','6','4',0};
148 static const WCHAR ExtensionArchitecturemips
[] = {'m','i','p','s',0};
149 static const WCHAR ExtensionArchitectureppc
[] = {'p','p','c',0};
150 static const WCHAR ExtensionArchitecturex86
[] = {'x','8','6',0};
152 TRACE("%s %p 0x%x 0x%x\n",
153 debugstr_w(SectionName
), PlatformInfo
, ProductType
, SuiteMask
);
155 *ScorePlatform
= *ScoreMajorVersion
= *ScoreMinorVersion
= *ScoreProductType
= *ScoreSuiteMask
= 0;
157 Section
= pSetupDuplicateString(SectionName
);
160 TRACE("pSetupDuplicateString() failed\n");
164 /* Set various extensions values */
165 switch (PlatformInfo
->Platform
)
167 case VER_PLATFORM_WIN32_WINDOWS
:
168 //pExtensionPlatform = ExtensionPlatformWindows;
170 case VER_PLATFORM_WIN32_NT
:
171 //pExtensionPlatform = ExtensionPlatformNT;
174 ERR("Unknown platform 0x%lx\n", PlatformInfo
->Platform
);
175 //pExtensionPlatform = ExtensionPlatformNone;
178 switch (PlatformInfo
->ProcessorArchitecture
)
180 case PROCESSOR_ARCHITECTURE_ALPHA
:
181 pExtensionArchitecture
= ExtensionArchitecturealpha
;
183 case PROCESSOR_ARCHITECTURE_AMD64
:
184 pExtensionArchitecture
= ExtensionArchitectureamd64
;
186 case PROCESSOR_ARCHITECTURE_IA64
:
187 pExtensionArchitecture
= ExtensionArchitectureia64
;
189 case PROCESSOR_ARCHITECTURE_INTEL
:
190 pExtensionArchitecture
= ExtensionArchitecturex86
;
192 case PROCESSOR_ARCHITECTURE_MIPS
:
193 pExtensionArchitecture
= ExtensionArchitecturemips
;
195 case PROCESSOR_ARCHITECTURE_PPC
:
196 pExtensionArchitecture
= ExtensionArchitectureppc
;
199 ERR("Unknown processor architecture 0x%x\n", PlatformInfo
->ProcessorArchitecture
);
200 case PROCESSOR_ARCHITECTURE_UNKNOWN
:
201 pExtensionArchitecture
= ExtensionArchitectureNone
;
207 * Field[1] Architecture
208 * Field[2] Major version
209 * Field[3] Minor version
210 * Field[4] Product type
211 * Field[5] Suite mask
212 * Remark: these fields may be NULL if the information is not provided
215 if (Fields
[0] == NULL
)
217 TRACE("No extension found\n");
218 *ScorePlatform
= *ScoreMajorVersion
= *ScoreMinorVersion
= *ScoreProductType
= *ScoreSuiteMask
= ULONG_MAX
;
222 Fields
[1] = Fields
[0] + 1;
223 Fields
[2] = Fields
[3] = Fields
[4] = Fields
[5] = NULL
;
224 for (i
= 2; Fields
[i
- 1] != NULL
&& i
< 6; i
++)
226 Fields
[i
] = wcschr(Fields
[i
- 1], '.');
230 *(Fields
[i
] - 1) = UNICODE_NULL
;
233 /* Take care of first 2 fields */
234 if (strncmpiW(Fields
[0], ExtensionPlatformWindows
, strlenW(ExtensionPlatformWindows
)) == 0)
236 if (PlatformInfo
->Platform
!= VER_PLATFORM_WIN32_WINDOWS
)
238 TRACE("Mismatch on platform field\n");
241 Fields
[1] += wcslen(ExtensionPlatformWindows
) - 1;
243 else if (strncmpiW(Fields
[0], ExtensionPlatformNT
, strlenW(ExtensionPlatformNT
)) == 0)
245 if (PlatformInfo
->Platform
!= VER_PLATFORM_WIN32_NT
)
247 TRACE("Mismatch on platform field\n");
250 Fields
[1] += wcslen(ExtensionPlatformNT
) - 1;
254 /* No platform specified */
255 *ScorePlatform
|= 0x02;
257 if (strcmpiW(Fields
[1], ExtensionArchitectureNone
) == 0)
259 /* No architecture specified */
260 *ScorePlatform
|= 0x01;
262 else if (strcmpiW(Fields
[1], pExtensionArchitecture
) != 0)
264 TRACE("Mismatch on architecture field ('%s' and '%s')\n",
265 debugstr_w(Fields
[1]), debugstr_w(pExtensionArchitecture
));
269 /* Check if informations are matching */
270 if (Fields
[2] && *Fields
[2])
272 DWORD MajorVersion
, MinorVersion
= 0;
273 MajorVersion
= strtoulW(Fields
[2], NULL
, 0);
274 if ((MajorVersion
== 0 || MajorVersion
== ULONG_MAX
) &&
275 (errno
== ERANGE
|| errno
== EINVAL
))
277 TRACE("Wrong MajorVersion ('%s')\n", debugstr_w(Fields
[2]));
280 if (Fields
[3] && *Fields
[3])
282 MinorVersion
= strtoulW(Fields
[3], NULL
, 0);
283 if ((MinorVersion
== 0 || MinorVersion
== ULONG_MAX
) &&
284 (errno
== ERANGE
|| errno
== EINVAL
))
286 TRACE("Wrong MinorVersion ('%s')\n", debugstr_w(Fields
[3]));
290 if (PlatformInfo
->MajorVersion
< MajorVersion
||
291 (PlatformInfo
->MajorVersion
== MajorVersion
&& PlatformInfo
->MinorVersion
< MinorVersion
))
293 TRACE("Mismatch on version field (%lu.%lu and %lu.%lu)\n",
294 MajorVersion
, MinorVersion
, PlatformInfo
->MajorVersion
, PlatformInfo
->MinorVersion
);
297 *ScoreMajorVersion
= MajorVersion
- PlatformInfo
->MajorVersion
;
298 if (MajorVersion
== PlatformInfo
->MajorVersion
)
299 *ScoreMinorVersion
= MinorVersion
- PlatformInfo
->MinorVersion
;
301 *ScoreMinorVersion
= MinorVersion
;
303 else if (Fields
[3] && *Fields
[3])
305 TRACE("Minor version found without major version\n");
310 *ScoreMajorVersion
= PlatformInfo
->MajorVersion
;
311 *ScoreMinorVersion
= PlatformInfo
->MinorVersion
;
314 if (Fields
[4] && *Fields
[4])
316 DWORD CurrentProductType
;
317 CurrentProductType
= strtoulW(Fields
[4], NULL
, 0);
318 if ((CurrentProductType
== 0 || CurrentProductType
== ULONG_MAX
) &&
319 (errno
== ERANGE
|| errno
== EINVAL
))
321 TRACE("Wrong Product type ('%s')\n", debugstr_w(Fields
[4]));
324 if (CurrentProductType
!= ProductType
)
326 TRACE("Mismatch on product type (0x%08lx and 0x%08x)\n",
327 CurrentProductType
, ProductType
);
332 *ScoreProductType
= 1;
334 if (Fields
[5] && *Fields
[5])
336 DWORD CurrentSuiteMask
;
337 CurrentSuiteMask
= strtoulW(Fields
[5], NULL
, 0);
338 if ((CurrentSuiteMask
== 0 || CurrentSuiteMask
== ULONG_MAX
) &&
339 (errno
== ERANGE
|| errno
== EINVAL
))
341 TRACE("Wrong Suite mask ('%s')\n", debugstr_w(Fields
[5]));
344 if ((CurrentSuiteMask
& ~SuiteMask
) != 0)
346 TRACE("Mismatch on suite mask (0x%08lx and 0x%08x)\n",
347 CurrentSuiteMask
, SuiteMask
);
350 *ScoreSuiteMask
= SuiteMask
& ~CurrentSuiteMask
;
353 *ScoreSuiteMask
= SuiteMask
;
364 IN LPCWSTR SectionName
,
367 struct GetSectionCallbackInfo
*info
= Context
;
368 DWORD Score1
, Score2
, Score3
, Score4
, Score5
;
371 if (SectionName
[info
->PrefixLength
] != '.')
374 ret
= CheckSectionValid(
375 &SectionName
[info
->PrefixLength
],
379 &Score1
, &Score2
, &Score3
, &Score4
, &Score5
);
382 TRACE("Section %s not compatible\n", debugstr_w(SectionName
));
385 if (Score1
> info
->BestScore1
) goto done
;
386 if (Score1
< info
->BestScore1
) goto bettersection
;
387 if (Score2
> info
->BestScore2
) goto done
;
388 if (Score2
< info
->BestScore2
) goto bettersection
;
389 if (Score3
> info
->BestScore3
) goto done
;
390 if (Score3
< info
->BestScore3
) goto bettersection
;
391 if (Score4
> info
->BestScore4
) goto done
;
392 if (Score4
< info
->BestScore4
) goto bettersection
;
393 if (Score5
> info
->BestScore5
) goto done
;
394 if (Score5
< info
->BestScore5
) goto bettersection
;
398 strcpyW(info
->BestSection
, SectionName
);
399 info
->BestScore1
= Score1
;
400 info
->BestScore2
= Score2
;
401 info
->BestScore3
= Score3
;
402 info
->BestScore4
= Score4
;
403 info
->BestScore5
= Score5
;
409 /***********************************************************************
410 * SetupDiGetActualSectionToInstallExW (SETUPAPI.@)
413 SetupDiGetActualSectionToInstallExW(
415 IN PCWSTR InfSectionName
,
416 IN PSP_ALTPLATFORM_INFO AlternatePlatformInfo OPTIONAL
,
417 OUT PWSTR InfSectionWithExt OPTIONAL
,
418 IN DWORD InfSectionWithExtSize
,
419 OUT PDWORD RequiredSize OPTIONAL
,
420 OUT PWSTR
* Extension OPTIONAL
,
425 TRACE("%p %s %p %p %lu %p %p %p\n", InfHandle
, debugstr_w(InfSectionName
),
426 AlternatePlatformInfo
, InfSectionWithExt
, InfSectionWithExtSize
,
427 RequiredSize
, Extension
, Reserved
);
429 if (!InfHandle
|| InfHandle
== (HINF
)INVALID_HANDLE_VALUE
)
430 SetLastError(ERROR_INVALID_HANDLE
);
431 else if (!InfSectionName
)
432 SetLastError(ERROR_INVALID_PARAMETER
);
433 else if (AlternatePlatformInfo
&& AlternatePlatformInfo
->cbSize
!= sizeof(SP_ALTPLATFORM_INFO
))
434 SetLastError(ERROR_INVALID_USER_BUFFER
);
435 else if (Reserved
!= NULL
)
436 SetLastError(ERROR_INVALID_PARAMETER
);
439 static SP_ALTPLATFORM_INFO CurrentPlatform
= { 0, };
440 static BYTE CurrentProductType
= 0;
441 static WORD CurrentSuiteMask
= 0;
442 PSP_ALTPLATFORM_INFO pPlatformInfo
= &CurrentPlatform
;
443 struct GetSectionCallbackInfo CallbackInfo
;
448 /* Fill platform info if needed */
449 if (AlternatePlatformInfo
)
451 pPlatformInfo
= AlternatePlatformInfo
;
457 if (CurrentPlatform
.cbSize
!= sizeof(SP_ALTPLATFORM_INFO
))
459 /* That's the first time we go here. We need to fill in the structure */
460 SYSTEM_INFO SystemInfo
;
461 GetSystemInfo(&SystemInfo
);
462 CurrentPlatform
.cbSize
= sizeof(SP_ALTPLATFORM_INFO
);
463 CurrentPlatform
.Platform
= OsVersionInfo
.dwPlatformId
;
464 CurrentPlatform
.MajorVersion
= OsVersionInfo
.dwMajorVersion
;
465 CurrentPlatform
.MinorVersion
= OsVersionInfo
.dwMinorVersion
;
466 CurrentPlatform
.ProcessorArchitecture
= SystemInfo
.wProcessorArchitecture
;
467 CurrentPlatform
.Reserved
= 0;
468 CurrentProductType
= OsVersionInfo
.wProductType
;
469 CurrentSuiteMask
= OsVersionInfo
.wSuiteMask
;
471 ProductType
= CurrentProductType
;
472 SuiteMask
= CurrentSuiteMask
;
475 CallbackInfo
.PlatformInfo
= pPlatformInfo
;
476 CallbackInfo
.ProductType
= ProductType
;
477 CallbackInfo
.SuiteMask
= SuiteMask
;
478 CallbackInfo
.PrefixLength
= strlenW(InfSectionName
);
479 CallbackInfo
.BestScore1
= ULONG_MAX
;
480 CallbackInfo
.BestScore2
= ULONG_MAX
;
481 CallbackInfo
.BestScore3
= ULONG_MAX
;
482 CallbackInfo
.BestScore4
= ULONG_MAX
;
483 CallbackInfo
.BestScore5
= ULONG_MAX
;
484 strcpyW(CallbackInfo
.BestSection
, InfSectionName
);
485 TRACE("EnumerateSectionsStartingWith(InfSectionName = %S)\n", InfSectionName
);
486 if (!EnumerateSectionsStartingWith(
492 SetLastError(ERROR_GEN_FAILURE
);
495 TRACE("CallbackInfo.BestSection = %S\n", CallbackInfo
.BestSection
);
497 dwFullLength
= lstrlenW(CallbackInfo
.BestSection
);
498 if (RequiredSize
!= NULL
)
499 *RequiredSize
= dwFullLength
+ 1;
501 if (InfSectionWithExtSize
> 0)
503 if (InfSectionWithExtSize
< dwFullLength
+ 1)
505 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
508 strcpyW(InfSectionWithExt
, CallbackInfo
.BestSection
);
511 DWORD dwLength
= lstrlenW(InfSectionName
);
512 *Extension
= (dwLength
== dwFullLength
) ? NULL
: &InfSectionWithExt
[dwLength
];
520 TRACE("Returning %d\n", ret
);
527 IN
struct DeviceInfoSet
*list
,
528 IN LPCWSTR InstancePath
,
529 IN LPCGUID pClassGuid
,
530 OUT
struct DeviceInfo
**pDeviceInfo
)
534 struct DeviceInfo
*deviceInfo
;
538 size
= FIELD_OFFSET(struct DeviceInfo
, Data
) + (strlenW(InstancePath
) + 1) * sizeof(WCHAR
);
539 deviceInfo
= HeapAlloc(GetProcessHeap(), 0, size
);
542 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
545 ZeroMemory(deviceInfo
, size
);
547 cr
= CM_Locate_DevNode_ExW(&deviceInfo
->dnDevInst
, (DEVINSTID_W
)InstancePath
, CM_LOCATE_DEVNODE_PHANTOM
, list
->hMachine
);
548 if (cr
!= CR_SUCCESS
)
550 SetLastError(GetErrorCodeFromCrCode(cr
));
554 deviceInfo
->set
= list
;
555 deviceInfo
->InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
556 strcpyW(deviceInfo
->Data
, InstancePath
);
557 deviceInfo
->instanceId
= deviceInfo
->Data
;
558 deviceInfo
->UniqueId
= strrchrW(deviceInfo
->Data
, '\\');
559 deviceInfo
->DeviceDescription
= NULL
;
560 memcpy(&deviceInfo
->ClassGuid
, pClassGuid
, sizeof(GUID
));
561 deviceInfo
->CreationFlags
= 0;
562 InitializeListHead(&deviceInfo
->DriverListHead
);
563 InitializeListHead(&deviceInfo
->InterfaceListHead
);
565 *pDeviceInfo
= deviceInfo
;
571 DestroyClassInstallParams(struct ClassInstallParams
* installParams
)
573 HeapFree(GetProcessHeap(), 0, installParams
->PropChangeParams
);
574 HeapFree(GetProcessHeap(), 0, installParams
->AddPropertyPageData
);
579 DestroyDeviceInfo(struct DeviceInfo
*deviceInfo
)
581 PLIST_ENTRY ListEntry
;
582 struct DriverInfoElement
*driverInfo
;
583 struct DeviceInterface
*deviceInterface
;
585 while (!IsListEmpty(&deviceInfo
->DriverListHead
))
587 ListEntry
= RemoveHeadList(&deviceInfo
->DriverListHead
);
588 driverInfo
= CONTAINING_RECORD(ListEntry
, struct DriverInfoElement
, ListEntry
);
589 if (!DestroyDriverInfoElement(driverInfo
))
592 while (!IsListEmpty(&deviceInfo
->InterfaceListHead
))
594 ListEntry
= RemoveHeadList(&deviceInfo
->InterfaceListHead
);
595 deviceInterface
= CONTAINING_RECORD(ListEntry
, struct DeviceInterface
, ListEntry
);
596 if (!DestroyDeviceInterface(deviceInterface
))
599 DestroyClassInstallParams(&deviceInfo
->ClassInstallParams
);
600 if (deviceInfo
->hmodDevicePropPageProvider
)
601 FreeLibrary(deviceInfo
->hmodDevicePropPageProvider
);
602 return HeapFree(GetProcessHeap(), 0, deviceInfo
);
606 DestroyDeviceInfoSet(struct DeviceInfoSet
* list
)
608 PLIST_ENTRY ListEntry
;
609 struct DeviceInfo
*deviceInfo
;
611 while (!IsListEmpty(&list
->ListHead
))
613 ListEntry
= RemoveHeadList(&list
->ListHead
);
614 deviceInfo
= CONTAINING_RECORD(ListEntry
, struct DeviceInfo
, ListEntry
);
615 if (!DestroyDeviceInfo(deviceInfo
))
618 if (list
->HKLM
!= HKEY_LOCAL_MACHINE
)
619 RegCloseKey(list
->HKLM
);
620 CM_Disconnect_Machine(list
->hMachine
);
621 DestroyClassInstallParams(&list
->ClassInstallParams
);
622 if (list
->hmodClassPropPageProvider
)
623 FreeLibrary(list
->hmodClassPropPageProvider
);
624 return HeapFree(GetProcessHeap(), 0, list
);
627 /***********************************************************************
628 * SetupDiBuildClassInfoList (SETUPAPI.@)
630 * Returns a list of setup class GUIDs that identify the classes
631 * that are installed on a local machine.
634 * Flags [I] control exclusion of classes from the list.
635 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
636 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
637 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
643 BOOL WINAPI
SetupDiBuildClassInfoList(
645 LPGUID ClassGuidList
,
646 DWORD ClassGuidListSize
,
650 return SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
651 ClassGuidListSize
, RequiredSize
,
655 /***********************************************************************
656 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
658 * Returns a list of setup class GUIDs that identify the classes
659 * that are installed on a local or remote machine.
662 * Flags [I] control exclusion of classes from the list.
663 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
664 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
665 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
666 * MachineName [I] name of a remote machine.
667 * Reserved [I] must be NULL.
673 BOOL WINAPI
SetupDiBuildClassInfoListExA(
675 LPGUID ClassGuidList
,
676 DWORD ClassGuidListSize
,
681 LPWSTR MachineNameW
= NULL
;
684 TRACE("0x%lx %p %lu %p %s %p\n", Flags
, ClassGuidList
,
685 ClassGuidListSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
689 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
690 if (MachineNameW
== NULL
) return FALSE
;
693 bResult
= SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
694 ClassGuidListSize
, RequiredSize
,
695 MachineNameW
, Reserved
);
697 MyFree(MachineNameW
);
702 /***********************************************************************
703 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
705 * Returns a list of setup class GUIDs that identify the classes
706 * that are installed on a local or remote machine.
709 * Flags [I] control exclusion of classes from the list.
710 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
711 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
712 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
713 * MachineName [I] name of a remote machine.
714 * Reserved [I] must be NULL.
720 BOOL WINAPI
SetupDiBuildClassInfoListExW(
722 LPGUID ClassGuidList
,
723 DWORD ClassGuidListSize
,
729 HKEY hClassesKey
= INVALID_HANDLE_VALUE
;
734 DWORD dwGuidListIndex
= 0;
736 TRACE("0x%lx %p %lu %p %s %p\n", Flags
, ClassGuidList
,
737 ClassGuidListSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
741 SetLastError(ERROR_INVALID_PARAMETER
);
744 else if (!ClassGuidList
&& ClassGuidListSize
> 0)
746 SetLastError(ERROR_INVALID_PARAMETER
);
750 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
751 KEY_ENUMERATE_SUB_KEYS
,
755 if (hClassesKey
== INVALID_HANDLE_VALUE
)
760 for (dwIndex
= 0; ; dwIndex
++)
763 lError
= RegEnumKeyExW(hClassesKey
,
771 TRACE("RegEnumKeyExW() returns %d\n", lError
);
772 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
774 TRACE("Key name: %s\n", debugstr_w(szKeyName
));
776 if (RegOpenKeyExW(hClassesKey
,
782 RegCloseKey(hClassesKey
);
786 if (!RegQueryValueExW(hClassKey
,
787 REGSTR_VAL_NOUSECLASS
,
793 TRACE("'NoUseClass' value found!\n");
794 RegCloseKey(hClassKey
);
798 if ((Flags
& DIBCI_NOINSTALLCLASS
) &&
799 (!RegQueryValueExW(hClassKey
,
800 REGSTR_VAL_NOINSTALLCLASS
,
806 TRACE("'NoInstallClass' value found!\n");
807 RegCloseKey(hClassKey
);
811 if ((Flags
& DIBCI_NODISPLAYCLASS
) &&
812 (!RegQueryValueExW(hClassKey
,
813 REGSTR_VAL_NODISPLAYCLASS
,
819 TRACE("'NoDisplayClass' value found!\n");
820 RegCloseKey(hClassKey
);
824 RegCloseKey(hClassKey
);
826 TRACE("Guid: %s\n", debugstr_w(szKeyName
));
827 if (dwGuidListIndex
< ClassGuidListSize
)
829 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
833 TRACE("Guid: %p\n", &szKeyName
[1]);
835 UuidFromStringW(&szKeyName
[1],
836 &ClassGuidList
[dwGuidListIndex
]);
842 if (lError
!= ERROR_SUCCESS
)
846 RegCloseKey(hClassesKey
);
848 if (RequiredSize
!= NULL
)
849 *RequiredSize
= dwGuidListIndex
;
851 if (ClassGuidListSize
< dwGuidListIndex
)
853 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
860 /***********************************************************************
861 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
863 BOOL WINAPI
SetupDiClassGuidsFromNameA(
865 LPGUID ClassGuidList
,
866 DWORD ClassGuidListSize
,
869 return SetupDiClassGuidsFromNameExA(ClassName
, ClassGuidList
,
870 ClassGuidListSize
, RequiredSize
,
874 /***********************************************************************
875 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
877 BOOL WINAPI
SetupDiClassGuidsFromNameW(
879 LPGUID ClassGuidList
,
880 DWORD ClassGuidListSize
,
883 return SetupDiClassGuidsFromNameExW(ClassName
, ClassGuidList
,
884 ClassGuidListSize
, RequiredSize
,
888 /***********************************************************************
889 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
891 BOOL WINAPI
SetupDiClassGuidsFromNameExA(
893 LPGUID ClassGuidList
,
894 DWORD ClassGuidListSize
,
899 LPWSTR ClassNameW
= NULL
;
900 LPWSTR MachineNameW
= NULL
;
903 TRACE("%s %p %lu %p %s %p\n", debugstr_a(ClassName
), ClassGuidList
,
904 ClassGuidListSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
908 SetLastError(ERROR_INVALID_PARAMETER
);
912 ClassNameW
= pSetupMultiByteToUnicode(ClassName
, CP_ACP
);
913 if (ClassNameW
== NULL
)
918 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
919 if (MachineNameW
== NULL
)
926 bResult
= SetupDiClassGuidsFromNameExW(ClassNameW
, ClassGuidList
,
927 ClassGuidListSize
, RequiredSize
,
928 MachineNameW
, Reserved
);
930 MyFree(MachineNameW
);
936 /***********************************************************************
937 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
939 BOOL WINAPI
SetupDiClassGuidsFromNameExW(
941 LPGUID ClassGuidList
,
942 DWORD ClassGuidListSize
,
948 WCHAR szClassName
[MAX_CLASS_NAME_LEN
];
954 DWORD dwGuidListIndex
= 0;
956 TRACE("%s %p %lu %p %s %p\n", debugstr_w(ClassName
), ClassGuidList
,
957 ClassGuidListSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
959 if (!ClassName
|| !RequiredSize
)
961 SetLastError(ERROR_INVALID_PARAMETER
);
964 if (!ClassGuidList
&& ClassGuidListSize
> 0)
966 SetLastError(ERROR_INVALID_PARAMETER
);
971 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
972 KEY_ENUMERATE_SUB_KEYS
,
976 if (hClassesKey
== INVALID_HANDLE_VALUE
)
981 for (dwIndex
= 0; ; dwIndex
++)
984 lError
= RegEnumKeyExW(hClassesKey
,
992 TRACE("RegEnumKeyExW() returns %d\n", lError
);
993 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
995 TRACE("Key name: %p\n", szKeyName
);
997 if (RegOpenKeyExW(hClassesKey
,
1003 RegCloseKey(hClassesKey
);
1007 dwLength
= MAX_CLASS_NAME_LEN
* sizeof(WCHAR
);
1008 if (!RegQueryValueExW(hClassKey
,
1012 (LPBYTE
)szClassName
,
1015 TRACE("Class name: %p\n", szClassName
);
1017 if (strcmpiW(szClassName
, ClassName
) == 0)
1019 TRACE("Found matching class name\n");
1021 TRACE("Guid: %p\n", szKeyName
);
1022 if (dwGuidListIndex
< ClassGuidListSize
)
1024 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
1028 TRACE("Guid: %p\n", &szKeyName
[1]);
1030 UuidFromStringW(&szKeyName
[1],
1031 &ClassGuidList
[dwGuidListIndex
]);
1038 RegCloseKey(hClassKey
);
1041 if (lError
!= ERROR_SUCCESS
)
1045 RegCloseKey(hClassesKey
);
1047 if (RequiredSize
!= NULL
)
1048 *RequiredSize
= dwGuidListIndex
;
1050 if (ClassGuidListSize
< dwGuidListIndex
)
1052 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1059 /***********************************************************************
1060 * SetupDiClassNameFromGuidA (SETUPAPI.@)
1062 BOOL WINAPI
SetupDiClassNameFromGuidA(
1063 const GUID
* ClassGuid
,
1065 DWORD ClassNameSize
,
1066 PDWORD RequiredSize
)
1068 return SetupDiClassNameFromGuidExA(ClassGuid
, ClassName
,
1069 ClassNameSize
, RequiredSize
,
1073 /***********************************************************************
1074 * SetupDiClassNameFromGuidW (SETUPAPI.@)
1076 BOOL WINAPI
SetupDiClassNameFromGuidW(
1077 const GUID
* ClassGuid
,
1079 DWORD ClassNameSize
,
1080 PDWORD RequiredSize
)
1082 return SetupDiClassNameFromGuidExW(ClassGuid
, ClassName
,
1083 ClassNameSize
, RequiredSize
,
1087 /***********************************************************************
1088 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1090 BOOL WINAPI
SetupDiClassNameFromGuidExA(
1091 const GUID
* ClassGuid
,
1093 DWORD ClassNameSize
,
1094 PDWORD RequiredSize
,
1098 WCHAR ClassNameW
[MAX_CLASS_NAME_LEN
];
1099 LPWSTR MachineNameW
= NULL
;
1103 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
1104 ret
= SetupDiClassNameFromGuidExW(ClassGuid
, ClassNameW
, MAX_CLASS_NAME_LEN
,
1105 RequiredSize
, MachineNameW
, Reserved
);
1108 int len
= WideCharToMultiByte(CP_ACP
, 0, ClassNameW
, -1, ClassName
,
1109 ClassNameSize
, NULL
, NULL
);
1110 if (len
== 0 || len
> ClassNameSize
)
1112 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1116 MyFree(MachineNameW
);
1120 /***********************************************************************
1121 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1123 BOOL WINAPI
SetupDiClassNameFromGuidExW(
1124 const GUID
* ClassGuid
,
1126 DWORD ClassNameSize
,
1127 PDWORD RequiredSize
,
1137 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassName
,
1138 ClassNameSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
1140 /* Make sure there's a GUID */
1141 if (ClassGuid
== NULL
)
1143 SetLastError(ERROR_INVALID_CLASS
); /* On Vista: ERROR_INVALID_USER_BUFFER */
1147 /* Make sure there's a real buffer when there's a size */
1148 if ((ClassNameSize
> 0) && (ClassName
== NULL
))
1150 SetLastError(ERROR_INVALID_PARAMETER
); /* On Vista: ERROR_INVALID_USER_BUFFER */
1154 /* Open the key for the GUID */
1155 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, KEY_QUERY_VALUE
, DIOCR_INSTALLER
, MachineName
, Reserved
);
1157 if (hKey
== INVALID_HANDLE_VALUE
)
1160 /* Retrieve the class name data and close the key */
1161 rc
= QueryRegistryValue(hKey
, REGSTR_VAL_CLASS
, (LPBYTE
*) &Buffer
, &dwRegType
, &dwLength
);
1164 /* Make sure we got the data */
1165 if (rc
!= ERROR_SUCCESS
)
1171 /* Make sure the data is a string */
1172 if (dwRegType
!= REG_SZ
)
1175 SetLastError(ERROR_GEN_FAILURE
);
1179 /* Determine the length of the class name */
1180 dwLength
/= sizeof(WCHAR
);
1182 if ((dwLength
== 0) || (Buffer
[dwLength
- 1] != UNICODE_NULL
))
1183 /* Count the null-terminator */
1186 /* Inform the caller about the class name */
1187 if ((ClassName
!= NULL
) && (dwLength
<= ClassNameSize
))
1189 memcpy(ClassName
, Buffer
, (dwLength
- 1) * sizeof(WCHAR
));
1190 ClassName
[dwLength
- 1] = UNICODE_NULL
;
1193 /* Inform the caller about the required size */
1194 if (RequiredSize
!= NULL
)
1195 *RequiredSize
= dwLength
;
1197 /* Clean up the buffer */
1200 /* Make sure the buffer was large enough */
1201 if ((ClassName
== NULL
) || (dwLength
> ClassNameSize
))
1203 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1210 /***********************************************************************
1211 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1214 SetupDiCreateDeviceInfoList(const GUID
*ClassGuid
,
1217 return SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
, NULL
, NULL
);
1220 /***********************************************************************
1221 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1224 SetupDiCreateDeviceInfoListExA(const GUID
*ClassGuid
,
1229 LPWSTR MachineNameW
= NULL
;
1232 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1233 debugstr_a(MachineName
), Reserved
);
1237 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
1238 if (MachineNameW
== NULL
)
1239 return INVALID_HANDLE_VALUE
;
1242 hDevInfo
= SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
,
1243 MachineNameW
, Reserved
);
1245 MyFree(MachineNameW
);
1250 /***********************************************************************
1251 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1253 * Create an empty DeviceInfoSet list.
1256 * ClassGuid [I] if not NULL only devices with GUID ClassGuid are associated
1258 * hwndParent [I] hwnd needed for interface related actions.
1259 * MachineName [I] name of machine to create emtpy DeviceInfoSet list, if NULL
1260 * local registry will be used.
1261 * Reserved [I] must be NULL
1264 * Success: empty list.
1265 * Failure: INVALID_HANDLE_VALUE.
1268 SetupDiCreateDeviceInfoListExW(const GUID
*ClassGuid
,
1273 struct DeviceInfoSet
*list
= NULL
;
1274 DWORD size
= FIELD_OFFSET(struct DeviceInfoSet
, szData
);
1277 HDEVINFO ret
= INVALID_HANDLE_VALUE
;
1279 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1280 debugstr_w(MachineName
), Reserved
);
1282 if (MachineName
!= NULL
)
1284 SIZE_T len
= strlenW(MachineName
);
1285 if (len
>= SP_MAX_MACHINENAME_LENGTH
- 4)
1287 SetLastError(ERROR_INVALID_MACHINENAME
);
1291 size
+= (len
+ 3) * sizeof(WCHAR
);
1296 if (Reserved
!= NULL
)
1298 SetLastError(ERROR_INVALID_PARAMETER
);
1299 return INVALID_HANDLE_VALUE
;
1302 list
= MyMalloc(size
);
1305 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1306 return INVALID_HANDLE_VALUE
;
1308 ZeroMemory(list
, FIELD_OFFSET(struct DeviceInfoSet
, szData
));
1310 list
->magic
= SETUP_DEVICE_INFO_SET_MAGIC
;
1311 memcpy(&list
->ClassGuid
,
1312 ClassGuid
? ClassGuid
: &GUID_NULL
,
1313 sizeof(list
->ClassGuid
));
1314 list
->InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
1315 list
->InstallParams
.Flags
|= DI_CLASSINSTALLPARAMS
;
1316 list
->InstallParams
.hwndParent
= hwndParent
;
1319 rc
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &list
->HKLM
);
1320 if (rc
!= ERROR_SUCCESS
)
1322 SetLastError(ERROR_INVALID_MACHINENAME
);
1326 list
->szData
[0] = list
->szData
[1] = '\\';
1327 strcpyW(list
->szData
+ 2, MachineName
);
1328 list
->MachineName
= list
->szData
;
1332 list
->HKLM
= HKEY_LOCAL_MACHINE
;
1333 list
->MachineName
= NULL
;
1335 cr
= CM_Connect_MachineW(list
->MachineName
, &list
->hMachine
);
1336 if (cr
!= CR_SUCCESS
)
1338 SetLastError(GetErrorCodeFromCrCode(cr
));
1341 InitializeListHead(&list
->DriverListHead
);
1342 InitializeListHead(&list
->ListHead
);
1344 return (HDEVINFO
)list
;
1347 if (ret
== INVALID_HANDLE_VALUE
)
1351 if (list
->HKLM
!= NULL
&& list
->HKLM
!= HKEY_LOCAL_MACHINE
)
1352 RegCloseKey(list
->HKLM
);
1359 /***********************************************************************
1360 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1362 HKEY WINAPI
SetupDiCreateDevRegKeyA(
1363 HDEVINFO DeviceInfoSet
,
1364 PSP_DEVINFO_DATA DeviceInfoData
,
1369 PCSTR InfSectionName
)
1371 PWSTR InfSectionNameW
= NULL
;
1374 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1375 HwProfile
, KeyType
, InfHandle
, debugstr_a(InfSectionName
));
1379 if (!InfSectionName
)
1381 SetLastError(ERROR_INVALID_PARAMETER
);
1382 return INVALID_HANDLE_VALUE
;
1386 InfSectionNameW
= pSetupMultiByteToUnicode(InfSectionName
, CP_ACP
);
1387 if (InfSectionNameW
== NULL
) return INVALID_HANDLE_VALUE
;
1390 key
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, Scope
,
1391 HwProfile
, KeyType
, InfHandle
, InfSectionNameW
);
1392 MyFree(InfSectionNameW
);
1397 OpenHardwareProfileKey(
1400 IN DWORD samDesired
);
1402 /***********************************************************************
1403 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1405 HKEY WINAPI
SetupDiCreateDevRegKeyW(
1406 HDEVINFO DeviceInfoSet
,
1407 PSP_DEVINFO_DATA DeviceInfoData
,
1412 PCWSTR InfSectionName
)
1414 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1415 HKEY key
= INVALID_HANDLE_VALUE
;
1416 LPWSTR lpGuidString
= NULL
;
1417 LPWSTR DriverKey
= NULL
; /* {GUID}\Index */
1418 LPWSTR pDeviceInstance
; /* Points into DriverKey, on the Index field */
1419 DWORD Index
; /* Index used in the DriverKey name */
1423 HKEY hHWProfileKey
= INVALID_HANDLE_VALUE
;
1424 HKEY hEnumKey
= NULL
;
1425 HKEY hClassKey
= NULL
;
1426 HKEY hDeviceKey
= INVALID_HANDLE_VALUE
;
1430 TRACE("%p %p %lu %lu %lu %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1431 HwProfile
, KeyType
, InfHandle
, debugstr_w(InfSectionName
));
1433 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1435 SetLastError(ERROR_INVALID_HANDLE
);
1436 return INVALID_HANDLE_VALUE
;
1438 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1440 SetLastError(ERROR_INVALID_HANDLE
);
1441 return INVALID_HANDLE_VALUE
;
1443 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1444 || !DeviceInfoData
->Reserved
)
1446 SetLastError(ERROR_INVALID_PARAMETER
);
1447 return INVALID_HANDLE_VALUE
;
1449 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
1451 SetLastError(ERROR_INVALID_FLAGS
);
1452 return INVALID_HANDLE_VALUE
;
1454 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
1456 SetLastError(ERROR_INVALID_FLAGS
);
1457 return INVALID_HANDLE_VALUE
;
1459 if (InfHandle
&& !InfSectionName
)
1461 SetLastError(ERROR_INVALID_PARAMETER
);
1462 return INVALID_HANDLE_VALUE
;
1464 if (!InfHandle
&& InfSectionName
)
1466 SetLastError(ERROR_INVALID_PARAMETER
);
1467 return INVALID_HANDLE_VALUE
;
1470 if (Scope
== DICS_FLAG_GLOBAL
)
1471 RootKey
= set
->HKLM
;
1472 else /* Scope == DICS_FLAG_CONFIGSPECIFIC */
1474 hHWProfileKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, KEY_CREATE_SUB_KEY
);
1475 if (hHWProfileKey
== INVALID_HANDLE_VALUE
)
1477 RootKey
= hHWProfileKey
;
1480 if (KeyType
== DIREG_DEV
)
1482 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1484 rc
= RegCreateKeyExW(
1486 REGSTR_PATH_SYSTEMENUM
,
1489 REG_OPTION_NON_VOLATILE
,
1494 if (rc
!= ERROR_SUCCESS
)
1499 rc
= RegCreateKeyExW(
1501 deviceInfo
->instanceId
,
1504 REG_OPTION_NON_VOLATILE
,
1505 #if _WIN32_WINNT >= 0x502
1506 KEY_READ
| KEY_WRITE
,
1513 if (rc
!= ERROR_SUCCESS
)
1519 else /* KeyType == DIREG_DRV */
1521 /* Open device key, to read Driver value */
1522 hDeviceKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
, DIREG_DEV
, KEY_QUERY_VALUE
| KEY_SET_VALUE
);
1523 if (hDeviceKey
== INVALID_HANDLE_VALUE
)
1526 rc
= RegOpenKeyExW(RootKey
, REGSTR_PATH_CLASS_NT
, 0, KEY_CREATE_SUB_KEY
, &hClassKey
);
1527 if (rc
!= ERROR_SUCCESS
)
1533 rc
= RegQueryValueExW(hDeviceKey
, REGSTR_VAL_DRIVER
, NULL
, NULL
, NULL
, &dwSize
);
1534 if (rc
!= ERROR_SUCCESS
)
1536 /* Create a new driver key */
1538 if (UuidToStringW((UUID
*)&DeviceInfoData
->ClassGuid
, &lpGuidString
) != RPC_S_OK
)
1541 /* The driver key is in \System\CurrentControlSet\Control\Class\{GUID}\Index */
1542 DriverKey
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpGuidString
) + 7) * sizeof(WCHAR
) + sizeof(UNICODE_NULL
));
1545 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1550 strcpyW(&DriverKey
[1], lpGuidString
);
1551 pDeviceInstance
= &DriverKey
[strlenW(DriverKey
)];
1552 *pDeviceInstance
++ = '}';
1553 *pDeviceInstance
++ = '\\';
1555 /* Try all values for Index between 0 and 9999 */
1557 while (Index
<= 9999)
1559 sprintfW(pDeviceInstance
, InstanceKeyFormat
, Index
);
1560 rc
= RegCreateKeyExW(hClassKey
,
1564 REG_OPTION_NON_VOLATILE
,
1565 #if _WIN32_WINNT >= 0x502
1566 KEY_READ
| KEY_WRITE
,
1573 if (rc
!= ERROR_SUCCESS
)
1578 if (Disposition
== REG_CREATED_NEW_KEY
)
1587 /* Unable to create more than 9999 devices within the same class */
1588 SetLastError(ERROR_GEN_FAILURE
);
1592 /* Write the new Driver value */
1593 rc
= RegSetValueExW(hDeviceKey
, REGSTR_VAL_DRIVER
, 0, REG_SZ
, (const BYTE
*)DriverKey
, (strlenW(DriverKey
) + 1) * sizeof(WCHAR
));
1594 if (rc
!= ERROR_SUCCESS
)
1603 /* Open the existing driver key */
1605 DriverKey
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
1608 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1612 rc
= RegQueryValueExW(hDeviceKey
, REGSTR_VAL_DRIVER
, NULL
, NULL
, (LPBYTE
)DriverKey
, &dwSize
);
1613 if (rc
!= ERROR_SUCCESS
)
1619 rc
= RegCreateKeyExW(hClassKey
,
1623 REG_OPTION_NON_VOLATILE
,
1624 #if _WIN32_WINNT >= 0x502
1625 KEY_READ
| KEY_WRITE
,
1632 if (rc
!= ERROR_SUCCESS
)
1640 /* Do installation of the specified section */
1643 FIXME("Need to install section %s in file %p\n",
1644 debugstr_w(InfSectionName
), InfHandle
);
1650 RpcStringFreeW(&lpGuidString
);
1651 HeapFree(GetProcessHeap(), 0, DriverKey
);
1652 if (hHWProfileKey
!= INVALID_HANDLE_VALUE
)
1653 RegCloseKey(hHWProfileKey
);
1654 if (hEnumKey
!= NULL
)
1655 RegCloseKey(hEnumKey
);
1656 if (hClassKey
!= NULL
)
1657 RegCloseKey(hClassKey
);
1658 if (hDeviceKey
!= INVALID_HANDLE_VALUE
)
1659 RegCloseKey(hDeviceKey
);
1660 if (hKey
!= NULL
&& hKey
!= key
)
1663 TRACE("Returning 0x%p\n", key
);
1667 /***********************************************************************
1668 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1670 BOOL WINAPI
SetupDiCreateDeviceInfoA(
1671 HDEVINFO DeviceInfoSet
,
1673 CONST GUID
*ClassGuid
,
1674 PCSTR DeviceDescription
,
1676 DWORD CreationFlags
,
1677 PSP_DEVINFO_DATA DeviceInfoData
)
1680 LPWSTR DeviceNameW
= NULL
;
1681 LPWSTR DeviceDescriptionW
= NULL
;
1687 DeviceNameW
= pSetupMultiByteToUnicode(DeviceName
, CP_ACP
);
1688 if (DeviceNameW
== NULL
) return FALSE
;
1690 if (DeviceDescription
)
1692 DeviceDescriptionW
= pSetupMultiByteToUnicode(DeviceDescription
, CP_ACP
);
1693 if (DeviceDescriptionW
== NULL
)
1695 MyFree(DeviceNameW
);
1700 ret
= SetupDiCreateDeviceInfoW(DeviceInfoSet
, DeviceNameW
, ClassGuid
, DeviceDescriptionW
,
1701 hwndParent
, CreationFlags
, DeviceInfoData
);
1703 MyFree(DeviceNameW
);
1704 MyFree(DeviceDescriptionW
);
1709 /***********************************************************************
1710 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1712 BOOL WINAPI
SetupDiCreateDeviceInfoW(
1713 HDEVINFO DeviceInfoSet
,
1715 CONST GUID
*ClassGuid
,
1716 PCWSTR DeviceDescription
,
1718 DWORD CreationFlags
,
1719 PSP_DEVINFO_DATA DeviceInfoData
)
1721 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1722 struct DeviceInfo
*deviceInfo
= NULL
;
1725 DEVINST RootDevInst
;
1727 WCHAR GenInstanceId
[MAX_DEVICE_ID_LEN
];
1729 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet
, debugstr_w(DeviceName
),
1730 debugstr_guid(ClassGuid
), debugstr_w(DeviceDescription
),
1731 hwndParent
, CreationFlags
, DeviceInfoData
);
1735 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1738 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1740 SetLastError(ERROR_INVALID_HANDLE
);
1745 SetLastError(ERROR_INVALID_PARAMETER
);
1748 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1750 SetLastError(ERROR_INVALID_HANDLE
);
1753 if (!IsEqualGUID(&set
->ClassGuid
, &GUID_NULL
) &&
1754 !IsEqualGUID(ClassGuid
, &set
->ClassGuid
))
1756 SetLastError(ERROR_CLASS_MISMATCH
);
1759 if (CreationFlags
& ~(DICD_GENERATE_ID
| DICD_INHERIT_CLASSDRVS
))
1761 TRACE("Unknown flags: 0x%08lx\n", CreationFlags
& ~(DICD_GENERATE_ID
| DICD_INHERIT_CLASSDRVS
));
1762 SetLastError(ERROR_INVALID_FLAGS
);
1766 /* Get the root device instance */
1767 cr
= CM_Locate_DevInst_ExW(&RootDevInst
,
1769 CM_LOCATE_DEVINST_NORMAL
,
1771 if (cr
!= CR_SUCCESS
)
1773 SetLastError(ERROR_INVALID_DATA
);
1777 /* Create the new device instance */
1778 cr
= CM_Create_DevInst_ExW(&DevInst
,
1779 (DEVINSTID
)DeviceName
,
1781 (CreationFlags
& DICD_GENERATE_ID
) ?
1782 CM_CREATE_DEVINST_GENERATE_ID
: 0,
1784 if (cr
!= CR_SUCCESS
)
1786 SetLastError(GetErrorCodeFromCrCode(cr
));
1790 if (CreationFlags
& DICD_GENERATE_ID
)
1792 /* Grab the actual instance ID that was created */
1793 cr
= CM_Get_Device_ID_Ex(DevInst
,
1798 if (cr
!= CR_SUCCESS
)
1800 SetLastError(GetErrorCodeFromCrCode(cr
));
1804 DeviceName
= GenInstanceId
;
1805 TRACE("Using generated instance ID: %s\n", debugstr_w(DeviceName
));
1808 if (CreateDeviceInfo(set
, DeviceName
, ClassGuid
, &deviceInfo
))
1810 InsertTailList(&set
->ListHead
, &deviceInfo
->ListEntry
);
1812 if (!DeviceInfoData
)
1816 if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1818 SetLastError(ERROR_INVALID_USER_BUFFER
);
1822 memcpy(&DeviceInfoData
->ClassGuid
, ClassGuid
, sizeof(GUID
));
1823 DeviceInfoData
->DevInst
= deviceInfo
->dnDevInst
;
1824 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInfo
;
1832 if (deviceInfo
!= NULL
)
1834 /* Remove deviceInfo from List */
1835 RemoveEntryList(&deviceInfo
->ListEntry
);
1837 /* Destroy deviceInfo */
1838 DestroyDeviceInfo(deviceInfo
);
1842 TRACE("Returning %d\n", ret
);
1846 /***********************************************************************
1847 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1849 BOOL WINAPI
SetupDiRegisterDeviceInfo(
1850 HDEVINFO DeviceInfoSet
,
1851 PSP_DEVINFO_DATA DeviceInfoData
,
1853 PSP_DETSIG_CMPPROC CompareProc
,
1854 PVOID CompareContext
,
1855 PSP_DEVINFO_DATA DupDeviceInfoData
)
1857 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1858 WCHAR DevInstId
[MAX_DEVICE_ID_LEN
];
1859 DEVINST ParentDevInst
;
1861 DWORD dwError
= ERROR_SUCCESS
;
1863 TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet
, DeviceInfoData
, Flags
,
1864 CompareProc
, CompareContext
, DupDeviceInfoData
);
1866 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1868 SetLastError(ERROR_INVALID_HANDLE
);
1871 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1873 SetLastError(ERROR_INVALID_HANDLE
);
1876 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1877 || !DeviceInfoData
->Reserved
)
1879 SetLastError(ERROR_INVALID_PARAMETER
);
1883 if (Flags
& ~SPRDI_FIND_DUPS
)
1885 TRACE("Unknown flags: 0x%08lx\n", Flags
& ~SPRDI_FIND_DUPS
);
1886 SetLastError(ERROR_INVALID_FLAGS
);
1890 if (Flags
& SPRDI_FIND_DUPS
)
1892 FIXME("Unimplemented codepath!\n");
1895 CM_Get_Device_ID_Ex(DeviceInfoData
->DevInst
,
1901 CM_Get_Parent_Ex(&ParentDevInst
,
1902 DeviceInfoData
->DevInst
,
1906 cr
= CM_Create_DevInst_Ex(&DeviceInfoData
->DevInst
,
1909 CM_CREATE_DEVINST_NORMAL
| CM_CREATE_DEVINST_DO_NOT_INSTALL
,
1911 if (cr
!= CR_SUCCESS
&&
1912 cr
!= CR_ALREADY_SUCH_DEVINST
)
1914 dwError
= ERROR_NO_SUCH_DEVINST
;
1917 SetLastError(dwError
);
1919 return (dwError
== ERROR_SUCCESS
);
1922 /***********************************************************************
1923 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1925 BOOL WINAPI
SetupDiEnumDeviceInfo(
1928 PSP_DEVINFO_DATA info
)
1932 TRACE("%p %d %p\n", devinfo
, index
, info
);
1936 SetLastError(ERROR_INVALID_PARAMETER
);
1939 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
1941 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
1942 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
1944 if (info
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1945 SetLastError(ERROR_INVALID_USER_BUFFER
);
1948 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
1949 while (ItemList
!= &list
->ListHead
&& index
-- > 0)
1950 ItemList
= ItemList
->Flink
;
1951 if (ItemList
== &list
->ListHead
)
1952 SetLastError(ERROR_NO_MORE_ITEMS
);
1955 struct DeviceInfo
*DevInfo
= CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
1956 memcpy(&info
->ClassGuid
,
1957 &DevInfo
->ClassGuid
,
1959 info
->DevInst
= DevInfo
->dnDevInst
;
1960 info
->Reserved
= (ULONG_PTR
)DevInfo
;
1966 SetLastError(ERROR_INVALID_HANDLE
);
1969 SetLastError(ERROR_INVALID_HANDLE
);
1973 /***********************************************************************
1974 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1976 BOOL WINAPI
SetupDiGetDeviceInstanceIdA(
1977 HDEVINFO DeviceInfoSet
,
1978 PSP_DEVINFO_DATA DeviceInfoData
,
1979 PSTR DeviceInstanceId
,
1980 DWORD DeviceInstanceIdSize
,
1981 PDWORD RequiredSize
)
1987 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1988 DeviceInstanceIdSize
, RequiredSize
);
1990 if (!DeviceInstanceId
&& DeviceInstanceIdSize
> 0)
1992 SetLastError(ERROR_INVALID_PARAMETER
);
1996 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
2001 if (!ret
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
2003 instanceId
= MyMalloc(size
* sizeof(WCHAR
));
2006 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
2013 int len
= WideCharToMultiByte(CP_ACP
, 0, instanceId
, -1,
2015 DeviceInstanceIdSize
, NULL
, NULL
);
2021 if (len
> DeviceInstanceIdSize
)
2023 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2027 *RequiredSize
= len
;
2035 *RequiredSize
= size
;
2036 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2042 /***********************************************************************
2043 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
2045 BOOL WINAPI
SetupDiGetDeviceInstanceIdW(
2046 HDEVINFO DeviceInfoSet
,
2047 PSP_DEVINFO_DATA DeviceInfoData
,
2048 PWSTR DeviceInstanceId
,
2049 DWORD DeviceInstanceIdSize
,
2050 PDWORD RequiredSize
)
2052 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2053 struct DeviceInfo
*devInfo
;
2055 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
2056 DeviceInstanceIdSize
, RequiredSize
);
2058 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2060 SetLastError(ERROR_INVALID_HANDLE
);
2063 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2065 SetLastError(ERROR_INVALID_HANDLE
);
2068 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2069 || !DeviceInfoData
->Reserved
)
2071 SetLastError(ERROR_INVALID_PARAMETER
);
2074 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2075 if (!DeviceInstanceId
&& DeviceInstanceIdSize
> 0)
2077 SetLastError(ERROR_INVALID_PARAMETER
);
2080 if (DeviceInstanceId
&& DeviceInstanceIdSize
== 0)
2082 SetLastError(ERROR_INVALID_PARAMETER
);
2085 TRACE("instance ID: %s\n", debugstr_w(devInfo
->instanceId
));
2086 if (DeviceInstanceIdSize
< lstrlenW(devInfo
->instanceId
) + 1)
2088 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2090 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
2093 lstrcpyW(DeviceInstanceId
, devInfo
->instanceId
);
2095 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
2099 /***********************************************************************
2100 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
2102 BOOL WINAPI
SetupDiGetActualSectionToInstallA(
2104 PCSTR InfSectionName
,
2105 PSTR InfSectionWithExt
,
2106 DWORD InfSectionWithExtSize
,
2107 PDWORD RequiredSize
,
2110 return SetupDiGetActualSectionToInstallExA(InfHandle
, InfSectionName
,
2111 NULL
, InfSectionWithExt
, InfSectionWithExtSize
, RequiredSize
,
2115 /***********************************************************************
2116 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
2118 BOOL WINAPI
SetupDiGetActualSectionToInstallW(
2120 PCWSTR InfSectionName
,
2121 PWSTR InfSectionWithExt
,
2122 DWORD InfSectionWithExtSize
,
2123 PDWORD RequiredSize
,
2126 return SetupDiGetActualSectionToInstallExW(InfHandle
, InfSectionName
,
2127 NULL
, InfSectionWithExt
, InfSectionWithExtSize
, RequiredSize
,
2131 /***********************************************************************
2132 * SetupDiGetActualSectionToInstallExA (SETUPAPI.@)
2135 SetupDiGetActualSectionToInstallExA(
2137 IN PCSTR InfSectionName
,
2138 IN PSP_ALTPLATFORM_INFO AlternatePlatformInfo OPTIONAL
,
2139 OUT PSTR InfSectionWithExt OPTIONAL
,
2140 IN DWORD InfSectionWithExtSize
,
2141 OUT PDWORD RequiredSize OPTIONAL
,
2142 OUT PSTR
* Extension OPTIONAL
,
2145 LPWSTR InfSectionNameW
= NULL
;
2146 LPWSTR InfSectionWithExtW
= NULL
;
2148 BOOL bResult
= FALSE
;
2154 InfSectionNameW
= pSetupMultiByteToUnicode(InfSectionName
, CP_ACP
);
2155 if (InfSectionNameW
== NULL
)
2158 if (InfSectionWithExt
)
2160 InfSectionWithExtW
= MyMalloc(InfSectionWithExtSize
* sizeof(WCHAR
));
2161 if (InfSectionWithExtW
== NULL
)
2165 bResult
= SetupDiGetActualSectionToInstallExW(
2166 InfHandle
, InfSectionNameW
, AlternatePlatformInfo
,
2167 InfSectionWithExt
? InfSectionWithExtW
: NULL
,
2168 InfSectionWithExtSize
,
2170 Extension
? &ExtensionW
: NULL
,
2173 if (bResult
&& InfSectionWithExt
)
2175 bResult
= WideCharToMultiByte(CP_ACP
, 0, InfSectionWithExtW
, -1, InfSectionWithExt
,
2176 InfSectionWithExtSize
, NULL
, NULL
) != 0;
2178 if (bResult
&& Extension
)
2180 if (ExtensionW
== NULL
)
2183 *Extension
= &InfSectionWithExt
[ExtensionW
- InfSectionWithExtW
];
2187 MyFree(InfSectionNameW
);
2188 MyFree(InfSectionWithExtW
);
2193 /***********************************************************************
2194 * SetupDiGetClassDescriptionA (SETUPAPI.@)
2196 BOOL WINAPI
SetupDiGetClassDescriptionA(
2197 const GUID
* ClassGuid
,
2198 PSTR ClassDescription
,
2199 DWORD ClassDescriptionSize
,
2200 PDWORD RequiredSize
)
2202 return SetupDiGetClassDescriptionExA(ClassGuid
, ClassDescription
,
2203 ClassDescriptionSize
,
2204 RequiredSize
, NULL
, NULL
);
2207 /***********************************************************************
2208 * SetupDiGetClassDescriptionW (SETUPAPI.@)
2210 BOOL WINAPI
SetupDiGetClassDescriptionW(
2211 const GUID
* ClassGuid
,
2212 PWSTR ClassDescription
,
2213 DWORD ClassDescriptionSize
,
2214 PDWORD RequiredSize
)
2216 return SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescription
,
2217 ClassDescriptionSize
,
2218 RequiredSize
, NULL
, NULL
);
2221 /***********************************************************************
2222 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
2224 BOOL WINAPI
SetupDiGetClassDescriptionExA(
2225 const GUID
* ClassGuid
,
2226 PSTR ClassDescription
,
2227 DWORD ClassDescriptionSize
,
2228 PDWORD RequiredSize
,
2232 PWCHAR ClassDescriptionW
= NULL
;
2233 LPWSTR MachineNameW
= NULL
;
2236 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassDescription
,
2237 ClassDescriptionSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
2239 if (ClassDescriptionSize
> 0)
2241 ClassDescriptionW
= MyMalloc(ClassDescriptionSize
* sizeof(WCHAR
));
2242 if (!ClassDescriptionW
)
2244 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2251 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
2254 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2259 ret
= SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescriptionW
,
2260 ClassDescriptionSize
* sizeof(WCHAR
), RequiredSize
, MachineNameW
, Reserved
);
2263 DWORD len
= (DWORD
)WideCharToMultiByte(CP_ACP
, 0, ClassDescriptionW
, -1, ClassDescription
,
2264 ClassDescriptionSize
, NULL
, NULL
);
2265 if (len
== 0 || len
> ClassDescriptionSize
)
2267 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2273 MyFree(ClassDescriptionW
);
2274 MyFree(MachineNameW
);
2278 /***********************************************************************
2279 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
2281 BOOL WINAPI
SetupDiGetClassDescriptionExW(
2282 const GUID
* ClassGuid
,
2283 PWSTR ClassDescription
,
2284 DWORD ClassDescriptionSize
,
2285 PDWORD RequiredSize
,
2295 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassDescription
,
2296 ClassDescriptionSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
2298 /* Make sure there's a GUID */
2301 SetLastError(ERROR_INVALID_PARAMETER
);
2305 /* Make sure there's a real buffer when there's a size */
2306 if (!ClassDescription
&& ClassDescriptionSize
> 0)
2308 SetLastError(ERROR_INVALID_PARAMETER
);
2312 /* Open the key for the GUID */
2313 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
2318 if (hKey
== INVALID_HANDLE_VALUE
)
2321 /* Retrieve the class description data and close the key */
2322 rc
= QueryRegistryValue(hKey
, NULL
, (LPBYTE
*) &Buffer
, &dwRegType
, &dwLength
);
2325 /* Make sure we got the data */
2326 if (rc
!= ERROR_SUCCESS
)
2332 /* Make sure the data is a string */
2333 if (dwRegType
!= REG_SZ
)
2336 SetLastError(ERROR_GEN_FAILURE
);
2340 /* Determine the length of the class description */
2341 dwLength
/= sizeof(WCHAR
);
2343 /* Count the null-terminator if none is present */
2344 if ((dwLength
== 0) || (Buffer
[dwLength
- 1] != UNICODE_NULL
))
2347 /* Inform the caller about the class description */
2348 if ((ClassDescription
!= NULL
) && (dwLength
<= ClassDescriptionSize
))
2350 memcpy(ClassDescription
, Buffer
, (dwLength
- 1) * sizeof(WCHAR
));
2351 ClassDescription
[dwLength
- 1] = UNICODE_NULL
;
2354 /* Inform the caller about the required size */
2355 if (RequiredSize
!= NULL
)
2356 *RequiredSize
= dwLength
;
2358 /* Clean up the buffer */
2361 /* Make sure the buffer was large enough */
2362 if ((ClassDescription
== NULL
) || (dwLength
> ClassDescriptionSize
))
2364 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2371 /***********************************************************************
2372 * SetupDiGetClassDevsA (SETUPAPI.@)
2374 HDEVINFO WINAPI
SetupDiGetClassDevsA(
2380 return SetupDiGetClassDevsExA(class, enumstr
, parent
,
2381 flags
, NULL
, NULL
, NULL
);
2384 /***********************************************************************
2385 * SetupDiGetClassDevsExA (SETUPAPI.@)
2387 HDEVINFO WINAPI
SetupDiGetClassDevsExA(
2397 LPWSTR enumstrW
= NULL
, machineW
= NULL
;
2401 enumstrW
= pSetupMultiByteToUnicode(enumstr
, CP_ACP
);
2404 ret
= INVALID_HANDLE_VALUE
;
2410 machineW
= pSetupMultiByteToUnicode(machine
, CP_ACP
);
2414 ret
= INVALID_HANDLE_VALUE
;
2418 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, deviceset
,
2419 machineW
, reserved
);
2427 /***********************************************************************
2428 * SetupDiGetClassDevsW (SETUPAPI.@)
2430 HDEVINFO WINAPI
SetupDiGetClassDevsW(
2436 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2440 /***********************************************************************
2441 * SetupDiGetClassDevsExW (SETUPAPI.@)
2443 HDEVINFO WINAPI
SetupDiGetClassDevsExW(
2452 HDEVINFO hDeviceInfo
= INVALID_HANDLE_VALUE
;
2453 struct DeviceInfoSet
*list
;
2454 CONST GUID
*pClassGuid
;
2456 HDEVINFO set
= INVALID_HANDLE_VALUE
;
2458 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2459 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2462 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2464 SetLastError(ERROR_INVALID_PARAMETER
);
2465 return INVALID_HANDLE_VALUE
;
2468 /* Create the deviceset if not set */
2471 list
= (struct DeviceInfoSet
*)deviceset
;
2472 if (list
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2474 SetLastError(ERROR_INVALID_HANDLE
);
2477 hDeviceInfo
= deviceset
;
2481 hDeviceInfo
= SetupDiCreateDeviceInfoListExW(
2482 flags
& (DIGCF_DEVICEINTERFACE
| DIGCF_ALLCLASSES
) ? NULL
: class,
2483 NULL
, machine
, NULL
);
2484 if (hDeviceInfo
== INVALID_HANDLE_VALUE
)
2486 list
= (struct DeviceInfoSet
*)hDeviceInfo
;
2489 if (flags
& DIGCF_PROFILE
)
2490 FIXME(": flag DIGCF_PROFILE ignored\n");
2492 if (flags
& DIGCF_DEVICEINTERFACE
)
2496 SetLastError(ERROR_INVALID_PARAMETER
);
2499 rc
= SETUP_CreateInterfaceList(list
, machine
, class, enumstr
, flags
& DIGCF_PRESENT
);
2503 /* Determine which class(es) should be included in the deviceset */
2504 if (flags
& DIGCF_ALLCLASSES
)
2506 /* The caller wants all classes. Check if
2507 * the deviceset limits us to one class */
2508 if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2511 pClassGuid
= &list
->ClassGuid
;
2515 /* The caller wants one class. Check if it matches deviceset class */
2516 if (IsEqualIID(&list
->ClassGuid
, class)
2517 || IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2523 SetLastError(ERROR_INVALID_PARAMETER
);
2527 else if (!IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2529 /* No class specified. Try to use the one of the deviceset */
2530 if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2531 pClassGuid
= &list
->ClassGuid
;
2534 SetLastError(ERROR_INVALID_PARAMETER
);
2540 SetLastError(ERROR_INVALID_PARAMETER
);
2543 rc
= SETUP_CreateDevicesList(list
, machine
, pClassGuid
, enumstr
);
2545 if (rc
!= ERROR_SUCCESS
)
2553 if (!deviceset
&& hDeviceInfo
!= INVALID_HANDLE_VALUE
&& hDeviceInfo
!= set
)
2554 SetupDiDestroyDeviceInfoList(hDeviceInfo
);
2558 /***********************************************************************
2559 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2561 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2562 HDEVINFO DeviceInfoSet
,
2563 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2565 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2567 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2569 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2571 SetLastError(ERROR_INVALID_HANDLE
);
2574 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2576 SetLastError(ERROR_INVALID_HANDLE
);
2580 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2582 SetLastError(ERROR_INVALID_PARAMETER
);
2585 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2586 DevInfoData
->RemoteMachineHandle
= set
->hMachine
;
2587 if (set
->MachineName
)
2590 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2594 DevInfoData
->RemoteMachineName
[0] = 0;
2599 /***********************************************************************
2600 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2602 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2603 HDEVINFO DeviceInfoSet
,
2604 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2606 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2608 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2610 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2612 SetLastError(ERROR_INVALID_HANDLE
);
2615 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2617 SetLastError(ERROR_INVALID_HANDLE
);
2621 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2623 SetLastError(ERROR_INVALID_PARAMETER
);
2626 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2627 DevInfoData
->RemoteMachineHandle
= set
->hMachine
;
2628 if (set
->MachineName
)
2629 strcpyW(DevInfoData
->RemoteMachineName
, set
->MachineName
+ 2);
2631 DevInfoData
->RemoteMachineName
[0] = 0;
2636 /***********************************************************************
2637 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2639 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2640 HDEVINFO DeviceInfoSet
,
2641 PSP_DEVINFO_DATA DeviceInfoData
,
2642 const GUID
*InterfaceClassGuid
,
2643 PCSTR ReferenceString
,
2644 DWORD CreationFlags
,
2645 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2648 LPWSTR ReferenceStringW
= NULL
;
2650 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2651 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2652 CreationFlags
, DeviceInterfaceData
);
2654 if (ReferenceString
)
2656 ReferenceStringW
= pSetupMultiByteToUnicode(ReferenceString
, CP_ACP
);
2657 if (ReferenceStringW
== NULL
) return FALSE
;
2660 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2661 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2662 DeviceInterfaceData
);
2664 MyFree(ReferenceStringW
);
2669 /***********************************************************************
2670 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2672 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2673 HDEVINFO DeviceInfoSet
,
2674 PSP_DEVINFO_DATA DeviceInfoData
,
2675 const GUID
*InterfaceClassGuid
,
2676 PCWSTR ReferenceString
,
2677 DWORD CreationFlags
,
2678 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2680 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2681 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2682 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2683 CreationFlags
, DeviceInterfaceData
);
2685 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2687 SetLastError(ERROR_INVALID_HANDLE
);
2690 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2692 SetLastError(ERROR_INVALID_HANDLE
);
2695 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2696 || !DeviceInfoData
->Reserved
)
2698 SetLastError(ERROR_INVALID_PARAMETER
);
2701 if (!InterfaceClassGuid
)
2703 SetLastError(ERROR_INVALID_USER_BUFFER
);
2707 FIXME("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2708 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2709 CreationFlags
, DeviceInterfaceData
);
2710 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2714 /***********************************************************************
2715 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2717 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2718 HDEVINFO DeviceInfoSet
,
2719 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2723 PCSTR InfSectionName
)
2726 PWSTR InfSectionNameW
= NULL
;
2728 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2729 samDesired
, InfHandle
, InfSectionName
);
2732 if (!InfSectionName
)
2734 SetLastError(ERROR_INVALID_PARAMETER
);
2735 return INVALID_HANDLE_VALUE
;
2737 InfSectionNameW
= pSetupMultiByteToUnicode(InfSectionName
, CP_ACP
);
2738 if (!InfSectionNameW
)
2739 return INVALID_HANDLE_VALUE
;
2741 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2742 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2744 MyFree(InfSectionNameW
);
2748 /***********************************************************************
2749 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2751 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2752 HDEVINFO DeviceInfoSet
,
2753 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2757 PCWSTR InfSectionName
)
2760 LPWSTR SymbolicLink
;
2761 DWORD Length
, Index
;
2763 WCHAR bracedGuidString
[39];
2764 struct DeviceInterface
*DevItf
;
2765 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2767 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2768 samDesired
, InfHandle
, InfSectionName
);
2770 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2771 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2773 SetLastError(ERROR_INVALID_HANDLE
);
2774 return INVALID_HANDLE_VALUE
;
2776 if (!DeviceInterfaceData
||
2777 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2778 !DeviceInterfaceData
->Reserved
)
2780 SetLastError(ERROR_INVALID_PARAMETER
);
2781 return INVALID_HANDLE_VALUE
;
2783 if (InfHandle
&& !InfSectionName
)
2785 SetLastError(ERROR_INVALID_PARAMETER
);
2786 return INVALID_HANDLE_VALUE
;
2789 hKey
= SetupDiOpenClassRegKeyExW(&DeviceInterfaceData
->InterfaceClassGuid
, samDesired
, DIOCR_INTERFACE
, NULL
, NULL
);
2790 if (hKey
== INVALID_HANDLE_VALUE
)
2792 hKey
= SetupDiOpenClassRegKeyExW(NULL
, samDesired
, DIOCR_INTERFACE
, NULL
, NULL
);
2793 if (hKey
== INVALID_HANDLE_VALUE
)
2795 SetLastError(ERROR_INVALID_PARAMETER
);
2796 return INVALID_HANDLE_VALUE
;
2798 SETUPDI_GuidToString(&DeviceInterfaceData
->InterfaceClassGuid
, bracedGuidString
);
2800 if (RegCreateKeyExW(hKey
, bracedGuidString
, 0, NULL
, 0, samDesired
, NULL
, &hDevKey
, NULL
) != ERROR_SUCCESS
)
2802 SetLastError(ERROR_INVALID_PARAMETER
);
2803 return INVALID_HANDLE_VALUE
;
2809 DevItf
= (struct DeviceInterface
*)DeviceInterfaceData
->Reserved
;
2811 Length
= (wcslen(DevItf
->SymbolicLink
)+1) * sizeof(WCHAR
);
2812 SymbolicLink
= HeapAlloc(GetProcessHeap(), 0, Length
);
2816 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2817 return INVALID_HANDLE_VALUE
;
2820 wcscpy(SymbolicLink
, DevItf
->SymbolicLink
);
2823 while(SymbolicLink
[Index
])
2825 if (SymbolicLink
[Index
] == L
'\\')
2827 SymbolicLink
[Index
] = L
'#';
2832 rc
= RegCreateKeyExW(hKey
, SymbolicLink
, 0, NULL
, 0, samDesired
, NULL
, &hDevKey
, NULL
);
2835 HeapFree(GetProcessHeap(), 0, SymbolicLink
);
2837 if (rc
== ERROR_SUCCESS
)
2839 if (InfHandle
&& InfSectionName
)
2841 if (!SetupInstallFromInfSection(NULL
/*FIXME */,
2844 SPINST_INIFILES
| SPINST_REGISTRY
| SPINST_INI2REG
| SPINST_FILES
| SPINST_BITREG
| SPINST_REGSVR
| SPINST_UNREGSVR
| SPINST_PROFILEITEMS
| SPINST_COPYINF
,
2848 set
->SelectedDevice
->InstallParams
.InstallMsgHandler
,
2849 set
->SelectedDevice
->InstallParams
.InstallMsgHandlerContext
,
2850 INVALID_HANDLE_VALUE
,
2853 RegCloseKey(hDevKey
);
2854 return INVALID_HANDLE_VALUE
;
2863 /***********************************************************************
2864 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2866 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2867 HDEVINFO DeviceInfoSet
,
2868 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2871 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2874 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2876 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2877 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2879 SetLastError(ERROR_INVALID_HANDLE
);
2882 if (!DeviceInterfaceData
||
2883 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2884 !DeviceInterfaceData
->Reserved
)
2886 SetLastError(ERROR_INVALID_PARAMETER
);
2890 FIXME("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2891 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2895 /***********************************************************************
2896 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2899 * DeviceInfoSet [I] Set of devices from which to enumerate
2901 * DeviceInfoData [I] (Optional) If specified, a specific device
2902 * instance from which to enumerate interfaces.
2903 * If it isn't specified, all interfaces for all
2904 * devices in the set are enumerated.
2905 * InterfaceClassGuid [I] The interface class to enumerate.
2906 * MemberIndex [I] An index of the interface instance to enumerate.
2907 * A caller should start with MemberIndex set to 0,
2908 * and continue until the function fails with
2909 * ERROR_NO_MORE_ITEMS.
2910 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2911 * member must be set to
2912 * sizeof(SP_DEVICE_INTERFACE_DATA).
2915 * Success: non-zero value.
2916 * Failure: FALSE. Call GetLastError() for more info.
2918 BOOL WINAPI
SetupDiEnumDeviceInterfaces(
2919 HDEVINFO DeviceInfoSet
,
2920 PSP_DEVINFO_DATA DeviceInfoData
,
2921 CONST GUID
* InterfaceClassGuid
,
2923 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2925 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2928 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet
, DeviceInfoData
,
2929 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
2931 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2932 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2934 SetLastError(ERROR_INVALID_HANDLE
);
2937 if (DeviceInfoData
&& (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2938 !DeviceInfoData
->Reserved
))
2940 SetLastError(ERROR_INVALID_PARAMETER
);
2943 if (!DeviceInterfaceData
||
2944 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2946 SetLastError(ERROR_INVALID_PARAMETER
);
2951 struct DeviceInfo
*devInfo
=
2952 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2954 PLIST_ENTRY InterfaceListEntry
= devInfo
->InterfaceListHead
.Flink
;
2955 while (InterfaceListEntry
!= &devInfo
->InterfaceListHead
&& !found
)
2957 struct DeviceInterface
*DevItf
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
2958 if (!IsEqualIID(&DevItf
->InterfaceClassGuid
, InterfaceClassGuid
))
2960 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2963 if (MemberIndex
-- == 0)
2965 /* return this item */
2966 memcpy(&DeviceInterfaceData
->InterfaceClassGuid
,
2967 &DevItf
->InterfaceClassGuid
,
2969 DeviceInterfaceData
->Flags
= DevItf
->Flags
;
2970 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)DevItf
;
2974 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2977 SetLastError(ERROR_NO_MORE_ITEMS
);
2982 PLIST_ENTRY ItemList
= set
->ListHead
.Flink
;
2983 while (ItemList
!= &set
->ListHead
&& !found
)
2985 PLIST_ENTRY InterfaceListEntry
;
2986 struct DeviceInfo
*devInfo
=
2987 CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
2988 InterfaceListEntry
= devInfo
->InterfaceListHead
.Flink
;
2989 while (InterfaceListEntry
!= &devInfo
->InterfaceListHead
&& !found
)
2991 struct DeviceInterface
*DevItf
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
2992 if (!IsEqualIID(&DevItf
->InterfaceClassGuid
, InterfaceClassGuid
))
2994 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2997 if (MemberIndex
-- == 0)
2999 /* return this item */
3000 memcpy(&DeviceInterfaceData
->InterfaceClassGuid
,
3001 &DevItf
->InterfaceClassGuid
,
3003 DeviceInterfaceData
->Flags
= DevItf
->Flags
;
3004 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)DevItf
;
3008 InterfaceListEntry
= InterfaceListEntry
->Flink
;
3010 ItemList
= ItemList
->Flink
;
3014 SetLastError(ERROR_NO_MORE_ITEMS
);
3019 /***********************************************************************
3020 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
3022 * Destroy a DeviceInfoList and free all used memory of the list.
3025 * devinfo [I] DeviceInfoList pointer to list to destroy
3028 * Success: non zero value.
3029 * Failure: zero value.
3031 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
3035 TRACE("%p\n", devinfo
);
3036 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
3038 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
3040 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
3042 ret
= DestroyDeviceInfoSet(list
);
3047 SetLastError(ERROR_INVALID_HANDLE
);
3052 /***********************************************************************
3053 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
3055 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
3056 HDEVINFO DeviceInfoSet
,
3057 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
3058 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
3059 DWORD DeviceInterfaceDetailDataSize
,
3060 PDWORD RequiredSize
,
3061 PSP_DEVINFO_DATA DeviceInfoData
)
3063 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3064 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailDataW
= NULL
;
3065 DWORD sizeW
= 0, bytesNeeded
;
3068 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
3069 DeviceInterfaceData
, DeviceInterfaceDetailData
,
3070 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
3072 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
3073 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3075 SetLastError(ERROR_INVALID_HANDLE
);
3078 if (!DeviceInterfaceData
||
3079 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
3080 !DeviceInterfaceData
->Reserved
)
3082 SetLastError(ERROR_INVALID_PARAMETER
);
3085 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
)))
3087 SetLastError(ERROR_INVALID_USER_BUFFER
);
3091 if((DeviceInterfaceDetailDataSize
!= 0) &&
3092 (DeviceInterfaceDetailDataSize
< (FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + sizeof(CHAR
))))
3094 SetLastError(ERROR_INVALID_USER_BUFFER
);
3098 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
3100 SetLastError(ERROR_INVALID_USER_BUFFER
);
3105 if (DeviceInterfaceDetailData
!= NULL
)
3107 sizeW
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
3108 + (DeviceInterfaceDetailDataSize
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
)) * sizeof(WCHAR
);
3109 DeviceInterfaceDetailDataW
= (PSP_DEVICE_INTERFACE_DETAIL_DATA_W
)MyMalloc(sizeW
);
3110 if (!DeviceInterfaceDetailDataW
)
3112 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3114 DeviceInterfaceDetailDataW
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
);
3116 if (!DeviceInterfaceDetailData
|| (DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataW
))
3118 ret
= SetupDiGetDeviceInterfaceDetailW(
3120 DeviceInterfaceData
,
3121 DeviceInterfaceDetailDataW
,
3125 bytesNeeded
= (sizeW
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)) / sizeof(WCHAR
)
3126 + FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
);
3128 *RequiredSize
= bytesNeeded
;
3129 if (ret
&& DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
>= bytesNeeded
)
3131 if (!WideCharToMultiByte(
3133 DeviceInterfaceDetailDataW
->DevicePath
, -1,
3134 DeviceInterfaceDetailData
->DevicePath
, DeviceInterfaceDetailDataSize
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
3141 MyFree(DeviceInterfaceDetailDataW
);
3146 /***********************************************************************
3147 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
3149 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
3150 HDEVINFO DeviceInfoSet
,
3151 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
3152 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
3153 DWORD DeviceInterfaceDetailDataSize
,
3154 PDWORD RequiredSize
,
3155 PSP_DEVINFO_DATA DeviceInfoData
)
3157 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3160 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
3161 DeviceInterfaceData
, DeviceInterfaceDetailData
,
3162 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
3164 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
3165 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3167 SetLastError(ERROR_INVALID_HANDLE
);
3170 if (!DeviceInterfaceData
||
3171 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
3172 !DeviceInterfaceData
->Reserved
)
3174 SetLastError(ERROR_INVALID_PARAMETER
);
3177 if (DeviceInterfaceDetailData
&& DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
))
3179 SetLastError(ERROR_INVALID_USER_BUFFER
);
3182 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
3184 SetLastError(ERROR_INVALID_USER_BUFFER
);
3187 if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
3189 SetLastError(ERROR_INVALID_PARAMETER
);
3192 if ((DeviceInterfaceDetailData
!= NULL
)
3193 && (DeviceInterfaceDetailDataSize
< (FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)) + sizeof(WCHAR
)))
3195 SetLastError(ERROR_INVALID_PARAMETER
);
3200 struct DeviceInterface
*deviceInterface
= (struct DeviceInterface
*)DeviceInterfaceData
->Reserved
;
3201 LPCWSTR devName
= deviceInterface
->SymbolicLink
;
3202 DWORD sizeRequired
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
) +
3203 (lstrlenW(devName
) + 1) * sizeof(WCHAR
);
3205 if (sizeRequired
> DeviceInterfaceDetailDataSize
)
3207 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3209 *RequiredSize
= sizeRequired
;
3213 strcpyW(DeviceInterfaceDetailData
->DevicePath
, devName
);
3214 TRACE("DevicePath is %s\n", debugstr_w(DeviceInterfaceDetailData
->DevicePath
));
3217 memcpy(&DeviceInfoData
->ClassGuid
,
3218 &deviceInterface
->DeviceInfo
->ClassGuid
,
3220 DeviceInfoData
->DevInst
= deviceInterface
->DeviceInfo
->dnDevInst
;
3221 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInterface
->DeviceInfo
;
3229 struct PropertyMapEntry
3236 static struct PropertyMapEntry PropertyMap
[] = {
3237 { REG_SZ
, "DeviceDesc", REGSTR_VAL_DEVDESC
},
3238 { REG_MULTI_SZ
, "HardwareId", REGSTR_VAL_HARDWAREID
},
3239 { REG_MULTI_SZ
, "CompatibleIDs", REGSTR_VAL_COMPATIBLEIDS
},
3240 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
3241 { REG_SZ
, "Service", REGSTR_VAL_SERVICE
},
3242 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
3243 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
3244 { REG_SZ
, "Class", REGSTR_VAL_CLASS
},
3245 { REG_SZ
, "ClassGUID", REGSTR_VAL_CLASSGUID
},
3246 { REG_SZ
, "Driver", REGSTR_VAL_DRIVER
},
3247 { REG_DWORD
, "ConfigFlags", REGSTR_VAL_CONFIGFLAGS
},
3248 { REG_SZ
, "Mfg", REGSTR_VAL_MFG
},
3249 { REG_SZ
, "FriendlyName", REGSTR_VAL_FRIENDLYNAME
},
3250 { REG_SZ
, "LocationInformation", REGSTR_VAL_LOCATION_INFORMATION
},
3251 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3252 { REG_DWORD
, "Capabilities", REGSTR_VAL_CAPABILITIES
},
3253 { REG_DWORD
, "UINumber", REGSTR_VAL_UI_NUMBER
},
3254 { REG_MULTI_SZ
, "UpperFilters", REGSTR_VAL_UPPERFILTERS
},
3255 { REG_MULTI_SZ
, "LowerFilters", REGSTR_VAL_LOWERFILTERS
},
3256 { 0, NULL
, NULL
}, /* SPDRP_BUSTYPEGUID */
3257 { 0, NULL
, NULL
}, /* SPDRP_LEGACYBUSTYPE */
3258 { 0, NULL
, NULL
}, /* SPDRP_BUSNUMBER */
3259 { 0, NULL
, NULL
}, /* SPDRP_ENUMERATOR_NAME */
3260 { REG_BINARY
, "Security", REGSTR_SECURITY
},
3261 { 0, NULL
, NULL
}, /* SPDRP_SECURITY_SDS */
3262 { 0, NULL
, NULL
}, /* SPDRP_DEVTYPE */
3263 { 0, NULL
, NULL
}, /* SPDRP_EXCLUSIVE */
3264 { 0, NULL
, NULL
}, /* SPDRP_CHARACTERISTICS */
3265 { 0, NULL
, NULL
}, /* SPDRP_ADDRESS */
3266 { REG_SZ
, "UINumberDescFormat", REGSTR_UI_NUMBER_DESC_FORMAT
},
3267 { 0, NULL
, NULL
}, /* SPDRP_DEVICE_POWER_DATA */
3268 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY */
3269 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY_HW_DEFAULT */
3270 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY_OVERRIDE */
3271 { 0, NULL
, NULL
}, /* SPDRP_INSTALL_STATE */
3274 /***********************************************************************
3275 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3277 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
3278 HDEVINFO DeviceInfoSet
,
3279 PSP_DEVINFO_DATA DeviceInfoData
,
3281 PDWORD PropertyRegDataType
,
3282 PBYTE PropertyBuffer
,
3283 DWORD PropertyBufferSize
,
3284 PDWORD RequiredSize
)
3287 BOOL bIsStringProperty
;
3289 DWORD RequiredSizeA
, RequiredSizeW
;
3290 DWORD PropertyBufferSizeW
= 0;
3291 PBYTE PropertyBufferW
= NULL
;
3293 TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
,
3294 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3297 if (PropertyBufferSize
!= 0)
3299 PropertyBufferSizeW
= PropertyBufferSize
* 2;
3300 PropertyBufferW
= HeapAlloc(GetProcessHeap(), 0, PropertyBufferSizeW
);
3301 if (!PropertyBufferW
)
3303 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3308 ret
= SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet
,
3313 PropertyBufferSizeW
,
3316 if (ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
3318 bIsStringProperty
= (RegType
== REG_SZ
|| RegType
== REG_MULTI_SZ
|| RegType
== REG_EXPAND_SZ
);
3320 if (bIsStringProperty
)
3321 RequiredSizeA
= RequiredSizeW
/ sizeof(WCHAR
);
3323 RequiredSizeA
= RequiredSizeW
;
3325 *RequiredSize
= RequiredSizeA
;
3326 if (PropertyRegDataType
)
3327 *PropertyRegDataType
= RegType
;
3332 HeapFree(GetProcessHeap(), 0, PropertyBufferW
);
3336 if (RequiredSizeA
<= PropertyBufferSize
)
3338 if (bIsStringProperty
&& PropertyBufferSize
> 0)
3340 if (WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)PropertyBufferW
, RequiredSizeW
/ sizeof(WCHAR
), (LPSTR
)PropertyBuffer
, PropertyBufferSize
, NULL
, NULL
) == 0)
3342 /* Last error is already set by WideCharToMultiByte */
3347 memcpy(PropertyBuffer
, PropertyBufferW
, RequiredSizeA
);
3351 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3355 HeapFree(GetProcessHeap(), 0, PropertyBufferW
);
3359 /***********************************************************************
3360 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3362 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3363 HDEVINFO DeviceInfoSet
,
3364 PSP_DEVINFO_DATA DeviceInfoData
,
3366 PDWORD PropertyRegDataType
,
3367 PBYTE PropertyBuffer
,
3368 DWORD PropertyBufferSize
,
3369 PDWORD RequiredSize
)
3371 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3372 struct DeviceInfo
*devInfo
;
3374 LONG lError
= ERROR_SUCCESS
;
3377 TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
,
3378 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3381 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3383 SetLastError(ERROR_INVALID_HANDLE
);
3386 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3388 SetLastError(ERROR_INVALID_HANDLE
);
3391 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3392 || !DeviceInfoData
->Reserved
)
3394 SetLastError(ERROR_INVALID_PARAMETER
);
3398 if (Property
>= SPDRP_MAXIMUM_PROPERTY
)
3400 SetLastError(ERROR_INVALID_REG_PROPERTY
);
3404 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3406 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3407 && PropertyMap
[Property
].nameW
)
3410 size
= PropertyBufferSize
;
3411 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_QUERY_VALUE
);
3412 if (hKey
== INVALID_HANDLE_VALUE
)
3414 lError
= RegQueryValueExW(hKey
, PropertyMap
[Property
].nameW
,
3415 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3419 *RequiredSize
= size
;
3424 if (PropertyBuffer
== NULL
&& size
!= 0)
3425 lError
= ERROR_INSUFFICIENT_BUFFER
;
3427 case ERROR_MORE_DATA
:
3428 lError
= ERROR_INSUFFICIENT_BUFFER
;
3434 else if (Property
== SPDRP_PHYSICAL_DEVICE_OBJECT_NAME
)
3436 size
= (strlenW(devInfo
->Data
) + 1) * sizeof(WCHAR
);
3438 if (PropertyRegDataType
)
3439 *PropertyRegDataType
= REG_SZ
;
3441 *RequiredSize
= size
;
3442 if (PropertyBufferSize
>= size
)
3444 strcpyW((LPWSTR
)PropertyBuffer
, devInfo
->Data
);
3447 lError
= ERROR_INSUFFICIENT_BUFFER
;
3451 size
= PropertyBufferSize
;
3453 cr
= CM_Get_DevNode_Registry_Property_ExW(devInfo
->dnDevInst
,
3454 Property
+ (CM_DRP_DEVICEDESC
- SPDRP_DEVICEDESC
),
3455 PropertyRegDataType
,
3460 if ((cr
== CR_SUCCESS
) || (cr
== CR_BUFFER_SMALL
))
3463 *RequiredSize
= size
;
3466 if (cr
!= CR_SUCCESS
)
3470 case CR_INVALID_DEVINST
:
3471 lError
= ERROR_NO_SUCH_DEVINST
;
3474 case CR_INVALID_PROPERTY
:
3475 lError
= ERROR_INVALID_REG_PROPERTY
;
3478 case CR_BUFFER_SMALL
:
3479 lError
= ERROR_INSUFFICIENT_BUFFER
;
3483 lError
= ERROR_INVALID_DATA
;
3489 SetLastError(lError
);
3490 return (lError
== ERROR_SUCCESS
);
3493 /***********************************************************************
3494 * Internal for SetupDiSetDeviceRegistryPropertyA/W
3496 BOOL WINAPI
IntSetupDiSetDeviceRegistryPropertyAW(
3497 HDEVINFO DeviceInfoSet
,
3498 PSP_DEVINFO_DATA DeviceInfoData
,
3500 const BYTE
*PropertyBuffer
,
3501 DWORD PropertyBufferSize
,
3505 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3507 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3508 PropertyBuffer
, PropertyBufferSize
);
3510 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3512 SetLastError(ERROR_INVALID_HANDLE
);
3515 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3517 SetLastError(ERROR_INVALID_HANDLE
);
3520 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3521 || !DeviceInfoData
->Reserved
)
3523 SetLastError(ERROR_INVALID_PARAMETER
);
3526 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3527 && PropertyMap
[Property
].nameW
3528 && PropertyMap
[Property
].nameA
)
3532 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_SET_VALUE
);
3533 if (hKey
== INVALID_HANDLE_VALUE
)
3535 /* Write new data */
3539 hKey
, PropertyMap
[Property
].nameA
, 0,
3540 PropertyMap
[Property
].regType
, PropertyBuffer
,
3541 PropertyBufferSize
);
3546 hKey
, PropertyMap
[Property
].nameW
, 0,
3547 PropertyMap
[Property
].regType
, PropertyBuffer
,
3548 PropertyBufferSize
);
3558 ERR("Property 0x%lx not implemented\n", Property
);
3559 SetLastError(ERROR_NOT_SUPPORTED
);
3562 TRACE("Returning %d\n", ret
);
3565 /***********************************************************************
3566 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3568 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3569 HDEVINFO DeviceInfoSet
,
3570 PSP_DEVINFO_DATA DeviceInfoData
,
3572 const BYTE
*PropertyBuffer
,
3573 DWORD PropertyBufferSize
)
3575 return IntSetupDiSetDeviceRegistryPropertyAW(DeviceInfoSet
,
3583 /***********************************************************************
3584 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3586 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
3587 HDEVINFO DeviceInfoSet
,
3588 PSP_DEVINFO_DATA DeviceInfoData
,
3590 const BYTE
*PropertyBuffer
,
3591 DWORD PropertyBufferSize
)
3593 return IntSetupDiSetDeviceRegistryPropertyAW(DeviceInfoSet
,
3601 /***********************************************************************
3602 * SetupDiInstallClassA (SETUPAPI.@)
3604 BOOL WINAPI
SetupDiInstallClassA(
3610 return SetupDiInstallClassExA(hwndParent
, InfFileName
, Flags
, FileQueue
, NULL
, NULL
, NULL
);
3613 /***********************************************************************
3614 * SetupDiInstallClassExA (SETUPAPI.@)
3617 SetupDiInstallClassExA(
3618 IN HWND hwndParent OPTIONAL
,
3619 IN PCSTR InfFileName OPTIONAL
,
3621 IN HSPFILEQ FileQueue OPTIONAL
,
3622 IN CONST GUID
*InterfaceClassGuid OPTIONAL
,
3626 PWSTR InfFileNameW
= NULL
;
3631 SetLastError(ERROR_INVALID_PARAMETER
);
3636 InfFileNameW
= pSetupMultiByteToUnicode(InfFileName
, CP_ACP
);
3637 if (InfFileNameW
== NULL
)
3639 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3644 Result
= SetupDiInstallClassExW(hwndParent
, InfFileNameW
, Flags
,
3645 FileQueue
, InterfaceClassGuid
, Reserved1
, Reserved2
);
3647 MyFree(InfFileNameW
);
3652 HKEY
SETUP_CreateClassKey(HINF hInf
)
3654 WCHAR FullBuffer
[MAX_PATH
];
3655 WCHAR Buffer
[MAX_PATH
];
3660 /* Obtain the Class GUID for this class */
3661 if (!SetupGetLineTextW(NULL
,
3664 REGSTR_VAL_CLASSGUID
,
3666 sizeof(Buffer
) / sizeof(WCHAR
),
3669 return INVALID_HANDLE_VALUE
;
3672 /* Build the corresponding registry key name */
3673 lstrcpyW(FullBuffer
, REGSTR_PATH_CLASS_NT
);
3674 lstrcatW(FullBuffer
, BackSlash
);
3675 lstrcatW(FullBuffer
, Buffer
);
3677 /* Obtain the Class name for this class */
3678 if (!SetupGetLineTextW(NULL
,
3683 sizeof(Buffer
) / sizeof(WCHAR
),
3686 return INVALID_HANDLE_VALUE
;
3689 /* Try to open or create the registry key */
3690 TRACE("Opening class key %s\n", debugstr_w(FullBuffer
));
3691 #if 0 // I keep this for reference...
3692 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3698 /* Use RegCreateKeyExW */
3701 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3705 REG_OPTION_NON_VOLATILE
,
3711 ERR("RegCreateKeyExW(%s) failed\n", debugstr_w(FullBuffer
));
3712 return INVALID_HANDLE_VALUE
;
3714 if (Disposition
== REG_CREATED_NEW_KEY
)
3715 TRACE("The class key %s was successfully created\n", debugstr_w(FullBuffer
));
3717 TRACE("The class key %s was successfully opened\n", debugstr_w(FullBuffer
));
3719 TRACE( "setting value %s to %s\n", debugstr_w(REGSTR_VAL_CLASS
), debugstr_w(Buffer
) );
3720 if (RegSetValueExW(hClassKey
,
3725 RequiredSize
* sizeof(WCHAR
)))
3727 RegCloseKey(hClassKey
);
3728 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3730 return INVALID_HANDLE_VALUE
;
3736 /***********************************************************************
3737 * SetupDiInstallClassW (SETUPAPI.@)
3739 BOOL WINAPI
SetupDiInstallClassW(
3745 return SetupDiInstallClassExW(hwndParent
, InfFileName
, Flags
, FileQueue
, NULL
, NULL
, NULL
);
3749 /***********************************************************************
3750 * SetupDiOpenClassRegKey (SETUPAPI.@)
3752 HKEY WINAPI
SetupDiOpenClassRegKey(
3753 const GUID
* ClassGuid
,
3756 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3757 DIOCR_INSTALLER
, NULL
, NULL
);
3761 /***********************************************************************
3762 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3764 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3765 const GUID
* ClassGuid
,
3771 PWSTR MachineNameW
= NULL
;
3774 TRACE("%s 0x%lx 0x%lx %s %p\n", debugstr_guid(ClassGuid
), samDesired
,
3775 Flags
, debugstr_a(MachineName
), Reserved
);
3779 MachineNameW
= pSetupMultiByteToUnicode(MachineName
, CP_ACP
);
3780 if (MachineNameW
== NULL
)
3781 return INVALID_HANDLE_VALUE
;
3784 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3785 Flags
, MachineNameW
, Reserved
);
3787 MyFree(MachineNameW
);
3793 /***********************************************************************
3794 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3796 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3797 const GUID
* ClassGuid
,
3809 TRACE("%s 0x%lx 0x%lx %s %p\n", debugstr_guid(ClassGuid
), samDesired
,
3810 Flags
, debugstr_w(MachineName
), Reserved
);
3812 if (MachineName
!= NULL
)
3814 l
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &HKLM
);
3815 if (l
!= ERROR_SUCCESS
)
3818 return INVALID_HANDLE_VALUE
;
3822 HKLM
= HKEY_LOCAL_MACHINE
;
3824 if (Flags
== DIOCR_INSTALLER
)
3826 lpKeyName
= REGSTR_PATH_CLASS_NT
;
3828 else if (Flags
== DIOCR_INTERFACE
)
3830 lpKeyName
= REGSTR_PATH_DEVICE_CLASSES
;
3834 ERR("Invalid Flags parameter!\n");
3835 SetLastError(ERROR_INVALID_FLAGS
);
3836 if (MachineName
!= NULL
) RegCloseKey(HKLM
);
3837 return INVALID_HANDLE_VALUE
;
3842 if ((l
= RegOpenKeyExW(HKLM
,
3848 SetLastError(ERROR_INVALID_CLASS
);
3849 hClassesKey
= INVALID_HANDLE_VALUE
;
3851 if (MachineName
!= NULL
)
3857 WCHAR bracedGuidString
[39];
3859 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3861 if (!(l
= RegOpenKeyExW(HKLM
,
3867 if (MachineName
!= NULL
)
3870 if ((l
= RegOpenKeyExW(hClassesKey
,
3877 key
= INVALID_HANDLE_VALUE
;
3879 RegCloseKey(hClassesKey
);
3883 if (MachineName
!= NULL
) RegCloseKey(HKLM
);
3885 key
= INVALID_HANDLE_VALUE
;
3892 /***********************************************************************
3893 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3895 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3896 HDEVINFO DeviceInfoSet
,
3899 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3901 struct DeviceInfoSet
* list
;
3903 DWORD dwLength
, dwError
, dwIndex
, dwKeyName
, dwSubIndex
;
3905 WCHAR Buffer
[MAX_PATH
+ 1];
3906 WCHAR SymBuffer
[MAX_PATH
+ 1];
3907 WCHAR InstancePath
[MAX_PATH
+ 1];
3908 HKEY hKey
, hDevKey
, hSymKey
;
3909 struct DeviceInfo
* deviceInfo
;
3910 struct DeviceInterface
*deviceInterface
;
3912 PLIST_ENTRY ItemList
;
3913 PLIST_ENTRY InterfaceListEntry
;
3915 TRACE("%p %s %08x %p\n",
3916 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3919 if (DeviceInterfaceData
&& DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
3921 SetLastError(ERROR_INVALID_PARAMETER
);
3925 if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3927 SetLastError(ERROR_INVALID_HANDLE
);
3931 list
= (struct DeviceInfoSet
* )DeviceInfoSet
;
3933 dwLength
= wcslen(DevicePath
);
3936 /* path must be at least a guid length + L'\0' */
3937 SetLastError(ERROR_BAD_PATHNAME
);
3941 if (DevicePath
[0] != L
'\\' ||
3942 DevicePath
[1] != L
'\\' ||
3943 (DevicePath
[2] != L
'?' && DevicePath
[2] != L
'.') ||
3944 DevicePath
[3] != L
'\\')
3946 /* invalid formatted path */
3947 SetLastError(ERROR_BAD_PATHNAME
);
3951 /* check for reference strings */
3952 pEnd
= wcschr(&DevicePath
[4], L
'\\');
3955 /* no reference string */
3956 pEnd
= DevicePath
+ dwLength
;
3960 wcscpy(Buffer
, pEnd
- 37);
3963 dwError
= UuidFromStringW(Buffer
, &ClassId
);
3964 if (dwError
!= NOERROR
)
3966 /* invalid formatted path */
3967 SetLastError(ERROR_BAD_PATHNAME
);
3971 hKey
= SetupDiOpenClassRegKeyExW(&ClassId
, KEY_READ
, DIOCR_INTERFACE
, list
->MachineName
, NULL
);
3973 if (hKey
== INVALID_HANDLE_VALUE
)
3975 /* invalid device class */
3979 ItemList
= list
->ListHead
.Flink
;
3980 while (ItemList
!= &list
->ListHead
)
3982 deviceInfo
= CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
3983 InterfaceListEntry
= deviceInfo
->InterfaceListHead
.Flink
;
3984 while (InterfaceListEntry
!= &deviceInfo
->InterfaceListHead
)
3986 deviceInterface
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
3987 if (!IsEqualIID(&deviceInterface
->InterfaceClassGuid
, &ClassId
))
3989 InterfaceListEntry
= InterfaceListEntry
->Flink
;
3993 if (!wcsicmp(deviceInterface
->SymbolicLink
, DevicePath
))
3995 if (DeviceInterfaceData
)
3997 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)deviceInterface
;
3998 DeviceInterfaceData
->Flags
= deviceInterface
->Flags
;
3999 CopyMemory(&DeviceInterfaceData
->InterfaceClassGuid
, &ClassId
, sizeof(GUID
));
4013 dwKeyName
= sizeof(Buffer
) / sizeof(WCHAR
);
4014 dwError
= RegEnumKeyExW(hKey
, dwIndex
, Buffer
, &dwKeyName
, NULL
, NULL
, NULL
, NULL
);
4016 if (dwError
!= ERROR_SUCCESS
)
4019 if (RegOpenKeyExW(hKey
, Buffer
, 0, KEY_READ
, &hDevKey
) != ERROR_SUCCESS
)
4023 InstancePath
[0] = 0;
4024 dwKeyName
= sizeof(InstancePath
);
4026 dwError
= RegQueryValueExW(hDevKey
, L
"DeviceInstance", NULL
, NULL
, (LPBYTE
)InstancePath
, &dwKeyName
);
4031 dwKeyName
= sizeof(Buffer
) / sizeof(WCHAR
);
4032 dwError
= RegEnumKeyExW(hDevKey
, dwSubIndex
, Buffer
, &dwKeyName
, NULL
, NULL
, NULL
, NULL
);
4034 if (dwError
!= ERROR_SUCCESS
)
4037 dwError
= RegOpenKeyExW(hDevKey
, Buffer
, 0, KEY_READ
, &hSymKey
);
4038 if (dwError
!= ERROR_SUCCESS
)
4041 /* query for symbolic link */
4042 dwKeyName
= sizeof(SymBuffer
);
4043 SymBuffer
[0] = L
'\0';
4044 dwError
= RegQueryValueExW(hSymKey
, L
"SymbolicLink", NULL
, NULL
, (LPBYTE
)SymBuffer
, &dwKeyName
);
4046 if (dwError
!= ERROR_SUCCESS
)
4048 RegCloseKey(hSymKey
);
4052 if (!wcsicmp(SymBuffer
, DevicePath
))
4054 Ret
= CreateDeviceInfo(list
, InstancePath
, &ClassId
, &deviceInfo
);
4055 RegCloseKey(hSymKey
);
4056 RegCloseKey(hDevKey
);
4061 deviceInterface
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct DeviceInterface
) + (wcslen(SymBuffer
) + 1) * sizeof(WCHAR
));
4062 if (deviceInterface
)
4065 CopyMemory(&deviceInterface
->InterfaceClassGuid
, &ClassId
, sizeof(GUID
));
4066 deviceInterface
->DeviceInfo
= deviceInfo
;
4067 deviceInterface
->Flags
= SPINT_ACTIVE
; //FIXME
4069 wcscpy(deviceInterface
->SymbolicLink
, SymBuffer
);
4071 InsertTailList(&deviceInfo
->InterfaceListHead
, &deviceInterface
->ListEntry
);
4072 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
4075 if (DeviceInterfaceData
)
4077 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)deviceInterface
;
4078 DeviceInterfaceData
->Flags
= deviceInterface
->Flags
;
4079 CopyMemory(&DeviceInterfaceData
->InterfaceClassGuid
, &ClassId
, sizeof(GUID
));
4084 SetLastError(ERROR_INVALID_USER_BUFFER
);
4090 HeapFree(GetProcessHeap(), 0, deviceInfo
);
4095 RegCloseKey(hSymKey
);
4099 RegCloseKey(hDevKey
);
4107 /***********************************************************************
4108 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
4110 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
4111 HDEVINFO DeviceInfoSet
,
4114 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
4116 LPWSTR DevicePathW
= NULL
;
4119 TRACE("%p %s %08lx %p\n", DeviceInfoSet
, debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
4121 DevicePathW
= pSetupMultiByteToUnicode(DevicePath
, CP_ACP
);
4122 if (DevicePathW
== NULL
)
4125 bResult
= SetupDiOpenDeviceInterfaceW(DeviceInfoSet
,
4126 DevicePathW
, OpenFlags
, DeviceInterfaceData
);
4128 MyFree(DevicePathW
);
4133 /***********************************************************************
4134 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
4136 BOOL WINAPI
SetupDiSetClassInstallParamsA(
4137 HDEVINFO DeviceInfoSet
,
4138 PSP_DEVINFO_DATA DeviceInfoData
,
4139 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
4140 DWORD ClassInstallParamsSize
)
4142 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
4143 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
4148 IntSetupDiRegisterDeviceInfo(
4149 IN HDEVINFO DeviceInfoSet
,
4150 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
4152 return SetupDiRegisterDeviceInfo(DeviceInfoSet
, DeviceInfoData
, 0, NULL
, NULL
, NULL
);
4155 /***********************************************************************
4156 * SetupDiCallClassInstaller (SETUPAPI.@)
4158 BOOL WINAPI
SetupDiCallClassInstaller(
4159 DI_FUNCTION InstallFunction
,
4160 HDEVINFO DeviceInfoSet
,
4161 PSP_DEVINFO_DATA DeviceInfoData
)
4165 TRACE("%u %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
4168 SetLastError(ERROR_INVALID_PARAMETER
);
4169 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
4170 SetLastError(ERROR_INVALID_HANDLE
);
4171 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4172 SetLastError(ERROR_INVALID_HANDLE
);
4173 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->HKLM
!= HKEY_LOCAL_MACHINE
)
4174 SetLastError(ERROR_INVALID_HANDLE
);
4175 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4176 SetLastError(ERROR_INVALID_USER_BUFFER
);
4179 SP_DEVINSTALL_PARAMS_W InstallParams
;
4180 #define CLASS_COINSTALLER 0x1
4181 #define DEVICE_COINSTALLER 0x2
4182 #define CLASS_INSTALLER 0x4
4183 UCHAR CanHandle
= 0;
4184 DEFAULT_CLASS_INSTALL_PROC DefaultHandler
= NULL
;
4186 switch (InstallFunction
)
4188 case DIF_ADDPROPERTYPAGE_ADVANCED
:
4189 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4191 case DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
4192 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4194 case DIF_ALLOW_INSTALL
:
4195 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4198 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4200 case DIF_DESTROYPRIVATEDATA
:
4201 CanHandle
= CLASS_INSTALLER
;
4203 case DIF_INSTALLDEVICE
:
4204 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4205 DefaultHandler
= SetupDiInstallDevice
;
4207 case DIF_INSTALLDEVICEFILES
:
4208 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4209 DefaultHandler
= SetupDiInstallDriverFiles
;
4211 case DIF_INSTALLINTERFACES
:
4212 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4213 DefaultHandler
= SetupDiInstallDeviceInterfaces
;
4215 case DIF_NEWDEVICEWIZARD_FINISHINSTALL
:
4216 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4218 case DIF_NEWDEVICEWIZARD_POSTANALYZE
:
4219 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4221 case DIF_NEWDEVICEWIZARD_PREANALYZE
:
4222 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4224 case DIF_NEWDEVICEWIZARD_PRESELECT
:
4225 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4227 case DIF_NEWDEVICEWIZARD_SELECT
:
4228 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4230 case DIF_POWERMESSAGEWAKE
:
4231 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4233 case DIF_PROPERTYCHANGE
:
4234 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4235 DefaultHandler
= SetupDiChangeState
;
4237 case DIF_REGISTER_COINSTALLERS
:
4238 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4239 DefaultHandler
= SetupDiRegisterCoDeviceInstallers
;
4241 case DIF_REGISTERDEVICE
:
4242 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4243 DefaultHandler
= IntSetupDiRegisterDeviceInfo
;
4246 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4247 DefaultHandler
= SetupDiRemoveDevice
;
4249 case DIF_SELECTBESTCOMPATDRV
:
4250 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4251 DefaultHandler
= SetupDiSelectBestCompatDrv
;
4253 case DIF_SELECTDEVICE
:
4254 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
4255 DefaultHandler
= SetupDiSelectDevice
;
4257 case DIF_TROUBLESHOOTER
:
4258 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4261 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
4262 DefaultHandler
= SetupDiUnremoveDevice
;
4265 ERR("Install function %u not supported\n", InstallFunction
);
4266 SetLastError(ERROR_NOT_SUPPORTED
);
4269 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4270 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
))
4271 /* Don't process this call, as a parameter is invalid */
4276 LIST_ENTRY ClassCoInstallersListHead
;
4277 LIST_ENTRY DeviceCoInstallersListHead
;
4278 HMODULE ClassInstallerLibrary
= NULL
;
4279 CLASS_INSTALL_PROC ClassInstaller
= NULL
;
4280 COINSTALLER_CONTEXT_DATA Context
;
4281 PLIST_ENTRY ListEntry
;
4283 DWORD dwRegType
, dwLength
;
4284 DWORD rc
= NO_ERROR
;
4286 InitializeListHead(&ClassCoInstallersListHead
);
4287 InitializeListHead(&DeviceCoInstallersListHead
);
4289 if (CanHandle
& DEVICE_COINSTALLER
)
4291 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_QUERY_VALUE
);
4292 if (hKey
!= INVALID_HANDLE_VALUE
)
4294 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_COINSTALLERS_32
, NULL
, &dwRegType
, NULL
, &dwLength
);
4295 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_MULTI_SZ
)
4297 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
4298 if (KeyBuffer
!= NULL
)
4300 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_COINSTALLERS_32
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
4301 if (rc
== ERROR_SUCCESS
)
4304 for (ptr
= KeyBuffer
; *ptr
; ptr
+= strlenW(ptr
) + 1)
4306 /* Add coinstaller to DeviceCoInstallersListHead list */
4307 struct CoInstallerElement
*coinstaller
;
4308 TRACE("Got device coinstaller '%s'\n", debugstr_w(ptr
));
4309 coinstaller
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CoInstallerElement
));
4312 ZeroMemory(coinstaller
, sizeof(struct CoInstallerElement
));
4313 if (GetFunctionPointer(ptr
, &coinstaller
->Module
, (PVOID
*)&coinstaller
->Function
) == ERROR_SUCCESS
)
4314 InsertTailList(&DeviceCoInstallersListHead
, &coinstaller
->ListEntry
);
4316 HeapFree(GetProcessHeap(), 0, coinstaller
);
4319 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
4325 if (CanHandle
& CLASS_COINSTALLER
)
4329 REGSTR_PATH_CODEVICEINSTALLERS
,
4333 if (rc
== ERROR_SUCCESS
)
4335 WCHAR szGuidString
[40];
4336 if (pSetupStringFromGuid(&DeviceInfoData
->ClassGuid
, szGuidString
, ARRAYSIZE(szGuidString
)) == ERROR_SUCCESS
)
4338 rc
= RegQueryValueExW(hKey
, szGuidString
, NULL
, &dwRegType
, NULL
, &dwLength
);
4339 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_MULTI_SZ
)
4341 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
4342 if (KeyBuffer
!= NULL
)
4344 rc
= RegQueryValueExW(hKey
, szGuidString
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
4345 if (rc
== ERROR_SUCCESS
)
4348 for (ptr
= KeyBuffer
; *ptr
; ptr
+= strlenW(ptr
) + 1)
4350 /* Add coinstaller to ClassCoInstallersListHead list */
4351 struct CoInstallerElement
*coinstaller
;
4352 TRACE("Got class coinstaller '%s'\n", debugstr_w(ptr
));
4353 coinstaller
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CoInstallerElement
));
4356 ZeroMemory(coinstaller
, sizeof(struct CoInstallerElement
));
4357 if (GetFunctionPointer(ptr
, &coinstaller
->Module
, (PVOID
*)&coinstaller
->Function
) == ERROR_SUCCESS
)
4358 InsertTailList(&ClassCoInstallersListHead
, &coinstaller
->ListEntry
);
4360 HeapFree(GetProcessHeap(), 0, coinstaller
);
4363 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
4370 if ((CanHandle
& CLASS_INSTALLER
) && !(InstallParams
.FlagsEx
& DI_FLAGSEX_CI_FAILED
))
4372 hKey
= SetupDiOpenClassRegKey(&DeviceInfoData
->ClassGuid
, KEY_QUERY_VALUE
);
4373 if (hKey
!= INVALID_HANDLE_VALUE
)
4375 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_INSTALLER_32
, NULL
, &dwRegType
, NULL
, &dwLength
);
4376 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_SZ
)
4378 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
4379 if (KeyBuffer
!= NULL
)
4381 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_INSTALLER_32
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
4382 if (rc
== ERROR_SUCCESS
)
4384 /* Get ClassInstaller function pointer */
4385 TRACE("Got class installer '%s'\n", debugstr_w(KeyBuffer
));
4386 if (GetFunctionPointer(KeyBuffer
, &ClassInstallerLibrary
, (PVOID
*)&ClassInstaller
) != ERROR_SUCCESS
)
4388 InstallParams
.FlagsEx
|= DI_FLAGSEX_CI_FAILED
;
4389 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
4392 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
4399 /* Call Class co-installers */
4400 Context
.PostProcessing
= FALSE
;
4402 ListEntry
= ClassCoInstallersListHead
.Flink
;
4403 while (rc
== NO_ERROR
&& ListEntry
!= &ClassCoInstallersListHead
)
4405 struct CoInstallerElement
*coinstaller
;
4406 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4407 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4408 coinstaller
->PrivateData
= Context
.PrivateData
;
4409 if (rc
== ERROR_DI_POSTPROCESSING_REQUIRED
)
4411 coinstaller
->DoPostProcessing
= TRUE
;
4414 ListEntry
= ListEntry
->Flink
;
4417 /* Call Device co-installers */
4418 ListEntry
= DeviceCoInstallersListHead
.Flink
;
4419 while (rc
== NO_ERROR
&& ListEntry
!= &DeviceCoInstallersListHead
)
4421 struct CoInstallerElement
*coinstaller
;
4422 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4423 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4424 coinstaller
->PrivateData
= Context
.PrivateData
;
4425 if (rc
== ERROR_DI_POSTPROCESSING_REQUIRED
)
4427 coinstaller
->DoPostProcessing
= TRUE
;
4430 ListEntry
= ListEntry
->Flink
;
4433 /* Call Class installer */
4436 rc
= (*ClassInstaller
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
4437 FreeFunctionPointer(ClassInstallerLibrary
, ClassInstaller
);
4440 rc
= ERROR_DI_DO_DEFAULT
;
4442 /* Call default handler */
4443 if (rc
== ERROR_DI_DO_DEFAULT
)
4445 if (DefaultHandler
&& !(InstallParams
.Flags
& DI_NODI_DEFAULTACTION
))
4447 if ((*DefaultHandler
)(DeviceInfoSet
, DeviceInfoData
))
4450 rc
= GetLastError();
4456 /* Call Class co-installers that required postprocessing */
4457 Context
.PostProcessing
= TRUE
;
4458 ListEntry
= ClassCoInstallersListHead
.Flink
;
4459 while (ListEntry
!= &ClassCoInstallersListHead
)
4461 struct CoInstallerElement
*coinstaller
;
4462 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4463 if (coinstaller
->DoPostProcessing
)
4465 Context
.InstallResult
= rc
;
4466 Context
.PrivateData
= coinstaller
->PrivateData
;
4467 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4469 FreeFunctionPointer(coinstaller
->Module
, coinstaller
->Function
);
4470 ListEntry
= ListEntry
->Flink
;
4473 /* Call Device co-installers that required postprocessing */
4474 ListEntry
= DeviceCoInstallersListHead
.Flink
;
4475 while (ListEntry
!= &DeviceCoInstallersListHead
)
4477 struct CoInstallerElement
*coinstaller
;
4478 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4479 if (coinstaller
->DoPostProcessing
)
4481 Context
.InstallResult
= rc
;
4482 Context
.PrivateData
= coinstaller
->PrivateData
;
4483 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4485 FreeFunctionPointer(coinstaller
->Module
, coinstaller
->Function
);
4486 ListEntry
= ListEntry
->Flink
;
4489 /* Free allocated memory */
4490 while (!IsListEmpty(&ClassCoInstallersListHead
))
4492 ListEntry
= RemoveHeadList(&ClassCoInstallersListHead
);
4493 HeapFree(GetProcessHeap(), 0, CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
));
4495 while (!IsListEmpty(&DeviceCoInstallersListHead
))
4497 ListEntry
= RemoveHeadList(&DeviceCoInstallersListHead
);
4498 HeapFree(GetProcessHeap(), 0, CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
));
4501 ret
= (rc
== NO_ERROR
);
4505 TRACE("Returning %d\n", ret
);
4509 /***********************************************************************
4510 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
4512 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
4513 HDEVINFO DeviceInfoSet
,
4514 PSP_DEVINFO_DATA DeviceInfoData
,
4515 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
4517 SP_DEVINSTALL_PARAMS_W deviceInstallParamsW
;
4520 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4522 if (DeviceInstallParams
== NULL
)
4523 SetLastError(ERROR_INVALID_PARAMETER
);
4524 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_A
))
4525 SetLastError(ERROR_INVALID_USER_BUFFER
);
4528 deviceInstallParamsW
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4529 ret
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &deviceInstallParamsW
);
4533 /* Do W->A conversion */
4535 DeviceInstallParams
,
4536 &deviceInstallParamsW
,
4537 FIELD_OFFSET(SP_DEVINSTALL_PARAMS_W
, DriverPath
));
4538 if (WideCharToMultiByte(CP_ACP
, 0, deviceInstallParamsW
.DriverPath
, -1,
4539 DeviceInstallParams
->DriverPath
, MAX_PATH
, NULL
, NULL
) == 0)
4541 DeviceInstallParams
->DriverPath
[0] = '\0';
4547 TRACE("Returning %d\n", ret
);
4551 /***********************************************************************
4552 * SetupDiGetDeviceInfoListClass (SETUPAPI.@)
4555 SetupDiGetDeviceInfoListClass(
4556 IN HDEVINFO DeviceInfoSet
,
4557 OUT LPGUID ClassGuid
)
4559 struct DeviceInfoSet
*list
;
4562 TRACE("%p %p\n", DeviceInfoSet
, ClassGuid
);
4565 SetLastError(ERROR_INVALID_HANDLE
);
4566 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4567 SetLastError(ERROR_INVALID_HANDLE
);
4568 else if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
4569 SetLastError(ERROR_NO_ASSOCIATED_CLASS
);
4572 memcpy(&ClassGuid
, &list
->ClassGuid
, sizeof(GUID
));
4577 TRACE("Returning %d\n", ret
);
4581 /***********************************************************************
4582 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
4585 SetupDiGetDeviceInstallParamsW(
4586 IN HDEVINFO DeviceInfoSet
,
4587 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4588 OUT PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4590 struct DeviceInfoSet
*list
;
4593 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4596 SetLastError(ERROR_INVALID_HANDLE
);
4597 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4598 SetLastError(ERROR_INVALID_HANDLE
);
4599 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4600 SetLastError(ERROR_INVALID_USER_BUFFER
);
4601 else if (!DeviceInstallParams
)
4602 SetLastError(ERROR_INVALID_PARAMETER
);
4603 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_W
))
4604 SetLastError(ERROR_INVALID_USER_BUFFER
);
4607 PSP_DEVINSTALL_PARAMS_W Source
;
4610 Source
= &((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->InstallParams
;
4612 Source
= &list
->InstallParams
;
4618 memcpy(DeviceInstallParams
, Source
, Source
->cbSize
);
4620 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4622 SetLastError(RtlNtStatusToDosError(_SEH2_GetExceptionCode()));
4628 TRACE("Returning %d\n", ret
);
4633 CheckDeviceInstallParameters(
4634 IN PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4636 DWORD SupportedFlags
=
4637 DI_NOVCP
| /* 0x00000008 */
4638 DI_DIDCOMPAT
| /* 0x00000010 */
4639 DI_DIDCLASS
| /* 0x00000020 */
4640 DI_NEEDRESTART
| /* 0x00000080 */
4641 DI_NEEDREBOOT
| /* 0x00000100 */
4642 DI_RESOURCEPAGE_ADDED
| /* 0x00002000 */
4643 DI_PROPERTIES_CHANGE
| /* 0x00004000 */
4644 DI_ENUMSINGLEINF
| /* 0x00010000 */
4645 DI_DONOTCALLCONFIGMG
| /* 0x00020000 */
4646 DI_CLASSINSTALLPARAMS
| /* 0x00100000 */
4647 DI_NODI_DEFAULTACTION
| /* 0x00200000 */
4648 DI_QUIETINSTALL
| /* 0x00800000 */
4649 DI_NOFILECOPY
| /* 0x01000000 */
4650 DI_DRIVERPAGE_ADDED
; /* 0x04000000 */
4651 DWORD SupportedFlagsEx
=
4652 DI_FLAGSEX_CI_FAILED
| /* 0x00000004 */
4653 DI_FLAGSEX_DIDINFOLIST
| /* 0x00000010 */
4654 DI_FLAGSEX_DIDCOMPATINFO
| /* 0x00000020 */
4655 DI_FLAGSEX_ALLOWEXCLUDEDDRVS
| /* 0x00000800 */
4656 DI_FLAGSEX_NO_DRVREG_MODIFY
| /* 0x00008000 */
4657 DI_FLAGSEX_INSTALLEDDRIVER
; /* 0x04000000 */
4660 /* FIXME: add support for more flags */
4662 /* FIXME: DI_CLASSINSTALLPARAMS flag is not correctly used.
4663 * It should be checked before accessing to other values
4664 * of the SP_DEVINSTALL_PARAMS structure */
4666 if (DeviceInstallParams
->Flags
& ~SupportedFlags
)
4668 FIXME("Unknown Flags: 0x%08lx\n", DeviceInstallParams
->Flags
& ~SupportedFlags
);
4669 SetLastError(ERROR_INVALID_FLAGS
);
4671 else if (DeviceInstallParams
->FlagsEx
& ~SupportedFlagsEx
)
4673 FIXME("Unknown FlagsEx: 0x%08lx\n", DeviceInstallParams
->FlagsEx
& ~SupportedFlagsEx
);
4674 SetLastError(ERROR_INVALID_FLAGS
);
4676 else if ((DeviceInstallParams
->Flags
& DI_NOVCP
)
4677 && (DeviceInstallParams
->FileQueue
== NULL
|| DeviceInstallParams
->FileQueue
== (HSPFILEQ
)INVALID_HANDLE_VALUE
))
4678 SetLastError(ERROR_INVALID_USER_BUFFER
);
4681 /* FIXME: check Reserved field */
4688 /***********************************************************************
4689 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
4692 SetupDiSetDeviceInstallParamsW(
4693 IN HDEVINFO DeviceInfoSet
,
4694 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4695 IN PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4697 struct DeviceInfoSet
*list
;
4700 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4703 SetLastError(ERROR_INVALID_HANDLE
);
4704 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4705 SetLastError(ERROR_INVALID_HANDLE
);
4706 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4707 SetLastError(ERROR_INVALID_USER_BUFFER
);
4708 else if (!DeviceInstallParams
)
4709 SetLastError(ERROR_INVALID_PARAMETER
);
4710 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_W
))
4711 SetLastError(ERROR_INVALID_USER_BUFFER
);
4712 else if (CheckDeviceInstallParameters(DeviceInstallParams
))
4714 PSP_DEVINSTALL_PARAMS_W Destination
;
4717 Destination
= &((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->InstallParams
;
4719 Destination
= &list
->InstallParams
;
4720 memcpy(Destination
, DeviceInstallParams
, DeviceInstallParams
->cbSize
);
4724 TRACE("Returning %d\n", ret
);
4728 /***********************************************************************
4729 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
4732 SetupDiSetDeviceInstallParamsA(
4733 HDEVINFO DeviceInfoSet
,
4734 PSP_DEVINFO_DATA DeviceInfoData
,
4735 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
4737 SP_DEVINSTALL_PARAMS_W deviceInstallParamsW
;
4741 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4743 if (DeviceInstallParams
== NULL
)
4744 SetLastError(ERROR_INVALID_PARAMETER
);
4745 else if (DeviceInstallParams
->cbSize
< sizeof(SP_DEVINSTALL_PARAMS_A
))
4746 SetLastError(ERROR_INVALID_USER_BUFFER
);
4749 memcpy(&deviceInstallParamsW
, DeviceInstallParams
, FIELD_OFFSET(SP_DEVINSTALL_PARAMS_A
, DriverPath
));
4750 deviceInstallParamsW
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4751 len
= MultiByteToWideChar(CP_ACP
, 0, DeviceInstallParams
->DriverPath
, -1, NULL
, 0);
4754 ERR("DrivePath is NULL\n");
4759 MultiByteToWideChar(CP_ACP
, 0, DeviceInstallParams
->DriverPath
, -1, deviceInstallParamsW
.DriverPath
, len
);
4760 ret
= SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &deviceInstallParamsW
);
4764 TRACE("Returning %d\n", ret
);
4769 OpenHardwareProfileKey(
4772 IN DWORD samDesired
)
4774 HKEY hHWProfilesKey
= NULL
;
4775 HKEY hHWProfileKey
= NULL
;
4776 HKEY ret
= INVALID_HANDLE_VALUE
;
4779 rc
= RegOpenKeyExW(HKLM
,
4780 REGSTR_PATH_HWPROFILES
,
4784 if (rc
!= ERROR_SUCCESS
)
4791 rc
= RegOpenKeyExW(hHWProfilesKey
,
4800 snprintfW(subKey
, 4, InstanceKeyFormat
, HwProfile
);
4802 rc
= RegOpenKeyExW(hHWProfilesKey
,
4808 if (rc
!= ERROR_SUCCESS
)
4813 ret
= hHWProfileKey
;
4816 if (hHWProfilesKey
!= NULL
)
4817 RegCloseKey(hHWProfilesKey
);
4818 if (hHWProfileKey
!= NULL
&& hHWProfileKey
!= ret
)
4819 RegCloseKey(hHWProfileKey
);
4824 IsDeviceInfoInDeviceInfoSet(
4825 struct DeviceInfoSet
*deviceInfoSet
,
4826 struct DeviceInfo
*deviceInfo
)
4828 PLIST_ENTRY ListEntry
;
4830 ListEntry
= deviceInfoSet
->ListHead
.Flink
;
4831 while (ListEntry
!= &deviceInfoSet
->ListHead
)
4833 if (deviceInfo
== CONTAINING_RECORD(ListEntry
, struct DeviceInfo
, ListEntry
))
4836 ListEntry
= ListEntry
->Flink
;
4842 /***********************************************************************
4843 * SetupDiDeleteDeviceInfo (SETUPAPI.@)
4846 SetupDiDeleteDeviceInfo(
4847 IN HDEVINFO DeviceInfoSet
,
4848 IN PSP_DEVINFO_DATA DeviceInfoData
)
4850 struct DeviceInfoSet
*deviceInfoSet
;
4851 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
;
4854 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4857 SetLastError(ERROR_INVALID_HANDLE
);
4858 else if ((deviceInfoSet
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4859 SetLastError(ERROR_INVALID_HANDLE
);
4860 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4861 SetLastError(ERROR_INVALID_USER_BUFFER
);
4862 else if (!IsDeviceInfoInDeviceInfoSet(deviceInfoSet
, deviceInfo
))
4863 SetLastError(ERROR_INVALID_PARAMETER
);
4866 RemoveEntryList(&deviceInfo
->ListEntry
);
4867 DestroyDeviceInfo(deviceInfo
);
4875 /***********************************************************************
4876 * SetupDiOpenDeviceInfoA (SETUPAPI.@)
4879 SetupDiOpenDeviceInfoA(
4880 IN HDEVINFO DeviceInfoSet
,
4881 IN PCSTR DeviceInstanceId
,
4882 IN HWND hwndParent OPTIONAL
,
4884 OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4886 LPWSTR DeviceInstanceIdW
= NULL
;
4889 TRACE("%p %s %p %lx %p\n", DeviceInfoSet
, DeviceInstanceId
, hwndParent
, OpenFlags
, DeviceInfoData
);
4891 DeviceInstanceIdW
= pSetupMultiByteToUnicode(DeviceInstanceId
, CP_ACP
);
4892 if (DeviceInstanceIdW
== NULL
)
4895 bResult
= SetupDiOpenDeviceInfoW(DeviceInfoSet
,
4896 DeviceInstanceIdW
, hwndParent
, OpenFlags
, DeviceInfoData
);
4898 MyFree(DeviceInstanceIdW
);
4904 /***********************************************************************
4905 * SetupDiOpenDeviceInfoW (SETUPAPI.@)
4908 SetupDiOpenDeviceInfoW(
4909 IN HDEVINFO DeviceInfoSet
,
4910 IN PCWSTR DeviceInstanceId
,
4911 IN HWND hwndParent OPTIONAL
,
4913 OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4915 struct DeviceInfoSet
*list
;
4916 HKEY hEnumKey
, hKey
= NULL
;
4920 TRACE("%p %s %p %lx %p\n",
4921 DeviceInfoSet
, debugstr_w(DeviceInstanceId
),
4922 hwndParent
, OpenFlags
, DeviceInfoData
);
4924 if (OpenFlags
& DIOD_CANCEL_REMOVE
)
4925 FIXME("DIOD_CANCEL_REMOVE flag not implemented\n");
4928 SetLastError(ERROR_INVALID_HANDLE
);
4929 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4930 SetLastError(ERROR_INVALID_HANDLE
);
4931 else if (!DeviceInstanceId
)
4932 SetLastError(ERROR_INVALID_PARAMETER
);
4933 else if (OpenFlags
& ~(DIOD_CANCEL_REMOVE
| DIOD_INHERIT_CLASSDRVS
))
4935 TRACE("Unknown flags: 0x%08lx\n", OpenFlags
& ~(DIOD_CANCEL_REMOVE
| DIOD_INHERIT_CLASSDRVS
));
4936 SetLastError(ERROR_INVALID_FLAGS
);
4938 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4939 SetLastError(ERROR_INVALID_USER_BUFFER
);
4942 struct DeviceInfo
*deviceInfo
= NULL
;
4943 /* Search if device already exists in DeviceInfoSet.
4944 * If yes, return the existing element
4945 * If no, create a new element using information in registry
4947 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
4948 while (ItemList
!= &list
->ListHead
)
4950 deviceInfo
= CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
4951 if (!wcscmp(deviceInfo
->instanceId
, DeviceInstanceId
))
4954 ItemList
= ItemList
->Flink
;
4959 /* good one found */
4965 WCHAR szClassGuid
[MAX_GUID_STRING_LEN
];
4967 /* Open supposed registry key */
4970 REGSTR_PATH_SYSTEMENUM
,
4974 if (rc
!= ERROR_SUCCESS
)
4985 RegCloseKey(hEnumKey
);
4986 if (rc
!= ERROR_SUCCESS
)
4988 if (rc
== ERROR_FILE_NOT_FOUND
)
4989 rc
= ERROR_NO_SUCH_DEVINST
;
4994 ClassGUID
= GUID_NULL
;
4995 dwSize
= MAX_GUID_STRING_LEN
* sizeof(WCHAR
);
4997 if (RegQueryValueExW(hKey
,
4998 REGSTR_VAL_CLASSGUID
,
5001 (LPBYTE
)szClassGuid
,
5002 &dwSize
) == ERROR_SUCCESS
)
5004 szClassGuid
[MAX_GUID_STRING_LEN
- 2] = UNICODE_NULL
;
5006 /* Convert a string to a ClassGuid */
5007 UuidFromStringW(&szClassGuid
[1], &ClassGUID
);
5010 if (!CreateDeviceInfo(list
, DeviceInstanceId
, &ClassGUID
, &deviceInfo
))
5013 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
5018 if (ret
&& deviceInfo
&& DeviceInfoData
)
5020 memcpy(&DeviceInfoData
->ClassGuid
, &deviceInfo
->ClassGuid
, sizeof(GUID
));
5021 DeviceInfoData
->DevInst
= deviceInfo
->dnDevInst
;
5022 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInfo
;
5033 /***********************************************************************
5034 * SetupDiGetSelectedDevice (SETUPAPI.@)
5037 SetupDiGetSelectedDevice(
5038 IN HDEVINFO DeviceInfoSet
,
5039 OUT PSP_DEVINFO_DATA DeviceInfoData
)
5041 struct DeviceInfoSet
*list
;
5044 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5047 SetLastError(ERROR_INVALID_HANDLE
);
5048 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5049 SetLastError(ERROR_INVALID_HANDLE
);
5050 else if (list
->SelectedDevice
== NULL
)
5051 SetLastError(ERROR_NO_DEVICE_SELECTED
);
5052 else if (!DeviceInfoData
)
5053 SetLastError(ERROR_INVALID_PARAMETER
);
5054 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5055 SetLastError(ERROR_INVALID_USER_BUFFER
);
5058 memcpy(&DeviceInfoData
->ClassGuid
,
5059 &list
->SelectedDevice
->ClassGuid
,
5061 DeviceInfoData
->DevInst
= list
->SelectedDevice
->dnDevInst
;
5062 DeviceInfoData
->Reserved
= (ULONG_PTR
)list
->SelectedDevice
;
5066 TRACE("Returning %d\n", ret
);
5071 /***********************************************************************
5072 * SetupDiSetSelectedDevice (SETUPAPI.@)
5075 SetupDiSetSelectedDevice(
5076 IN HDEVINFO DeviceInfoSet
,
5077 IN PSP_DEVINFO_DATA DeviceInfoData
)
5079 struct DeviceInfoSet
*list
;
5082 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5085 SetLastError(ERROR_INVALID_HANDLE
);
5086 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5087 SetLastError(ERROR_INVALID_HANDLE
);
5088 else if (!DeviceInfoData
)
5089 SetLastError(ERROR_INVALID_PARAMETER
);
5090 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5091 SetLastError(ERROR_INVALID_USER_BUFFER
);
5092 else if (DeviceInfoData
->Reserved
== 0)
5093 SetLastError(ERROR_INVALID_USER_BUFFER
);
5096 list
->SelectedDevice
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5100 TRACE("Returning %d\n", ret
);
5105 /* Return the current hardware profile id, or -1 if error */
5107 SETUPAPI_GetCurrentHwProfile(
5108 IN HDEVINFO DeviceInfoSet
)
5111 DWORD dwRegType
, dwLength
;
5114 DWORD ret
= (DWORD
)-1;
5116 rc
= RegOpenKeyExW(((struct DeviceInfoSet
*)DeviceInfoSet
)->HKLM
,
5117 REGSTR_PATH_IDCONFIGDB
,
5121 if (rc
!= ERROR_SUCCESS
)
5127 dwLength
= sizeof(DWORD
);
5128 rc
= RegQueryValueExW(hKey
,
5129 REGSTR_VAL_CURRENTCONFIG
,
5132 (LPBYTE
)&hwProfile
, &dwLength
);
5133 if (rc
!= ERROR_SUCCESS
)
5138 else if (dwRegType
!= REG_DWORD
|| dwLength
!= sizeof(DWORD
))
5140 SetLastError(ERROR_GEN_FAILURE
);
5155 IN HDEVINFO DeviceInfoSet
,
5156 IN PSP_DEVINFO_DATA DeviceInfoData
)
5159 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
5160 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5163 cr
= CM_Enable_DevNode_Ex(deviceInfo
->dnDevInst
, 0, set
->hMachine
);
5164 if (cr
!= CR_SUCCESS
)
5166 SetLastError(GetErrorCodeFromCrCode(cr
));
5172 FIXME("Stub: ResetDevice(%p %p)\n", DeviceInfoSet
, DeviceInfoData
);
5177 static BOOL
StopDevice(
5178 IN HDEVINFO DeviceInfoSet
,
5179 IN PSP_DEVINFO_DATA DeviceInfoData
)
5181 FIXME("Stub: StopDevice(%p %p)\n", DeviceInfoSet
, DeviceInfoData
);
5185 /***********************************************************************
5186 * SetupDiChangeState (SETUPAPI.@)
5190 IN HDEVINFO DeviceInfoSet
,
5191 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
5193 PSP_PROPCHANGE_PARAMS PropChange
;
5194 HKEY hKey
= INVALID_HANDLE_VALUE
;
5195 LPCWSTR RegistryValueName
;
5196 DWORD dwConfigFlags
, dwLength
, dwRegType
;
5200 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5202 if (!DeviceInfoData
)
5203 PropChange
= ((struct DeviceInfoSet
*)DeviceInfoSet
)->ClassInstallParams
.PropChangeParams
;
5205 PropChange
= ((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->ClassInstallParams
.PropChangeParams
;
5208 SetLastError(ERROR_INVALID_PARAMETER
);
5212 if (PropChange
->Scope
== DICS_FLAG_GLOBAL
)
5213 RegistryValueName
= REGSTR_VAL_CONFIGFLAGS
;
5215 RegistryValueName
= REGSTR_VAL_CSCONFIGFLAGS
;
5217 switch (PropChange
->StateChange
)
5222 /* Enable/disable device in registry */
5223 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, PropChange
->Scope
, PropChange
->HwProfile
, DIREG_DEV
, KEY_QUERY_VALUE
| KEY_SET_VALUE
);
5224 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5225 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, PropChange
->Scope
, PropChange
->HwProfile
, DIREG_DEV
, NULL
, NULL
);
5226 if (hKey
== INVALID_HANDLE_VALUE
)
5228 dwLength
= sizeof(DWORD
);
5229 rc
= RegQueryValueExW(
5234 (LPBYTE
)&dwConfigFlags
, &dwLength
);
5235 if (rc
== ERROR_FILE_NOT_FOUND
)
5237 else if (rc
!= ERROR_SUCCESS
)
5242 else if (dwRegType
!= REG_DWORD
|| dwLength
!= sizeof(DWORD
))
5244 SetLastError(ERROR_GEN_FAILURE
);
5247 if (PropChange
->StateChange
== DICS_ENABLE
)
5248 dwConfigFlags
&= ~(PropChange
->Scope
== DICS_FLAG_GLOBAL
? CONFIGFLAG_DISABLED
: CSCONFIGFLAG_DISABLED
);
5250 dwConfigFlags
|= (PropChange
->Scope
== DICS_FLAG_GLOBAL
? CONFIGFLAG_DISABLED
: CSCONFIGFLAG_DISABLED
);
5251 rc
= RegSetValueExW(
5256 (LPBYTE
)&dwConfigFlags
, sizeof(DWORD
));
5257 if (rc
!= ERROR_SUCCESS
)
5263 /* Enable/disable device if needed */
5264 if (PropChange
->Scope
== DICS_FLAG_GLOBAL
5265 || PropChange
->HwProfile
== 0
5266 || PropChange
->HwProfile
== SETUPAPI_GetCurrentHwProfile(DeviceInfoSet
))
5268 if (PropChange
->StateChange
== DICS_ENABLE
)
5269 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
5271 ret
= StopDevice(DeviceInfoSet
, DeviceInfoData
);
5277 case DICS_PROPCHANGE
:
5279 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
5284 ERR("Unknown StateChange 0x%lx\n", PropChange
->StateChange
);
5285 SetLastError(ERROR_NOT_SUPPORTED
);
5290 if (hKey
!= INVALID_HANDLE_VALUE
)
5293 TRACE("Returning %d\n", ret
);
5297 /***********************************************************************
5298 * SetupDiSelectDevice (SETUPAPI.@)
5301 SetupDiSelectDevice(
5302 IN HDEVINFO DeviceInfoSet
,
5303 IN OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
5305 FIXME("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5306 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
5311 /***********************************************************************
5312 * SetupDiRegisterCoDeviceInstallers (SETUPAPI.@)
5315 SetupDiRegisterCoDeviceInstallers(
5316 IN HDEVINFO DeviceInfoSet
,
5317 IN PSP_DEVINFO_DATA DeviceInfoData
)
5319 BOOL ret
= FALSE
; /* Return value */
5321 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5324 SetLastError(ERROR_INVALID_PARAMETER
);
5325 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
5326 SetLastError(ERROR_INVALID_HANDLE
);
5327 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5328 SetLastError(ERROR_INVALID_HANDLE
);
5329 else if (!DeviceInfoData
)
5330 SetLastError(ERROR_INVALID_PARAMETER
);
5331 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5332 SetLastError(ERROR_INVALID_USER_BUFFER
);
5335 SP_DEVINSTALL_PARAMS_W InstallParams
;
5336 struct DriverInfoElement
*SelectedDriver
;
5339 WCHAR SectionName
[MAX_PATH
];
5340 DWORD SectionNameLength
= 0;
5341 HKEY hKey
= INVALID_HANDLE_VALUE
;
5342 PVOID Context
= NULL
;
5344 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
5345 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5349 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
5350 if (SelectedDriver
== NULL
)
5352 SetLastError(ERROR_NO_DRIVER_SELECTED
);
5356 /* Get .CoInstallers section name */
5357 Result
= SetupDiGetActualSectionToInstallW(
5358 SelectedDriver
->InfFileDetails
->hInf
,
5359 SelectedDriver
->Details
.SectionName
,
5360 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
5361 if (!Result
|| SectionNameLength
> MAX_PATH
- strlenW(DotCoInstallers
) - 1)
5363 lstrcatW(SectionName
, DotCoInstallers
);
5365 /* Open/Create driver key information */
5366 #if _WIN32_WINNT >= 0x502
5367 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_READ
| KEY_WRITE
);
5369 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_ALL_ACCESS
);
5371 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5372 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, NULL
, NULL
);
5373 if (hKey
== INVALID_HANDLE_VALUE
)
5376 /* Install .CoInstallers section */
5377 DoAction
= SPINST_REGISTRY
;
5378 if (!(InstallParams
.Flags
& DI_NOFILECOPY
))
5380 DoAction
|= SPINST_FILES
;
5381 Context
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
5385 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5386 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5387 DoAction
, hKey
, SelectedDriver
->InfFileDetails
->DirectoryName
, SP_COPY_NEWER
,
5388 SetupDefaultQueueCallbackW
, Context
,
5389 DeviceInfoSet
, DeviceInfoData
);
5397 SetupTermDefaultQueueCallback(Context
);
5398 if (hKey
!= INVALID_HANDLE_VALUE
)
5402 TRACE("Returning %d\n", ret
);
5407 InfIsFromOEMLocation(
5409 OUT LPBOOL IsOEMLocation
)
5413 last
= strrchrW(FullName
, '\\');
5416 /* No directory specified */
5417 *IsOEMLocation
= FALSE
;
5424 Windir
= MyMalloc((MAX_PATH
+ 1 + strlenW(InfDirectory
)) * sizeof(WCHAR
));
5427 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5431 ret
= GetSystemWindowsDirectoryW(Windir
, MAX_PATH
);
5432 if (ret
== 0 || ret
> MAX_PATH
)
5435 SetLastError(ERROR_GEN_FAILURE
);
5438 if (*Windir
&& Windir
[strlenW(Windir
) - 1] != '\\')
5439 strcatW(Windir
, BackSlash
);
5440 strcatW(Windir
, InfDirectory
);
5442 if (strncmpiW(FullName
, Windir
, last
- FullName
) == 0)
5444 /* The path is %SYSTEMROOT%\Inf */
5445 *IsOEMLocation
= FALSE
;
5449 /* The file is in another place */
5450 *IsOEMLocation
= TRUE
;
5457 /***********************************************************************
5458 * SetupDiInstallDevice (SETUPAPI.@)
5461 SetupDiInstallDevice(
5462 IN HDEVINFO DeviceInfoSet
,
5463 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
5465 SP_DEVINSTALL_PARAMS_W InstallParams
;
5466 struct DriverInfoElement
*SelectedDriver
;
5467 SYSTEMTIME DriverDate
;
5468 WCHAR SectionName
[MAX_PATH
];
5470 DWORD SectionNameLength
= 0;
5471 BOOL Result
= FALSE
;
5474 LPWSTR pSectionName
= NULL
;
5475 WCHAR ClassName
[MAX_CLASS_NAME_LEN
];
5477 LPWSTR lpGuidString
= NULL
, lpFullGuidString
= NULL
;
5478 BOOL RebootRequired
= FALSE
;
5479 HKEY hKey
= INVALID_HANDLE_VALUE
;
5480 BOOL NeedtoCopyFile
;
5481 LARGE_INTEGER fullVersion
;
5483 PVOID Context
= NULL
;
5484 BOOL ret
= FALSE
; /* Return value */
5486 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5489 SetLastError(ERROR_INVALID_PARAMETER
);
5490 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
5491 SetLastError(ERROR_INVALID_HANDLE
);
5492 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5493 SetLastError(ERROR_INVALID_HANDLE
);
5494 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5495 SetLastError(ERROR_INVALID_USER_BUFFER
);
5501 /* One parameter is bad */
5505 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
5506 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5510 if (InstallParams
.FlagsEx
& DI_FLAGSEX_SETFAILEDINSTALL
)
5512 /* Set FAILEDINSTALL in ConfigFlags registry value */
5513 DWORD ConfigFlags
, regType
;
5514 Result
= SetupDiGetDeviceRegistryPropertyW(
5519 (PBYTE
)&ConfigFlags
,
5520 sizeof(ConfigFlags
),
5522 if (!Result
|| regType
!= REG_DWORD
)
5524 SetLastError(ERROR_GEN_FAILURE
);
5527 ConfigFlags
|= DNF_DISABLED
;
5528 Result
= SetupDiSetDeviceRegistryPropertyW(
5532 (PBYTE
)&ConfigFlags
,
5533 sizeof(ConfigFlags
));
5536 SetLastError(ERROR_GEN_FAILURE
);
5544 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
5545 if (SelectedDriver
== NULL
)
5547 SetLastError(ERROR_NO_DRIVER_SELECTED
);
5551 FileTimeToSystemTime(&SelectedDriver
->Info
.DriverDate
, &DriverDate
);
5553 Result
= SetupDiGetActualSectionToInstallW(
5554 SelectedDriver
->InfFileDetails
->hInf
,
5555 SelectedDriver
->Details
.SectionName
,
5556 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
5557 if (!Result
|| SectionNameLength
> MAX_PATH
- strlenW(DotServices
))
5559 pSectionName
= &SectionName
[strlenW(SectionName
)];
5561 /* Get information from [Version] section */
5562 if (!SetupDiGetINFClassW(SelectedDriver
->Details
.InfFileName
, &ClassGuid
, ClassName
, MAX_CLASS_NAME_LEN
, &RequiredSize
))
5564 /* Format ClassGuid to a string */
5565 if (UuidToStringW((UUID
*)&ClassGuid
, &lpGuidString
) != RPC_S_OK
)
5567 RequiredSize
= lstrlenW(lpGuidString
);
5568 lpFullGuidString
= HeapAlloc(GetProcessHeap(), 0, (RequiredSize
+ 3) * sizeof(WCHAR
));
5569 if (!lpFullGuidString
)
5571 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5574 lpFullGuidString
[0] = '{';
5575 memcpy(&lpFullGuidString
[1], lpGuidString
, RequiredSize
* sizeof(WCHAR
));
5576 lpFullGuidString
[RequiredSize
+ 1] = '}';
5577 lpFullGuidString
[RequiredSize
+ 2] = '\0';
5579 /* Copy .inf file to Inf\ directory (if needed) */
5580 Result
= InfIsFromOEMLocation(SelectedDriver
->Details
.InfFileName
, &NeedtoCopyFile
);
5585 WCHAR NewFileName
[MAX_PATH
];
5586 struct InfFileDetails
*newInfFileDetails
;
5587 Result
= SetupCopyOEMInfW(
5588 SelectedDriver
->Details
.InfFileName
,
5591 SP_COPY_NOOVERWRITE
,
5592 NewFileName
, MAX_PATH
,
5595 if (!Result
&& GetLastError() != ERROR_FILE_EXISTS
)
5597 /* Create a new struct InfFileDetails, and set it to
5598 * SelectedDriver->InfFileDetails, to release use of
5599 * current InfFile */
5600 newInfFileDetails
= CreateInfFileDetails(NewFileName
);
5601 if (!newInfFileDetails
)
5603 DereferenceInfFile(SelectedDriver
->InfFileDetails
);
5604 SelectedDriver
->InfFileDetails
= newInfFileDetails
;
5605 strcpyW(SelectedDriver
->Details
.InfFileName
, NewFileName
);
5608 /* Open/Create driver key information */
5609 #if _WIN32_WINNT >= 0x502
5610 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_READ
| KEY_WRITE
);
5612 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_ALL_ACCESS
);
5614 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5615 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, NULL
, NULL
);
5616 if (hKey
== INVALID_HANDLE_VALUE
)
5619 /* Install main section */
5621 if (!(InstallParams
.FlagsEx
& DI_FLAGSEX_NO_DRVREG_MODIFY
))
5622 DoAction
|= SPINST_REGISTRY
;
5623 if (!(InstallParams
.Flags
& DI_NOFILECOPY
))
5625 DoAction
|= SPINST_FILES
;
5626 Context
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
5630 *pSectionName
= '\0';
5631 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5632 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5633 DoAction
, hKey
, SelectedDriver
->InfFileDetails
->DirectoryName
, SP_COPY_NEWER
,
5634 SetupDefaultQueueCallbackW
, Context
,
5635 DeviceInfoSet
, DeviceInfoData
);
5638 InstallParams
.Flags
|= DI_NOFILECOPY
;
5639 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5641 /* Write information to driver key */
5642 *pSectionName
= UNICODE_NULL
;
5643 memcpy(&fullVersion
, &SelectedDriver
->Info
.DriverVersion
, sizeof(LARGE_INTEGER
));
5644 TRACE("Write information to driver key\n");
5645 TRACE("DriverDate : '%u-%u-%u'\n", DriverDate
.wMonth
, DriverDate
.wDay
, DriverDate
.wYear
);
5646 TRACE("DriverDesc : '%s'\n", debugstr_w(SelectedDriver
->Info
.Description
));
5647 TRACE("DriverVersion : '%ld.%ld.%lu.%ld'\n", fullVersion
.HighPart
>> 16, fullVersion
.HighPart
& 0xffff, fullVersion
.LowPart
>> 16, fullVersion
.LowPart
& 0xffff);
5648 TRACE("InfPath : '%s'\n", debugstr_w(SelectedDriver
->InfFileDetails
->FileName
));
5649 TRACE("InfSection : '%s'\n", debugstr_w(SelectedDriver
->Details
.SectionName
));
5650 TRACE("InfSectionExt : '%s'\n", debugstr_w(&SectionName
[strlenW(SelectedDriver
->Details
.SectionName
)]));
5651 TRACE("MatchingDeviceId: '%s'\n", debugstr_w(SelectedDriver
->MatchingId
));
5652 TRACE("ProviderName : '%s'\n", debugstr_w(SelectedDriver
->Info
.ProviderName
));
5653 sprintfW(Buffer
, DateFormat
, DriverDate
.wMonth
, DriverDate
.wDay
, DriverDate
.wYear
);
5654 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_DATE
, 0, REG_SZ
, (const BYTE
*)Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
));
5655 if (rc
== ERROR_SUCCESS
)
5656 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_DATE_DATA
, 0, REG_BINARY
, (const BYTE
*)&SelectedDriver
->Info
.DriverDate
, sizeof(FILETIME
));
5657 if (rc
== ERROR_SUCCESS
)
5658 rc
= RegSetValueExW(hKey
, REGSTR_VAL_DRVDESC
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.Description
, (strlenW(SelectedDriver
->Info
.Description
) + 1) * sizeof(WCHAR
));
5659 if (rc
== ERROR_SUCCESS
)
5661 sprintfW(Buffer
, VersionFormat
, fullVersion
.HighPart
>> 16, fullVersion
.HighPart
& 0xffff, fullVersion
.LowPart
>> 16, fullVersion
.LowPart
& 0xffff);
5662 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_VERSION
, 0, REG_SZ
, (const BYTE
*)Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
));
5664 if (rc
== ERROR_SUCCESS
)
5665 rc
= RegSetValueExW(hKey
, REGSTR_VAL_INFPATH
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->InfFileDetails
->FileName
, (strlenW(SelectedDriver
->InfFileDetails
->FileName
) + 1) * sizeof(WCHAR
));
5666 if (rc
== ERROR_SUCCESS
)
5667 rc
= RegSetValueExW(hKey
, REGSTR_VAL_INFSECTION
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Details
.SectionName
, (strlenW(SelectedDriver
->Details
.SectionName
) + 1) * sizeof(WCHAR
));
5668 if (rc
== ERROR_SUCCESS
)
5669 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
));
5670 if (rc
== ERROR_SUCCESS
)
5671 rc
= RegSetValueExW(hKey
, REGSTR_VAL_MATCHINGDEVID
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->MatchingId
, (strlenW(SelectedDriver
->MatchingId
) + 1) * sizeof(WCHAR
));
5672 if (rc
== ERROR_SUCCESS
)
5673 rc
= RegSetValueExW(hKey
, REGSTR_VAL_PROVIDER_NAME
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.ProviderName
, (strlenW(SelectedDriver
->Info
.ProviderName
) + 1) * sizeof(WCHAR
));
5674 if (rc
!= ERROR_SUCCESS
)
5680 hKey
= INVALID_HANDLE_VALUE
;
5682 /* FIXME: Process .LogConfigOverride section */
5684 /* Install .Services section */
5685 strcpyW(pSectionName
, DotServices
);
5686 Result
= SetupInstallServicesFromInfSectionExW(
5687 SelectedDriver
->InfFileDetails
->hInf
,
5696 if (GetLastError() == ERROR_SUCCESS_REBOOT_REQUIRED
)
5697 RebootRequired
= TRUE
;
5699 /* Open device registry key */
5700 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_SET_VALUE
);
5701 if (hKey
== INVALID_HANDLE_VALUE
)
5704 /* Install .HW section */
5706 if (!(InstallParams
.FlagsEx
& DI_FLAGSEX_NO_DRVREG_MODIFY
))
5707 DoAction
|= SPINST_REGISTRY
;
5708 strcpyW(pSectionName
, DotHW
);
5709 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5710 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5711 DoAction
, hKey
, NULL
, 0,
5713 DeviceInfoSet
, DeviceInfoData
);
5717 /* Write information to enum key */
5718 TRACE("Write information to enum key\n");
5719 TRACE("Class : '%s'\n", debugstr_w(ClassName
));
5720 TRACE("ClassGUID : '%s'\n", debugstr_w(lpFullGuidString
));
5721 TRACE("DeviceDesc : '%s'\n", debugstr_w(SelectedDriver
->Info
.Description
));
5722 TRACE("Mfg : '%s'\n", debugstr_w(SelectedDriver
->Info
.MfgName
));
5723 rc
= RegSetValueExW(hKey
, REGSTR_VAL_CLASS
, 0, REG_SZ
, (const BYTE
*)ClassName
, (strlenW(ClassName
) + 1) * sizeof(WCHAR
));
5724 if (rc
== ERROR_SUCCESS
)
5725 rc
= RegSetValueExW(hKey
, REGSTR_VAL_CLASSGUID
, 0, REG_SZ
, (const BYTE
*)lpFullGuidString
, (strlenW(lpFullGuidString
) + 1) * sizeof(WCHAR
));
5726 if (rc
== ERROR_SUCCESS
)
5727 rc
= RegSetValueExW(hKey
, REGSTR_VAL_DEVDESC
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.Description
, (strlenW(SelectedDriver
->Info
.Description
) + 1) * sizeof(WCHAR
));
5728 if (rc
== ERROR_SUCCESS
)
5729 rc
= RegSetValueExW(hKey
, REGSTR_VAL_MFG
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.MfgName
, (strlenW(SelectedDriver
->Info
.MfgName
) + 1) * sizeof(WCHAR
));
5730 if (rc
!= ERROR_SUCCESS
)
5736 /* Start the device */
5737 if (!RebootRequired
&& !(InstallParams
.Flags
& (DI_NEEDRESTART
| DI_NEEDREBOOT
| DI_DONOTCALLCONFIGMG
)))
5738 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
5743 /* End of installation */
5744 if (hKey
!= INVALID_HANDLE_VALUE
)
5747 RpcStringFreeW(&lpGuidString
);
5748 HeapFree(GetProcessHeap(), 0, lpFullGuidString
);
5750 SetupTermDefaultQueueCallback(Context
);
5751 TRACE("Returning %d\n", ret
);
5755 static HKEY
SETUPDI_OpenDevKey(HKEY RootKey
, struct DeviceInfo
*devInfo
, REGSAM samDesired
)
5757 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
5760 l
= RegOpenKeyExW(RootKey
, REGSTR_PATH_SYSTEMENUM
, 0, READ_CONTROL
, &enumKey
);
5763 l
= RegOpenKeyExW(enumKey
, devInfo
->instanceId
, 0, samDesired
, &key
);
5764 RegCloseKey(enumKey
);
5771 static HKEY
SETUPDI_OpenDrvKey(HKEY RootKey
, struct DeviceInfo
*devInfo
, REGSAM samDesired
)
5773 LPWSTR DriverKey
= NULL
;
5777 HKEY hEnumKey
= NULL
;
5779 HKEY key
= INVALID_HANDLE_VALUE
;
5781 hKey
= SETUPDI_OpenDevKey(RootKey
, devInfo
, KEY_QUERY_VALUE
);
5782 if (hKey
== INVALID_HANDLE_VALUE
)
5784 /* Read the 'Driver' key */
5785 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_DRIVER
, NULL
, &dwRegType
, NULL
, &dwLength
);
5786 if (rc
!= ERROR_SUCCESS
)
5791 else if (dwRegType
!= REG_SZ
)
5793 SetLastError(ERROR_GEN_FAILURE
);
5796 DriverKey
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
5799 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5802 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_DRIVER
, NULL
, &dwRegType
, (LPBYTE
)DriverKey
, &dwLength
);
5803 if (rc
!= ERROR_SUCCESS
)
5810 /* Need to open the driver key */
5813 REGSTR_PATH_CLASS_NT
,
5817 if (rc
!= ERROR_SUCCESS
)
5828 if (rc
!= ERROR_SUCCESS
)
5836 if (hEnumKey
!= NULL
)
5837 RegCloseKey(hEnumKey
);
5838 if (hKey
!= NULL
&& hKey
!= key
)
5841 HeapFree(GetProcessHeap(), 0, DriverKey
);
5845 /***********************************************************************
5846 * SetupDiOpenDevRegKey (SETUPAPI.@)
5848 HKEY WINAPI
SetupDiOpenDevRegKey(
5849 HDEVINFO DeviceInfoSet
,
5850 PSP_DEVINFO_DATA DeviceInfoData
,
5856 struct DeviceInfoSet
*set
= DeviceInfoSet
;
5857 struct DeviceInfo
*devInfo
;
5858 HKEY key
= INVALID_HANDLE_VALUE
;
5861 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
5862 Scope
, HwProfile
, KeyType
, samDesired
);
5864 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
5866 SetLastError(ERROR_INVALID_HANDLE
);
5867 return INVALID_HANDLE_VALUE
;
5869 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5871 SetLastError(ERROR_INVALID_HANDLE
);
5872 return INVALID_HANDLE_VALUE
;
5874 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
5875 || !DeviceInfoData
->Reserved
)
5877 SetLastError(ERROR_INVALID_PARAMETER
);
5878 return INVALID_HANDLE_VALUE
;
5880 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
5882 SetLastError(ERROR_INVALID_FLAGS
);
5883 return INVALID_HANDLE_VALUE
;
5885 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
5887 SetLastError(ERROR_INVALID_FLAGS
);
5888 return INVALID_HANDLE_VALUE
;
5890 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5891 if (devInfo
->set
!= set
)
5893 SetLastError(ERROR_INVALID_PARAMETER
);
5894 return INVALID_HANDLE_VALUE
;
5896 if (Scope
!= DICS_FLAG_GLOBAL
)
5898 RootKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, 0);
5899 if (RootKey
== INVALID_HANDLE_VALUE
)
5900 return INVALID_HANDLE_VALUE
;
5903 RootKey
= set
->HKLM
;
5907 key
= SETUPDI_OpenDevKey(RootKey
, devInfo
, samDesired
);
5910 key
= SETUPDI_OpenDrvKey(RootKey
, devInfo
, samDesired
);
5913 WARN("unknown KeyType %d\n", KeyType
);
5915 if (RootKey
!= set
->HKLM
)
5916 RegCloseKey(RootKey
);
5920 static BOOL
SETUPDI_DeleteDevKey(HKEY RootKey
, struct DeviceInfo
*devInfo
)
5926 static BOOL
SETUPDI_DeleteDrvKey(HKEY RootKey
, struct DeviceInfo
*devInfo
)
5932 /***********************************************************************
5933 * SetupDiDeleteDevRegKey (SETUPAPI.@)
5935 BOOL WINAPI
SetupDiDeleteDevRegKey(
5936 HDEVINFO DeviceInfoSet
,
5937 PSP_DEVINFO_DATA DeviceInfoData
,
5942 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
5943 struct DeviceInfo
*devInfo
;
5947 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
5950 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
5952 SetLastError(ERROR_INVALID_HANDLE
);
5955 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5957 SetLastError(ERROR_INVALID_HANDLE
);
5960 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
5961 || !DeviceInfoData
->Reserved
)
5963 SetLastError(ERROR_INVALID_PARAMETER
);
5966 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
5968 SetLastError(ERROR_INVALID_FLAGS
);
5971 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
5973 SetLastError(ERROR_INVALID_FLAGS
);
5976 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5977 if (devInfo
->set
!= set
)
5979 SetLastError(ERROR_INVALID_PARAMETER
);
5982 if (Scope
!= DICS_FLAG_GLOBAL
)
5984 RootKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, 0);
5985 if (RootKey
== INVALID_HANDLE_VALUE
)
5989 RootKey
= set
->HKLM
;
5993 ret
= SETUPDI_DeleteDevKey(RootKey
, devInfo
);
5996 ret
= SETUPDI_DeleteDrvKey(RootKey
, devInfo
);
5999 ret
= SETUPDI_DeleteDevKey(RootKey
, devInfo
);
6001 ret
= SETUPDI_DeleteDrvKey(RootKey
, devInfo
);
6004 WARN("unknown KeyType %d\n", KeyType
);
6006 if (RootKey
!= set
->HKLM
)
6007 RegCloseKey(RootKey
);