简体   繁体   中英

always use WIFI in Windows Mobile 6.5 C#

How can I force my Windows Mobile 6.5 app to always use the phone WIFI adapter, even when the phone is docked to a PC over USB.

Is this possible to do in code? I've tried to use the Connection Manager API but I cannot figure out how to select a specific network adapter.

Edit: This is the code I try to use (found it somewhere on the web) but in Connect() I cannot figure out how to add specific adapter, only if it should connect to internet or work network.

namespace Model
{
    using System;
    using System.Text;
    using System.Runtime.InteropServices;

    public class ConnectionManager : IDisposable
    {
        #region Consts
        private const int RAS_MaxEntryName = 20;
        #endregion

        #region structs
        private class ConnectionInfo
        {
            public int cbSize = 0x40; // structure size
            public int dwParams = 0;
            public int dwFlags = 0; // flags of connection settings
            public int dwPriority = 0; // connection priority
            public int bExclusive = 0;
            public int bDisabled = 0;
            public Guid guidDestNet = Guid.Empty; // Connection GUID
            public IntPtr hWnd = IntPtr.Zero;
            public int uMsg = 0;
            public int lParam = 0;
            public int ulMaxCost = 0;
            public int ulMinRcvBw = 0;
            public int ulMaxConnLatency = 0;
        }

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        private struct RasConn
        {
            public int dwSize;
            public IntPtr hRasconn;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxEntryName + 1)]
            public string szEntryName;
        }
        #endregion

        #region P/Invoke
        [DllImport("cellcore.dll")]
        private static extern int ConnMgrEstablishConnection(
            ConnectionInfo connInfo,
            out IntPtr connection
            );

        [DllImport("coredll.dll", CharSet = CharSet.Auto)]
        private static extern uint RasEnumConnections(
            [In, Out]RasConn[] lpRasconn,   // buffer to receive connections data
            ref int lpcb,          // size in bytes of buffer
            out int lpcConnections // number of connections written to buffer
            );

        [DllImport("coredll.dll")]
        private static extern uint RasHangUp(
            IntPtr hRasConn
            );
        #endregion

        public ConnectionManager()
        {

        }

        public bool Connect()
        {
            ConnectionInfo connInfo_ = new ConnectionInfo();
            connInfo_.cbSize = Marshal.SizeOf(connInfo_);
            connInfo_.dwFlags = 0;
            connInfo_.dwParams = 0x1;
            connInfo_.guidDestNet = new Guid("436EF144-B4FB-4863-A041-8F905A62C572");
            connInfo_.dwPriority = 0x08000;
            connInfo_.bExclusive = 0;
            connInfo_.bDisabled = 0;
            connInfo_.hWnd = IntPtr.Zero;
            connInfo_.lParam = 0;

            IntPtr conn_ = IntPtr.Zero; //we dont need to save it because it aint work
            return ConnMgrEstablishConnection(connInfo_, out conn_) == 0;
        }

        //using ras to disconnect
        public static void Disconnect()
        {
            RasConn[] rconn_ = new RasConn[1]; //as a rule 1 connection is enough
            int out_ = Marshal.SizeOf(typeof(RasConn));
            int cout_ = 1;

            rconn_[0].dwSize = out_;
            rconn_[0].szEntryName = null;


            RasEnumConnections(rconn_, ref out_, out cout_);

            if (cout_ > 0)
            {
                RasHangUp(rconn_[0].hRasconn);
                System.Threading.Thread.Sleep(3000); //msdn says that we should do that
            }
        }

        public void Dispose()
        {
            ConnectionManager.Disconnect();
        }
    }
}

I am not sure but I assume you can handle this using provisioning and specifying the Desktop-Passthru-Connection (ActiveSync/WMDC), also called DTPT, as unsecure and the WiFi/LAN connection as secure ( http://msdn.microsoft.com/en-us/library/aa455851.aspx ). That should work, as the connMgr first uses the 'secure' connection. STOP: I just read the note on the linked site: "Note Setting the value of Secure to false is not supported for Desktop Passthrough (DTPT) connections. DTPT was designed to work as a secure connection.". So this approach is no option for DTPT.

Another approach would be to specify the DTPT connection as a 'Work' connection, wheras (I assume) your connection request is for an 'Internet' connection. Example provisioning: http://msdn.microsoft.com/en-us/library/ms890844.aspx . There is also a connection setting in ActiveSync/WMDC to specify the 'target' for DTPT: Automatic/Internet/Work. Did you try to set it to work?

Possibly you can also simply remove the DTPT connection for connection manager usage: http://msdn.microsoft.com/en-us/library/aa456184.aspx .

To use wap provisioning you need the DMProcessConfigXML API: http://msdn.microsoft.com/en-us/library/ee497867%28v=winembedded.60%29.aspx . A .net example is here: How do I use DMProcessConfigXML to provision my Windows Mobile device?

To provide more help I would need a RapiConfig dump of your connection setup of the device.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM