如何通过可移动设备盘符获取设备路径或GUID-CSDN论坛
1个回答
2016-09-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);
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);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询