在C ++ / WinRT中等效于Platform :: IBoxArray [英] Equivalent of Platform::IBoxArray in C++/WinRT

查看:187
本文介绍了在C ++ / WinRT中等效于Platform :: IBoxArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将UWP应用程序从C ++ / CX移植到C ++ / WinRT。我遇到了 safe_cast< Platform :: IBoxArray< byte> ^>(数据)其中 data 的类型为 Windows :: Foundation :: IInspectable ^

I am currently porting an UWP application from C++/CX to C++/WinRT. I encountered a safe_cast<Platform::IBoxArray<byte>^>(data) where data is of type Windows::Foundation::IInspectable ^.

我知道 safe_cast as< T> 方法表示,而且我知道有用于装箱的函数( winrt :: box_value )并在WinRT / C ++中取消装箱( winrt :: unbox_value )。

I know that the safe_cast is represented by the as<T> method, and I know there are functions for boxing (winrt::box_value) and unboxing (winrt::unbox_value) in WinRT/C++.

但是,我需要知道 Platform :: IBoxArray 的等效项才能执行转换(QueryInterface)。根据 https:// docs。 microsoft.com/de-de/cpp/cppcx/platform-iboxarray-interface?view=vs-2017 IBoxArray Windows :: Foundation :: IReferenceArray ,但是没有 winrt :: Windows :: Foundation :: IReferenceArray ...

However, I need to know the equivalent of Platform::IBoxArray in order to perform the cast (QueryInterface). According to https://docs.microsoft.com/de-de/cpp/cppcx/platform-iboxarray-interface?view=vs-2017, IBoxArray is the C++/CX equivalent of Windows::Foundation::IReferenceArray, but there is no winrt::Windows::Foundation::IReferenceArray...

nackground的更新:我要实现的目标是从其相机中检索HoloLens附加到每个Media Foundation样本的视图变换。我的代码基于 https://github.com/Microsoft/HoloLensForCV ,我得到了真正的一切工作,除了最后一步。问题位于这段代码周围:

Update for nackground: What I am trying to achieve is retrieving the view transform attached by the HoloLens to every Media Foundation sample from its camera. My code is based on https://github.com/Microsoft/HoloLensForCV, and I got really everything working except for this last step. The problem is located around this piece of code:

static const GUID MF_EXTENSION_VIEW_TRANSFORM = {
    0x4e251fa4, 0x830f, 0x4770, 0x85, 0x9a, 0x4b, 0x8d, 0x99, 0xaa, 0x80, 0x9b
};

// ...

// In the event handler, which receives const winrt::Windows::Media::Capture::Frames::MediaFrameReader& sender:

auto frame = sender.TryAcquireLatestFrame();
// ...

if (frame.Properties().HasKey(MF_EXTENSION_VIEW_TRANSFORM)) {
    auto /* IInspectable */ userData = frame.Properties().Lookup(MF_EXTENSION_VIEW_TRANSFORM);

    // Now I would have to do the following:
    // auto userBytes = safe_cast<Platform::IBoxArray<Byte> ^>(userData)->Value;
    //viewTransform = *reinterpret_cast<float4x4 *>(userBytes.Data);
}


推荐答案

我不敢相信确实有效,但使用的信息来自 https://docs.microsoft.com/de-de/windows/uwp/cpp-and-winrt-apis/interop-winrt-cx ,我想出了以下解决方案:

I can't believe that actually worked, but using information from https://docs.microsoft.com/de-de/windows/uwp/cpp-and-winrt-apis/interop-winrt-cx, I came up with the following solution:

通过/ ZW启用使用Windows运行时扩展并使用以下转换:

Enable "Consume Windows Runtime Extension" via /ZW and use the following conversion:

auto abi = reinterpret_cast<Platform::Object ^>(winrt::get_abi(userData));
auto userBytes = safe_cast<Platform::IBoxArray<byte> ^>(abi)->Value;
viewTransform = *reinterpret_cast<float4x4 *>(userBytes->Data);

不幸的是,该解决方案的缺点是生成

Unfortunately, the solution has the drawback of generating


警告C4447:在没有线程模型的情况下找到了主要签名。考虑使用'int main(Platform :: Array ^ args)'。

warning C4447: 'main' signature found without threading model. Consider using 'int main(Platform::Array^ args)'.

但是现在,我可以忍受...

But for now, I can live with it ...

这篇关于在C ++ / WinRT中等效于Platform :: IBoxArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆