Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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
Posted
Updated 26-Jul-14 0:51am
v2

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
 
Share this answer
 
Comments
saeid javani 28-Jul-14 8:17am    
thank for your answer amy. i do your solution and not worked!
in my code IN is defined correctly. that is an object of WirelessNetworkInterface class with all of my wireless interface attributes. the problem is from somewhere else.
Finally, I found a good sample:
http://developer.toradex.com/knowledge-base/wifi-configuration-from-program[^]

Hope it could help someone else, too.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900