0

我将使用BeginSearch搜索更新。ISearchCompletedCallback的实现方式如下:

#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_;
};

我还创建了另一个类(枚举器),我在其中放置了启动异步搜索的方法和一些我需要在我的程序中使用的私有数据成员:

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_;
};

我的问题是,当我使用方法BeginSearch时,我收到错误“无效指针”(请参阅​​方法 Enumerator::AsynchSearch)。看起来指针CComPtr<ISCC> iscc_已被错误地初始化。我应该以哪种方式初始化CComPtr<ISCC> iscc_指针?谢谢。

4

0 回答 0