locked
How to Enable Disable wifi in Windows Mobile 6 using C# RRS feed

  • Question

  • Hi All,

    Currently i am working on windows mobile 6 and now i want to enable and disable wifi through pragmatically for that i used

    [DllImport("Coredll.dll")]
    public static extern int SetDevicePower(string pvDevice, int dwDeviceFlags, PowerState DeviceState);
    
    [DllImport("Coredll.dll")]
    public static extern int GetDevicePower( string pvDevice, int dwDeviceFlags, ref PowerState DeviceState);
    
    [DllImport("Coredll.dll")]
    public static extern int DevicePowerNotify(string device,    PowerState state, int flags);
    
    
    public enum PowerState : int
        {
          Unspecified = -1,
          D0 = 0,
          D1,
          D2, 
          D3,
          D4, 
        }
    
    
    private const int POWER_NAME = 0x00000001;
    
    
    string deviceName = "{98C5250D-C29A-4985-AE5F-AFE5367E5006}\\TNETWLN1"; 
    
    int res1 = DevicePowerNotify(deviceName, PowerState.D0, POWER_NAME);
    
    int res2 = SetDevicePower(deviceName, POWER_NAME , PowerState.D0);
    
    
    
    
    

    Here res1 and res2 r returning value '2' instead of '0 '.

    where im missing?

    So, please some one help in this issue very urgent....

    thanks in advance......


    Nagarjuna Dilip
    Friday, June 25, 2010 6:11 AM

Answers

  • Try this link. it may helps you. it is from OpenNETCF WiFi application

    http://msdn.microsoft.com/en-us/library/aa446491.aspx

    Good luck


    Vinoth.R http://vinoth-vinothblog.blogspot.com http://www.e-consystems.com
    Friday, June 25, 2010 10:20 AM
  • hi,

    Thanks alot 4 ur support.........

    I found my solution.........

    http://blogs.msdn.com/b/raffael/archive/2009/02/27/wireless-programming-on-windows-mobile-supported-or-not-supported.aspx


     

     

      [DllImport("coredll.dll", SetLastError = true)] 
      private static extern int SetDevicePower(string pvDevice, int dwDeviceFlags, DevicePowerState DeviceState); 
    
      private enum DevicePowerState : int 
      { 
        Unspecified = -1, 
        D0 = 0, // Full On: full power, full functionality 
        D1, // Low Power On: fully functional at low power/performance 
        D2, // Standby: partially powered with automatic wake 
        D3, // Sleep: partially powered with device initiated wake 
        D4, // Off: unpowered 
      }
    
      private const int POWER_NAME = 0x00000001;
    
    So, to turn the WiFi ON:
    
      string driver = Utilities.WiFi.FindDriverKey(); 
      SetDevicePower(driver, POWER_NAME, DevicePowerState.D0);
    
    And OFF:
    
      string driver = Utilities.WiFi.FindDriverKey(); 
      SetDevicePower(driver, POWER_NAME, DevicePowerState.D4);
    
    Utilities.WiFi.FindDriverKey() is simply a function that returns the whole registry key name of the key containing the NDIS MINIPORT class GUID defined in the SDK’s pm.h:
    
      private static string FindDriverKey() 
      { 
         string ret = string.Empty; 
    
         //#define PMCLASS_NDIS_MINIPORT      TEXT("{98C5250D-C29A-4985-AE5F-AFE5367E5006}") 
         //(From "c:\Program Files (x86)\Windows Mobile 6 SDK\PocketPC\Include\Armv4i\pm.h") 
         string WiFiDriverClass= "{98C5250D-C29A-4985-AE5F-AFE5367E5006}"; 
    
         foreach (string tmp in Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\Power\\State", false).GetValueNames()) 
         { 
           if (tmp.Contains(WiFiDriverClass)) 
           { 
             ret = tmp; 
             break; 
           } 
         } 
    
         return ret; 
      }
    
    
    

     


    Nagarjuna Dilip
    Monday, June 28, 2010 9:14 AM

All replies

  • you can enable and disable the wifi service using Wireless Zero Config API.  See the sample Win32 program given in the AKU

    \<your AKU>\PUBLIC\COMMON\OAK\DRIVERS\NETSAMP\WZCTOOL

    Using WZCSetInterfaceEx() API you can enable and disable the Wifi

     


    Vinoth.R http://vinoth-vinothblog.blogspot.com http://www.e-consystems.com
    Friday, June 25, 2010 7:07 AM
  • Thanks 4 ur reply....

    provided link is discussing about wht i ve implement which is in my question.....

    i dnt find abt WZCSetInterfaceEx () API in the provided link.........

    plz relook at this issue .......very urgent

    by de way im using HTC HD MINI T5555

     

    Thanks in advance


    Nagarjuna Dilip
    Friday, June 25, 2010 7:19 AM
  • I have given the sample source code path directory of the WZC API usage in windows Mobile AKU. if you don't have windows Mobile AKU you can get it from windows CE also in the same directory path and that is not a hyperlink. Also you can use WZCSetInterface() function provided the WZCsetInterfaceEX is not supported.

     

     

     


    Vinoth.R http://vinoth-vinothblog.blogspot.com http://www.e-consystems.com
    Friday, June 25, 2010 7:34 AM
  • if you dont mind....can u plz give me any example how to use this interface.......

     


    Nagarjuna Dilip
    Friday, June 25, 2010 8:27 AM
  • Try this link. it may helps you. it is from OpenNETCF WiFi application

    http://msdn.microsoft.com/en-us/library/aa446491.aspx

    Good luck


    Vinoth.R http://vinoth-vinothblog.blogspot.com http://www.e-consystems.com
    Friday, June 25, 2010 10:20 AM
  • Hi vinod........

    sorry for the late reply........

    the provided solution is not working in mobile.........

    there is an exceptions while runtime the solution........so the application is quitting..........

    acctually this application is not supporting to my mobile........

    my mobile model no is HTC HD MINI T5555.....

    please suggest me how to work with system dll's even OpenNetCF is also used through base dll's rite........

    so i want to use through system dll's if possible.........thanks 4 ur replies and plz help me.........very urgent.........

     


    Nagarjuna Dilip
    Monday, June 28, 2010 5:39 AM
  • hi,

    Thanks alot 4 ur support.........

    I found my solution.........

    http://blogs.msdn.com/b/raffael/archive/2009/02/27/wireless-programming-on-windows-mobile-supported-or-not-supported.aspx


     

     

      [DllImport("coredll.dll", SetLastError = true)] 
      private static extern int SetDevicePower(string pvDevice, int dwDeviceFlags, DevicePowerState DeviceState); 
    
      private enum DevicePowerState : int 
      { 
        Unspecified = -1, 
        D0 = 0, // Full On: full power, full functionality 
        D1, // Low Power On: fully functional at low power/performance 
        D2, // Standby: partially powered with automatic wake 
        D3, // Sleep: partially powered with device initiated wake 
        D4, // Off: unpowered 
      }
    
      private const int POWER_NAME = 0x00000001;
    
    So, to turn the WiFi ON:
    
      string driver = Utilities.WiFi.FindDriverKey(); 
      SetDevicePower(driver, POWER_NAME, DevicePowerState.D0);
    
    And OFF:
    
      string driver = Utilities.WiFi.FindDriverKey(); 
      SetDevicePower(driver, POWER_NAME, DevicePowerState.D4);
    
    Utilities.WiFi.FindDriverKey() is simply a function that returns the whole registry key name of the key containing the NDIS MINIPORT class GUID defined in the SDK’s pm.h:
    
      private static string FindDriverKey() 
      { 
         string ret = string.Empty; 
    
         //#define PMCLASS_NDIS_MINIPORT      TEXT("{98C5250D-C29A-4985-AE5F-AFE5367E5006}") 
         //(From "c:\Program Files (x86)\Windows Mobile 6 SDK\PocketPC\Include\Armv4i\pm.h") 
         string WiFiDriverClass= "{98C5250D-C29A-4985-AE5F-AFE5367E5006}"; 
    
         foreach (string tmp in Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\Power\\State", false).GetValueNames()) 
         { 
           if (tmp.Contains(WiFiDriverClass)) 
           { 
             ret = tmp; 
             break; 
           } 
         } 
    
         return ret; 
      }
    
    
    

     


    Nagarjuna Dilip
    Monday, June 28, 2010 9:14 AM