I am having trouble writing a FileStream file to SafeFileHandle, this file is used to write data to the HID device. I will post code snippets as they are found in several different objects.
This is the descriptor 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 returned handle is valid.
Then the stream:
FileStreamDevice = new FileStream(HidHandle, FileAccess.ReadWrite, 65, true);
The thread is created successfully, but both Position and Length return a NotSupportedException (which is afaik, this is normal).
Then I send a 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.