USB操作中如何通过GUID得到路径字符串呢?

NTRTS 2009-08-16 12:22:20
完全不懂,头都大了,唉...公司任务

查了很多资料,一点头绪都没有
...全文
23 点赞 收藏 2
写回复
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
NTRTS 2009-08-16
回答得真快...试试看
回复
MoXiaoRab 2009-08-16
这种帖子以前回答过,如下代码看看能不能搞定

HidD_GetHidGuid (&hidGUID);

DeviceInfoSet = SetupDiGetClassDevs (&hidGUID, NULL, NULL, (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)); deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);

if(DeviceInfoSet == INVALID_HANDLE_VALUE)
printf("DeviceInfoSet is INVALID_HANDLE_VALUE\n");

result = SetupDiEnumDeviceInterfaces (DeviceInfoSet, NULL, &hidGUID, Index, &deviceInterfaceData);
if (result == FALSE)
SetupDiDestroyDeviceInfoList (DeviceInfoSet);


SetupDiGetDeviceInterfaceDetail (DeviceInfoSet, &deviceInterfaceData, NULL, 0, &requiredSize, 0);
deviceDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(requiredSize);
deviceDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
if(deviceDetail == NULL)
printf("There is no enough memory space available for deviceDetail\n");

if (!SetupDiGetDeviceInterfaceDetail (DeviceInfoSet, &deviceInterfaceData, deviceDetail, requiredSize, &requiredSize, NULL))
{
printf("SetupDiGetDeviceInterfaceDetail failed\n");
SetupDiDestroyDeviceInfoList (DeviceInfoSet);
free (deviceDetail);
return INVALID_HANDLE_VALUE;
}

printf("path: %s\n", deviceDetail->DevicePath);
deviceHandle = CreateFile (deviceDetail->DevicePath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

if(deviceHandle == INVALID_HANDLE_VALUE);
printf("CreateFile open failed (%d)\n", GetLastError());

SetupDiDestroyDeviceInfoList (DeviceInfoSet);
free (deviceDetail);


回复
发动态
发帖子
硬件/系统
创建于2007-09-28

2590

社区成员

VC/MFC 硬件/系统
申请成为版主
社区公告
暂无公告