Change binding order of network adapters in Windows XP

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I am trying to look for a way to change the binding order of network
adapters in Windows XP programmaticaly.
I'm already checked out http://support.microsoft.com/kb/894564/en-us, and
what I do is
1 - acquire a write lock using
INetCfgLock->AcquireWriteLock
2 - enumerate all the components
INetCfgClass->EnumComponents
3 - search for the component I want to put on the top of the list.
4 - enumerate all the binding paths for the component
INetCfgComponentBindings->EnumBindingPaths
5 - for each binding path I try to call
INetCfgComponentBindings->MoveBefore
with NULL as the second argument.
but it gives me E_INVALIDARG
And here is where I stuck :-(

I have the latest Windows XP DDK downloaded from MSDN.

Can anyone give me any suggestion what may be the cause for the error?
May be the null as second parameter?
What do i do if I can not pass null as the second argument to MoveBefore?

Next is my code. Thanks in advance.

HRESULT NetCfgAPI::SetPrimaryNetworkAdapter(INetCfg* pNetCfg,LPWSTR
adapterName)
{
HRESULT hr= NULL;
LPWSTR displayName = NULL;
INetCfgClass* pNetCfgClass = NULL;
INetCfgComponent* pNetCfgComp = NULL;
INetCfgBindingPath* pNetCfgBind = NULL;
IEnumNetCfgComponent* pEnumComp = NULL;
IEnumNetCfgBindingPath* pEnumBind= NULL;
NetCfgComponentBindings* pNetCfgCompBind = NULL;

hr = this->HrGetComponentEnum(pNetCfg, &GUID_DEVCLASS_NET, &pEnumComp,
&pNetCfgClass);
if (hr==S_OK)
{
hr = this->HrGetFirstComponent(pEnumComp, &pNetCfgComp);
while (hr==S_OK)
{
hr = pNetCfgComp->GetDisplayName(&displayName);


if (wcscmp(displayName, adapterName)==0)
{

hr = pNetCfgComp->QueryInterface( IID_INetCfgComponentBindings, (PVOID
*)&pNetCfgCompBind );
if ( hr == S_OK )
{
// PATHS
LPWSTR path;
hr = this->HrGetBindingPathEnum(pNetCfgComp,EBP_BELOW,&pEnumBind);
if (hr==S_OK)
{
hr = this->HrGetFirstBindingPath(pEnumBind, &pNetCfgBind);
while (hr==S_OK)
{
hr = pNetCfgBind->GetPathToken(&path);
hr = pNetCfgCompBind->MoveBefore(pNetCfgBind,NULL); // Move adapter
binding to Primary
hr = this->HrGetNextBindingPath(pEnumBind, &pNetCfgBind);
}
}

}
}
hr = this->HrGetNextComponent(pEnumComp, &pNetCfgComp);
}
}
return hr;
}
 
Back
Top