我想使用IUpdate5接口,但我找不到任何方法来实例化它。我目前使用的是IUpdate,它工作得很完美,但是我怎么才能使用这些接口的版本版本,比如IUpdateSession3,IUpdateSearcher3,IUpdate4,IUpdate5等等。我尝试了从IUpdate*到IUpdate5*的直接转换,但是我得到了像这样的错误。
//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“。
发布于 2018-07-11 22:00:40
你有没有试过QueryInterface?当然,使用CComQIPtr<IUpdate5> update(ref);会更好。
https://stackoverflow.com/questions/51283032
复制相似问题