2017-07-23 37 views
0

我正在嘗試爲Windows混合現實使用SpatialSurfaceObserver類。我是這樣的:https://developer.microsoft.com/en-us/windows/mixed-reality/spatial_mapping_in_directx使用WRL實例化SpatialSurfaceObserver

但是,我遇到了障礙。示例狀態我應該簡單地創建一個實例,如下所示: 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」,但並沒有真正理解如何使用它們,以及它們是否適合我的情況。

任何想法我失蹤?

回答

1

這裏沒有任何專業知識,只有一個想法。

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

你能嘗試調用

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

一些參考文獻可能會有所幫助:

+0

哇,這實際上是完美的作品!非常感謝,你救了我的一天:) – Jan