⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notify.cpp

📁 网络驱动开发
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//+---------------------------------------------------------------------------
//
//  Microsoft Windows
//  Copyright (C) Microsoft Corporation, 1992-2001.
//
//  File:       N O T I F Y . C P P
//
//  Contents:   Sample notify object code
//  
//  Notes:
//
//  Author:     Alok Sinha

//----------------------------------------------------------------------------

#include "notify.h"

//----------------------------------------------------------------------------
//
// Function:  CMuxNotify::CMuxNotify
//
// Purpose:   Constructor for CMuxNotify
//
// Arguments: None
//
// Returns:   None
//
// Notes:
//

CMuxNotify::CMuxNotify (VOID) : m_pncc (NULL),
                                m_pnc(NULL),
                                m_eApplyAction(eActUnknown),
                                m_pUnkContext(NULL)
{
    TraceMsg( L"-->CMuxNotify::CMuxNotify(Constructor).\n" );

    TraceMsg( L"<--CMuxNotify::CMuxNotify(Constructor).\n" );
}


// ----------------------------------------------------------------------
//
// Function:  CMuxNotify::~CMuxNotify
//
// Purpose:   Destructor for class CMuxNotify
//
// Arguments: None
//
// Returns:   None
//
// Notes:
//
CMuxNotify::~CMuxNotify (VOID)
{
    CMuxPhysicalAdapter *pAdapter;
    DWORD dwAdapterCount;
    DWORD i;

    TraceMsg( L"-->CMuxNotify::~CMuxNotify(Destructor).\n" );

    // release interfaces if acquired

    ReleaseObj( m_pncc );
    ReleaseObj( m_pnc );
    ReleaseObj( m_pUnkContext );

    dwAdapterCount = m_AdaptersList.ListCount();

    for (i=0; i < dwAdapterCount; ++i) {

        m_AdaptersList.Remove( &pAdapter );

        delete pAdapter;
    }

    dwAdapterCount = m_AdaptersToRemove.ListCount();

    for (i=0; i < dwAdapterCount; ++i) {

        m_AdaptersToRemove.Remove( &pAdapter );

        delete pAdapter;
    }

    dwAdapterCount = m_AdaptersToAdd.ListCount();

    for (i=0; i < dwAdapterCount; ++i) {

        m_AdaptersToAdd.Remove( &pAdapter );

        delete pAdapter;
    }

    TraceMsg( L"<--CMuxNotify::~CMuxNotify(Destructor).\n" );
}

//
//---------------------- NOTIFY OBJECT FUNCTIONS -----------------------------
//

//----------------------------------------------------------------------------
// INetCfgComponentControl                                           
//                                                                       
// The following functions provide the INetCfgComponentControl interface.
//                                                                       
//----------------------------------------------------------------------------

//
// Function:  CMuxNotify::Initialize
//
// Purpose:   Initialize the notify object
//
// Arguments:
//           IN pnccItem   :  Pointer to INetCfgComponent object
//           IN pnc        :  Pointer to INetCfg object
//           IN fInstalling:  TRUE if we are being installed
//
// Returns:
//
// Notes:
//

STDMETHODIMP CMuxNotify::Initialize (INetCfgComponent* pncc,
                                     INetCfg* pnc, 
                                     BOOL fInstalling)
{
    HRESULT hr = S_OK;

    TraceMsg( L"-->CMuxNotify INetCfgControl::Initialize.\n" );


    // Save INetCfg & INetCfgComponent and add a refcount

    m_pncc = pncc;
    m_pnc = pnc;

    if (m_pncc) {

        m_pncc->AddRef();
    }

    if (m_pnc) {

        m_pnc->AddRef();
    }


    //
    // If this not an installation, then we need to 
    // initialize all of our data and classes
    //

    if ( !fInstalling ) {

        hr = HrLoadAdapterConfiguration();
    }

    TraceMsg( L"<--CMuxNotify INetCfgControl::Initialize(HRESULT = %x).\n",
           hr );

    return hr;
}

// ----------------------------------------------------------------------
//
// Function:  CMuxNotify::CancelChanges
//
// Purpose:   Cancel any changes made to internal data
//
// Arguments: None
//
// Returns:   S_OK on success, otherwise an error code
//
// Notes:
//

STDMETHODIMP CMuxNotify::CancelChanges (VOID)
{
    TraceMsg( L"-->CMuxNotify INetCfgControl::CancelChanges.\n" );


    TraceMsg( L"<--CMuxNotify INetCfgControl::CancelChanges(HRESULT = %x).\n",
              S_OK );

    return S_OK;
}

// ----------------------------------------------------------------------
//
// Function:  CMuxNotify::ApplyRegistryChanges
//
// Purpose:   Apply changes.
//
// Arguments: None
//
// Returns:   S_OK.
//
// Notes:     We can make changes to registry etc. here.

STDMETHODIMP CMuxNotify::ApplyRegistryChanges(VOID)
{
    CMuxPhysicalAdapter *pAdapter = NULL;
    GUID                   guidAdapter;
    DWORD                  dwAdapterCount;
    DWORD                  i;

    TraceMsg( L"-->CMuxNotify INetCfgControl::ApplyRegistryChanges.\n" );

    //
    // Make registry changes for the adapters added.
    //

    dwAdapterCount = m_AdaptersToAdd.ListCount();

    TraceMsg( L"   Adding %d new adapters.\n",
              dwAdapterCount );

    for (i=0; i < dwAdapterCount; ++i) {

        m_AdaptersToAdd.Find( i,
                              &pAdapter );
   
        pAdapter->ApplyRegistryChanges( eActAdd );

    }

    //
    // Make registry changes for the adapters uninstalled.
    //

    dwAdapterCount = m_AdaptersToRemove.ListCount();

    TraceMsg( L"   Removing %d adapters.\n",
              dwAdapterCount );

    for (i=0; i < dwAdapterCount; ++i) {

        m_AdaptersToRemove.Find( i,
                                 &pAdapter );
           
        pAdapter->ApplyRegistryChanges( eActRemove );
    }

    //
    // Make registry changes for the miniports added/removed
    // through the property pages.
    //

    dwAdapterCount = m_AdaptersList.ListCount();

    for (i=0; i < dwAdapterCount; ++i) {

        m_AdaptersList.Find( i,
                             &pAdapter );

        pAdapter->ApplyRegistryChanges( eActUpdate );
    }

    TraceMsg( L"<--CMuxNotify INetCfgControl::ApplyRegistryChanges(HRESULT = %x).\n",
              S_OK );

    return S_OK;
}

// ----------------------------------------------------------------------
//
// Function:  CMuxNotify::ApplyPnpChanges
//
// Purpose:   Apply changes.
//
// Arguments:
//            IN pfCallback: PnPConfigCallback interface.
//
// Returns:   S_OK.
//
// Notes:     

STDMETHODIMP CMuxNotify::ApplyPnpChanges (
                                       INetCfgPnpReconfigCallback* pfCallback)
{
    CMuxPhysicalAdapter *pAdapter = NULL;
    GUID                   guidAdapter;
    DWORD                  dwAdapterCount;
    DWORD                  i;

    TraceMsg( L"-->CMuxNotify INetCfgControl::ApplyPnpChanges.\n" );

    //
    // Apply PnP changes for the adapters added.
    //

    dwAdapterCount = m_AdaptersToAdd.ListCount();

    TraceMsg( L"   Applying PnP changes when %d adapters added.\n",
            dwAdapterCount );

    for (i=0; i < dwAdapterCount; ++i) {

        m_AdaptersToAdd.Remove( &pAdapter );

        pAdapter->ApplyPnpChanges( pfCallback,
                                eActAdd );

        pAdapter->GetAdapterGUID( &guidAdapter );

        m_AdaptersList.Insert( pAdapter,
                            guidAdapter );
    }

    //
    // Apply PnP changes for the adapters uninstalled.
    //

    dwAdapterCount = m_AdaptersToRemove.ListCount();

    TraceMsg( L"   Applying PnP changes when %d adapters removed.\n",
            dwAdapterCount );

    for (i=0; i < dwAdapterCount; ++i) {

        m_AdaptersToRemove.Remove( &pAdapter );

        pAdapter->ApplyPnpChanges( pfCallback,
                            eActRemove );

        delete pAdapter;
    }

    //
    // Apply PnP changes for the miniports added/removed through
    // the property pages.
    //

    dwAdapterCount = m_AdaptersList.ListCount();

    for (i=0; i < dwAdapterCount; ++i) {

        m_AdaptersList.Find( i,
                          &pAdapter );

        pAdapter->ApplyPnpChanges( pfCallback,
                                eActUpdate );
    }

    TraceMsg( L"<--CMuxNotify INetCfgControl::ApplyPnpChanges(HRESULT = %x).\n",
            S_OK );

    return S_OK;
}


//----------------------------------------------------------------------------
// INetCfgComponentSetup                                           
//                                                                       
// The following functions provide the INetCfgComponentSetup interface.
//                                                                       
//----------------------------------------------------------------------------

// ----------------------------------------------------------------------
//
// Function:  CMuxNotify::Install
//
// Purpose:   Do operations necessary during the installation.
//
// Arguments:
//            IN dwSetupFlags:  Setup flags
//
// Returns:   S_OK
//
// Notes:     Don't do anything irreversible (like modifying registry) yet
//            since the config. actually completes only when Apply is called!
//

STDMETHODIMP CMuxNotify::Install (DWORD dwSetupFlags)
{

    TraceMsg( L"-->CMuxNotify INetCfgSetup::Install.\n" );

    // Start up the install process

    m_eApplyAction = eActInstall;

    TraceMsg( L"<--CMuxNotify INetCfgSetup::Install(HRESULT = %x).\n",
            S_OK );

    return S_OK;
}

// ----------------------------------------------------------------------
//
// Function:  CMuxNotify::Upgrade
//
// Purpose:   Do operations necessary during the upgrade.
//
// Arguments:
//            IN dwSetupFlags: Setup flags
//
// Returns:   S_OK
//
// Notes:     Don't do anything irreversible (like modifying registry) yet
//            since the config. actually completes only when Apply is called!
//

STDMETHODIMP CMuxNotify::Upgrade (IN DWORD dwSetupFlags,
                                  IN DWORD dwUpgradeFromBuildNo)
{

    TraceMsg( L"-->CMuxNotify INetCfgSetup::Upgrade.\n" );

    TraceMsg( L"   DwSetupFlags = %x, dwUpgradeFromBuildNo = %x\n",
              dwSetupFlags,
              dwUpgradeFromBuildNo );

    TraceMsg( L"<--CMuxNotify INetCfgSetup::Upgrade(HRESULT = %x).\n",
              S_OK );

    return S_OK;
}


// ----------------------------------------------------------------------
//
// Function:  CMuxNotify::ReadAnswerFile
//
// Purpose:   Read settings from answerfile and configure CMuxNotify
//
// Arguments:
//            IN pszAnswerFile   : Name of AnswerFile
//            IN pszAnswerSection: Name of parameters section
//
// Returns:
//
// Notes:     Don't do anything irreversible (like modifying registry) yet
//            since the config. actually completes only when Apply is called!
//

STDMETHODIMP CMuxNotify::ReadAnswerFile (PCWSTR pszAnswerFile,
                                         PCWSTR pszAnswerSection)
{
    PCWSTR pszParamReadFromAnswerFile = L"ParamFromAnswerFile";

    TraceMsg( L"-->CMuxNotify INetCfgSetup::ReadAnswerFile.\n" );

    // We will pretend here that szParamReadFromAnswerFile was actually
    // read from the AnswerFile using the following steps
    //
    //   - Open file pszAnswerFile using SetupAPI
    //   - locate section pszAnswerSection
    //   - locate the required key and get its value
    //   - store its value in pszParamReadFromAnswerFile
    //   - close HINF for pszAnswerFile

    // Now that we have read pszParamReadFromAnswerFile from the
    // AnswerFile, store it in our memory structure.
    // Remember we should not be writing it to the registry till
    // our Apply is called!!
    //

    TraceMsg( L"<--CMuxNotify INetCfgSetup::ReadAnswerFile(HRESULT = %x).\n",
              S_OK );

    return S_OK;
}


// ----------------------------------------------------------------------
//
// Function:  CMuxNotify::Removing
//
// Purpose:   Do necessary cleanup when being removed
//
// Arguments: None
//
// Returns:   S_OK
//
// Notes:     Don't do anything irreversible (like modifying registry) yet
//            since the removal is actually complete only when Apply is called!
//

STDMETHODIMP CMuxNotify::Removing (VOID)
{

    TraceMsg( L"-->CMuxNotify INetCfgSetup::Removing.\n" );

    TraceMsg( L"<--CMuxNotify INetCfgSetup::Removing(HRESULT = %x).\n",
            S_OK );

    return S_OK;
}



//----------------------------------------------------------------------------
// INetCfgComponentNotifyBinding                                          
//                                                                       
// The following functions provide the INetCfgComponentNotifyBinding interface.
//                                                                       
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
//
// Function:  CMuxNotify::QueryBindingPath
//
// Purpose:  This is specific to the component being installed. This will 
//           ask us if we want to bind to the Item being passed into
//           this routine. We can disable the binding by returning
//           NETCFG_S_DISABLE_QUERY 
//
//
// Arguments:
//           IN dwChangeFlag: Type of binding change
//           IN pncbpItem   : Pointer to INetCfgBindingPath object
//
// Returns:   S_OK on success, otherwise an error code.
//
// Notes:
//
STDMETHODIMP CMuxNotify::QueryBindingPath (IN DWORD dwChangeFlag,  
                                           IN INetCfgBindingPath *pncbp)
{
    TraceMsg( L"-->CMuxNotify INetCfgNotifyBinding::QueryBindingPath.\n" );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -