關(guān)于軒氏同步器修改pid,隱藏同步器vid和pid這個(gè)問題很多朋友還不知道,今天小六來為大家解答以上的問題,現(xiàn)在讓我們一起來看看吧!
1、pre t=;code; l=;cpp;;PSP_DEVICE_INTERFACE_DETAIL_DATA HID_FindDevices(USHORT V_ID, USHORT P_ID, unsigned short *FIFO_Lenh){GUID HidGuid;HDEVINFO DevInfo;HIDD_ATTRIBUTES DevAttributes;SP_DEVICE_INTERFACE_DATA DevData;PSP_DEVICE_INTERFACE_DETAIL_DATA DevDetail;PHIDP_PREPARSED_DATA PreparsedData;HIDP_CAPS Capabilities;ULONG Lenh;int Index;BOOL ok;HANDLE DevHandle;int DevCount = 0;/* Get GUID for all System HIDs */HidD_GetHidGuid(HidGuid);/* Get Device Information for all present devices */DevInfo = SetupDiGetClassDevs(HidGuid, NULL, NULL, (DIGCF_PRESENT DIGCF_DEVICEINTERFACE));DevData.cbSize = sizeof(DevData);DevDetail = NULL;Index = -1;*FIFO_Lenh = 0;/* Scan all Devices */do {Index++;/* Device Interface Element of a Device Information set */ok = SetupDiEnumDeviceInterfaces(DevInfo, 0, HidGuid, Index, DevData);if (!ok) break;/* Get Device Interface Details - Get Lenh */ok = SetupDiGetDeviceInterfaceDetail(DevInfo, DevData, NULL, 0, Lenh, NULL);/* Allocate memory for Device Detailed Data */DevDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA) malloc(Lenh);/* Set cbSize in the DevDetail structure */DevDetail-;cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);/* Get Device Interface Details */ok = SetupDiGetDeviceInterfaceDetail(DevInfo, DevData, DevDetail, Lenh, NULL, NULL);if (!ok) {free(DevDetail);DevDetail = NULL;continue;}/* Create File for Device Read/Write */DevHandle = CreateFile(DevDetail-;DevicePath, GENERIC_READ GENERIC_WRITE, FILE_SHARE_READ FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL,OPEN_EXISTING, 0, NULL);if (DevHandle == INVALID_HANDLE_VALUE){free(DevDetail);DevDetail = NULL;continue;}DevAttributes.Size = sizeof(DevAttributes);ok = HidD_GetAttributes(DevHandle,DevAttributes);if(!ok) {free(DevDetail);CloseHandle(DevHandle);DevDetail = NULL;continue;}if(DevAttributes.VendorID!=V_IDDevAttributes.ProductID != P_ID){free(DevDetail);CloseHandle(DevHandle);DevDetail = NULL;continue;}/* Get Preparsed Data */ok = HidD_GetPreparsedData(DevHandle, PreparsedData);if (!ok) {free(DevDetail);CloseHandle(DevHandle);DevDetail = NULL;continue;}/* Get Device;s Capabilities */HidP_GetCaps(PreparsedData, Capabilities);*FIFO_Lenh = Capabilities.InputReportByteLenh;CloseHandle (DevHandle);break;} while (DevCount 20);SetupDiDestroyDeviceInfoList (DevInfo);return DevDetail;} 打開一個(gè)指定VendorID和ProductID的HID設(shè)備extern ;C; {// Declare the C libraries usedinclude ;setupapi.h; // Must link in setupapi.libinclude ;hidsdi.h; // Must link in hid.lib}然后在setting—;Link—;object/libary modules 中添加setupapi.lib hid.lib 兩個(gè)庫文件。
本文分享完畢,希望對(duì)大家有所幫助。
標(biāo)簽:
免責(zé)聲明:本文由用戶上傳,如有侵權(quán)請(qǐng)聯(lián)系刪除!