#include "usb_interface.h" #include #include #include #include #include #include extern "C"{ #include #include #include #include #include #include #include "usbscan.h" } DEFINE_GUID (GUID_DEVINTERFACE_USBPRINT, 0x28d78fad, 0x5a12, 0x11d1, 0xae, 0x5b, 0x0, 0x0, 0xf8, 0x3, 0xa8, 0xc2); using namespace std; _USB_VAR USB_Var; HANDLE hUsb = INVALID_HANDLE_VALUE; char DeviceName[MAX_PATH]; OVERLAPPED overlap; Usb_Interface::Usb_Interface() {} //USB获取当前的设备信息 bool Usb_Interface::Usb_Exsit(uint16_t vid,uint16_t pid) { // uint8_t vid_buf[8]; // uint8_t pid_buf[8]; // //vid & pid 组合成字符串 // sprintf((char *)(&vid_buf[0]),"vid_%04x",vid); // sprintf((char *)(&pid_buf[0]),"pid_%04x",pid); // Get handle to the devices HDEVINFO hInfo = SetupDiGetClassDevs((LPGUID)&GUID_DEVINTERFACE_USBPRINT, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); if (hInfo == INVALID_HANDLE_VALUE) { return false; } SP_INTERFACE_DEVICE_DATA Interface_Info; Interface_Info.cbSize = sizeof(Interface_Info); // Enumerate device if (!SetupDiEnumInterfaceDevice(hInfo, NULL, (LPGUID) &GUID_DEVINTERFACE_USBPRINT,0, &Interface_Info)) { SetupDiDestroyDeviceInfoList(hInfo); return false; } DWORD needed; // get the required length SetupDiGetInterfaceDeviceDetail(hInfo, &Interface_Info, NULL, 0, &needed, NULL); PSP_INTERFACE_DEVICE_DETAIL_DATA detail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc(needed); if (!detail) { SetupDiDestroyDeviceInfoList(hInfo); return false; } // fill the device details detail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); if (!SetupDiGetInterfaceDeviceDetail(hInfo, &Interface_Info, detail, needed,NULL, NULL)) { free((PVOID) detail); SetupDiDestroyDeviceInfoList(hInfo); return false;; } char *ptr = (char *)(detail->DevicePath); DevicePath = QString("PID:0x8800,VID:0x0fe6"); memset(DeviceName,0x00,MAX_PATH); for(int i = 0; i