[Windows Mobile] Connection Manager API C#
Posted on April 24th, 2009 by admin
Some posts ago i wrote about using RAS to establish internet connection in that post i mentioned about Connection Manager API. Full description you can find on MSDN, but in most cases developers use 2 functions:
ConnMgrEstablishConnection
ConnMgrReleaseConnection
So to establish connection we need just fill one struct and call ConnMgrEstablishConnection. Thats easy, isnt it?
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;
}
I dont know why, but ConnMgrReleaseConnection aint work for me
i returns success result, but connection still established, so to Disconnect i still use RAS, but how? i can call RasHangUp if i dont know Connection Handle, so we need to use RasEnumConnections to get it and then call RasHangUp
//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
}
}
Sources you can donload here
Filed under: Programming
December 2nd, 2009 at 6:40 pm
Hi,
RasEnumConnections not work on my windows mobile 6.1 device. Why ?
Thanks
March 9th, 2010 at 8:30 am
Dear all,
I am new to C#.net. Can any one give me the built code for RAS Dial connection and i am using winCE 5.0 version.
Thanks.
Dinesh