描述:
Private Sub WriteReport()
'Send data to the device.
Dim Count As Integer
Dim NumberOfBytesRead As Long
Dim NumberOfBytesToSend As Long
Dim NumberOfBytesWritten As Long
Dim SendBuffer() As Byte
'1. 前面已经找到USB设备,CreateFile也已返回USB Handle
'但Capabilities.OutputReportByteLength总是为0,Redim定义
'错误,不知道为什么?
ReDim SendBuffer(Capabilities.OutputReportByteLength - 1)
'The first byte is the Report ID
'2. 不知道Report ID是什么意思,一定要设为0吗?
SendBuffer(0) = 0
'The next bytes are data
For Count = 1 To Capabilities.OutputReportByteLength - 1
SendBuffer(Count) = OutputReportData(Count - 1)
Next Count
NumberOfBytesWritten = 0
'3. 为什么有时WriteFile返回参数错误?
Result = WriteFile _
(HidDevice, _
SendBuffer(0), _
CLng(Capabilities.OutputReportByteLength), _
NumberOfBytesWritten, _
0)
Call DisplayResultOfAPICall("WriteFile")
lstResults.AddItem " OutputReportByteLength = " & Capabilities.OutputReportByteLength
lstResults.AddItem " NumberOfBytesWritten = " & NumberOfBytesWritten
lstResults.AddItem " Report ID: " & SendBuffer(0)
lstResults.AddItem " Report Data:"
For Count = 1 To UBound(SendBuffer)
lstResults.AddItem " " & Hex$(SendBuffer(Count))
Next Count
End Sub
打搅大家了,万分抱歉
只要有帮助,再加帖给分!
解决方案1:
楼上的厉害啊
解决方案2: 粗略看了一下msdn……你用WriteFile应该是可以的,用户模式下用DeviceIoControl是没有用的……
其他的……唉,太麻烦,看不下去了
你把你api的调用顺序写来看看?
不会也
解决方案4:对了,你的usb设备具体是什么?
解决方案5: http://www.cppfans.com/forum/guestbkans.asp?id=1231
希望对你有帮助
HidD_GetPreparsedData等api的C函数原型贴来看看
解决方案7:你调用Err.LastDllError看看返回什么API错误代码
解决方案8:公司封掉了USB,试8了