我正在尝试将 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/