我试图使用此API;但是,我无法解决这些事件。 所以这是使用Network List 1.0 Type Library com。
这是我的代码:
public class AvailibleWLan : INetworkListManagerEvents, INetworkEvents, INetworkConnectionEvents
{
public NETWORKLIST.INetworkListManager NewWorkList {get;set;}
public List<WirelessNetwork> Connections { get; set; }
public AvailibleWLan()
{
Connections = new List<WirelessNetwork>();
NewWorkList = new NETWORKLIST.NetworkListManager();
foreach (NETWORKLIST.INetwork Network in NewWorkList.GetNetworks(NETWORKLIST.NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_ALL))
{
String Name = Network.GetName();
var Connectivity = Network.GetConnectivity();
var Description = Network.GetDescription();
}
}
//public event NetworkPropertyChanged NetworkConnectivityChanged;
public WirelessNetwork Network { get; set; }
void INetworkListManagerEvents.ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
{
throw new NotImplementedException();
}
void INetworkConnectionEvents.NetworkConnectionConnectivityChanged(Guid connectionId, NLM_CONNECTIVITY newConnectivity)
{
throw new NotImplementedException();
}
void INetworkConnectionEvents.NetworkConnectionPropertyChanged(Guid connectionId, NLM_CONNECTION_PROPERTY_CHANGE Flags)
{
throw new NotImplementedException();
}
void INetworkEvents.NetworkAdded(Guid networkId)
{
throw new NotImplementedException();
}
void INetworkEvents.NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity)
{
throw new NotImplementedException();
}
void INetworkEvents.NetworkDeleted(Guid networkId)
{
throw new NotImplementedException();
}
void INetworkEvents.NetworkPropertyChanged(Guid networkId, NLM_NETWORK_PROPERTY_CHANGE Flags)
{
throw new NotImplementedException();
}
}
所以我在所有活动中休息了一下。和vs永远不会爆发。
答案 0 :(得分:2)
你定义了所有必要的回调函数,这很好。但是你必须通过调用网络接口方法“建议”注册感兴趣的网络来注册这些事件。
以下是代码示例:
namespace NetworkListSample
{
class TestNetworkEvents : INetworkListManagerEvents, INetworkConnectionEvents
{
private INetworkListManager m_nlm = new NetworkListManager();
private static Guid s_INetworkListManagerEventsGuid = typeof(INetworkListManagerEvents).GUID;
private static Guid s_INetworkConnectionEventsGuid = typeof(INetworkConnectionEvents).GUID;
public void RegisterForEvents()
{
// Here it will only register for events of a network which is connected,
// if you wish to register for events of disconnected networks
// use a different NLM_ENUM_NETWORK enum value
IEnumNetworks Networks = m_nlm.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED);
foreach (INetwork item in Networks)
{
IConnectionPoint cp = null;
IConnectionPointContainer icpc = (IConnectionPointContainer)m_nlm;
int cookie = -1;
Guid tempGuid = s_INetworkListManagerEventsGuid;
icpc.FindConnectionPoint(ref tempGuid, out cp);
cp.Advise(this, out cookie);
}
}
public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
{
throw new NotImplementedException();
}
public void NetworkConnectionConnectivityChanged(Guid connectionId, NLM_CONNECTIVITY newConnectivity)
{
throw new NotImplementedException();
}
public void NetworkConnectionPropertyChanged(Guid connectionId, NLM_CONNECTION_PROPERTY_CHANGE Flags)
{
throw new NotImplementedException();
}
}
}
请不要忘记将“整数cookie”作为参数的“unadvise”。