Re: Connection to GPRS with P/Invoke

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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 MVP
www.peterfoot.net | www.inthehand.com
In The Hand Ltd - .NET Solutions for Mobility

"hassanmushtaq" <hassangugu@xxxxxxxxx> wrote in message news:ea1baf6c-9ac3-42d3-8393-33d2aa162ffb@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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 some
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 = 0;
const uint CONNMGR_PARAM_GUIDDESTNET = 0x1;
const uint CONNMGR_FLAG_PROXY_HTTP = 0x1;
const uint CONNMGR_PRIORITY_USERINTERACTIVE = 0x08000;
const uint INFINITE = 0xffffffff;
const uint CONNMGR_STATUS_CONNECTED = 0x10;
static Hashtable ht = new Hashtable();

static GPRSConnection()
{
ManualResetEvent mre = new ManualResetEvent(false);
mre.Handle = 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 = new ConnectionInfo();
IntPtr phConnection = IntPtr.Zero;
uint status = 0;

if (ht[urlStr] != null)
return true;

if (ConnMgrMapURL(urlStr, ref ci.guidDestNet, IntPtr.Zero) != S_OK)
return false;

ci.cbSize = (uint) Marshal.SizeOf(ci);
ci.dwParams = CONNMGR_PARAM_GUIDDESTNET;
ci.dwFlags = CONNMGR_FLAG_PROXY_HTTP;
ci.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
ci.bExclusive = 0;
ci.bDisabled = 0;
ci.hWnd = IntPtr.Zero;
ci.uMsg = 0;
ci.lParam = 0;

if (ConnMgrEstablishConnectionSync(ref ci, ref phConnection,
INFINITE, ref status) != S_OK &&
status != CONNMGR_STATUS_CONNECTED)
return false;

ht[urlStr] = 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 = true;
IntPtr ph = IntPtr.Zero;
if (ht[urlStr] == null)
return true;
ph = (IntPtr)ht[urlStr];
if (ConnMgrReleaseConnection(ph, 1) != S_OK)
res = 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

.



Relevant Pages

  • Connection to GPRS with P/Invoke
    ... public static bool Setup ... public uint dwParams; ... private static extern int ConnMgrMapURL(string pwszURL, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Connection to GPRS with P/Invoke
    ... If this is good and the connection attempt is still failing look at the status returned and call Marshal.GetLastWin32Errorafter CommMgrEstablishConnectionSync has returned false for a more detailed error response. ... >> public uint dwParams; ... >> private static extern int ConnMgrMapURL(string pwszURL, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Connection to GPRS with P/Invoke
    ... Do you know how to close the GPRS connection ... public uint dwParams; ... private static extern int ConnMgrMapURL(string pwszURL, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Connection to GPRS with P/Invoke
    ... IntPtr phConnection = IntPtr.Zero; ... public uint dwParams; ... private static extern int ConnMgrMapURL(string pwszURL, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Manipulating win32 app menus from c# using pinvoke...
    ... supplying the fMask of the MENUITEMINFO with the MF_OWNERDRAW constant from ... public uint cbSize; ... public IntPtr hbmpChecked; ... private static extern IntPtr GetSubMenu ...
    (microsoft.public.dotnet.languages.csharp)