作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试调用 IStoreProduct
的 get_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/
我是一名优秀的程序员,十分优秀!