Menambahkan Komponen

Subsistem konfigurasi jaringan dapat menginformasikan objek pemberitahuan ketika subsistem menambahkan komponen jaringan. Setelah menginisialisasi objek pemberitahuan, subsistem memanggil metode INetCfgComponentNotifyGlobal::GetSupportedNotifications untuk mengambil jenis-jenis pemberitahuan yang dibutuhkan oleh objek tersebut. Jika objek pemberitahuan ditentukan membutuhkan pemberitahuan ketika komponen jaringan ditambahkan, subsistem memanggil metode INetCfgComponentNotifyGlobal::SysNotifyComponent milik objek dan meneruskan NCN_ADD untuk memberi tahu bahwa subsistem telah menginstal komponen jaringan. Jika komponen yang memiliki objek pemberitahuan harus mengikat komponen yang ditentukan, objek pemberitahuan harus melakukan operasi untuk memfasilitasi pengikatan. Misalnya, kode berikut menunjukkan bagaimana objek pemberitahuan dapat mengikat komponennya ke komponen yang ditentukan jika komponen yang ditentukan adalah kartu jaringan fisik yang diperlukan.

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