New Bee
New Bee

Reputation: 1011

INetworkConnectionEvents Supports what?

I'm trying to use this API; however, I cannot get the events to fire. So this is using Network List 1.0 Type Library com.

Here is my code:

 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();
    }
}

So i have put a break on all the events. and vs is never breaking out.

Upvotes: 1

Views: 2225

Answers (1)

NTR
NTR

Reputation: 21

you defined all necessary callback functions, thats great. But you have to register for these events with calling the network interface method "advise" for the networks of interest.

Here is a code sample for that:

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();
        }
    }
}

Please don't forget the "unadvise" which takes the integer cookie(s) as parameter.

Upvotes: 2

Related Questions