gpt4 book ai didi

c++ - 如何为 C++/WRL 初始化 IVectorView 的实例?

转载 作者:行者123 更新时间:2023-11-30 05:21:21 25 4
gpt4 key购买 nike

我正在尝试调用 IStoreProductget_Skus() 方法来检索它的 Skus属性使用C++/WRL (不是 C++/CX)而且我找不到任何合适的代码示例。该方法是这样定义的(正如我从 Visual Studio 的头文件中获取的那样):

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

所以当我尝试这样做时:

#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)))
{
}

它给我一个错误:

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

我对 WRL 比较陌生。谁能告诉我应该如何调用该方法?

最佳答案

你忘记了一颗星星——它应该是这样的:

IVectorView<StoreSku*>* pStrSkus;

if (SUCCEEDED(pStorePrdct->get_Skus(&pStrSkus)))
{
...
pStrSkus->Release();
}

更好的是,改用 ComPtr,这样您就不必手动释放它:

ComPtr<IVectorView<StoreSku*>> pStrSkus;

if (SUCCEEDED(pStorePrdct->get_Skus(&pStrSkus)))
{
...
}

关于c++ - 如何为 C++/WRL 初始化 IVectorView 的实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40190165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com