加入元件
當子系統新增網路元件時,網路設定子系統可以通知物件。 初始化 notify 物件之後,子系統會呼叫 notify 物件的 INetCfgComponentNotifyGlobal::GetSupportedNotifications 方法,以擷取物件所需的通知類型。 如果通知物件指定在新增網路元件時需要通知,子系統會呼叫 notify 物件的 INetCfgComponentNotifyGlobal::SysNotifyComponent 方法,並傳遞NCN_ADD,以通知該子系統已安裝網路元件。 如果擁有 notify 物件的元件應該系結至指定的元件,則 notify 物件應該執行作業來協助系結。 例如,下列程式碼顯示如果指定的元件是必要的實體網路卡,notify 物件如何將其元件系結至指定的元件。
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;
}