#include <windows.h>
#include <basetyps.h>
#include <windowsx.h>
#include <initguid.h>
#include <devioctl.h>
#include <usbioctl.h>
#include <dbt.h>
#include <stdio.h>
#include <setupapi.h>
char* GetUsbDeviceLabel(char* key_name)
{
HDEVINFO di = SetupDiGetClassDevs(&GUID_CLASS_USB_DEVICE, 0, 0, DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);
if(di == INVALID_HANDLE_VALUE)
{
MyPrintf("没有找到");
return 0;
}
for(int i = 0; ; i++)
{
BYTE tmp_buf1[513];
//主控的描述字符串
SP_DEVINFO_DATA DevInfoData;
DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
if(! SetupDiEnumDeviceInfo(di, i, &DevInfoData))
break;
if(! SetupDiGetDeviceRegistryProperty(di, &DevInfoData, SPDRP_DRIVER, 0, tmp_buf1, 513, 0))
continue;
if(strcmp(key_name, (char*)tmp_buf1) != 0)
continue;
if(SetupDiGetDeviceRegistryProperty(di, &DevInfoData, SPDRP_DEVICEDESC, 0, tmp_buf1, 513, 0))
{
strcpy(key_name, (char*)tmp_buf1);
return key_name;
}
else
{
return 0;
}
}
return 0;
}
void GetPortDevDescString(HANDLE hub, int port_idx, USB_DEVICE_DESCRIPTOR* dev_desc)
{
//读语言的种类
BYTE tmp_buf1[513] = {0};
DWORD data_len;
USB_DESCRIPTOR_REQUEST* str_req = (USB_DESCRIPTOR_REQUEST*)tmp_buf1;
USB_STRING_DESCRIPTOR* str_desc = (USB_STRING_DESCRIPTOR*)(tmp_buf1 + sizeof(USB_DESCRIPTOR_REQUEST) - 1);
int LanIDs_num = 0;
WORD* LanIDs = 0;
int i;
str_req->ConnectionIndex = port_idx;
str_req->SetupPacket.wValue = (USB_STRING_DESCRIPTOR_TYPE << 8) | 0;