1

I have a Win32 app that is using WRL (Windows Runtime Template Library) to access the WinRT API.

How do I go about calling a function that takes an IIterable from native C++? My issue is obtaining something that implements IIterable or IVector.

As a concrete example, suppose I wanted to call SetDefaultMenuItems in Include\10.0.14393.0\winrt\windows.ui.input.h:

namespace ABI {
namespace Windows {
namespace UI {
namespace Input {

    MIDL_INTERFACE("A6B79ECB-6A52-4430-910C-56370A9D6B42")
    IRadialControllerConfiguration : public IInspectable
    {
        public:
            virtual HRESULT STDMETHODCALLTYPE SetDefaultMenuItems( 
            /* [in] */ __RPC__in_opt __FIIterable_1_Windows__CUI__CInput__CRadialControllerSystemMenuItemKind *buttons) = 0;
        // ...
    };
}
}
}
}

There doesn't seem to be a stock implementation of IIterable or IVector for native C++.

Larry B
  • 194
  • 14
  • You could construct a [VectorView](https://code.msdn.microsoft.com/windowsapps/Windows-Runtime-Component-9b6c6989/sourcecode?fileId=113783&pathId=1623023906) over a `std::vector`, or any other appropriate container wrapper that matches your Standard C++ collection type. – IInspectable Dec 29 '16 at 13:29
  • I need to create a runtime component that implements IVectorView. I should then try to use that custom component to get the IIterable to pass to the API? – Larry B Dec 30 '16 at 16:55
  • There is no `IVectorView` interface. `VectorView` is a class template, that implements the `IIterable` interface. You can immediately pass a pointer to a `VectorView` to a function expecting an `IIterable` interface. This really sounds like you are completely lost here, probably because you don't understand COM, C++, or how C++ is used to implement COM. And then WRL adds yet another abstraction that you need to master first. This is unlikely to end well. You'll have to start over and get familiar with the basics. – IInspectable Dec 30 '16 at 17:19
  • You're right I am new. – Larry B Dec 30 '16 at 17:24
  • Adding updated link to VectorView implementation for future visitors: https://github.com/microsoft/AdaptiveCards/blob/master/source/uwp/Renderer/lib/Vector.h. – Hitesh Kumar Saini Oct 04 '22 at 17:09

1 Answers1

2

I ended up using cppwinrt to do what I wanted. With this, I was able to pass vanilla std containers, etc. to WinRT.

Larry B
  • 194
  • 14