Mobile device communication on Windows CE using the Remote Application Programming Interface - RAPI
Abstract
This paper introduces essential information on application development in Windows CE and explains about a sample project done on Windows CE. It also covers communication from the device DB to a Windows Desktop Application. The Project was developed using VC++ Toolkit for Windows CE because of its support for cross-platform compilers.
The part of the Application that is going to run in HPC on Windows CE was developed in two versions - one using pure SDK function to reduce the Memory footprint and Execution speed in the mobile device, and other using MFC as a Rapid Application Developing Kit. Both use the local database provided by the Object store of windows CE.
The other module that resides on the Desktop, will communicate with the DeviceDB using a set of Remote application programming interfaces (RAPIs). These RAPIs allow the desktop application to invoke functions directly on the remote Windows CE-based device. Windows CE provides one-way remote API (RAPI), in which the Windows CE-based device is the RAPI server, and the desktop computer is the RAPI client.


Introduction to Windows CE
Windows CE is a 32 bit Operating System for mobile devices, and is widely used in HPC and Palm PC. Its main advantage is that it supports a large subset of Windows API that is familiar to application Programmers. It is also used to develop applications rapidly because of its support for Microsoft Foundation Classes (MFC), ActiveX, and ATL.
It provides native Support for Unicode, which makes it easy to process and display text from a variety of languages. It also supports the P32 Executable format. It can communicate with any other device using Serial Port or IrDA port and network. It provides classes for socket communication and enables the writing of programs using TCP/IP & UDP.
Windows CE has two types of memory - RAM & ROM. There are no mass storage devices like hard disks. The ROM is where the operating system resides with other standard applications, to reduce the usage of precious RAM. The RAM is divided into two sections:
- Programming Memory
- Object Store
The amount of memory earmarked for program memory and object store can be manually adjusted by the device user. All the applications that we develop are generally stored in the object store and loaded into the program memory during execution. This memory is made persistent with the usage of backup batteries.
DataBase In Windows CE
The Windows CE data model is a small, flat structure, optimized for efficient storage. Data Operations are transactional i.e. if a Windows CE based device looses power during any data transaction, Windows CE reverts all partial database operation to the "last known good state", thus protecting against data loss. Windows CE supports a set of API for accessing the database. For each function, there is a corresponding RAPI call.
Database Model
Each Windows CE database contains a maximum of CEDB_MAXSORTORDER, sort indices, and one or more records. The Maximum Size of the record is defined in the CEDB_MAXRECORDSIZE, a constant in windbase.h or Rapi.h. The record can have a variable no of properties equivalent to rows and columns in the normal database, but it cannot contain another record.
From Windows CE 3.0, the database can be stored in volumes other than Object Store. In prior versions, the database can be stored only in the object store and its maximum capacity varies depending on the version - it can be obtained from the CEDB_MAXNUMRECORDS constant.
Hierarchy Of Windows CE Database

Database
Each Database can have one or more records of varying size. The Database is identified by its OID (Object Identifier). The Database is created using the CeCreateDatabase call. During creation, the Database can take "n" no. of sorting orders. The database creates an index on these fields and the user can search through any of these. The Database can be mounted or unmounted after the use. It can also be deleted using CeDeleteDatabase.
Records
Each Record contains more than one property. They can be identified by OID or the index in the sorting order. They can be made read or write using CeWriteRecordProps and CeReadRecordProps. CeDeleteRecord is used to delete a Record from a Database. The Output of the CeSeekDatabase can be used to identify the single record.
Remote application Programming Interface
API are a special set of API's provided by Windows CE, using which a desktop application can communicate directly with the device. Each RAPI is a RemoteProcedureCall (RPC) in which the desktop application acts as a client and the Windows CE in the mobile device is the server.
The four main functionalities provided by RAPI are
- Application calls
- Database calls
- File Operation calls
- Registry Operation calls
Application Calls
These are used to invoke the functions and Applications residing in the Mobile device.
CeCreateProcess
This function creates a new process that runs a specified executable file residing on the Windows CE platform.
CeRapiInvoke
This function remotely executes a function residing on the Windows CE platform, and provides for both input parameters and output data
Database Calls
These are used to make calls to the device database, and are more or less similar in syntax to the ordinary database calls. Some of the RAPI versions of the database calls are CeCreateDatabase, CeSeekDatabase, CeDeleteDatabase, CeWriteRecordProps, CeReadRecordProps, CeDeleteRecord.
File Operation Calls
The following table shows the some of the RAPI file management functions.
CeCopyFile
CeMoveFile
CeCreateFile
CeDeleteFile
CeReadFile
CeGetFileSize
CeWriteFile
CeCloseHandle
About The Project
Sample Windows CE Application Program (Mobile Device Module)
The Project under consideration is the simulation of the Census in a paperless world.
The first part of the project is the program residing in the mobile device. This will obtain the data about the families in the field, and add them to the device database. Further the field person can edit the details of a family previously entered, and can sort them in any specific order. Proper Error handling is done on unexpected failures like Memory Overflow. This Windows CE part is provided in two versions - one using MFC and other using SDK alone.
Communication through Windows CE Services Desktop - Mobile device Communication
The Second part running in the desktop communicates with the mobile device. It extracts all the data entered on that day by the field person, and adds them to the central Database mounted on the desktop. Further, the user can edit the details of the families, add new members (and complaints, if any), and can delete the details. He can also delete the entire contents of the database in the mobile device.
Comparison between SDK & MFC versions
The Windows CE part of this project is available in two versions - one in SDK and other in MFC. The SDK version occupies less memory in the object store and takes little more time to develop. The MFC version occupies more space and it is easy and fast to develop an application using it. The Memory utilization of both the versions are listed below.
SDK
23.0 KB
2040 - 2300 KB
MFC
45.3 KB
3800 - 4200 KB
The Main Window is designed like the desktop in the Windows Operating System. It consists of two icons that point to two sub-modules of the project. They are as follows:
Sample Windows CE Applicatioin Program (MOBILE DEVICE MODULE)
The Main Window is designed like the desktop in the Windows Operating System. It consists of two icons that point to two sub-modules of the project. They are as follows:
- Creating Family Details
- Editing existing details
Creating Family Details
This Editor is used to add details of all the members of a family in the main database. During the process, the user can alter the previous details, cancel the details of a particular member, or cancel the entire details of the family. A Database is created using CeCreateDatabase with a 3 sort order, which will be utilized later. Each record is added to the list using CeWriteRecordProps at the end while saving. The Newly added Records are marked as Unread. Till then, the data is in the List Box. The flow is as follows.

Editing Existing Details
This Editor is used to view the details about the members of the family, previously added to the database. The user can view the details in any desired sort order. He can also update the details in response to any complaints. For each Sort Order, a new Database handle is opened using CeOpenDatabase with the particular Sort Order. The List Boxes are reset and the contents are filled in the new order. While editing, CeSeekDatabase is used to find the record using the index, and is over written using CeWriteRecordProps. The flow is as follows:

Communication Through Windows CE Services Desktop - Mobile Device Communication
This module consists of the specifically designed CRecordView in which the user can scroll through the master database. The user can add, delete or update the Master Database. The Record View connects to the mobile device using RAPI, through Windows CE Services. It consists of three Main tasks.
- Extract
- Add New
- Delete Device DB
Extract
The Record View connects to the Mobile Device using RAPI. It initializes the connection using RapiInitEx. Then, the Remote Database is opened and Records marked Unread are added to Main Master Database in the Desktop. Simultaneously, the Extracted Records in the Remote Database are marked as read.
Add New
The Record View connects to the Mobile Device using RAPI. It initializes the connection using RapiInitEx. Then, the Remote Database is opened and the Record currently pointed to by the Master Database, is added to the Remote Database.
Clear Device Database
After extracting, the device database is to be cleaned. This function also establishes connection with the remote device and uses CeDeleteRecord to delete all the records.

Conclusion
Using this Windows CE project for the Hand-held PC, one can add or edit census data in the hand held device and later (perhaps at the end of the day) transfer the data to the main PC. This application will come handy to field persons who conduct surveys for various products.
Requirements
- Windows 95/98 2000 or Windows NT 4.0 Or above
- Windows CE version 2.0 or above
- Windows CE Services - Either Active Sync or any other 3rd party tool.

