2

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?

Mikewhat
  • 62
  • 5
c00000fd
  • 20,994
  • 29
  • 177
  • 400

1 Answers1

2

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)))
{
    ...
}
Sunius
  • 2,789
  • 18
  • 30
  • Thanks. I knew it was easy. – c00000fd Oct 22 '16 at 19:20
  • Listen, it's a separate question, but if I need to initiate and pass an `IVector` of `HSTRING`s how would I do it? Pretty much this in C# converted to C++/WRL: `string[] storeIds = new string[] { "9NBLGGH4TNMP", "9NBLGGH4TNMN" };` – c00000fd Oct 22 '16 at 19:23
  • You need to make a class that implements IVector. Easiest to do by wrapping std::vector. – Sunius Oct 23 '16 at 12:19