News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

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

By Joao Paulo Figueira, July 19, 2003.
Print version

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:

  • Check if there is a quick way to connect to a URL.
  • Request the connection to the URL.
  • Disconnect.

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:

  • S_OK: You can quickly connect to the URL.
  • S_FALSE: There is no fast connection to the URL.
  • E_FAIL: You cannot connect to the URL.

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:

  • HRESULT DoConnectingError(): The connection failed.
  • HRESULT DoEstablishingConnection(): Starting to establish the connection.
  • HRESULT DoConnected(): The connection was established.
  • HRESULT DoDisconnected(): Disconnected from the Internet.
  • HRESULT DoWaitingForConnection(): Waiting for the connection to establish.
  • HRESULT DoReleaseConnection(): The connection is being released (closed).

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:

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House