See the question and my original answer on StackOverflow

You can get a lot of information using the Unified Device Property Model available in Vista and higher. It has the DEVPKEY_Device_Class and DEVPKEY_Device_ClassGuid properties:

HDEVINFO list = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT | DIGCF_ALLCLASSES /*| DIGCF_PROFILE*/);
for (int i = 0; true; ++i)
{
  SP_DEVINFO_DATA data = { 0 };
  data.cbSize = sizeof(SP_DEVINFO_DATA);
  if (!SetupDiEnumDeviceInfo(list, i, &data))
    break;

  // get name property
  DEVPROPTYPE type;
  DWORD size = 0;
  SetupDiGetDeviceProperty(list, &data, &DEVPKEY_NAME, &type, NULL, 0, &size, 0);
  if (size > 0)
  {
    LPWSTR name = (LPWSTR)malloc(size);
    SetupDiGetDeviceProperty(list, &data, &DEVPKEY_NAME, &type, (PBYTE)name, size, &size, 0);
    wprintf(L"name: %s\n", name);
    free(name);
  }

  // get class name
  SetupDiGetDeviceProperty(list, &data, &DEVPKEY_Device_Class, &type, NULL, 0, &size, 0);
  if (size > 0)
  {
    LPWSTR name = (LPWSTR)malloc(size);
    SetupDiGetDeviceProperty(list, &data, &DEVPKEY_Device_Class, &type, (PBYTE)name, size, &size, 0);
    wprintf(L" class: %s\n", name);
    free(name);
  }

  // get class guid
  SetupDiGetDeviceProperty(list, &data, &DEVPKEY_Device_ClassGuid, &type, NULL, 0, &size, 0);
  if (size > 0)
  {
    GUID* guid = (GUID*)malloc(size);
    SetupDiGetDeviceProperty(list, &data, &DEVPKEY_Device_ClassGuid, &type, (PBYTE)guid, size, &size, 0);
    wchar_t name[64];
    StringFromGUID2(*guid, (LPOLESTR)name, ARRAYSIZE(name));
    wprintf(L" class guid: %s\n", name);
    free(guid);
  }
}
SetupDiDestroyDeviceInfoList(list);

This will output something like this:

name: ACPI Fan                                      
 class: System                                      
 class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318} 
name: ACPI Fan                                      
 class: System                                      
 class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318} 
name: ACPI Fan                                      
 class: System                                      
 class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318} 
name: ACPI Fan                                      
 class: System                                      
 class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318} 
name: ACPI Fan                                      
 class: System                                      
 class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318} 
name: Microsoft Hyper-V Virtual Machine Bus Provider
 class: System                                      
 class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318} 
name: Plug and Play Software Device Enumerator      
 class: System                                      
 class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318} 
etc...