2 * SetupAPI device installer
4 * Copyright 2000 Andreas Mohr for CodeWeavers
5 * 2005 Hervé Poussineau (hpoussin@reactos.com)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
33 #define NTOS_MODE_USER
34 #include <ndk/ntndk.h>
36 #include "setupapi_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
41 /* Unicode constants */
42 static const WCHAR ClassGUID
[] = {'C','l','a','s','s','G','U','I','D',0};
43 static const WCHAR Class
[] = {'C','l','a','s','s',0};
44 static const WCHAR ClassInstall32
[] = {'C','l','a','s','s','I','n','s','t','a','l','l','3','2',0};
45 static const WCHAR DeviceInstance
[] = {'D','e','v','i','c','e','I','n','s','t','a','n','c','e',0};
46 static const WCHAR NoDisplayClass
[] = {'N','o','D','i','s','p','l','a','y','C','l','a','s','s',0};
47 static const WCHAR NoInstallClass
[] = {'N','o','I','s','t','a','l','l','C','l','a','s','s',0};
48 static const WCHAR NoUseClass
[] = {'N','o','U','s','e','C','l','a','s','s',0};
49 static const WCHAR NtExtension
[] = {'.','N','T',0};
50 static const WCHAR NtPlatformExtension
[] = {'.','N','T','x','8','6',0};
51 static const WCHAR SymbolicLink
[] = {'S','y','m','b','o','l','i','c','L','i','n','k',0};
52 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
53 static const WCHAR WinExtension
[] = {'.','W','i','n',0};
55 /* Registry key and value names */
56 static const WCHAR ControlClass
[] = {'S','y','s','t','e','m','\\',
57 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
58 'C','o','n','t','r','o','l','\\',
59 'C','l','a','s','s',0};
61 static const WCHAR DeviceClasses
[] = {'S','y','s','t','e','m','\\',
62 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
63 'C','o','n','t','r','o','l','\\',
64 'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
66 static const WCHAR EnumKeyName
[] = {'S','y','s','t','e','m','\\',
67 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
71 /* FIXME: header mess */
72 DEFINE_GUID(GUID_NULL
,
73 0x00000000L
, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
75 (CALLBACK
* CLASS_INSTALL_PROC
) (
76 IN DI_FUNCTION InstallFunction
,
77 IN HDEVINFO DeviceInfoSet
,
78 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
);
80 (WINAPI
* DEFAULT_CLASS_INSTALL_PROC
) (
81 IN HDEVINFO DeviceInfoSet
,
82 IN OUT PSP_DEVINFO_DATA DeviceInfoData
);
84 (CALLBACK
* COINSTALLER_PROC
) (
85 IN DI_FUNCTION InstallFunction
,
86 IN HDEVINFO DeviceInfoSet
,
87 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
88 IN OUT PCOINSTALLER_CONTEXT_DATA Context
);
90 #define SETUP_DEV_INFO_SET_MAGIC 0xd00ff057
92 struct CoInstallerElement
97 COINSTALLER_PROC Function
;
98 BOOL DoPostProcessing
;
102 struct DeviceInterface
/* Element of DeviceInfoElement.InterfaceListHead */
104 LIST_ENTRY ListEntry
;
106 struct DeviceInfoElement
* DeviceInfo
;
107 GUID InterfaceClassGuid
;
110 /* SPINT_ACTIVE : the interface is active/enabled
111 * SPINT_DEFAULT: the interface is the default interface for the device class FIXME???
112 * SPINT_REMOVED: the interface is removed
116 WCHAR SymbolicLink
[0]; /* \\?\ACPI#PNP0501#4&2658d0a0&0#{GUID} */
119 /* We don't want to open the .inf file to read only one information in it, so keep a handle to it once it
120 * has been already loaded once. Keep also a reference counter */
121 struct InfFileDetails
127 struct DriverInfoElement
/* Element of DeviceInfoSet.DriverListHead and DeviceInfoElement.DriverListHead */
129 LIST_ENTRY ListEntry
;
132 SP_DRVINFO_DATA_V2_W Info
;
133 SP_DRVINFO_DETAIL_DATA_W Details
;
136 struct InfFileDetails
*InfFileDetails
;
139 struct DeviceInfoElement
/* Element of DeviceInfoSet.ListHead */
141 LIST_ENTRY ListEntry
;
143 /* Reserved Field points to a struct DriverInfoElement */
144 SP_DEVINSTALL_PARAMS_W InstallParams
;
146 /* Information about devnode:
148 * "Root\*PNP0501" for example.
149 * It doesn't contain the unique ID for the device
150 * (points into the Data field at the end of the structure)
151 * WARNING: no NULL char exist between DeviceName and UniqueId
154 * "5&1be2108e&0" or "0000"
155 * If DICD_GENERATE_ID is specified in creation flags,
156 * this unique ID is autogenerated using 4 digits, base 10
157 * (points into the Data field at the end of the structure)
158 * - DeviceDescription
159 * String which identifies the device. Can be NULL. If not NULL,
160 * points into the Data field at the end of the structure
162 * Identifies the class of this device. FIXME: can it be GUID_NULL?
164 * Is a combination of:
166 * the unique ID needs to be generated
167 * - DICD_INHERIT_CLASSDRVS
168 * inherit driver of the device info set (== same pointer)
172 PCWSTR DeviceDescription
;
176 /* If CreationFlags contains DICD_INHERIT_CLASSDRVS, this list is invalid */
177 /* If the driver is not searched/detected, this list is empty */
178 LIST_ENTRY DriverListHead
; /* List of struct DriverInfoElement */
180 /* List of interfaces implemented by this device */
181 LIST_ENTRY InterfaceListHead
; /* List of struct DeviceInterface */
186 struct DeviceInfoSet
/* HDEVINFO */
188 DWORD magic
; /* SETUP_DEV_INFO_SET_MAGIC */
189 GUID ClassGuid
; /* If != GUID_NULL, only devices of this class can be in the device info set */
190 HKEY HKLM
; /* Local or distant HKEY_LOCAL_MACHINE registry key */
192 /* Reserved Field points to a struct DriverInfoElement */
193 SP_DEVINSTALL_PARAMS_W InstallParams
;
195 /* If the driver is not searched/detected, this list is empty */
196 LIST_ENTRY DriverListHead
; /* List of struct DriverInfoElement */
198 LIST_ENTRY ListHead
; /* List of struct DeviceInfoElement */
201 /***********************************************************************
202 * SetupDiBuildClassInfoList (SETUPAPI.@)
204 BOOL WINAPI
SetupDiBuildClassInfoList(
206 LPGUID ClassGuidList
,
207 DWORD ClassGuidListSize
,
211 return SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
212 ClassGuidListSize
, RequiredSize
,
216 /***********************************************************************
217 * SetupDiBuildClassInfoListExA (SETUPAPI.@)
219 BOOL WINAPI
SetupDiBuildClassInfoListExA(
221 LPGUID ClassGuidList
,
222 DWORD ClassGuidListSize
,
227 LPWSTR MachineNameW
= NULL
;
234 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
235 if (MachineNameW
== NULL
) return FALSE
;
238 bResult
= SetupDiBuildClassInfoListExW(Flags
, ClassGuidList
,
239 ClassGuidListSize
, RequiredSize
,
240 MachineNameW
, Reserved
);
243 MyFree(MachineNameW
);
248 /***********************************************************************
249 * SetupDiBuildClassInfoListExW (SETUPAPI.@)
251 BOOL WINAPI
SetupDiBuildClassInfoListExW(
253 LPGUID ClassGuidList
,
254 DWORD ClassGuidListSize
,
259 WCHAR szKeyName
[MAX_GUID_STRING_LEN
+ 1];
265 DWORD dwGuidListIndex
= 0;
269 if (RequiredSize
!= NULL
)
272 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
277 if (hClassesKey
== INVALID_HANDLE_VALUE
)
282 for (dwIndex
= 0; ; dwIndex
++)
284 dwLength
= MAX_GUID_STRING_LEN
+ 1;
285 lError
= RegEnumKeyExW(hClassesKey
,
293 TRACE("RegEnumKeyExW() returns %ld\n", lError
);
294 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
296 TRACE("Key name: %p\n", szKeyName
);
298 if (RegOpenKeyExW(hClassesKey
,
304 RegCloseKey(hClassesKey
);
308 if (!RegQueryValueExW(hClassKey
,
315 TRACE("'NoUseClass' value found!\n");
316 RegCloseKey(hClassKey
);
320 if ((Flags
& DIBCI_NOINSTALLCLASS
) &&
321 (!RegQueryValueExW(hClassKey
,
328 TRACE("'NoInstallClass' value found!\n");
329 RegCloseKey(hClassKey
);
333 if ((Flags
& DIBCI_NODISPLAYCLASS
) &&
334 (!RegQueryValueExW(hClassKey
,
341 TRACE("'NoDisplayClass' value found!\n");
342 RegCloseKey(hClassKey
);
346 RegCloseKey(hClassKey
);
348 TRACE("Guid: %p\n", szKeyName
);
349 if (dwGuidListIndex
< ClassGuidListSize
)
351 if (szKeyName
[0] == L
'{' && szKeyName
[37] == L
'}')
355 TRACE("Guid: %p\n", &szKeyName
[1]);
357 UuidFromStringW(&szKeyName
[1],
358 &ClassGuidList
[dwGuidListIndex
]);
364 if (lError
!= ERROR_SUCCESS
)
368 RegCloseKey(hClassesKey
);
370 if (RequiredSize
!= NULL
)
371 *RequiredSize
= dwGuidListIndex
;
373 if (ClassGuidListSize
< dwGuidListIndex
)
375 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
382 /***********************************************************************
383 * SetupDiClassGuidsFromNameA (SETUPAPI.@)
385 BOOL WINAPI
SetupDiClassGuidsFromNameA(
387 LPGUID ClassGuidList
,
388 DWORD ClassGuidListSize
,
391 return SetupDiClassGuidsFromNameExA(ClassName
, ClassGuidList
,
392 ClassGuidListSize
, RequiredSize
,
396 /***********************************************************************
397 * SetupDiClassGuidsFromNameW (SETUPAPI.@)
399 BOOL WINAPI
SetupDiClassGuidsFromNameW(
401 LPGUID ClassGuidList
,
402 DWORD ClassGuidListSize
,
405 return SetupDiClassGuidsFromNameExW(ClassName
, ClassGuidList
,
406 ClassGuidListSize
, RequiredSize
,
410 /***********************************************************************
411 * SetupDiClassGuidsFromNameExA (SETUPAPI.@)
413 BOOL WINAPI
SetupDiClassGuidsFromNameExA(
415 LPGUID ClassGuidList
,
416 DWORD ClassGuidListSize
,
421 LPWSTR ClassNameW
= NULL
;
422 LPWSTR MachineNameW
= NULL
;
427 ClassNameW
= MultiByteToUnicode(ClassName
, CP_ACP
);
428 if (ClassNameW
== NULL
)
433 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
434 if (MachineNameW
== NULL
)
441 bResult
= SetupDiClassGuidsFromNameExW(ClassNameW
, ClassGuidList
,
442 ClassGuidListSize
, RequiredSize
,
443 MachineNameW
, Reserved
);
446 MyFree(MachineNameW
);
453 /***********************************************************************
454 * SetupDiClassGuidsFromNameExW (SETUPAPI.@)
456 BOOL WINAPI
SetupDiClassGuidsFromNameExW(
458 LPGUID ClassGuidList
,
459 DWORD ClassGuidListSize
,
464 WCHAR szKeyName
[MAX_GUID_STRING_LEN
+ 1];
465 WCHAR szClassName
[256];
471 DWORD dwGuidListIndex
= 0;
473 if (RequiredSize
!= NULL
)
476 hClassesKey
= SetupDiOpenClassRegKeyExW(NULL
,
477 KEY_ENUMERATE_SUB_KEYS
,
481 if (hClassesKey
== INVALID_HANDLE_VALUE
)
486 for (dwIndex
= 0; ; dwIndex
++)
488 dwLength
= MAX_GUID_STRING_LEN
+ 1;
489 lError
= RegEnumKeyExW(hClassesKey
,
497 TRACE("RegEnumKeyExW() returns %ld\n", lError
);
498 if (lError
== ERROR_SUCCESS
|| lError
== ERROR_MORE_DATA
)
500 TRACE("Key name: %p\n", szKeyName
);
502 if (RegOpenKeyExW(hClassesKey
,
508 RegCloseKey(hClassesKey
);
512 dwLength
= 256 * sizeof(WCHAR
);
513 if (!RegQueryValueExW(hClassKey
,
520 TRACE("Class name: %p\n", szClassName
);
522 if (strcmpiW(szClassName
, ClassName
) == 0)
524 TRACE("Found matching class name\n");
526 TRACE("Guid: %p\n", szKeyName
);
527 if (dwGuidListIndex
< ClassGuidListSize
)
529 if (szKeyName
[0] == L
'{' && szKeyName
[37] == L
'}')
533 TRACE("Guid: %p\n", &szKeyName
[1]);
535 UuidFromStringW(&szKeyName
[1],
536 &ClassGuidList
[dwGuidListIndex
]);
543 RegCloseKey(hClassKey
);
546 if (lError
!= ERROR_SUCCESS
)
550 RegCloseKey(hClassesKey
);
552 if (RequiredSize
!= NULL
)
553 *RequiredSize
= dwGuidListIndex
;
555 if (ClassGuidListSize
< dwGuidListIndex
)
557 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
564 /***********************************************************************
565 * SetupDiClassNameFromGuidA (SETUPAPI.@)
567 BOOL WINAPI
SetupDiClassNameFromGuidA(
568 const GUID
* ClassGuid
,
573 return SetupDiClassNameFromGuidExA(ClassGuid
, ClassName
,
574 ClassNameSize
, RequiredSize
,
578 /***********************************************************************
579 * SetupDiClassNameFromGuidW (SETUPAPI.@)
581 BOOL WINAPI
SetupDiClassNameFromGuidW(
582 const GUID
* ClassGuid
,
587 return SetupDiClassNameFromGuidExW(ClassGuid
, ClassName
,
588 ClassNameSize
, RequiredSize
,
592 /***********************************************************************
593 * SetupDiClassNameFromGuidExA (SETUPAPI.@)
595 BOOL WINAPI
SetupDiClassNameFromGuidExA(
596 const GUID
* ClassGuid
,
603 WCHAR ClassNameW
[MAX_CLASS_NAME_LEN
];
604 LPWSTR MachineNameW
= NULL
;
608 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
609 ret
= SetupDiClassNameFromGuidExW(ClassGuid
, ClassNameW
, MAX_CLASS_NAME_LEN
,
610 NULL
, MachineNameW
, Reserved
);
613 int len
= WideCharToMultiByte(CP_ACP
, 0, ClassNameW
, -1, ClassName
,
614 ClassNameSize
, NULL
, NULL
);
616 if (!ClassNameSize
&& RequiredSize
)
619 MyFree(MachineNameW
);
623 /***********************************************************************
624 * SetupDiClassNameFromGuidExW (SETUPAPI.@)
626 BOOL WINAPI
SetupDiClassNameFromGuidExW(
627 const GUID
* ClassGuid
,
638 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
643 if (hKey
== INVALID_HANDLE_VALUE
)
648 if (RequiredSize
!= NULL
)
651 rc
= RegQueryValueExW(hKey
,
657 if (rc
!= ERROR_SUCCESS
)
664 *RequiredSize
= dwLength
/ sizeof(WCHAR
);
667 dwLength
= ClassNameSize
* sizeof(WCHAR
);
668 rc
= RegQueryValueExW(hKey
,
674 if (rc
!= ERROR_SUCCESS
)
686 /***********************************************************************
687 * SetupDiCreateDeviceInfoList (SETUPAPI.@)
690 SetupDiCreateDeviceInfoList(const GUID
*ClassGuid
,
693 return SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
, NULL
, NULL
);
696 /***********************************************************************
697 * SetupDiCreateDeviceInfoListExA (SETUPAPI.@)
700 SetupDiCreateDeviceInfoListExA(const GUID
*ClassGuid
,
705 LPWSTR MachineNameW
= NULL
;
708 TRACE("%p %p %s %p\n", ClassGuid
, hwndParent
, MachineName
, Reserved
);
712 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
713 if (MachineNameW
== NULL
)
714 return (HDEVINFO
)INVALID_HANDLE_VALUE
;
717 hDevInfo
= SetupDiCreateDeviceInfoListExW(ClassGuid
, hwndParent
,
718 MachineNameW
, Reserved
);
721 MyFree(MachineNameW
);
726 /***********************************************************************
727 * SetupDiCreateDeviceInfoListExW (SETUPAPI.@)
730 SetupDiCreateDeviceInfoListExW(const GUID
*ClassGuid
,
735 struct DeviceInfoSet
*list
;
738 TRACE("%p %p %S %p\n", ClassGuid
, hwndParent
, MachineName
, Reserved
);
740 list
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct DeviceInfoSet
));
743 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
744 return (HDEVINFO
)INVALID_HANDLE_VALUE
;
746 memset(list
, 0, sizeof(struct DeviceInfoSet
));
748 list
->magic
= SETUP_DEV_INFO_SET_MAGIC
;
751 ClassGuid
? ClassGuid
: &GUID_NULL
,
752 sizeof(list
->ClassGuid
));
753 list
->InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
754 list
->InstallParams
.Flags
|= DI_CLASSINSTALLPARAMS
;
755 list
->InstallParams
.hwndParent
= hwndParent
;
758 rc
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &list
->HKLM
);
759 if (rc
!= ERROR_SUCCESS
)
762 HeapFree(GetProcessHeap(), 0, list
);
763 return (HDEVINFO
)INVALID_HANDLE_VALUE
;
768 list
->HKLM
= HKEY_LOCAL_MACHINE
;
770 InitializeListHead(&list
->DriverListHead
);
771 InitializeListHead(&list
->ListHead
);
772 return (HDEVINFO
)list
;
775 /***********************************************************************
776 * SetupDiEnumDeviceInfo (SETUPAPI.@)
778 BOOL WINAPI
SetupDiEnumDeviceInfo(
779 HDEVINFO DeviceInfoSet
,
781 PSP_DEVINFO_DATA DeviceInfoData
)
785 TRACE("%p, 0x%08lx, %p\n", DeviceInfoSet
, MemberIndex
, DeviceInfoData
);
787 SetLastError(ERROR_INVALID_PARAMETER
);
788 else if (DeviceInfoSet
&& DeviceInfoSet
!= (HDEVINFO
)INVALID_HANDLE_VALUE
)
790 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)DeviceInfoSet
;
792 if (list
->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
793 SetLastError(ERROR_INVALID_HANDLE
);
794 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
795 SetLastError(ERROR_INVALID_USER_BUFFER
);
798 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
799 while (ItemList
!= &list
->ListHead
&& MemberIndex
-- > 0)
800 ItemList
= ItemList
->Flink
;
801 if (ItemList
== &list
->ListHead
)
802 SetLastError(ERROR_NO_MORE_ITEMS
);
805 struct DeviceInfoElement
*DevInfo
= (struct DeviceInfoElement
*)ItemList
;
806 memcpy(&DeviceInfoData
->ClassGuid
,
809 DeviceInfoData
->DevInst
= 0; /* FIXME */
810 /* Note: this appears to be dangerous, passing a private
811 * pointer a heap-allocated datum to the caller. However, the
812 * expected lifetime of the device data is the same as the
813 * HDEVINFO; once that is closed, the data are no longer valid.
815 DeviceInfoData
->Reserved
= (ULONG_PTR
)DevInfo
;
821 SetLastError(ERROR_INVALID_HANDLE
);
825 /***********************************************************************
826 * SetupDiGetActualSectionToInstallA (SETUPAPI.@)
828 BOOL WINAPI
SetupDiGetActualSectionToInstallA(
830 PCSTR InfSectionName
,
831 PSTR InfSectionWithExt
,
832 DWORD InfSectionWithExtSize
,
836 LPWSTR InfSectionNameW
= NULL
;
837 PWSTR InfSectionWithExtW
= NULL
;
839 BOOL bResult
= FALSE
;
845 InfSectionNameW
= MultiByteToUnicode(InfSectionName
, CP_ACP
);
846 if (InfSectionNameW
== NULL
) goto end
;
848 if (InfSectionWithExt
)
850 InfSectionWithExtW
= HeapAlloc(GetProcessHeap(), 0, InfSectionWithExtSize
* sizeof(WCHAR
));
851 if (InfSectionWithExtW
== NULL
) goto end
;
854 bResult
= SetupDiGetActualSectionToInstallW(InfHandle
, InfSectionNameW
,
855 InfSectionWithExt
? InfSectionNameW
: NULL
,
856 InfSectionWithExtSize
, RequiredSize
,
857 Extension
? &ExtensionW
: NULL
);
859 if (bResult
&& InfSectionWithExt
)
861 bResult
= WideCharToMultiByte(CP_ACP
, 0, InfSectionWithExtW
, -1, InfSectionWithExt
,
862 InfSectionWithExtSize
, NULL
, NULL
) != 0;
864 if (bResult
&& Extension
)
866 if (ExtensionW
== NULL
)
869 *Extension
= &InfSectionWithExt
[ExtensionW
- InfSectionWithExtW
];
873 if (InfSectionNameW
) MyFree(InfSectionNameW
);
874 if (InfSectionWithExtW
) HeapFree(GetProcessHeap(), 0, InfSectionWithExtW
);
879 /***********************************************************************
880 * SetupDiGetActualSectionToInstallW (SETUPAPI.@)
882 BOOL WINAPI
SetupDiGetActualSectionToInstallW(
884 PCWSTR InfSectionName
,
885 PWSTR InfSectionWithExt
,
886 DWORD InfSectionWithExtSize
,
890 WCHAR szBuffer
[MAX_PATH
];
893 LONG lLineCount
= -1;
895 lstrcpyW(szBuffer
, InfSectionName
);
896 dwLength
= lstrlenW(szBuffer
);
898 if (OsVersionInfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
900 /* Test section name with '.NTx86' extension */
901 lstrcpyW(&szBuffer
[dwLength
], NtPlatformExtension
);
902 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
904 if (lLineCount
== -1)
906 /* Test section name with '.NT' extension */
907 lstrcpyW(&szBuffer
[dwLength
], NtExtension
);
908 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
913 /* Test section name with '.Win' extension */
914 lstrcpyW(&szBuffer
[dwLength
], WinExtension
);
915 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
918 if (lLineCount
== -1)
920 /* Test section name without extension */
921 szBuffer
[dwLength
] = 0;
922 lLineCount
= SetupGetLineCountW(InfHandle
, szBuffer
);
925 if (lLineCount
== -1)
927 SetLastError(ERROR_INVALID_PARAMETER
);
931 dwFullLength
= lstrlenW(szBuffer
);
933 if (InfSectionWithExt
!= NULL
&& InfSectionWithExtSize
!= 0)
935 if (InfSectionWithExtSize
< (dwFullLength
+ 1))
937 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
941 lstrcpyW(InfSectionWithExt
, szBuffer
);
942 if (Extension
!= NULL
)
944 *Extension
= (dwLength
== dwFullLength
) ? NULL
: &InfSectionWithExt
[dwLength
];
948 if (RequiredSize
!= NULL
)
950 *RequiredSize
= dwFullLength
+ 1;
956 /***********************************************************************
957 * SetupDiGetClassDescriptionA (SETUPAPI.@)
959 BOOL WINAPI
SetupDiGetClassDescriptionA(
960 const GUID
* ClassGuid
,
961 PSTR ClassDescription
,
962 DWORD ClassDescriptionSize
,
965 return SetupDiGetClassDescriptionExA(ClassGuid
, ClassDescription
,
966 ClassDescriptionSize
,
967 RequiredSize
, NULL
, NULL
);
970 /***********************************************************************
971 * SetupDiGetClassDescriptionW (SETUPAPI.@)
973 BOOL WINAPI
SetupDiGetClassDescriptionW(
974 const GUID
* ClassGuid
,
975 PWSTR ClassDescription
,
976 DWORD ClassDescriptionSize
,
979 return SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescription
,
980 ClassDescriptionSize
,
981 RequiredSize
, NULL
, NULL
);
984 /***********************************************************************
985 * SetupDiGetClassDescriptionExA (SETUPAPI.@)
987 BOOL WINAPI
SetupDiGetClassDescriptionExA(
988 const GUID
* ClassGuid
,
989 PSTR ClassDescription
,
990 DWORD ClassDescriptionSize
,
995 PWCHAR ClassDescriptionW
;
996 LPWSTR MachineNameW
= NULL
;
1000 if (ClassDescriptionSize
> 0)
1002 ClassDescriptionW
= HeapAlloc(GetProcessHeap(), 0, ClassDescriptionSize
* sizeof(WCHAR
));
1003 if (!ClassDescriptionW
)
1005 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1011 ClassDescriptionW
= NULL
;
1015 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
1018 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1024 ret
= SetupDiGetClassDescriptionExW(ClassGuid
, ClassDescriptionW
, ClassDescriptionSize
* sizeof(WCHAR
),
1025 NULL
, MachineNameW
, Reserved
);
1028 int len
= WideCharToMultiByte(CP_ACP
, 0, ClassDescriptionW
, -1, ClassDescription
,
1029 ClassDescriptionSize
, NULL
, NULL
);
1031 if (!ClassDescriptionSize
&& RequiredSize
)
1032 *RequiredSize
= len
;
1036 HeapFree(GetProcessHeap(), 0, ClassDescriptionW
);
1037 MyFree(MachineNameW
);
1041 /***********************************************************************
1042 * SetupDiGetClassDescriptionExW (SETUPAPI.@)
1044 BOOL WINAPI
SetupDiGetClassDescriptionExW(
1045 const GUID
* ClassGuid
,
1046 PWSTR ClassDescription
,
1047 DWORD ClassDescriptionSize
,
1048 PDWORD RequiredSize
,
1055 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
,
1060 if (hKey
== INVALID_HANDLE_VALUE
)
1062 WARN("SetupDiOpenClassRegKeyExW() failed (Error %lu)\n", GetLastError());
1066 if (RequiredSize
!= NULL
)
1069 if (RegQueryValueExW(hKey
,
1080 *RequiredSize
= dwLength
/ sizeof(WCHAR
);
1083 dwLength
= ClassDescriptionSize
* sizeof(WCHAR
);
1084 if (RegQueryValueExW(hKey
,
1088 (LPBYTE
)ClassDescription
,
1100 /***********************************************************************
1101 * SetupDiGetClassDevsA (SETUPAPI.@)
1103 HDEVINFO WINAPI
SetupDiGetClassDevsA(
1109 return SetupDiGetClassDevsExA(class, enumstr
, parent
,
1110 flags
, NULL
, NULL
, NULL
);
1113 /***********************************************************************
1114 * SetupDiGetClassDevsW (SETUPAPI.@)
1116 HDEVINFO WINAPI
SetupDiGetClassDevsW(
1122 return SetupDiGetClassDevsExW(class, enumstr
, parent
,
1123 flags
, NULL
, NULL
, NULL
);
1126 /***********************************************************************
1127 * SetupDiGetClassDevsExA (SETUPAPI.@)
1129 HDEVINFO WINAPI
SetupDiGetClassDevsExA(
1139 LPWSTR enumstrW
= NULL
;
1140 LPWSTR machineW
= NULL
;
1144 int len
= MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, NULL
, 0);
1145 enumstrW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1148 ret
= (HDEVINFO
)INVALID_HANDLE_VALUE
;
1151 MultiByteToWideChar(CP_ACP
, 0, enumstr
, -1, enumstrW
, len
);
1155 int len
= MultiByteToWideChar(CP_ACP
, 0, machine
, -1, NULL
, 0);
1156 machineW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1159 ret
= (HDEVINFO
)INVALID_HANDLE_VALUE
;
1162 MultiByteToWideChar(CP_ACP
, 0, machine
, -1, machineW
, len
);
1164 ret
= SetupDiGetClassDevsExW(class, enumstrW
, parent
, flags
, deviceset
, machineW
, reserved
);
1167 HeapFree(GetProcessHeap(), 0, enumstrW
);
1168 HeapFree(GetProcessHeap(), 0, machineW
);
1173 CreateDeviceInfoElement(
1174 IN LPCWSTR InstancePath
,
1175 IN LPCGUID pClassGuid
,
1176 OUT
struct DeviceInfoElement
**pDeviceInfo
)
1179 struct DeviceInfoElement
*deviceInfo
;
1181 *pDeviceInfo
= NULL
;
1183 size
= sizeof(struct DeviceInfoElement
) + (wcslen(InstancePath
) + 1) * sizeof(WCHAR
);
1184 deviceInfo
= HeapAlloc(GetProcessHeap(), 0, size
);
1187 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1190 memset(deviceInfo
, 0, size
);
1191 deviceInfo
->InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
1192 wcscpy(deviceInfo
->Data
, InstancePath
);
1193 deviceInfo
->DeviceName
= deviceInfo
->Data
;
1194 deviceInfo
->UniqueId
= wcsrchr(deviceInfo
->Data
, '\\');
1195 deviceInfo
->DeviceDescription
= NULL
;
1196 memcpy(&deviceInfo
->ClassGuid
, pClassGuid
, sizeof(GUID
));
1197 deviceInfo
->CreationFlags
= 0;
1198 InitializeListHead(&deviceInfo
->DriverListHead
);
1199 InitializeListHead(&deviceInfo
->InterfaceListHead
);
1201 *pDeviceInfo
= deviceInfo
;
1206 CreateDeviceInterface(
1207 IN
struct DeviceInfoElement
* deviceInfo
,
1208 IN LPCWSTR SymbolicLink
,
1209 IN LPCGUID pInterfaceGuid
,
1210 OUT
struct DeviceInterface
**pDeviceInterface
)
1212 struct DeviceInterface
*deviceInterface
;
1214 *pDeviceInterface
= NULL
;
1216 deviceInterface
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct DeviceInterface
) + (wcslen(SymbolicLink
) + 1) * sizeof(WCHAR
));
1217 if (!deviceInterface
)
1219 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1222 deviceInterface
->DeviceInfo
= deviceInfo
;
1223 wcscpy(deviceInterface
->SymbolicLink
, SymbolicLink
);
1224 deviceInterface
->Flags
= 0; /* FIXME */
1225 memcpy(&deviceInterface
->InterfaceClassGuid
, pInterfaceGuid
, sizeof(GUID
));
1227 *pDeviceInterface
= deviceInterface
;
1231 static LONG
SETUP_CreateDevListFromEnumerator(
1232 struct DeviceInfoSet
*list
,
1233 LPCGUID pClassGuid OPTIONAL
,
1235 HKEY hEnumeratorKey
) /* handle to Enumerator registry key */
1237 HKEY hDeviceIdKey
, hInstanceIdKey
;
1238 WCHAR KeyBuffer
[MAX_PATH
];
1239 WCHAR InstancePath
[MAX_PATH
];
1240 LPWSTR pEndOfInstancePath
; /* Pointer into InstancePath buffer */
1241 struct DeviceInfoElement
*deviceInfo
;
1243 DWORD dwLength
, dwRegType
;
1246 /* Enumerate device IDs (subkeys of hEnumeratorKey) */
1249 dwLength
= sizeof(KeyBuffer
) / sizeof(KeyBuffer
[0]);
1250 rc
= RegEnumKeyExW(hEnumeratorKey
, i
, KeyBuffer
, &dwLength
, NULL
, NULL
, NULL
, NULL
);
1251 if (rc
== ERROR_NO_MORE_ITEMS
)
1253 if (rc
!= ERROR_SUCCESS
)
1257 /* Open device id sub key */
1258 rc
= RegOpenKeyExW(hEnumeratorKey
, KeyBuffer
, 0, KEY_ENUMERATE_SUB_KEYS
, &hDeviceIdKey
);
1259 if (rc
!= ERROR_SUCCESS
)
1261 wcscpy(InstancePath
, Enumerator
);
1262 wcscat(InstancePath
, L
"\\");
1263 wcscat(InstancePath
, KeyBuffer
);
1264 wcscat(InstancePath
, L
"\\");
1265 pEndOfInstancePath
= &InstancePath
[wcslen(InstancePath
)];
1267 /* Enumerate instance IDs (subkeys of hDeviceIdKey) */
1273 dwLength
= sizeof(KeyBuffer
) / sizeof(KeyBuffer
[0]);
1274 rc
= RegEnumKeyExW(hDeviceIdKey
, j
, KeyBuffer
, &dwLength
, NULL
, NULL
, NULL
, NULL
);
1275 if (rc
== ERROR_NO_MORE_ITEMS
)
1277 if (rc
!= ERROR_SUCCESS
)
1279 RegCloseKey(hDeviceIdKey
);
1284 /* Open instance id sub key */
1285 rc
= RegOpenKeyExW(hDeviceIdKey
, KeyBuffer
, 0, KEY_QUERY_VALUE
, &hInstanceIdKey
);
1286 if (rc
!= ERROR_SUCCESS
)
1288 RegCloseKey(hDeviceIdKey
);
1291 *pEndOfInstancePath
= '\0';
1292 wcscat(InstancePath
, KeyBuffer
);
1294 /* Read ClassGUID value */
1295 dwLength
= sizeof(KeyBuffer
) - sizeof(WCHAR
);
1296 rc
= RegQueryValueExW(hInstanceIdKey
, ClassGUID
, NULL
, &dwRegType
, (LPBYTE
)KeyBuffer
, &dwLength
);
1297 RegCloseKey(hInstanceIdKey
);
1298 if (rc
== ERROR_FILE_NOT_FOUND
)
1301 /* Skip this bad entry as we can't verify it */
1304 else if (rc
!= ERROR_SUCCESS
)
1306 RegCloseKey(hDeviceIdKey
);
1309 else if (dwRegType
!= REG_SZ
)
1311 RegCloseKey(hDeviceIdKey
);
1312 return ERROR_GEN_FAILURE
;
1315 KeyBuffer
[37] = '\0'; /* Replace the } by a NULL character */
1316 if (UuidFromStringW(&KeyBuffer
[1], &KeyGuid
) != RPC_S_OK
)
1318 RegCloseKey(hDeviceIdKey
);
1319 return GetLastError();
1321 if (pClassGuid
&& !IsEqualIID(&KeyGuid
, pClassGuid
))
1323 /* Skip this entry as it is not the right device class */
1327 /* Add the entry to the list */
1328 if (!CreateDeviceInfoElement(InstancePath
, &KeyGuid
, &deviceInfo
))
1330 RegCloseKey(hDeviceIdKey
);
1331 return GetLastError();
1333 TRACE("Adding '%S' to device info set %p\n", InstancePath
, list
);
1334 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
1336 RegCloseKey(hDeviceIdKey
);
1339 return ERROR_SUCCESS
;
1342 static LONG
SETUP_CreateDevList(
1343 struct DeviceInfoSet
*list
,
1344 PCWSTR MachineName OPTIONAL
,
1345 LPGUID
class OPTIONAL
,
1346 PCWSTR Enumerator OPTIONAL
)
1348 HKEY HKLM
, hEnumKey
, hEnumeratorKey
;
1349 WCHAR KeyBuffer
[MAX_PATH
];
1354 if (IsEqualIID(class, &GUID_NULL
))
1358 if (MachineName
!= NULL
)
1360 rc
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &HKLM
);
1361 if (rc
!= ERROR_SUCCESS
)
1365 HKLM
= HKEY_LOCAL_MACHINE
;
1367 rc
= RegOpenKeyExW(HKLM
,
1370 KEY_ENUMERATE_SUB_KEYS
,
1372 if (MachineName
!= NULL
) RegCloseKey(HKLM
);
1373 if (rc
!= ERROR_SUCCESS
)
1376 /* If enumerator is provided, call directly SETUP_CreateDevListFromEnumerator.
1377 * Else, enumerate all enumerators all call SETUP_CreateDevListFromEnumerator
1386 KEY_ENUMERATE_SUB_KEYS
,
1388 RegCloseKey(hEnumKey
);
1389 if (rc
!= ERROR_SUCCESS
)
1391 rc
= SETUP_CreateDevListFromEnumerator(list
, class, Enumerator
, hEnumeratorKey
);
1392 RegCloseKey(hEnumeratorKey
);
1397 /* Enumerate enumerators */
1401 dwLength
= sizeof(KeyBuffer
) / sizeof(KeyBuffer
[0]);
1402 rc
= RegEnumKeyExW(hEnumKey
, i
, KeyBuffer
, &dwLength
, NULL
, NULL
, NULL
, NULL
);
1403 if (rc
== ERROR_NO_MORE_ITEMS
)
1405 if (rc
!= ERROR_SUCCESS
)
1407 RegCloseKey(hEnumKey
);
1413 rc
= RegOpenKeyExW(hEnumKey
, KeyBuffer
, 0, KEY_ENUMERATE_SUB_KEYS
, &hEnumeratorKey
);
1414 if (rc
!= ERROR_SUCCESS
)
1416 RegCloseKey(hEnumKey
);
1420 /* Call SETUP_CreateDevListFromEnumerator */
1421 rc
= SETUP_CreateDevListFromEnumerator(list
, class, KeyBuffer
, hEnumeratorKey
);
1422 RegCloseKey(hEnumeratorKey
);
1423 if (rc
!= ERROR_SUCCESS
)
1425 RegCloseKey(hEnumKey
);
1429 RegCloseKey(hEnumKey
);
1430 return ERROR_SUCCESS
;
1435 static LONG
SETUP_CreateSerialDeviceList(
1436 struct DeviceInfoSet
*list
,
1438 LPGUID InterfaceGuid
,
1439 PCWSTR DeviceInstanceW
)
1441 static const size_t initialSize
= 100;
1443 WCHAR buf
[initialSize
];
1445 static const WCHAR devicePrefixW
[] = { 'C','O','M',0 };
1447 struct DeviceInfoElement
*deviceInfo
;
1450 WARN("'MachineName' is ignored on Wine!\n");
1451 if (DeviceInstanceW
)
1452 WARN("'DeviceInstanceW' can't be set on Wine!\n");
1458 if (QueryDosDeviceW(NULL
, devices
, size
) != 0)
1460 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1464 HeapFree(GetProcessHeap(), 0, devices
);
1465 devices
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
1467 return ERROR_NOT_ENOUGH_MEMORY
;
1473 HeapFree(GetProcessHeap(), 0, devices
);
1474 return GetLastError();
1478 /* 'devices' is a MULTI_SZ string */
1479 for (ptr
= devices
; *ptr
; ptr
+= strlenW(ptr
) + 1)
1481 if (strncmpW(devicePrefixW
, ptr
, sizeof(devicePrefixW
) / sizeof(devicePrefixW
[0]) - 1) == 0)
1483 /* We have found a device */
1484 struct DeviceInterface
*interfaceInfo
;
1485 TRACE("Adding %s to list\n", debugstr_w(ptr
));
1486 /* Step 1. Create a device info element */
1487 if (!CreateDeviceInfoElement(ptr
, &GUID_SERENUM_BUS_ENUMERATOR
, &deviceInfo
))
1490 HeapFree(GetProcessHeap(), 0, devices
);
1491 return GetLastError();
1493 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
1495 /* Step 2. Create an interface list for this element */
1496 if (!CreateDeviceInterface(deviceInfo
, ptr
, InterfaceGuid
, &interfaceInfo
))
1499 HeapFree(GetProcessHeap(), 0, devices
);
1500 return GetLastError();
1502 InsertTailList(&deviceInfo
->InterfaceListHead
, &interfaceInfo
->ListEntry
);
1506 HeapFree(GetProcessHeap(), 0, devices
);
1507 return ERROR_SUCCESS
;
1510 #else /* __REACTOS__ */
1512 static LONG
SETUP_CreateInterfaceList(
1513 struct DeviceInfoSet
*list
,
1515 LPGUID InterfaceGuid
,
1516 PCWSTR DeviceInstanceW
/* OPTIONAL */)
1518 HKEY hInterfaceKey
; /* HKLM\SYSTEM\CurrentControlSet\Control\DeviceClasses\{GUID} */
1519 HKEY hDeviceInstanceKey
; /* HKLM\SYSTEM\CurrentControlSet\Control\DeviceClasses\{GUID}\##?#{InstancePath} */
1520 HKEY hReferenceKey
; /* HKLM\SYSTEM\CurrentControlSet\Control\DeviceClasses\{GUID}\##?#{InstancePath}\#{ReferenceString} */
1521 HKEY hEnumKey
; /* HKLM\SYSTEM\CurrentControlSet\Enum */
1522 HKEY hKey
; /* HKLM\SYSTEM\CurrentControlSet\Enum\{Instance\Path} */
1524 WCHAR KeyBuffer
[max(MAX_PATH
, MAX_GUID_STRING_LEN
) + 1];
1527 DWORD dwLength
, dwInstancePathLength
;
1530 struct DeviceInfoElement
*deviceInfo
;
1532 /* Open registry key related to this interface */
1533 hInterfaceKey
= SetupDiOpenClassRegKeyExW(InterfaceGuid
, KEY_ENUMERATE_SUB_KEYS
, DIOCR_INTERFACE
, MachineName
, NULL
);
1534 if (hInterfaceKey
== INVALID_HANDLE_VALUE
)
1535 return GetLastError();
1537 /* Enumerate sub keys of hInterfaceKey */
1541 dwLength
= sizeof(KeyBuffer
) / sizeof(KeyBuffer
[0]);
1542 rc
= RegEnumKeyExW(hInterfaceKey
, i
, KeyBuffer
, &dwLength
, NULL
, NULL
, NULL
, NULL
);
1543 if (rc
== ERROR_NO_MORE_ITEMS
)
1545 if (rc
!= ERROR_SUCCESS
)
1547 RegCloseKey(hInterfaceKey
);
1553 rc
= RegOpenKeyExW(hInterfaceKey
, KeyBuffer
, 0, KEY_QUERY_VALUE
| KEY_ENUMERATE_SUB_KEYS
, &hDeviceInstanceKey
);
1554 if (rc
!= ERROR_SUCCESS
)
1556 RegCloseKey(hInterfaceKey
);
1560 /* Read DeviceInstance */
1561 rc
= RegQueryValueExW(hDeviceInstanceKey
, DeviceInstance
, NULL
, &dwRegType
, NULL
, &dwInstancePathLength
);
1562 if (rc
!= ERROR_SUCCESS
)
1564 RegCloseKey(hDeviceInstanceKey
);
1565 RegCloseKey(hInterfaceKey
);
1568 if (dwRegType
!= REG_SZ
)
1570 RegCloseKey(hDeviceInstanceKey
);
1571 RegCloseKey(hInterfaceKey
);
1572 return ERROR_GEN_FAILURE
;
1574 InstancePath
= HeapAlloc(GetProcessHeap(), 0, dwInstancePathLength
+ sizeof(WCHAR
));
1577 RegCloseKey(hDeviceInstanceKey
);
1578 RegCloseKey(hInterfaceKey
);
1579 return ERROR_NOT_ENOUGH_MEMORY
;
1581 rc
= RegQueryValueExW(hDeviceInstanceKey
, DeviceInstance
, NULL
, NULL
, (LPBYTE
)InstancePath
, &dwInstancePathLength
);
1582 if (rc
!= ERROR_SUCCESS
)
1584 HeapFree(GetProcessHeap(), 0, InstancePath
);
1585 RegCloseKey(hDeviceInstanceKey
);
1586 RegCloseKey(hInterfaceKey
);
1589 InstancePath
[dwInstancePathLength
/ sizeof(WCHAR
)] = '\0';
1590 TRACE("DeviceInstance %s\n", debugstr_w(InstancePath
));
1592 if (DeviceInstanceW
)
1594 /* Check if device enumerator is not the right one */
1595 if (wcscmp(DeviceInstanceW
, InstancePath
) != 0)
1597 HeapFree(GetProcessHeap(), 0, InstancePath
);
1598 RegCloseKey(hDeviceInstanceKey
);
1603 /* Find class GUID associated to the device instance */
1608 KEY_ENUMERATE_SUB_KEYS
,
1610 if (rc
!= ERROR_SUCCESS
)
1612 HeapFree(GetProcessHeap(), 0, InstancePath
);
1613 RegCloseKey(hDeviceInstanceKey
);
1614 RegCloseKey(hInterfaceKey
);
1623 RegCloseKey(hEnumKey
);
1624 if (rc
!= ERROR_SUCCESS
)
1626 HeapFree(GetProcessHeap(), 0, InstancePath
);
1627 RegCloseKey(hDeviceInstanceKey
);
1628 RegCloseKey(hInterfaceKey
);
1631 dwLength
= sizeof(KeyBuffer
) - sizeof(WCHAR
);
1632 rc
= RegQueryValueExW(hKey
, ClassGUID
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
1634 if (rc
!= ERROR_SUCCESS
)
1636 HeapFree(GetProcessHeap(), 0, InstancePath
);
1637 RegCloseKey(hDeviceInstanceKey
);
1638 RegCloseKey(hInterfaceKey
);
1641 KeyBuffer
[dwLength
/ sizeof(WCHAR
)] = '\0';
1642 KeyBuffer
[37] = '\0'; /* Replace the } by a NULL character */
1643 if (UuidFromStringW(&KeyBuffer
[1], &ClassGuid
) != RPC_S_OK
)
1645 HeapFree(GetProcessHeap(), 0, InstancePath
);
1646 RegCloseKey(hDeviceInstanceKey
);
1647 RegCloseKey(hInterfaceKey
);
1648 return ERROR_GEN_FAILURE
;
1650 TRACE("ClassGUID %s\n", debugstr_guid(&ClassGuid
));
1652 /* If current device doesn't match the list GUID (if any), skip this entry */
1653 if (!IsEqualIID(&list
->ClassGuid
, &GUID_NULL
) && !IsEqualIID(&list
->ClassGuid
, &ClassGuid
))
1655 HeapFree(GetProcessHeap(), 0, InstancePath
);
1656 RegCloseKey(hDeviceInstanceKey
);
1660 /* Enumerate subkeys of hDeviceInstanceKey (ie "#ReferenceString" in IoRegisterDeviceInterface). Skip entries that don't start with '#' */
1664 LPWSTR pSymbolicLink
;
1665 struct DeviceInterface
*interfaceInfo
;
1667 dwLength
= sizeof(KeyBuffer
) / sizeof(KeyBuffer
[0]);
1668 rc
= RegEnumKeyExW(hDeviceInstanceKey
, j
, KeyBuffer
, &dwLength
, NULL
, NULL
, NULL
, NULL
);
1669 if (rc
== ERROR_NO_MORE_ITEMS
)
1671 if (rc
!= ERROR_SUCCESS
)
1673 HeapFree(GetProcessHeap(), 0, InstancePath
);
1674 RegCloseKey(hDeviceInstanceKey
);
1675 RegCloseKey(hInterfaceKey
);
1679 if (KeyBuffer
[0] != '#')
1680 /* This entry doesn't represent an interesting entry */
1684 rc
= RegOpenKeyExW(hDeviceInstanceKey
, KeyBuffer
, 0, KEY_QUERY_VALUE
, &hReferenceKey
);
1685 if (rc
!= ERROR_SUCCESS
)
1687 RegCloseKey(hDeviceInstanceKey
);
1688 RegCloseKey(hInterfaceKey
);
1692 /* Read SymbolicLink value */
1693 rc
= RegQueryValueExW(hReferenceKey
, SymbolicLink
, NULL
, &dwRegType
, NULL
, &dwLength
);
1694 if (rc
!= ERROR_SUCCESS
)
1696 RegCloseKey(hReferenceKey
);
1697 RegCloseKey(hDeviceInstanceKey
);
1698 RegCloseKey(hInterfaceKey
);
1701 if (dwRegType
!= REG_SZ
)
1703 RegCloseKey(hReferenceKey
);
1704 RegCloseKey(hDeviceInstanceKey
);
1705 RegCloseKey(hInterfaceKey
);
1706 return ERROR_GEN_FAILURE
;
1709 /* We have found a device */
1710 /* Step 1. Create a device info element */
1711 if (!CreateDeviceInfoElement(InstancePath
, &ClassGuid
, &deviceInfo
))
1713 RegCloseKey(hReferenceKey
);
1714 RegCloseKey(hDeviceInstanceKey
);
1715 RegCloseKey(hInterfaceKey
);
1716 return GetLastError();
1718 TRACE("Adding device %s to list\n", debugstr_w(InstancePath
));
1719 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
1721 /* Step 2. Create an interface list for this element */
1722 pSymbolicLink
= HeapAlloc(GetProcessHeap(), 0, (dwLength
+ 1) * sizeof(WCHAR
));
1725 RegCloseKey(hReferenceKey
);
1726 RegCloseKey(hDeviceInstanceKey
);
1727 RegCloseKey(hInterfaceKey
);
1728 return ERROR_NOT_ENOUGH_MEMORY
;
1730 rc
= RegQueryValueExW(hReferenceKey
, SymbolicLink
, NULL
, NULL
, (LPBYTE
)pSymbolicLink
, &dwLength
);
1731 pSymbolicLink
[dwLength
/ sizeof(WCHAR
)] = '\0';
1732 RegCloseKey(hReferenceKey
);
1733 if (rc
!= ERROR_SUCCESS
)
1735 HeapFree(GetProcessHeap(), 0, pSymbolicLink
);
1736 RegCloseKey(hDeviceInstanceKey
);
1737 RegCloseKey(hInterfaceKey
);
1740 if (!CreateDeviceInterface(deviceInfo
, pSymbolicLink
, InterfaceGuid
, &interfaceInfo
))
1742 HeapFree(GetProcessHeap(), 0, pSymbolicLink
);
1743 RegCloseKey(hDeviceInstanceKey
);
1744 RegCloseKey(hInterfaceKey
);
1745 return GetLastError();
1747 TRACE("Adding interface %s to list\n", debugstr_w(pSymbolicLink
));
1748 HeapFree(GetProcessHeap(), 0, pSymbolicLink
);
1749 InsertTailList(&deviceInfo
->InterfaceListHead
, &interfaceInfo
->ListEntry
);
1751 RegCloseKey(hDeviceInstanceKey
);
1753 RegCloseKey(hInterfaceKey
);
1754 return ERROR_SUCCESS
;
1756 #endif /* __REACTOS__ */
1758 /***********************************************************************
1759 * SetupDiGetClassDevsExW (SETUPAPI.@)
1761 HDEVINFO WINAPI
SetupDiGetClassDevsExW(
1770 HDEVINFO hDeviceInfo
= INVALID_HANDLE_VALUE
;
1771 struct DeviceInfoSet
*list
;
1775 TRACE("%s %s %p 0x%08lx %p %s %p\n", debugstr_guid(class), debugstr_w(enumstr
),
1776 parent
, flags
, deviceset
, debugstr_w(machine
), reserved
);
1778 /* Create the deviceset if not set */
1781 list
= (struct DeviceInfoSet
*)deviceset
;
1782 if (list
->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
1784 SetLastError(ERROR_INVALID_HANDLE
);
1785 return INVALID_HANDLE_VALUE
;
1787 hDeviceInfo
= deviceset
;
1791 hDeviceInfo
= SetupDiCreateDeviceInfoListExW(
1792 flags
& DIGCF_DEVICEINTERFACE
? NULL
: class,
1793 NULL
, machine
, NULL
);
1794 if (hDeviceInfo
== INVALID_HANDLE_VALUE
)
1795 return INVALID_HANDLE_VALUE
;
1796 list
= (struct DeviceInfoSet
*)hDeviceInfo
;
1799 if (IsEqualIID(&list
->ClassGuid
, &GUID_NULL
))
1802 pClassGuid
= &list
->ClassGuid
;
1804 if (flags
& DIGCF_PRESENT
)
1805 FIXME(": flag DIGCF_PRESENT ignored\n");
1806 if (flags
& DIGCF_PROFILE
)
1807 FIXME(": flag DIGCF_PROFILE ignored\n");
1809 if (flags
& DIGCF_ALLCLASSES
)
1811 rc
= SETUP_CreateDevList(list
, machine
, pClassGuid
, enumstr
);
1812 if (rc
!= ERROR_SUCCESS
)
1816 SetupDiDestroyDeviceInfoList(hDeviceInfo
);
1817 return INVALID_HANDLE_VALUE
;
1821 else if (flags
& DIGCF_DEVICEINTERFACE
)
1825 SetLastError(ERROR_INVALID_PARAMETER
);
1827 SetupDiDestroyDeviceInfoList(hDeviceInfo
);
1828 return INVALID_HANDLE_VALUE
;
1832 /* Special case: find serial ports by calling QueryDosDevice */
1833 if (IsEqualIID(class, &GUID_DEVINTERFACE_COMPORT
))
1834 rc
= SETUP_CreateSerialDeviceList(list
, machine
, (LPGUID
)class, enumstr
);
1835 if (IsEqualIID(class, &GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR
))
1836 rc
= SETUP_CreateSerialDeviceList(list
, machine
, (LPGUID
)class, enumstr
);
1839 ERR("Wine can only enumerate serial devices at the moment!\n");
1840 rc
= ERROR_INVALID_PARAMETER
;
1842 #else /* __REACTOS__ */
1843 rc
= SETUP_CreateInterfaceList(list
, machine
, (LPGUID
)class, enumstr
);
1844 #endif /* __REACTOS__ */
1845 if (rc
!= ERROR_SUCCESS
)
1849 SetupDiDestroyDeviceInfoList(hDeviceInfo
);
1850 return INVALID_HANDLE_VALUE
;
1856 rc
= SETUP_CreateDevList(list
, machine
, (LPGUID
)class, enumstr
);
1857 if (rc
!= ERROR_SUCCESS
)
1861 SetupDiDestroyDeviceInfoList(hDeviceInfo
);
1862 return INVALID_HANDLE_VALUE
;
1868 /***********************************************************************
1869 * SetupDiEnumDeviceInterfaces (SETUPAPI.@)
1871 BOOL WINAPI
SetupDiEnumDeviceInterfaces(
1872 HDEVINFO DeviceInfoSet
,
1873 PSP_DEVINFO_DATA DeviceInfoData
,
1874 CONST GUID
* InterfaceClassGuid
,
1876 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
1880 TRACE("%p, %p, %s, %ld, %p\n", DeviceInfoSet
, DeviceInfoData
,
1881 debugstr_guid(InterfaceClassGuid
), MemberIndex
, DeviceInterfaceData
);
1883 if (!DeviceInterfaceData
)
1884 SetLastError(ERROR_INVALID_PARAMETER
);
1885 else if (DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
1886 SetLastError(ERROR_INVALID_USER_BUFFER
);
1887 else if (DeviceInfoSet
&& DeviceInfoSet
!= (HDEVINFO
)INVALID_HANDLE_VALUE
)
1889 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)DeviceInfoSet
;
1891 if (list
->magic
== SETUP_DEV_INFO_SET_MAGIC
)
1893 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
1895 while (ItemList
!= &list
->ListHead
&& !Found
)
1897 PLIST_ENTRY InterfaceListEntry
;
1898 struct DeviceInfoElement
*DevInfo
= (struct DeviceInfoElement
*)ItemList
;
1899 if (DeviceInfoData
&& (struct DeviceInfoElement
*)DeviceInfoData
->Reserved
!= DevInfo
)
1901 /* We are not searching for this element */
1902 ItemList
= ItemList
->Flink
;
1905 InterfaceListEntry
= DevInfo
->InterfaceListHead
.Flink
;
1906 while (InterfaceListEntry
!= &DevInfo
->InterfaceListHead
&& !Found
)
1908 struct DeviceInterface
*DevItf
= (struct DeviceInterface
*)InterfaceListEntry
;
1909 if (!IsEqualIID(&DevItf
->InterfaceClassGuid
, InterfaceClassGuid
))
1911 InterfaceListEntry
= InterfaceListEntry
->Flink
;
1914 if (MemberIndex
-- == 0)
1916 /* return this item */
1917 memcpy(&DeviceInterfaceData
->InterfaceClassGuid
,
1918 &DevItf
->InterfaceClassGuid
,
1920 DeviceInterfaceData
->Flags
= 0; /* FIXME */
1921 /* Note: this appears to be dangerous, passing a private
1922 * pointer a heap-allocated datum to the caller. However, the
1923 * expected lifetime of the device data is the same as the
1924 * HDEVINFO; once that is closed, the data are no longer valid.
1926 DeviceInterfaceData
->Reserved
= (ULONG_PTR
)DevItf
;
1929 InterfaceListEntry
= InterfaceListEntry
->Flink
;
1931 ItemList
= ItemList
->Flink
;
1934 SetLastError(ERROR_NO_MORE_ITEMS
);
1939 SetLastError(ERROR_INVALID_HANDLE
);
1942 SetLastError(ERROR_INVALID_HANDLE
);
1946 static VOID
ReferenceInfFile(struct InfFileDetails
* infFile
)
1948 InterlockedIncrement(&infFile
->References
);
1951 static VOID
DereferenceInfFile(struct InfFileDetails
* infFile
)
1953 if (InterlockedDecrement(&infFile
->References
) == 0)
1955 SetupCloseInfFile(infFile
->hInf
);
1956 HeapFree(GetProcessHeap(), 0, infFile
);
1960 static BOOL
DestroyDriverInfoElement(struct DriverInfoElement
* driverInfo
)
1962 DereferenceInfFile(driverInfo
->InfFileDetails
);
1963 HeapFree(GetProcessHeap(), 0, driverInfo
->MatchingId
);
1964 HeapFree(GetProcessHeap(), 0, driverInfo
);
1968 static BOOL
DestroyDeviceInfoElement(struct DeviceInfoElement
* deviceInfo
)
1970 PLIST_ENTRY ListEntry
;
1971 struct DriverInfoElement
*driverInfo
;
1973 while (!IsListEmpty(&deviceInfo
->DriverListHead
))
1975 ListEntry
= RemoveHeadList(&deviceInfo
->DriverListHead
);
1976 driverInfo
= (struct DriverInfoElement
*)ListEntry
;
1977 if (!DestroyDriverInfoElement(driverInfo
))
1980 while (!IsListEmpty(&deviceInfo
->InterfaceListHead
))
1982 ListEntry
= RemoveHeadList(&deviceInfo
->InterfaceListHead
);
1983 HeapFree(GetProcessHeap(), 0, ListEntry
);
1985 HeapFree(GetProcessHeap(), 0, deviceInfo
);
1989 static BOOL
DestroyDeviceInfoSet(struct DeviceInfoSet
* list
)
1991 PLIST_ENTRY ListEntry
;
1992 struct DeviceInfoElement
*deviceInfo
;
1994 while (!IsListEmpty(&list
->ListHead
))
1996 ListEntry
= RemoveHeadList(&list
->ListHead
);
1997 deviceInfo
= (struct DeviceInfoElement
*)ListEntry
;
1998 if (!DestroyDeviceInfoElement(deviceInfo
))
2001 if (list
->HKLM
!= HKEY_LOCAL_MACHINE
)
2002 RegCloseKey(list
->HKLM
);
2003 HeapFree(GetProcessHeap(), 0, list
);
2007 /***********************************************************************
2008 * SetupDiDestroyDeviceInfoList (SETUPAPI.@)
2010 BOOL WINAPI
SetupDiDestroyDeviceInfoList(HDEVINFO devinfo
)
2014 TRACE("%p\n", devinfo
);
2015 if (devinfo
&& devinfo
!= (HDEVINFO
)INVALID_HANDLE_VALUE
)
2017 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)devinfo
;
2019 if (list
->magic
== SETUP_DEV_INFO_SET_MAGIC
)
2020 ret
= DestroyDeviceInfoSet(list
);
2022 SetLastError(ERROR_INVALID_HANDLE
);
2025 SetLastError(ERROR_INVALID_HANDLE
);
2027 TRACE("Returning %d\n", ret
);
2031 /***********************************************************************
2032 * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@)
2034 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailA(
2035 HDEVINFO DeviceInfoSet
,
2036 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2037 PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData
,
2038 DWORD DeviceInterfaceDetailDataSize
,
2039 PDWORD RequiredSize
,
2040 PSP_DEVINFO_DATA DeviceInfoData
)
2042 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailDataW
= NULL
;
2043 DWORD sizeW
= 0, sizeA
;
2046 TRACE("(%p, %p, %p, %ld, %p, %p)\n", DeviceInfoSet
,
2047 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2048 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2050 if (DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
))
2051 SetLastError(ERROR_INVALID_USER_BUFFER
);
2052 else if (DeviceInterfaceDetailData
== NULL
&& DeviceInterfaceDetailDataSize
!= 0)
2053 SetLastError(ERROR_INVALID_PARAMETER
);
2054 else if (DeviceInterfaceDetailData
!= NULL
&& DeviceInterfaceDetailDataSize
< FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + 1)
2055 SetLastError(ERROR_INVALID_PARAMETER
);
2058 if (DeviceInterfaceDetailData
!= NULL
)
2060 sizeW
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)
2061 + (DeviceInterfaceDetailDataSize
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
)) * sizeof(WCHAR
);
2062 DeviceInterfaceDetailDataW
= (PSP_DEVICE_INTERFACE_DETAIL_DATA_W
)HeapAlloc(GetProcessHeap(), 0, sizeW
);
2063 if (!DeviceInterfaceDetailDataW
)
2065 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2068 if (!DeviceInterfaceDetailData
|| (DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataW
))
2070 DeviceInterfaceDetailDataW
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
);
2071 ret
= SetupDiGetDeviceInterfaceDetailW(
2073 DeviceInterfaceData
,
2074 DeviceInterfaceDetailDataW
,
2078 sizeA
= (sizeW
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
)) / sizeof(WCHAR
)
2079 + FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
);
2081 *RequiredSize
= sizeA
;
2082 if (ret
&& DeviceInterfaceDetailData
&& DeviceInterfaceDetailDataSize
<= sizeA
)
2084 if (!WideCharToMultiByte(
2086 DeviceInterfaceDetailDataW
->DevicePath
, -1,
2087 DeviceInterfaceDetailData
->DevicePath
, DeviceInterfaceDetailDataSize
- FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
),
2094 HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailDataW
);
2097 TRACE("Returning %d\n", ret
);
2101 /***********************************************************************
2102 * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@)
2104 BOOL WINAPI
SetupDiGetDeviceInterfaceDetailW(
2105 HDEVINFO DeviceInfoSet
,
2106 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
,
2107 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData
,
2108 DWORD DeviceInterfaceDetailDataSize
,
2109 PDWORD RequiredSize
,
2110 PSP_DEVINFO_DATA DeviceInfoData
)
2114 TRACE("(%p, %p, %p, %ld, %p, %p): stub\n", DeviceInfoSet
,
2115 DeviceInterfaceData
, DeviceInterfaceDetailData
,
2116 DeviceInterfaceDetailDataSize
, RequiredSize
, DeviceInfoData
);
2118 if (!DeviceInfoSet
|| !DeviceInterfaceData
)
2119 SetLastError(ERROR_INVALID_PARAMETER
);
2120 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
2121 SetLastError(ERROR_INVALID_HANDLE
);
2122 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
2123 SetLastError(ERROR_INVALID_HANDLE
);
2124 else if (DeviceInterfaceData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DATA
))
2125 SetLastError(ERROR_INVALID_USER_BUFFER
);
2126 else if (DeviceInterfaceDetailData
->cbSize
!= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
))
2127 SetLastError(ERROR_INVALID_USER_BUFFER
);
2128 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
2129 SetLastError(ERROR_INVALID_USER_BUFFER
);
2130 else if (DeviceInterfaceDetailData
== NULL
&& DeviceInterfaceDetailDataSize
!= 0)
2131 SetLastError(ERROR_INVALID_PARAMETER
);
2132 else if (DeviceInterfaceDetailData
!= NULL
&& DeviceInterfaceDetailDataSize
< FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
))
2133 SetLastError(ERROR_INVALID_PARAMETER
);
2136 struct DeviceInterface
*deviceInterface
= (struct DeviceInterface
*)DeviceInterfaceData
->Reserved
;
2137 LPCWSTR devName
= deviceInterface
->SymbolicLink
;
2138 DWORD sizeRequired
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
) +
2139 (lstrlenW(devName
) + 1) * sizeof(WCHAR
);
2141 if (sizeRequired
> DeviceInterfaceDetailDataSize
)
2143 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2145 *RequiredSize
= sizeRequired
;
2149 wcscpy(DeviceInterfaceDetailData
->DevicePath
, devName
);
2150 TRACE("DevicePath is %s\n", debugstr_w(DeviceInterfaceDetailData
->DevicePath
));
2153 memcpy(&DeviceInfoData
->ClassGuid
,
2154 &deviceInterface
->DeviceInfo
->ClassGuid
,
2156 DeviceInfoData
->DevInst
= 0; /* FIXME */
2157 /* Note: this appears to be dangerous, passing a private
2158 * pointer a heap-allocated datum to the caller. However, the
2159 * expected lifetime of the device data is the same as the
2160 * HDEVINFO; once that is closed, the data are no longer valid.
2162 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInterface
->DeviceInfo
;
2168 TRACE("Returning %d\n", ret
);
2172 /***********************************************************************
2173 * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@)
2175 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyA(
2177 PSP_DEVINFO_DATA DeviceInfoData
,
2179 PDWORD PropertyRegDataType
,
2180 PBYTE PropertyBuffer
,
2181 DWORD PropertyBufferSize
,
2182 PDWORD RequiredSize
)
2185 BOOL bIsStringProperty
;
2187 DWORD RequiredSizeA
, RequiredSizeW
;
2188 DWORD PropertyBufferSizeW
;
2189 PBYTE PropertyBufferW
;
2191 TRACE("%p %p %ld %p %p %ld %p\n", devinfo
, DeviceInfoData
,
2192 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
2195 PropertyBufferSizeW
= PropertyBufferSize
* 2;
2196 PropertyBufferW
= HeapAlloc(GetProcessHeap(), 0, PropertyBufferSizeW
);
2198 bResult
= SetupDiGetDeviceRegistryPropertyW(
2204 PropertyBufferSizeW
,
2207 if (bResult
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
2209 bIsStringProperty
= (RegType
== REG_SZ
|| RegType
== REG_MULTI_SZ
|| RegType
== REG_EXPAND_SZ
);
2211 if (bIsStringProperty
)
2212 RequiredSizeA
= RequiredSizeW
/ sizeof(WCHAR
);
2214 RequiredSizeA
= RequiredSizeW
;
2216 *RequiredSize
= RequiredSizeA
;
2217 if (PropertyRegDataType
)
2218 *PropertyRegDataType
= RegType
;
2223 HeapFree(GetProcessHeap(), 0, PropertyBufferW
);
2227 if (RequiredSizeA
<= PropertyBufferSize
)
2229 if (bIsStringProperty
&& PropertyBufferSize
> 0)
2231 if (WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)PropertyBufferW
, RequiredSizeW
/ sizeof(WCHAR
), (LPSTR
)PropertyBuffer
, PropertyBufferSize
, NULL
, NULL
) == 0)
2233 /* Last error is already set by WideCharToMultiByte */
2238 memcpy(PropertyBuffer
, PropertyBufferW
, RequiredSizeA
);
2242 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2246 HeapFree(GetProcessHeap(), 0, PropertyBufferW
);
2250 /***********************************************************************
2251 * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@)
2253 BOOL WINAPI
SetupDiGetDeviceRegistryPropertyW(
2254 HDEVINFO DeviceInfoSet
,
2255 PSP_DEVINFO_DATA DeviceInfoData
,
2257 PDWORD PropertyRegDataType
,
2258 PBYTE PropertyBuffer
,
2259 DWORD PropertyBufferSize
,
2260 PDWORD RequiredSize
)
2262 HKEY hEnumKey
, hKey
;
2266 TRACE("%p %p %ld %p %p %ld %p\n", DeviceInfoSet
, DeviceInfoData
,
2267 Property
, PropertyRegDataType
, PropertyBuffer
, PropertyBufferSize
,
2270 if (!DeviceInfoSet
|| DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
2271 SetLastError(ERROR_INVALID_HANDLE
);
2272 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
2273 SetLastError(ERROR_INVALID_HANDLE
);
2274 else if (!DeviceInfoData
)
2275 SetLastError(ERROR_INVALID_PARAMETER
);
2276 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
2277 SetLastError(ERROR_INVALID_USER_BUFFER
);
2278 else if (Property
>= SPDRP_MAXIMUM_PROPERTY
)
2279 SetLastError(ERROR_INVALID_PARAMETER
);
2282 struct DeviceInfoSet
*list
= (struct DeviceInfoSet
*)DeviceInfoSet
;
2283 struct DeviceInfoElement
*DevInfo
= (struct DeviceInfoElement
*)DeviceInfoData
->Reserved
;
2287 case SPDRP_CAPABILITIES
:
2289 case SPDRP_CLASSGUID
:
2290 case SPDRP_COMPATIBLEIDS
:
2291 case SPDRP_CONFIGFLAGS
:
2292 case SPDRP_DEVICEDESC
:
2294 case SPDRP_FRIENDLYNAME
:
2295 case SPDRP_HARDWAREID
:
2296 case SPDRP_LOCATION_INFORMATION
:
2297 case SPDRP_LOWERFILTERS
:
2299 case SPDRP_SECURITY
:
2301 case SPDRP_UI_NUMBER
:
2302 case SPDRP_UI_NUMBER_DESC_FORMAT
:
2303 case SPDRP_UPPERFILTERS
:
2305 LPCWSTR RegistryPropertyName
;
2310 case SPDRP_CAPABILITIES
:
2311 RegistryPropertyName
= L
"Capabilities"; break;
2313 RegistryPropertyName
= L
"Class"; break;
2314 case SPDRP_CLASSGUID
:
2315 RegistryPropertyName
= L
"ClassGUID"; break;
2316 case SPDRP_COMPATIBLEIDS
:
2317 RegistryPropertyName
= L
"CompatibleIDs"; break;
2318 case SPDRP_CONFIGFLAGS
:
2319 RegistryPropertyName
= L
"ConfigFlags"; break;
2320 case SPDRP_DEVICEDESC
:
2321 RegistryPropertyName
= L
"DeviceDesc"; break;
2323 RegistryPropertyName
= L
"Driver"; break;
2324 case SPDRP_FRIENDLYNAME
:
2325 RegistryPropertyName
= L
"FriendlyName"; break;
2326 case SPDRP_HARDWAREID
:
2327 RegistryPropertyName
= L
"HardwareID"; break;
2328 case SPDRP_LOCATION_INFORMATION
:
2329 RegistryPropertyName
= L
"LocationInformation"; break;
2330 case SPDRP_LOWERFILTERS
:
2331 RegistryPropertyName
= L
"LowerFilters"; break;
2333 RegistryPropertyName
= L
"Mfg"; break;
2334 case SPDRP_SECURITY
:
2335 RegistryPropertyName
= L
"Security"; break;
2337 RegistryPropertyName
= L
"Service"; break;
2338 case SPDRP_UI_NUMBER
:
2339 RegistryPropertyName
= L
"UINumber"; break;
2340 case SPDRP_UI_NUMBER_DESC_FORMAT
:
2341 RegistryPropertyName
= L
"UINumberDescFormat"; break;
2342 case SPDRP_UPPERFILTERS
:
2343 RegistryPropertyName
= L
"UpperFilters"; break;
2345 /* Should not happen */
2346 RegistryPropertyName
= NULL
; break;
2349 /* Open registry key name */
2354 KEY_ENUMERATE_SUB_KEYS
,
2356 if (rc
!= ERROR_SUCCESS
)
2367 RegCloseKey(hEnumKey
);
2368 if (rc
!= ERROR_SUCCESS
)
2373 /* Read registry entry */
2374 BufferSize
= PropertyBufferSize
;
2375 rc
= RegQueryValueExW(
2377 RegistryPropertyName
,
2378 NULL
, /* Reserved */
2379 PropertyRegDataType
,
2383 *RequiredSize
= BufferSize
;
2386 if (PropertyBuffer
!= NULL
|| BufferSize
== 0)
2389 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2391 case ERROR_MORE_DATA
:
2392 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2401 case SPDRP_PHYSICAL_DEVICE_OBJECT_NAME
:
2403 DWORD required
= (wcslen(DevInfo
->Data
) + 1) * sizeof(WCHAR
);
2405 if (PropertyRegDataType
)
2406 *PropertyRegDataType
= REG_SZ
;
2408 *RequiredSize
= required
;
2409 if (PropertyBufferSize
>= required
)
2411 wcscpy((LPWSTR
)PropertyBuffer
, DevInfo
->Data
);
2415 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2419 /*case SPDRP_BUSTYPEGUID:
2420 case SPDRP_LEGACYBUSTYPE:
2421 case SPDRP_BUSNUMBER:
2422 case SPDRP_ENUMERATOR_NAME:
2423 case SPDRP_SECURITY_SDS:
2425 case SPDRP_EXCLUSIVE:
2426 case SPDRP_CHARACTERISTICS:
2428 case SPDRP_DEVICE_POWER_DATA:*/
2429 #if (WINVER >= 0x501)
2430 /*case SPDRP_REMOVAL_POLICY:
2431 case SPDRP_REMOVAL_POLICY_HW_DEFAULT:
2432 case SPDRP_REMOVAL_POLICY_OVERRIDE:
2433 case SPDRP_INSTALL_STATE:*/
2438 FIXME("Property 0x%lx not implemented\n", Property
);
2439 SetLastError(ERROR_NOT_SUPPORTED
);
2444 TRACE("Returning %d\n", ret
);
2448 /***********************************************************************
2449 * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@)
2451 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyA(
2452 IN HDEVINFO DeviceInfoSet
,
2453 IN OUT PSP_DEVINFO_DATA DeviceInfoData
,
2455 IN CONST BYTE
*PropertyBuffer
,
2456 IN DWORD PropertyBufferSize
)
2458 FIXME("%p %p 0x%lx %p 0x%lx\n", DeviceInfoSet
, DeviceInfoData
,
2459 Property
, PropertyBuffer
, PropertyBufferSize
);
2460 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2464 /***********************************************************************
2465 * SetupDiSetDeviceRegistryPropertyW (SETUPAPI.@)
2467 BOOL WINAPI
SetupDiSetDeviceRegistryPropertyW(
2468 IN HDEVINFO DeviceInfoSet
,
2469 IN OUT PSP_DEVINFO_DATA DeviceInfoData
,
2471 IN
const BYTE
*PropertyBuffer
,
2472 IN DWORD PropertyBufferSize
)
2474 struct DeviceInfoSet
*list
;
2477 TRACE("%p %p 0x%lx %p 0x%lx\n", DeviceInfoSet
, DeviceInfoData
,
2478 Property
, PropertyBuffer
, PropertyBufferSize
);
2481 SetLastError(ERROR_INVALID_HANDLE
);
2482 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
2483 SetLastError(ERROR_INVALID_HANDLE
);
2484 else if (DeviceInfoData
)
2485 SetLastError(ERROR_INVALID_HANDLE
);
2486 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
2487 SetLastError(ERROR_INVALID_USER_BUFFER
);
2492 case SPDRP_COMPATIBLEIDS
:
2493 case SPDRP_CONFIGFLAGS
:
2494 case SPDRP_FRIENDLYNAME
:
2495 case SPDRP_HARDWAREID
:
2496 case SPDRP_LOCATION_INFORMATION
:
2497 case SPDRP_LOWERFILTERS
:
2498 case SPDRP_SECURITY
:
2500 case SPDRP_UI_NUMBER_DESC_FORMAT
:
2501 case SPDRP_UPPERFILTERS
:
2503 LPCWSTR RegistryPropertyName
;
2504 DWORD RegistryDataType
;
2510 case SPDRP_COMPATIBLEIDS
:
2511 RegistryPropertyName
= L
"CompatibleIDs";
2512 RegistryDataType
= REG_MULTI_SZ
;
2514 case SPDRP_CONFIGFLAGS
:
2515 RegistryPropertyName
= L
"ConfigFlags";
2516 RegistryDataType
= REG_DWORD
;
2518 case SPDRP_FRIENDLYNAME
:
2519 RegistryPropertyName
= L
"FriendlyName";
2520 RegistryDataType
= REG_SZ
;
2522 case SPDRP_HARDWAREID
:
2523 RegistryPropertyName
= L
"HardwareID";
2524 RegistryDataType
= REG_MULTI_SZ
;
2526 case SPDRP_LOCATION_INFORMATION
:
2527 RegistryPropertyName
= L
"LocationInformation";
2528 RegistryDataType
= REG_SZ
;
2530 case SPDRP_LOWERFILTERS
:
2531 RegistryPropertyName
= L
"LowerFilters";
2532 RegistryDataType
= REG_MULTI_SZ
;
2534 case SPDRP_SECURITY
:
2535 RegistryPropertyName
= L
"Security";
2536 RegistryDataType
= REG_BINARY
;
2539 RegistryPropertyName
= L
"Service";
2540 RegistryDataType
= REG_SZ
;
2542 case SPDRP_UI_NUMBER_DESC_FORMAT
:
2543 RegistryPropertyName
= L
"UINumberDescFormat";
2544 RegistryDataType
= REG_SZ
;
2546 case SPDRP_UPPERFILTERS
:
2547 RegistryPropertyName
= L
"UpperFilters";
2548 RegistryDataType
= REG_MULTI_SZ
;
2551 /* Should not happen */
2552 RegistryPropertyName
= NULL
;
2553 RegistryDataType
= REG_BINARY
;
2556 /* Open device registry key */
2557 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_SET_VALUE
);
2558 if (hKey
!= INVALID_HANDLE_VALUE
)
2560 /* Write new data */
2561 rc
= RegSetValueExW(
2563 RegistryPropertyName
,
2567 PropertyBufferSize
);
2568 if (rc
== ERROR_SUCCESS
)
2577 /*case SPDRP_CHARACTERISTICS:
2579 case SPDRP_EXCLUSIVE:*/
2580 #if (WINVER >= 0x501)
2581 //case SPDRP_REMOVAL_POLICY_OVERRIDE:
2583 //case SPDRP_SECURITY_SDS:
2587 FIXME("Property 0x%lx not implemented\n", Property
);
2588 SetLastError(ERROR_NOT_SUPPORTED
);
2593 TRACE("Returning %d\n", ret
);
2597 /***********************************************************************
2598 * SetupDiInstallClassA (SETUPAPI.@)
2600 BOOL WINAPI
SetupDiInstallClassA(
2606 UNICODE_STRING FileNameW
;
2609 if (!RtlCreateUnicodeStringFromAsciiz(&FileNameW
, InfFileName
))
2611 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2615 Result
= SetupDiInstallClassW(hwndParent
, FileNameW
.Buffer
, Flags
, FileQueue
);
2617 RtlFreeUnicodeString(&FileNameW
);
2622 static HKEY
CreateClassKey(HINF hInf
)
2624 WCHAR FullBuffer
[MAX_PATH
];
2625 WCHAR Buffer
[MAX_PATH
];
2630 if (!SetupGetLineTextW(NULL
,
2638 return INVALID_HANDLE_VALUE
;
2641 lstrcpyW(FullBuffer
, ControlClass
);
2642 lstrcatW(FullBuffer
, Buffer
);
2645 if (!SetupGetLineTextW(NULL
,
2653 RegDeleteKeyW(HKEY_LOCAL_MACHINE
, FullBuffer
);
2654 return INVALID_HANDLE_VALUE
;
2657 if (ERROR_SUCCESS
!= RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
2661 REG_OPTION_NON_VOLATILE
,
2667 RegDeleteKeyW(HKEY_LOCAL_MACHINE
, FullBuffer
);
2668 return INVALID_HANDLE_VALUE
;
2671 if (ERROR_SUCCESS
!= RegSetValueExW(hClassKey
,
2676 RequiredSize
* sizeof(WCHAR
)))
2678 RegCloseKey(hClassKey
);
2679 RegDeleteKeyW(HKEY_LOCAL_MACHINE
, FullBuffer
);
2680 return INVALID_HANDLE_VALUE
;
2686 /***********************************************************************
2687 * SetupDiInstallClassW (SETUPAPI.@)
2689 BOOL WINAPI
SetupDiInstallClassW(
2695 WCHAR SectionName
[MAX_PATH
];
2696 DWORD SectionNameLength
= 0;
2698 BOOL bFileQueueCreated
= FALSE
;
2701 FIXME("not fully implemented\n");
2703 if ((Flags
& DI_NOVCP
) && (FileQueue
== NULL
|| FileQueue
== INVALID_HANDLE_VALUE
))
2705 SetLastError(ERROR_INVALID_PARAMETER
);
2709 /* Open the .inf file */
2710 hInf
= SetupOpenInfFileW(InfFileName
,
2714 if (hInf
== INVALID_HANDLE_VALUE
)
2720 /* Create or open the class registry key 'HKLM\\CurrentControlSet\\Class\\{GUID}' */
2721 hClassKey
= CreateClassKey(hInf
);
2722 if (hClassKey
== INVALID_HANDLE_VALUE
)
2724 SetupCloseInfFile(hInf
);
2730 /* Try to append a layout file */
2732 SetupOpenAppendInfFileW(NULL
, hInf
, NULL
);
2735 /* Retrieve the actual section name */
2736 SetupDiGetActualSectionToInstallW(hInf
,
2744 if (!(Flags
& DI_NOVCP
))
2746 FileQueue
= SetupOpenFileQueue();
2747 if (FileQueue
== INVALID_HANDLE_VALUE
)
2749 SetupCloseInfFile(hInf
);
2750 RegCloseKey(hClassKey
);
2754 bFileQueueCreated
= TRUE
;
2759 SetupInstallFromInfSectionW(NULL
,
2768 INVALID_HANDLE_VALUE
,
2771 /* FIXME: More code! */
2773 if (bFileQueueCreated
)
2774 SetupCloseFileQueue(FileQueue
);
2776 SetupCloseInfFile(hInf
);
2778 RegCloseKey(hClassKey
);
2783 /***********************************************************************
2784 * SetupDiOpenClassRegKey (SETUPAPI.@)
2786 HKEY WINAPI
SetupDiOpenClassRegKey(
2787 const GUID
* ClassGuid
,
2790 return SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
2791 DIOCR_INSTALLER
, NULL
, NULL
);
2795 /***********************************************************************
2796 * SetupDiOpenClassRegKeyExA (SETUPAPI.@)
2798 HKEY WINAPI
SetupDiOpenClassRegKeyExA(
2799 const GUID
* ClassGuid
,
2805 PWSTR MachineNameW
= NULL
;
2812 MachineNameW
= MultiByteToUnicode(MachineName
, CP_ACP
);
2813 if (MachineNameW
== NULL
)
2814 return INVALID_HANDLE_VALUE
;
2817 hKey
= SetupDiOpenClassRegKeyExW(ClassGuid
, samDesired
,
2818 Flags
, MachineNameW
, Reserved
);
2821 MyFree(MachineNameW
);
2827 /***********************************************************************
2828 * SetupDiOpenClassRegKeyExW (SETUPAPI.@)
2830 HKEY WINAPI
SetupDiOpenClassRegKeyExW(
2831 const GUID
* ClassGuid
,
2837 LPWSTR lpGuidString
;
2838 LPWSTR lpFullGuidString
;
2846 if (Flags
== DIOCR_INSTALLER
)
2848 lpKeyName
= ControlClass
;
2850 else if (Flags
== DIOCR_INTERFACE
)
2852 lpKeyName
= DeviceClasses
;
2856 ERR("Invalid Flags parameter!\n");
2857 SetLastError(ERROR_INVALID_PARAMETER
);
2858 return INVALID_HANDLE_VALUE
;
2861 if (MachineName
!= NULL
)
2863 rc
= RegConnectRegistryW(MachineName
, HKEY_LOCAL_MACHINE
, &HKLM
);
2864 if (rc
!= ERROR_SUCCESS
)
2867 return INVALID_HANDLE_VALUE
;
2871 HKLM
= HKEY_LOCAL_MACHINE
;
2873 rc
= RegOpenKeyExW(HKLM
,
2878 if (MachineName
!= NULL
) RegCloseKey(HKLM
);
2879 if (rc
!= ERROR_SUCCESS
)
2882 return INVALID_HANDLE_VALUE
;
2885 if (ClassGuid
== NULL
)
2888 if (UuidToStringW((UUID
*)ClassGuid
, &lpGuidString
) != RPC_S_OK
)
2890 SetLastError(ERROR_GEN_FAILURE
);
2891 RegCloseKey(hClassesKey
);
2892 return INVALID_HANDLE_VALUE
;
2895 dwLength
= lstrlenW(lpGuidString
);
2896 lpFullGuidString
= HeapAlloc(GetProcessHeap(), 0, (dwLength
+ 3) * sizeof(WCHAR
));
2897 if (!lpFullGuidString
)
2899 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2900 RpcStringFreeW(&lpGuidString
);
2901 return INVALID_HANDLE_VALUE
;
2903 lpFullGuidString
[0] = '{';
2904 memcpy(&lpFullGuidString
[1], lpGuidString
, dwLength
* sizeof(WCHAR
));
2905 lpFullGuidString
[dwLength
+ 1] = '}';
2906 lpFullGuidString
[dwLength
+ 2] = '\0';
2907 RpcStringFreeW(&lpGuidString
);
2909 rc
= RegOpenKeyExW(hClassesKey
,
2914 if (rc
!= ERROR_SUCCESS
)
2917 HeapFree(GetProcessHeap(), 0, lpFullGuidString
);
2918 RegCloseKey(hClassesKey
);
2919 return INVALID_HANDLE_VALUE
;
2922 HeapFree(GetProcessHeap(), 0, lpFullGuidString
);
2923 RegCloseKey(hClassesKey
);
2928 /***********************************************************************
2929 * SetupDiOpenDeviceInterfaceW (SETUPAPI.@)
2931 BOOL WINAPI
SetupDiOpenDeviceInterfaceW(
2932 HDEVINFO DeviceInfoSet
,
2935 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2937 FIXME("%p %s %08lx %p\n",
2938 DeviceInfoSet
, debugstr_w(DevicePath
), OpenFlags
, DeviceInterfaceData
);
2942 /***********************************************************************
2943 * SetupDiOpenDeviceInterfaceA (SETUPAPI.@)
2945 BOOL WINAPI
SetupDiOpenDeviceInterfaceA(
2946 HDEVINFO DeviceInfoSet
,
2949 PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
)
2951 LPWSTR DevicePathW
= NULL
;
2954 TRACE("%p %s %08lx %p\n", DeviceInfoSet
, debugstr_a(DevicePath
), OpenFlags
, DeviceInterfaceData
);
2956 DevicePathW
= MultiByteToUnicode(DevicePath
, CP_ACP
);
2957 if (DevicePathW
== NULL
)
2960 bResult
= SetupDiOpenDeviceInterfaceW(DeviceInfoSet
,
2961 DevicePathW
, OpenFlags
, DeviceInterfaceData
);
2963 MyFree(DevicePathW
);
2968 /***********************************************************************
2969 * SetupDiSetClassInstallParamsA (SETUPAPI.@)
2971 BOOL WINAPI
SetupDiSetClassInstallParamsA(
2972 HDEVINFO DeviceInfoSet
,
2973 PSP_DEVINFO_DATA DeviceInfoData
,
2974 PSP_CLASSINSTALL_HEADER ClassInstallParams
,
2975 DWORD ClassInstallParamsSize
)
2977 FIXME("%p %p %x %lu\n",DeviceInfoSet
, DeviceInfoData
,
2978 ClassInstallParams
->InstallFunction
, ClassInstallParamsSize
);
2984 IN PWSTR InstallerName
,
2985 OUT HMODULE
* ModulePointer
,
2986 OUT PVOID
* FunctionPointer
)
2988 HMODULE hModule
= NULL
;
2989 LPSTR FunctionNameA
= NULL
;
2993 *ModulePointer
= NULL
;
2994 *FunctionPointer
= NULL
;
2996 Comma
= strchrW(InstallerName
, ',');
2999 rc
= ERROR_INVALID_PARAMETER
;
3005 hModule
= LoadLibraryW(InstallerName
);
3009 rc
= GetLastError();
3013 /* Skip comma spaces */
3014 while (*Comma
== ',' || isspaceW(*Comma
))
3017 /* W->A conversion for function name */
3018 FunctionNameA
= UnicodeToMultiByte(Comma
, CP_ACP
);
3021 rc
= GetLastError();
3025 /* Search function */
3026 *FunctionPointer
= GetProcAddress(hModule
, FunctionNameA
);
3027 if (!*FunctionPointer
)
3029 rc
= GetLastError();
3033 *ModulePointer
= hModule
;
3037 if (rc
!= ERROR_SUCCESS
&& hModule
)
3038 FreeLibrary(hModule
);
3039 MyFree(FunctionNameA
);
3044 FreeFunctionPointer(
3045 IN HMODULE ModulePointer
,
3046 IN PVOID FunctionPointer
)
3048 if (ModulePointer
== NULL
)
3049 return ERROR_SUCCESS
;
3050 if (FreeLibrary(ModulePointer
))
3051 return ERROR_SUCCESS
;
3053 return GetLastError();
3056 /***********************************************************************
3057 * SetupDiCallClassInstaller (SETUPAPI.@)
3059 BOOL WINAPI
SetupDiCallClassInstaller(
3060 IN DI_FUNCTION InstallFunction
,
3061 IN HDEVINFO DeviceInfoSet
,
3062 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
3066 TRACE("%ld %p %p\n", InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3069 SetLastError(ERROR_INVALID_PARAMETER
);
3070 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
3071 SetLastError(ERROR_INVALID_HANDLE
);
3072 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
3073 SetLastError(ERROR_INVALID_HANDLE
);
3074 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->HKLM
!= HKEY_LOCAL_MACHINE
)
3075 SetLastError(ERROR_INVALID_HANDLE
);
3076 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
3077 SetLastError(ERROR_INVALID_USER_BUFFER
);
3080 SP_DEVINSTALL_PARAMS_W InstallParams
;
3081 #define CLASS_COINSTALLER 0x1
3082 #define DEVICE_COINSTALLER 0x2
3083 #define CLASS_INSTALLER 0x4
3084 UCHAR CanHandle
= 0;
3085 DEFAULT_CLASS_INSTALL_PROC DefaultHandler
= NULL
;
3087 switch (InstallFunction
)
3089 case DIF_ALLOW_INSTALL
:
3090 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3092 case DIF_DESTROYPRIVATEDATA
:
3093 CanHandle
= CLASS_INSTALLER
;
3095 case DIF_INSTALLDEVICE
:
3096 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3097 DefaultHandler
= SetupDiInstallDevice
;
3099 case DIF_INSTALLDEVICEFILES
:
3100 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3101 DefaultHandler
= SetupDiInstallDriverFiles
;
3103 case DIF_INSTALLINTERFACES
:
3104 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3105 DefaultHandler
= SetupDiInstallDeviceInterfaces
;
3107 case DIF_NEWDEVICEWIZARD_FINISHINSTALL
:
3108 CanHandle
= CLASS_COINSTALLER
| DEVICE_COINSTALLER
| CLASS_INSTALLER
;
3110 case DIF_NEWDEVICEWIZARD_POSTANALYZE
:
3111 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3113 case DIF_NEWDEVICEWIZARD_PREANALYZE
:
3114 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3116 case DIF_REGISTER_COINSTALLERS
:
3117 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3118 DefaultHandler
= SetupDiRegisterCoDeviceInstallers
;
3120 case DIF_SELECTBESTCOMPATDRV
:
3121 CanHandle
= CLASS_COINSTALLER
| CLASS_INSTALLER
;
3122 DefaultHandler
= SetupDiSelectBestCompatDrv
;
3125 FIXME("Install function %ld not implemented\n", InstallFunction
);
3126 SetLastError(ERROR_INVALID_PARAMETER
);
3129 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
3130 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
))
3131 /* Don't process this call, as a parameter is invalid */
3136 LIST_ENTRY ClassCoInstallersListHead
;
3137 LIST_ENTRY DeviceCoInstallersListHead
;
3138 HMODULE ClassInstallerLibrary
= NULL
;
3139 CLASS_INSTALL_PROC ClassInstaller
= NULL
;
3140 COINSTALLER_CONTEXT_DATA Context
;
3141 PLIST_ENTRY ListEntry
;
3143 DWORD dwRegType
, dwLength
;
3144 DWORD rc
= NO_ERROR
;
3146 InitializeListHead(&ClassCoInstallersListHead
);
3147 InitializeListHead(&DeviceCoInstallersListHead
);
3149 if (CanHandle
& DEVICE_COINSTALLER
)
3151 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_QUERY_VALUE
);
3152 if (hKey
!= INVALID_HANDLE_VALUE
)
3154 rc
= RegQueryValueExW(hKey
, L
"CoInstallers32", NULL
, &dwRegType
, NULL
, &dwLength
);
3155 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_MULTI_SZ
)
3157 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
3158 if (KeyBuffer
!= NULL
)
3160 rc
= RegQueryValueExW(hKey
, L
"CoInstallers32", NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
3161 if (rc
== ERROR_SUCCESS
)
3164 for (ptr
= KeyBuffer
; *ptr
; ptr
+= strlenW(ptr
) + 1)
3166 /* Add coinstaller to DeviceCoInstallersListHead list */
3167 struct CoInstallerElement
*coinstaller
;
3168 TRACE("Got device coinstaller '%s'\n", debugstr_w(ptr
));
3169 coinstaller
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CoInstallerElement
));
3172 memset(coinstaller
, 0, sizeof(struct CoInstallerElement
));
3173 if (GetFunctionPointer(ptr
, &coinstaller
->Module
, (PVOID
*)&coinstaller
->Function
) == ERROR_SUCCESS
)
3174 InsertTailList(&DeviceCoInstallersListHead
, &coinstaller
->ListEntry
);
3176 HeapFree(GetProcessHeap(), 0, coinstaller
);
3179 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
3185 if (CanHandle
& CLASS_COINSTALLER
)
3189 L
"SYSTEM\\CurrentControlSet\\Control\\CoDeviceInstallers",
3193 if (rc
== ERROR_SUCCESS
)
3195 LPWSTR lpGuidString
;
3196 if (UuidToStringW((UUID
*)&DeviceInfoData
->ClassGuid
, &lpGuidString
) == RPC_S_OK
)
3198 rc
= RegQueryValueExW(hKey
, lpGuidString
, NULL
, &dwRegType
, NULL
, &dwLength
);
3199 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_MULTI_SZ
)
3201 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
3202 if (KeyBuffer
!= NULL
)
3204 rc
= RegQueryValueExW(hKey
, lpGuidString
, NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
3205 if (rc
== ERROR_SUCCESS
)
3208 for (ptr
= KeyBuffer
; *ptr
; ptr
+= strlenW(ptr
) + 1)
3210 /* Add coinstaller to ClassCoInstallersListHead list */
3211 struct CoInstallerElement
*coinstaller
;
3212 TRACE("Got class coinstaller '%s'\n", debugstr_w(ptr
));
3213 coinstaller
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CoInstallerElement
));
3216 memset(coinstaller
, 0, sizeof(struct CoInstallerElement
));
3217 if (GetFunctionPointer(ptr
, &coinstaller
->Module
, (PVOID
*)&coinstaller
->Function
) == ERROR_SUCCESS
)
3218 InsertTailList(&ClassCoInstallersListHead
, &coinstaller
->ListEntry
);
3220 HeapFree(GetProcessHeap(), 0, coinstaller
);
3223 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
3226 RpcStringFreeW(&lpGuidString
);
3231 if ((CanHandle
& CLASS_INSTALLER
) && !(InstallParams
.FlagsEx
& DI_FLAGSEX_CI_FAILED
))
3233 hKey
= SetupDiOpenClassRegKey(&DeviceInfoData
->ClassGuid
, KEY_QUERY_VALUE
);
3234 if (hKey
!= INVALID_HANDLE_VALUE
)
3236 rc
= RegQueryValueExW(hKey
, L
"Installer32", NULL
, &dwRegType
, NULL
, &dwLength
);
3237 if (rc
== ERROR_SUCCESS
&& dwRegType
== REG_SZ
)
3239 LPWSTR KeyBuffer
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
3240 if (KeyBuffer
!= NULL
)
3242 rc
= RegQueryValueExW(hKey
, L
"Installer32", NULL
, NULL
, (LPBYTE
)KeyBuffer
, &dwLength
);
3243 if (rc
== ERROR_SUCCESS
)
3245 /* Get ClassInstaller function pointer */
3246 TRACE("Got class installer '%s'\n", debugstr_w(KeyBuffer
));
3247 if (GetFunctionPointer(KeyBuffer
, &ClassInstallerLibrary
, (PVOID
*)&ClassInstaller
) != ERROR_SUCCESS
)
3249 InstallParams
.FlagsEx
|= DI_FLAGSEX_CI_FAILED
;
3250 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
3253 HeapFree(GetProcessHeap(), 0, KeyBuffer
);
3260 /* Call Class co-installers */
3261 Context
.PostProcessing
= FALSE
;
3263 ListEntry
= ClassCoInstallersListHead
.Flink
;
3264 while (rc
== NO_ERROR
&& ListEntry
!= &ClassCoInstallersListHead
)
3266 struct CoInstallerElement
*coinstaller
= (struct CoInstallerElement
*)ListEntry
;
3267 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
3268 coinstaller
->PrivateData
= Context
.PrivateData
;
3269 if (rc
== ERROR_DI_POSTPROCESSING_REQUIRED
)
3271 coinstaller
->DoPostProcessing
= TRUE
;
3274 ListEntry
= ListEntry
->Flink
;
3277 /* Call Device co-installers */
3278 ListEntry
= DeviceCoInstallersListHead
.Flink
;
3279 while (rc
== NO_ERROR
&& ListEntry
!= &DeviceCoInstallersListHead
)
3281 struct CoInstallerElement
*coinstaller
= (struct CoInstallerElement
*)ListEntry
;
3282 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
3283 coinstaller
->PrivateData
= Context
.PrivateData
;
3284 if (rc
== ERROR_DI_POSTPROCESSING_REQUIRED
)
3286 coinstaller
->DoPostProcessing
= TRUE
;
3289 ListEntry
= ListEntry
->Flink
;
3292 /* Call Class installer */
3295 rc
= (*ClassInstaller
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
3296 FreeFunctionPointer(ClassInstallerLibrary
, ClassInstaller
);
3299 rc
= ERROR_DI_DO_DEFAULT
;
3301 /* Call default handler */
3302 if (rc
== ERROR_DI_DO_DEFAULT
)
3304 if (DefaultHandler
&& !(InstallParams
.Flags
& DI_NODI_DEFAULTACTION
))
3306 if ((*DefaultHandler
)(DeviceInfoSet
, DeviceInfoData
))
3309 rc
= GetLastError();
3315 /* Call Class co-installers that required postprocessing */
3316 Context
.PostProcessing
= TRUE
;
3317 ListEntry
= ClassCoInstallersListHead
.Flink
;
3318 while (ListEntry
!= &ClassCoInstallersListHead
)
3320 struct CoInstallerElement
*coinstaller
= (struct CoInstallerElement
*)ListEntry
;
3321 if (coinstaller
->DoPostProcessing
)
3323 Context
.InstallResult
= rc
;
3324 Context
.PrivateData
= coinstaller
->PrivateData
;
3325 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
3327 FreeFunctionPointer(coinstaller
->Module
, coinstaller
->Function
);
3328 ListEntry
= ListEntry
->Flink
;
3331 /* Call Device co-installers that required postprocessing */
3332 ListEntry
= DeviceCoInstallersListHead
.Flink
;
3333 while (ListEntry
!= &DeviceCoInstallersListHead
)
3335 struct CoInstallerElement
*coinstaller
= (struct CoInstallerElement
*)ListEntry
;
3336 if (coinstaller
->DoPostProcessing
)
3338 Context
.InstallResult
= rc
;
3339 Context
.PrivateData
= coinstaller
->PrivateData
;
3340 rc
= (*coinstaller
->Function
)(InstallFunction
, DeviceInfoSet
, DeviceInfoData
, &Context
);
3342 FreeFunctionPointer(coinstaller
->Module
, coinstaller
->Function
);
3343 ListEntry
= ListEntry
->Flink
;
3346 /* Free allocated memory */
3347 while (!IsListEmpty(&ClassCoInstallersListHead
))
3349 ListEntry
= RemoveHeadList(&ClassCoInstallersListHead
);
3350 HeapFree(GetProcessHeap(), 0, ListEntry
);
3352 while (!IsListEmpty(&DeviceCoInstallersListHead
))
3354 ListEntry
= RemoveHeadList(&DeviceCoInstallersListHead
);
3355 HeapFree(GetProcessHeap(), 0, ListEntry
);
3358 ret
= (rc
== NO_ERROR
);
3362 TRACE("Returning %d\n", ret
);
3366 /***********************************************************************
3367 * SetupDiGetDeviceInstallParamsA (SETUPAPI.@)
3369 BOOL WINAPI
SetupDiGetDeviceInstallParamsA(
3370 IN HDEVINFO DeviceInfoSet
,
3371 IN PSP_DEVINFO_DATA DeviceInfoData
,
3372 OUT PSP_DEVINSTALL_PARAMS_A DeviceInstallParams
)
3374 SP_DEVINSTALL_PARAMS_W deviceInstallParamsW
;
3377 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3379 if (DeviceInstallParams
== NULL
)
3380 SetLastError(ERROR_INVALID_PARAMETER
);
3381 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_A
))
3382 SetLastError(ERROR_INVALID_USER_BUFFER
);
3385 deviceInstallParamsW
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
3386 ret
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &deviceInstallParamsW
);
3390 /* Do W->A conversion */
3392 DeviceInstallParams
,
3393 &deviceInstallParamsW
,
3394 FIELD_OFFSET(SP_DEVINSTALL_PARAMS_W
, DriverPath
));
3395 if (WideCharToMultiByte(CP_ACP
, 0, deviceInstallParamsW
.DriverPath
, -1,
3396 DeviceInstallParams
->DriverPath
, MAX_PATH
, NULL
, NULL
) == 0)
3398 DeviceInstallParams
->DriverPath
[0] = '\0';
3404 TRACE("Returning %d\n", ret
);
3408 /***********************************************************************
3409 * SetupDiGetDeviceInstallParamsW (SETUPAPI.@)
3411 BOOL WINAPI
SetupDiGetDeviceInstallParamsW(
3412 IN HDEVINFO DeviceInfoSet
,
3413 IN PSP_DEVINFO_DATA DeviceInfoData
,
3414 OUT PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
3416 struct DeviceInfoSet
*list
;
3419 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3422 SetLastError(ERROR_INVALID_HANDLE
);
3423 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
3424 SetLastError(ERROR_INVALID_HANDLE
);
3425 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
3426 SetLastError(ERROR_INVALID_USER_BUFFER
);
3427 else if (!DeviceInstallParams
)
3428 SetLastError(ERROR_INVALID_PARAMETER
);
3429 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_W
))
3430 SetLastError(ERROR_INVALID_USER_BUFFER
);
3433 PSP_DEVINSTALL_PARAMS_W Source
;
3436 Source
= &((struct DeviceInfoElement
*)DeviceInfoData
->Reserved
)->InstallParams
;
3438 Source
= &list
->InstallParams
;
3439 memcpy(DeviceInstallParams
, Source
, Source
->cbSize
);
3443 TRACE("Returning %d\n", ret
);
3447 /***********************************************************************
3448 * SetupDiSetDeviceInstallParamsW (SETUPAPI.@)
3450 BOOL WINAPI
SetupDiSetDeviceInstallParamsW(
3451 IN HDEVINFO DeviceInfoSet
,
3452 IN PSP_DEVINFO_DATA DeviceInfoData
,
3453 IN PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
3455 struct DeviceInfoSet
*list
;
3458 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
3461 SetLastError(ERROR_INVALID_HANDLE
);
3462 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
3463 SetLastError(ERROR_INVALID_HANDLE
);
3464 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
3465 SetLastError(ERROR_INVALID_USER_BUFFER
);
3466 else if (!DeviceInstallParams
)
3467 SetLastError(ERROR_INVALID_PARAMETER
);
3468 else if (DeviceInstallParams
->cbSize
!= sizeof(SP_DEVINSTALL_PARAMS_W
))
3469 SetLastError(ERROR_INVALID_USER_BUFFER
);
3472 PSP_DEVINSTALL_PARAMS_W Destination
;
3474 /* FIXME: Validate parameters */
3477 Destination
= &((struct DeviceInfoElement
*)DeviceInfoData
->Reserved
)->InstallParams
;
3479 Destination
= &list
->InstallParams
;
3480 memcpy(Destination
, DeviceInstallParams
, DeviceInstallParams
->cbSize
);
3484 TRACE("Returning %d\n", ret
);
3488 /***********************************************************************
3489 * SetupDiCreateDevRegKey (SETUPAPI.@)
3491 HKEY WINAPI
SetupDiCreateDevRegKeyW(
3492 IN HDEVINFO DeviceInfoSet
,
3493 IN PSP_DEVINFO_DATA DeviceInfoData
,
3497 IN HINF InfHandle OPTIONAL
,
3498 IN PCWSTR InfSectionName OPTIONAL
)
3500 struct DeviceInfoSet
*list
;
3501 HKEY ret
= INVALID_HANDLE_VALUE
;
3503 TRACE("%p %p %lu %lu %lu %p %s\n", DeviceInfoSet
, DeviceInfoData
,
3504 Scope
, HwProfile
, KeyType
, InfHandle
, debugstr_w(InfSectionName
));
3507 SetLastError(ERROR_INVALID_HANDLE
);
3508 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
3509 SetLastError(ERROR_INVALID_HANDLE
);
3510 else if (!DeviceInfoData
)
3511 SetLastError(ERROR_INVALID_PARAMETER
);
3512 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
3513 SetLastError(ERROR_INVALID_USER_BUFFER
);
3514 else if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3515 SetLastError(ERROR_INVALID_PARAMETER
);
3516 else if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
3517 SetLastError(ERROR_INVALID_PARAMETER
);
3518 else if (InfHandle
&& !InfSectionName
)
3519 SetLastError(ERROR_INVALID_PARAMETER
);
3520 else if (!InfHandle
&& InfSectionName
)
3521 SetLastError(ERROR_INVALID_PARAMETER
);
3524 LPWSTR lpGuidString
= NULL
;
3525 LPWSTR DriverKey
= NULL
; /* {GUID}\Index */
3526 LPWSTR pDeviceInstance
; /* Points into DriverKey, on the Index field */
3527 DWORD Index
; /* Index used in the DriverKey name */
3529 HKEY hClassKey
= INVALID_HANDLE_VALUE
;
3530 HKEY hDeviceKey
= INVALID_HANDLE_VALUE
;
3531 HKEY hKey
= INVALID_HANDLE_VALUE
;
3533 if (Scope
== DICS_FLAG_CONFIGSPECIFIC
)
3535 FIXME("DICS_FLAG_CONFIGSPECIFIC case unimplemented\n");
3539 if (KeyType
== DIREG_DEV
)
3541 FIXME("DIREG_DEV case unimplemented\n");
3543 else /* KeyType == DIREG_DRV */
3545 if (UuidToStringW((UUID
*)&DeviceInfoData
->ClassGuid
, &lpGuidString
) != RPC_S_OK
)
3547 /* The driver key is in HKLM\System\CurrentControlSet\Control\Class\{GUID}\Index */
3548 DriverKey
= HeapAlloc(GetProcessHeap(), 0, (wcslen(lpGuidString
) + 7) * sizeof(WCHAR
) + sizeof(UNICODE_STRING
));
3551 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3554 wcscpy(DriverKey
, L
"{");
3555 wcscat(DriverKey
, lpGuidString
);
3556 wcscat(DriverKey
, L
"}\\");
3557 pDeviceInstance
= &DriverKey
[wcslen(DriverKey
)];
3558 rc
= RegOpenKeyExW(list
->HKLM
,
3563 if (rc
!= ERROR_SUCCESS
)
3569 /* Try all values for Index between 0 and 9999 */
3571 while (Index
<= 9999)
3574 wsprintf(pDeviceInstance
, L
"%04lu", Index
);
3575 rc
= RegCreateKeyEx(hClassKey
,
3579 REG_OPTION_NON_VOLATILE
,
3580 #if _WIN32_WINNT >= 0x502
3581 KEY_READ
| KEY_WRITE
,
3588 if (rc
!= ERROR_SUCCESS
)
3593 if (Disposition
== REG_CREATED_NEW_KEY
)
3596 hKey
= INVALID_HANDLE_VALUE
;
3601 /* Unable to create more than 9999 devices within the same class */
3602 SetLastError(ERROR_GEN_FAILURE
);
3606 /* Open device key, to write Driver value */
3607 hDeviceKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, Scope
, HwProfile
, DIREG_DEV
, KEY_SET_VALUE
);
3608 if (hDeviceKey
== INVALID_HANDLE_VALUE
)
3610 rc
= RegSetValueEx(hDeviceKey
, L
"Driver", 0, REG_SZ
, (const BYTE
*)DriverKey
, (wcslen(DriverKey
) + 1) * sizeof(WCHAR
));
3611 if (rc
!= ERROR_SUCCESS
)
3618 /* Do installation of the specified section */
3621 FIXME("Need to install section %s in file %p\n",
3622 debugstr_w(InfSectionName
), InfHandle
);
3628 RpcStringFreeW(&lpGuidString
);
3629 HeapFree(GetProcessHeap(), 0, DriverKey
);
3630 if (hClassKey
!= INVALID_HANDLE_VALUE
)
3631 RegCloseKey(hClassKey
);
3632 if (hDeviceKey
!= INVALID_HANDLE_VALUE
)
3633 RegCloseKey(hDeviceKey
);
3634 if (hKey
!= INVALID_HANDLE_VALUE
&& hKey
!= ret
)
3638 TRACE("Returning 0x%p\n", ret
);
3642 /***********************************************************************
3643 * SetupDiOpenDevRegKey (SETUPAPI.@)
3645 HKEY WINAPI
SetupDiOpenDevRegKey(
3646 HDEVINFO DeviceInfoSet
,
3647 PSP_DEVINFO_DATA DeviceInfoData
,
3653 struct DeviceInfoSet
*list
;
3654 HKEY ret
= INVALID_HANDLE_VALUE
;
3656 TRACE("%p %p %lu %lu %lu 0x%lx\n", DeviceInfoSet
, DeviceInfoData
,
3657 Scope
, HwProfile
, KeyType
, samDesired
);
3660 SetLastError(ERROR_INVALID_HANDLE
);
3661 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
3662 SetLastError(ERROR_INVALID_HANDLE
);
3663 else if (!DeviceInfoData
)
3664 SetLastError(ERROR_INVALID_PARAMETER
);
3665 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
3666 SetLastError(ERROR_INVALID_USER_BUFFER
);
3667 else if (Scope
!= DICS_FLAG_GLOBAL
&& Scope
!= DICS_FLAG_CONFIGSPECIFIC
)
3668 SetLastError(ERROR_INVALID_PARAMETER
);
3669 else if (KeyType
!= DIREG_DEV
&& KeyType
!= DIREG_DRV
)
3670 SetLastError(ERROR_INVALID_PARAMETER
);
3673 HKEY hKey
= INVALID_HANDLE_VALUE
;
3674 HKEY hRootKey
= INVALID_HANDLE_VALUE
;
3675 struct DeviceInfoElement
*deviceInfo
= (struct DeviceInfoElement
*)DeviceInfoData
->Reserved
;
3676 LPWSTR DriverKey
= NULL
;
3681 if (Scope
== DICS_FLAG_CONFIGSPECIFIC
)
3683 FIXME("DICS_FLAG_CONFIGSPECIFIC case unimplemented\n");
3685 else /* Scope == DICS_FLAG_GLOBAL */
3691 KEY_ENUMERATE_SUB_KEYS
,
3693 if (rc
!= ERROR_SUCCESS
)
3700 deviceInfo
->DeviceName
,
3702 KeyType
== DIREG_DEV
? samDesired
: KEY_QUERY_VALUE
,
3704 RegCloseKey(hRootKey
);
3705 hRootKey
= INVALID_HANDLE_VALUE
;
3706 if (rc
!= ERROR_SUCCESS
)
3711 if (KeyType
== DIREG_DEV
)
3713 /* We're done. Just return the hKey handle */
3717 /* Read the 'Driver' key */
3718 rc
= RegQueryValueExW(hKey
, L
"Driver", NULL
, &dwRegType
, NULL
, &dwLength
);
3719 if (rc
!= ERROR_SUCCESS
)
3724 if (dwRegType
!= REG_SZ
)
3726 SetLastError(ERROR_GEN_FAILURE
);
3729 DriverKey
= HeapAlloc(GetProcessHeap(), 0, dwLength
);
3732 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3735 rc
= RegQueryValueExW(hKey
, L
"Driver", NULL
, &dwRegType
, (LPBYTE
)DriverKey
, &dwLength
);
3736 if (rc
!= ERROR_SUCCESS
)
3742 hKey
= INVALID_HANDLE_VALUE
;
3743 /* Need to open the driver key */
3748 KEY_ENUMERATE_SUB_KEYS
,
3750 if (rc
!= ERROR_SUCCESS
)
3761 if (rc
!= ERROR_SUCCESS
)
3769 if (hRootKey
!= INVALID_HANDLE_VALUE
)
3770 RegCloseKey(hRootKey
);
3771 if (hKey
!= INVALID_HANDLE_VALUE
&& hKey
!= ret
)
3775 TRACE("Returning 0x%p\n", ret
);
3779 /***********************************************************************
3780 * SetupDiCreateDeviceInfoA (SETUPAPI.@)
3782 BOOL WINAPI
SetupDiCreateDeviceInfoA(
3783 HDEVINFO DeviceInfoSet
,
3785 CONST GUID
*ClassGuid
,
3786 PCSTR DeviceDescription
,
3788 DWORD CreationFlags
,
3789 PSP_DEVINFO_DATA DeviceInfoData
)
3791 LPWSTR DeviceNameW
= NULL
;
3792 LPWSTR DeviceDescriptionW
= NULL
;
3799 DeviceNameW
= MultiByteToUnicode(DeviceName
, CP_ACP
);
3800 if (DeviceNameW
== NULL
) return FALSE
;
3802 if (DeviceDescription
)
3804 DeviceDescriptionW
= MultiByteToUnicode(DeviceDescription
, CP_ACP
);
3805 if (DeviceDescriptionW
== NULL
)
3807 if (DeviceNameW
) MyFree(DeviceNameW
);
3812 bResult
= SetupDiCreateDeviceInfoW(DeviceInfoSet
, DeviceNameW
,
3813 ClassGuid
, DeviceDescriptionW
,
3814 hwndParent
, CreationFlags
,
3817 if (DeviceNameW
) MyFree(DeviceNameW
);
3818 if (DeviceDescriptionW
) MyFree(DeviceDescriptionW
);
3823 /***********************************************************************
3824 * SetupDiCreateDeviceInfoW (SETUPAPI.@)
3826 BOOL WINAPI
SetupDiCreateDeviceInfoW(
3827 HDEVINFO DeviceInfoSet
,
3829 CONST GUID
*ClassGuid
,
3830 PCWSTR DeviceDescription
,
3832 DWORD CreationFlags
,
3833 PSP_DEVINFO_DATA DeviceInfoData
)
3835 struct DeviceInfoSet
*list
;
3838 TRACE("%p %S %s %S %p %lx %p\n", DeviceInfoSet
, DeviceName
,
3839 debugstr_guid(ClassGuid
), DeviceDescription
,
3840 hwndParent
, CreationFlags
, DeviceInfoData
);
3843 SetLastError(ERROR_INVALID_HANDLE
);
3844 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
3845 SetLastError(ERROR_INVALID_HANDLE
);
3846 else if (!ClassGuid
)
3847 SetLastError(ERROR_INVALID_PARAMETER
);
3848 else if (!IsEqualIID(&list
->ClassGuid
, &GUID_NULL
) && !IsEqualIID(&list
->ClassGuid
, ClassGuid
))
3849 SetLastError(ERROR_CLASS_MISMATCH
);
3850 else if (CreationFlags
& ~(DICD_GENERATE_ID
| DICD_INHERIT_CLASSDRVS
))
3852 TRACE("Unknown flags: 0x%08lx\n", CreationFlags
& ~(DICD_GENERATE_ID
| DICD_INHERIT_CLASSDRVS
));
3853 SetLastError(ERROR_INVALID_PARAMETER
);
3857 SP_DEVINFO_DATA DevInfo
;
3859 if (CreationFlags
& DICD_GENERATE_ID
)
3861 /* Generate a new unique ID for this device */
3862 SetLastError(ERROR_GEN_FAILURE
);
3863 FIXME("not implemented\n");
3867 /* Device name is fully qualified. Try to open it */
3870 DevInfo
.cbSize
= sizeof(SP_DEVINFO_DATA
);
3871 rc
= SetupDiOpenDeviceInfoW(
3874 NULL
, /* hwndParent */
3875 CreationFlags
& DICD_INHERIT_CLASSDRVS
? DIOD_INHERIT_CLASSDRVS
: 0,
3880 /* SetupDiOpenDeviceInfoW has already added
3881 * the device info to the device info set
3883 SetLastError(ERROR_DEVINST_ALREADY_EXISTS
);
3885 else if (GetLastError() == ERROR_FILE_NOT_FOUND
)
3887 struct DeviceInfoElement
*deviceInfo
;
3889 /* FIXME: ClassGuid can be NULL */
3890 if (CreateDeviceInfoElement(DeviceName
, ClassGuid
, &deviceInfo
))
3892 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
3894 if (!DeviceInfoData
)
3898 if (DeviceInfoData
->cbSize
!= sizeof(PSP_DEVINFO_DATA
))
3900 SetLastError(ERROR_INVALID_USER_BUFFER
);
3904 memcpy(&DeviceInfoData
->ClassGuid
, ClassGuid
, sizeof(GUID
));
3905 DeviceInfoData
->DevInst
= 0; /* FIXME */
3906 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInfo
;
3915 TRACE("Returning %d\n", ret
);
3919 /***********************************************************************
3920 * Helper functions for SetupDiBuildDriverInfoList
3924 IN PLIST_ENTRY DriverListHead
,
3925 IN DWORD DriverType
, /* SPDIT_CLASSDRIVER or SPDIT_COMPATDRIVER */
3926 IN LPGUID ClassGuid
,
3927 IN INFCONTEXT ContextDevice
,
3928 IN
struct InfFileDetails
*InfFileDetails
,
3930 IN LPCWSTR ProviderName
,
3931 IN LPCWSTR ManufacturerName
,
3932 IN LPCWSTR MatchingId
,
3933 FILETIME DriverDate
,
3934 DWORDLONG DriverVersion
,
3937 struct DriverInfoElement
*driverInfo
= NULL
;
3938 HANDLE hFile
= INVALID_HANDLE_VALUE
;
3939 DWORD RequiredSize
= 128; /* Initial buffer size */
3940 BOOL Result
= FALSE
;
3941 PLIST_ENTRY PreviousEntry
;
3942 LPWSTR InfInstallSection
= NULL
;
3945 driverInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct DriverInfoElement
));
3948 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3951 memset(driverInfo
, 0, sizeof(struct DriverInfoElement
));
3953 driverInfo
->Details
.cbSize
= sizeof(SP_DRVINFO_DETAIL_DATA
);
3954 driverInfo
->Details
.Reserved
= (ULONG_PTR
)driverInfo
;
3956 /* Copy InfFileName field */
3957 wcsncpy(driverInfo
->Details
.InfFileName
, InfFile
, MAX_PATH
- 1);
3958 driverInfo
->Details
.InfFileName
[MAX_PATH
- 1] = '\0';
3960 /* Fill InfDate field */
3961 /* FIXME: hFile = CreateFile(driverInfo->Details.InfFileName,
3962 GENERIC_READ, FILE_SHARE_READ,
3963 NULL, OPEN_EXISTING, 0, NULL);
3964 if (hFile == INVALID_HANDLE_VALUE)
3966 Result = GetFileTime(hFile, NULL, NULL, &driverInfo->Details.InfDate);
3970 /* Fill SectionName field */
3971 Result
= SetupGetStringFieldW(
3974 driverInfo
->Details
.SectionName
, LINE_LEN
,
3979 /* Fill DrvDescription field */
3980 Result
= SetupGetStringFieldW(
3982 0, /* Field index */
3983 driverInfo
->Details
.DrvDescription
, LINE_LEN
,
3986 /* Copy MatchingId information */
3987 driverInfo
->MatchingId
= HeapAlloc(GetProcessHeap(), 0, (wcslen(MatchingId
) + 1) * sizeof(WCHAR
));
3988 if (!driverInfo
->MatchingId
)
3990 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3993 RtlCopyMemory(driverInfo
->MatchingId
, MatchingId
, (wcslen(MatchingId
) + 1) * sizeof(WCHAR
));
3995 /* Get inf install section */
3997 RequiredSize
= 128; /* Initial buffer size */
3998 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3999 while (!Result
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
4001 HeapFree(GetProcessHeap(), 0, InfInstallSection
);
4002 InfInstallSection
= HeapAlloc(GetProcessHeap(), 0, RequiredSize
* sizeof(WCHAR
));
4003 if (!InfInstallSection
)
4005 Result
= SetupGetStringFieldW(
4007 1, /* Field index */
4008 InfInstallSection
, RequiredSize
,
4014 TRACE("Adding driver '%S' [%S/%S] (Rank 0x%lx)\n",
4015 driverInfo
->Details
.DrvDescription
, InfFile
, InfInstallSection
, Rank
);
4017 driverInfo
->DriverRank
= Rank
;
4018 memcpy(&driverInfo
->ClassGuid
, ClassGuid
, sizeof(GUID
));
4019 driverInfo
->Info
.DriverType
= DriverType
;
4020 driverInfo
->Info
.Reserved
= (ULONG_PTR
)driverInfo
;
4021 wcsncpy(driverInfo
->Info
.Description
, driverInfo
->Details
.DrvDescription
, LINE_LEN
- 1);
4022 driverInfo
->Info
.Description
[LINE_LEN
- 1] = '\0';
4023 wcsncpy(driverInfo
->Info
.MfgName
, ManufacturerName
, LINE_LEN
- 1);
4024 driverInfo
->Info
.MfgName
[LINE_LEN
- 1] = '\0';
4027 wcsncpy(driverInfo
->Info
.ProviderName
, ProviderName
, LINE_LEN
- 1);
4028 driverInfo
->Info
.ProviderName
[LINE_LEN
- 1] = '\0';
4031 driverInfo
->Info
.ProviderName
[0] = '\0';
4032 driverInfo
->Info
.DriverDate
= DriverDate
;
4033 driverInfo
->Info
.DriverVersion
= DriverVersion
;
4034 ReferenceInfFile(InfFileDetails
);
4035 driverInfo
->InfFileDetails
= InfFileDetails
;
4037 /* Insert current driver in driver list, according to its rank */
4038 PreviousEntry
= DriverListHead
->Flink
;
4039 while (PreviousEntry
!= DriverListHead
)
4041 if (((struct DriverInfoElement
*)PreviousEntry
)->DriverRank
>= Rank
)
4043 /* Insert before the current item */
4044 InsertHeadList(PreviousEntry
, &driverInfo
->ListEntry
);
4048 if (PreviousEntry
== DriverListHead
)
4050 /* Insert at the end of the list */
4051 InsertTailList(DriverListHead
, &driverInfo
->ListEntry
);
4060 HeapFree(GetProcessHeap(), 0, driverInfo
->MatchingId
);
4061 HeapFree(GetProcessHeap(), 0, driverInfo
);
4063 if (hFile
!= INVALID_HANDLE_VALUE
)
4065 HeapFree(GetProcessHeap(), 0, InfInstallSection
);
4071 GetVersionInformationFromInfFile(
4073 OUT LPGUID ClassGuid
,
4074 OUT LPWSTR
* pProviderName
,
4075 OUT FILETIME
* DriverDate
,
4076 OUT DWORDLONG
* DriverVersion
)
4079 WCHAR guidW
[MAX_GUID_STRING_LEN
+ 1];
4080 LPWSTR DriverVer
= NULL
;
4081 LPWSTR ProviderName
= NULL
;
4082 LPWSTR pComma
; /* Points into DriverVer */
4083 LPWSTR pVersion
= NULL
; /* Points into DriverVer */
4084 SYSTEMTIME SystemTime
;
4086 BOOL ret
= FALSE
; /* Final result */
4088 /* Get class Guid */
4089 if (!SetupGetLineTextW(
4092 L
"Version", L
"ClassGUID",
4093 guidW
, sizeof(guidW
),
4094 NULL
/* Required size */))
4098 guidW
[37] = '\0'; /* Replace the } by a NULL character */
4099 if (UuidFromStringW(&guidW
[1], ClassGuid
) != RPC_S_OK
)
4101 SetLastError(ERROR_GEN_FAILURE
);
4105 /* Get provider name */
4106 Result
= SetupGetLineTextW(
4108 hInf
, L
"Version", L
"Provider",
4113 /* We know know the needed buffer size */
4114 ProviderName
= HeapAlloc(GetProcessHeap(), 0, RequiredSize
* sizeof(WCHAR
));
4117 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4120 Result
= SetupGetLineTextW(
4122 hInf
, L
"Version", L
"Provider",
4123 ProviderName
, RequiredSize
,
4128 *pProviderName
= ProviderName
;
4130 /* Read the "DriverVer" value */
4131 Result
= SetupGetLineTextW(
4133 hInf
, L
"Version", L
"DriverVer",
4138 /* We know know the needed buffer size */
4139 DriverVer
= HeapAlloc(GetProcessHeap(), 0, RequiredSize
* sizeof(WCHAR
));
4142 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4145 Result
= SetupGetLineTextW(
4147 hInf
, L
"Version", L
"DriverVer",
4148 DriverVer
, RequiredSize
,
4154 /* Get driver date and driver version, by analyzing the "DriverVer" value */
4155 pComma
= wcschr(DriverVer
, ',');
4158 *pComma
= UNICODE_NULL
;
4159 pVersion
= pComma
+ 1;
4161 /* Get driver date version. Invalid date = 00/00/00 */
4162 memset(DriverDate
, 0, sizeof(FILETIME
));
4163 if (wcslen(DriverVer
) == 10
4164 && (DriverVer
[2] == '-' || DriverVer
[2] == '/')
4165 && (DriverVer
[5] == '-' || DriverVer
[5] == '/'))
4167 memset(&SystemTime
, 0, sizeof(SYSTEMTIME
));
4168 DriverVer
[2] = DriverVer
[5] = UNICODE_NULL
;
4169 SystemTime
.wMonth
= ((DriverVer
[0] - '0') * 10) + DriverVer
[1] - '0';
4170 SystemTime
.wDay
= ((DriverVer
[3] - '0') * 10) + DriverVer
[4] - '0';
4171 SystemTime
.wYear
= ((DriverVer
[6] - '0') * 1000) + ((DriverVer
[7] - '0') * 100) + ((DriverVer
[8] - '0') * 10) + DriverVer
[9] - '0';
4172 SystemTimeToFileTime(&SystemTime
, DriverDate
);
4174 /* Get driver version. Invalid version = 0.0.0.0 */
4176 /* FIXME: use pVersion to fill DriverVersion variable */
4182 HeapFree(GetProcessHeap(), 0, ProviderName
);
4183 HeapFree(GetProcessHeap(), 0, DriverVer
);
4185 TRACE("Returning %d\n", ret
);
4189 /***********************************************************************
4190 * SetupDiBuildDriverInfoList (SETUPAPI.@)
4193 SetupDiBuildDriverInfoList(
4194 IN HDEVINFO DeviceInfoSet
,
4195 IN OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4196 IN DWORD DriverType
)
4198 struct DeviceInfoSet
*list
;
4199 SP_DEVINSTALL_PARAMS_W InstallParams
;
4200 PVOID Buffer
= NULL
;
4201 struct InfFileDetails
*currentInfFileDetails
= NULL
;
4202 LPWSTR ProviderName
= NULL
;
4203 LPWSTR ManufacturerName
= NULL
;
4204 WCHAR ManufacturerSection
[LINE_LEN
+ 1];
4205 LPWSTR HardwareIDs
= NULL
;
4206 LPWSTR CompatibleIDs
= NULL
;
4207 FILETIME DriverDate
;
4208 DWORDLONG DriverVersion
= 0;
4212 TRACE("%p %p %ld\n", DeviceInfoSet
, DeviceInfoData
, DriverType
);
4215 SetLastError(ERROR_INVALID_HANDLE
);
4216 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
4217 SetLastError(ERROR_INVALID_HANDLE
);
4218 else if (list
->HKLM
!= HKEY_LOCAL_MACHINE
)
4219 SetLastError(ERROR_INVALID_HANDLE
);
4220 else if (DriverType
!= SPDIT_CLASSDRIVER
&& DriverType
!= SPDIT_COMPATDRIVER
)
4221 SetLastError(ERROR_INVALID_PARAMETER
);
4222 else if (DriverType
== SPDIT_CLASSDRIVER
&& DeviceInfoData
)
4223 SetLastError(ERROR_INVALID_PARAMETER
);
4224 else if (DriverType
== SPDIT_COMPATDRIVER
&& !DeviceInfoData
)
4225 SetLastError(ERROR_INVALID_PARAMETER
);
4226 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4227 SetLastError(ERROR_INVALID_USER_BUFFER
);
4232 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS
);
4233 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
4237 if (DriverType
== SPDIT_COMPATDRIVER
)
4239 /* Get hardware IDs list */
4241 RequiredSize
= 512; /* Initial buffer size */
4242 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4243 while (!Result
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
4245 HeapFree(GetProcessHeap(), 0, HardwareIDs
);
4246 HardwareIDs
= HeapAlloc(GetProcessHeap(), 0, RequiredSize
);
4249 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4252 Result
= SetupDiGetDeviceRegistryPropertyW(
4264 /* Get compatible IDs list */
4266 RequiredSize
= 512; /* Initial buffer size */
4267 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4268 while (!Result
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
4270 HeapFree(GetProcessHeap(), 0, CompatibleIDs
);
4271 CompatibleIDs
= HeapAlloc(GetProcessHeap(), 0, RequiredSize
);
4274 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4277 Result
= SetupDiGetDeviceRegistryPropertyW(
4280 SPDRP_COMPATIBLEIDS
,
4282 (PBYTE
)CompatibleIDs
,
4285 if (!Result
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
4287 /* No compatible ID for this device */
4288 HeapFree(GetProcessHeap(), 0, CompatibleIDs
);
4289 CompatibleIDs
= NULL
;
4297 /* Enumerate .inf files */
4299 RequiredSize
= 32768; /* Initial buffer size */
4300 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4301 while (!Result
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
4303 HeapFree(GetProcessHeap(), 0, Buffer
);
4304 Buffer
= HeapAlloc(GetProcessHeap(), 0, RequiredSize
* sizeof(WCHAR
));
4308 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4311 Result
= SetupGetInfFileListW(
4312 *InstallParams
.DriverPath
? InstallParams
.DriverPath
: NULL
,
4314 Buffer
, RequiredSize
,
4317 if (!Result
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
4319 /* No .inf file in specified directory. So, we should
4320 * success as we created an empty driver info list.
4329 for (filename
= (LPCWSTR
)Buffer
; *filename
; filename
+= wcslen(filename
) + 1)
4331 INFCONTEXT ContextManufacturer
, ContextDevice
;
4333 TRACE("Opening file %S\n", filename
);
4335 currentInfFileDetails
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct InfFileDetails
));
4336 if (!currentInfFileDetails
)
4338 memset(currentInfFileDetails
, 0, sizeof(struct InfFileDetails
));
4340 currentInfFileDetails
->hInf
= SetupOpenInfFileW(filename
, NULL
, INF_STYLE_WIN4
, NULL
);
4341 ReferenceInfFile(currentInfFileDetails
);
4342 if (currentInfFileDetails
->hInf
== INVALID_HANDLE_VALUE
)
4344 HeapFree(GetProcessHeap(), 0, currentInfFileDetails
);
4345 currentInfFileDetails
= NULL
;
4349 if (!GetVersionInformationFromInfFile(
4350 currentInfFileDetails
->hInf
,
4356 SetupCloseInfFile(currentInfFileDetails
->hInf
);
4357 HeapFree(GetProcessHeap(), 0, currentInfFileDetails
->hInf
);
4358 currentInfFileDetails
= NULL
;
4362 if (DriverType
== SPDIT_CLASSDRIVER
)
4364 /* Check if the ClassGuid in this .inf file is corresponding with our needs */
4365 if (!IsEqualIID(&list
->ClassGuid
, &GUID_NULL
) && !IsEqualIID(&list
->ClassGuid
, &ClassGuid
))
4371 /* Get the manufacturers list */
4372 Result
= SetupFindFirstLineW(currentInfFileDetails
->hInf
, L
"Manufacturer", NULL
, &ContextManufacturer
);
4375 Result
= SetupGetStringFieldW(
4376 &ContextManufacturer
,
4377 0, /* Field index */
4382 /* We got the needed size for the buffer */
4383 ManufacturerName
= HeapAlloc(GetProcessHeap(), 0, RequiredSize
* sizeof(WCHAR
));
4384 if (!ManufacturerName
)
4386 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4389 Result
= SetupGetStringFieldW(
4390 &ContextManufacturer
,
4391 0, /* Field index */
4392 ManufacturerName
, RequiredSize
,
4395 /* Get manufacturer section name */
4396 Result
= SetupGetStringFieldW(
4397 &ContextManufacturer
,
4398 1, /* Field index */
4399 ManufacturerSection
, LINE_LEN
,
4403 ManufacturerSection
[RequiredSize
] = 0; /* Final NULL char */
4404 /* Add (possible) extension to manufacturer section name */
4405 Result
= SetupDiGetActualSectionToInstallW(
4406 currentInfFileDetails
->hInf
, ManufacturerSection
, ManufacturerSection
, LINE_LEN
, NULL
, NULL
);
4409 TRACE("Enumerating devices in manufacturer %S\n", ManufacturerSection
);
4410 Result
= SetupFindFirstLineW(currentInfFileDetails
->hInf
, ManufacturerSection
, NULL
, &ContextDevice
);
4415 if (DriverType
== SPDIT_CLASSDRIVER
)
4417 /* FIXME: read [ControlFlags] / ExcludeFromSelect */
4418 if (!AddDriverToList(
4419 &list
->DriverListHead
,
4423 currentInfFileDetails
,
4428 DriverDate
, DriverVersion
,
4434 else /* DriverType = SPDIT_COMPATDRIVER */
4436 /* 1. Get all fields */
4437 DWORD FieldCount
= SetupGetFieldCount(&ContextDevice
);
4441 BOOL DriverAlreadyAdded
;
4443 for (i
= 2; i
<= FieldCount
; i
++)
4445 LPWSTR DeviceId
= NULL
;
4447 RequiredSize
= 128; /* Initial buffer size */
4448 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4449 while (!Result
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
4451 HeapFree(GetProcessHeap(), 0, DeviceId
);
4452 DeviceId
= HeapAlloc(GetProcessHeap(), 0, RequiredSize
* sizeof(WCHAR
));
4455 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4458 Result
= SetupGetStringFieldW(
4461 DeviceId
, RequiredSize
,
4466 HeapFree(GetProcessHeap(), 0, DeviceId
);
4469 DriverAlreadyAdded
= FALSE
;
4470 for (DriverRank
= 0, currentId
= (LPCWSTR
)HardwareIDs
; !DriverAlreadyAdded
&& *currentId
; currentId
+= wcslen(currentId
) + 1, DriverRank
++)
4472 if (wcscmp(DeviceId
, currentId
) == 0)
4475 &((struct DeviceInfoElement
*)DeviceInfoData
->Reserved
)->DriverListHead
,
4479 currentInfFileDetails
,
4484 DriverDate
, DriverVersion
,
4485 DriverRank
+ (i
== 2 ? 0 : 0x1000 + i
- 3));
4486 DriverAlreadyAdded
= TRUE
;
4491 for (DriverRank
= 0, currentId
= (LPCWSTR
)CompatibleIDs
; !DriverAlreadyAdded
&& *currentId
; currentId
+= wcslen(currentId
) + 1, DriverRank
++)
4493 if (wcscmp(DeviceId
, currentId
) == 0)
4496 &((struct DeviceInfoElement
*)DeviceInfoData
->Reserved
)->DriverListHead
,
4500 currentInfFileDetails
,
4505 DriverDate
, DriverVersion
,
4506 DriverRank
+ (i
== 2 ? 0x2000 : 0x3000 + i
- 3));
4507 DriverAlreadyAdded
= TRUE
;
4511 HeapFree(GetProcessHeap(), 0, DeviceId
);
4514 Result
= SetupFindNextLine(&ContextDevice
, &ContextDevice
);
4517 HeapFree(GetProcessHeap(), 0, ManufacturerName
);
4518 ManufacturerName
= NULL
;
4519 Result
= SetupFindNextLine(&ContextManufacturer
, &ContextManufacturer
);
4524 HeapFree(GetProcessHeap(), 0, ProviderName
);
4525 ProviderName
= NULL
;
4527 DereferenceInfFile(currentInfFileDetails
);
4528 currentInfFileDetails
= NULL
;
4539 InstallParams
.Flags
|= DI_DIDCOMPAT
;
4540 InstallParams
.FlagsEx
|= DI_FLAGSEX_DIDCOMPATINFO
;
4544 InstallParams
.Flags
|= DI_DIDCLASS
;
4545 InstallParams
.FlagsEx
|= DI_FLAGSEX_DIDINFOLIST
;
4547 ret
= SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
4550 HeapFree(GetProcessHeap(), 0, ProviderName
);
4551 HeapFree(GetProcessHeap(), 0, ManufacturerName
);
4552 HeapFree(GetProcessHeap(), 0, HardwareIDs
);
4553 HeapFree(GetProcessHeap(), 0, CompatibleIDs
);
4554 if (currentInfFileDetails
)
4555 DereferenceInfFile(currentInfFileDetails
);
4556 HeapFree(GetProcessHeap(), 0, Buffer
);
4558 TRACE("Returning %d\n", ret
);
4562 /***********************************************************************
4563 * SetupDiDeleteDeviceInfo (SETUPAPI.@)
4566 SetupDiDeleteDeviceInfo(
4567 IN HDEVINFO DeviceInfoSet
,
4568 IN PSP_DEVINFO_DATA DeviceInfoData
)
4570 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
4572 FIXME("not implemented\n");
4573 SetLastError(ERROR_GEN_FAILURE
);
4578 /***********************************************************************
4579 * SetupDiDestroyDriverInfoList (SETUPAPI.@)
4582 SetupDiDestroyDriverInfoList(
4583 IN HDEVINFO DeviceInfoSet
,
4584 IN PSP_DEVINFO_DATA DeviceInfoData
,
4585 IN DWORD DriverType
)
4587 struct DeviceInfoSet
*list
;
4590 TRACE("%p %p 0x%lx\n", DeviceInfoSet
, DeviceInfoData
, DriverType
);
4593 SetLastError(ERROR_INVALID_HANDLE
);
4594 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
4595 SetLastError(ERROR_INVALID_HANDLE
);
4596 else if (DriverType
!= SPDIT_CLASSDRIVER
&& DriverType
!= SPDIT_COMPATDRIVER
)
4597 SetLastError(ERROR_INVALID_PARAMETER
);
4598 else if (DriverType
== SPDIT_COMPATDRIVER
&& !DeviceInfoData
)
4599 SetLastError(ERROR_INVALID_PARAMETER
);
4600 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4601 SetLastError(ERROR_INVALID_USER_BUFFER
);
4604 PLIST_ENTRY ListEntry
;
4605 struct DriverInfoElement
*driverInfo
;
4606 SP_DEVINSTALL_PARAMS_W InstallParams
;
4608 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4609 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
))
4612 if (!DeviceInfoData
)
4613 /* Fall back to destroying class driver list */
4614 DriverType
= SPDIT_CLASSDRIVER
;
4616 if (DriverType
== SPDIT_CLASSDRIVER
)
4618 while (!IsListEmpty(&list
->DriverListHead
))
4620 ListEntry
= RemoveHeadList(&list
->DriverListHead
);
4621 driverInfo
= (struct DriverInfoElement
*)ListEntry
;
4622 DestroyDriverInfoElement(driverInfo
);
4624 InstallParams
.Reserved
= 0;
4625 InstallParams
.Flags
&= ~(DI_DIDCLASS
| DI_MULTMFGS
);
4626 InstallParams
.FlagsEx
&= ~DI_FLAGSEX_DIDINFOLIST
;
4627 ret
= SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, NULL
, &InstallParams
);
4631 SP_DEVINSTALL_PARAMS_W InstallParamsSet
;
4632 struct DeviceInfoElement
*deviceInfo
;
4634 InstallParamsSet
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
4635 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, NULL
, &InstallParamsSet
))
4637 deviceInfo
= (struct DeviceInfoElement
*)DeviceInfoData
->Reserved
;
4638 while (!IsListEmpty(&deviceInfo
->DriverListHead
))
4640 ListEntry
= RemoveHeadList(&deviceInfo
->DriverListHead
);
4641 driverInfo
= (struct DriverInfoElement
*)ListEntry
;
4642 if ((PVOID
)InstallParamsSet
.Reserved
== driverInfo
)
4644 InstallParamsSet
.Reserved
= 0;
4645 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, NULL
, &InstallParamsSet
);
4647 DestroyDriverInfoElement(driverInfo
);
4649 InstallParams
.Reserved
= 0;
4650 InstallParams
.Flags
&= ~DI_DIDCOMPAT
;
4651 InstallParams
.FlagsEx
&= ~DI_FLAGSEX_DIDCOMPATINFO
;
4652 ret
= SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
4657 TRACE("Returning %d\n", ret
);
4662 /***********************************************************************
4663 * SetupDiOpenDeviceInfoA (SETUPAPI.@)
4666 SetupDiOpenDeviceInfoA(
4667 IN HDEVINFO DeviceInfoSet
,
4668 IN PCSTR DeviceInstanceId
,
4669 IN HWND hwndParent OPTIONAL
,
4671 OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4673 LPWSTR DeviceInstanceIdW
= NULL
;
4676 TRACE("%p %s %p %lx %p\n", DeviceInfoSet
, DeviceInstanceId
, hwndParent
, OpenFlags
, DeviceInfoData
);
4678 DeviceInstanceIdW
= MultiByteToUnicode(DeviceInstanceId
, CP_ACP
);
4679 if (DeviceInstanceIdW
== NULL
)
4682 bResult
= SetupDiOpenDeviceInfoW(DeviceInfoSet
,
4683 DeviceInstanceIdW
, hwndParent
, OpenFlags
, DeviceInfoData
);
4685 MyFree(DeviceInstanceIdW
);
4691 /***********************************************************************
4692 * SetupDiOpenDeviceInfoW (SETUPAPI.@)
4695 SetupDiOpenDeviceInfoW(
4696 IN HDEVINFO DeviceInfoSet
,
4697 IN PCWSTR DeviceInstanceId
,
4698 IN HWND hwndParent OPTIONAL
,
4700 OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
4702 struct DeviceInfoSet
*list
;
4703 HKEY hEnumKey
, hKey
;
4707 TRACE("%p %S %p %lx %p\n", DeviceInfoSet
, DeviceInstanceId
, hwndParent
, OpenFlags
, DeviceInfoData
);
4709 if (OpenFlags
& DIOD_CANCEL_REMOVE
)
4710 FIXME("DIOD_CANCEL_REMOVE flag not implemented\n");
4713 SetLastError(ERROR_INVALID_HANDLE
);
4714 else if ((list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
4715 SetLastError(ERROR_INVALID_HANDLE
);
4716 else if (!DeviceInstanceId
)
4717 SetLastError(ERROR_INVALID_PARAMETER
);
4718 else if (OpenFlags
& ~(DIOD_CANCEL_REMOVE
| DIOD_INHERIT_CLASSDRVS
))
4720 TRACE("Unknown flags: 0x%08lx\n", OpenFlags
& ~(DIOD_CANCEL_REMOVE
| DIOD_INHERIT_CLASSDRVS
));
4721 SetLastError(ERROR_INVALID_PARAMETER
);
4723 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4724 SetLastError(ERROR_INVALID_USER_BUFFER
);
4727 struct DeviceInfoElement
*deviceInfo
= NULL
;
4728 /* Search if device already exists in DeviceInfoSet.
4729 * If yes, return the existing element
4730 * If no, create a new element using informations in registry
4732 PLIST_ENTRY ItemList
= list
->ListHead
.Flink
;
4733 while (ItemList
!= &list
->ListHead
)
4738 FIXME("not implemented\n");
4739 ItemList
= ItemList
->Flink
;
4744 /* good one found */
4749 /* Open supposed registry key */
4754 KEY_ENUMERATE_SUB_KEYS
,
4756 if (rc
!= ERROR_SUCCESS
)
4767 RegCloseKey(hEnumKey
);
4768 if (rc
!= ERROR_SUCCESS
)
4774 /* FIXME: GUID_NULL is not allowed */
4775 if (!CreateDeviceInfoElement(DeviceInstanceId
, &GUID_NULL
/* FIXME */, &deviceInfo
))
4780 InsertTailList(&list
->ListHead
, &deviceInfo
->ListEntry
);
4786 if (ret
&& deviceInfo
&& DeviceInfoData
)
4788 memcpy(&DeviceInfoData
->ClassGuid
, &deviceInfo
->ClassGuid
, sizeof(GUID
));
4789 DeviceInfoData
->DevInst
= 0; /* FIXME */
4790 DeviceInfoData
->Reserved
= (ULONG_PTR
)deviceInfo
;
4798 /***********************************************************************
4799 * SetupDiEnumDriverInfoA (SETUPAPI.@)
4802 SetupDiEnumDriverInfoA(
4803 IN HDEVINFO DeviceInfoSet
,
4804 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4805 IN DWORD DriverType
,
4806 IN DWORD MemberIndex
,
4807 OUT PSP_DRVINFO_DATA_A DriverInfoData
)
4809 SP_DRVINFO_DATA_V2_W driverInfoData2W
;
4812 TRACE("%p %p 0x%lx %ld %p\n", DeviceInfoSet
, DeviceInfoData
,
4813 DriverType
, MemberIndex
, DriverInfoData
);
4815 if (DriverInfoData
== NULL
)
4816 SetLastError(ERROR_INVALID_PARAMETER
);
4817 else if (DriverInfoData
->cbSize
!= sizeof(SP_DRVINFO_DATA_V1_A
) && DriverInfoData
->cbSize
!= sizeof(SP_DRVINFO_DATA_V2_A
))
4818 SetLastError(ERROR_INVALID_USER_BUFFER
);
4821 driverInfoData2W
.cbSize
= sizeof(SP_DRVINFO_DATA_V2_W
);
4822 ret
= SetupDiEnumDriverInfoW(DeviceInfoSet
, DeviceInfoData
,
4823 DriverType
, MemberIndex
, &driverInfoData2W
);
4827 /* Do W->A conversion */
4828 DriverInfoData
->DriverType
= driverInfoData2W
.DriverType
;
4829 DriverInfoData
->Reserved
= driverInfoData2W
.Reserved
;
4830 if (WideCharToMultiByte(CP_ACP
, 0, driverInfoData2W
.Description
, -1,
4831 DriverInfoData
->Description
, LINE_LEN
, NULL
, NULL
) == 0)
4833 DriverInfoData
->Description
[0] = '\0';
4836 if (WideCharToMultiByte(CP_ACP
, 0, driverInfoData2W
.MfgName
, -1,
4837 DriverInfoData
->MfgName
, LINE_LEN
, NULL
, NULL
) == 0)
4839 DriverInfoData
->MfgName
[0] = '\0';
4842 if (WideCharToMultiByte(CP_ACP
, 0, driverInfoData2W
.ProviderName
, -1,
4843 DriverInfoData
->ProviderName
, LINE_LEN
, NULL
, NULL
) == 0)
4845 DriverInfoData
->ProviderName
[0] = '\0';
4848 if (DriverInfoData
->cbSize
== sizeof(SP_DRVINFO_DATA_V2_A
))
4850 /* Copy more fields */
4851 DriverInfoData
->DriverDate
= driverInfoData2W
.DriverDate
;
4852 DriverInfoData
->DriverVersion
= driverInfoData2W
.DriverVersion
;
4857 TRACE("Returning %d\n", ret
);
4862 /***********************************************************************
4863 * SetupDiEnumDriverInfoW (SETUPAPI.@)
4866 SetupDiEnumDriverInfoW(
4867 IN HDEVINFO DeviceInfoSet
,
4868 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4869 IN DWORD DriverType
,
4870 IN DWORD MemberIndex
,
4871 OUT PSP_DRVINFO_DATA_W DriverInfoData
)
4873 PLIST_ENTRY ListHead
;
4876 TRACE("%p %p 0x%lx %ld %p\n", DeviceInfoSet
, DeviceInfoData
,
4877 DriverType
, MemberIndex
, DriverInfoData
);
4879 if (!DeviceInfoSet
|| !DriverInfoData
)
4880 SetLastError(ERROR_INVALID_PARAMETER
);
4881 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
4882 SetLastError(ERROR_INVALID_HANDLE
);
4883 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
4884 SetLastError(ERROR_INVALID_HANDLE
);
4885 else if (DriverType
!= SPDIT_CLASSDRIVER
&& DriverType
!= SPDIT_COMPATDRIVER
)
4886 SetLastError(ERROR_INVALID_PARAMETER
);
4887 else if (DriverType
== SPDIT_CLASSDRIVER
&& DeviceInfoData
)
4888 SetLastError(ERROR_INVALID_PARAMETER
);
4889 else if (DriverType
== SPDIT_COMPATDRIVER
&& !DeviceInfoData
)
4890 SetLastError(ERROR_INVALID_PARAMETER
);
4891 else if (DriverInfoData
->cbSize
!= sizeof(SP_DRVINFO_DATA_V1_W
) && DriverInfoData
->cbSize
!= sizeof(SP_DRVINFO_DATA_V2_W
))
4892 SetLastError(ERROR_INVALID_USER_BUFFER
);
4895 struct DeviceInfoElement
*devInfo
= (struct DeviceInfoElement
*)DeviceInfoData
->Reserved
;
4896 PLIST_ENTRY ItemList
;
4897 if (DriverType
== SPDIT_CLASSDRIVER
||
4898 devInfo
->CreationFlags
& DICD_INHERIT_CLASSDRVS
)
4900 ListHead
= &((struct DeviceInfoSet
*)DeviceInfoSet
)->DriverListHead
;
4904 ListHead
= &devInfo
->DriverListHead
;
4907 ItemList
= ListHead
->Flink
;
4908 while (ItemList
!= ListHead
&& MemberIndex
-- > 0)
4909 ItemList
= ItemList
->Flink
;
4910 if (ItemList
== ListHead
)
4911 SetLastError(ERROR_NO_MORE_ITEMS
);
4914 struct DriverInfoElement
*DrvInfo
= (struct DriverInfoElement
*)ItemList
;
4917 &DriverInfoData
->DriverType
,
4918 &DrvInfo
->Info
.DriverType
,
4919 DriverInfoData
->cbSize
- FIELD_OFFSET(SP_DRVINFO_DATA_W
, DriverType
));
4924 TRACE("Returning %d\n", ret
);
4928 /***********************************************************************
4929 * SetupDiGetSelectedDriverW (SETUPAPI.@)
4932 SetupDiGetSelectedDriverW(
4933 IN HDEVINFO DeviceInfoSet
,
4934 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4935 OUT PSP_DRVINFO_DATA_W DriverInfoData
)
4939 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DriverInfoData
);
4941 if (!DeviceInfoSet
|| !DriverInfoData
)
4942 SetLastError(ERROR_INVALID_PARAMETER
);
4943 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
4944 SetLastError(ERROR_INVALID_HANDLE
);
4945 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
4946 SetLastError(ERROR_INVALID_HANDLE
);
4947 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
4948 SetLastError(ERROR_INVALID_USER_BUFFER
);
4949 else if (DriverInfoData
->cbSize
!= sizeof(SP_DRVINFO_DATA_V1_W
) && DriverInfoData
->cbSize
!= sizeof(SP_DRVINFO_DATA_V2_W
))
4950 SetLastError(ERROR_INVALID_USER_BUFFER
);
4953 SP_DEVINSTALL_PARAMS InstallParams
;
4955 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS
);
4956 if (SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
))
4958 struct DriverInfoElement
*driverInfo
;
4959 driverInfo
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
4960 if (driverInfo
== NULL
)
4961 SetLastError(ERROR_NO_DRIVER_SELECTED
);
4965 &DriverInfoData
->DriverType
,
4966 &driverInfo
->Info
.DriverType
,
4967 DriverInfoData
->cbSize
- FIELD_OFFSET(SP_DRVINFO_DATA_W
, DriverType
));
4973 TRACE("Returning %d\n", ret
);
4978 /***********************************************************************
4979 * SetupDiSetSelectedDriverA (SETUPAPI.@)
4982 SetupDiSetSelectedDriverA(
4983 IN HDEVINFO DeviceInfoSet
,
4984 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
4985 IN OUT PSP_DRVINFO_DATA_A DriverInfoData OPTIONAL
)
4987 SP_DRVINFO_DATA_V1_W DriverInfoDataW
;
4988 PSP_DRVINFO_DATA_W pDriverInfoDataW
= NULL
;
4991 if (DriverInfoData
!= NULL
)
4993 if (DriverInfoData
->cbSize
!= sizeof(SP_DRVINFO_DATA_V2_A
) &&
4994 DriverInfoData
->cbSize
!= sizeof(SP_DRVINFO_DATA_V1_A
));
4996 SetLastError(ERROR_INVALID_PARAMETER
);
5000 DriverInfoDataW
.cbSize
= sizeof(SP_DRVINFO_DATA_V1_W
);
5001 DriverInfoDataW
.Reserved
= DriverInfoData
->Reserved
;
5003 if (DriverInfoDataW
.Reserved
== 0)
5005 DriverInfoDataW
.DriverType
= DriverInfoData
->DriverType
;
5007 /* convert the strings to unicode */
5008 if (!MultiByteToWideChar(CP_ACP
,
5010 DriverInfoData
->Description
,
5012 DriverInfoDataW
.Description
,
5014 !MultiByteToWideChar(CP_ACP
,
5016 DriverInfoData
->ProviderName
,
5018 DriverInfoDataW
.ProviderName
,
5025 pDriverInfoDataW
= (PSP_DRVINFO_DATA_W
)&DriverInfoDataW
;
5028 ret
= SetupDiSetSelectedDriverW(DeviceInfoSet
,
5032 if (ret
&& pDriverInfoDataW
!= NULL
)
5034 DriverInfoData
->Reserved
= DriverInfoDataW
.Reserved
;
5041 /***********************************************************************
5042 * SetupDiSetSelectedDriverW (SETUPAPI.@)
5045 SetupDiSetSelectedDriverW(
5046 IN HDEVINFO DeviceInfoSet
,
5047 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
5048 IN OUT PSP_DRVINFO_DATA_W DriverInfoData OPTIONAL
)
5052 TRACE("%p %p %p\n", DeviceInfoSet
, DeviceInfoData
, DriverInfoData
);
5055 SetLastError(ERROR_INVALID_PARAMETER
);
5056 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
5057 SetLastError(ERROR_INVALID_HANDLE
);
5058 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
5059 SetLastError(ERROR_INVALID_HANDLE
);
5060 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5061 SetLastError(ERROR_INVALID_USER_BUFFER
);
5062 else if (DriverInfoData
&& DriverInfoData
->cbSize
!= sizeof(SP_DRVINFO_DATA_V1_W
) && DriverInfoData
->cbSize
!= sizeof(SP_DRVINFO_DATA_V2_W
))
5063 SetLastError(ERROR_INVALID_USER_BUFFER
);
5066 struct DriverInfoElement
**pDriverInfo
;
5067 PLIST_ENTRY ListHead
, ItemList
;
5071 pDriverInfo
= (struct DriverInfoElement
**)&((struct DeviceInfoElement
*)DeviceInfoData
->Reserved
)->InstallParams
.Reserved
;
5072 ListHead
= &((struct DeviceInfoElement
*)DeviceInfoData
->Reserved
)->DriverListHead
;
5076 pDriverInfo
= (struct DriverInfoElement
**)&((struct DeviceInfoSet
*)DeviceInfoSet
)->InstallParams
.Reserved
;
5077 ListHead
= &((struct DeviceInfoSet
*)DeviceInfoSet
)->DriverListHead
;
5080 if (!DriverInfoData
)
5082 *pDriverInfo
= NULL
;
5087 /* Search selected driver in list */
5088 ItemList
= ListHead
->Flink
;
5089 while (ItemList
!= ListHead
)
5091 if (DriverInfoData
->Reserved
!= 0)
5093 if (DriverInfoData
->Reserved
== (ULONG_PTR
)ItemList
)
5098 /* The caller wants to compare only DriverType, Description and ProviderName fields */
5099 struct DriverInfoElement
*driverInfo
= (struct DriverInfoElement
*)ItemList
;
5100 if (driverInfo
->Info
.DriverType
== DriverInfoData
->DriverType
5101 && wcscmp(driverInfo
->Info
.Description
, DriverInfoData
->Description
) == 0
5102 && wcscmp(driverInfo
->Info
.ProviderName
, DriverInfoData
->ProviderName
) == 0)
5108 if (ItemList
== ListHead
)
5109 SetLastError(ERROR_INVALID_PARAMETER
);
5112 *pDriverInfo
= (struct DriverInfoElement
*)ItemList
;
5113 DriverInfoData
->Reserved
= (ULONG_PTR
)ItemList
;
5115 TRACE("Choosing driver whose rank is 0x%lx\n",
5116 ((struct DriverInfoElement
*)ItemList
)->DriverRank
);
5118 memcpy(&DeviceInfoData
->ClassGuid
, &(*pDriverInfo
)->ClassGuid
, sizeof(GUID
));
5123 TRACE("Returning %d\n", ret
);
5127 /***********************************************************************
5128 * SetupDiGetDriverInfoDetailA (SETUPAPI.@)
5131 SetupDiGetDriverInfoDetailA(
5132 IN HDEVINFO DeviceInfoSet
,
5133 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
5134 IN PSP_DRVINFO_DATA_A DriverInfoData
,
5135 OUT PSP_DRVINFO_DETAIL_DATA_A DriverInfoDetailData OPTIONAL
,
5136 IN DWORD DriverInfoDetailDataSize
,
5137 OUT PDWORD RequiredSize OPTIONAL
)
5139 SP_DRVINFO_DATA_V2_W DriverInfoDataW
;
5140 PSP_DRVINFO_DETAIL_DATA_W DriverInfoDetailDataW
= NULL
;
5142 DWORD HardwareIDLen
= 0;
5145 /* do some sanity checks, the unicode version might do more thorough checks */
5146 if (DriverInfoData
== NULL
||
5147 (DriverInfoDetailData
== NULL
&& DriverInfoDetailDataSize
!= 0) ||
5148 (DriverInfoDetailData
!= NULL
&&
5149 (DriverInfoDetailDataSize
< FIELD_OFFSET(SP_DRVINFO_DETAIL_DATA_A
, HardwareID
) + sizeof(CHAR
) ||
5150 DriverInfoDetailData
->cbSize
!= sizeof(SP_DRVINFO_DETAIL_DATA_A
))))
5152 SetLastError(ERROR_INVALID_PARAMETER
);
5156 /* make sure we support both versions of the SP_DRVINFO_DATA structure */
5157 if (DriverInfoData
->cbSize
== sizeof(SP_DRVINFO_DATA_V1_A
))
5159 DriverInfoDataW
.cbSize
= sizeof(SP_DRVINFO_DATA_V1_W
);
5161 else if (DriverInfoData
->cbSize
== sizeof(SP_DRVINFO_DATA_V2_A
))
5163 DriverInfoDataW
.cbSize
= sizeof(SP_DRVINFO_DATA_V2_W
);
5167 SetLastError(ERROR_INVALID_PARAMETER
);
5170 DriverInfoDataW
.DriverType
= DriverInfoData
->DriverType
;
5171 DriverInfoDataW
.Reserved
= DriverInfoData
->Reserved
;
5173 /* convert the strings to unicode */
5174 if (MultiByteToWideChar(CP_ACP
,
5176 DriverInfoData
->Description
,
5178 DriverInfoDataW
.Description
,
5180 MultiByteToWideChar(CP_ACP
,
5182 DriverInfoData
->MfgName
,
5184 DriverInfoDataW
.MfgName
,
5186 MultiByteToWideChar(CP_ACP
,
5188 DriverInfoData
->ProviderName
,
5190 DriverInfoDataW
.ProviderName
,
5193 if (DriverInfoDataW
.cbSize
== sizeof(SP_DRVINFO_DATA_V2_W
))
5195 DriverInfoDataW
.DriverDate
= ((PSP_DRVINFO_DATA_V2_A
)DriverInfoData
)->DriverDate
;
5196 DriverInfoDataW
.DriverVersion
= ((PSP_DRVINFO_DATA_V2_A
)DriverInfoData
)->DriverVersion
;
5199 if (DriverInfoDetailData
!= NULL
)
5201 /* calculate the unicode buffer size from the ansi buffer size */
5202 HardwareIDLen
= DriverInfoDetailDataSize
- FIELD_OFFSET(SP_DRVINFO_DETAIL_DATA_A
, HardwareID
);
5203 BufSize
= FIELD_OFFSET(SP_DRVINFO_DETAIL_DATA_W
, HardwareID
) +
5204 (HardwareIDLen
* sizeof(WCHAR
));
5206 DriverInfoDetailDataW
= MyMalloc(BufSize
);
5207 if (DriverInfoDetailDataW
== NULL
)
5209 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5213 /* initialize the buffer */
5214 ZeroMemory(DriverInfoDetailDataW
,
5216 DriverInfoDetailDataW
->cbSize
= sizeof(SP_DRVINFO_DETAIL_DATA_W
);
5219 /* call the unicode version */
5220 ret
= SetupDiGetDriverInfoDetailW(DeviceInfoSet
,
5223 DriverInfoDetailDataW
,
5229 if (DriverInfoDetailDataW
!= NULL
)
5231 /* convert the SP_DRVINFO_DETAIL_DATA_W structure to ansi */
5232 DriverInfoDetailData
->cbSize
= sizeof(SP_DRVINFO_DETAIL_DATA_A
);
5233 DriverInfoDetailData
->InfDate
= DriverInfoDetailDataW
->InfDate
;
5234 DriverInfoDetailData
->Reserved
= DriverInfoDetailDataW
->Reserved
;
5235 if (WideCharToMultiByte(CP_ACP
,
5237 DriverInfoDetailDataW
->SectionName
,
5239 DriverInfoDetailData
->SectionName
,
5243 WideCharToMultiByte(CP_ACP
,
5245 DriverInfoDetailDataW
->InfFileName
,
5247 DriverInfoDetailData
->InfFileName
,
5251 WideCharToMultiByte(CP_ACP
,
5253 DriverInfoDetailDataW
->DrvDescription
,
5255 DriverInfoDetailData
->DrvDescription
,
5259 WideCharToMultiByte(CP_ACP
,
5261 DriverInfoDetailDataW
->HardwareID
,
5263 DriverInfoDetailData
->HardwareID
,
5269 DWORD hwidlen
= HardwareIDLen
;
5270 CHAR
*s
= DriverInfoDetailData
->HardwareID
;
5272 /* count the strings in the list */
5275 len
= lstrlenA(s
) + 1;
5284 /* looks like the string list wasn't terminated... */
5285 SetLastError(ERROR_INVALID_USER_BUFFER
);
5291 /* make sure CompatIDsOffset points to the second string in the
5295 DriverInfoDetailData
->CompatIDsOffset
= lstrlenA(DriverInfoDetailData
->HardwareID
) + 1;
5296 DriverInfoDetailData
->CompatIDsLength
= (DWORD
)(s
- DriverInfoDetailData
->HardwareID
) -
5297 DriverInfoDetailData
->CompatIDsOffset
+ 1;
5301 DriverInfoDetailData
->CompatIDsOffset
= 0;
5302 DriverInfoDetailData
->CompatIDsLength
= 0;
5311 if (RequiredSize
!= NULL
)
5313 *RequiredSize
= FIELD_OFFSET(SP_DRVINFO_DETAIL_DATA_A
, HardwareID
) +
5314 (((*RequiredSize
) - FIELD_OFFSET(SP_DRVINFO_DETAIL_DATA_W
, HardwareID
)) / sizeof(WCHAR
));
5320 if (DriverInfoDetailDataW
!= NULL
)
5322 MyFree(DriverInfoDetailDataW
);
5328 /***********************************************************************
5329 * SetupDiGetDriverInfoDetailW (SETUPAPI.@)
5332 SetupDiGetDriverInfoDetailW(
5333 IN HDEVINFO DeviceInfoSet
,
5334 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
5335 IN PSP_DRVINFO_DATA_W DriverInfoData
,
5336 OUT PSP_DRVINFO_DETAIL_DATA_W DriverInfoDetailData OPTIONAL
,
5337 IN DWORD DriverInfoDetailDataSize
,
5338 OUT PDWORD RequiredSize OPTIONAL
)
5343 SetLastError(ERROR_INVALID_PARAMETER
);
5344 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
5345 SetLastError(ERROR_INVALID_HANDLE
);
5346 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
5347 SetLastError(ERROR_INVALID_HANDLE
);
5348 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5349 SetLastError(ERROR_INVALID_USER_BUFFER
);
5350 else if (!DriverInfoData
)
5351 SetLastError(ERROR_INVALID_PARAMETER
);
5352 else if (!DriverInfoDetailData
&& DriverInfoDetailDataSize
!= 0)
5353 SetLastError(ERROR_INVALID_PARAMETER
);
5354 else if (DriverInfoDetailData
&& DriverInfoDetailDataSize
< sizeof(SP_DRVINFO_DETAIL_DATA_W
))
5355 SetLastError(ERROR_INVALID_PARAMETER
);
5356 else if (DriverInfoDetailData
&& DriverInfoDetailData
->cbSize
!= sizeof(SP_DRVINFO_DETAIL_DATA_W
))
5357 SetLastError(ERROR_INVALID_USER_BUFFER
);
5358 else if (DriverInfoDetailData
&& DriverInfoDetailData
->Reserved
== 0)
5359 SetLastError(ERROR_INVALID_PARAMETER
);
5362 struct DriverInfoElement
*driverInfoElement
;
5363 driverInfoElement
= (struct DriverInfoElement
*)DriverInfoData
->Reserved
;
5366 DriverInfoDetailData
,
5367 &driverInfoElement
->Details
,
5368 driverInfoElement
->Details
.cbSize
);
5369 /* FIXME: copy HardwareIDs/CompatibleIDs if buffer is big enough
5370 * Don't forget to set CompatIDsOffset and CompatIDsLength fields.
5375 TRACE("Returning %d\n", ret
);
5379 /***********************************************************************
5380 * SetupDiSelectBestCompatDrv (SETUPAPI.@)
5383 SetupDiSelectBestCompatDrv(
5384 IN HDEVINFO DeviceInfoSet
,
5385 IN PSP_DEVINFO_DATA DeviceInfoData
)
5387 SP_DRVINFO_DATA_W drvInfoData
;
5390 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5392 /* Drivers are sorted by rank in the driver list, so
5393 * the first driver in the list is the best one.
5395 drvInfoData
.cbSize
= sizeof(SP_DRVINFO_DATA_W
);
5396 ret
= SetupDiEnumDriverInfoW(
5400 0, /* Member index */
5405 ret
= SetupDiSetSelectedDriverW(
5411 TRACE("Returning %d\n", ret
);
5415 /***********************************************************************
5416 * SetupDiInstallDriverFiles (SETUPAPI.@)
5419 SetupDiInstallDriverFiles(
5420 IN HDEVINFO DeviceInfoSet
,
5421 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
5425 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5428 SetLastError(ERROR_INVALID_PARAMETER
);
5429 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
5430 SetLastError(ERROR_INVALID_HANDLE
);
5431 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
5432 SetLastError(ERROR_INVALID_HANDLE
);
5433 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5434 SetLastError(ERROR_INVALID_USER_BUFFER
);
5435 else if (DeviceInfoData
&& ((struct DeviceInfoElement
*)DeviceInfoData
->Reserved
)->InstallParams
.Reserved
== 0)
5436 SetLastError(ERROR_NO_DRIVER_SELECTED
);
5437 else if (!DeviceInfoData
&& ((struct DeviceInfoSet
*)DeviceInfoSet
)->InstallParams
.Reserved
== 0)
5438 SetLastError(ERROR_NO_DRIVER_SELECTED
);
5441 SP_DEVINSTALL_PARAMS_W InstallParams
;
5442 struct DriverInfoElement
*SelectedDriver
;
5443 WCHAR SectionName
[MAX_PATH
];
5444 DWORD SectionNameLength
= 0;
5446 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
5447 ret
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5451 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
5452 if (!SelectedDriver
)
5454 SetLastError(ERROR_NO_DRIVER_SELECTED
);
5458 ret
= SetupDiGetActualSectionToInstallW(
5459 SelectedDriver
->InfFileDetails
->hInf
,
5460 SelectedDriver
->Details
.SectionName
,
5461 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
5465 if (!InstallParams
.InstallMsgHandler
)
5467 InstallParams
.InstallMsgHandler
= SetupDefaultQueueCallbackW
;
5468 InstallParams
.InstallMsgHandlerContext
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
5469 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5471 ret
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5472 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5473 SPINST_FILES
, NULL
, NULL
, SP_COPY_NEWER
,
5474 InstallParams
.InstallMsgHandler
, InstallParams
.InstallMsgHandlerContext
,
5475 DeviceInfoSet
, DeviceInfoData
);
5479 TRACE("Returning %d\n", ret
);
5483 /***********************************************************************
5484 * SetupDiRegisterCoDeviceInstallers (SETUPAPI.@)
5487 SetupDiRegisterCoDeviceInstallers(
5488 IN HDEVINFO DeviceInfoSet
,
5489 IN PSP_DEVINFO_DATA DeviceInfoData
)
5491 BOOL ret
= FALSE
; /* Return value */
5493 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5496 SetLastError(ERROR_INVALID_PARAMETER
);
5497 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
5498 SetLastError(ERROR_INVALID_HANDLE
);
5499 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
5500 SetLastError(ERROR_INVALID_HANDLE
);
5501 else if (!DeviceInfoData
)
5502 SetLastError(ERROR_INVALID_PARAMETER
);
5503 else if (DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5504 SetLastError(ERROR_INVALID_USER_BUFFER
);
5507 SP_DEVINSTALL_PARAMS_W InstallParams
;
5508 struct DriverInfoElement
*SelectedDriver
;
5511 WCHAR SectionName
[MAX_PATH
];
5512 DWORD SectionNameLength
= 0;
5513 HKEY hKey
= INVALID_HANDLE_VALUE
;;
5515 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
5516 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5520 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
5521 if (SelectedDriver
== NULL
)
5523 SetLastError(ERROR_NO_DRIVER_SELECTED
);
5527 /* Get .CoInstallers section name */
5528 Result
= SetupDiGetActualSectionToInstallW(
5529 SelectedDriver
->InfFileDetails
->hInf
,
5530 SelectedDriver
->Details
.SectionName
,
5531 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
5532 if (!Result
|| SectionNameLength
> MAX_PATH
- wcslen(L
".CoInstallers") - 1)
5534 wcscat(SectionName
, L
".CoInstallers");
5536 /* Open/Create driver key information */
5537 #if _WIN32_WINNT >= 0x502
5538 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_READ
| KEY_WRITE
);
5540 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_ALL_ACCESS
);
5542 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5543 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, NULL
, NULL
);
5544 if (hKey
== INVALID_HANDLE_VALUE
)
5547 /* Install .CoInstallers section */
5548 DoAction
= SPINST_REGISTRY
;
5549 if (!(InstallParams
.Flags
& DI_NOFILECOPY
))
5551 DoAction
|= SPINST_FILES
;
5552 if (!InstallParams
.InstallMsgHandler
)
5554 InstallParams
.InstallMsgHandler
= SetupDefaultQueueCallbackW
;
5555 InstallParams
.InstallMsgHandlerContext
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
5556 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5559 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5560 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5561 DoAction
, hKey
, NULL
, SP_COPY_NEWER
,
5562 InstallParams
.InstallMsgHandler
, InstallParams
.InstallMsgHandlerContext
,
5563 DeviceInfoSet
, DeviceInfoData
);
5570 if (hKey
!= INVALID_HANDLE_VALUE
)
5574 TRACE("Returning %d\n", ret
);
5578 /***********************************************************************
5579 * SetupDiInstallDeviceInterfaces (SETUPAPI.@)
5582 SetupDiInstallDeviceInterfaces(
5583 IN HDEVINFO DeviceInfoSet
,
5584 IN PSP_DEVINFO_DATA DeviceInfoData
)
5586 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5588 FIXME("SetupDiInstallDeviceInterfaces not implemented. Doing nothing\n");
5589 //SetLastError(ERROR_GEN_FAILURE);
5594 /***********************************************************************
5595 * SetupDiInstallDevice (SETUPAPI.@)
5598 SetupDiInstallDevice(
5599 IN HDEVINFO DeviceInfoSet
,
5600 IN PSP_DEVINFO_DATA DeviceInfoData
)
5602 struct DeviceInfoElement
*DevInfo
= (struct DeviceInfoElement
*)DeviceInfoData
->Reserved
;
5603 SP_DEVINSTALL_PARAMS_W InstallParams
;
5604 struct DriverInfoElement
*SelectedDriver
;
5605 SYSTEMTIME DriverDate
;
5606 WCHAR SectionName
[MAX_PATH
];
5608 DWORD SectionNameLength
= 0;
5609 BOOL Result
= FALSE
;
5610 INFCONTEXT ContextService
;
5614 LPCWSTR AssociatedService
= NULL
;
5615 LPWSTR pSectionName
= NULL
;
5616 WCHAR ClassName
[MAX_CLASS_NAME_LEN
];
5618 LPWSTR lpGuidString
= NULL
, lpFullGuidString
= NULL
;
5619 BOOL RebootRequired
= FALSE
;
5620 HKEY hKey
= INVALID_HANDLE_VALUE
;
5621 HKEY hClassKey
= INVALID_HANDLE_VALUE
;
5623 BOOL ret
= FALSE
; /* Return value */
5625 TRACE("%p %p\n", DeviceInfoSet
, DeviceInfoData
);
5628 SetLastError(ERROR_INVALID_PARAMETER
);
5629 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
5630 SetLastError(ERROR_INVALID_HANDLE
);
5631 else if (((struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
5632 SetLastError(ERROR_INVALID_HANDLE
);
5633 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
5634 SetLastError(ERROR_INVALID_USER_BUFFER
);
5640 /* One parameter is bad */
5644 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
5645 Result
= SetupDiGetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5649 if (InstallParams
.FlagsEx
& DI_FLAGSEX_SETFAILEDINSTALL
)
5651 /* FIXME: set FAILEDINSTALL in ConfigFlags registry value */
5655 SelectedDriver
= (struct DriverInfoElement
*)InstallParams
.Reserved
;
5656 if (SelectedDriver
== NULL
)
5658 SetLastError(ERROR_NO_DRIVER_SELECTED
);
5662 FileTimeToSystemTime(&SelectedDriver
->Info
.DriverDate
, &DriverDate
);
5664 Result
= SetupDiGetActualSectionToInstallW(
5665 SelectedDriver
->InfFileDetails
->hInf
,
5666 SelectedDriver
->Details
.SectionName
,
5667 SectionName
, MAX_PATH
, &SectionNameLength
, NULL
);
5668 if (!Result
|| SectionNameLength
> MAX_PATH
- 9)
5670 pSectionName
= &SectionName
[wcslen(SectionName
)];
5672 /* Get information from [Version] section */
5673 if (!SetupDiGetINFClassW(SelectedDriver
->Details
.InfFileName
, &ClassGuid
, ClassName
, MAX_CLASS_NAME_LEN
, &RequiredSize
))
5675 /* Format ClassGuid to a string */
5676 if (UuidToStringW((UUID
*)&ClassGuid
, &lpGuidString
) != RPC_S_OK
)
5678 RequiredSize
= lstrlenW(lpGuidString
);
5679 lpFullGuidString
= HeapAlloc(GetProcessHeap(), 0, (RequiredSize
+ 3) * sizeof(WCHAR
));
5680 if (!lpFullGuidString
)
5682 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5685 lpFullGuidString
[0] = '{';
5686 memcpy(&lpFullGuidString
[1], lpGuidString
, RequiredSize
* sizeof(WCHAR
));
5687 lpFullGuidString
[RequiredSize
+ 1] = '}';
5688 lpFullGuidString
[RequiredSize
+ 2] = '\0';
5690 /* Open/Create driver key information */
5691 #if _WIN32_WINNT >= 0x502
5692 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_READ
| KEY_WRITE
);
5694 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, KEY_ALL_ACCESS
);
5696 if (hKey
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
5697 hKey
= SetupDiCreateDevRegKeyW(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DRV
, NULL
, NULL
);
5698 if (hKey
== INVALID_HANDLE_VALUE
)
5701 /* Install main section */
5702 DoAction
= SPINST_REGISTRY
;
5703 if (!(InstallParams
.Flags
& DI_NOFILECOPY
))
5705 DoAction
|= SPINST_FILES
;
5706 if (!InstallParams
.InstallMsgHandler
)
5708 InstallParams
.InstallMsgHandler
= SetupDefaultQueueCallbackW
;
5709 InstallParams
.InstallMsgHandlerContext
= SetupInitDefaultQueueCallback(InstallParams
.hwndParent
);
5710 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5713 *pSectionName
= '\0';
5714 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5715 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5716 DoAction
, hKey
, NULL
, SP_COPY_NEWER
,
5717 InstallParams
.InstallMsgHandler
, InstallParams
.InstallMsgHandlerContext
,
5718 DeviceInfoSet
, DeviceInfoData
);
5721 if (!(InstallParams
.Flags
& DI_NOFILECOPY
) && !(InstallParams
.Flags
& DI_NOVCP
))
5723 if (Result
&& InstallParams
.InstallMsgHandler
== SetupDefaultQueueCallbackW
)
5725 /* Delete resources allocated by SetupInitDefaultQueueCallback */
5726 SetupTermDefaultQueueCallback(InstallParams
.InstallMsgHandlerContext
);
5729 InstallParams
.Flags
|= DI_NOFILECOPY
;
5730 SetupDiSetDeviceInstallParamsW(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
5732 /* Write information to driver key */
5733 *pSectionName
= UNICODE_NULL
;
5734 TRACE("Write information to driver key\n");
5735 TRACE("DriverDate : '%u-%u-%u'\n", DriverDate
.wMonth
, DriverDate
.wDay
, DriverDate
.wYear
);
5736 TRACE("DriverDesc : '%S'\n", SelectedDriver
->Info
.Description
);
5737 TRACE("DriverVersion : '%u.%u.%u.%u'\n", SelectedDriver
->Info
.DriverVersion
& 0xff, (SelectedDriver
->Info
.DriverVersion
>> 8) & 0xff, (SelectedDriver
->Info
.DriverVersion
>> 16) & 0xff, (SelectedDriver
->Info
.DriverVersion
>> 24) & 0xff);
5738 TRACE("InfPath : '%S'\n", SelectedDriver
->Details
.InfFileName
);
5739 TRACE("InfSection : '%S'\n", SelectedDriver
->Details
.SectionName
);
5740 TRACE("InfSectionExt : '%S'\n", &SectionName
[wcslen(SelectedDriver
->Details
.SectionName
)]);
5741 TRACE("MatchingDeviceId: '%S'\n", SelectedDriver
->MatchingId
);
5742 TRACE("ProviderName : '%S'\n", SelectedDriver
->Info
.ProviderName
);
5743 swprintf(Buffer
, L
"%u-%u-%u", DriverDate
.wMonth
, DriverDate
.wDay
, DriverDate
.wYear
);
5744 rc
= RegSetValueEx(hKey
, L
"DriverDate", 0, REG_SZ
, (const BYTE
*)Buffer
, (wcslen(Buffer
) + 1) * sizeof(WCHAR
));
5745 if (rc
== ERROR_SUCCESS
)
5746 rc
= RegSetValueEx(hKey
, L
"DriverDateData", 0, REG_BINARY
, (const BYTE
*)&SelectedDriver
->Info
.DriverDate
, sizeof(FILETIME
));
5747 if (rc
== ERROR_SUCCESS
)
5748 rc
= RegSetValueEx(hKey
, L
"DriverDesc", 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.Description
, (wcslen(SelectedDriver
->Info
.Description
) + 1) * sizeof(WCHAR
));
5749 if (rc
== ERROR_SUCCESS
)
5751 swprintf(Buffer
, L
"%u.%u.%u.%u", SelectedDriver
->Info
.DriverVersion
& 0xff, (SelectedDriver
->Info
.DriverVersion
>> 8) & 0xff, (SelectedDriver
->Info
.DriverVersion
>> 16) & 0xff, (SelectedDriver
->Info
.DriverVersion
>> 24) & 0xff);
5752 rc
= RegSetValueEx(hKey
, L
"DriverVersion", 0, REG_SZ
, (const BYTE
*)Buffer
, (wcslen(Buffer
) + 1) * sizeof(WCHAR
));
5754 if (rc
== ERROR_SUCCESS
)
5755 rc
= RegSetValueEx(hKey
, L
"InfPath", 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Details
.InfFileName
, (wcslen(SelectedDriver
->Details
.InfFileName
) + 1) * sizeof(WCHAR
));
5756 if (rc
== ERROR_SUCCESS
)
5757 rc
= RegSetValueEx(hKey
, L
"InfSection", 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Details
.SectionName
, (wcslen(SelectedDriver
->Details
.SectionName
) + 1) * sizeof(WCHAR
));
5758 if (rc
== ERROR_SUCCESS
)
5759 rc
= RegSetValueEx(hKey
, L
"InfSectionExt", 0, REG_SZ
, (const BYTE
*)&SectionName
[wcslen(SelectedDriver
->Details
.SectionName
)], (wcslen(SectionName
) - wcslen(SelectedDriver
->Details
.SectionName
) + 1) * sizeof(WCHAR
));
5760 if (rc
== ERROR_SUCCESS
)
5761 rc
= RegSetValueEx(hKey
, L
"MatchingDeviceId", 0, REG_SZ
, (const BYTE
*)SelectedDriver
->MatchingId
, (wcslen(SelectedDriver
->MatchingId
) + 1) * sizeof(WCHAR
));
5762 if (rc
== ERROR_SUCCESS
)
5763 rc
= RegSetValueEx(hKey
, L
"ProviderName", 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.ProviderName
, (wcslen(SelectedDriver
->Info
.ProviderName
) + 1) * sizeof(WCHAR
));
5764 if (rc
!= ERROR_SUCCESS
)
5770 hKey
= INVALID_HANDLE_VALUE
;
5772 /* FIXME: Process .LogConfigOverride section */
5774 /* Install .Services section */
5775 wcscpy(pSectionName
, L
".Services");
5776 Result
= SetupFindFirstLineW(SelectedDriver
->InfFileDetails
->hInf
, SectionName
, NULL
, &ContextService
);
5779 LPWSTR ServiceName
= NULL
;
5780 LPWSTR ServiceSection
= NULL
;
5782 Result
= SetupGetStringFieldW(
5784 1, /* Field index */
5789 if (RequiredSize
> 0)
5791 /* We got the needed size for the buffer */
5792 ServiceName
= HeapAlloc(GetProcessHeap(), 0, RequiredSize
* sizeof(WCHAR
));
5795 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5798 Result
= SetupGetStringFieldW(
5800 1, /* Field index */
5801 ServiceName
, RequiredSize
,
5806 Result
= SetupGetIntField(
5808 2, /* Field index */
5812 /* The field may be empty. Ignore the error */
5815 Result
= SetupGetStringFieldW(
5817 3, /* Field index */
5822 if (RequiredSize
> 0)
5824 /* We got the needed size for the buffer */
5825 ServiceSection
= HeapAlloc(GetProcessHeap(), 0, RequiredSize
* sizeof(WCHAR
));
5826 if (!ServiceSection
)
5828 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5831 Result
= SetupGetStringFieldW(
5833 3, /* Field index */
5834 ServiceSection
, RequiredSize
,
5839 SetLastError(ERROR_SUCCESS
);
5840 Result
= SetupInstallServicesFromInfSectionExW(
5841 SelectedDriver
->InfFileDetails
->hInf
,
5842 ServiceSection
, Flags
, DeviceInfoSet
, DeviceInfoData
, ServiceName
, NULL
);
5843 if (Result
&& (Flags
& SPSVCINST_ASSOCSERVICE
))
5845 AssociatedService
= ServiceName
;
5847 if (GetLastError() == ERROR_SUCCESS_REBOOT_REQUIRED
)
5848 RebootRequired
= TRUE
;
5851 HeapFree(GetProcessHeap(), 0, ServiceName
);
5852 HeapFree(GetProcessHeap(), 0, ServiceSection
);
5855 Result
= SetupFindNextLine(&ContextService
, &ContextService
);
5858 /* Copy .inf file to Inf\ directory */
5859 FIXME("FIXME: Copy .inf file to Inf\\ directory\n"); /* SetupCopyOEMInf */
5861 /* Open device registry key */
5862 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
, DeviceInfoData
, DICS_FLAG_GLOBAL
, 0, DIREG_DEV
, KEY_SET_VALUE
);
5863 if (hKey
== INVALID_HANDLE_VALUE
)
5866 /* Install .HW section */
5867 wcscpy(pSectionName
, L
".HW");
5868 Result
= SetupInstallFromInfSectionW(InstallParams
.hwndParent
,
5869 SelectedDriver
->InfFileDetails
->hInf
, SectionName
,
5870 SPINST_REGISTRY
, hKey
, NULL
, 0,
5871 InstallParams
.InstallMsgHandler
, InstallParams
.InstallMsgHandlerContext
,
5872 DeviceInfoSet
, DeviceInfoData
);
5876 /* Write information to enum key */
5877 TRACE("Write information to enum key\n");
5878 TRACE("Service : '%S'\n", AssociatedService
);
5879 TRACE("Class : '%S'\n", ClassName
);
5880 TRACE("ClassGUID : '%S'\n", lpFullGuidString
);
5881 TRACE("DeviceDesc : '%S'\n", SelectedDriver
->Info
.Description
);
5882 TRACE("Mfg : '%S'\n", SelectedDriver
->Info
.MfgName
);
5883 rc
= RegSetValueEx(hKey
, L
"Service", 0, REG_SZ
, (const BYTE
*)AssociatedService
, (wcslen(AssociatedService
) + 1) * sizeof(WCHAR
));
5884 if (rc
== ERROR_SUCCESS
)
5885 rc
= RegSetValueEx(hKey
, L
"Class", 0, REG_SZ
, (const BYTE
*)ClassName
, (wcslen(ClassName
) + 1) * sizeof(WCHAR
));
5886 if (rc
== ERROR_SUCCESS
)
5887 rc
= RegSetValueEx(hKey
, L
"ClassGUID", 0, REG_SZ
, (const BYTE
*)lpFullGuidString
, (wcslen(lpFullGuidString
) + 1) * sizeof(WCHAR
));
5888 if (rc
== ERROR_SUCCESS
)
5889 rc
= RegSetValueEx(hKey
, L
"DeviceDesc", 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.Description
, (wcslen(SelectedDriver
->Info
.Description
) + 1) * sizeof(WCHAR
));
5890 if (rc
== ERROR_SUCCESS
)
5891 rc
= RegSetValueEx(hKey
, L
"Mfg", 0, REG_SZ
, (const BYTE
*)SelectedDriver
->Info
.MfgName
, (wcslen(SelectedDriver
->Info
.MfgName
) + 1) * sizeof(WCHAR
));
5892 if (rc
!= ERROR_SUCCESS
)
5898 /* Start the device */
5899 if (!RebootRequired
&& !(InstallParams
.Flags
& (DI_NEEDRESTART
| DI_NEEDREBOOT
| DI_DONOTCALLCONFIGMG
)))
5901 PLUGPLAY_CONTROL_RESET_DEVICE_DATA ResetDeviceData
;
5903 RtlInitUnicodeString(&ResetDeviceData
.DeviceInstance
, DevInfo
->DeviceName
);
5904 Status
= NtPlugPlayControl(PlugPlayControlResetDevice
, &ResetDeviceData
, sizeof(PLUGPLAY_CONTROL_RESET_DEVICE_DATA
));
5905 ret
= NT_SUCCESS(Status
);
5911 /* End of installation */
5912 if (hClassKey
!= INVALID_HANDLE_VALUE
)
5913 RegCloseKey(hClassKey
);
5914 if (hKey
!= INVALID_HANDLE_VALUE
)
5917 RpcStringFreeW(&lpGuidString
);
5918 HeapFree(GetProcessHeap(), 0, (LPWSTR
)AssociatedService
);
5919 HeapFree(GetProcessHeap(), 0, lpFullGuidString
);
5921 TRACE("Returning %d\n", ret
);