首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在wuapi.h中使用IUpdate5

如何在wuapi.h中使用IUpdate5
EN

Stack Overflow用户
提问于 2018-07-11 18:23:23
回答 1查看 159关注 0票数 1

我想使用IUpdate5接口,但我找不到任何方法来实例化它。我目前使用的是IUpdate,它工作得很完美,但是我怎么才能使用这些接口的版本版本,比如IUpdateSession3,IUpdateSearcher3,IUpdate4,IUpdate5等等。我尝试了从IUpdate*到IUpdate5*的直接转换,但是我得到了像这样的错误。

代码语言:javascript
复制
    //Initialize com components
CoInitialize(NULL);
CComQIPtr<IUpdateSession3> session;
if (auto res = session.CoCreateInstance(CLSID_UpdateSession)) {
    qDebug() << "Failed " << res;
}

IUpdateSearcher* casted;
if (session->CreateUpdateSearcher(&casted)) {
    qDebug() << "CreateUpdateSearcher failed";
}
IUpdateSearcher3* searcher = (IUpdateSearcher3*)casted;


CComQIPtr<ISearchResult> result;
CComBSTR criteria = "IsInstalled=1 and Type='Software'";
if (auto res = searcher->Search(criteria, &result)) {
    qDebug() << "Error " << res;
}

CComQIPtr<IUpdateCollection> updates;
if (auto res = result->get_Updates(&updates)) {
    qDebug() << "get_Updates fail " << res;
}

LONG count;
if (auto res = updates->get_Count(&count)) {
    qDebug() << "Updates count " << res;
}

CoCreateInstance(CLSID_UpdateSearcher, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateSearcher3, (LPVOID*)&searcher);

for (auto i = 0; i < count; ++i) {

    IUpdate* ref;
    if (auto res = updates->get_Item(i, &ref)) {
        qDebug() << "get_Item error " << res;
    }
    IUpdate5* update = (IUpdate5*)ref;

    VARIANT_BOOL rebootRequired;
    if (auto res = update->get_RebootRequired(&rebootRequired)) {
        qDebug() << "Reboot required error" << res;
    }

    qDebug() << "Reboot required is " << (rebootRequired == VARIANT_TRUE ? "yes" : "no");

}

它在if(auto res = update->get_RebootRequired(&rebootRequired))行抛出内存错误。错误是"0xC0000005:访问冲突读取位置0x00000008“。

EN

回答 1

Stack Overflow用户

发布于 2018-07-11 22:00:40

你有没有试过QueryInterface?当然,使用CComQIPtr<IUpdate5> update(ref);会更好。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51283032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档