To obtain the list of hardware devices installed in Windows 2000 Program Yes
Setupdi Class API functions.
BelowCodeSection shows how to display the list of all installed hardware devices:
# Include <stdio. h>
# Include <windows. h>
# Include <setupapi. h>
# Include <devguid. h>
# Include <regstr. h>
# Pragma comment (Lib, "setupapi. lib ")
Int main (INT argc, char * argv [], char * envp [])
{
Hdevinfo;
Sp_devinfo_data deviceinfodata;
Dword I;
// Create a hdevinfo with all present devices.
Hdevinfo = setupdigetclassdevs (null,
0, // enumerator
0,
Digcf_present | digcf_allclasses );
If (hdevinfo = invalid_handle_value)
{
// Insert error handling here.
Return 1;
}
// Enumerate through all devices in set.
Deviceinfodata. cbsize = sizeof (sp_devinfo_data );
For (I = 0; setupdienumdeviceinfo (hdevinfo, I,
& Deviceinfodata); I ++)
{
DWORD datat;
Lptstr buffer = NULL;
DWORD buffersize = 0;
//
// Call function with null to begin,
// Then use the returned buffer size
// To alloc the buffer. keep calling
// Success or an unknown failure.
//
While (! Setupdigetdeviceregistryproperty (
Hdevinfo,
& Deviceinfodata,
Spdrp_devicedesc,
& Datat,
(Pbyte) buffer,
Buffersize,
& Buffersize ))
{
If (getlasterror () =
Error_insufficient_buffer)
{
// Change the buffer size.
If (buffer) localfree (buffer );
Buffer = (lptstr) localalloc (lptr, buffersize );
}
Else
{
// Insert error handling here.
Break;
}
}
Printf ("Result: [% s] \ n", buffer );
If (buffer) localfree (buffer );
}
If (getlasterror ()! = No_error &&
Getlasterror ()! = Error_no_more_items)
{
// Insert error handling here.
Return 1;
}
// Cleanup
Setupdidestroydeviceinfolist (hdevinfo );
Return 0;
}
The following code snippet shows how to retrieve all display adapter groups on the system: hdevinfo = setupdigetclassdevs (
(Lpguid) & guid_devclass_display,
0,
0,
Digcf_present );
The following code snippet shows how to retrieve all device groups on the Peripheral Component Interconnect (PCI) Bus: hdevinfo = setupdigetclassdevs (null,
Regstr_key_pcienum, // enumerator
0,
Digcf_present | digcf_allclasses );