[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
March 12th, 2011 at 2:14 pm
work fine on my wm6.5 phone,thanks.
April 27th, 2011 at 1:24 pm
The reason I think the ConnMgrReleaseConnection doesnt work for you is because it leaves the connection cashed. But it depends on how you use it.
Prior to Windows Mobile 5.0, an application could only specify whether or not a connection was cached. With Windows Mobile 5.0 and continuing with Windows Mobile 6, you can specify the amount of time you would like the Connection Manager to cache the connection. You do this by simply passing the desired number of seconds to cache the connection rather than passing a 0 or a 1 to the cache parameter. For example, the following code shows how to release the connection and request that the Connection Manager cache the connection for 5 minutes (300 seconds).
// Release the connection and cache it for 5 minutes.
ConnMgrReleaseConnection(_connectionHandle, 300);
April 27th, 2011 at 1:48 pm
I`ve tried 0 connection still established