Tech Support > Microsoft Windows > Drivers > SetupDiEnumDeviceInterfaces is failing
SetupDiEnumDeviceInterfaces is failing
Posted by Gaurav Patney on January 16th, 2005


Hi,
I am trying to find find information for hard disk , for that i have to call
win32 CreateFile, so i am trying to call SetupDiEnumDeviceInterfaces so
that after that i can call SetupDiGetDeviceInterfaceDetail to get detailed
path of the device.

The call to SetupDiEnumDeviceInterfaces keeps failing consistently and
GetLastError() keeps returning ERROR_NO_MORE_ITEMS. If someone know of a
problem in the code then please let me know. I have a hard disk on machine .
The call to SetupDiGetClassDevs() succeeds and i can find the name of the
disk by calling SetupDiGetDeviceRegistryProperty(). I have to find size of
disk and relate it to disk name and thats why i need to call CreateFile().

I had used another approach ( without SetUpDi.. functions) for finding disk
size and disk name but that failed when application ran on a machine with
RAID .

I am using win32 SDK.

Thanks,
gaurav



HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;

// Create a HDEVINFO .
hDevInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_DISKDRIVE,
0, // Enumerator
0,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);

if (hDevInfo == INVALID_HANDLE_VALUE)
{
// Insert error handling here.
return 1;
}

SP_DEVICE_INTERFACE_DATA interfacedata;
DWORD requiredSize;
int status = 1;

// Enumerate through all devices in Set.

for(int ia = 0; status; ia++)
{
interfacedata.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);

status = SetupDiEnumDeviceInterfaces(
hDevInfo,
0,
&GUID_DEVCLASS_DISKDRIVE,
ia,
&interfacedata);

if(status == FALSE)
{

DWORD lastError = ::GetLastError();

if(ERROR_NO_MORE_ITEMS == lastError)
{
// do some error processing here
}
}
}



Similar Posts