【发布时间】:2019-08-05 18:58:29
【问题描述】:
我目前正在将 UWP 应用程序从 C++/CX 移植到 C++/WinRT。我遇到了safe_cast<Platform::IBoxArray<byte>^>(data),其中data 的类型为Windows::Foundation::IInspectable ^。
我知道safe_cast 由as<T> 方法表示,并且我知道在WinRT/C++ 中有装箱(winrt::box_value) 和拆箱(winrt::unbox_value) 的函数。
但是,我需要知道 Platform::IBoxArray 的等价物才能执行强制转换 (QueryInterface)。根据https://docs.microsoft.com/de-de/cpp/cppcx/platform-iboxarray-interface?view=vs-2017,IBoxArray是Windows::Foundation::IReferenceArray的C++/CX等价物,但没有winrt::Windows::Foundation::IReferenceArray...
nackground 更新:我想要实现的是检索 HoloLens 附加到相机中每个 Media Foundation 样本的视图变换。我的代码基于https://github.com/Microsoft/HoloLensForCV,除了最后一步之外,我得到了真正的一切工作。问题出在这段代码附近:
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);
}
【问题讨论】:
-
您要使用什么 API?
-
我正在尝试从 Media Foundation 示例中提取 HoloLens 视图转换 - 此代码使用我从 Microsofts C++/CX 示例中获得的自定义 GUID 来获取
IInspectable,然后转换为IBoxArray然后 reinterpret_casted 转换为 float4x4 矩阵。所以问题是:我需要知道第一次转换的接口,但我发现没有办法从调试器中获取它...... -
我不熟悉那个 API,但你可能想试试
Windows::Foundation::IReferenceArray<T>。