📄 notify.cpp
字号:
DumpChangeFlag( dwChangeFlag );
DumpBindingPath( pncbp );
TraceMsg( L"<--CMuxNotify INetCfgNotifyBinding::QueryBindingPath(HRESULT = %x).\n",
S_OK );
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CMuxNotify::NotifyBindingPath
//
// Purpose: We are now being told to bind to the component passed to us.
//
//
// Arguments:
// IN dwChangeFlag: Type of system change
// IN pncc : Pointer to INetCfgComponent object
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CMuxNotify::NotifyBindingPath (IN DWORD dwChangeFlag,
IN INetCfgBindingPath *pncbp)
{
INetCfgComponent *pnccLower;
INetCfgComponent *pnccUpper;
LPWSTR pszwInfIdLower;
LPWSTR pszwInfIdUpper;
DWORD dwCharcteristics;
HRESULT hr = S_OK;
TraceMsg( L"-->CMuxNotify INetCfgNotifyBinding::NotifyBindingPath.\n" );
DumpChangeFlag( dwChangeFlag );
DumpBindingPath( pncbp );
//
// We are only interested to know 1) when a component is installed
// and we are binding to it i.e. dwChangeFlag = NCN_ADD | NCN_ENABLE
// and 2) when a component is removed to which we are bound i.e.
// dwChangeFlag = NCN_REMOVE | NCN_ENABLE. dwChangeFlag is never
// set to NCN_ADD or NCN_REMOVE only. So, checking for NCN_ENABLE
// covers the case of NCN_ADD | NCN_ENABLE and checking for NCN_REMOVE
// covers the case of NCN_REMOVE | NCN_ENABLE. We don't care about
// NCN_ADD | NCN_DISABLE (case 1) and NCN_REMOVE | NCN_DISABLE (case 2).
//
if ( dwChangeFlag & (NCN_ENABLE | NCN_REMOVE) ) {
//
// Get the upper and lower components.
//
hr = HrGetUpperAndLower( pncbp,
&pnccUpper,
&pnccLower );
if ( hr == S_OK ) {
hr = pnccLower->GetCharacteristics( &dwCharcteristics );
if ( hr == S_OK ) {
hr = pnccLower->GetId( &pszwInfIdLower );
if ( hr == S_OK ) {
hr = pnccUpper->GetId( &pszwInfIdUpper );
if ( hr == S_OK ) {
//
// We are interested only in binding to a
// physical ethernet adapters.
//
if ( dwCharcteristics & NCF_PHYSICAL ) {
if ( !_wcsicmp( pszwInfIdUpper, c_szMuxProtocol ) ) {
if ( dwChangeFlag & NCN_ADD ) {
hr = HrAddAdapter( pnccLower );
m_eApplyAction = eActAdd;
} else if ( dwChangeFlag & NCN_REMOVE ) {
hr = HrRemoveAdapter( pnccLower );
m_eApplyAction = eActRemove;
}
}
} // Physical Adapters.
else if (dwCharcteristics & NCF_VIRTUAL) {
}
CoTaskMemFree( pszwInfIdUpper );
} // Got the upper component id.
CoTaskMemFree( pszwInfIdLower );
} // Got the lower component id.
} // Got NIC's characteristics
ReleaseObj(pnccLower);
ReleaseObj(pnccUpper);
} // Got the upper and lower components.
}
TraceMsg( L"<--CMuxNotify INetCfgNotifyBinding::NotifyBindingPath(HRESULT = %x).\n",
S_OK );
return S_OK;
}
//----------------------------------------------------------------------------
// INetCfgComponentNotifyGlobal
//
// The following functions provide the INetCfgComponentNotifyGlobal interface.
//
//----------------------------------------------------------------------------
// ----------------------------------------------------------------------
//
// Function: CMuxNotify::GetSupportedNotifications
//
// Purpose: Tell the system which notifications we are interested in
//
// Arguments:
// OUT pdwNotificationFlag: Pointer to NotificationFlag
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CMuxNotify::GetSupportedNotifications (
OUT DWORD* pdwNotificationFlag)
{
TraceMsg( L"-->CMuxNotify INetCfgNotifyGlobal::GetSupportedNotifications.\n" );
*pdwNotificationFlag = NCN_NET | NCN_NETTRANS | NCN_ADD | NCN_REMOVE |
NCN_BINDING_PATH | NCN_ENABLE | NCN_DISABLE;
TraceMsg( L"<--CMuxNotify INetCfgNotifyGlobal::GetSupportedNotifications(HRESULT = %x).\n",
S_OK );
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CMuxNotify::SysQueryBindingPath
//
// Purpose: Enable or Disable a binding path.
//
// Arguments:
// IN dwChangeFlag: Type of binding change
// IN pncbp : Pointer to INetCfgBindingPath object
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CMuxNotify::SysQueryBindingPath (DWORD dwChangeFlag,
INetCfgBindingPath* pncbp)
{
INetCfgComponent *pnccLower;
INetCfgComponent *pnccUpper;
LPWSTR pszwInfIdLower;
LPWSTR pszwInfIdUpper;
DWORD dwCharcteristics;
HRESULT hr = S_OK;
TraceMsg( L"-->CMuxNotify INetCfgNotifyGlobal::SysQueryBindingPath.\n" );
DumpChangeFlag( dwChangeFlag );
DumpBindingPath( pncbp );
if ( dwChangeFlag & NCN_ENABLE ) {
//
// Get the upper and lower components.
//
hr = HrGetUpperAndLower( pncbp,
&pnccUpper,
&pnccLower );
if ( hr == S_OK ) {
hr = pnccLower->GetCharacteristics( &dwCharcteristics );
if ( hr == S_OK ) {
hr = pnccLower->GetId( &pszwInfIdLower );
if ( hr == S_OK ) {
hr = pnccUpper->GetId( &pszwInfIdUpper );
if ( hr == S_OK ) {
//
// We are interested only in bindings to physical
// ethernet adapters.
//
if ( dwCharcteristics & NCF_PHYSICAL ) {
#ifdef DISABLE_PROTOCOLS_TO_PHYSICAL
//
// If it not our protocol binding to the
// physical adapter then, disable the
// binding.
//
if (_wcsicmp( pszwInfIdUpper, c_szMuxProtocol ) ) {
TraceMsg( L" Disabling the binding between %s "
L"and %s.\n",
pszwInfIdUpper,
pszwInfIdLower );
hr = NETCFG_S_DISABLE_QUERY;
}
#endif
} // Physical Adapters.
else {
if (dwCharcteristics & NCF_VIRTUAL) {
// If the lower component is our miniport
// and the upper component is our protocol
// then also, disable the binding.
if ( !_wcsicmp(pszwInfIdLower, c_szMuxMiniport) &&
!_wcsicmp(pszwInfIdUpper, c_szMuxProtocol) ) {
TraceMsg( L" Disabling the binding between %s "
L"and %s.\n",
pszwInfIdUpper,
pszwInfIdLower );
hr = NETCFG_S_DISABLE_QUERY;
}
} // Virtual Adapters
}
CoTaskMemFree( pszwInfIdUpper );
} // Got the upper component id.
CoTaskMemFree( pszwInfIdLower );
} // Got the lower component id.
} // Got NIC's characteristics
ReleaseObj(pnccLower);
ReleaseObj(pnccUpper);
}
}
TraceMsg( L"<--CMuxNotify INetCfgNotifyGlobal::SysQueryBindingPath(HRESULT = %x).\n",
hr );
return hr;
}
// ----------------------------------------------------------------------
//
// Function: CMuxNotify::SysNotifyBindingPath
//
// Purpose: System tells us by calling this function which
// binding path has just been formed.
//
// 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::SysNotifyBindingPath (DWORD dwChangeFlag,
INetCfgBindingPath* pncbp)
{
TraceMsg( L"-->CMuxNotify INetCfgNotifyGlobal::SysNotifyBindingPath.\n" );
DumpChangeFlag( dwChangeFlag );
DumpBindingPath( pncbp );
TraceMsg( L"<--CMuxNotify INetCfgNotifyGlobal::SysNotifyBindingPath(HRESULT = %x).\n",
S_OK );
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CMuxNotify::SysNotifyComponent
//
// Purpose: System tells us by calling this function which
// component has undergone a change (installed/removed)
//
// Arguments:
// IN dwChangeFlag: Type of system change
// IN pncc : Pointer to INetCfgComponent object
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CMuxNotify::SysNotifyComponent (DWORD dwChangeFlag,
INetCfgComponent* pncc)
{
TraceMsg( L"-->CMuxNotify INetCfgNotifyGlobal::SysNotifyComponent.\n" );
DumpChangeFlag( dwChangeFlag );
DumpComponent( pncc );
TraceMsg( L"<--CMuxNotify INetCfgNotifyGlobal::SysNotifyComponent(HRESULT = %x).\n",
S_OK );
return S_OK;
}
//----------------------------------------------------------------------------
// INetCfgComponentPropertyUi
//
// The following functions provide the INetCfgComponentPropertyUi interface.
//
//----------------------------------------------------------------------------
// ----------------------------------------------------------------------
//
// Function: CMuxNotify::MergePropPages
//
// Purpose: Supply our property page to system.
//
// Arguments:
// OUT pdwDefPages : Pointer to num default pages
// OUT pahpspPrivate: Pointer to array of pages
// OUT pcPages : Pointer to num pages
// IN hwndParent : Handle of parent window
// IN szStartPage : Pointer to
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CMuxNotify::MergePropPages (IN OUT DWORD* pdwDefPages,
OUT LPBYTE* pahpspPrivate,
OUT UINT* pcPages,
IN HWND hwndParent,
OUT PCWSTR* szStartPage)
{
HRESULT hr = S_OK;
HPROPSHEETPAGE *ahpsp;;
INetLanConnectionUiInfo *pLanConnUiInfo;
TraceMsg(L"-->CMuxNotify INetCfgPropertyUi::MergePropPages\n");
//
// We don't want any default pages to be shown
//
*pdwDefPages = 0;
*pcPages = 0;
*pahpspPrivate = NULL;
if ( !m_pUnkContext ) {
return E_UNEXPECTED;
}
hr = m_pUnkContext->QueryInterface(
IID_INetLanConnectionUiInfo,
reinterpret_cast<PVOID *>(&pLanConnUiInfo));
if ( hr == S_OK ) {
ReleaseObj( pLanConnUiInfo );
ahpsp = (HPROPSHEETPAGE*)CoTaskMemAlloc( sizeof(HPROPSHEETPAGE) );
if (ahpsp) {
PROPSHEETPAGE psp = {0};
psp.dwSize = sizeof(PROPSHEETPAGE);
psp.dwFlags = PSP_DEFAULT;
psp.hInstance = _Module.GetModuleInstance();
psp.pszTemplate = MAKEINTRESOURCE(IDD_NOTIFY_GENERAL);
psp.pfnDlgProc = NotifyDialogProc;
psp.pfnCallback = NULL; (LPFNPSPCALLBACK)NotifyPropSheetPageProc;
psp.lParam = (LPARAM) this;
psp.pszHeaderTitle = NULL;
psp.pszHeaderSubTitle = NULL;
ahpsp[0] = ::CreatePropertySheetPage(&psp);
*pcPages = 1;
*pahpspPrivate = (LPBYTE)ahpsp;
}
else {
hr = E_OUTOFMEMORY;
}
}
TraceMsg(L"<--CMuxNotify INetCfgPropertyUi::MergePropPages(HRESULT = %x).\n",
hr );
return hr;
}
// ----------------------------------------------------------------------
//
// Function: CMuxNotify::ValidateProperties
//
// Purpose: Validate changes to property page.
//
// Arguments:
// IN hwndSheet: Window handle of property sheet
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CMuxNotify::ValidateProperties (HWND hwndSheet)
{
TraceMsg( L"-->CMuxNotify INetCfgPropertyUi::ValidateProperties\n" );
TraceMsg(L"<--CMuxNotify INetCfgPropertyUi::ValidateProperties(HRESULT = %x).\n",
S_OK );
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CMuxNotify::CancelProperties
//
// Purpose: Cancel changes to property page
//
// Arguments: None
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CMuxNotify::CancelProperties (VOID)
{
TraceMsg(L"-->CMuxNotify INetCfgPropertyUi::CancelProperties\n");
TraceMsg(L"<--CMuxNotify INetCfgPropertyUi::CancelProperties(HRESULT = %x).\n",
S_OK );
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CMuxNotify::ApplyProperties
//
// Purpose: Apply value of controls on property page
// to internal memory structure
//
// Arguments: None
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CMuxNotify::ApplyProperties (VOID)
{
INetLanConnectionUiInfo *pLanConnUiInfo;
CMuxPhysicalAdapter *pAdapter;
GUID guidAdapter;
INetCfgComponent *pncc;
HRESULT hr = S_OK;
TraceMsg(L"-->CMuxNotify INetCfgPropertyUi::ApplyProperties\n");
if ( m_pUnkContext ) {
hr = m_pUnkContext->QueryInterface(
IID_INetLanConnectionUiInfo,
reinterpret_cast<PVOID *>(&pLanConnUiInfo));
if ( hr == S_OK ) {
hr = pLanConnUiInfo->GetDeviceGuid( &guidAdapter );
if ( hr == S_OK ) {
hr = m_AdaptersList.FindByKey( guidAdapter,
&pAdapter );
if ( hr == S_OK ) {
switch( m_eApplyAction ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -