Hi... trying a basic write to an USB-attached HID device.
//Relevant Code//
Dim numberOfBytesWritten As Int32 = 0
Dim outputReportBuffer() As Byte = Nothing
Dim Success As Boolean
Array.Resize(outputReportBuffer, Capabilities.OutputReportByteLength)
outputReportBuffer(0) = 0
' Write
Success = WriteFile(deviceHandle, outputReportBuffer, _
outputReportBuffer.Length, numberOfBytesWritten, IntPtr.Zero)
' Test for WriteFile failure
If (Success = 0) Then
ErrorExit("Could not write an Output Report")
End If
<DllImport("kernel32.dll", SetLastError:=True)> _
Shared Function WriteFile _
(ByVal hFile As SafeFileHandle, _
ByVal lpBuffer() As Byte, _
ByVal nNumberOfBytesToWrite As Int32, _
ByRef lpNumberOfBytesWritten As Int32, _
ByVal lpOverlapped As IntPtr) _
As Boolean
End Function
(Took out the ReportID byte for the moment, because I'm just sending zeroes anyway.)
//Some things tried//
1.) Got USB Complete(4th) and perused the updated posted code.
2.) Now able to successfully CreateFile, Locate, Get Attributes, Capabilities, Handle, etc. for attached device; but cannot WriteFile to simply intialize it.
3.) Exceptions include protected memory error et al., depending on the permutations I attempt to get things to work.
4.) Just trying to write zeroes to reset the device at this point, nothing fancy.
5.) As noted, handle is valid.
6.) During debug, "Capabilities.OutputReportByteLength" identifies as only 1 Byte, which seemed odd.
//Background//
1.) [The original source code that came with board was <= VB6.]
2.) Purchased Appleman's Win32 API book et al. including apigid32.dll, but had difficulty translating stuff to newer environment.
3.) Presently using VB via VS Express 2012, to somewhat begin fresh.
Code above... any help is appreciated.