问题补充说明:请详细解答一下谢谢了... 请详细解答一下 谢谢了 展开
pret=;code;l=;cpp;;PSP_DEVICE_INTERFACE_来自DETAIL_DATAHID_FindDevices(USHORTV_ID,USHORTP_ID,unsignedshort*FIFO_Lenh)
{
GUIDHidGuid;
HDEVINFODevInfo;
HIDD_ATTRIBUTESDevAttributes;
SP_DEVICE_INTERFACE_DATADevData;
PSP_DE坏策需费VICE_INTE拉伤情配RFACE_DETAIL360问答_DATADevDetail;
PHIDP_PREPARSED_DATAPreparsedData;
HIDP_CAPSCapabilities;
ULONGLenh;
intIndex;
BOOLok;
HANDLEDevHandle;
intDe玉功境音传马剂究充vCount=0;
/*GetGUIDforallSystemHIDs*/
HidD_输斗GetHidGuid(HidGuid);
/*GetDeviceInformationforallpresentdevices*/
DevInfo=SetupDiGetClassDevs(HidGuid,
NU亲免LL,
NULL,
(DIGCF_PRESENTDIGCF_DEVICEINTERFACE)
);
DevData.cbSize=sizeof(DevData);
DevDetail=NULL;
Index=-1;
*FIFO_Lenh=0;
/*ScanallDevices*/
do{
Index++;
/*DeviceInt补周草永虽祖求宽九erfaceElem丝与喜药entofaDeviceInformationset*/
ok=SetupDiEnumDeviceInterfaces(DevInfo,
0,
HidGuid,
Index,
DevData
);
if(!ok)break;
/*GetDeviceInterfaceDetails-GetLenh*/
ok=SetupDiGetDeviceInterfaceDetail(DevInfo,
DevData,
NULL,
0,
Lenh,
NUL气轴皮危因息L
);
/*AllocatememoryforDeviceDetailedData*/
DevDetail=(PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(Lenh);
/*SetcbSizeintheDevD批etailstructure*/
DevDetail-;cbSize=sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
/*GetDe象生伤说西广viceInterfaceDetails*/
o心煤车业解妒眼示k=SetupDiGe殖叫块曲创矿频tDeviceInterfaceDetail(DevInfo,
DevData,
D武evDetail夜配革植燃集包保应,
Lenh,
NULL,
NULL
);
if(!ok)
{
free(DevDetail);
DevDetail=NU顺宁注凯菜管化守LL;
continue子只坐伟困切磁免属该考;
}
/*CreateFileforDeviceRead/Write*/
DevHandle=CreateFile(DevDetail-;DevicePath,
GENERIC_READGENER谁谈呀亮IC_WRITE,
FILE_SHARE_READFILE_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;
}
/*GetPreparsedData*/
ok=HidD_GetPreparsedData(DevHandle,PreparsedData);
if(!ok)
{
free(DevDetail);
CloseHandle(DevHandle);
DevDetail=NULL;
continue;
}
/*GetDevice;sCapabilities*/
HidP_GetCaps(PreparsedData,Capabilities);
*FIFO_Lenh=Capabilities.InputReportByteLenh;
CloseHandle(DevHandle);
break;
}while(DevCount20);
SetupDiDestroyDeviceInfoList(DevInfo);
returnDevDetail;
}打开一个指定VendorID和ProductID的HID设备extern;C;{
//DeclaretheClibrariesused
include;setupapi.h;//Mustlinkinsetupapi.lib
include;hidsdi.h;//Mustlinkinhid.lib
}然后在setting—;Link—;object/libarymodules中添加setupapi.libhid.lib两个库文件。