Question

I've got a device running Windows Mobile 5.0. It has a program that creates and deletes the handheld's GPRS connection on the fly whenever it runs.

I'm trying to build a little program that can do something similar. It can be called with a parameter to start the connection, however the connection needs to persist so that the phone can be used afterwards even if my program isn't running.

Using this MSDN article I wrote some code which creates a GPRS connection fine (connection successful) However, it doesn't seem to be the connection the phone can use.

Is there any way I can make the connection available for the device after my program runs? If so, is that device-specific?

const int _syncConnectTimeOut = 60000;

[DllImport("CellCore.dll")]
static extern int ConnMgrMapURL(string url, ref Guid networkGuid, int passZero);
[DllImport("CellCore.dll")]
static extern int ConnMgrEstablishConnection(ConnMgrConnectionInfo connectionInfo, ref IntPtr connectionHandle);
[DllImport("CellCore.dll")]
static extern int ConnMgrEstablishConnectionSync(ConnMgrConnectionInfo connectionInfo, ref IntPtr connectionHandle, uint dwTimeout, ref ConnMgrStatus dwStatus);
[DllImport("CellCore.dll")]
static extern int ConnMgrReleaseConnection(IntPtr connectionHandle, int cache);
[DllImport("CellCore.dll")]
static extern int ConnMgrConnectionStatus(IntPtr connectionHandle, ref ConnMgrStatus status);

public void Start(string name)
{
    string url = "http://internet.com/";
    IntPtr _connectionHandle = IntPtr.Zero;           

    Guid networkGuid = Guid.Empty;
    ConnMgrStatus status = ConnMgrStatus.Unknown;
    ConnMgrMapURL(url, ref networkGuid, 0);
    ConnMgrConnectionInfo info = new ConnMgrConnectionInfo(networkGuid, ConnMgrPriority.HighPriorityBackground);
    ConnMgrEstablishConnectionSync(info, ref _connectionHandle, _syncConnectTimeOut, ref status);

    if (status == ConnMgrStatus.Connected) {
        Debug.WriteLine("Connect Succeeded");
    } else {
        Debug.WriteLine("Connect failed: " + status.ToString());
    }
}

[Flags]
enum ConnMgrParam : int
{
    GuidDestNet = 0x1,
    MaxCost = 0x2,
    MinRcvBw = 0x4,
    MaxConnLatency = 0x8
}

[Flags]
enum ConnMgrProxy : int
{
    NoProxy = 0x0,
    Http = 0x1,
    Wap = 0x2,
    Socks4 = 0x4,
    Socks5 = 0x8
}

enum ConnMgrPriority
{
    UserInteractive = 0x8000,
    HighPriorityBackground = 0x0200,
    LowPriorityBackground = 0x0008
}

enum ConnMgrStatus
{
    Unknown = 0x00,
    Connected = 0x10,
    Suspended = 0x11,
    Disconnected = 0x20,
    ConnectionFailed = 0x21,
    ConnectionCanceled = 0x22,
    ConnectionDisabled = 0x23,
    NoPathToDestination = 0x24,
    WaitingForPath = 0x25,
    WaitingForPhone = 0x26,
    PhoneOff = 0x27,
    ExclusiveConflict = 0x28,
    NoResources = 0x29,
    ConnectionLinkFailed = 0x2a,
    AuthenticationFailed = 0x2b,
    NoPathWithProperty = 0x2c,
    WaitingConnection = 0x40,
    WaitingForResource = 0x41,
    WaitingForNetwork = 0x42,
    WaitingDisconnection = 0x80,
    WaitingConnectionAbort = 0x81
}

[StructLayout(LayoutKind.Sequential)]
class ConnMgrConnectionInfo
{
    Int32 cbSize;                          // DWORD
    public ConnMgrParam dwParams = 0;      // DWORD
    public ConnMgrProxy dwFlags = 0;       // DWORD
    public ConnMgrPriority dwPriority = 0; // DWORD
    public Int32 bExclusive = 0;           // BOOL
    public Int32 bDisabled = 0;            // BOOL
    public Guid guidDestNet = Guid.Empty;  // GUID
    public IntPtr hWnd = IntPtr.Zero;      // HWND
    public UInt32 uMsg = 0;                // UINT
    public Int32 lParam = 0;               // LPARAM
    public UInt32 ulMaxCost = 0;           // ULONG
    public UInt32 ulMinRcvBw = 0;          // ULONG
    public UInt32 ulMaxConnLatency = 0;    // ULONG 

    public ConnMgrConnectionInfo()
    {
        cbSize = Marshal.SizeOf(typeof(ConnMgrConnectionInfo));
    }

    public ConnMgrConnectionInfo(Guid destination, ConnMgrPriority priority, ConnMgrProxy proxy)
        : this()
    {
        guidDestNet = destination;
        dwParams = ConnMgrParam.GuidDestNet;
        dwPriority = priority;
        dwFlags = proxy;
    }

    public ConnMgrConnectionInfo(Guid destination, ConnMgrPriority priority)
        : this(destination, priority, ConnMgrProxy.NoProxy) { }

    public ConnMgrConnectionInfo(Guid destination)
        : this(destination, ConnMgrPriority.UserInteractive) { }
}
Was it helpful?

Solution 3

Josef got me started on the right path. I found this answer and subsequent links that explained how to use OMA client provisioning to change device configuration and ultimately allow me to create a GPRS connection.

http://msdn.microsoft.com/en-us/bb737297

Code:

/// <summary>
/// Creates a GPRS Connection with the specified name.
/// </summary>
/// <param name="name">The name of the connection to create.</param>
public void Start(string name)
{
    string xml = "<wap-provisioningdoc>" +
                     "<characteristic type=\"CM_GPRSEntries\">" +
                         "<characteristic type=\"" + name + "\">" +
                            "<parm name=\"DestId\" value=\"{436EF144-B4FB-4863-A041-8F905A62C572}\" />" +
                            "<parm name=\"UserName\" value=\"\" />" +
                            "<parm name=\"Password\" value=\"\" />" +
                            "<parm name=\"Domain\" value=\"\" />" +
                            "<characteristic type=\"DevSpecificCellular\">" +
                                "<parm name=\"GPRSInfoValid\" value=\"1\" />" +
                                "<parm name=\"GPRSInfoAccessPointName\" value=\"internet.com\" />" +
                            "</characteristic>" +
                        "</characteristic>" +
                    "</characteristic>" +
                "</wap-provisioningdoc>";

        XmlDocument configDoc = new XmlDocument();
        configDoc.LoadXml(xml);

        XmlDocument result = ConfigurationManager.ProcessConfiguration(configDoc, true);
    }

OTHER TIPS

I don't have any GPRS devices, but it could be as simple as Closing the handles and Releasing resources you have opened.

See this similar question: Closing GPRS Connections On Windows Mobile

Tor create or delete a connection use dmprocessconfig with a wap provisioning xml file. msdn has examples for this

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top