How To Use a Specific Connection using ConnectionMgr
Previous Topic  Next Topic 

Problem:        How To Use a Specific Connection using ConnectionMgr


Solution:        An improvement to the ConnectionMgr extension for Windows Mobile allows you to find the available connections on a device, and select which connection to use, instead of just taking the default as selected by the system.


The ConnectionMgr extension for Windows Mobile is used to request that the system initiates a network connection, so that a network resource can be used. Sometimes, on devices with multiple types of connections available, you may wish to specify which connection to use, instead of accepting the default connection selected by the system. The new CM_GetConnectionName and CM_ConnectByIndex functions provide this capability.


In order to choose a specific connection, you first need to find out what the available connections are to choose from. To do this, use the CM_GetConnectionName function in a loop until you have found all of the connections. The system stores available connections by name, with a unique index number for each one. Start by requesting the name of the connection with an index of 0, store that name, then increment the index and retrieve the next name, until you have retrieved all available connections. Once you have the list of connections and their indexes, you can initiate the connection using the index of the connection you want to use.


For example (lists all connections in a paragraph control named edConnName):


dim connidx, connname, done

connidx = 0

done = false

while not done

       connname = CM_GetConnectionName( connidx )

       if connname = "" then

               done = true

       else

               edConnName = edConnName &connidx &" - " &connname &chr(10)

               connidx = connidx + 1

       endif

wend


Sample output might look like this:


0 - My Work Network

1 - My ISP

2 - Work

3 - Secure WAP Network

4 - The WAP Network

5 - The Internet


Now, once you have the connection index of the connection you want to use, you can initiate that connection usng CM_ConnectByIndex, like this:


'connect using The Internet

result = CM_ConnectByIndex(5)



Here's a more complete sample that will search all connections for one named "The Internet" and either connect with it or display an error message:


'connect to "The Internet"

dim connidx, connname, done

connidx = 0

done = false

while not done

       connname = CM_GetConnectionName( connidx )

       if connname = "" then Exit While

       if connname = "The Internet" then

               done = true

               Exit While

       else

               connidx = connidx + 1

       endif

wend

if done then

       result = CM_ConnectByIndex(connidx)

else

       MsgBox("The Internet connection not found.")

endif



Keywords:      connection, dialup, WLAN, WWAN, internet


KB ID: 10089 

Updated: 2010-06-21


Satellite Forms KnowledgeBase Online

Satellite Forms Website Home