|
-
March 9th, 2005, 05:38 PM
#1
SetupDiEnumDeviceInterfaces()
Hello,
I have a problem with SetupDiEnumDeviceInterfaces(). It returns FALSE and GetLastError() returns ERROR_NO_MORE_ITEMS. It never returns TRUE meaning it thinks there's no devices attached to the USB port. I have a USB device connected. Device manager says it's set up correctly. I'm passing the ClassGuid for the USB device class.
I'm wondering if anyone knows why it never returns TRUE?
Thanks.
Here's the code:
#include "stdafx.h"
#include "windows.h"
#include "Setupapi.h"
#include "stdio.h"
struct __declspec(uuid("36FC9E60-C465-11CF-8056-444553540000")) uuidUsbDevClass
{
};
int main(int argc, char* argv[])
{
char szTraceBuf[256];
GUID guidUsbDevClass = __uuidof(uuidUsbDevClass);
// Get device interface info set handle for all devices attached to system
HDEVINFO hDevInfo = SetupDiGetClassDevs(
&guidUsbDevClass, /* CONST GUID * ClassGuid - USB class GUID */
NULL, /* PCTSTR Enumerator */
NULL, /* HWND hwndParent */
DIGCF_DEVICEINTERFACE | DIGCF_PRESENT /* DWORD Flags */
);
if (hDevInfo == INVALID_HANDLE_VALUE)
{
sprintf(szTraceBuf, "SetupDiClassDevs() failed. GetLastError() " \
"returns: 0x%x\n", GetLastError());
OutputDebugString(szTraceBuf);
printf("SetupDiClassDevs() failed. GetLastError() " \
"returns: 0x%x\n", GetLastError());
return 1;
}
sprintf(szTraceBuf, "Device info set handle for all devices attached to " \
"system: 0x%x\n", hDevInfo);
OutputDebugString(szTraceBuf);
printf("Device info set handle for all devices attached to " \
"system: 0x%x\n", hDevInfo);
// Retrieve a context structure for a device interface of a device
// information set.
DWORD dwIndex = 0;
SP_DEVICE_INTERFACE_DATA devInterfaceData;
ZeroMemory(&devInterfaceData, sizeof(SP_DEVICE_INTERFACE_DATA));
devInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
BOOL bRet = FALSE;
while(TRUE)
{
bRet = SetupDiEnumDeviceInterfaces(
hDevInfo, /* HDEVINFO DeviceInfoSet */
NULL, /* PSP_DEVINFO_DATA DeviceInfoData */
&guidUsbDevClass, /* CONST GUID * InterfaceClassGuid */
dwIndex,
&devInterfaceData /* PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData */
);
if (!bRet)
{
sprintf(szTraceBuf, "SetupDiEnumDeviceInterfaces failed " \
"GetLastError() returns: 0x%x\n", GetLastError());
OutputDebugString(szTraceBuf);
printf("SetupDiEnumDeviceInterfaces failed " \
"GetLastError() returns: 0x%x\n", GetLastError());
if (GetLastError() == ERROR_NO_MORE_ITEMS)
{
break;
}
}
dwIndex++;
}
sprintf(szTraceBuf, "Number of device interface sets representing all " \
"devices attached to system: 0x%x\n", dwIndex);
OutputDebugString(szTraceBuf);
printf("Number of device interface sets representing all " \
"devices attached to system: 0x%x\n", dwIndex);
SetupDiDestroyDeviceInfoList(hDevInfo);
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|