次の方法で共有


コンポーネントの追加

ネットワーク構成サブシステムは、サブシステムがネットワーク コンポーネントを追加するときに通知オブジェクトに通知できます。 通知オブジェクトを初期化した後、サブシステムは通知オブジェクトの INetCfgComponentNotifyGlobal::GetSupportedNotifications メソッドを呼び出して、オブジェクトに必要な通知の種類を取得します。 通知オブジェクトが、ネットワーク コンポーネントの追加時に通知が必要なことを指定した場合、サブシステムは通知オブジェクトの INetCfgComponentNotifyGlobal::SysNotifyComponent メソッドを呼び出し、NCN_ADD を渡して、サブシステムがネットワーク コンポーネントをインストールしたことを通知します。 通知オブジェクトを所有するコンポーネントを指定されたコンポーネントにバインドする必要がある場合、通知オブジェクトはバインドを容易にする操作を実行する必要があります。 たとえば、次のコードは、指定したコンポーネントが必要な物理ネットワーク カードである場合に、通知オブジェクトがそのコンポーネントを指定したコンポーネントにバインドする方法を示しています。

HRESULT CSample::SysNotifyComponent(DWORD dwChangeFlag,
        INetCfgComponent* pnccItem)
{
    HRESULT hr = S_OK;
    INetCfgComponentBindings *pncfgcompbind;
    // Retrieve bindings for the notify object's component (m_pncc)
    hr = m_pncc->QueryInterface(IID_INetCfgComponentBindings, 
                                (LPVOID*)&pncfgcompbind);
    // Determine if notification is about adding a component
    if (SUCCEEDED(hr) && (NCN_ADD & dwChangeFlag)) {
        // Retrieve the characteristics of the added component
        DWORD dwcc;
        hr = pnccItem->GetCharacteristics(&dwcc);
        // Determine if the added component is a physical adapter
        if (SUCCEEDED(hr) && (dwcc & NCF_PHYSICAL)) {
            // Determine the component's ID
            LPWSTR pszwInfId;
            hr = pnccItem->GetId(&pszwInfId);
            if (SUCCEEDED(hr)) {
                // Compare the component's ID to the required ID
                // and if they are the same perform the binding.
                static const TCHAR c_szCompId[] = TEXT("BINDTO_NIC");
                if (!_tcsicmp(pszwInfId, c_szCompId)) {
                    hr = pncfgcompbind->BindTo(pnccItem);
                }
            }
        }
    }
    return hr;
}