c++uwphololenswrl

Instantiating a SpatialSurfaceObserver with WRL


I am trying to use the SpatialSurfaceObserver class for Windows Mixed Reality. I was following this: https://developer.microsoft.com/en-us/windows/mixed-reality/spatial_mapping_in_directx

However, I have hit a roadblock. The sample states I should simply create an instance like so: m_surfaceObserver = ref new SpatialSurfaceObserver();

However, I am using pure C++, no C#, no C++/CX etc. So far this was no problem, I was expecting to use an activation factory to create an instance, but as far as I can tell, the one for this class does not contain any function to create an instance.

Basically I thought to use this:

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(...);

But there is no function I could use.

Then I found ActivateInstance, and thought that should work:

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

But this doesn't compile either, it always complains that ISpatialSurfaceObserver does not contain an "InterfaceType" member.

I also ran into "Make" and "MakeAndActivate", but didn't really understood how to use them and if they are the right thing for my case.

Any idea what I am missing?


Solution

  • Not any expertise here but one idea to try.

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

    Could you try to call

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

    Some references that might be helpful: