Download the source code

Windows Mobile 5 introduce the GPS Intermediate Driver. As the name implies, it is an intermediate driver between client application and the actual GPS device. The client application sees this driver as an actual GPS device. The device sees this driver as a client application. The GPS Intermediate driver interacts with the actual device driver provided with the GPS hardware and gives this data to the application. We can access either the parsed or raw GPS data using this driver.

The parsed data API has 4 functions:

    GPSOpenDevice
    GPSGetPosition
    GPSGetDeviceState
    GPSCloseDevice

GPSOpenDevice opens the device for accessing the data and returns a handle to the device. GPSGetPosition retrieves the parsed data. GPSGetDeviceState retrieves the device information. GPSCloseDevice closes the device. It is important the GPSCloseDevice should be called for each GPSOpenDevice. Whenever we open the device, the driver increment the reference count and when we close the device the reference count is decremented. When the device is no longer used by any client application, the device is closed. So it very important to close the device after use, otherwise it will stay opened and lot of power will be consumed. The GPS hardware is one of the components that use lot of power.

To receive the raw data, application uses CreateFile to open the device, ReadFile to read the raw data and CloseHandle to the close the device. The filename parameter of the CreateFile will be the COM port. This COM port is configured in the registry key HKEY_LOCAL_MACHINESystemCurrentControlSetGPS Intermediate DriverDrivers. Under this key there will an entry CurrentDriver. The value of this key will be a subkey of the above registry key. For example if the current GPS driver is “GPSOneDevice” then the key will be HKEY_LOCAL_MACHINESystemCurrentControlSetGPS Intermediate DriverDriversGPSOneDevice. Under this key, the entry “InterfaceType” and “CommPort” determines the COM port and the type. If CommPort entry has the value COM4, the filename for the CreateFile will be “$deviceCOM4:”. The ReadFile returns the string data in the NMEA format. For more information, visit this NMEA Web Site.

The syntax of the GPSOpenDevice function is
HANDLE GPSOpenDevice(HANDLE hNewLocationData,HANDLE hDeviceStateChange,const WCHAR szDeviceName,DWORD dwFlags);. The first and second parameters are handle to and event object created by CreateEvent API. The event hNewLocationData will be set when the location data is available and the hDeviceStateChange event will be set when the device state is changed. we can use WaitForMultipleObject for wait for the events. Whenever an event occurs we could retrieve the GPS position or device information. This gives us very convenient way to read the data from the device.

The sample application created here is a simple dialog based application. The Longitude, Latitude, Speed and Satellite count is displayed. The application will also display the device information if available. The application is created by Visual Studio 2008. The application creates a thread when the device is started and waits for any event occurs. Whenever the event occurs the main application will be notified about the event. When the main application is notified the data is displayed on the screen.