阅读:1028回复:0
再问
USB_HidFileHandle : THandle;
hardwareDeviceInfo : HDEVINFO; functionClassDeviceData : PSPDeviceInterfaceDetailData; predictedLength : Dword; requiredLength : Dword; Success:LongBool; devicepath:String; deviceInfoData :_SP_DEVICE_INTERFACE_DATA; const LINK_GUID_V: TGUID =\'{D4ACFD5E-7710-4579-9B7D-9731967C3C5A}\'; LINK_GUID : PGUID = @LINK_GUID_V; begin hardwareDeviceInfo := SetupDiGetClassDevs ( Link_GUid, nil, // Define no enumerator (global) 0, // Define no (DIGCF_PRESENT or // Only Devices present DIGCF_INTERFACEDEVICE)); // Function class devices. if hardwareDeviceInfo = Pointer(INVALID_HANDLE_VALUE) then Exit; //ADD deviceInfoData.cbSize := sizeof (_SP_DEVICE_INTERFACE_DATA); Success := SetupDiEnumDeviceInterfaces(hardwareDeviceInfo, nil, LINK_GUID^, 0, deviceInfoData); if Success then begin SetupDiGetInterfaceDeviceDetail( hardwareDeviceInfo, @deviceInfoData, nil, // probing so no output buffer yet 0, // probing so output buffer length of zero @requiredLength, nil); // not interested in the specific dev-node predictedLength := requiredLength; functionClassDeviceData := AllocMem(predictedLength); functionClassDeviceData.cbSize := sizeof (_SP_DEVICE_INTERFACE_DETAIL_DATA_); if (not SetupDiGetInterfaceDeviceDetail ( HardwareDeviceInfo, @DeviceInfoData, functionClassDeviceData, predictedLength, @requiredLength, nil)) then begin freeMem(functionClassDeviceData); exit; end; devicepath:=functionClassDeviceData.DevicePath; //取得DevicePath后,打开设备 USB_HidFileHandle := CreateFile( PChar(devicepath), GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if USB_HidFileHandle = INVALID_HANDLE_VALUE then 上面所取得devicepath总是为\'\\\'空,请问是哪里出错? |
|
最新喜欢:![]() |