none
Delegate of win api will not be executed RRS feed

  • Question

  • Hello,

    I'm using a wlan api wrapper class. This function contains a callback function /delegate http://msdn.microsoft.com/en-us/library/windows/desktop/ms706278(v=vs.85).aspx which should be raised when a wlan adapter changes ( for example if the wlan interface is connecting to an other ssid)

    I register the callback function like this:

            public NativeWifiWrapper()
            {
                WlanNotificationCallbackDelegate wlanNotificationCallbackDelegate = new WlanNotificationCallbackDelegate(WlanNotificationCallback);
            }
    
            public static void WlanNotificationCallback(ref WlanNotificationData notificationData, IntPtr context)
            {
    
            }

    For testing I disabled my wlan interface and enabled it. But the callback function was not executed.

    I took the wrapper class from http://wifiperf.googlecode.com/svn-history/r3/trunk/wifi/Interop.cs removed the static keyword from the class and added my constructor and the callback function WlanNotificationCallback (see code above)

    Have anyone a idea why the callback function will not be raised by the wlan api?

    Saturday, August 18, 2012 6:33 PM

Answers

  • Hmmm, the code you show clearly creates a delegate of type WlanNotificationCallbackDelegate and saves it to a variable called wlanNotificationCallbackDelegate.  But this only creates the delegate.  This doesn't apply this delegate to anywhere.  Besides, the variable is declared locally inside the constructor, so it gets destroyed right after construction.

    So in general you need to use this delegate you are instantiating elsewhere.  I don't know your wrapper, but it should take the delegate somewhere somehow.  Instantiating one is not sufficient.


    Jose R. MCP
    Code Samples

    • Proposed as answer by Mike FengModerator Wednesday, August 22, 2012 12:33 PM
    • Marked as answer by martin.doku Wednesday, August 22, 2012 1:20 PM
    Saturday, August 18, 2012 7:21 PM