Задача этого BHO — зарегестрировать\дерегистрировать не-перманентный Namespace Handler.
Проще некуда

bhoinject.h

// bhoinject.h : Declaration of the CBHOInject

#ifndef __BHOINJECT_H_
#define __BHOINJECT_H_

#include "resource.h"       // main symbols



/////////////////////////////////////////////////////////////////////////////
// CBHOInject class
//

class ATL_NO_VTABLE CBHOInject: 
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CBHOInject, &CLSID_BHOInject>,
    public IObjectWithSiteImpl<CBHOInject>
{
public:
    CBHOInject();
    virtual ~CBHOInject();

DECLARE_REGISTRY_RESOURCEID(IDR_BHOINJECT)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CBHOInject)
    COM_INTERFACE_ENTRY(IObjectWithSite)
END_COM_MAP()

// Data members
private:
    IClassFactory* m_pClsFactory;
    IInternetSession* m_pInternetSession;
};



#endif //__BHOINJECT_H_



bhoinject.cpp

///////////////////////////////////////////////////////////////////////////////
// bhoinject.cpp : Implementation of CBHOInject
//

#include "stdafx.h"
#include "scprotocol.h"
#include "bhoinject.h"
#include "scph.h"
#include "scurl.h"

#ifdef _DEBUG
#include "objcounter.h"
#endif //#ifdef _DEBUG



/////////////////////////////////////////////////////////////////////////////
// CBHOInject class
//

#ifdef _DEBUG
CObjCounter g_dbgBHOInjectCounter;
#endif //#ifdef _DEBUG



CBHOInject::CBHOInject()
: m_pInternetSession(NULL),
  m_pClsFactory(NULL)
{
#ifdef _DEBUG
    g_dbgBHOInjectCounter.AddInstance();
#endif //#ifdef _DEBUG

    BOOL bSuccess = FALSE;
    if (SUCCEEDED(CoGetClassObject(CLSID_SCProtocolHandler, CLSCTX_ALL, NULL,
        IID_IClassFactory, (void**)&m_pClsFactory)))
    {
        if (SUCCEEDED(CoInternetGetSession(0, &m_pInternetSession, 0)))
        {
            const LPCWSTR alpszPatterns[] =
            {
                SCPATT_AUTH,
                SCPATT_IMAGE,
                SCPATT_PAY,
                SCPATT_PAYINT,
                SCPATT_PAYPROC
            };

            if (SUCCEEDED(m_pInternetSession->RegisterNameSpace(m_pClsFactory, CLSID_SCProtocolHandler,
                SCURL_PROTOCOL, COUNTOF(alpszPatterns), alpszPatterns, 0)))
                bSuccess = TRUE;
        }
    }

    if (!bSuccess)
    {
        if (m_pInternetSession != NULL)
        {
            m_pInternetSession->Release();
            m_pInternetSession = NULL;
        }

        if (m_pClsFactory != NULL)
        {
            m_pClsFactory->Release();
            m_pClsFactory = NULL;
        }
    }
}



CBHOInject::~CBHOInject()
{
#ifdef _DEBUG
    g_dbgBHOInjectCounter.DelInstance();
#endif //#ifdef _DEBUG

    if (m_pInternetSession != NULL)
    {
        ATLASSERT(m_pClsFactory != NULL);
        ATLVERHRES(m_pInternetSession->UnregisterNameSpace(m_pClsFactory, SCURL_PROTOCOL));

        m_pInternetSession->Release();
    }

    if (m_pClsFactory != NULL)
        m_pClsFactory->Release();
}

Chez, ICQ#161095094

Posted via:RSDN@Home;version:1.1.3;muzikstamp:01 The Inexperienced Spiral Traveller — Sylla'boreal

Автор: Chez    Оценить