Use DataWrite::DetachBuffer An error occurred(WinRT C++)

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

c++
uwp
windows-runtime
asked on Stack Overflow Mar 28, 2017 by Sniper • edited Dec 18, 2017 by Andrew Henle

1 Answer

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);
answered on Stack Overflow Dec 18, 2017 by MoDu

User contributions licensed under CC BY-SA 3.0