Question

I have the following code snippet,

IUpdateSession *iUpdate;
IUpdateSearcher *updateSearcher;
ISearchResult* pISearchResults;
IUpdateCollection* pIUpdateCollection;
IStringCollection *pIStrCollCVEs;
IUpdate2 *pIUpdate;
long lUpdateCount;

...

CoCreateInstance(
            CLSID_UpdateSession,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IUpdateSession,
            (LPVOID*)&iUpdate
            );

iUpdate->CreateUpdateSearcher(&updateSearcher);

printf("\n Searching updates");

updateSearcher->Search(_bstr_t(_T("IsInstalled = 0")), &pISearchResults);
printf("\n Following updates found..\n");

pISearchResults->get_Updates(&pIUpdateCollection);
pIUpdateCollection->get_Count(&lUpdateCount);

LONG lCount;
BSTR buff;
while (0 != lUpdateCount)
{
    pIUpdateCollection->get_Item(lUpdateCount, &pIUpdate);

    pIUpdate->get_CveIDs(&pIStrCollCVEs);

    pIStrCollCVEs->get_Count(&lCount);

    pIUpdate->get_Title(&buff);
    printf("TITLE : %s \n", buff);
    while(0 != lCount)
    {
        pIStrCollCVEs ->get_Item(lCount, &buff);
        _bstr_t b(buff);

        printf("CVEID = %s \n", buff);

        lCount --;
    }

    printf("\n");
    lUpdateCount --;
}


::CoUninitialize();
getchar();

ERROR: error C2664: 'IUpdateCollection::get_Item' : cannot convert parameter 2 from 'IUpdate2 * *' to 'IUpdate * *'

@Line43

How to get a pointer to IUpdate2 interface,

Was it helpful?

Solution

Your get_Item() member of your collection requires an IUpdate interface pointer; not an IUpdate2 interface pointer.

Note: this code is absolutely riddled with bugs, bad practices, and memory leaks. Aong them:

  • Interface pointers that are never released
  • BSTR's that are never freed.
  • HRESULTs that are never checked.
  • Invalid indexing into a zero-based collection

Just to name a few. Regardless The following should address your interface mismatch. The rest of this menagerie I leave to you:

while (0 != lUpdateCount)
{
    IUpdate* pIUpd = NULL;
    HRESULT hr = pIUpdateCollection->get_Item(lUpdateCount, &pIUpd);
    if (SUCCEEDED(hr) && pIUpd)
    {
        hr = pIUpd->QueryInterface(__uuidof(pIUpdate), (LPVOID*)&pIUpdate);
        pIUpd->Release();

        if (SUCCEEDED(hr) && pIUpdate != NULL)
        {
            pIUpdate->get_CveIDs(&pIStrCollCVEs);
            pIStrCollCVEs->get_Count(&lCount);

            pIUpdate->get_Title(&buff);
            printf("TITLE : %s \n", buff);
            while(0 != lCount)
            {
                pIStrCollCVEs ->get_Item(lCount, &buff);
                _bstr_t b(buff, false);
                printf("CVEID = %s \n", buff);
                lCount --;
            }
        }
    }

    printf("\n");
    lUpdateCount--;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top