Click here to Skip to main content
13,355,335 members (73,648 online)
Click here to Skip to main content
Add your own
alternative version


37 bookmarked
Posted 24 Sep 2008

Managed Wrapper to Connection Manager and How to Bypass the Connection Planner

, 24 Sep 2008
Rate this:
Please Sign up or sign in to vote.
This article explains how we can bypass the Connection Planner and establish a connection using the Connection Manager APIs on Windows Mobile devices.


This article explains how we can bypass the Connection Planner and establish a connection using the Connection Manager APIs on Windows Mobile devices. A new application block Connection Manager is created which contains a wrapper to the Connection Manager native APIs on Windows Mobile devices. Also, the ConnectionMonitor application block, provided by the Microsoft Patterns & Practices group, is enhanced to retrieve all the connections available on the device.

What is the Connection Manager in Windows Mobile?

Connection Manager, which you can implement by using the Connection Manager API, centralizes and automates the establishment and management of various types of network connections for applications that connect to the Internet or to the corporate network from Windows Mobile devices. When one or more applications request a connection, the Connection Manager establishes a connection using an optimal connection type, and notifies all the applications that the connection is active. Applications are configured to specify a connection name and a network name.

The Connection Manager tracks which connections are in use or are requested by applications. It closes unused connections, automatically disconnects connections when they are idle for a specified period of time, and closes low-priority connections to open high-priority connections. For example, voice connections are typically given a higher priority than data connections.

The Connection Manager handles many different types of connections, including Point-to-Point Protocol (PPP), Remote Access Service (RAS), and Point-to-Point Tunneling Protocol (PPTP) connections. The Connection Manager can also configure proxy server settings to allow network resources through a firewall or a Wireless Application Protocol (WAP) gateway.


Fig. Connection Manager Architecture

Connection Monitor Application Block

This application block is provided by the Microsoft Patterns & Practices group. This application block allows your application to retrieve connectivity information from a mobile device and monitor connectivity status changes.

Connection Manager Functions

The Connection Manager API consists of about 11 functions, but you only need two of these functions to know the connection status.



This function enumerates the available networks.


This function returns detailed information about the existing data connections on the Windows Mobile device.

Connection Manager Application Block

This application block provides Managed APIs to establish or release connection from a mobile device. This application block bridges the gap in the managed code which allows the user to manage his connections.

Connection Manager Functions

The Connection Manager API consists of about 11 functions, but you only need six of these functions for the tasks of establishing and releasing a network connection. In many cases, your application may require as few as two of these functions. The following table shows six functions:



Retrieves the network identifier (Internet or Work) for the specified URL.


Selects and establishes the appropriate connection for the specified network identifier. This method returns without waiting for the connection attempt to complete; use ConnMgrConnectionStatus to determine the connection status.


Selects and establishes the appropriate connection for the specified network identifier. This method does not return until the connection attempt completes.


Releases the specified connection, which may also close the connection.


Retrieves the status of the specified connection.


This function maps a connection reference to its corresponding GUID. This function enables you to bypass the Connection Planner by explicitly providing a GUID that will map to the connection.

Using the Code

Display Connection Status

CMConsole is the sample code which shows how a user can use the Connection Monitor and Connection Manager application blocks. This part of the Connection Monitor sample was provided by the Microsoft Patterns & Practices group, and has been enhanced to show how we can use the Connection Manager application block to establish a connection.

public ConsoleForm()
      monitor = ConnectionMonitorFactory.CreateFromConfiguration();
      monitor.ActiveNetworkChanged += NetworkChangeHandler;

The console screen shows the different connections, Cell Connection, NIC Connection, and Desktop connection which are defined in the app.config. ConnectionMonitorFactory.CreateFromConfiguration() returns a ConnectionMonitor object which keeps track of the status of the various connections specified in the configuration file.

The ConnectionMonitorFactory object (monitor) retrieves a list of connections to be monitored from the app.config file. Internally, this object registers for SystemProperty for each of these connections. The ActiveNetworkChanged event indicates any one connection status has been changed so that we can update the connection list.


Fig. Display Connection List

Bypass Connection Planner

In the ConnectionList screen, it is implemented how we can bypass the connection planner in this code sample. It also explains how we can use the Connection Manager application block. ConnectionMonitorNativeHelper.GetConnectionList() retrieves all the available connections on the device. It is displayed in the screen below. We can select a particular connection, say, “MY GPRS Connection”, and select the “Connect” menu in this sample to connect to the selected connection.

Note:- You can create a new GPRS connection on your WM 6.0 device emulator and test it with a Cellular Emulator.


Fig. List of all the available connections on the mobile device
private void mnuConnect_Click(object sender, EventArgs e)
    ConnectionMonitorNativeHelper.CONNMONITOR_CONNECTION_DETAILED_STATUS cnStatus = 
    if (_connectionHandle != IntPtr.Zero)
    ConnMgrReleaseConnection(_connectionHandle, 0);
    _connectionHandle = IntPtr.Zero;
    if (cnStatus.dwConnectionStatus != CONNMONITOR_STATUS_CONNECTED)
    ConnMgrStatus status = ConnMgrStatus.Unknown;
    Guid forceConnGuid = new Guid();
    if (ConnMgrMapConRef(ConnMgrConRefTypeEnum.ConRefType_NAP, 
        cnStatus.pszDescription, ref forceConnGuid) != 0)
                         cnStatus.pszDescription, ref forceConnGuid);

    ConnMgrConnectionInfo info = new ConnMgrConnectionInfo(forceConnGuid, 
    ConnMgrEstablishConnectionSync(info, ref _connectionHandle, 
                                   _syncConnectTimeout, ref status);

    if (status == ConnMgrStatus.Connected)
        MessageBox.Show("Connect Succeeded");
        MessageBox.Show("Connect failed: " + status.ToString());



Fig. After a connection was successfully made


  1. Establishing Network Connectivity with the Windows Mobile Connection Manager
  2. Connection Manager Application Development for Windows Mobile-based Devices
  3. Smart Client Software Factory


This article, along with any associated source code and files, is licensed under A Public Domain dedication


About the Author

Naynesh Shah
Architect Tata Consultancy Services
India India
Naynesh Shah is a senior solution architect working with the Mobile Solutions - Technology Excellency Group of TATA Consultancy Services.

He specializes in architecting enterprise and embedded mobile solutions based on Windows CE and Windows Mobile. He is also involved in helping customers define the mobile middleware adoption strategy.

You may also be interested in...


Comments and Discussions

Bugactive connection / isconnected status bug Pin
Figuerres29-Mar-13 10:57
memberFiguerres29-Mar-13 10:57 
GeneralMy vote of 5 Pin
hjgode29-Sep-10 19:14
memberhjgode29-Sep-10 19:14 
GeneralRe: My vote of 5 Pin
hjgode12-Jun-12 8:43
memberhjgode12-Jun-12 8:43 
Generalchange the link (GPRS->WiFi or WiFi->GPRS) Pin
bsw00617-Mar-10 7:54
memberbsw00617-Mar-10 7:54 
GeneralRe: change the link (GPRS->WiFi or WiFi->GPRS) Pin
Floppe24-May-12 2:40
memberFloppe24-May-12 2:40 
General2 parallel connections Pin
Nandiator25-Nov-09 6:51
memberNandiator25-Nov-09 6:51 
GeneralUse it in NETCF and select correct AP for Request Pin
sir_zealot@go2.pl16-Nov-09 1:35
membersir_zealot@go2.pl16-Nov-09 1:35 
Answergood articl. but the connection cannot be shared with other applications. Pin
E_lwh28-Apr-09 19:09
memberE_lwh28-Apr-09 19:09 
QuestionUnable to Open CMConsole Pin
Member 434273616-Nov-08 23:25
memberMember 434273616-Nov-08 23:25 
AnswerRe: Unable to Open CMConsole Pin
RobstaHendricks22-Mar-10 4:48
memberRobstaHendricks22-Mar-10 4:48 
GeneralThanks for a very interesting article, one comment to help a new user to protect himself for incorrect usage. Pin
Member 460340530-Sep-08 5:40
memberMember 460340530-Sep-08 5:40 
GeneralIt's not possible to bypass the Connection Planner if you are using System.Net.HttpWebRequest Pin
Rodrigo Fernandez29-Sep-08 23:00
memberRodrigo Fernandez29-Sep-08 23:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 24 Sep 2008
Article Copyright 2008 by Naynesh Shah
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid