使用DataWrite :: DetachBuffer发生错误(WinRT C ++)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用DataWrite :: DetachBuffer发生错误(WinRT C ++)相关的知识,希望对你有一定的参考价值。
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());
});
这段代码是在成功之后访问hid驱动程序需要向hid设备发送命令,但这里的错误featureReport-> Data = dataWriter-> DetachBuffer();错误消息:HRESULT:0x80070057参数错误
答案
您可能正在达到无效的缓冲区长度。在尝试写入之前尝试获取缓冲区长度。
(pseudo code)
FeatureReport report = hidDevice->GetFeatureReport(reportId)
Array<UINT8>^buff = ref new Array<UINT8>(report.Data.Length);
以上是关于使用DataWrite :: DetachBuffer发生错误(WinRT C ++)的主要内容,如果未能解决你的问题,请参考以下文章