QA: How do I connect my Pocket PC to the Internet?

Joao Paulo Figueira (joao.fig@mail.telepac.pt), July 19, 2003.

Question

I want to start a connection to the Internet from within my application. How do I do this?

Answer

For the Pocket PC 2002 there is one recommended solution: use the Connection Manager API. While you could do this using RAS, the Connection Manager is far more flexible and determines what is the best network for connecting to the Internet. For instance, if your Pocket PC is on the cradle and the PC is connected to the Internet, there is no way you can have your Pocket PC access the Internet using RAS. Through the Connection Manager API, it is possible.

Ok, but how do I use that API? It looks very complex...

You don't have to learn how to use the Connection Manager API, because Microsoft has already provided help. In the Pocket PC 2002 SDK there is a sample project (under MFC) named CMHELPER. This project consists of a very simple dialog-based MFC application that allows you to:

These functionalities are encapsulated in the CConnection class, through the IsAvailable, AttemptConnect and HangupConnection methods.

The IsAvailable method takes as parameters the URL string and and a boolean stating if you are going through a proxy or not. The method returns a HRESULT with the following possible values:

So, this is the method to use before attempting to establish a connection. To connect, you call AttemptConnect, using the same parameters. The method, as its name implies, attempts to connect to the URL and notifies you of its progress. This is done by calling a number of virtual methods, one for each connection status. These methods are:

You intercept these methods by deriving a class from CConnection, and overriding the methods corresponding to the states you want to be notified about. Note: these methods are called from within a thread that exists for the lifetime of your conection, so take every precaution when writing these, especially in what concerns thread synchronization issues.

Finally, when the connection is no longer needed, you call HangupConnection(). This method signals the thread to stop, closing the open connection.

So, with a little help from Microsoft, making connections to the Internet is as simple as this.

Related resources: