【发布时间】: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->Lookup("bin") 并查看它的类型为Windows.Foundation.IArrayReference。
编辑:愚蠢的我,this page 已经告诉我,我需要先将其转换为 IBoxArray 并通过 Value 属性获取数组:
Platform::Array<unsigned char>^ binaryData = safe_cast<Platform::IBoxArray<unsigned char>^>(data->Lookup("bin"))->Value;
会做的。
【问题讨论】:
-
既然您已经找到答案,请将其发布为答案并将主题标记为已回答,以帮助其他在搜索答案时发现此主题的人。
-
既然您已经找到答案,请将其发布为答案并将主题标记为已回答,以帮助其他在搜索答案时发现此主题的人。