Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The SetupDiGetClassDevs function returns a handle to a device information set that contains requested device information elements for a local computer.
WINSETUPAPI HDEVINFO SetupDiGetClassDevsA(
const GUID *ClassGuid,
PCSTR Enumerator,
HWND hwndParent,
DWORD Flags
);
ClassGuid
A pointer to the GUID for a device setup class or a device interface class. This pointer is optional and can be NULL. For more information about how to set ClassGuid, see the following Remarks section.
Enumerator
A pointer to a NULL-terminated string that specifies:
For more information about how to set the Enumerator value, see the following Remarks section.
hwndParent
A handle to the top-level window to be used for a user interface that is associated with installing a device instance in the device information set. This handle is optional and can be NULL.
Flags
A variable of type DWORD that specifies control options that filter the device information elements that are added to the device information set. This parameter can be a bitwise OR of zero or more of the following flags. For more information about combining these flags, see the following Remarks section.
Return a list of installed devices for all device setup classes or all device interface classes.
Return devices that support device interfaces for the specified device interface classes. This flag must be set in the Flags parameter if the Enumerator parameter specifies a device instance ID.
Return only the device that is associated with the system default device interface, if one is set, for the specified device interface classes.
Return only devices that are currently present in a system.
Return only devices that are a part of the current hardware profile.
If the operation succeeds, SetupDiGetClassDevs returns a handle to a device information set that contains all installed devices that matched the supplied parameters. If the operation fails, the function returns INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
The caller of SetupDiGetClassDevs must delete the returned device information set when it is no longer needed by calling SetupDiDestroyDeviceInfoList.
Call SetupDiGetClassDevsEx to retrieve the devices for a class on a remote computer.
Use the following filtering options to control whether SetupDiGetClassDevs returns devices for all device setup classes or only for a specified device setup class:The following are some examples of how to use the SetupDiGetClassDevs function.
Example 1: Build a list of all devices in the system, including devices that are not currently present.
Handle = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES);
Example 2: Build a list of all devices that are present in the system.
Handle = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
Example 3: Build a list of all devices that are present in the system that are from the network adapter device setup class.
Handle = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT);
Example 4: Build a list of all devices that are present in the system that have enabled an interface from the storage volume device interface class.
Handle = SetupDiGetClassDevs(&GUID_DEVINTERFACE_VOLUME, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
Example 5: Build a list of all devices that are present in the system but do not belong to any known device setup class (Windows Vista and later versions of Windows).
DeviceInfoSet = SetupDiGetClassDevs(
NULL,
NULL,
NULL,
DIGCF_ALLCLASSES | DIGCF_PRESENT);
ZeroMemory(&DeviceInfoData, sizeof(SP_DEVINFO_DATA));
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
DeviceIndex = 0;
while (SetupDiEnumDeviceInfo(
DeviceInfoSet,
DeviceIndex,
&DeviceInfoData)) {
DeviceIndex++;
if (!SetupDiGetDeviceProperty(
DeviceInfoSet,
&DeviceInfoData,
&DEVPKEY_Device_Class,
&PropType,
(PBYTE)&DevGuid,
sizeof(GUID),
&Size,
0) || PropType != DEVPROP_TYPE_GUID) {
Error = GetLastError();
if (Error == ERROR_NOT_FOUND) {
\\
\\ This device has an unknown device setup class.
\\
}
}
}
if (DeviceInfoSet) {
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
}
Note
The setupapi.h header defines SetupDiGetClassDevs as an alias that automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that is not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
Requirement | Value |
---|---|
Minimum supported client | Available in Microsoft Windows 2000 and later versions of Windows. |
Target Platform | DesktopFor universal, call CM_Get_Device_ID_ListFor universal, call CM_Get_Device_Interface_List |
Header | setupapi.h (include SetupAPI.h) |
Library | SetupAPI.lib |
DLL | SetupAPI.dll |
API set | ext-ms-win-setupapi-classinstallers-l1-1-2 (introduced in Windows 10, version 10.0.14393) |
Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!