【问题标题】:Retrieving a byte array in an UWP AppServiceConnection在 UWP AppServiceConnection 中检索字节数组
【发布时间】:2019-05-22 04:06:16
【问题描述】:

another question 开始,我正在尝试在AppServiceConnection 之间传递数据。我对发送和接收字节数组感兴趣。 感谢this question,我知道可接受的类型。但问题是我不知道如何在接收端重现数据,也没有相关文档。

特别是,我有以下几点:

Platform::Array<unsigned char>^ binaryData;
// ... Omitted code to construct the actual data ...
auto data = ref new ValueSet();
data->Insert("bin", binaryData);
if (_connection != nullptr)
    create_task(_connection->SendMessageAsync(data));

在我的服务代码和接收器代码中,我有

// Reproduce the data for processing
Platform::Array<unsigned char>^ binaryData = safe_cast<Platform::Array<unsigned char>^>(data->Lookup("bin"));

但这会使接收器崩溃。我尝试打印出对象data-&gt;Lookup("bin") 并查看它的类型为Windows.Foundation.IArrayReference

编辑:愚蠢的我,this page 已经告诉我,我需要先将其转换为 IBoxArray 并通过 Value 属性获取数组:

Platform::Array<unsigned char>^ binaryData = safe_cast<Platform::IBoxArray<unsigned char>^>(data->Lookup("bin"))->Value;

会做的。

【问题讨论】:

  • 既然您已经找到答案,请将其发布为答案并将主题标记为已回答,以帮助其他在搜索答案时发现此主题的人。
  • 既然您已经找到答案,请将其发布为答案并将主题标记为已回答,以帮助其他在搜索答案时发现此主题的人。

标签: uwp c++-cx


【解决方案1】:

The documentation for IReferenceArray 表示首先将其转换为IBoxArray 并通过Value 属性获取实际数组:更改为

Platform::Array<unsigned char>^ binaryData = safe_cast<Platform::IBoxArray<unsigned char>^>(data->Lookup("bin"))->Value;

会做的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-02
    • 1970-01-01
    • 2022-12-09
    • 2016-07-06
    • 1970-01-01
    • 1970-01-01
    • 2013-01-22
    相关资源
    最近更新 更多