Как использовать IUpdate5 из wuapi.h

Я хочу использовать интерфейс 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».

0

Решение

Вы когда-нибудь пробовали QueryInterface? Было бы намного лучше с CComQIPtr<IUpdate5> update(ref); конечно.

0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]