0

auto featureReport = hidDevice->CreateFeatureReport(6); auto dataWriter = ref new DataWriter();

Array<UINT8>^buff = ref new Array<UINT8>(6);

buff[0] = (uint8)featureReport->Id;
buff[1] = 0xe;//update mode
buff[2] = 0;
buff[3] = 0;
buff[4] = 0;
buff[5] = 0;

dataWriter->WriteBytes(buff);
featureReport->Data = dataWriter->DetachBuffer();

create_task(hidDevice->SendFeatureReportAsync(featureReport))
    .then([this](task<uint32> bytesWrittenTask)
{
    auto x = bytesWrittenTask.get();    // If exception occured, let an exception flow down the task chain so it can be caught

    //MessageDialog^ msg = ref new MessageDialog(x.ToString());
});

This code is to access the hid driver after the success of the need to send commands to the hid device, but here the error featureReport-> Data = dataWriter-> DetachBuffer (); Error Message: HRESULT: 0x80070057 Parameter Error

Andrew Henle
  • 32,625
  • 3
  • 24
  • 56
Sniper
  • 1
  • Your code seems right to me. As I don't know the details about your hid device, I just tested with some mock data and there is no error when I call `dataWriter->DetachBuffer()`. So I'd suppose the problem may be not in the code you've posted. Besides, for HID development, you may refer to [Custom HID device sample](https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CustomHidDeviceAccess). – Jay Zuo Mar 29 '17 at 08:54
  • Thanks for your reply. my program is refer to the Custom HID device sample, can you give me your test code about the hid driver. I compare with my code – Sniper Mar 29 '17 at 15:11

1 Answers1

0

You are probably hitting an invalid buffer length. Try to get the buffer length, before you try to write to it.

(pseudo code)
FeatureReport report = hidDevice->GetFeatureReport(reportId)
Array<UINT8>^buff = ref new Array<UINT8>(report.Data.Length);
MoDu
  • 106
  • 10