Main part of the implementation:
#include
#include
#include
#pragma comment (Lib, "Setupapi.lib")
Clistbox m_strlist;
........
Enumerate the main implementation code of all hardware devices:
m_strlist.resetcontent ();
HDEVINFO HDEVINFO;
Sp_devinfo_data deficeinfodata;
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;
}
// Enumerate Through all defices 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 with,
// use the return buffer size
// TO Alloc the buffer. Keep Calling Until
// 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 = (char *) Localalloc (LPTR, BUFFERSIZE);
}
Else
{
// INSERT Error Handling Here.
Break;
}
}
m_strlist.addstring (buffer);
IF (Buffer) Localfree (buffer);
}
IF (getLastError ()! = no_error &&
GetLastError ()! = Error_no_more_items)
{
// INSERT Error Handling Here.
Return;
}
// cleanup
SetupdideStroyDeviceInfolist (HDevinfo);