阅读:1080回复:0
求教各位,求教“无心化语”,急,急,急,特急!
各位大师,我在采取本站中一个类似的例子做USB相关程序时,总出错,
程序所取出的USB的管道名总为\'\\\',不知错在何处?代码如下: 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); 此时USB_HidFileHandle总为 INVALID_HANDLE_VALUE,不知何故? |
|
最新喜欢:![]() |