I am going to search for updates with BeginSearch. ISearchCompletedCallback has been implemented in with way:
#pragma once
class ISCC : public ISearchCompletedCallback
{
public:
ISCC()
{ }
~ISCC()
{ }
public:
ULONG STDMETHODCALLTYPE ISCC::AddRef()
{
InterlockedIncrement(&refCounter_);
return refCounter_;
}
ULONG STDMETHODCALLTYPE Release()
{
ULONG ulRefCount = InterlockedDecrement(&refCounter_);
if (0 == refCounter_)
{
delete this;
}
return ulRefCount;
}
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID *ppvObj)
{
if (!ppvObj)
return E_INVALIDARG;
*ppvObj = NULL;
if (riid == IID_IUnknown || riid == IID_ISearchCompletedCallback)
{
*ppvObj = (LPVOID)this;
AddRef();
return NOERROR;
}
return E_NOINTERFACE;
}
virtual HRESULT STDMETHODCALLTYPE Invoke(
ISearchJob *searchJob, ISearchCompletedCallbackArgs *callbackArgs)
{
std::cout << "Invoked" << std::endl;
return S_OK;
}
private:
long refCounter_;
};
Also i created another class (Enumerator) where i placed method to start asynchronous search and some private data members which i need to use in my programm:
class Enumerator
{
public:
Enumerator() { }
~Enumerator() { }
public:
//! Begins execution of an asynchronous search for updates.
void AsynchSearch(const _tstring& criteria = _T("IsInstalled=0"))
{
CComPtr<IUpdateSession> pUpSession;
if (SUCCEEDED(CoCreateInstance(
CLSID_UpdateSession,
NULL,
CLSCTX_INPROC_SERVER,
IID_IUpdateSession,
(LPVOID*)&pUpSession)))
{
if (SUCCEEDED(pUpSession->CreateUpdateSearcher(&pUpSearcher_)))
{
HRESULT ret;
ret = pUpSearcher_->BeginSearch(
CComVariant(criteria.c_str()).bstrVal,
iscc_,
CComVariant(_T("Scanning")),
&pJob_);
if (FAILED(ret))
{
// I get next error in this place
// E_POINTER Invalid pointer. <<-- Error!!!
std::cout << "Error occured" << std::endl;
}
}
}
}
private:
//! Asynchronous search callback.
CComPtr<ISCC> iscc_;
//! Job pointer.
CComPtr<ISearchJob> pJob_;
//! Searcher pointer.
CComPtr<IUpdateSearcher> pUpSearcher_;
};
My problem i that when i use method BeginSearch i get error "Invalid pointer" (see method Enumerator::AsynchSearch). Looks like pointer CComPtr<ISCC> iscc_
has been initialized incorrectly. In which way should I initialize CComPtr<ISCC> iscc_
pointer? Thanks.