【问题标题】:Error running Windows CE sample code运行 Windows CE 示例代码时出错
【发布时间】:2011-01-28 00:08:43
【问题描述】:

我有这个在 Windows CE 中禁用/启用 WIFI 的示例代码。

[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;

public Form1()
{
    InitializeComponent();
}

//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 he SDK’s pm.h:

private void button1_Click(object sender, EventArgs e)
{
    string driver = Utilities.WiFi.FindDriverKey();
    SetDevicePower(driver, POWER_NAME, DevicePowerState.D0);
}


private void button2_Click(object sender, EventArgs e)
{

    string driver = Utilities.WiFi.FindDriverKey();
    SetDevicePower(driver, POWER_NAME, DevicePowerState.D4);
}


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

但是,我得到了这个错误:

当前上下文中不存在名称“Utilities”

为什么会出现这个错误?

【问题讨论】:

    标签: c# windows-ce


    【解决方案1】:

    这可能是因为 FindDriverKey() 曾经位于 Utilities 类或命名空间中。只需在致电FindDriverKey() 之前放下Utilities.Wifi,您就应该准备就绪。或者,您可以创建一个 Utilities 命名空间,然后创建一个名为 Wifi 的静态类,并将 FindDriverKey() 函数放到 Wifi 类中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-20
      • 2015-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      • 1970-01-01
      相关资源
      最近更新 更多