c00000fd c00000fd - 9 months ago 69
C++ Question

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

I'm trying to call

method of
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:

: cannot instantiate abstract class

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

Answer Source

You forgot a star - it should have been this:

IVectorView<StoreSku*>* pStrSkus;

if (SUCCEEDED(pStorePrdct->get_Skus(&pStrSkus)))

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)))