c++windows-runtimewindows-store-appswindows-10wrl

How to initialize an instance of IVectorView for C++/WRL?


I'm trying to call get_Skus() method of IStoreProduct to retrieve its Skus property using C++/WRL (not C++/CX) and I can't find any suitable code examples. That method is defined as such (as I get it from the header file in Visual Studio):

virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Skus( 
        /* [out][retval] */ __RPC__deref_out_opt IVectorView<ABI::Windows::Services::Store::StoreSku*> **value) = 0;

So when I try to do:

#include <Windows.Services.Store.h>
#include <wrl.h>

using namespace ABI::Windows::Services::Store;
using namespace ABI::Windows::Foundation::Collections;

IVectorView<StoreSku*> pStrSkus;

//IStoreProduct* pStorePrdct = ...;
if (SUCCEEDED(pStorePrdct->get_Skus(&pStrSkus)))
{
}

it gives me an error that:

'ABI::Windows::Foundation::Collections::IVectorView' : cannot instantiate abstract class

I'm relatively new to WRL. Can someone show me how am I supposed to call that method?


Solution

  • You forgot a star - it should have been this:

    IVectorView<StoreSku*>* pStrSkus;
    
    if (SUCCEEDED(pStorePrdct->get_Skus(&pStrSkus)))
    {
        ...
        pStrSkus->Release();
    }
    

    Even better, use a ComPtr instead, so you don't have to release it manually:

    ComPtr<IVectorView<StoreSku*>> pStrSkus;
    
    if (SUCCEEDED(pStorePrdct->get_Skus(&pStrSkus)))
    {
        ...
    }