c++ - 使用 WRL 实例化 SpatialSurfaceObserver

标签 c++ uwp hololens wrl

我正在尝试将 SpatialSurfaceObserver 类用于 Windows Mixed Reality。我在关注这个:https://developer.microsoft.com/en-us/windows/mixed-reality/spatial_mapping_in_directx

但是,我遇到了障碍。示例说明我应该像这样简单地创建一个实例: m_surfaceObserver = ref new SpatialSurfaceObserver();

但是,我使用的是纯 C++,没有 C#,没有 C++/CX 等。到目前为止,这没问题,我希望使用激活工厂来创建一个实例,但据我所知,那个因为这个类不包含任何创建实例的函数。

基本上我想用这个:

using namespace ABI::Windows::Perception::Spatial;
ComPtr<Surfaces::ISpatialSurfaceObserverStatics> observerFactory;
ABI::Windows::Foundation::GetActivationFactory(HStringReference(RuntimeClass_Windows_Perception_Spatial_Surfaces_SpatialSurfaceObserver).Get(), &observerFactory);

observerFactory->someCreatorFunction(...);

但是没有我可以使用的功能。

然后我找到了 ActivateInstance,并认为它应该有效:

ComPtr<Surfaces::ISpatialSurfaceObserver> observer;
ABI::Windows::Foundation::ActivateInstance(HStringReference(RuntimeClass_Windows_Perception_Spatial_Surfaces_SpatialSurfaceObserver).Get(), &observer);

但这也不编译,它总是提示 ISpatialSurfaceObserver 不包含“InterfaceType”成员。

我也遇到了“Make”和“MakeAndActivate”,但并没有真正理解如何使用它们以及它们是否适合我的情况。

知道我错过了什么吗?

最佳答案

这里没有任何专业知识,只有一个可以尝试的想法。

ABI::Windows::Foundation::ActivateInstance(HStringReference(RuntimeClass_Windows_Perception_Spatial_Surfaces_SpatialSurfaceObserver).Get(), &observer);

你能试试打电话吗

::RoActivateInstance(HStringReference(RuntimeClass_Windows_Perception_Spatial_Surfaces_SpatialSurfaceObserver).Get(), &observer);

一些可能有用的引用资料:

关于c++ - 使用 WRL 实例化 SpatialSurfaceObserver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45268836/

相关文章:

c++ - 如何在redhawk上添加一个关于idl的项目

c++ - C++11 中的隐式构造函数参数转换

c++ - wstring 到 const wchar* 使用 c_str()

c# - 如何在 Vuforia 中使用 Unity 脚本

c++ - 格式化 C++ 输出两列不同的理由

uwp - 不断收到 BLE UWP Unreachable 错误

xaml - ScrollViewer IsHorizo​​ntalScrollChainingEnabled 和 IsHorizo​​ntalRailEnabled 功能

xaml - Xamarin.Forms 工具栏项目图标大小

unity3d - unity Vuforia NullReferenceException

c# - 从 Unity 到 HoloLens 的程序问题 - 无法从 'string' 转换为 'System.IO.Stream'