I'm having some problems writing to a FileStream writing to a SafeFileHandle, this file is used to write data to a HID device. I'll post snippets of the code since these occur in several different objects.
This is the handle creation code:
HidHandle = FileIO.CreateFile(pDevicePathName, FileIO.GENERIC_READ | FileIO.GENERIC_WRITE, FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE, IntPtr.Zero, FileIO.OPEN_EXISTING, FileIO.FILE_FLAG_OVERLAPPED, 0);
The handle returned is valid.
Then the stream:
FileStreamDevice = new FileStream(HidHandle, FileAccess.ReadWrite, 65, true);
The stream is created succesfully, but both Position and Length return NotSupportedException (which afaik, is normal).
Then I send the message:
byte[] pMsg = new byte[65];
ManualResetEvent manualevent = new ManualResetEvent(false);
IAsyncResult asynResult = device.FileStreamDevice.BeginWrite(pMsg, 0, pMsg.Length,
new AsyncCallback(End_Write), new DeviceAsyncState(device.FileStreamDeviceData, manualevent));
This immediately returns the following exception message:
'The parameter is incorrect'
This is the top of the stack trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.BeginWriteCore(Byte[] bytes, Int32 offset, Int32 numBytes, AsyncCallback userCallback, Object stateObject)
Thanks in advance.