返回首页

简介
本文使用一种通用方法,设置一个无线网络适配器在Windows Mobile设备上的电源状态。使用代码
粘贴到一个类的代码,并调用静态SetRadioPowerStatus方法,以国家规定的设置无线电。在C#代码

public enum DevicePowerState : int

{

    Unspecified = -1,

    FullPower = 0,      // Full On: full power, full functionality

    LowPower,           // Low Power On: fully functional at low power/performance

    Standby,            // Standby: partially powered with automatic wake

    Sleep,              // Sleep: partially powered with device initiated wake

    Off,                // Off: unpowered

}        



private const int POWER_NAME = 0x00000001;



[DllImport("coredll.dll", SetLastError = true)]

private static extern int DevicePowerNotify(string deviceId, 

                          DevicePowerState state, int flags);



[DllImport("coredll.dll", SetLastError = true)]

private static extern int SetDevicePower(string deviceId, 

                          int flags, DevicePowerState state);



public static void SetRadioPowerStatus(DevicePowerState state)

{

    String key = "{98C5250D-C29A-4985-AE5F-AFE5367E5006}\\SWLD246L1";



    int i1 = DevicePowerNotify(key, state, POWER_NAME);



    if (i1 == 0)

    {

        int i2 = SetDevicePower(key, POWER_NAME, state);

    }

}
在VB.NET代码{C}兴趣点
均P / Invoke调用必须返回0成功的。请注意设备的名称("; SWLD246L1quot";,在这种情况下)的第二部分是取决于你的硬件。该名称将注册表[HKLM \ COMMS下一个键的名称。依次打开每个键找到一个显示名称的值等于安装的适配器。|约翰H. ROUX

回答

评论会员: 时间:2