📄 guid.txt
字号:
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 /*const*/ 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, /* CONST GUID * ClassGuid - USB class GUID */
NULL, /* PCTSTR Enumerator */
NULL, /* HWND hwndParent */
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE /* 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 */
&GUID_DEVINTERFACE_USB_DEVICE, /* 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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -