2024年3月13日发(作者:)

OutputDebugString(szTraceBuf);

printf("Device info set handle for all devices attached to "

"system: 0x%xn", 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));

= sizeof(SP_DEVICE_INTERFACE_DATA);

BOOL bRet = FALSE;

while(TRUE)

{

bRet = SetupDiEnumDeviceInterfaces(

hDevInfo,

NULL,

&guidUsbDevClass,

dwIndex,

&devInterfaceData

);

if (!bRet)

{

sprintf(szTraceBuf, "SetupDiEnumDeviceInterfaces failed "

"GetLastError() returns: 0x%xn", GetLastError());

OutputDebugString(szTraceBuf);

printf("SetupDiEnumDeviceInterfaces failed "

"GetLastError() returns: 0x%xn", GetLastError());

if (GetLastError() == ERROR_NO_MORE_ITEMS)

{

break;

}

}

dwIndex++;

}

sprintf(szTraceBuf, "Number of device interface sets representing all "

"devices attached to system: 0x%xn", dwIndex);

OutputDebugString(szTraceBuf);

printf("Number of device interface sets representing all "

"devices attached to system: 0x%xn", dwIndex);

SetupDiDestroyDeviceInfoList(hDevInfo);

return 0;

}

scottweddle

March 10th, 2005, 11:29 AM

Here's more to add:

I'm doing this enumeration at the application level (user mode) not driver level (kernel mode).

In order to be able to enumerate the devices does ther driver have to call IoRegisterDeviceInterface()?

Funny thing is when I call SetDiGetClassDevs() with whatever combonation for the 1st and 4th argument's I always get

back the same handle. I'm passing the ClassGuid for the USB devices that come under the registry key:

HKEY_LOCAL_MACHINESYSTEMControlSet001EnumUSB

My theroy is that if you pass only DIGCF_DEVICEINTERFACE as the 4th arg along with the USB ClassGuid then

SetupDiEnumDeviceInterfaces() should return a count = to the number of univeral serial bus controllers listed in the

Computer Management dialog under the device manager tree icon.

If you pass the combonation of flags DIGCF_PRESENT | DIGCF_DEVICEINTERFACE and I have my device attached

to the host SetupDiEnumDeviceInterfaces() should return 1.

That's all for now.

Thanks,

Scott

scottweddle

March 11th, 2005, 12:43 PM

Problem solved. I was using the wrong GUID. The correct GUID is:

A5DCBF10-6530-11D2-901F-00C04FB951ED.

Here the code that works. Its basically the same except for how the GUID is declared and passed to functions

SetupDiGetClassDevs() and SetupDiEnumDeviceInterfaces().

#include "stdafx.h"

#include "windows.h"

#include "Setupapi.h"

#include "stdio.h"

static GUID GUID_DEVINTERFACE_USB_DEVICE =

{ 0xA5DCBF10L, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } };

int main(int argc, char* argv[])

{

char szTraceBuf[256];

// Get device interface info set handle for all devices attached to system

HDEVINFO hDevInfo = SetupDiGetClassDevs(

&GUID_DEVINTERFACE_USB_DEVICE,

NULL,

NULL,

DIGCF_PRESENT | DIGCF_DEVICEINTERFACE

);

if (hDevInfo == INVALID_HANDLE_VALUE)

{

sprintf(szTraceBuf, "SetupDiClassDevs() failed. GetLastError() "

"returns: 0x%xn", GetLastError());

OutputDebugString(szTraceBuf);

printf("SetupDiClassDevs() failed. GetLastError() "

"returns: 0x%xn", GetLastError());

return 1;

}

sprintf(szTraceBuf, "Device info set handle for all devices attached to "

"system: 0x%xn", hDevInfo);

OutputDebugString(szTraceBuf);

printf("Device info set handle for all devices attached to "

"system: 0x%xn", 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));

= sizeof(SP_DEVICE_INTERFACE_DATA);

BOOL bRet = FALSE;

while(TRUE)

{

bRet = SetupDiEnumDeviceInterfaces(

hDevInfo,

NULL,

&GUID_DEVINTERFACE_USB_DEVICE,

dwIndex,

&devInterfaceData

);

if (!bRet)

{

sprintf(szTraceBuf, "SetupDiEnumDeviceInterfaces failed "

"GetLastError() returns: 0x%xn", GetLastError());

OutputDebugString(szTraceBuf);

printf("SetupDiEnumDeviceInterfaces failed "

"GetLastError() returns: 0x%xn", GetLastError());

if (GetLastError() == ERROR_NO_MORE_ITEMS)

{

break;

}

}

dwIndex++;

}

sprintf(szTraceBuf, "Number of device interface sets representing all "

"devices attached to system: 0x%xn", dwIndex);

OutputDebugString(szTraceBuf);

printf("Number of device interface sets representing all "

"devices attached to system: 0x%xn", dwIndex);

SetupDiDestroyDeviceInfoList(hDevInfo);

return 0;

}

Neor

March 13th, 2005, 09:18 AM

Congratulation!

howcani

June 29th, 2005, 09:34 PM

I really need to know where you found the device interface GUID as distinct from the device

optionalreaction

September 3rd, 2005, 12:51 PM

I really need to know where you found the device interface GUID as distinct from the device

Yes, so do I.

Has anyone got the (current) 'interface GUID' header file that they could post here?

Keith

guitarmy

September 10th, 2005, 12:04 PM

Look in the winioctl.h header in the sdk include directory. make sure to include initguid.h as well if you plan to use the

predefined guids.

eric

optionalreaction

September 11th, 2005, 01:58 PM

Look in the winioctl.h header in the sdk include directory. make sure to include initguid.h as well if you plan to use the

predefined guids.

eric