M
Max Yaffe
Dear Group:
I'm trying to enumerate a list of all devices belonging to a given
class and for each device, enumerate a list of all interfaces
associated with that device.
I've poured over the SetupDIxxx documentation & am now thoroughly
confused. Here's a sample of the code I've tried:
GUID ClassGuid = CLASS_GUID;
GUID InterfaceGuid1 = INTERFACE_GUID_1;
GUID InterfaceGuid2 = INTERFACE_GUID_2;
DWORD DeviceListLoad()
{
HDEVINFO hDeviceInfoSet;
DWORD DeviceEnum;
DWORD InterfaceEnum;
LPDEVICE lpDevice;
DWORD LastError;
// Get a list of all devices which have CMS Version 5.0 GUID
hDeviceInfoSet = SetupDiGetClassDevs(
&ClassGuid,
NULL, // no enumerator
NULL, // Define no UI window
DIGCF_PRESENT // Only Devices present
);
for (DeviceEnum=0;;DeviceEnum++)
{
SP_DEVINFO_DATA DeviceInfoData;
ZeroMemory(&DeviceInfoData, sizeof(SP_DEVINFO_DATA));
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
// Get the DeviceInfoData
if (FALSE == SetupDiEnumDeviceInfo(
hDeviceInfoSet,
DevEnum,
&DeviceInfoData))
{
LastError = GetLastError();
if (ERROR_NO_MORE_ITEMS = LastError)
// At the end of the device set
break;
else
// A real error happened
return LastError;
}
for (InterfaceEnum = 0; ; InterfaceEnum++)
{
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
ZeroMemory(&DeviceInterfaceData,
sizeof(SP_DEVICE_INTERFACE_DATA));
DeviceInterfaceData.cbSize =
sizeof(SP_DEVICE_INTERFACE_DATA);
// Get an interface
if (FALSE == SetupDiEnumDeviceInterfaces(
hDeviceInfoSet,
lpDeviceInfoData,
==>> &Guid, //IN WHAT GOES HERE???
InterfaceEnum,
&DeviceInterfaceData))
{
LastError = GetLastError();
if (ERROR_NO_MORE_ITEMS = LastError)
// At the end of the list
break;
else
// A real error happened.
return LastError;
}
//
// OK We found a device of our class
// which containes an InterfaceGuid.
if (DeviceInterfaceData.InterfaceClassGuid ==
InterfaceGuid1)
DoSomethingToDevice(...);
else if (DeviceInterfaceData.InterfaceClassGuid ==
InterfaceGuid2)
DoSomethingDifferentToDevice(...);
else
DontDoAnything();
}
}
SetupDiDestroyDeviceInfoList(hDeviceInfoSet);
return ERROR_SUCCESS;
}
OK so this can't work since I'm looking for an interface GUID & can't
supply one.
So how can I get a list of interfaces belonging to a device of a given
class?
Thanks for your help in advance
Max
I'm trying to enumerate a list of all devices belonging to a given
class and for each device, enumerate a list of all interfaces
associated with that device.
I've poured over the SetupDIxxx documentation & am now thoroughly
confused. Here's a sample of the code I've tried:
GUID ClassGuid = CLASS_GUID;
GUID InterfaceGuid1 = INTERFACE_GUID_1;
GUID InterfaceGuid2 = INTERFACE_GUID_2;
DWORD DeviceListLoad()
{
HDEVINFO hDeviceInfoSet;
DWORD DeviceEnum;
DWORD InterfaceEnum;
LPDEVICE lpDevice;
DWORD LastError;
// Get a list of all devices which have CMS Version 5.0 GUID
hDeviceInfoSet = SetupDiGetClassDevs(
&ClassGuid,
NULL, // no enumerator
NULL, // Define no UI window
DIGCF_PRESENT // Only Devices present
);
for (DeviceEnum=0;;DeviceEnum++)
{
SP_DEVINFO_DATA DeviceInfoData;
ZeroMemory(&DeviceInfoData, sizeof(SP_DEVINFO_DATA));
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
// Get the DeviceInfoData
if (FALSE == SetupDiEnumDeviceInfo(
hDeviceInfoSet,
DevEnum,
&DeviceInfoData))
{
LastError = GetLastError();
if (ERROR_NO_MORE_ITEMS = LastError)
// At the end of the device set
break;
else
// A real error happened
return LastError;
}
for (InterfaceEnum = 0; ; InterfaceEnum++)
{
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
ZeroMemory(&DeviceInterfaceData,
sizeof(SP_DEVICE_INTERFACE_DATA));
DeviceInterfaceData.cbSize =
sizeof(SP_DEVICE_INTERFACE_DATA);
// Get an interface
if (FALSE == SetupDiEnumDeviceInterfaces(
hDeviceInfoSet,
lpDeviceInfoData,
==>> &Guid, //IN WHAT GOES HERE???
InterfaceEnum,
&DeviceInterfaceData))
{
LastError = GetLastError();
if (ERROR_NO_MORE_ITEMS = LastError)
// At the end of the list
break;
else
// A real error happened.
return LastError;
}
//
// OK We found a device of our class
// which containes an InterfaceGuid.
if (DeviceInterfaceData.InterfaceClassGuid ==
InterfaceGuid1)
DoSomethingToDevice(...);
else if (DeviceInterfaceData.InterfaceClassGuid ==
InterfaceGuid2)
DoSomethingDifferentToDevice(...);
else
DontDoAnything();
}
}
SetupDiDestroyDeviceInfoList(hDeviceInfoSet);
return ERROR_SUCCESS;
}
OK so this can't work since I'm looking for an interface GUID & can't
supply one.
So how can I get a list of interfaces belonging to a device of a given
class?
Thanks for your help in advance
Max