C# 在Windows Mobile 6.5 C中始终使用WIFI#
如何强制我的Windows Mobile 6.5应用程序始终使用手机WIFI适配器,即使手机通过USB与PC对接 这可以在代码中实现吗? 我曾尝试使用连接管理器API,但我不知道如何选择特定的网络适配器 编辑: 这是我尝试使用的代码(在web上的某个地方找到),但在Connect()中,我不知道如何添加特定的适配器,只有当它应该连接到internet或工作网络时C# 在Windows Mobile 6.5 C中始终使用WIFI#,c#,wifi,windows-mobile-6.5,C#,Wifi,Windows Mobile 6.5,如何强制我的Windows Mobile 6.5应用程序始终使用手机WIFI适配器,即使手机通过USB与PC对接 这可以在代码中实现吗? 我曾尝试使用连接管理器API,但我不知道如何选择特定的网络适配器 编辑: 这是我尝试使用的代码(在web上的某个地方找到),但在Connect()中,我不知道如何添加特定的适配器,只有当它应该连接到internet或工作网络时 namespace Model { using System; using System.Text; usin
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();
}
}
}
我不确定,但我假设您可以通过设置并指定桌面直通连接(ActiveSync/WMDC)(也称为DTPT)为不安全连接,将WiFi/LAN连接指定为安全连接()来处理此问题。这应该是可行的,因为connMgr首先使用“安全”连接。停止:我刚刚读了链接站点上的注释: “注意:桌面直通(DTPT)连接不支持将Secure的值设置为false。DTPT被设计为安全连接。”。因此,这种方法对于DTPT是没有选择的 另一种方法是将DTPT连接指定为“工作”连接,而(我假设)您的连接请求是“Internet”连接。配置示例:。 ActiveSync/WMDC中还有一个连接设置,用于指定DTPT的“目标”:自动/互联网/工作。你试过让它工作吗 您可能还可以简单地删除DTPT连接以使用连接管理器: 要使用wap设置,您需要DMProcessConfigXML API:。下面是一个.net示例:
为了提供更多帮助,我需要一个设备连接设置的RapiConfig转储。发布到目前为止获得的代码。