2 * SetupAPI device installer
4 * Copyright 2000 Andreas Mohr for CodeWeavers
5 * 2005-2006 Hervé Poussineau (hpoussin@reactos.org)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "setupapi_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
26 /* Unicode constants */
27 static const WCHAR BackSlash
[] = {'\\',0};
28 static const WCHAR ClassGUID
[] = {'C','l','a','s','s','G','U','I','D',0};
29 static const WCHAR Class
[] = {'C','l','a','s','s',0};
30 static const WCHAR DateFormat
[] = {'%','u','-','%','u','-','%','u',0};
31 static const WCHAR DotCoInstallers
[] = {'.','C','o','I','n','s','t','a','l','l','e','r','s',0};
32 static const WCHAR DotHW
[] = {'.','H','W',0};
33 static const WCHAR DotServices
[] = {'.','S','e','r','v','i','c','e','s',0};
34 static const WCHAR InfDirectory
[] = {'i','n','f','\\',0};
35 static const WCHAR InstanceKeyFormat
[] = {'%','0','4','l','u',0};
36 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
37 static const WCHAR VersionFormat
[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
39 static const WCHAR REGSTR_DRIVER_DATE
[] = {'D','r','i','v','e','r','D','a','t','e',0};
40 static const WCHAR REGSTR_DRIVER_DATE_DATA
[] = {'D','r','i','v','e','r','D','a','t','e','D','a','t','a',0};
41 static const WCHAR REGSTR_DRIVER_VERSION
[] = {'D','r','i','v','e','r','V','e','r','s','i','o','n',0};
42 static const WCHAR REGSTR_SECURITY
[] = {'S','e','c','u','r','i','t','y',0};
43 static const WCHAR REGSTR_UI_NUMBER_DESC_FORMAT
[] = {'U','I','N','u','m','b','e','r','D','e','s','c','F','o','r','m','a','t',0};
46 (CALLBACK
* CLASS_INSTALL_PROC
) (
47 IN DI_FUNCTION InstallFunction
,
48 IN HDEVINFO DeviceInfoSet
,
49 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
);
51 (WINAPI
* DEFAULT_CLASS_INSTALL_PROC
) (
52 IN HDEVINFO DeviceInfoSet
,
53 IN OUT PSP_DEVINFO_DATA DeviceInfoData
);
55 (CALLBACK
* COINSTALLER_PROC
) (
56 IN DI_FUNCTION InstallFunction
,
57 IN HDEVINFO DeviceInfoSet
,
58 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
59 IN OUT PCOINSTALLER_CONTEXT_DATA Context
);
61 struct CoInstallerElement
66 COINSTALLER_PROC Function
;
67 BOOL DoPostProcessing
;
71 struct GetSectionCallbackInfo
73 PSP_ALTPLATFORM_INFO PlatformInfo
;
77 WCHAR BestSection
[LINE_LEN
+ 1];
78 DWORD BestScore1
, BestScore2
, BestScore3
, BestScore4
, BestScore5
;
83 static void SETUPDI_GuidToString(const GUID
*guid
, LPWSTR guidStr
)
85 static const WCHAR fmt
[] = {'{','%','0','8','X','-','%','0','4','X','-',
86 '%','0','4','X','-','%','0','2','X','%','0','2','X','-','%','0','2',
87 'X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%',
90 sprintfW(guidStr
, fmt
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
91 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
92 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
96 GetErrorCodeFromCrCode(const IN CONFIGRET cr
)
100 case CR_ACCESS_DENIED
: return ERROR_ACCESS_DENIED
;
101 case CR_BUFFER_SMALL
: return ERROR_INSUFFICIENT_BUFFER
;
102 case CR_CALL_NOT_IMPLEMENTED
: return ERROR_CALL_NOT_IMPLEMENTED
;
103 case CR_FAILURE
: return ERROR_GEN_FAILURE
;
104 case CR_INVALID_DATA
: return ERROR_INVALID_USER_BUFFER
;
105 case CR_INVALID_DEVICE_ID
: return ERROR_INVALID_PARAMETER
;
106 case CR_INVALID_MACHINENAME
: return ERROR_INVALID_COMPUTERNAME
;
107 case CR_INVALID_DEVNODE
: return ERROR_INVALID_PARAMETER
;
108 case CR_INVALID_FLAG
: return ERROR_INVALID_FLAGS
;
109 case CR_INVALID_POINTER
: return ERROR_INVALID_PARAMETER
;
110 case CR_INVALID_PROPERTY
: return ERROR_INVALID_PARAMETER
;
111 case CR_NO_SUCH_DEVNODE
: return ERROR_FILE_NOT_FOUND
;
112 case CR_NO_SUCH_REGISTRY_KEY
: return ERROR_FILE_NOT_FOUND
;
113 case CR_NO_SUCH_VALUE
: return ERROR_FILE_NOT_FOUND
;
114 case CR_OUT_OF_MEMORY
: return ERROR_NOT_ENOUGH_MEMORY
;
115 case CR_REGISTRY_ERROR
: return ERROR_GEN_FAILURE
;
116 case CR_SUCCESS
: return ERROR_SUCCESS
;
117 default: return ERROR_GEN_FAILURE
;
120 /* Does not happen */
123 /* Lower scores are best ones */
126 IN LPCWSTR SectionName
,
127 IN PSP_ALTPLATFORM_INFO PlatformInfo
,
130 OUT PDWORD ScorePlatform
,
131 OUT PDWORD ScoreMajorVersion
,
132 OUT PDWORD ScoreMinorVersion
,
133 OUT PDWORD ScoreProductType
,
134 OUT PDWORD ScoreSuiteMask
)
136 LPWSTR Section
= NULL
;
137 LPCWSTR pExtensionPlatform
, pExtensionArchitecture
;
142 static const WCHAR ExtensionPlatformNone
[] = {'.',0};
143 static const WCHAR ExtensionPlatformNT
[] = {'.','N','T',0};
144 static const WCHAR ExtensionPlatformWindows
[] = {'.','W','i','n',0};
146 static const WCHAR ExtensionArchitectureNone
[] = {0};
147 static const WCHAR ExtensionArchitecturealpha
[] = {'a','l','p','h','a',0};
148 static const WCHAR ExtensionArchitectureamd64
[] = {'A','M','D','6','4',0};
149 static const WCHAR ExtensionArchitectureia64
[] = {'I','A','6','4',0};
150 static const WCHAR ExtensionArchitecturemips
[] = {'m','i','p','s',0};
151 static const WCHAR ExtensionArchitectureppc
[] = {'p','p','c',0};
152 static const WCHAR ExtensionArchitecturex86
[] = {'x','8','6',0};
154 TRACE("%s %p 0x%x 0x%x\n",
155 debugstr_w(SectionName
), PlatformInfo
, ProductType
, SuiteMask
);
157 *ScorePlatform
= *ScoreMajorVersion
= *ScoreMinorVersion
= *ScoreProductType
= *ScoreSuiteMask
= 0;
159 Section
= DuplicateString(SectionName
);
162 TRACE("DuplicateString() failed\n");
166 /* Set various extensions values */
167 switch (PlatformInfo
->Platform
)
169 case VER_PLATFORM_WIN32_WINDOWS
:
170 pExtensionPlatform
= ExtensionPlatformWindows
;
172 case VER_PLATFORM_WIN32_NT
:
173 pExtensionPlatform
= ExtensionPlatformNT
;
176 ERR("Unknown platform 0x%lx\n", PlatformInfo
->Platform
);
177 pExtensionPlatform
= ExtensionPlatformNone
;
180 switch (PlatformInfo
->ProcessorArchitecture
)
182 case PROCESSOR_ARCHITECTURE_ALPHA
:
183 pExtensionArchitecture
= ExtensionArchitecturealpha
;
185 case PROCESSOR_ARCHITECTURE_AMD64
:
186 pExtensionArchitecture
= ExtensionArchitectureamd64
;
188 case PROCESSOR_ARCHITECTURE_IA64
:
189 pExtensionArchitecture
= ExtensionArchitectureia64
;
191 case PROCESSOR_ARCHITECTURE_INTEL
:
192 pExtensionArchitecture
= ExtensionArchitecturex86
;
194 case PROCESSOR_ARCHITECTURE_MIPS
:
195 pExtensionArchitecture
= ExtensionArchitecturemips
;
197 case PROCESSOR_ARCHITECTURE_PPC
:
198 pExtensionArchitecture
= ExtensionArchitectureppc
;
201 ERR("Unknown processor architecture 0x%x\n", PlatformInfo
->ProcessorArchitecture
);
202 case PROCESSOR_ARCHITECTURE_UNKNOWN
:
203 pExtensionArchitecture
= ExtensionArchitectureNone
;
209 * Field[1] Architecture
210 * Field[2] Major version
211 * Field[3] Minor version
212 * Field[4] Product type
213 * Field[5] Suite mask
214 * Remark: lastests fields may be NULL if the information is not provided
217 if (Fields
[0] == NULL
)
219 TRACE("No extension found\n");
220 *ScorePlatform
= *ScoreMajorVersion
= *ScoreMinorVersion
= *ScoreProductType
= *ScoreSuiteMask
= ULONG_MAX
;
224 Fields
[1] = Fields
[0] + 1;
225 Fields
[2] = Fields
[3] = Fields
[4] = Fields
[5] = NULL
;
226 for (i
= 2; Fields
[i
- 1] != NULL
&& i
< 6; i
++)
228 Fields
[i
] = wcschr(Fields
[i
- 1], '.');
232 *(Fields
[i
] - 1) = UNICODE_NULL
;
235 /* Take care of first 2 fields */
236 if (strncmpiW(Fields
[0], ExtensionPlatformWindows
, strlenW(ExtensionPlatformWindows
)) == 0)
238 if (PlatformInfo
->Platform
!= VER_PLATFORM_WIN32_WINDOWS
)
240 TRACE("Mismatch on platform field\n");
243 Fields
[1] += wcslen(ExtensionPlatformWindows
) - 1;
245 else if (strncmpiW(Fields
[0], ExtensionPlatformNT
, strlenW(ExtensionPlatformNT
)) == 0)
247 if (PlatformInfo
->Platform
!= VER_PLATFORM_WIN32_NT
)
249 TRACE("Mismatch on platform field\n");
252 Fields
[1] += wcslen(ExtensionPlatformNT
) - 1;
256 /* No platform specified */
257 *ScorePlatform
|= 0x02;
259 if (strcmpiW(Fields
[1], ExtensionArchitectureNone
) == 0)
261 /* No architecture specified */
262 *ScorePlatform
|= 0x01;
264 else if (strcmpiW(Fields
[1], pExtensionArchitecture
) != 0)
266 TRACE("Mismatch on architecture field ('%s' and '%s')\n",
267 debugstr_w(Fields
[1]), debugstr_w(pExtensionArchitecture
));
271 /* Check if informations are matching */
272 if (Fields
[2] && *Fields
[2])
274 DWORD MajorVersion
, MinorVersion
= 0;
275 MajorVersion
= strtoulW(Fields
[2], NULL
, 0);
276 if ((MajorVersion
== 0 || MajorVersion
== ULONG_MAX
) &&
277 (errno
== ERANGE
|| errno
== EINVAL
))
279 TRACE("Wrong MajorVersion ('%s')\n", debugstr_w(Fields
[2]));
282 if (Fields
[3] && *Fields
[3])
284 MinorVersion
= strtoulW(Fields
[3], NULL
, 0);
285 if ((MinorVersion
== 0 || MinorVersion
== ULONG_MAX
) &&
286 (errno
== ERANGE
|| errno
== EINVAL
))
288 TRACE("Wrong MinorVersion ('%s')\n", debugstr_w(Fields
[3]));
292 if (PlatformInfo
->MajorVersion
< MajorVersion
||
293 (PlatformInfo
->MajorVersion
== MajorVersion
&& PlatformInfo
->MinorVersion
< MinorVersion
))
295 TRACE("Mismatch on version field (%lu.%lu and %lu.%lu)\n",
296 MajorVersion
, MinorVersion
, PlatformInfo
->MajorVersion
, PlatformInfo
->MinorVersion
);
299 *ScoreMajorVersion
= MajorVersion
- PlatformInfo
->MajorVersion
;
300 if (MajorVersion
== PlatformInfo
->MajorVersion
)
301 *ScoreMinorVersion
= MinorVersion
- PlatformInfo
->MinorVersion
;
303 *ScoreMinorVersion
= MinorVersion
;
305 else if (Fields
[3] && *Fields
[3])
307 TRACE("Minor version found without major version\n");
312 *ScoreMajorVersion
= PlatformInfo
->MajorVersion
;
313 *ScoreMinorVersion
= PlatformInfo
->MinorVersion
;
316 if (Fields
[4] && *Fields
[4])
318 DWORD CurrentProductType
;
319 CurrentProductType
= strtoulW(Fields
[4], NULL
, 0);
320 if ((CurrentProductType
== 0 || CurrentProductType
== ULONG_MAX
) &&
321 (errno
== ERANGE
|| errno
== EINVAL
))
323 TRACE("Wrong Product type ('%s')\n", debugstr_w(Fields
[4]));
326 if (CurrentProductType
!= ProductType
)
328 TRACE("Mismatch on product type (0x%08lx and 0x%08x)\n",
329 CurrentProductType
, ProductType
);
334 *ScoreProductType
= 1;
336 if (Fields
[5] && *Fields
[5])
338 DWORD CurrentSuiteMask
;
339 CurrentSuiteMask
= strtoulW(Fields
[5], NULL
, 0);
340 if ((CurrentSuiteMask
== 0 || CurrentSuiteMask
== ULONG_MAX
) &&
341 (errno
== ERANGE
|| errno
== EINVAL
))
343 TRACE("Wrong Suite mask ('%s')\n", debugstr_w(Fields
[5]));
346 if ((CurrentSuiteMask
& ~SuiteMask
) != 0)
348 TRACE("Mismatch on suite mask (0x%08lx and 0x%08x)\n",
349 CurrentSuiteMask
, SuiteMask
);
352 *ScoreSuiteMask
= SuiteMask
& ~CurrentSuiteMask
;
355 *ScoreSuiteMask
= SuiteMask
;
366 IN LPCWSTR SectionName
,
369 struct GetSectionCallbackInfo
*info
= Context
;
370 DWORD Score1
, Score2
, Score3
, Score4
, Score5
;
373 if (SectionName
[info
->PrefixLength
] != '.')
376 ret
= CheckSectionValid(
377 &SectionName
[info
->PrefixLength
],
381 &Score1
, &Score2
, &Score3
, &Score4
, &Score5
);
384 TRACE("Section %s not compatible\n", debugstr_w(SectionName
));
387 if (Score1
> info
->BestScore1
) goto done
;
388 if (Score1
< info
->BestScore1
) goto bettersection
;
389 if (Score2
> info
->BestScore2
) goto done
;
390 if (Score2
< info
->BestScore2
) goto bettersection
;
391 if (Score3
> info
->BestScore3
) goto done
;
392 if (Score3
< info
->BestScore3
) goto bettersection
;
393 if (Score4
> info
->BestScore4
) goto done
;
394 if (Score4
< info
->BestScore4
) goto bettersection
;
395 if (Score5
> info
->BestScore5
) goto done
;
396 if (Score5
< info
->BestScore5
) goto bettersection
;
400 strcpyW(info
->BestSection
, SectionName
);
401 info
->BestScore1
= Score1
;
402 info
->BestScore2
= Score2
;
403 info
->BestScore3
= Score3
;
404 info
->BestScore4
= Score4
;
405 info
->BestScore5
= Score5
;
411 /***********************************************************************
412 * SetupDiGetActualSectionToInstallExW (SETUPAPI.@)
415 SetupDiGetActualSectionToInstallExW(
417 IN PCWSTR InfSectionName
,
418 IN PSP_ALTPLATFORM_INFO AlternatePlatformInfo OPTIONAL
,
419 OUT PWSTR InfSectionWithExt OPTIONAL
,
420 IN DWORD InfSectionWithExtSize
,
421 OUT PDWORD RequiredSize OPTIONAL
,
422 OUT PWSTR
* Extension OPTIONAL
,
427 TRACE("%p %s %p %p %lu %p %p %p\n", InfHandle
, debugstr_w(InfSectionName
),
428 AlternatePlatformInfo
, InfSectionWithExt
, InfSectionWithExtSize
,
429 RequiredSize
, Extension
, Reserved
);
431 if (!InfHandle
|| InfHandle
== (HINF
)INVALID_HANDLE_VALUE
)
432 SetLastError(ERROR_INVALID_HANDLE
);
433 else if (!InfSectionName
)
434 SetLastError(ERROR_INVALID_PARAMETER
);
435 else if (AlternatePlatformInfo
&& AlternatePlatformInfo
->cbSize
!= sizeof(SP_ALTPLATFORM_INFO
))
436 SetLastError(ERROR_INVALID_USER_BUFFER
);
437 else if (Reserved
!= NULL
)
438 SetLastError(ERROR_INVALID_PARAMETER
);
441 static SP_ALTPLATFORM_INFO CurrentPlatform
= { 0, };
442 static BYTE CurrentProductType
= 0;
443 static WORD CurrentSuiteMask
= 0;
444 PSP_ALTPLATFORM_INFO pPlatformInfo
= &CurrentPlatform
;
445 struct GetSectionCallbackInfo CallbackInfo
;
450 /* Fill platform info if needed */
451 if (AlternatePlatformInfo
)
453 pPlatformInfo
= AlternatePlatformInfo
;
459 if (CurrentPlatform
.cbSize
!= sizeof(SP_ALTPLATFORM_INFO
))
461 /* That's the first time we go here. We need to fill in the structure */
462 OSVERSIONINFOEX VersionInfo
;
463 SYSTEM_INFO SystemInfo
;
464 VersionInfo
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
465 ret
= GetVersionExW((OSVERSIONINFO
*)&VersionInfo
);
468 GetSystemInfo(&SystemInfo
);
469 CurrentPlatform
.cbSize
= sizeof(SP_ALTPLATFORM_INFO
);
470 CurrentPlatform
.Platform
= VersionInfo
.dwPlatformId
;
471 CurrentPlatform
.MajorVersion
= VersionInfo
.dwMajorVersion
;
472 CurrentPlatform
.MinorVersion
= VersionInfo
.dwMinorVersion
;
473 CurrentPlatform
.ProcessorArchitecture
= SystemInfo
.wProcessorArchitecture
;
474 CurrentPlatform
.Reserved
= 0;
475 CurrentProductType
= VersionInfo
.wProductType
;
476 CurrentSuiteMask
= VersionInfo
.wSuiteMask
;
478 ProductType
= CurrentProductType
;
479 SuiteMask
= CurrentSuiteMask
;
482 CallbackInfo
.PlatformInfo
= pPlatformInfo
;
483 CallbackInfo
.ProductType
= ProductType
;
484 CallbackInfo
.SuiteMask
= SuiteMask
;
485 CallbackInfo
.PrefixLength
= strlenW(InfSectionName
);
486 CallbackInfo
.BestScore1
= ULONG_MAX
;
487 CallbackInfo
.BestScore2
= ULONG_MAX
;
488 CallbackInfo
.BestScore3
= ULONG_MAX
;
489 CallbackInfo
.BestScore4
= ULONG_MAX
;
490 CallbackInfo
.BestScore5
= ULONG_MAX
;
491 strcpyW(CallbackInfo
.BestSection
, InfSectionName
);
492 if (!EnumerateSectionsStartingWith(
498 SetLastError(ERROR_GEN_FAILURE
);
502 dwFullLength
= lstrlenW(CallbackInfo
.BestSection
);
503 if (RequiredSize
!= NULL
)
504 *RequiredSize
= dwFullLength
+ 1;
506 if (InfSectionWithExtSize
> 0)
508 if (InfSectionWithExtSize
< dwFullLength
+ 1)
510 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
513 strcpyW(InfSectionWithExt
, CallbackInfo
.BestSection
);
516 DWORD dwLength
= lstrlenW(InfSectionName
);
517 *Extension
= (dwLength
== dwFullLength
) ? NULL
: &InfSectionWithExt
[dwLength
];
525 TRACE("Returning %d\n", ret
);
532 IN
struct DeviceInfoSet
*list
,
533 IN LPCWSTR InstancePath
,
534 IN LPCGUID pClassGuid
,
535 OUT
struct DeviceInfo
**pDeviceInfo
)
539 struct DeviceInfo
*deviceInfo
;
543 size
= FIELD_OFFSET(struct DeviceInfo
, Data
) + (strlenW(InstancePath
) + 1) * sizeof(WCHAR
);
544 deviceInfo
= HeapAlloc(GetProcessHeap(), 0, size
);
547 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
550 ZeroMemory(deviceInfo
, size
);
552 cr
= CM_Locate_DevNode_ExW(&deviceInfo
->dnDevInst
, (DEVINSTID_W
)InstancePath
, CM_LOCATE_DEVNODE_PHANTOM
, list
->hMachine
);
553 if (cr
!= CR_SUCCESS
)
555 SetLastError(GetErrorCodeFromCrCode(cr
));
559 deviceInfo
->set
= list
;
560 deviceInfo
->InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
561 strcpyW(deviceInfo
->Data
, InstancePath
);
562 deviceInfo
->instanceId
= deviceInfo
->Data
;
563 deviceInfo
->UniqueId
= strrchrW(deviceInfo
->Data
, '\\');
564 deviceInfo
->DeviceDescription
= NULL
;
565 memcpy(&deviceInfo
->ClassGuid
, pClassGuid
, sizeof(GUID
));
566 deviceInfo
->CreationFlags
= 0;
567 InitializeListHead(&deviceInfo
->DriverListHead
);
568 InitializeListHead(&deviceInfo
->InterfaceListHead
);
570 *pDeviceInfo
= deviceInfo
;
576 DestroyClassInstallParams(struct ClassInstallParams
* installParams
)
578 HeapFree(GetProcessHeap(), 0, installParams
->PropChangeParams
);
579 HeapFree(GetProcessHeap(), 0, installParams
->AddPropertyPageData
);
584 DestroyDeviceInfo(struct DeviceInfo
*deviceInfo
)
586 PLIST_ENTRY ListEntry
;
587 struct DriverInfoElement
*driverInfo
;
588 struct DeviceInterface
*deviceInterface
;
590 while (!IsListEmpty(&deviceInfo
->DriverListHead
))
592 ListEntry
= RemoveHeadList(&deviceInfo
->DriverListHead
);
593 driverInfo
= CONTAINING_RECORD(ListEntry
, struct DriverInfoElement
, ListEntry
);
594 if (!DestroyDriverInfoElement(driverInfo
))
597 while (!IsListEmpty(&deviceInfo
->InterfaceListHead
))
599 ListEntry
= RemoveHeadList(&deviceInfo
->InterfaceListHead
);
600 deviceInterface
= CONTAINING_RECORD(ListEntry
, struct DeviceInterface
, ListEntry
);
601 if (!DestroyDeviceInterface(deviceInterface
))
604 DestroyClassInstallParams(&deviceInfo
->ClassInstallParams
);
605 return HeapFree(GetProcessHeap(), 0, deviceInfo
);
609 DestroyDeviceInfoSet(struct DeviceInfoSet
* list
)
611 PLIST_ENTRY ListEntry
;
612 struct DeviceInfo
*deviceInfo
;
614 while (!IsListEmpty(&list
->ListHead
))
616 ListEntry
= RemoveHeadList(&list
->ListHead
);
617 deviceInfo
= CONTAINING_RECORD(ListEntry
, struct DeviceInfo
, ListEntry
);
618 if (!DestroyDeviceInfo(deviceInfo
))
621 if (list
->HKLM
!= HKEY_LOCAL_MACHINE
)
622 RegCloseKey(list
->HKLM
);
623 CM_Disconnect_Machine(list
->hMachine
);
624 DestroyClassInstallParams(&list
->ClassInstallParams
);
625 return HeapFree(GetProcessHeap(), 0, list
);
628 /***********************************************************************
629 * SetupDiBuildClassInfoList (SETUPAPI.@)
631 * Returns a list of setup class GUIDs that identify the classes
632 * that are installed on a local machine.
635 * Flags [I] control exclusion of classes from the list.
636 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
637 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
638 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
644 BOOL WINAPI
SetupDiBuildClassInfoList(
646 LPGUID ClassGuidList
,
647 DWORD ClassGuidListSize
,
651 return SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
652 ClassGuidListSize
, RequiredSize
,
656 /***********************************************************************
657 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
659 * Returns a list of setup class GUIDs that identify the classes
660 * that are installed on a local or remote macine.
663 * Flags [I] control exclusion of classes from the list.
664 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
665 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
666 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
667 * MachineName [I] name of a remote machine.
668 * Reserved [I] must be NULL.
674 BOOL WINAPI
SetupDiBuildClassInfoListExA(
676 LPGUID ClassGuidList
,
677 DWORD ClassGuidListSize
,
682 LPWSTR MachineNameW
= NULL
;
685 TRACE("0x%lx %p %lu %p %s %p\n", Flags
, ClassGuidList
,
686 ClassGuidListSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
690 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
691 if (MachineNameW
== NULL
) return FALSE
;
694 bResult
= SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
695 ClassGuidListSize
, RequiredSize
,
696 MachineNameW
, Reserved
);
698 MyFree(MachineNameW
);
703 /***********************************************************************
704 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
706 * Returns a list of setup class GUIDs that identify the classes
707 * that are installed on a local or remote macine.
710 * Flags [I] control exclusion of classes from the list.
711 * ClassGuidList [O] pointer to a GUID-typed array that receives a list of setup class GUIDs.
712 * ClassGuidListSize [I] The number of GUIDs in the array (ClassGuidList).
713 * RequiredSize [O] pointer, which receives the number of GUIDs that are returned.
714 * MachineName [I] name of a remote machine.
715 * Reserved [I] must be NULL.
721 BOOL WINAPI
SetupDiBuildClassInfoListExW(
723 LPGUID ClassGuidList
,
724 DWORD ClassGuidListSize
,
730 HKEY hClassesKey
= INVALID_HANDLE_VALUE
;
735 DWORD dwGuidListIndex
= 0;
737 TRACE("0x%lx %p %lu %p %s %p\n", Flags
, ClassGuidList
,
738 ClassGuidListSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
742 SetLastError(ERROR_INVALID_PARAMETER
);
745 else if (!ClassGuidList
&& ClassGuidListSize
> 0)
747 SetLastError(ERROR_INVALID_PARAMETER
);
751 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
752 KEY_ENUMERATE_SUB_KEYS
,
756 if (hClassesKey
== INVALID_HANDLE_VALUE
)
761 for (dwIndex
= 0; ; dwIndex
++)
764 lError
= RegEnumKeyExW(hClassesKey
,
772 TRACE("RegEnumKeyExW() returns %d\n", lError
);
773 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
775 TRACE("Key name: %s\n", debugstr_w(szKeyName
));
777 if (RegOpenKeyExW(hClassesKey
,
783 RegCloseKey(hClassesKey
);
787 if (!RegQueryValueExW(hClassKey
,
788 REGSTR_VAL_NOUSECLASS
,
794 TRACE("'NoUseClass' value found!\n");
795 RegCloseKey(hClassKey
);
799 if ((Flags
& DIBCI_NOINSTALLCLASS
) &&
800 (!RegQueryValueExW(hClassKey
,
801 REGSTR_VAL_NOINSTALLCLASS
,
807 TRACE("'NoInstallClass' value found!\n");
808 RegCloseKey(hClassKey
);
812 if ((Flags
& DIBCI_NODISPLAYCLASS
) &&
813 (!RegQueryValueExW(hClassKey
,
814 REGSTR_VAL_NODISPLAYCLASS
,
820 TRACE("'NoDisplayClass' value found!\n");
821 RegCloseKey(hClassKey
);
825 RegCloseKey(hClassKey
);
827 TRACE("Guid: %s\n", debugstr_w(szKeyName
));
828 if (dwGuidListIndex
< ClassGuidListSize
)
830 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
834 TRACE("Guid: %p\n", &szKeyName
[1]);
836 UuidFromStringW(&szKeyName
[1],
837 &ClassGuidList
[dwGuidListIndex
]);
843 if (lError
!= ERROR_SUCCESS
)
847 RegCloseKey(hClassesKey
);
849 if (RequiredSize
!= NULL
)
850 *RequiredSize
= dwGuidListIndex
;
852 if (ClassGuidListSize
< dwGuidListIndex
)
854 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
861 /***********************************************************************
862 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
864 BOOL WINAPI
SetupDiClassGuidsFromNameA(
866 LPGUID ClassGuidList
,
867 DWORD ClassGuidListSize
,
870 return SetupDiClassGuidsFromNameExA(ClassName
, ClassGuidList
,
871 ClassGuidListSize
, RequiredSize
,
875 /***********************************************************************
876 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
878 BOOL WINAPI
SetupDiClassGuidsFromNameW(
880 LPGUID ClassGuidList
,
881 DWORD ClassGuidListSize
,
884 return SetupDiClassGuidsFromNameExW(ClassName
, ClassGuidList
,
885 ClassGuidListSize
, RequiredSize
,
889 /***********************************************************************
890 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
892 BOOL WINAPI
SetupDiClassGuidsFromNameExA(
894 LPGUID ClassGuidList
,
895 DWORD ClassGuidListSize
,
900 LPWSTR ClassNameW
= NULL
;
901 LPWSTR MachineNameW
= NULL
;
904 TRACE("%s %p %lu %p %s %p\n", debugstr_a(ClassName
), ClassGuidList
,
905 ClassGuidListSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
909 SetLastError(ERROR_INVALID_PARAMETER
);
913 ClassNameW
= MultiByteToUnicode(ClassName
, CP_ACP
);
914 if (ClassNameW
== NULL
)
919 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
920 if (MachineNameW
== NULL
)
927 bResult
= SetupDiClassGuidsFromNameExW(ClassNameW
, ClassGuidList
,
928 ClassGuidListSize
, RequiredSize
,
929 MachineNameW
, Reserved
);
931 MyFree(MachineNameW
);
937 /***********************************************************************
938 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
940 BOOL WINAPI
SetupDiClassGuidsFromNameExW(
942 LPGUID ClassGuidList
,
943 DWORD ClassGuidListSize
,
949 WCHAR szClassName
[MAX_CLASS_NAME_LEN
];
955 DWORD dwGuidListIndex
= 0;
957 TRACE("%s %p %lu %p %s %p\n", debugstr_w(ClassName
), ClassGuidList
,
958 ClassGuidListSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
960 if (!ClassName
|| !RequiredSize
)
962 SetLastError(ERROR_INVALID_PARAMETER
);
965 if (!ClassGuidList
&& ClassGuidListSize
> 0)
967 SetLastError(ERROR_INVALID_PARAMETER
);
972 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
973 KEY_ENUMERATE_SUB_KEYS
,
977 if (hClassesKey
== INVALID_HANDLE_VALUE
)
982 for (dwIndex
= 0; ; dwIndex
++)
985 lError
= RegEnumKeyExW(hClassesKey
,
993 TRACE("RegEnumKeyExW() returns %d\n", lError
);
994 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
996 TRACE("Key name: %p\n", szKeyName
);
998 if (RegOpenKeyExW(hClassesKey
,
1004 RegCloseKey(hClassesKey
);
1008 dwLength
= MAX_CLASS_NAME_LEN
* sizeof(WCHAR
);
1009 if (!RegQueryValueExW(hClassKey
,
1013 (LPBYTE
)szClassName
,
1016 TRACE("Class name: %p\n", szClassName
);
1018 if (strcmpiW(szClassName
, ClassName
) == 0)
1020 TRACE("Found matching class name\n");
1022 TRACE("Guid: %p\n", szKeyName
);
1023 if (dwGuidListIndex
< ClassGuidListSize
)
1025 if (szKeyName
[0] == '{' && szKeyName
[37] == '}')
1029 TRACE("Guid: %p\n", &szKeyName
[1]);
1031 UuidFromStringW(&szKeyName
[1],
1032 &ClassGuidList
[dwGuidListIndex
]);
1039 RegCloseKey(hClassKey
);
1042 if (lError
!= ERROR_SUCCESS
)
1046 RegCloseKey(hClassesKey
);
1048 if (RequiredSize
!= NULL
)
1049 *RequiredSize
= dwGuidListIndex
;
1051 if (ClassGuidListSize
< dwGuidListIndex
)
1053 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1060 /***********************************************************************
1061 * SetupDiClassNameFromGuidA (SETUPAPI.@)
1063 BOOL WINAPI
SetupDiClassNameFromGuidA(
1064 const GUID
* ClassGuid
,
1066 DWORD ClassNameSize
,
1067 PDWORD RequiredSize
)
1069 return SetupDiClassNameFromGuidExA(ClassGuid
, ClassName
,
1070 ClassNameSize
, RequiredSize
,
1074 /***********************************************************************
1075 * SetupDiClassNameFromGuidW (SETUPAPI.@)
1077 BOOL WINAPI
SetupDiClassNameFromGuidW(
1078 const GUID
* ClassGuid
,
1080 DWORD ClassNameSize
,
1081 PDWORD RequiredSize
)
1083 return SetupDiClassNameFromGuidExW(ClassGuid
, ClassName
,
1084 ClassNameSize
, RequiredSize
,
1088 /***********************************************************************
1089 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
1091 BOOL WINAPI
SetupDiClassNameFromGuidExA(
1092 const GUID
* ClassGuid
,
1094 DWORD ClassNameSize
,
1095 PDWORD RequiredSize
,
1099 WCHAR ClassNameW
[MAX_CLASS_NAME_LEN
];
1100 LPWSTR MachineNameW
= NULL
;
1104 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1105 ret
= SetupDiClassNameFromGuidExW(ClassGuid
, ClassNameW
, MAX_CLASS_NAME_LEN
,
1106 NULL
, MachineNameW
, Reserved
);
1109 int len
= WideCharToMultiByte(CP_ACP
, 0, ClassNameW
, -1, ClassName
,
1110 ClassNameSize
, NULL
, NULL
);
1111 if (len
== 0 || len
> ClassNameSize
)
1113 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1116 else if (RequiredSize
)
1117 *RequiredSize
= len
;
1119 MyFree(MachineNameW
);
1123 /***********************************************************************
1124 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
1126 BOOL WINAPI
SetupDiClassNameFromGuidExW(
1127 const GUID
* ClassGuid
,
1129 DWORD ClassNameSize
,
1130 PDWORD RequiredSize
,
1139 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassName
,
1140 ClassNameSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
1142 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1147 if (hKey
== INVALID_HANDLE_VALUE
)
1152 if (RequiredSize
!= NULL
)
1155 if (RegQueryValueExW(hKey
,
1166 *RequiredSize
= dwLength
/ sizeof(WCHAR
) + 1;
1171 SetLastError(ERROR_INVALID_CLASS
);
1175 if (!ClassName
&& ClassNameSize
> 0)
1177 SetLastError(ERROR_INVALID_PARAMETER
);
1182 dwLength
= ClassNameSize
* sizeof(WCHAR
) - sizeof(UNICODE_NULL
);
1183 rc
= RegQueryValueExW(hKey
,
1189 if (rc
!= ERROR_SUCCESS
)
1195 if (dwRegType
!= REG_SZ
)
1197 SetLastError(ERROR_GEN_FAILURE
);
1202 if (ClassNameSize
> 1)
1203 ClassName
[ClassNameSize
] = UNICODE_NULL
;
1209 /***********************************************************************
1210 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
1213 SetupDiCreateDeviceInfoList(const GUID
*ClassGuid
,
1216 return SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
, NULL
, NULL
);
1219 /***********************************************************************
1220 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
1223 SetupDiCreateDeviceInfoListExA(const GUID
*ClassGuid
,
1228 LPWSTR MachineNameW
= NULL
;
1231 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1232 debugstr_a(MachineName
), Reserved
);
1236 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1237 if (MachineNameW
== NULL
)
1238 return INVALID_HANDLE_VALUE
;
1241 hDevInfo
= SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
,
1242 MachineNameW
, Reserved
);
1244 MyFree(MachineNameW
);
1249 /***********************************************************************
1250 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
1252 * Create an empty DeviceInfoSet list.
1255 * ClassGuid [I] if not NULL only devices with GUID ClcassGuid are associated
1257 * hwndParent [I] hwnd needed for interface related actions.
1258 * MachineName [I] name of machine to create emtpy DeviceInfoSet list, if NULL
1259 * local registry will be used.
1260 * Reserved [I] must be NULL
1263 * Success: empty list.
1264 * Failure: INVALID_HANDLE_VALUE.
1267 SetupDiCreateDeviceInfoListExW(const GUID
*ClassGuid
,
1272 struct DeviceInfoSet
*list
= NULL
;
1273 DWORD size
= FIELD_OFFSET(struct DeviceInfoSet
, szData
);
1276 HDEVINFO ret
= INVALID_HANDLE_VALUE
;
1278 TRACE("%s %p %s %p\n", debugstr_guid(ClassGuid
), hwndParent
,
1279 debugstr_w(MachineName
), Reserved
);
1281 if (MachineName
!= NULL
)
1283 SIZE_T len
= strlenW(MachineName
);
1284 if (len
>= SP_MAX_MACHINENAME_LENGTH
- 4)
1286 SetLastError(ERROR_INVALID_MACHINENAME
);
1289 size
+= (len
+ 3) * sizeof(WCHAR
);
1292 if (Reserved
!= NULL
)
1294 SetLastError(ERROR_INVALID_PARAMETER
);
1295 return INVALID_HANDLE_VALUE
;
1298 list
= MyMalloc(size
);
1301 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1302 return INVALID_HANDLE_VALUE
;
1304 ZeroMemory(list
, FIELD_OFFSET(struct DeviceInfoSet
, szData
));
1306 list
->magic
= SETUP_DEVICE_INFO_SET_MAGIC
;
1307 memcpy(&list
->ClassGuid
,
1308 ClassGuid
? ClassGuid
: &GUID_NULL
,
1309 sizeof(list
->ClassGuid
));
1310 list
->InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
1311 list
->InstallParams
.Flags
|= DI_CLASSINSTALLPARAMS
;
1312 list
->InstallParams
.hwndParent
= hwndParent
;
1315 rc
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &list
->HKLM
);
1316 if (rc
!= ERROR_SUCCESS
)
1318 SetLastError(ERROR_INVALID_MACHINENAME
);
1322 list
->szData
[0] = list
->szData
[1] = '\\';
1323 strcpyW(list
->szData
+ 2, MachineName
);
1324 list
->MachineName
= list
->szData
;
1328 list
->HKLM
= HKEY_LOCAL_MACHINE
;
1329 list
->MachineName
= NULL
;
1331 cr
= CM_Connect_MachineW(list
->MachineName
, &list
->hMachine
);
1332 if (cr
!= CR_SUCCESS
)
1334 SetLastError(GetErrorCodeFromCrCode(cr
));
1337 InitializeListHead(&list
->DriverListHead
);
1338 InitializeListHead(&list
->ListHead
);
1340 return (HDEVINFO
)list
;
1343 if (ret
== INVALID_HANDLE_VALUE
)
1347 if (list
->HKLM
!= NULL
&& list
->HKLM
!= HKEY_LOCAL_MACHINE
)
1348 RegCloseKey(list
->HKLM
);
1355 /***********************************************************************
1356 * SetupDiCreateDevRegKeyA (SETUPAPI.@)
1358 HKEY WINAPI
SetupDiCreateDevRegKeyA(
1359 HDEVINFO DeviceInfoSet
,
1360 PSP_DEVINFO_DATA DeviceInfoData
,
1365 PCSTR InfSectionName
)
1367 PWSTR InfSectionNameW
= NULL
;
1370 TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1371 HwProfile
, KeyType
, InfHandle
, debugstr_a(InfSectionName
));
1375 if (!InfSectionName
)
1377 SetLastError(ERROR_INVALID_PARAMETER
);
1378 return INVALID_HANDLE_VALUE
;
1382 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
1383 if (InfSectionNameW
== NULL
) return INVALID_HANDLE_VALUE
;
1386 key
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, Scope
,
1387 HwProfile
, KeyType
, InfHandle
, InfSectionNameW
);
1388 MyFree(InfSectionNameW
);
1393 OpenHardwareProfileKey(
1396 IN DWORD samDesired
);
1398 /***********************************************************************
1399 * SetupDiCreateDevRegKeyW (SETUPAPI.@)
1401 HKEY WINAPI
SetupDiCreateDevRegKeyW(
1402 HDEVINFO DeviceInfoSet
,
1403 PSP_DEVINFO_DATA DeviceInfoData
,
1408 PCWSTR InfSectionName
)
1410 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1411 HKEY key
= INVALID_HANDLE_VALUE
;
1413 TRACE("%p %p %lu %lu %lu %p %s\n", DeviceInfoSet
, DeviceInfoData
, Scope
,
1414 HwProfile
, KeyType
, InfHandle
, debugstr_w(InfSectionName
));
1416 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1418 SetLastError(ERROR_INVALID_HANDLE
);
1419 return INVALID_HANDLE_VALUE
;
1421 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1423 SetLastError(ERROR_INVALID_HANDLE
);
1424 return INVALID_HANDLE_VALUE
;
1426 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1427 || !DeviceInfoData
->Reserved
)
1429 SetLastError(ERROR_INVALID_PARAMETER
);
1430 return INVALID_HANDLE_VALUE
;
1432 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
1434 SetLastError(ERROR_INVALID_FLAGS
);
1435 return INVALID_HANDLE_VALUE
;
1437 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
1439 SetLastError(ERROR_INVALID_FLAGS
);
1440 return INVALID_HANDLE_VALUE
;
1442 if (InfHandle
&& !InfSectionName
)
1444 SetLastError(ERROR_INVALID_PARAMETER
);
1445 return INVALID_HANDLE_VALUE
;
1447 if (!InfHandle
&& InfSectionName
)
1449 SetLastError(ERROR_INVALID_PARAMETER
);
1450 return INVALID_HANDLE_VALUE
;
1453 LPWSTR lpGuidString
= NULL
;
1454 LPWSTR DriverKey
= NULL
; /* {GUID}\Index */
1455 LPWSTR pDeviceInstance
; /* Points into DriverKey, on the Index field */
1456 DWORD Index
; /* Index used in the DriverKey name */
1458 HKEY hHWProfileKey
= INVALID_HANDLE_VALUE
;
1459 HKEY hEnumKey
= NULL
;
1460 HKEY hClassKey
= NULL
;
1461 HKEY hDeviceKey
= INVALID_HANDLE_VALUE
;
1465 if (Scope
== DICS_FLAG_GLOBAL
)
1466 RootKey
= set
->HKLM
;
1467 else /* Scope == DICS_FLAG_CONFIGSPECIFIC */
1469 hHWProfileKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, KEY_CREATE_SUB_KEY
);
1470 if (hHWProfileKey
== INVALID_HANDLE_VALUE
)
1472 RootKey
= hHWProfileKey
;
1475 if (KeyType
== DIREG_DEV
)
1477 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1479 rc
= RegCreateKeyExW(
1481 REGSTR_PATH_SYSTEMENUM
,
1484 REG_OPTION_NON_VOLATILE
,
1489 if (rc
!= ERROR_SUCCESS
)
1494 rc
= RegCreateKeyExW(
1496 deviceInfo
->instanceId
,
1499 REG_OPTION_NON_VOLATILE
,
1500 #if _WIN32_WINNT >= 0x502
1501 KEY_READ
| KEY_WRITE
,
1508 if (rc
!= ERROR_SUCCESS
)
1514 else /* KeyType == DIREG_DRV */
1516 if (UuidToStringW((UUID
*)&DeviceInfoData
->ClassGuid
, &lpGuidString
) != RPC_S_OK
)
1518 /* The driver key is in \System\CurrentControlSet\Control\Class\{GUID}\Index */
1519 DriverKey
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpGuidString
) + 7) * sizeof(WCHAR
) + sizeof(UNICODE_NULL
));
1522 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1526 strcpyW(&DriverKey
[1], lpGuidString
);
1527 pDeviceInstance
= &DriverKey
[strlenW(DriverKey
)];
1528 *pDeviceInstance
++ = '}';
1529 *pDeviceInstance
++ = '\\';
1530 rc
= RegOpenKeyExW(RootKey
,
1531 REGSTR_PATH_CLASS_NT
,
1535 if (rc
!= ERROR_SUCCESS
)
1541 /* Try all values for Index between 0 and 9999 */
1543 while (Index
<= 9999)
1546 sprintfW(pDeviceInstance
, InstanceKeyFormat
, Index
);
1547 rc
= RegCreateKeyExW(hClassKey
,
1551 REG_OPTION_NON_VOLATILE
,
1552 #if _WIN32_WINNT >= 0x502
1553 KEY_READ
| KEY_WRITE
,
1560 if (rc
!= ERROR_SUCCESS
)
1565 if (Disposition
== REG_CREATED_NEW_KEY
)
1573 /* Unable to create more than 9999 devices within the same class */
1574 SetLastError(ERROR_GEN_FAILURE
);
1578 /* Open device key, to write Driver value */
1579 hDeviceKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
, DIREG_DEV
, KEY_SET_VALUE
);
1580 if (hDeviceKey
== INVALID_HANDLE_VALUE
)
1582 rc
= RegSetValueExW(hDeviceKey
, REGSTR_VAL_DRIVER
, 0, REG_SZ
, (const BYTE
*)DriverKey
, (strlenW(DriverKey
) + 1) * sizeof(WCHAR
));
1583 if (rc
!= ERROR_SUCCESS
)
1590 /* Do installation of the specified section */
1593 FIXME("Need to install section %s in file %p\n",
1594 debugstr_w(InfSectionName
), InfHandle
);
1600 RpcStringFreeW(&lpGuidString
);
1601 HeapFree(GetProcessHeap(), 0, DriverKey
);
1602 if (hHWProfileKey
!= INVALID_HANDLE_VALUE
)
1603 RegCloseKey(hHWProfileKey
);
1604 if (hEnumKey
!= NULL
)
1605 RegCloseKey(hEnumKey
);
1606 if (hClassKey
!= NULL
)
1607 RegCloseKey(hClassKey
);
1608 if (hDeviceKey
!= INVALID_HANDLE_VALUE
)
1609 RegCloseKey(hDeviceKey
);
1610 if (hKey
!= NULL
&& hKey
!= key
)
1613 TRACE("Returning 0x%p\n", key
);
1617 /***********************************************************************
1618 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
1620 BOOL WINAPI
SetupDiCreateDeviceInfoA(
1621 HDEVINFO DeviceInfoSet
,
1623 CONST GUID
*ClassGuid
,
1624 PCSTR DeviceDescription
,
1626 DWORD CreationFlags
,
1627 PSP_DEVINFO_DATA DeviceInfoData
)
1630 LPWSTR DeviceNameW
= NULL
;
1631 LPWSTR DeviceDescriptionW
= NULL
;
1637 DeviceNameW
= MultiByteToUnicode(DeviceName
, CP_ACP
);
1638 if (DeviceNameW
== NULL
) return FALSE
;
1640 if (DeviceDescription
)
1642 DeviceDescriptionW
= MultiByteToUnicode(DeviceDescription
, CP_ACP
);
1643 if (DeviceDescriptionW
== NULL
)
1645 MyFree(DeviceNameW
);
1650 ret
= SetupDiCreateDeviceInfoW(DeviceInfoSet
, DeviceNameW
, ClassGuid
, DeviceDescriptionW
,
1651 hwndParent
, CreationFlags
, DeviceInfoData
);
1653 MyFree(DeviceNameW
);
1654 MyFree(DeviceDescriptionW
);
1659 /***********************************************************************
1660 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
1662 BOOL WINAPI
SetupDiCreateDeviceInfoW(
1663 HDEVINFO DeviceInfoSet
,
1665 CONST GUID
*ClassGuid
,
1666 PCWSTR DeviceDescription
,
1668 DWORD CreationFlags
,
1669 PSP_DEVINFO_DATA DeviceInfoData
)
1671 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1674 TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet
, debugstr_w(DeviceName
),
1675 debugstr_guid(ClassGuid
), debugstr_w(DeviceDescription
),
1676 hwndParent
, CreationFlags
, DeviceInfoData
);
1680 SetLastError(ERROR_INVALID_DEVINST_NAME
);
1683 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1685 SetLastError(ERROR_INVALID_HANDLE
);
1690 SetLastError(ERROR_INVALID_PARAMETER
);
1693 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1695 SetLastError(ERROR_INVALID_HANDLE
);
1698 if (!IsEqualGUID(&set
->ClassGuid
, &GUID_NULL
) &&
1699 !IsEqualGUID(ClassGuid
, &set
->ClassGuid
))
1701 SetLastError(ERROR_CLASS_MISMATCH
);
1704 if (CreationFlags
& ~(DICD_GENERATE_ID
| DICD_INHERIT_CLASSDRVS
))
1706 TRACE("Unknown flags: 0x%08lx\n", CreationFlags
& ~(DICD_GENERATE_ID
| DICD_INHERIT_CLASSDRVS
));
1707 SetLastError(ERROR_INVALID_FLAGS
);
1711 SP_DEVINFO_DATA DevInfo
;
1713 if (CreationFlags
& DICD_GENERATE_ID
)
1715 /* Generate a new unique ID for this device */
1716 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1717 FIXME("not implemented\n");
1721 /* Device name is fully qualified. Try to open it */
1724 DevInfo
.cbSize
= sizeof(SP_DEVINFO_DATA
);
1725 rc
= SetupDiOpenDeviceInfoW(
1728 NULL
, /* hwndParent */
1729 CreationFlags
& DICD_INHERIT_CLASSDRVS
? DIOD_INHERIT_CLASSDRVS
: 0,
1734 /* SetupDiOpenDeviceInfoW has already added
1735 * the device info to the device info set
1737 SetLastError(ERROR_DEVINST_ALREADY_EXISTS
);
1739 else if (GetLastError() == ERROR_FILE_NOT_FOUND
)
1741 struct DeviceInfo
*deviceInfo
;
1743 if (CreateDeviceInfo(set
, DeviceName
, ClassGuid
, &deviceInfo
))
1745 InsertTailList(&set
->ListHead
, &deviceInfo
->ListEntry
);
1747 if (!DeviceInfoData
)
1751 if (DeviceInfoData
->cbSize
!= sizeof(PSP_DEVINFO_DATA
))
1753 SetLastError(ERROR_INVALID_USER_BUFFER
);
1757 memcpy(&DeviceInfoData
->ClassGuid
, ClassGuid
, sizeof(GUID
));
1758 DeviceInfoData
->DevInst
= deviceInfo
->dnDevInst
;
1759 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInfo
;
1767 TRACE("Returning %d\n", ret
);
1771 /***********************************************************************
1772 * SetupDiRegisterDeviceInfo (SETUPAPI.@)
1774 BOOL WINAPI
SetupDiRegisterDeviceInfo(
1775 HDEVINFO DeviceInfoSet
,
1776 PSP_DEVINFO_DATA DeviceInfoData
,
1778 PSP_DETSIG_CMPPROC CompareProc
,
1779 PVOID CompareContext
,
1780 PSP_DEVINFO_DATA DupDeviceInfoData
)
1782 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1784 TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet
, DeviceInfoData
, Flags
,
1785 CompareProc
, CompareContext
, DupDeviceInfoData
);
1787 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1789 SetLastError(ERROR_INVALID_HANDLE
);
1792 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1794 SetLastError(ERROR_INVALID_HANDLE
);
1797 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1798 || !DeviceInfoData
->Reserved
)
1800 SetLastError(ERROR_INVALID_PARAMETER
);
1803 FIXME("Stub %p %p 0x%lx %p %p %p\n", DeviceInfoSet
, DeviceInfoData
, Flags
,
1804 CompareProc
, CompareContext
, DupDeviceInfoData
);
1805 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1809 /***********************************************************************
1810 * SetupDiEnumDeviceInfo (SETUPAPI.@)
1812 BOOL WINAPI
SetupDiEnumDeviceInfo(
1815 PSP_DEVINFO_DATA info
)
1819 TRACE("%p %d %p\n", devinfo
, index
, info
);
1823 SetLastError(ERROR_INVALID_PARAMETER
);
1826 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
1828 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
1829 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
1831 if (info
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1832 SetLastError(ERROR_INVALID_USER_BUFFER
);
1835 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
1836 while (ItemList
!= &list
->ListHead
&& index
-- > 0)
1837 ItemList
= ItemList
->Flink
;
1838 if (ItemList
== &list
->ListHead
)
1839 SetLastError(ERROR_NO_MORE_ITEMS
);
1842 struct DeviceInfo
*DevInfo
= CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
1843 memcpy(&info
->ClassGuid
,
1844 &DevInfo
->ClassGuid
,
1846 info
->DevInst
= DevInfo
->dnDevInst
;
1847 info
->Reserved
= (ULONG_PTR
)DevInfo
;
1853 SetLastError(ERROR_INVALID_HANDLE
);
1856 SetLastError(ERROR_INVALID_HANDLE
);
1860 /***********************************************************************
1861 * SetupDiGetDeviceInstanceIdA (SETUPAPI.@)
1863 BOOL WINAPI
SetupDiGetDeviceInstanceIdA(
1864 HDEVINFO DeviceInfoSet
,
1865 PSP_DEVINFO_DATA DeviceInfoData
,
1866 PSTR DeviceInstanceId
,
1867 DWORD DeviceInstanceIdSize
,
1868 PDWORD RequiredSize
)
1874 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1875 DeviceInstanceIdSize
, RequiredSize
);
1877 if (!DeviceInstanceId
&& DeviceInstanceIdSize
> 0)
1879 SetLastError(ERROR_INVALID_PARAMETER
);
1883 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1888 if (!ret
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1890 instanceId
= MyMalloc(size
* sizeof(WCHAR
));
1893 ret
= SetupDiGetDeviceInstanceIdW(DeviceInfoSet
,
1900 int len
= WideCharToMultiByte(CP_ACP
, 0, instanceId
, -1,
1902 DeviceInstanceIdSize
, NULL
, NULL
);
1908 if (len
> DeviceInstanceIdSize
)
1910 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1914 *RequiredSize
= len
;
1922 *RequiredSize
= size
;
1923 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1929 /***********************************************************************
1930 * SetupDiGetDeviceInstanceIdW (SETUPAPI.@)
1932 BOOL WINAPI
SetupDiGetDeviceInstanceIdW(
1933 HDEVINFO DeviceInfoSet
,
1934 PSP_DEVINFO_DATA DeviceInfoData
,
1935 PWSTR DeviceInstanceId
,
1936 DWORD DeviceInstanceIdSize
,
1937 PDWORD RequiredSize
)
1939 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1940 struct DeviceInfo
*devInfo
;
1942 TRACE("%p %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstanceId
,
1943 DeviceInstanceIdSize
, RequiredSize
);
1945 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
1947 SetLastError(ERROR_INVALID_HANDLE
);
1950 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
1952 SetLastError(ERROR_INVALID_HANDLE
);
1955 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
1956 || !DeviceInfoData
->Reserved
)
1958 SetLastError(ERROR_INVALID_PARAMETER
);
1961 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
1962 if (!DeviceInstanceId
&& DeviceInstanceIdSize
> 0)
1964 SetLastError(ERROR_INVALID_PARAMETER
);
1967 if (DeviceInstanceId
&& DeviceInstanceIdSize
== 0)
1969 SetLastError(ERROR_INVALID_PARAMETER
);
1972 TRACE("instance ID: %s\n", debugstr_w(devInfo
->instanceId
));
1973 if (DeviceInstanceIdSize
< lstrlenW(devInfo
->instanceId
) + 1)
1975 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1977 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1980 lstrcpyW(DeviceInstanceId
, devInfo
->instanceId
);
1982 *RequiredSize
= lstrlenW(devInfo
->instanceId
) + 1;
1986 /***********************************************************************
1987 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
1989 BOOL WINAPI
SetupDiGetActualSectionToInstallA(
1991 PCSTR InfSectionName
,
1992 PSTR InfSectionWithExt
,
1993 DWORD InfSectionWithExtSize
,
1994 PDWORD RequiredSize
,
1997 return SetupDiGetActualSectionToInstallExA(InfHandle
, InfSectionName
,
1998 NULL
, InfSectionWithExt
, InfSectionWithExtSize
, RequiredSize
,
2002 /***********************************************************************
2003 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
2005 BOOL WINAPI
SetupDiGetActualSectionToInstallW(
2007 PCWSTR InfSectionName
,
2008 PWSTR InfSectionWithExt
,
2009 DWORD InfSectionWithExtSize
,
2010 PDWORD RequiredSize
,
2013 return SetupDiGetActualSectionToInstallExW(InfHandle
, InfSectionName
,
2014 NULL
, InfSectionWithExt
, InfSectionWithExtSize
, RequiredSize
,
2018 /***********************************************************************
2019 * SetupDiGetActualSectionToInstallExA (SETUPAPI.@)
2022 SetupDiGetActualSectionToInstallExA(
2024 IN PCSTR InfSectionName
,
2025 IN PSP_ALTPLATFORM_INFO AlternatePlatformInfo OPTIONAL
,
2026 OUT PSTR InfSectionWithExt OPTIONAL
,
2027 IN DWORD InfSectionWithExtSize
,
2028 OUT PDWORD RequiredSize OPTIONAL
,
2029 OUT PSTR
* Extension OPTIONAL
,
2032 LPWSTR InfSectionNameW
= NULL
;
2033 LPWSTR InfSectionWithExtW
= NULL
;
2035 BOOL bResult
= FALSE
;
2041 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2042 if (InfSectionNameW
== NULL
)
2045 if (InfSectionWithExt
)
2047 InfSectionWithExtW
= MyMalloc(InfSectionWithExtSize
* sizeof(WCHAR
));
2048 if (InfSectionWithExtW
== NULL
)
2052 bResult
= SetupDiGetActualSectionToInstallExW(
2053 InfHandle
, InfSectionNameW
, AlternatePlatformInfo
,
2054 InfSectionWithExt
? InfSectionWithExtW
: NULL
,
2055 InfSectionWithExtSize
,
2057 Extension
? &ExtensionW
: NULL
,
2060 if (bResult
&& InfSectionWithExt
)
2062 bResult
= WideCharToMultiByte(CP_ACP
, 0, InfSectionWithExtW
, -1, InfSectionWithExt
,
2063 InfSectionWithExtSize
, NULL
, NULL
) != 0;
2065 if (bResult
&& Extension
)
2067 if (ExtensionW
== NULL
)
2070 *Extension
= &InfSectionWithExt
[ExtensionW
- InfSectionWithExtW
];
2074 MyFree(InfSectionNameW
);
2075 MyFree(InfSectionWithExtW
);
2080 /***********************************************************************
2081 * SetupDiGetClassDescriptionA (SETUPAPI.@)
2083 BOOL WINAPI
SetupDiGetClassDescriptionA(
2084 const GUID
* ClassGuid
,
2085 PSTR ClassDescription
,
2086 DWORD ClassDescriptionSize
,
2087 PDWORD RequiredSize
)
2089 return SetupDiGetClassDescriptionExA(ClassGuid
, ClassDescription
,
2090 ClassDescriptionSize
,
2091 RequiredSize
, NULL
, NULL
);
2094 /***********************************************************************
2095 * SetupDiGetClassDescriptionW (SETUPAPI.@)
2097 BOOL WINAPI
SetupDiGetClassDescriptionW(
2098 const GUID
* ClassGuid
,
2099 PWSTR ClassDescription
,
2100 DWORD ClassDescriptionSize
,
2101 PDWORD RequiredSize
)
2103 return SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescription
,
2104 ClassDescriptionSize
,
2105 RequiredSize
, NULL
, NULL
);
2108 /***********************************************************************
2109 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
2111 BOOL WINAPI
SetupDiGetClassDescriptionExA(
2112 const GUID
* ClassGuid
,
2113 PSTR ClassDescription
,
2114 DWORD ClassDescriptionSize
,
2115 PDWORD RequiredSize
,
2119 PWCHAR ClassDescriptionW
= NULL
;
2120 LPWSTR MachineNameW
= NULL
;
2123 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassDescription
,
2124 ClassDescriptionSize
, RequiredSize
, debugstr_a(MachineName
), Reserved
);
2126 if (ClassDescriptionSize
> 0)
2128 ClassDescriptionW
= MyMalloc(ClassDescriptionSize
* sizeof(WCHAR
));
2129 if (!ClassDescriptionW
)
2131 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2138 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
2141 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2146 ret
= SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescriptionW
,
2147 ClassDescriptionSize
* sizeof(WCHAR
), RequiredSize
, MachineNameW
, Reserved
);
2150 DWORD len
= (DWORD
)WideCharToMultiByte(CP_ACP
, 0, ClassDescriptionW
, -1, ClassDescription
,
2151 ClassDescriptionSize
, NULL
, NULL
);
2152 if (len
== 0 || len
> ClassDescriptionSize
)
2154 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2160 MyFree(ClassDescriptionW
);
2161 MyFree(MachineNameW
);
2165 /***********************************************************************
2166 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
2168 BOOL WINAPI
SetupDiGetClassDescriptionExW(
2169 const GUID
* ClassGuid
,
2170 PWSTR ClassDescription
,
2171 DWORD ClassDescriptionSize
,
2172 PDWORD RequiredSize
,
2181 TRACE("%s %p %lu %p %s %p\n", debugstr_guid(ClassGuid
), ClassDescription
,
2182 ClassDescriptionSize
, RequiredSize
, debugstr_w(MachineName
), Reserved
);
2186 SetLastError(ERROR_INVALID_PARAMETER
);
2189 else if (!ClassDescription
&& ClassDescriptionSize
> 0)
2191 SetLastError(ERROR_INVALID_PARAMETER
);
2195 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
2200 if (hKey
== INVALID_HANDLE_VALUE
)
2202 WARN("SetupDiOpenClassRegKeyExW() failed (Error %u)\n", GetLastError());
2206 if (ClassDescriptionSize
< sizeof(UNICODE_NULL
) || !ClassDescription
)
2209 dwLength
= ClassDescriptionSize
* sizeof(WCHAR
) - sizeof(UNICODE_NULL
);
2211 rc
= RegQueryValueExW(hKey
,
2215 (LPBYTE
)ClassDescription
,
2218 if (rc
!= ERROR_MORE_DATA
&& rc
!= ERROR_SUCCESS
)
2223 else if (dwRegType
!= REG_SZ
)
2225 SetLastError(ERROR_GEN_FAILURE
);
2230 *RequiredSize
= dwLength
/ sizeof(WCHAR
) + 1;
2232 if (ClassDescriptionSize
* sizeof(WCHAR
) >= dwLength
+ sizeof(UNICODE_NULL
))
2234 if (ClassDescriptionSize
> sizeof(UNICODE_NULL
))
2235 ClassDescription
[ClassDescriptionSize
/ sizeof(WCHAR
)] = UNICODE_NULL
;
2240 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2245 /***********************************************************************
2246 * SetupDiGetClassDevsA (SETUPAPI.@)
2248 HDEVINFO WINAPI
SetupDiGetClassDevsA(
2254 return SetupDiGetClassDevsExA(class, enumstr
, parent
,
2255 flags
, NULL
, NULL
, NULL
);
2258 /***********************************************************************
2259 * SetupDiGetClassDevsExA (SETUPAPI.@)
2261 HDEVINFO WINAPI
SetupDiGetClassDevsExA(
2271 LPWSTR enumstrW
= NULL
, machineW
= NULL
;
2275 enumstrW
= MultiByteToUnicode(enumstr
, CP_ACP
);
2278 ret
= INVALID_HANDLE_VALUE
;
2284 machineW
= MultiByteToUnicode(machine
, CP_ACP
);
2288 ret
= INVALID_HANDLE_VALUE
;
2292 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, deviceset
,
2293 machineW
, reserved
);
2301 /***********************************************************************
2302 * SetupDiGetClassDevsW (SETUPAPI.@)
2304 HDEVINFO WINAPI
SetupDiGetClassDevsW(
2310 return SetupDiGetClassDevsExW(class, enumstr
, parent
, flags
, NULL
, NULL
,
2314 /***********************************************************************
2315 * SetupDiGetClassDevsExW (SETUPAPI.@)
2317 HDEVINFO WINAPI
SetupDiGetClassDevsExW(
2326 HDEVINFO hDeviceInfo
= INVALID_HANDLE_VALUE
;
2327 struct DeviceInfoSet
*list
;
2328 CONST GUID
*pClassGuid
;
2330 HDEVINFO set
= INVALID_HANDLE_VALUE
;
2332 TRACE("%s %s %p 0x%08x %p %s %p\n", debugstr_guid(class),
2333 debugstr_w(enumstr
), parent
, flags
, deviceset
, debugstr_w(machine
),
2336 if (!(flags
& DIGCF_ALLCLASSES
) && !class)
2338 SetLastError(ERROR_INVALID_PARAMETER
);
2342 /* Create the deviceset if not set */
2345 list
= (struct DeviceInfoSet
*)deviceset
;
2346 if (list
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2348 SetLastError(ERROR_INVALID_HANDLE
);
2351 hDeviceInfo
= deviceset
;
2355 hDeviceInfo
= SetupDiCreateDeviceInfoListExW(
2356 flags
& (DIGCF_DEVICEINTERFACE
| DIGCF_ALLCLASSES
) ? NULL
: class,
2357 NULL
, machine
, NULL
);
2358 if (hDeviceInfo
== INVALID_HANDLE_VALUE
)
2360 list
= (struct DeviceInfoSet
*)hDeviceInfo
;
2363 if (flags
& DIGCF_PROFILE
)
2364 FIXME(": flag DIGCF_PROFILE ignored\n");
2366 if (flags
& DIGCF_DEVICEINTERFACE
)
2370 SetLastError(ERROR_INVALID_PARAMETER
);
2373 rc
= SETUP_CreateInterfaceList(list
, machine
, class, enumstr
, flags
& DIGCF_PRESENT
);
2377 /* Determine which class(es) should be included in the deviceset */
2378 if (flags
& DIGCF_ALLCLASSES
)
2380 /* The caller wants all classes. Check if
2381 * the deviceset limits us to one class */
2382 if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2385 pClassGuid
= &list
->ClassGuid
;
2389 /* The caller wants one class. Check if it matches deviceset class */
2390 if (IsEqualIID(&list
->ClassGuid
, class)
2391 || IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2397 SetLastError(ERROR_INVALID_PARAMETER
);
2401 else if (!IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2403 /* No class specified. Try to use the one of the deviceset */
2404 if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
2405 pClassGuid
= &list
->ClassGuid
;
2408 SetLastError(ERROR_INVALID_PARAMETER
);
2414 SetLastError(ERROR_INVALID_PARAMETER
);
2417 rc
= SETUP_CreateDevicesList(list
, machine
, pClassGuid
, enumstr
);
2419 if (rc
!= ERROR_SUCCESS
)
2427 if (!deviceset
&& hDeviceInfo
!= INVALID_HANDLE_VALUE
&& hDeviceInfo
!= set
)
2428 SetupDiDestroyDeviceInfoList(hDeviceInfo
);
2432 /***********************************************************************
2433 * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@)
2435 BOOL WINAPI
SetupDiGetDeviceInfoListDetailA(
2436 HDEVINFO DeviceInfoSet
,
2437 PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData
)
2439 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2441 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2443 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2445 SetLastError(ERROR_INVALID_HANDLE
);
2448 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2450 SetLastError(ERROR_INVALID_HANDLE
);
2454 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A
))
2456 SetLastError(ERROR_INVALID_PARAMETER
);
2459 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2460 DevInfoData
->RemoteMachineHandle
= set
->hMachine
;
2461 if (set
->MachineName
)
2464 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2468 DevInfoData
->RemoteMachineName
[0] = 0;
2473 /***********************************************************************
2474 * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@)
2476 BOOL WINAPI
SetupDiGetDeviceInfoListDetailW(
2477 HDEVINFO DeviceInfoSet
,
2478 PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData
)
2480 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2482 TRACE("%p %p\n", DeviceInfoSet
, DevInfoData
);
2484 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2486 SetLastError(ERROR_INVALID_HANDLE
);
2489 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2491 SetLastError(ERROR_INVALID_HANDLE
);
2495 DevInfoData
->cbSize
!= sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W
))
2497 SetLastError(ERROR_INVALID_PARAMETER
);
2500 memcpy(&DevInfoData
->ClassGuid
, &set
->ClassGuid
, sizeof(GUID
));
2501 DevInfoData
->RemoteMachineHandle
= set
->hMachine
;
2502 if (set
->MachineName
)
2503 strcpyW(DevInfoData
->RemoteMachineName
, set
->MachineName
+ 2);
2505 DevInfoData
->RemoteMachineName
[0] = 0;
2510 /***********************************************************************
2511 * SetupDiCreateDeviceInterfaceA (SETUPAPI.@)
2513 BOOL WINAPI
SetupDiCreateDeviceInterfaceA(
2514 HDEVINFO DeviceInfoSet
,
2515 PSP_DEVINFO_DATA DeviceInfoData
,
2516 const GUID
*InterfaceClassGuid
,
2517 PCSTR ReferenceString
,
2518 DWORD CreationFlags
,
2519 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2522 LPWSTR ReferenceStringW
= NULL
;
2524 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2525 debugstr_guid(InterfaceClassGuid
), debugstr_a(ReferenceString
),
2526 CreationFlags
, DeviceInterfaceData
);
2528 if (ReferenceString
)
2530 ReferenceStringW
= MultiByteToUnicode(ReferenceString
, CP_ACP
);
2531 if (ReferenceStringW
== NULL
) return FALSE
;
2534 ret
= SetupDiCreateDeviceInterfaceW(DeviceInfoSet
, DeviceInfoData
,
2535 InterfaceClassGuid
, ReferenceStringW
, CreationFlags
,
2536 DeviceInterfaceData
);
2538 MyFree(ReferenceStringW
);
2543 /***********************************************************************
2544 * SetupDiCreateDeviceInterfaceW (SETUPAPI.@)
2546 BOOL WINAPI
SetupDiCreateDeviceInterfaceW(
2547 HDEVINFO DeviceInfoSet
,
2548 PSP_DEVINFO_DATA DeviceInfoData
,
2549 const GUID
*InterfaceClassGuid
,
2550 PCWSTR ReferenceString
,
2551 DWORD CreationFlags
,
2552 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2554 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2555 TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2556 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2557 CreationFlags
, DeviceInterfaceData
);
2559 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
2561 SetLastError(ERROR_INVALID_HANDLE
);
2564 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2566 SetLastError(ERROR_INVALID_HANDLE
);
2569 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
2570 || !DeviceInfoData
->Reserved
)
2572 SetLastError(ERROR_INVALID_PARAMETER
);
2575 if (!InterfaceClassGuid
)
2577 SetLastError(ERROR_INVALID_USER_BUFFER
);
2581 FIXME("%p %p %s %s %08x %p\n", DeviceInfoSet
, DeviceInfoData
,
2582 debugstr_guid(InterfaceClassGuid
), debugstr_w(ReferenceString
),
2583 CreationFlags
, DeviceInterfaceData
);
2584 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2588 /***********************************************************************
2589 * SetupDiCreateDeviceInterfaceRegKeyA (SETUPAPI.@)
2591 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyA(
2592 HDEVINFO DeviceInfoSet
,
2593 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2597 PCSTR InfSectionName
)
2600 PWSTR InfSectionNameW
= NULL
;
2602 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2603 samDesired
, InfHandle
, InfSectionName
);
2606 if (!InfSectionName
)
2608 SetLastError(ERROR_INVALID_PARAMETER
);
2609 return INVALID_HANDLE_VALUE
;
2611 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
2612 if (!InfSectionNameW
)
2613 return INVALID_HANDLE_VALUE
;
2615 key
= SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet
,
2616 DeviceInterfaceData
, Reserved
, samDesired
, InfHandle
,
2618 MyFree(InfSectionNameW
);
2622 /***********************************************************************
2623 * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@)
2625 HKEY WINAPI
SetupDiCreateDeviceInterfaceRegKeyW(
2626 HDEVINFO DeviceInfoSet
,
2627 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2631 PCWSTR InfSectionName
)
2633 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2634 TRACE("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2635 samDesired
, InfHandle
, InfSectionName
);
2637 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2638 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2640 SetLastError(ERROR_INVALID_HANDLE
);
2641 return INVALID_HANDLE_VALUE
;
2643 if (!DeviceInterfaceData
||
2644 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2645 !DeviceInterfaceData
->Reserved
)
2647 SetLastError(ERROR_INVALID_PARAMETER
);
2648 return INVALID_HANDLE_VALUE
;
2650 if (InfHandle
&& !InfSectionName
)
2652 SetLastError(ERROR_INVALID_PARAMETER
);
2653 return INVALID_HANDLE_VALUE
;
2656 FIXME("%p %p %d %08x %p %p\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
,
2657 samDesired
, InfHandle
, InfSectionName
);
2658 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2659 return INVALID_HANDLE_VALUE
;
2662 /***********************************************************************
2663 * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@)
2665 BOOL WINAPI
SetupDiDeleteDeviceInterfaceRegKey(
2666 HDEVINFO DeviceInfoSet
,
2667 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2670 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2673 TRACE("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2675 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2676 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2678 SetLastError(ERROR_INVALID_HANDLE
);
2681 if (!DeviceInterfaceData
||
2682 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2683 !DeviceInterfaceData
->Reserved
)
2685 SetLastError(ERROR_INVALID_PARAMETER
);
2689 FIXME("%p %p %d\n", DeviceInfoSet
, DeviceInterfaceData
, Reserved
);
2690 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2694 /***********************************************************************
2695 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
2698 * DeviceInfoSet [I] Set of devices from which to enumerate
2700 * DeviceInfoData [I] (Optional) If specified, a specific device
2701 * instance from which to enumerate interfaces.
2702 * If it isn't specified, all interfaces for all
2703 * devices in the set are enumerated.
2704 * InterfaceClassGuid [I] The interface class to enumerate.
2705 * MemberIndex [I] An index of the interface instance to enumerate.
2706 * A caller should start with MemberIndex set to 0,
2707 * and continue until the function fails with
2708 * ERROR_NO_MORE_ITEMS.
2709 * DeviceInterfaceData [I/O] Returns an enumerated interface. Its cbSize
2710 * member must be set to
2711 * sizeof(SP_DEVICE_INTERFACE_DATA).
2714 * Success: non-zero value.
2715 * Failure: FALSE. Call GetLastError() for more info.
2717 BOOL WINAPI
SetupDiEnumDeviceInterfaces(
2718 HDEVINFO DeviceInfoSet
,
2719 PSP_DEVINFO_DATA DeviceInfoData
,
2720 CONST GUID
* InterfaceClassGuid
,
2722 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2724 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2727 TRACE("%p, %p, %s, %d, %p\n", DeviceInfoSet
, DeviceInfoData
,
2728 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
2730 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2731 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2733 SetLastError(ERROR_INVALID_HANDLE
);
2736 if (DeviceInfoData
&& (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
) ||
2737 !DeviceInfoData
->Reserved
))
2739 SetLastError(ERROR_INVALID_PARAMETER
);
2742 if (!DeviceInterfaceData
||
2743 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2745 SetLastError(ERROR_INVALID_PARAMETER
);
2750 struct DeviceInfo
*devInfo
=
2751 (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
2753 PLIST_ENTRY InterfaceListEntry
= devInfo
->InterfaceListHead
.Flink
;
2754 while (InterfaceListEntry
!= &devInfo
->InterfaceListHead
&& !found
)
2756 struct DeviceInterface
*DevItf
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
2757 if (!IsEqualIID(&DevItf
->InterfaceClassGuid
, InterfaceClassGuid
))
2759 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2762 if (MemberIndex
-- == 0)
2764 /* return this item */
2765 memcpy(&DeviceInterfaceData
->InterfaceClassGuid
,
2766 &DevItf
->InterfaceClassGuid
,
2768 DeviceInterfaceData
->Flags
= DevItf
->Flags
;
2769 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)DevItf
;
2773 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2776 SetLastError(ERROR_NO_MORE_ITEMS
);
2781 PLIST_ENTRY ItemList
= set
->ListHead
.Flink
;
2782 while (ItemList
!= &set
->ListHead
&& !found
)
2784 PLIST_ENTRY InterfaceListEntry
;
2785 struct DeviceInfo
*devInfo
=
2786 CONTAINING_RECORD(ItemList
, struct DeviceInfo
, ListEntry
);
2787 InterfaceListEntry
= devInfo
->InterfaceListHead
.Flink
;
2788 while (InterfaceListEntry
!= &devInfo
->InterfaceListHead
&& !found
)
2790 struct DeviceInterface
*DevItf
= CONTAINING_RECORD(InterfaceListEntry
, struct DeviceInterface
, ListEntry
);
2791 if (!IsEqualIID(&DevItf
->InterfaceClassGuid
, InterfaceClassGuid
))
2793 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2796 if (MemberIndex
-- == 0)
2798 /* return this item */
2799 memcpy(&DeviceInterfaceData
->InterfaceClassGuid
,
2800 &DevItf
->InterfaceClassGuid
,
2802 DeviceInterfaceData
->Flags
= DevItf
->Flags
;
2803 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)DevItf
;
2807 InterfaceListEntry
= InterfaceListEntry
->Flink
;
2809 ItemList
= ItemList
->Flink
;
2813 SetLastError(ERROR_NO_MORE_ITEMS
);
2818 /***********************************************************************
2819 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2821 * Destroy a DeviceInfoList and free all used memory of the list.
2824 * devinfo [I] DeviceInfoList pointer to list to destroy
2827 * Success: non zero value.
2828 * Failure: zero value.
2830 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
2834 TRACE("%p\n", devinfo
);
2835 if (devinfo
&& devinfo
!= INVALID_HANDLE_VALUE
)
2837 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
2839 if (list
->magic
== SETUP_DEVICE_INFO_SET_MAGIC
)
2841 ret
= DestroyDeviceInfoSet(list
);
2846 SetLastError(ERROR_INVALID_HANDLE
);
2851 /***********************************************************************
2852 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2854 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
2855 HDEVINFO DeviceInfoSet
,
2856 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2857 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
2858 DWORD DeviceInterfaceDetailDataSize
,
2859 PDWORD RequiredSize
,
2860 PSP_DEVINFO_DATA DeviceInfoData
)
2862 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2863 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailDataW
= NULL
;
2864 DWORD sizeW
= 0, bytesNeeded
;
2867 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2868 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2869 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2871 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2872 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2874 SetLastError(ERROR_INVALID_HANDLE
);
2877 if (!DeviceInterfaceData
||
2878 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2879 !DeviceInterfaceData
->Reserved
)
2881 SetLastError(ERROR_INVALID_PARAMETER
);
2884 if (DeviceInterfaceDetailData
&& (DeviceInterfaceDetailData
->cbSize
<
2885 FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + 1 ||
2886 DeviceInterfaceDetailData
->cbSize
> sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
)))
2888 SetLastError(ERROR_INVALID_USER_BUFFER
);
2891 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2893 SetLastError(ERROR_INVALID_USER_BUFFER
);
2898 if (DeviceInterfaceDetailData
!= NULL
)
2900 sizeW
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
2901 + (DeviceInterfaceDetailDataSize
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
)) * sizeof(WCHAR
);
2902 DeviceInterfaceDetailDataW
= (PSP_DEVICE_INTERFACE_DETAIL_DATA_W
)MyMalloc(sizeW
);
2903 if (!DeviceInterfaceDetailDataW
)
2905 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2908 if (!DeviceInterfaceDetailData
|| (DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataW
))
2910 DeviceInterfaceDetailDataW
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
);
2911 ret
= SetupDiGetDeviceInterfaceDetailW(
2913 DeviceInterfaceData
,
2914 DeviceInterfaceDetailDataW
,
2918 bytesNeeded
= (sizeW
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)) / sizeof(WCHAR
)
2919 + FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
);
2921 *RequiredSize
= bytesNeeded
;
2922 if (ret
&& DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
<= bytesNeeded
)
2924 if (!WideCharToMultiByte(
2926 DeviceInterfaceDetailDataW
->DevicePath
, -1,
2927 DeviceInterfaceDetailData
->DevicePath
, DeviceInterfaceDetailDataSize
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
2934 MyFree(DeviceInterfaceDetailDataW
);
2939 /***********************************************************************
2940 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2942 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
2943 HDEVINFO DeviceInfoSet
,
2944 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2945 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
2946 DWORD DeviceInterfaceDetailDataSize
,
2947 PDWORD RequiredSize
,
2948 PSP_DEVINFO_DATA DeviceInfoData
)
2950 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2953 TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet
,
2954 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2955 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2957 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
||
2958 set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
2960 SetLastError(ERROR_INVALID_HANDLE
);
2963 if (!DeviceInterfaceData
||
2964 DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
) ||
2965 !DeviceInterfaceData
->Reserved
)
2967 SetLastError(ERROR_INVALID_PARAMETER
);
2970 if (DeviceInterfaceDetailData
&& DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
))
2972 SetLastError(ERROR_INVALID_USER_BUFFER
);
2975 if (!DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
)
2977 SetLastError(ERROR_INVALID_USER_BUFFER
);
2980 if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
2982 SetLastError(ERROR_INVALID_PARAMETER
);
2985 if (DeviceInterfaceDetailData
!= NULL
&& DeviceInterfaceDetailDataSize
< FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
))
2987 SetLastError(ERROR_INVALID_PARAMETER
);
2992 struct DeviceInterface
*deviceInterface
= (struct DeviceInterface
*)DeviceInterfaceData
->Reserved
;
2993 LPCWSTR devName
= deviceInterface
->SymbolicLink
;
2994 DWORD sizeRequired
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
) +
2995 (lstrlenW(devName
) + 1) * sizeof(WCHAR
);
2997 if (sizeRequired
> DeviceInterfaceDetailDataSize
)
2999 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3001 *RequiredSize
= sizeRequired
;
3005 strcpyW(DeviceInterfaceDetailData
->DevicePath
, devName
);
3006 TRACE("DevicePath is %s\n", debugstr_w(DeviceInterfaceDetailData
->DevicePath
));
3009 memcpy(&DeviceInfoData
->ClassGuid
,
3010 &deviceInterface
->DeviceInfo
->ClassGuid
,
3012 DeviceInfoData
->DevInst
= deviceInterface
->DeviceInfo
->dnDevInst
;
3013 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInterface
->DeviceInfo
;
3021 struct PropertyMapEntry
3028 static struct PropertyMapEntry PropertyMap
[] = {
3029 { REG_SZ
, "DeviceDesc", REGSTR_VAL_DEVDESC
},
3030 { REG_MULTI_SZ
, "HardwareId", REGSTR_VAL_HARDWAREID
},
3031 { REG_MULTI_SZ
, "CompatibleIDs", REGSTR_VAL_COMPATIBLEIDS
},
3032 { 0, NULL
, NULL
}, /* SPDRP_UNUSED0 */
3033 { REG_SZ
, "Service", REGSTR_VAL_SERVICE
},
3034 { 0, NULL
, NULL
}, /* SPDRP_UNUSED1 */
3035 { 0, NULL
, NULL
}, /* SPDRP_UNUSED2 */
3036 { REG_SZ
, "Class", REGSTR_VAL_CLASS
},
3037 { REG_SZ
, "ClassGUID", REGSTR_VAL_CLASSGUID
},
3038 { REG_SZ
, "Driver", REGSTR_VAL_DRIVER
},
3039 { REG_DWORD
, "ConfigFlags", REGSTR_VAL_CONFIGFLAGS
},
3040 { REG_SZ
, "Mfg", REGSTR_VAL_MFG
},
3041 { REG_SZ
, "FriendlyName", REGSTR_VAL_FRIENDLYNAME
},
3042 { REG_SZ
, "LocationInformation", REGSTR_VAL_LOCATION_INFORMATION
},
3043 { 0, NULL
, NULL
}, /* SPDRP_PHYSICAL_DEVICE_OBJECT_NAME */
3044 { REG_DWORD
, "Capabilities", REGSTR_VAL_CAPABILITIES
},
3045 { REG_DWORD
, "UINumber", REGSTR_VAL_UI_NUMBER
},
3046 { REG_MULTI_SZ
, "UpperFilters", REGSTR_VAL_UPPERFILTERS
},
3047 { REG_MULTI_SZ
, "LowerFilters", REGSTR_VAL_LOWERFILTERS
},
3048 { 0, NULL
, NULL
}, /* SPDRP_BUSTYPEGUID */
3049 { 0, NULL
, NULL
}, /* SPDRP_LEGACYBUSTYPE */
3050 { 0, NULL
, NULL
}, /* SPDRP_BUSNUMBER */
3051 { 0, NULL
, NULL
}, /* SPDRP_ENUMERATOR_NAME */
3052 { REG_BINARY
, "Security", REGSTR_SECURITY
},
3053 { 0, NULL
, NULL
}, /* SPDRP_SECURITY_SDS */
3054 { 0, NULL
, NULL
}, /* SPDRP_DEVTYPE */
3055 { 0, NULL
, NULL
}, /* SPDRP_EXCLUSIVE */
3056 { 0, NULL
, NULL
}, /* SPDRP_CHARACTERISTICS */
3057 { 0, NULL
, NULL
}, /* SPDRP_ADDRESS */
3058 { REG_SZ
, "UINumberDescFormat", REGSTR_UI_NUMBER_DESC_FORMAT
},
3059 { 0, NULL
, NULL
}, /* SPDRP_DEVICE_POWER_DATA */
3060 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY */
3061 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY_HW_DEFAULT */
3062 { 0, NULL
, NULL
}, /* SPDRP_REMOVAL_POLICY_OVERRIDE */
3063 { 0, NULL
, NULL
}, /* SPDRP_INSTALL_STATE */
3066 /***********************************************************************
3067 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
3069 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
3070 HDEVINFO DeviceInfoSet
,
3071 PSP_DEVINFO_DATA DeviceInfoData
,
3073 PDWORD PropertyRegDataType
,
3074 PBYTE PropertyBuffer
,
3075 DWORD PropertyBufferSize
,
3076 PDWORD RequiredSize
)
3079 BOOL bIsStringProperty
;
3081 DWORD RequiredSizeA
, RequiredSizeW
;
3082 DWORD PropertyBufferSizeW
= 0;
3083 PBYTE PropertyBufferW
= NULL
;
3085 TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
,
3086 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3089 if (PropertyBufferSize
!= 0)
3091 PropertyBufferSizeW
= PropertyBufferSize
* 2;
3092 PropertyBufferW
= HeapAlloc(GetProcessHeap(), 0, PropertyBufferSizeW
);
3093 if (!PropertyBufferW
)
3095 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3100 ret
= SetupDiGetDeviceRegistryPropertyW(
3106 PropertyBufferSizeW
,
3109 if (ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
3111 bIsStringProperty
= (RegType
== REG_SZ
|| RegType
== REG_MULTI_SZ
|| RegType
== REG_EXPAND_SZ
);
3113 if (bIsStringProperty
)
3114 RequiredSizeA
= RequiredSizeW
/ sizeof(WCHAR
);
3116 RequiredSizeA
= RequiredSizeW
;
3118 *RequiredSize
= RequiredSizeA
;
3119 if (PropertyRegDataType
)
3120 *PropertyRegDataType
= RegType
;
3125 HeapFree(GetProcessHeap(), 0, PropertyBufferW
);
3129 if (RequiredSizeA
<= PropertyBufferSize
)
3131 if (bIsStringProperty
&& PropertyBufferSize
> 0)
3133 if (WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)PropertyBufferW
, RequiredSizeW
/ sizeof(WCHAR
), (LPSTR
)PropertyBuffer
, PropertyBufferSize
, NULL
, NULL
) == 0)
3135 /* Last error is already set by WideCharToMultiByte */
3140 memcpy(PropertyBuffer
, PropertyBufferW
, RequiredSizeA
);
3144 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3148 HeapFree(GetProcessHeap(), 0, PropertyBufferW
);
3152 /***********************************************************************
3153 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
3155 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
3156 HDEVINFO DeviceInfoSet
,
3157 PSP_DEVINFO_DATA DeviceInfoData
,
3159 PDWORD PropertyRegDataType
,
3160 PBYTE PropertyBuffer
,
3161 DWORD PropertyBufferSize
,
3162 PDWORD RequiredSize
)
3165 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3166 struct DeviceInfo
*devInfo
;
3168 TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet
, DeviceInfoData
,
3169 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
3172 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3174 SetLastError(ERROR_INVALID_HANDLE
);
3177 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3179 SetLastError(ERROR_INVALID_HANDLE
);
3182 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3183 || !DeviceInfoData
->Reserved
)
3185 SetLastError(ERROR_INVALID_PARAMETER
);
3188 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
3189 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3190 && PropertyMap
[Property
].nameW
)
3192 DWORD size
= PropertyBufferSize
;
3195 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_QUERY_VALUE
);
3196 if (hKey
== INVALID_HANDLE_VALUE
)
3198 l
= RegQueryValueExW(hKey
, PropertyMap
[Property
].nameW
,
3199 NULL
, PropertyRegDataType
, PropertyBuffer
, &size
);
3203 *RequiredSize
= size
;
3206 if (PropertyBuffer
!= NULL
|| size
== 0)
3209 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3211 case ERROR_MORE_DATA
:
3212 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3218 else if (Property
== SPDRP_PHYSICAL_DEVICE_OBJECT_NAME
)
3220 DWORD required
= (strlenW(devInfo
->Data
) + 1) * sizeof(WCHAR
);
3222 if (PropertyRegDataType
)
3223 *PropertyRegDataType
= REG_SZ
;
3225 *RequiredSize
= required
;
3226 if (PropertyBufferSize
>= required
)
3228 strcpyW((LPWSTR
)PropertyBuffer
, devInfo
->Data
);
3232 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3236 ERR("Property 0x%lx not implemented\n", Property
);
3237 SetLastError(ERROR_NOT_SUPPORTED
);
3242 /***********************************************************************
3243 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
3245 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
3246 HDEVINFO DeviceInfoSet
,
3247 PSP_DEVINFO_DATA DeviceInfoData
,
3249 const BYTE
*PropertyBuffer
,
3250 DWORD PropertyBufferSize
)
3253 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3255 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3256 PropertyBuffer
, PropertyBufferSize
);
3258 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3260 SetLastError(ERROR_INVALID_HANDLE
);
3263 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3265 SetLastError(ERROR_INVALID_HANDLE
);
3268 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3269 || !DeviceInfoData
->Reserved
)
3271 SetLastError(ERROR_INVALID_PARAMETER
);
3275 FIXME("%p %p 0x%lx %p 0x%lx\n", DeviceInfoSet
, DeviceInfoData
,
3276 Property
, PropertyBuffer
, PropertyBufferSize
);
3277 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3281 /***********************************************************************
3282 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
3284 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
3285 HDEVINFO DeviceInfoSet
,
3286 PSP_DEVINFO_DATA DeviceInfoData
,
3288 const BYTE
*PropertyBuffer
,
3289 DWORD PropertyBufferSize
)
3292 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
3294 TRACE("%p %p %d %p %d\n", DeviceInfoSet
, DeviceInfoData
, Property
,
3295 PropertyBuffer
, PropertyBufferSize
);
3297 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
3299 SetLastError(ERROR_INVALID_HANDLE
);
3302 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3304 SetLastError(ERROR_INVALID_HANDLE
);
3307 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
3308 || !DeviceInfoData
->Reserved
)
3310 SetLastError(ERROR_INVALID_PARAMETER
);
3313 if (Property
< sizeof(PropertyMap
) / sizeof(PropertyMap
[0])
3314 && PropertyMap
[Property
].nameW
)
3318 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_SET_VALUE
);
3319 if (hKey
== INVALID_HANDLE_VALUE
)
3321 /* Write new data */
3323 hKey
, PropertyMap
[Property
].nameW
, 0,
3324 PropertyMap
[Property
].regType
, PropertyBuffer
,
3325 PropertyBufferSize
);
3334 ERR("Property 0x%lx not implemented\n", Property
);
3335 SetLastError(ERROR_NOT_SUPPORTED
);
3338 TRACE("Returning %d\n", ret
);
3342 /***********************************************************************
3343 * SetupDiInstallClassA (SETUPAPI.@)
3345 BOOL WINAPI
SetupDiInstallClassA(
3351 return SetupDiInstallClassExA(hwndParent
, InfFileName
, Flags
, FileQueue
, NULL
, NULL
, NULL
);
3354 /***********************************************************************
3355 * SetupDiInstallClassExA (SETUPAPI.@)
3358 SetupDiInstallClassExA(
3359 IN HWND hwndParent OPTIONAL
,
3360 IN PCSTR InfFileName OPTIONAL
,
3362 IN HSPFILEQ FileQueue OPTIONAL
,
3363 IN CONST GUID
*InterfaceClassGuid OPTIONAL
,
3367 PWSTR InfFileNameW
= NULL
;
3372 SetLastError(ERROR_INVALID_PARAMETER
);
3377 InfFileNameW
= MultiByteToUnicode(InfFileName
, CP_ACP
);
3378 if (InfFileNameW
== NULL
)
3380 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3385 Result
= SetupDiInstallClassExW(hwndParent
, InfFileNameW
, Flags
,
3386 FileQueue
, InterfaceClassGuid
, Reserved1
, Reserved2
);
3388 MyFree(InfFileNameW
);
3393 HKEY
SETUP_CreateClassKey(HINF hInf
)
3395 static const WCHAR slash
[] = { '\\',0 };
3396 WCHAR FullBuffer
[MAX_PATH
];
3397 WCHAR Buffer
[MAX_PATH
];
3401 if (!SetupGetLineTextW(NULL
,
3409 return INVALID_HANDLE_VALUE
;
3412 lstrcpyW(FullBuffer
, REGSTR_PATH_CLASS_NT
);
3413 lstrcatW(FullBuffer
, slash
);
3414 lstrcatW(FullBuffer
, Buffer
);
3416 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3422 if (!SetupGetLineTextW(NULL
,
3430 return INVALID_HANDLE_VALUE
;
3433 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
3437 REG_OPTION_NON_VOLATILE
,
3443 return INVALID_HANDLE_VALUE
;
3448 if (RegSetValueExW(hClassKey
,
3453 RequiredSize
* sizeof(WCHAR
)))
3455 RegCloseKey(hClassKey
);
3456 RegDeleteKeyW(HKEY_LOCAL_MACHINE
,
3458 return INVALID_HANDLE_VALUE
;
3464 /***********************************************************************
3465 * SetupDiInstallClassW (SETUPAPI.@)
3467 BOOL WINAPI
SetupDiInstallClassW(
3473 return SetupDiInstallClassExW(hwndParent
, InfFileName
, Flags
, FileQueue
, NULL
, NULL
, NULL
);
3477 /***********************************************************************
3478 * SetupDiOpenClassRegKey (SETUPAPI.@)
3480 HKEY WINAPI
SetupDiOpenClassRegKey(
3481 const GUID
* ClassGuid
,
3484 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3485 DIOCR_INSTALLER
, NULL
, NULL
);
3489 /***********************************************************************
3490 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
3492 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
3493 const GUID
* ClassGuid
,
3499 PWSTR MachineNameW
= NULL
;
3502 TRACE("%s 0x%lx 0x%lx %s %p\n", debugstr_guid(ClassGuid
), samDesired
,
3503 Flags
, debugstr_a(MachineName
), Reserved
);
3507 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
3508 if (MachineNameW
== NULL
)
3509 return INVALID_HANDLE_VALUE
;
3512 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
3513 Flags
, MachineNameW
, Reserved
);
3515 MyFree(MachineNameW
);
3521 /***********************************************************************
3522 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
3524 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
3525 const GUID
* ClassGuid
,
3537 TRACE("%s 0x%lx 0x%lx %s %p\n", debugstr_guid(ClassGuid
), samDesired
,
3538 Flags
, debugstr_w(MachineName
), Reserved
);
3540 if (MachineName
!= NULL
)
3542 l
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &HKLM
);
3543 if (l
!= ERROR_SUCCESS
)
3546 return INVALID_HANDLE_VALUE
;
3550 HKLM
= HKEY_LOCAL_MACHINE
;
3552 if (Flags
== DIOCR_INSTALLER
)
3554 lpKeyName
= REGSTR_PATH_CLASS_NT
;
3556 else if (Flags
== DIOCR_INTERFACE
)
3558 lpKeyName
= REGSTR_PATH_DEVICE_CLASSES
;
3562 ERR("Invalid Flags parameter!\n");
3563 SetLastError(ERROR_INVALID_PARAMETER
);
3564 if (MachineName
!= NULL
) RegCloseKey(HKLM
);
3565 return INVALID_HANDLE_VALUE
;
3570 if ((l
= RegOpenKeyExW(HKLM
,
3577 hClassesKey
= INVALID_HANDLE_VALUE
;
3579 if (MachineName
!= NULL
)
3585 WCHAR bracedGuidString
[39];
3587 SETUPDI_GuidToString(ClassGuid
, bracedGuidString
);
3589 if (!(l
= RegOpenKeyExW(HKLM
,
3595 if (MachineName
!= NULL
)
3598 if ((l
= RegOpenKeyExW(hClassesKey
,
3605 key
= INVALID_HANDLE_VALUE
;
3607 RegCloseKey(hClassesKey
);
3611 if (MachineName
!= NULL
) RegCloseKey(HKLM
);
3613 key
= INVALID_HANDLE_VALUE
;
3619 /***********************************************************************
3620 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
3622 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
3623 HDEVINFO DeviceInfoSet
,
3626 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3628 FIXME("%p %s %08x %p\n",
3629 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3633 /***********************************************************************
3634 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
3636 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
3637 HDEVINFO DeviceInfoSet
,
3640 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
3642 LPWSTR DevicePathW
= NULL
;
3645 TRACE("%p %s %08lx %p\n", DeviceInfoSet
, debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
3647 DevicePathW
= MultiByteToUnicode(DevicePath
, CP_ACP
);
3648 if (DevicePathW
== NULL
)
3651 bResult
= SetupDiOpenDeviceInterfaceW(DeviceInfoSet
,
3652 DevicePathW
, OpenFlags
, DeviceInterfaceData
);
3654 MyFree(DevicePathW
);
3659 /***********************************************************************
3660 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
3662 BOOL WINAPI
SetupDiSetClassInstallParamsA(
3663 HDEVINFO DeviceInfoSet
,
3664 PSP_DEVINFO_DATA DeviceInfoData
,
3665 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
3666 DWORD ClassInstallParamsSize
)
3668 FIXME("%p %p %x %u\n",DeviceInfoSet
, DeviceInfoData
,
3669 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
3674 IntSetupDiRegisterDeviceInfo(
3675 IN HDEVINFO DeviceInfoSet
,
3676 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
3678 return SetupDiRegisterDeviceInfo(DeviceInfoSet
, DeviceInfoData
, 0, NULL
, NULL
, NULL
);
3681 /***********************************************************************
3682 * SetupDiCallClassInstaller (SETUPAPI.@)
3684 BOOL WINAPI
SetupDiCallClassInstaller(
3685 DI_FUNCTION InstallFunction
,
3686 HDEVINFO DeviceInfoSet
,
3687 PSP_DEVINFO_DATA DeviceInfoData
)
3691 TRACE("%u %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3694 SetLastError(ERROR_INVALID_PARAMETER
);
3695 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
3696 SetLastError(ERROR_INVALID_HANDLE
);
3697 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
3698 SetLastError(ERROR_INVALID_HANDLE
);
3699 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->HKLM
!= HKEY_LOCAL_MACHINE
)
3700 SetLastError(ERROR_INVALID_HANDLE
);
3701 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
3702 SetLastError(ERROR_INVALID_USER_BUFFER
);
3705 SP_DEVINSTALL_PARAMS_W InstallParams
;
3706 #define CLASS_COINSTALLER 0x1
3707 #define DEVICE_COINSTALLER 0x2
3708 #define CLASS_INSTALLER 0x4
3709 UCHAR CanHandle
= 0;
3710 DEFAULT_CLASS_INSTALL_PROC DefaultHandler
= NULL
;
3712 switch (InstallFunction
)
3714 case DIF_ADDPROPERTYPAGE_ADVANCED
:
3715 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3717 case DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
3718 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3720 case DIF_ALLOW_INSTALL
:
3721 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3724 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3726 case DIF_DESTROYPRIVATEDATA
:
3727 CanHandle
= CLASS_INSTALLER
;
3729 case DIF_INSTALLDEVICE
:
3730 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3731 DefaultHandler
= SetupDiInstallDevice
;
3733 case DIF_INSTALLDEVICEFILES
:
3734 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3735 DefaultHandler
= SetupDiInstallDriverFiles
;
3737 case DIF_INSTALLINTERFACES
:
3738 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3739 DefaultHandler
= SetupDiInstallDeviceInterfaces
;
3741 case DIF_NEWDEVICEWIZARD_FINISHINSTALL
:
3742 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3744 case DIF_NEWDEVICEWIZARD_POSTANALYZE
:
3745 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3747 case DIF_NEWDEVICEWIZARD_PREANALYZE
:
3748 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3750 case DIF_NEWDEVICEWIZARD_PRESELECT
:
3751 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3753 case DIF_NEWDEVICEWIZARD_SELECT
:
3754 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3756 case DIF_POWERMESSAGEWAKE
:
3757 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3759 case DIF_PROPERTYCHANGE
:
3760 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3761 DefaultHandler
= SetupDiChangeState
;
3763 case DIF_REGISTER_COINSTALLERS
:
3764 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3765 DefaultHandler
= SetupDiRegisterCoDeviceInstallers
;
3767 case DIF_REGISTERDEVICE
:
3768 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3769 DefaultHandler
= IntSetupDiRegisterDeviceInfo
;
3772 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3773 DefaultHandler
= SetupDiRemoveDevice
;
3775 case DIF_SELECTBESTCOMPATDRV
:
3776 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3777 DefaultHandler
= SetupDiSelectBestCompatDrv
;
3779 case DIF_SELECTDEVICE
:
3780 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3781 DefaultHandler
= SetupDiSelectDevice
;
3783 case DIF_TROUBLESHOOTER
:
3784 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3787 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3788 DefaultHandler
= SetupDiUnremoveDevice
;
3791 ERR("Install function %u not supported\n", InstallFunction
);
3792 SetLastError(ERROR_NOT_SUPPORTED
);
3795 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
3796 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
))
3797 /* Don't process this call, as a parameter is invalid */
3802 LIST_ENTRY ClassCoInstallersListHead
;
3803 LIST_ENTRY DeviceCoInstallersListHead
;
3804 HMODULE ClassInstallerLibrary
= NULL
;
3805 CLASS_INSTALL_PROC ClassInstaller
= NULL
;
3806 COINSTALLER_CONTEXT_DATA Context
;
3807 PLIST_ENTRY ListEntry
;
3809 DWORD dwRegType
, dwLength
;
3810 DWORD rc
= NO_ERROR
;
3812 InitializeListHead(&ClassCoInstallersListHead
);
3813 InitializeListHead(&DeviceCoInstallersListHead
);
3815 if (CanHandle
& DEVICE_COINSTALLER
)
3817 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_QUERY_VALUE
);
3818 if (hKey
!= INVALID_HANDLE_VALUE
)
3820 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_COINSTALLERS_32
, NULL
, &dwRegType
, NULL
, &dwLength
);
3821 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_MULTI_SZ
)
3823 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
3824 if (KeyBuffer
!= NULL
)
3826 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_COINSTALLERS_32
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
3827 if (rc
== ERROR_SUCCESS
)
3830 for (ptr
= KeyBuffer
; *ptr
; ptr
+= strlenW(ptr
) + 1)
3832 /* Add coinstaller to DeviceCoInstallersListHead list */
3833 struct CoInstallerElement
*coinstaller
;
3834 TRACE("Got device coinstaller '%s'\n", debugstr_w(ptr
));
3835 coinstaller
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CoInstallerElement
));
3838 ZeroMemory(coinstaller
, sizeof(struct CoInstallerElement
));
3839 if (GetFunctionPointer(ptr
, &coinstaller
->Module
, (PVOID
*)&coinstaller
->Function
) == ERROR_SUCCESS
)
3840 InsertTailList(&DeviceCoInstallersListHead
, &coinstaller
->ListEntry
);
3842 HeapFree(GetProcessHeap(), 0, coinstaller
);
3845 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
3851 if (CanHandle
& CLASS_COINSTALLER
)
3855 REGSTR_PATH_CODEVICEINSTALLERS
,
3859 if (rc
== ERROR_SUCCESS
)
3861 LPWSTR lpGuidString
;
3862 if (UuidToStringW((UUID
*)&DeviceInfoData
->ClassGuid
, &lpGuidString
) == RPC_S_OK
)
3864 rc
= RegQueryValueExW(hKey
, lpGuidString
, NULL
, &dwRegType
, NULL
, &dwLength
);
3865 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_MULTI_SZ
)
3867 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
3868 if (KeyBuffer
!= NULL
)
3870 rc
= RegQueryValueExW(hKey
, lpGuidString
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
3871 if (rc
== ERROR_SUCCESS
)
3874 for (ptr
= KeyBuffer
; *ptr
; ptr
+= strlenW(ptr
) + 1)
3876 /* Add coinstaller to ClassCoInstallersListHead list */
3877 struct CoInstallerElement
*coinstaller
;
3878 TRACE("Got class coinstaller '%s'\n", debugstr_w(ptr
));
3879 coinstaller
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CoInstallerElement
));
3882 ZeroMemory(coinstaller
, sizeof(struct CoInstallerElement
));
3883 if (GetFunctionPointer(ptr
, &coinstaller
->Module
, (PVOID
*)&coinstaller
->Function
) == ERROR_SUCCESS
)
3884 InsertTailList(&ClassCoInstallersListHead
, &coinstaller
->ListEntry
);
3886 HeapFree(GetProcessHeap(), 0, coinstaller
);
3889 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
3892 RpcStringFreeW(&lpGuidString
);
3897 if ((CanHandle
& CLASS_INSTALLER
) && !(InstallParams
.FlagsEx
& DI_FLAGSEX_CI_FAILED
))
3899 hKey
= SetupDiOpenClassRegKey(&DeviceInfoData
->ClassGuid
, KEY_QUERY_VALUE
);
3900 if (hKey
!= INVALID_HANDLE_VALUE
)
3902 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_INSTALLER_32
, NULL
, &dwRegType
, NULL
, &dwLength
);
3903 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_SZ
)
3905 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
3906 if (KeyBuffer
!= NULL
)
3908 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_INSTALLER_32
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
3909 if (rc
== ERROR_SUCCESS
)
3911 /* Get ClassInstaller function pointer */
3912 TRACE("Got class installer '%s'\n", debugstr_w(KeyBuffer
));
3913 if (GetFunctionPointer(KeyBuffer
, &ClassInstallerLibrary
, (PVOID
*)&ClassInstaller
) != ERROR_SUCCESS
)
3915 InstallParams
.FlagsEx
|= DI_FLAGSEX_CI_FAILED
;
3916 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
3919 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
3926 /* Call Class co-installers */
3927 Context
.PostProcessing
= FALSE
;
3929 ListEntry
= ClassCoInstallersListHead
.Flink
;
3930 while (rc
== NO_ERROR
&& ListEntry
!= &ClassCoInstallersListHead
)
3932 struct CoInstallerElement
*coinstaller
;
3933 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
3934 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
3935 coinstaller
->PrivateData
= Context
.PrivateData
;
3936 if (rc
== ERROR_DI_POSTPROCESSING_REQUIRED
)
3938 coinstaller
->DoPostProcessing
= TRUE
;
3941 ListEntry
= ListEntry
->Flink
;
3944 /* Call Device co-installers */
3945 ListEntry
= DeviceCoInstallersListHead
.Flink
;
3946 while (rc
== NO_ERROR
&& ListEntry
!= &DeviceCoInstallersListHead
)
3948 struct CoInstallerElement
*coinstaller
;
3949 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
3950 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
3951 coinstaller
->PrivateData
= Context
.PrivateData
;
3952 if (rc
== ERROR_DI_POSTPROCESSING_REQUIRED
)
3954 coinstaller
->DoPostProcessing
= TRUE
;
3957 ListEntry
= ListEntry
->Flink
;
3960 /* Call Class installer */
3963 rc
= (*ClassInstaller
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3964 FreeFunctionPointer(ClassInstallerLibrary
, ClassInstaller
);
3967 rc
= ERROR_DI_DO_DEFAULT
;
3969 /* Call default handler */
3970 if (rc
== ERROR_DI_DO_DEFAULT
)
3972 if (DefaultHandler
&& !(InstallParams
.Flags
& DI_NODI_DEFAULTACTION
))
3974 if ((*DefaultHandler
)(DeviceInfoSet
, DeviceInfoData
))
3977 rc
= GetLastError();
3983 /* Call Class co-installers that required postprocessing */
3984 Context
.PostProcessing
= TRUE
;
3985 ListEntry
= ClassCoInstallersListHead
.Flink
;
3986 while (ListEntry
!= &ClassCoInstallersListHead
)
3988 struct CoInstallerElement
*coinstaller
;
3989 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
3990 if (coinstaller
->DoPostProcessing
)
3992 Context
.InstallResult
= rc
;
3993 Context
.PrivateData
= coinstaller
->PrivateData
;
3994 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
3996 FreeFunctionPointer(coinstaller
->Module
, coinstaller
->Function
);
3997 ListEntry
= ListEntry
->Flink
;
4000 /* Call Device co-installers that required postprocessing */
4001 ListEntry
= DeviceCoInstallersListHead
.Flink
;
4002 while (ListEntry
!= &DeviceCoInstallersListHead
)
4004 struct CoInstallerElement
*coinstaller
;
4005 coinstaller
= CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
);
4006 if (coinstaller
->DoPostProcessing
)
4008 Context
.InstallResult
= rc
;
4009 Context
.PrivateData
= coinstaller
->PrivateData
;
4010 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
4012 FreeFunctionPointer(coinstaller
->Module
, coinstaller
->Function
);
4013 ListEntry
= ListEntry
->Flink
;
4016 /* Free allocated memory */
4017 while (!IsListEmpty(&ClassCoInstallersListHead
))
4019 ListEntry
= RemoveHeadList(&ClassCoInstallersListHead
);
4020 HeapFree(GetProcessHeap(), 0, CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
));
4022 while (!IsListEmpty(&DeviceCoInstallersListHead
))
4024 ListEntry
= RemoveHeadList(&DeviceCoInstallersListHead
);
4025 HeapFree(GetProcessHeap(), 0, CONTAINING_RECORD(ListEntry
, struct CoInstallerElement
, ListEntry
));
4028 ret
= (rc
== NO_ERROR
);
4032 TRACE("Returning %d\n", ret
);
4036 /***********************************************************************
4037 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
4039 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
4040 HDEVINFO DeviceInfoSet
,
4041 PSP_DEVINFO_DATA DeviceInfoData
,
4042 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
4044 SP_DEVINSTALL_PARAMS_W deviceInstallParamsW
;
4047 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4049 if (DeviceInstallParams
== NULL
)
4050 SetLastError(ERROR_INVALID_PARAMETER
);
4051 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_A
))
4052 SetLastError(ERROR_INVALID_USER_BUFFER
);
4055 deviceInstallParamsW
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4056 ret
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &deviceInstallParamsW
);
4060 /* Do W->A conversion */
4062 DeviceInstallParams
,
4063 &deviceInstallParamsW
,
4064 FIELD_OFFSET(SP_DEVINSTALL_PARAMS_W
, DriverPath
));
4065 if (WideCharToMultiByte(CP_ACP
, 0, deviceInstallParamsW
.DriverPath
, -1,
4066 DeviceInstallParams
->DriverPath
, MAX_PATH
, NULL
, NULL
) == 0)
4068 DeviceInstallParams
->DriverPath
[0] = '\0';
4074 TRACE("Returning %d\n", ret
);
4078 /***********************************************************************
4079 * SetupDiGetDeviceInfoListClass (SETUPAPI.@)
4082 SetupDiGetDeviceInfoListClass(
4083 IN HDEVINFO DeviceInfoSet
,
4084 OUT LPGUID ClassGuid
)
4086 struct DeviceInfoSet
*list
;
4089 TRACE("%p %p\n", DeviceInfoSet
, ClassGuid
);
4092 SetLastError(ERROR_INVALID_HANDLE
);
4093 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4094 SetLastError(ERROR_INVALID_HANDLE
);
4095 else if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
4096 SetLastError(ERROR_NO_ASSOCIATED_CLASS
);
4099 memcpy(&ClassGuid
, &list
->ClassGuid
, sizeof(GUID
));
4104 TRACE("Returning %d\n", ret
);
4108 /***********************************************************************
4109 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
4112 SetupDiGetDeviceInstallParamsW(
4113 IN HDEVINFO DeviceInfoSet
,
4114 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4115 OUT PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4117 struct DeviceInfoSet
*list
;
4120 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4123 SetLastError(ERROR_INVALID_HANDLE
);
4124 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4125 SetLastError(ERROR_INVALID_HANDLE
);
4126 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4127 SetLastError(ERROR_INVALID_USER_BUFFER
);
4128 else if (!DeviceInstallParams
)
4129 SetLastError(ERROR_INVALID_PARAMETER
);
4130 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_W
))
4131 SetLastError(ERROR_INVALID_USER_BUFFER
);
4134 PSP_DEVINSTALL_PARAMS_W Source
;
4137 Source
= &((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->InstallParams
;
4139 Source
= &list
->InstallParams
;
4140 memcpy(DeviceInstallParams
, Source
, Source
->cbSize
);
4144 TRACE("Returning %d\n", ret
);
4149 CheckDeviceInstallParameters(
4150 IN PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4152 DWORD SupportedFlags
=
4153 DI_NOVCP
| /* 0x00000008 */
4154 DI_DIDCOMPAT
| /* 0x00000010 */
4155 DI_DIDCLASS
| /* 0x00000020 */
4156 DI_NEEDRESTART
| /* 0x00000080 */
4157 DI_NEEDREBOOT
| /* 0x00000100 */
4158 DI_RESOURCEPAGE_ADDED
| /* 0x00002000 */
4159 DI_PROPERTIES_CHANGE
| /* 0x00004000 */
4160 DI_ENUMSINGLEINF
| /* 0x00010000 */
4161 DI_DONOTCALLCONFIGMG
| /* 0x00020000 */
4162 DI_CLASSINSTALLPARAMS
| /* 0x00100000 */
4163 DI_NODI_DEFAULTACTION
| /* 0x00200000 */
4164 DI_QUIETINSTALL
| /* 0x00800000 */
4165 DI_NOFILECOPY
| /* 0x01000000 */
4166 DI_DRIVERPAGE_ADDED
; /* 0x04000000 */
4167 DWORD SupportedFlagsEx
=
4168 DI_FLAGSEX_CI_FAILED
| /* 0x00000004 */
4169 DI_FLAGSEX_DIDINFOLIST
| /* 0x00000010 */
4170 DI_FLAGSEX_DIDCOMPATINFO
| /* 0x00000020 */
4171 DI_FLAGSEX_ALLOWEXCLUDEDDRVS
| /* 0x00000800 */
4172 DI_FLAGSEX_NO_DRVREG_MODIFY
| /* 0x00008000 */
4173 DI_FLAGSEX_INSTALLEDDRIVER
; /* 0x04000000 */
4176 /* FIXME: add support for more flags */
4178 /* FIXME: DI_CLASSINSTALLPARAMS flag is not correctly used.
4179 * It should be checked before accessing to other values
4180 * of the SP_DEVINSTALL_PARAMS structure */
4182 if (DeviceInstallParams
->Flags
& ~SupportedFlags
)
4184 FIXME("Unknown Flags: 0x%08lx\n", DeviceInstallParams
->Flags
& ~SupportedFlags
);
4185 SetLastError(ERROR_INVALID_FLAGS
);
4187 else if (DeviceInstallParams
->FlagsEx
& ~SupportedFlagsEx
)
4189 FIXME("Unknown FlagsEx: 0x%08lx\n", DeviceInstallParams
->FlagsEx
& ~SupportedFlagsEx
);
4190 SetLastError(ERROR_INVALID_FLAGS
);
4192 else if ((DeviceInstallParams
->Flags
& DI_NOVCP
)
4193 && (DeviceInstallParams
->FileQueue
== NULL
|| DeviceInstallParams
->FileQueue
== (HSPFILEQ
)INVALID_HANDLE_VALUE
))
4194 SetLastError(ERROR_INVALID_USER_BUFFER
);
4197 /* FIXME: check Reserved field */
4204 /***********************************************************************
4205 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
4208 SetupDiSetDeviceInstallParamsW(
4209 IN HDEVINFO DeviceInfoSet
,
4210 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4211 IN PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
4213 struct DeviceInfoSet
*list
;
4216 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4219 SetLastError(ERROR_INVALID_HANDLE
);
4220 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4221 SetLastError(ERROR_INVALID_HANDLE
);
4222 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4223 SetLastError(ERROR_INVALID_USER_BUFFER
);
4224 else if (!DeviceInstallParams
)
4225 SetLastError(ERROR_INVALID_PARAMETER
);
4226 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_W
))
4227 SetLastError(ERROR_INVALID_USER_BUFFER
);
4228 else if (CheckDeviceInstallParameters(DeviceInstallParams
))
4230 PSP_DEVINSTALL_PARAMS_W Destination
;
4233 Destination
= &((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->InstallParams
;
4235 Destination
= &list
->InstallParams
;
4236 memcpy(Destination
, DeviceInstallParams
, DeviceInstallParams
->cbSize
);
4240 TRACE("Returning %d\n", ret
);
4244 BOOL WINAPI
SetupDiSetDeviceInstallParamsA(
4245 HDEVINFO DeviceInfoSet
,
4246 PSP_DEVINFO_DATA DeviceInfoData
,
4247 PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
4249 SP_DEVINSTALL_PARAMS_W deviceInstallParamsW
;
4253 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
4255 if (DeviceInstallParams
== NULL
)
4256 SetLastError(ERROR_INVALID_PARAMETER
);
4257 else if (DeviceInstallParams
->cbSize
< sizeof(SP_DEVINSTALL_PARAMS_A
))
4258 SetLastError(ERROR_INVALID_USER_BUFFER
);
4261 memcpy(&deviceInstallParamsW
, DeviceInstallParams
, FIELD_OFFSET(SP_DEVINSTALL_PARAMS_A
, DriverPath
));
4262 deviceInstallParamsW
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4263 len
= MultiByteToWideChar(CP_ACP
, 0, DeviceInstallParams
->DriverPath
, -1, NULL
, 0);
4266 ERR("DrivePath is NULL\n");
4271 MultiByteToWideChar(CP_ACP
, 0, DeviceInstallParams
->DriverPath
, -1, deviceInstallParamsW
.DriverPath
, len
);
4272 ret
= SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &deviceInstallParamsW
);
4276 TRACE("Returning %d\n", ret
);
4281 OpenHardwareProfileKey(
4284 IN DWORD samDesired
)
4286 HKEY hHWProfilesKey
= NULL
;
4287 HKEY hHWProfileKey
= NULL
;
4288 HKEY ret
= INVALID_HANDLE_VALUE
;
4291 rc
= RegOpenKeyExW(HKLM
,
4292 REGSTR_PATH_HWPROFILES
,
4296 if (rc
!= ERROR_SUCCESS
)
4313 snprintfW(subKey
, 4, InstanceKeyFormat
, HwProfile
);
4322 if (rc
!= ERROR_SUCCESS
)
4327 ret
= hHWProfileKey
;
4330 if (hHWProfilesKey
!= NULL
)
4331 RegCloseKey(hHWProfilesKey
);
4332 if (hHWProfileKey
!= NULL
&& hHWProfileKey
!= ret
)
4333 RegCloseKey(hHWProfileKey
);
4337 /***********************************************************************
4338 * SetupDiDeleteDeviceInfo (SETUPAPI.@)
4341 SetupDiDeleteDeviceInfo(
4342 IN HDEVINFO DeviceInfoSet
,
4343 IN PSP_DEVINFO_DATA DeviceInfoData
)
4345 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4347 FIXME("not implemented\n");
4348 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4353 /***********************************************************************
4354 * SetupDiOpenDeviceInfoA (SETUPAPI.@)
4357 SetupDiOpenDeviceInfoA(
4358 IN HDEVINFO DeviceInfoSet
,
4359 IN PCSTR DeviceInstanceId
,
4360 IN HWND hwndParent OPTIONAL
,
4362 OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4364 LPWSTR DeviceInstanceIdW
= NULL
;
4367 TRACE("%p %s %p %lx %p\n", DeviceInfoSet
, DeviceInstanceId
, hwndParent
, OpenFlags
, DeviceInfoData
);
4369 DeviceInstanceIdW
= MultiByteToUnicode(DeviceInstanceId
, CP_ACP
);
4370 if (DeviceInstanceIdW
== NULL
)
4373 bResult
= SetupDiOpenDeviceInfoW(DeviceInfoSet
,
4374 DeviceInstanceIdW
, hwndParent
, OpenFlags
, DeviceInfoData
);
4376 MyFree(DeviceInstanceIdW
);
4382 /***********************************************************************
4383 * SetupDiOpenDeviceInfoW (SETUPAPI.@)
4386 SetupDiOpenDeviceInfoW(
4387 IN HDEVINFO DeviceInfoSet
,
4388 IN PCWSTR DeviceInstanceId
,
4389 IN HWND hwndParent OPTIONAL
,
4391 OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4393 struct DeviceInfoSet
*list
;
4394 HKEY hEnumKey
, hKey
= NULL
;
4398 TRACE("%p %s %p %lx %p\n",
4399 DeviceInfoSet
, debugstr_w(DeviceInstanceId
),
4400 hwndParent
, OpenFlags
, DeviceInfoData
);
4402 if (OpenFlags
& DIOD_CANCEL_REMOVE
)
4403 FIXME("DIOD_CANCEL_REMOVE flag not implemented\n");
4406 SetLastError(ERROR_INVALID_HANDLE
);
4407 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4408 SetLastError(ERROR_INVALID_HANDLE
);
4409 else if (!DeviceInstanceId
)
4410 SetLastError(ERROR_INVALID_PARAMETER
);
4411 else if (OpenFlags
& ~(DIOD_CANCEL_REMOVE
| DIOD_INHERIT_CLASSDRVS
))
4413 TRACE("Unknown flags: 0x%08lx\n", OpenFlags
& ~(DIOD_CANCEL_REMOVE
| DIOD_INHERIT_CLASSDRVS
));
4414 SetLastError(ERROR_INVALID_FLAGS
);
4416 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4417 SetLastError(ERROR_INVALID_USER_BUFFER
);
4420 struct DeviceInfo
*deviceInfo
= NULL
;
4421 /* Search if device already exists in DeviceInfoSet.
4422 * If yes, return the existing element
4423 * If no, create a new element using information in registry
4425 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
4426 while (ItemList
!= &list
->ListHead
)
4431 FIXME("not implemented\n");
4432 ItemList
= ItemList
->Flink
;
4437 /* good one found */
4443 WCHAR szClassGuid
[MAX_GUID_STRING_LEN
];
4445 /* Open supposed registry key */
4448 REGSTR_PATH_SYSTEMENUM
,
4452 if (rc
!= ERROR_SUCCESS
)
4463 RegCloseKey(hEnumKey
);
4464 if (rc
!= ERROR_SUCCESS
)
4466 if (rc
== ERROR_FILE_NOT_FOUND
)
4467 rc
= ERROR_NO_SUCH_DEVINST
;
4472 ClassGUID
= GUID_NULL
;
4473 dwSize
= MAX_GUID_STRING_LEN
* sizeof(WCHAR
);
4475 if (RegQueryValueExW(hKey
,
4476 REGSTR_VAL_CLASSGUID
,
4479 (LPBYTE
)szClassGuid
,
4480 &dwSize
) == ERROR_SUCCESS
)
4482 szClassGuid
[MAX_GUID_STRING_LEN
- 2] = UNICODE_NULL
;
4484 /* Convert a string to a ClassGuid */
4485 UuidFromStringW(&szClassGuid
[1], &ClassGUID
);
4488 if (!CreateDeviceInfo(list
, DeviceInstanceId
, &ClassGUID
, &deviceInfo
))
4491 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
4496 if (ret
&& deviceInfo
&& DeviceInfoData
)
4498 memcpy(&DeviceInfoData
->ClassGuid
, &deviceInfo
->ClassGuid
, sizeof(GUID
));
4499 DeviceInfoData
->DevInst
= deviceInfo
->dnDevInst
;
4500 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInfo
;
4511 /***********************************************************************
4512 * SetupDiGetSelectedDevice (SETUPAPI.@)
4515 SetupDiGetSelectedDevice(
4516 IN HDEVINFO DeviceInfoSet
,
4517 OUT PSP_DEVINFO_DATA DeviceInfoData
)
4519 struct DeviceInfoSet
*list
;
4522 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4525 SetLastError(ERROR_INVALID_HANDLE
);
4526 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4527 SetLastError(ERROR_INVALID_HANDLE
);
4528 else if (list
->SelectedDevice
== NULL
)
4529 SetLastError(ERROR_NO_DEVICE_SELECTED
);
4530 else if (!DeviceInfoData
)
4531 SetLastError(ERROR_INVALID_PARAMETER
);
4532 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4533 SetLastError(ERROR_INVALID_USER_BUFFER
);
4536 memcpy(&DeviceInfoData
->ClassGuid
,
4537 &list
->SelectedDevice
->ClassGuid
,
4539 DeviceInfoData
->DevInst
= list
->SelectedDevice
->dnDevInst
;
4540 DeviceInfoData
->Reserved
= (ULONG_PTR
)list
->SelectedDevice
;
4544 TRACE("Returning %d\n", ret
);
4549 /***********************************************************************
4550 * SetupDiSetSelectedDevice (SETUPAPI.@)
4553 SetupDiSetSelectedDevice(
4554 IN HDEVINFO DeviceInfoSet
,
4555 IN PSP_DEVINFO_DATA DeviceInfoData
)
4557 struct DeviceInfoSet
*list
;
4560 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4563 SetLastError(ERROR_INVALID_HANDLE
);
4564 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4565 SetLastError(ERROR_INVALID_HANDLE
);
4566 else if (!DeviceInfoData
)
4567 SetLastError(ERROR_INVALID_PARAMETER
);
4568 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4569 SetLastError(ERROR_INVALID_USER_BUFFER
);
4570 else if (DeviceInfoData
->Reserved
== 0)
4571 SetLastError(ERROR_INVALID_USER_BUFFER
);
4574 list
->SelectedDevice
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
4578 TRACE("Returning %d\n", ret
);
4583 /* Return the current hardware profile id, or -1 if error */
4585 SETUPAPI_GetCurrentHwProfile(
4586 IN HDEVINFO DeviceInfoSet
)
4589 DWORD dwRegType
, dwLength
;
4592 DWORD ret
= (DWORD
)-1;
4595 ((struct DeviceInfoSet
*)DeviceInfoSet
)->HKLM
,
4596 REGSTR_PATH_IDCONFIGDB
,
4600 if (rc
!= ERROR_SUCCESS
)
4606 dwLength
= sizeof(DWORD
);
4607 rc
= RegQueryValueExW(
4609 REGSTR_VAL_CURRENTCONFIG
,
4612 (LPBYTE
)&hwProfile
, &dwLength
);
4613 if (rc
!= ERROR_SUCCESS
)
4618 else if (dwRegType
!= REG_DWORD
|| dwLength
!= sizeof(DWORD
))
4620 SetLastError(ERROR_GEN_FAILURE
);
4635 IN HDEVINFO DeviceInfoSet
,
4636 IN PSP_DEVINFO_DATA DeviceInfoData
)
4639 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
4640 struct DeviceInfo
*deviceInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
4643 cr
= CM_Enable_DevNode_Ex(deviceInfo
->dnDevInst
, 0, set
->hMachine
);
4644 if (cr
!= CR_SUCCESS
)
4646 SetLastError(GetErrorCodeFromCrCode(cr
));
4652 FIXME("Stub: ResetDevice(%p %p)\n", DeviceInfoSet
, DeviceInfoData
);
4657 static BOOL
StopDevice(
4658 IN HDEVINFO DeviceInfoSet
,
4659 IN PSP_DEVINFO_DATA DeviceInfoData
)
4661 FIXME("Stub: StopDevice(%p %p)\n", DeviceInfoSet
, DeviceInfoData
);
4665 /***********************************************************************
4666 * SetupDiChangeState (SETUPAPI.@)
4670 IN HDEVINFO DeviceInfoSet
,
4671 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
4673 PSP_PROPCHANGE_PARAMS PropChange
;
4674 HKEY hKey
= INVALID_HANDLE_VALUE
;
4675 LPCWSTR RegistryValueName
;
4676 DWORD dwConfigFlags
, dwLength
, dwRegType
;
4680 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4682 if (!DeviceInfoData
)
4683 PropChange
= ((struct DeviceInfoSet
*)DeviceInfoSet
)->ClassInstallParams
.PropChangeParams
;
4685 PropChange
= ((struct DeviceInfo
*)DeviceInfoData
->Reserved
)->ClassInstallParams
.PropChangeParams
;
4688 SetLastError(ERROR_INVALID_PARAMETER
);
4692 if (PropChange
->Scope
== DICS_FLAG_GLOBAL
)
4693 RegistryValueName
= REGSTR_VAL_CONFIGFLAGS
;
4695 RegistryValueName
= REGSTR_VAL_CSCONFIGFLAGS
;
4697 switch (PropChange
->StateChange
)
4702 /* Enable/disable device in registry */
4703 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, PropChange
->Scope
, PropChange
->HwProfile
, DIREG_DEV
, KEY_QUERY_VALUE
| KEY_SET_VALUE
);
4704 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
4705 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, PropChange
->Scope
, PropChange
->HwProfile
, DIREG_DEV
, NULL
, NULL
);
4706 if (hKey
== INVALID_HANDLE_VALUE
)
4708 dwLength
= sizeof(DWORD
);
4709 rc
= RegQueryValueExW(
4714 (LPBYTE
)&dwConfigFlags
, &dwLength
);
4715 if (rc
== ERROR_FILE_NOT_FOUND
)
4717 else if (rc
!= ERROR_SUCCESS
)
4722 else if (dwRegType
!= REG_DWORD
|| dwLength
!= sizeof(DWORD
))
4724 SetLastError(ERROR_GEN_FAILURE
);
4727 if (PropChange
->StateChange
== DICS_ENABLE
)
4728 dwConfigFlags
&= ~(PropChange
->Scope
== DICS_FLAG_GLOBAL
? CONFIGFLAG_DISABLED
: CSCONFIGFLAG_DISABLED
);
4730 dwConfigFlags
|= (PropChange
->Scope
== DICS_FLAG_GLOBAL
? CONFIGFLAG_DISABLED
: CSCONFIGFLAG_DISABLED
);
4731 rc
= RegSetValueExW(
4736 (LPBYTE
)&dwConfigFlags
, sizeof(DWORD
));
4737 if (rc
!= ERROR_SUCCESS
)
4743 /* Enable/disable device if needed */
4744 if (PropChange
->Scope
== DICS_FLAG_GLOBAL
4745 || PropChange
->HwProfile
== 0
4746 || PropChange
->HwProfile
== SETUPAPI_GetCurrentHwProfile(DeviceInfoSet
))
4748 if (PropChange
->StateChange
== DICS_ENABLE
)
4749 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
4751 ret
= StopDevice(DeviceInfoSet
, DeviceInfoData
);
4757 case DICS_PROPCHANGE
:
4759 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
4764 ERR("Unknown StateChange 0x%lx\n", PropChange
->StateChange
);
4765 SetLastError(ERROR_NOT_SUPPORTED
);
4770 if (hKey
!= INVALID_HANDLE_VALUE
)
4773 TRACE("Returning %d\n", ret
);
4777 /***********************************************************************
4778 * SetupDiSelectDevice (SETUPAPI.@)
4781 SetupDiSelectDevice(
4782 IN HDEVINFO DeviceInfoSet
,
4783 IN OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4785 FIXME("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4786 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4791 /***********************************************************************
4792 * SetupDiRegisterCoDeviceInstallers (SETUPAPI.@)
4795 SetupDiRegisterCoDeviceInstallers(
4796 IN HDEVINFO DeviceInfoSet
,
4797 IN PSP_DEVINFO_DATA DeviceInfoData
)
4799 BOOL ret
= FALSE
; /* Return value */
4801 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4804 SetLastError(ERROR_INVALID_PARAMETER
);
4805 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
4806 SetLastError(ERROR_INVALID_HANDLE
);
4807 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4808 SetLastError(ERROR_INVALID_HANDLE
);
4809 else if (!DeviceInfoData
)
4810 SetLastError(ERROR_INVALID_PARAMETER
);
4811 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4812 SetLastError(ERROR_INVALID_USER_BUFFER
);
4815 SP_DEVINSTALL_PARAMS_W InstallParams
;
4816 struct DriverInfoElement
*SelectedDriver
;
4819 WCHAR SectionName
[MAX_PATH
];
4820 DWORD SectionNameLength
= 0;
4821 HKEY hKey
= INVALID_HANDLE_VALUE
;
4822 PVOID Context
= NULL
;
4824 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4825 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
4829 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
4830 if (SelectedDriver
== NULL
)
4832 SetLastError(ERROR_NO_DRIVER_SELECTED
);
4836 /* Get .CoInstallers section name */
4837 Result
= SetupDiGetActualSectionToInstallW(
4838 SelectedDriver
->InfFileDetails
->hInf
,
4839 SelectedDriver
->Details
.SectionName
,
4840 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
4841 if (!Result
|| SectionNameLength
> MAX_PATH
- strlenW(DotCoInstallers
) - 1)
4843 lstrcatW(SectionName
, DotCoInstallers
);
4845 /* Open/Create driver key information */
4846 #if _WIN32_WINNT >= 0x502
4847 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_READ
| KEY_WRITE
);
4849 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_ALL_ACCESS
);
4851 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
4852 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, NULL
, NULL
);
4853 if (hKey
== INVALID_HANDLE_VALUE
)
4856 /* Install .CoInstallers section */
4857 DoAction
= SPINST_REGISTRY
;
4858 if (!(InstallParams
.Flags
& DI_NOFILECOPY
))
4860 DoAction
|= SPINST_FILES
;
4861 Context
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
4865 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
4866 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
4867 DoAction
, hKey
, SelectedDriver
->InfFileDetails
->DirectoryName
, SP_COPY_NEWER
,
4868 SetupDefaultQueueCallbackW
, Context
,
4869 DeviceInfoSet
, DeviceInfoData
);
4877 SetupTermDefaultQueueCallback(Context
);
4878 if (hKey
!= INVALID_HANDLE_VALUE
)
4882 TRACE("Returning %d\n", ret
);
4887 InfIsFromOEMLocation(
4889 OUT LPBOOL IsOEMLocation
)
4893 last
= strrchrW(FullName
, '\\');
4896 /* No directory specified */
4897 *IsOEMLocation
= FALSE
;
4904 Windir
= MyMalloc((MAX_PATH
+ 1 + strlenW(InfDirectory
)) * sizeof(WCHAR
));
4907 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4911 ret
= GetSystemWindowsDirectoryW(Windir
, MAX_PATH
);
4912 if (ret
== 0 || ret
> MAX_PATH
)
4915 SetLastError(ERROR_GEN_FAILURE
);
4918 if (*Windir
&& Windir
[strlenW(Windir
) - 1] != '\\')
4919 strcatW(Windir
, BackSlash
);
4920 strcatW(Windir
, InfDirectory
);
4922 if (strncmpiW(FullName
, Windir
, last
- FullName
) == 0)
4924 /* The path is %SYSTEMROOT%\Inf */
4925 *IsOEMLocation
= FALSE
;
4929 /* The file is in another place */
4930 *IsOEMLocation
= TRUE
;
4937 /***********************************************************************
4938 * SetupDiInstallDevice (SETUPAPI.@)
4941 SetupDiInstallDevice(
4942 IN HDEVINFO DeviceInfoSet
,
4943 IN OUT PSP_DEVINFO_DATA DeviceInfoData
)
4945 SP_DEVINSTALL_PARAMS_W InstallParams
;
4946 struct DriverInfoElement
*SelectedDriver
;
4947 SYSTEMTIME DriverDate
;
4948 WCHAR SectionName
[MAX_PATH
];
4950 DWORD SectionNameLength
= 0;
4951 BOOL Result
= FALSE
;
4954 LPWSTR pSectionName
= NULL
;
4955 WCHAR ClassName
[MAX_CLASS_NAME_LEN
];
4957 LPWSTR lpGuidString
= NULL
, lpFullGuidString
= NULL
;
4958 BOOL RebootRequired
= FALSE
;
4959 HKEY hKey
= INVALID_HANDLE_VALUE
;
4960 BOOL NeedtoCopyFile
;
4961 LARGE_INTEGER fullVersion
;
4963 PVOID Context
= NULL
;
4964 BOOL ret
= FALSE
; /* Return value */
4966 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4969 SetLastError(ERROR_INVALID_PARAMETER
);
4970 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
4971 SetLastError(ERROR_INVALID_HANDLE
);
4972 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
4973 SetLastError(ERROR_INVALID_HANDLE
);
4974 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4975 SetLastError(ERROR_INVALID_USER_BUFFER
);
4981 /* One parameter is bad */
4985 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4986 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
4990 if (InstallParams
.FlagsEx
& DI_FLAGSEX_SETFAILEDINSTALL
)
4992 /* Set FAILEDINSTALL in ConfigFlags registry value */
4993 DWORD ConfigFlags
, regType
;
4994 Result
= SetupDiGetDeviceRegistryPropertyW(
4999 (PBYTE
)&ConfigFlags
,
5000 sizeof(ConfigFlags
),
5002 if (!Result
|| regType
!= REG_DWORD
)
5004 SetLastError(ERROR_GEN_FAILURE
);
5007 ConfigFlags
|= DNF_DISABLED
;
5008 Result
= SetupDiSetDeviceRegistryPropertyW(
5012 (PBYTE
)&ConfigFlags
,
5013 sizeof(ConfigFlags
));
5016 SetLastError(ERROR_GEN_FAILURE
);
5024 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
5025 if (SelectedDriver
== NULL
)
5027 SetLastError(ERROR_NO_DRIVER_SELECTED
);
5031 FileTimeToSystemTime(&SelectedDriver
->Info
.DriverDate
, &DriverDate
);
5033 Result
= SetupDiGetActualSectionToInstallW(
5034 SelectedDriver
->InfFileDetails
->hInf
,
5035 SelectedDriver
->Details
.SectionName
,
5036 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
5037 if (!Result
|| SectionNameLength
> MAX_PATH
- strlenW(DotServices
))
5039 pSectionName
= &SectionName
[strlenW(SectionName
)];
5041 /* Get information from [Version] section */
5042 if (!SetupDiGetINFClassW(SelectedDriver
->Details
.InfFileName
, &ClassGuid
, ClassName
, MAX_CLASS_NAME_LEN
, &RequiredSize
))
5044 /* Format ClassGuid to a string */
5045 if (UuidToStringW((UUID
*)&ClassGuid
, &lpGuidString
) != RPC_S_OK
)
5047 RequiredSize
= lstrlenW(lpGuidString
);
5048 lpFullGuidString
= HeapAlloc(GetProcessHeap(), 0, (RequiredSize
+ 3) * sizeof(WCHAR
));
5049 if (!lpFullGuidString
)
5051 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5054 lpFullGuidString
[0] = '{';
5055 memcpy(&lpFullGuidString
[1], lpGuidString
, RequiredSize
* sizeof(WCHAR
));
5056 lpFullGuidString
[RequiredSize
+ 1] = '}';
5057 lpFullGuidString
[RequiredSize
+ 2] = '\0';
5059 /* Copy .inf file to Inf\ directory (if needed) */
5060 Result
= InfIsFromOEMLocation(SelectedDriver
->Details
.InfFileName
, &NeedtoCopyFile
);
5065 WCHAR NewFileName
[MAX_PATH
];
5066 struct InfFileDetails
*newInfFileDetails
;
5067 Result
= SetupCopyOEMInfW(
5068 SelectedDriver
->Details
.InfFileName
,
5071 SP_COPY_NOOVERWRITE
,
5072 NewFileName
, MAX_PATH
,
5077 /* Create a new struct InfFileDetails, and set it to
5078 * SelectedDriver->InfFileDetails, to release use of
5079 * current InfFile */
5080 newInfFileDetails
= CreateInfFileDetails(NewFileName
);
5081 if (!newInfFileDetails
)
5083 DereferenceInfFile(SelectedDriver
->InfFileDetails
);
5084 SelectedDriver
->InfFileDetails
= newInfFileDetails
;
5085 strcpyW(SelectedDriver
->Details
.InfFileName
, NewFileName
);
5088 /* Open/Create driver key information */
5089 #if _WIN32_WINNT >= 0x502
5090 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_READ
| KEY_WRITE
);
5092 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_ALL_ACCESS
);
5094 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5095 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, NULL
, NULL
);
5096 if (hKey
== INVALID_HANDLE_VALUE
)
5099 /* Install main section */
5101 if (!(InstallParams
.FlagsEx
& DI_FLAGSEX_NO_DRVREG_MODIFY
))
5102 DoAction
|= SPINST_REGISTRY
;
5103 if (!(InstallParams
.Flags
& DI_NOFILECOPY
))
5105 DoAction
|= SPINST_FILES
;
5106 Context
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
5110 *pSectionName
= '\0';
5111 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5112 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5113 DoAction
, hKey
, SelectedDriver
->InfFileDetails
->DirectoryName
, SP_COPY_NEWER
,
5114 SetupDefaultQueueCallbackW
, Context
,
5115 DeviceInfoSet
, DeviceInfoData
);
5118 InstallParams
.Flags
|= DI_NOFILECOPY
;
5119 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5121 /* Write information to driver key */
5122 *pSectionName
= UNICODE_NULL
;
5123 memcpy(&fullVersion
, &SelectedDriver
->Info
.DriverVersion
, sizeof(LARGE_INTEGER
));
5124 TRACE("Write information to driver key\n");
5125 TRACE("DriverDate : '%u-%u-%u'\n", DriverDate
.wMonth
, DriverDate
.wDay
, DriverDate
.wYear
);
5126 TRACE("DriverDesc : '%s'\n", debugstr_w(SelectedDriver
->Info
.Description
));
5127 TRACE("DriverVersion : '%ld.%ld.%lu.%ld'\n", fullVersion
.HighPart
>> 16, fullVersion
.HighPart
& 0xffff, fullVersion
.LowPart
>> 16, fullVersion
.LowPart
& 0xffff);
5128 TRACE("InfPath : '%s'\n", debugstr_w(SelectedDriver
->InfFileDetails
->FileName
));
5129 TRACE("InfSection : '%s'\n", debugstr_w(SelectedDriver
->Details
.SectionName
));
5130 TRACE("InfSectionExt : '%s'\n", debugstr_w(&SectionName
[strlenW(SelectedDriver
->Details
.SectionName
)]));
5131 TRACE("MatchingDeviceId: '%s'\n", debugstr_w(SelectedDriver
->MatchingId
));
5132 TRACE("ProviderName : '%s'\n", debugstr_w(SelectedDriver
->Info
.ProviderName
));
5133 sprintfW(Buffer
, DateFormat
, DriverDate
.wMonth
, DriverDate
.wDay
, DriverDate
.wYear
);
5134 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_DATE
, 0, REG_SZ
, (const BYTE
*)Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
));
5135 if (rc
== ERROR_SUCCESS
)
5136 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_DATE_DATA
, 0, REG_BINARY
, (const BYTE
*)&SelectedDriver
->Info
.DriverDate
, sizeof(FILETIME
));
5137 if (rc
== ERROR_SUCCESS
)
5138 rc
= RegSetValueExW(hKey
, REGSTR_VAL_DRVDESC
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.Description
, (strlenW(SelectedDriver
->Info
.Description
) + 1) * sizeof(WCHAR
));
5139 if (rc
== ERROR_SUCCESS
)
5141 sprintfW(Buffer
, VersionFormat
, fullVersion
.HighPart
>> 16, fullVersion
.HighPart
& 0xffff, fullVersion
.LowPart
>> 16, fullVersion
.LowPart
& 0xffff);
5142 rc
= RegSetValueExW(hKey
, REGSTR_DRIVER_VERSION
, 0, REG_SZ
, (const BYTE
*)Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
));
5144 if (rc
== ERROR_SUCCESS
)
5145 rc
= RegSetValueExW(hKey
, REGSTR_VAL_INFPATH
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->InfFileDetails
->FileName
, (strlenW(SelectedDriver
->InfFileDetails
->FileName
) + 1) * sizeof(WCHAR
));
5146 if (rc
== ERROR_SUCCESS
)
5147 rc
= RegSetValueExW(hKey
, REGSTR_VAL_INFSECTION
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Details
.SectionName
, (strlenW(SelectedDriver
->Details
.SectionName
) + 1) * sizeof(WCHAR
));
5148 if (rc
== ERROR_SUCCESS
)
5149 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
));
5150 if (rc
== ERROR_SUCCESS
)
5151 rc
= RegSetValueExW(hKey
, REGSTR_VAL_MATCHINGDEVID
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->MatchingId
, (strlenW(SelectedDriver
->MatchingId
) + 1) * sizeof(WCHAR
));
5152 if (rc
== ERROR_SUCCESS
)
5153 rc
= RegSetValueExW(hKey
, REGSTR_VAL_PROVIDER_NAME
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.ProviderName
, (strlenW(SelectedDriver
->Info
.ProviderName
) + 1) * sizeof(WCHAR
));
5154 if (rc
!= ERROR_SUCCESS
)
5160 hKey
= INVALID_HANDLE_VALUE
;
5162 /* FIXME: Process .LogConfigOverride section */
5164 /* Install .Services section */
5165 strcpyW(pSectionName
, DotServices
);
5166 Result
= SetupInstallServicesFromInfSectionExW(
5167 SelectedDriver
->InfFileDetails
->hInf
,
5176 if (GetLastError() == ERROR_SUCCESS_REBOOT_REQUIRED
)
5177 RebootRequired
= TRUE
;
5179 /* Open device registry key */
5180 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_SET_VALUE
);
5181 if (hKey
== INVALID_HANDLE_VALUE
)
5184 /* Install .HW section */
5186 if (!(InstallParams
.FlagsEx
& DI_FLAGSEX_NO_DRVREG_MODIFY
))
5187 DoAction
|= SPINST_REGISTRY
;
5188 strcpyW(pSectionName
, DotHW
);
5189 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5190 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5191 DoAction
, hKey
, NULL
, 0,
5193 DeviceInfoSet
, DeviceInfoData
);
5197 /* Write information to enum key */
5198 TRACE("Write information to enum key\n");
5199 TRACE("Class : '%s'\n", debugstr_w(ClassName
));
5200 TRACE("ClassGUID : '%s'\n", debugstr_w(lpFullGuidString
));
5201 TRACE("DeviceDesc : '%s'\n", debugstr_w(SelectedDriver
->Info
.Description
));
5202 TRACE("Mfg : '%s'\n", debugstr_w(SelectedDriver
->Info
.MfgName
));
5203 rc
= RegSetValueExW(hKey
, REGSTR_VAL_CLASS
, 0, REG_SZ
, (const BYTE
*)ClassName
, (strlenW(ClassName
) + 1) * sizeof(WCHAR
));
5204 if (rc
== ERROR_SUCCESS
)
5205 rc
= RegSetValueExW(hKey
, REGSTR_VAL_CLASSGUID
, 0, REG_SZ
, (const BYTE
*)lpFullGuidString
, (strlenW(lpFullGuidString
) + 1) * sizeof(WCHAR
));
5206 if (rc
== ERROR_SUCCESS
)
5207 rc
= RegSetValueExW(hKey
, REGSTR_VAL_DEVDESC
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.Description
, (strlenW(SelectedDriver
->Info
.Description
) + 1) * sizeof(WCHAR
));
5208 if (rc
== ERROR_SUCCESS
)
5209 rc
= RegSetValueExW(hKey
, REGSTR_VAL_MFG
, 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.MfgName
, (strlenW(SelectedDriver
->Info
.MfgName
) + 1) * sizeof(WCHAR
));
5210 if (rc
!= ERROR_SUCCESS
)
5216 /* Start the device */
5217 if (!RebootRequired
&& !(InstallParams
.Flags
& (DI_NEEDRESTART
| DI_NEEDREBOOT
| DI_DONOTCALLCONFIGMG
)))
5218 ret
= ResetDevice(DeviceInfoSet
, DeviceInfoData
);
5223 /* End of installation */
5224 if (hKey
!= INVALID_HANDLE_VALUE
)
5227 RpcStringFreeW(&lpGuidString
);
5228 HeapFree(GetProcessHeap(), 0, lpFullGuidString
);
5230 SetupTermDefaultQueueCallback(Context
);
5231 TRACE("Returning %d\n", ret
);
5235 static HKEY
SETUPDI_OpenDevKey(HKEY RootKey
, struct DeviceInfo
*devInfo
, REGSAM samDesired
)
5237 HKEY enumKey
, key
= INVALID_HANDLE_VALUE
;
5240 l
= RegOpenKeyExW(RootKey
, REGSTR_PATH_SYSTEMENUM
, 0, 0, &enumKey
);
5243 l
= RegOpenKeyExW(enumKey
, devInfo
->instanceId
, 0, samDesired
, &key
);
5244 RegCloseKey(enumKey
);
5251 static HKEY
SETUPDI_OpenDrvKey(HKEY RootKey
, struct DeviceInfo
*devInfo
, REGSAM samDesired
)
5253 LPWSTR DriverKey
= NULL
;
5257 HKEY hEnumKey
= NULL
;
5259 HKEY key
= INVALID_HANDLE_VALUE
;
5261 hKey
= SETUPDI_OpenDevKey(RootKey
, devInfo
, KEY_QUERY_VALUE
);
5262 if (hKey
== INVALID_HANDLE_VALUE
)
5264 /* Read the 'Driver' key */
5265 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_DRIVER
, NULL
, &dwRegType
, NULL
, &dwLength
);
5266 if (rc
!= ERROR_SUCCESS
)
5271 else if (dwRegType
!= REG_SZ
)
5273 SetLastError(ERROR_GEN_FAILURE
);
5276 DriverKey
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
5279 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5282 rc
= RegQueryValueExW(hKey
, REGSTR_VAL_DRIVER
, NULL
, &dwRegType
, (LPBYTE
)DriverKey
, &dwLength
);
5283 if (rc
!= ERROR_SUCCESS
)
5290 /* Need to open the driver key */
5293 REGSTR_PATH_CLASS_NT
,
5297 if (rc
!= ERROR_SUCCESS
)
5308 if (rc
!= ERROR_SUCCESS
)
5316 if (hEnumKey
!= NULL
)
5317 RegCloseKey(hEnumKey
);
5318 if (hKey
!= NULL
&& hKey
!= key
)
5323 /***********************************************************************
5324 * SetupDiOpenDevRegKey (SETUPAPI.@)
5326 HKEY WINAPI
SetupDiOpenDevRegKey(
5327 HDEVINFO DeviceInfoSet
,
5328 PSP_DEVINFO_DATA DeviceInfoData
,
5334 struct DeviceInfoSet
*set
= DeviceInfoSet
;
5335 struct DeviceInfo
*devInfo
;
5336 HKEY key
= INVALID_HANDLE_VALUE
;
5339 TRACE("%p %p %d %d %d %x\n", DeviceInfoSet
, DeviceInfoData
,
5340 Scope
, HwProfile
, KeyType
, samDesired
);
5342 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
5344 SetLastError(ERROR_INVALID_HANDLE
);
5345 return INVALID_HANDLE_VALUE
;
5347 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5349 SetLastError(ERROR_INVALID_HANDLE
);
5350 return INVALID_HANDLE_VALUE
;
5352 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
5353 || !DeviceInfoData
->Reserved
)
5355 SetLastError(ERROR_INVALID_PARAMETER
);
5356 return INVALID_HANDLE_VALUE
;
5358 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
5360 SetLastError(ERROR_INVALID_FLAGS
);
5361 return INVALID_HANDLE_VALUE
;
5363 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
5365 SetLastError(ERROR_INVALID_FLAGS
);
5366 return INVALID_HANDLE_VALUE
;
5368 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5369 if (devInfo
->set
!= set
)
5371 SetLastError(ERROR_INVALID_PARAMETER
);
5372 return INVALID_HANDLE_VALUE
;
5374 if (Scope
!= DICS_FLAG_GLOBAL
)
5376 RootKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, 0);
5377 if (RootKey
== INVALID_HANDLE_VALUE
)
5378 return INVALID_HANDLE_VALUE
;
5381 RootKey
= set
->HKLM
;
5385 key
= SETUPDI_OpenDevKey(RootKey
, devInfo
, samDesired
);
5388 key
= SETUPDI_OpenDrvKey(RootKey
, devInfo
, samDesired
);
5391 WARN("unknown KeyType %d\n", KeyType
);
5393 if (RootKey
!= set
->HKLM
)
5394 RegCloseKey(RootKey
);
5398 static BOOL
SETUPDI_DeleteDevKey(HKEY RootKey
, struct DeviceInfo
*devInfo
)
5404 static BOOL
SETUPDI_DeleteDrvKey(HKEY RootKey
, struct DeviceInfo
*devInfo
)
5410 /***********************************************************************
5411 * SetupDiDeleteDevRegKey (SETUPAPI.@)
5413 BOOL WINAPI
SetupDiDeleteDevRegKey(
5414 HDEVINFO DeviceInfoSet
,
5415 PSP_DEVINFO_DATA DeviceInfoData
,
5420 struct DeviceInfoSet
*set
= (struct DeviceInfoSet
*)DeviceInfoSet
;
5421 struct DeviceInfo
*devInfo
;
5425 TRACE("%p %p %d %d %d\n", DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
,
5428 if (!DeviceInfoSet
|| DeviceInfoSet
== INVALID_HANDLE_VALUE
)
5430 SetLastError(ERROR_INVALID_HANDLE
);
5433 if (set
->magic
!= SETUP_DEVICE_INFO_SET_MAGIC
)
5435 SetLastError(ERROR_INVALID_HANDLE
);
5438 if (!DeviceInfoData
|| DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
)
5439 || !DeviceInfoData
->Reserved
)
5441 SetLastError(ERROR_INVALID_PARAMETER
);
5444 if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
5446 SetLastError(ERROR_INVALID_FLAGS
);
5449 if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
&& KeyType
!= DIREG_BOTH
)
5451 SetLastError(ERROR_INVALID_FLAGS
);
5454 devInfo
= (struct DeviceInfo
*)DeviceInfoData
->Reserved
;
5455 if (devInfo
->set
!= set
)
5457 SetLastError(ERROR_INVALID_PARAMETER
);
5460 if (Scope
!= DICS_FLAG_GLOBAL
)
5462 RootKey
= OpenHardwareProfileKey(set
->HKLM
, HwProfile
, 0);
5463 if (RootKey
== INVALID_HANDLE_VALUE
)
5467 RootKey
= set
->HKLM
;
5471 ret
= SETUPDI_DeleteDevKey(RootKey
, devInfo
);
5474 ret
= SETUPDI_DeleteDrvKey(RootKey
, devInfo
);
5477 ret
= SETUPDI_DeleteDevKey(RootKey
, devInfo
);
5479 ret
= SETUPDI_DeleteDrvKey(RootKey
, devInfo
);
5482 WARN("unknown KeyType %d\n", KeyType
);
5484 if (RootKey
!= set
->HKLM
)
5485 RegCloseKey(RootKey
);