如何通过C#连接到wince上的AccessPoint [英] How to Connect to an AccessPoint on wince via C#

查看:127
本文介绍了如何通过C#连接到wince上的AccessPoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过C#以编程方式在WinCE上连接到Wifi Access-Point。

我在很多论坛上搜索过OpenNetCF和WinCE API,但没有成功!

任何帮助将不胜感激

谢谢



这是我的代码:



  private   void  btn_Connect_Click(< span class =code-keyword> object  sender,EventArgs e)
{
WirelessNetworkInterface IN;
尝试
{
// 获取所有WZC网络接口
foreach (NetworkInterface currentNetworkInterface
in WirelessZeroConfigNetworkInterface.GetAllNetworkInterfaces())
{
if (currentNetworkInterface WirelessNetworkInterface)
{

// 确保我们正在处理WZC网络接口
如果(currentNetworkInterface WirelessZeroConfigNetworkInterface)
{
// 获取WZC NetworkInterface可以看到的所有附近接入点
foreach (AccessPoint currentAccessPoint
in ((WirelessZeroConfigNetworkInterface)currentNetworkInterface).NearbyAccessPoints)
{

if (currentAccessPoint.Name == IKCoDiag
{
IN =(WirelessNetworkInterface)currentNetworkInterface;

IN.Connect(currentAccessPoint.Name);
}
}
}
}
}
}
catch (例外ex)
{
MessageBox.Show( 问题: + ex 。信息);
}
}



当我调用此函数时,连接函数会出现此异常:



NotSupportedException

内部异常:无法计算表达式

解决方案

我认为这是因为你还没有定义 WirelessNetworkInterface 默认情况下对象为任何对象,因此编译器将此标记为未定义的行为。在程序中使用它之前,请尝试将其设置为null。如果在定义时没有为其分配内容,最好将引用类型初始化为null。



    - Amy


最后,我找到了一个很好的样本:

http://developer.toradex.com/knowledge-base/wifi-configuration-from-program [ ^ ]



希望它也可以帮助别人。

I want to connect to a Wifi Access-Point programmatically on WinCE via C#.
I searched many forums and read about OpenNetCF and WinCE APIs, but had no success!
Any help will be appreciated
Thanks

Here is my code:

private void btn_Connect_Click(object sender, EventArgs e)
        {
            WirelessNetworkInterface IN;
            try
            {
                // Get all the WZC Network Interfaces
                foreach (NetworkInterface currentNetworkInterface 
                    in WirelessZeroConfigNetworkInterface.GetAllNetworkInterfaces())
                {
                    if(currentNetworkInterface is WirelessNetworkInterface)
                    {

                        // Make sure we are dealing with a WZC Network Interface
                        if (currentNetworkInterface is WirelessZeroConfigNetworkInterface)
                        {
                            // Get all the Nearby Access Points that the WZC NetworkInterface can see
                            foreach (AccessPoint currentAccessPoint 
                                in ((WirelessZeroConfigNetworkInterface)currentNetworkInterface).NearbyAccessPoints)
                            {

                                if (currentAccessPoint.Name == "IKCoDiag")
                                {
                                    IN = (WirelessNetworkInterface)currentNetworkInterface;

                                    IN.Connect(currentAccessPoint.Name);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problem : " + ex.Message);
            }
        }


when i call this function ,this exception appears on connect function:

NotSupportedException
Inner exception :could not evaluate expression

解决方案

I think it's because you have not defined WirelessNetworkInterface object to anything by default, so the compiler flags this as undefined behavior. Try setting it to null before you use it in your program. And also it's good practice to initialize reference types to null if you don't assign something to it while defining.

   --Amy


Finally, I found a good sample:
http://developer.toradex.com/knowledge-base/wifi-configuration-from-program[^]

Hope it could help someone else, too.


这篇关于如何通过C#连接到wince上的AccessPoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆