Ok so I am trying to set up a Network Connection event using NetworkListManager
from System.Runtime.InteropServices.ComTypes
using this code:
private NetworkListManager nlm; //This is initialized before
private IConnectionPoint icp;
private int cookie = 0;
//This part is wrapped in a function call
Console.WriteLine("Subscribing the INetworkListManagerEvents");
IConnectionPointContainer icpc = (IConnectionPointContainer)nlm;
Guid tempGuid = typeof(INetworkListManagerEvents).GUID;
icpc.FindConnectionPoint(ref tempGuid, out icp);
//The error is thrown in icp.Advise with code 0x80040202
icp.Advise(this, out cookie);
I've already tried searching, but most people are concerned about different matters on this error
The correct way of using the NETWORKLIST
is like this:
using NETWORKLIST;
public class Foo : INetworkListManagerEvents
{
private NetworkListManager nlm;
private IConnectionPoint icp;
private int cookie = 0;
public Foo()
{
nlm = new NetworkListManager();
IConnectionPointContainer icpc = (IConnectionPointContainer)nlm;
Guid tempGuid = typeof(INetworkListManagerEvents).GUID;
icpc.FindConnectionPoint(ref tempGuid, out icp);
icp.Advise(this, out cookie);
}
//this method must be implemented
public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
{
//Your code goes here
}
}
What I was doing wrong is that I forgot to implement INetworkListManagerEvents
User contributions licensed under CC BY-SA 3.0