hassanmushtaq
Tue Mar 11 06:27:57 CDT 2008
On Mar 10, 5:44=A0pm, "Peter Foot" <feedb...@nospam-inthehand.com>
wrote:
> Step through the code in the debugger. First check if ConnMgrMapURL is
> succeeding and returning a valid Guid for the connection. If this is good
> and the connection attempt is still failing look at the status returned an=
d
> call Marshal.GetLastWin32Error() after CommMgrEstablishConnectionSync has
> returned false for a more detailed error response.
>
> Peter
>
> --
> Peter Foot
> Microsoft Device Application Development MVPwww.peterfoot.net|www.inthehan=
d.com
> In The Hand Ltd - .NET Solutions for Mobility
>
> "hassanmushtaq" <hassang...@gmail.com> wrote in message
>
> news:c0dd722c-9366-4e6c-8e30-17130c5b07bb@m3g2000hsc.googlegroups.com...
> On Mar 10, 10:38 am, hassanmushtaq <hassang...@gmail.com> wrote:
>
>
>
>
>
> > On Mar 9, 3:36 pm, "Peter Foot" <feedb...@nospam-inthehand.com> wrote:
>
> > > Can you elaborate on "it is not working", are you getting errors at
> > > compile
> > > time, or during execution? exactly where in the code and what return
> > > values,
> > > exceptions etc
>
> > > Peter
>
> > > --
> > > Peter Foot
> > > Microsoft Device Application Development
> > > MVPwww.peterfoot.net|www.inthehand.com
> > > In The Hand Ltd - .NET Solutions for Mobility
>
> > > "hassanmushtaq" <hassang...@gmail.com> wrote in message
>
> > >news:ea1baf6c-9ac3-42d3-8393-33d2aa162ffb@h25g2000hsf.googlegroups.com.=
..
>
> > > > hello
> > > > i m using VS 2003 with C# in CF 1.0.
> > > > i have made application of chatting client. my requirement is when
> > > > user bind to any socket it first made connection of GPRS. so can som=
e
> > > > one give me code of how to connect to GPRS in CF 1.0/
> > > > i have following code. but it is not working.
>
> > > > public class GPRSConnection
> > > > {
> > > > const int S_OK =3D 0;
> > > > const uint CONNMGR_PARAM_GUIDDESTNET =3D 0x1;
> > > > const uint CONNMGR_FLAG_PROXY_HTTP =3D 0x1;
> > > > const uint CONNMGR_PRIORITY_USERINTERACTIVE =3D 0x08000;
> > > > const uint INFINITE =3D 0xffffffff;
> > > > const uint CONNMGR_STATUS_CONNECTED =3D 0x10;
> > > > static Hashtable ht =3D new Hashtable();
>
> > > > static GPRSConnection()
> > > > {
> > > > ManualResetEvent mre =3D new ManualResetEvent(false);
> > > > mre.Handle =3D ConnMgrApiReadyEvent();
> > > > mre.WaitOne();
> > > > CloseHandle(mre.Handle);
> > > > }
>
> > > > ~GPRSConnection()
> > > > {
> > > > ReleaseAll();
> > > > }
>
> > > > public static bool Setup(Uri url)
> > > > {
> > > > return Setup(url.ToString());
> > > > }
>
> > > > public static bool Setup(string urlStr)
> > > > {
> > > > ConnectionInfo ci =3D new ConnectionInfo();
> > > > IntPtr phConnection =3D IntPtr.Zero;
> > > > uint status =3D 0;
>
> > > > if (ht[urlStr] !=3D null)
> > > > return true;
>
> > > > if (ConnMgrMapURL(urlStr, ref ci.guidDestNet, IntPtr.Zero) !=3D S_OK=
)
> > > > return false;
>
> > > > ci.cbSize =3D (uint) Marshal.SizeOf(ci);
> > > > ci.dwParams =3D CONNMGR_PARAM_GUIDDESTNET;
> > > > ci.dwFlags =3D CONNMGR_FLAG_PROXY_HTTP;
> > > > ci.dwPriority =3D CONNMGR_PRIORITY_USERINTERACTIVE;
> > > > ci.bExclusive =3D 0;
> > > > ci.bDisabled =3D 0;
> > > > ci.hWnd =3D IntPtr.Zero;
> > > > ci.uMsg =3D 0;
> > > > ci.lParam =3D 0;
>
> > > > if (ConnMgrEstablishConnectionSync(ref ci, ref phConnection,
> > > > INFINITE, ref status) !=3D S_OK &&
> > > > status !=3D CONNMGR_STATUS_CONNECTED)
> > > > return false;
>
> > > > ht[urlStr] =3D phConnection;
> > > > return true;
> > > > }
>
> > > > public static bool Release(Uri url)
> > > > {
> > > > return Release(url.ToString());
> > > > }
>
> > > > public static bool Release(string urlStr)
> > > > {
> > > > return Release(urlStr, true);
> > > > }
>
> > > > private static bool Release(string urlStr, bool removeNode)
> > > > {
> > > > bool res =3D true;
> > > > IntPtr ph =3D IntPtr.Zero;
> > > > if (ht[urlStr] =3D=3D null)
> > > > return true;
> > > > ph =3D (IntPtr)ht[urlStr];
> > > > if (ConnMgrReleaseConnection(ph, 1) !=3D S_OK)
> > > > res =3D false;
> > > > CloseHandle(ph);
> > > > if (removeNode)
> > > > ht.Remove(urlStr);
> > > > return res;
> > > > }
>
> > > > public static void ReleaseAll()
> > > > {
> > > > foreach(DictionaryEntry de in ht)
> > > > {
> > > > Release((string)de.Key, false);
> > > > }
> > > > ht.Clear();
> > > > }
>
> > > > [StructLayout(LayoutKind.Sequential)]
> > > > public struct ConnectionInfo
> > > > {
> > > > public uint cbSize;
> > > > public uint dwParams;
> > > > public uint dwFlags;
> > > > public uint dwPriority;
> > > > public int bExclusive;
> > > > public int bDisabled;
> > > > public Guid guidDestNet;
> > > > public IntPtr hWnd;
> > > > public uint uMsg;
> > > > public uint lParam;
> > > > public uint ulMaxCost;
> > > > public uint ulMinRcvBw;
> > > > public uint ulMaxConnLatency;
> > > > }
>
> > > > [DllImport("cellcore.dll")]
> > > > private static extern int ConnMgrMapURL(string pwszURL, ref Guid
> > > > pguid, IntPtr pdwIndex);
>
> > > > [DllImport("cellcore.dll")]
> > > > private static extern int ConnMgrEstablishConnectionSync(ref
> > > > ConnectionInfo ci, ref IntPtr phConnection, uint dwTimeout, ref uint=
> > > > pdwStatus);
>
> > > > [DllImport("cellcore.dll")]
> > > > private static extern IntPtr ConnMgrApiReadyEvent();
>
> > > > [DllImport("cellcore.dll")]
> > > > private static extern int ConnMgrReleaseConnection(IntPtr
> > > > hConnection, int bCache);
>
> > > > [DllImport("coredll.dll")]
> > > > private static extern int CloseHandle(IntPtr hObject);
> > > > }
> > > > so please help me
> > > > regards
> > > > Hassan Mushtaq- Hide quoted text -
>
> > > - Show quoted text -
>
> > sorry for not sending u full code. this is the code to call the
> > GPRSConnectin class which i write it in earlier post.
>
> > string url =3D "www.msn.com";
> > bool res =3D GPRSConnection.Setup("
http://" + url + "/");
> > if (res)
> > {
> > TcpClient tc =3D new TcpClient(url, 80);
> > NetworkStream ns =3D tc.GetStream();
> > byte[] buf =3D new byte[100];
> > ns.Write(buf, 0, 100); ns.Close();
> > tc.Close();
> > MessageBox.Show("Wrote 100 bytes");
> > }
> > else
> > {
> > MessageBox.Show("Connection establishment failed");
> > }
>
> > if (ConnMgrEstablishConnectionSync(ref ci, ref phConnection,
> > INFINITE, ref status) !=3D S_OK &&
> > status !=3D CONNMGR_STATUS_CONNECTED)
> > return false;- Hide quoted text -
>
> > - Show quoted text -
>
> sorry for not sending u full code. this is the code to call the
> GPRSConnectin class which i write it in earlier post.
>
> string url =3D "www.msn.com";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bool res =
=3D
> GPRSConnection.Setup("
http://" + url + "/");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (res)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 TcpClient tc =3D new
> TcpClient(url, 80);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 NetworkStream ns =3D
> tc.GetStream();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 byte[] buf =3D new byte[100];
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 ns.Write(buf, 0,
> 100); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0n=
s.Close();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 tc.Close();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 MessageBox.Show("Wrote 100
> bytes");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 MessageBox.Show("Connection
> establishment failed");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> this function return false in the main class. bcoz of that a
> messagebox appear "Connection Established Failed". can u tell me y it
> always retuen false.
> ///////////////////////////////////////////////
> if (ConnMgrEstablishConnectionSync(ref ci, ref phConnection,
> INFINITE, ref status) !=3D S_OK &&
> status !=3D CONNMGR_STATUS_CONNECTED)
> return false;
> /////////////////////////////////////////////
>
> regards
> hassan mushtaq- Hide quoted text -
>
> - Show quoted text -
thanks alot peter i have solved the problem.