【问题标题】:Instantiating a SpatialSurfaceObserver with WRL使用 WRL 实例化 SpatialSurfaceObserver
【发布时间】:2017-12-29 08:17:51
【问题描述】:

我正在尝试将 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”,但并不真正了解如何使用它们以及它们是否适合我的情况。

知道我错过了什么吗?

【问题讨论】:

    标签: c++ uwp hololens wrl


    【解决方案1】:

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

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

    你能打电话试试

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

    一些可能有用的参考资料:

    【讨论】:

    • 哇,这真的很完美!非常感谢,你拯救了我的一天:)
    猜你喜欢
    • 1970-01-01
    • 2016-08-13
    • 2012-12-10
    • 1970-01-01
    • 2020-04-28
    • 2014-02-08
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    相关资源
    最近更新 更多