Download the source code

The RAPI2 library is used by the desktop applications to communicate to the connected Windows CE based devices. The desktop applications can perform actions such as create, edit or delete the file system, database or registry.

This article describes how to enumerate the connected devices and get information such as name, platform, etc… Next part of the series will describe how to manipulate the file system and database.

RAPI2 uses the ActiveSync application to communicate to the connected device. Users should install the ActiveSync in order to work with the RAPI2 library.

IRAPIDesktop
IRAPIDevice
IRAPIEnumDevices
IRAPISession
IRAPISink

IRAPIDesktop serves as the connection point container of all the devices. This interface is used to enumerate the connected devices. This interface has following methods:

HRESULT Advise(IRAPISink* pISink,DWORD* pdwContext);
HRESULT EnumDevices(IRAPIEnumDevices** ppIEnum);
HRESULT FindDevices(RAPIDEVICEID *pDeviceID,RAPI_GETDEVICEOPCODE opFlags,IRAPIDevice** ppIDevice);
HRESULT UnAdvise(DWORD dwContext);

The Advice method is used to register the IRAPISink interface to receive the device notifications. The pISink parameter is a pointer to an interface that implements the IRAPISink. The IRAPISink has two methods:

HRESULT OnDeviceConnected(IRAPIDevice* pIDevice);
HRESULT OnDeviceDisconnected(IRAPIDevice* pIDevice);

The OnDeviceConnected will be called when a device is connected and OnDeviceDisconnected will be called when a device is disconnected. Both methods has one argument. This is a pointer to the IRAPIDevice interface which represents the device connected or disconnected.

The EnumDevices method is used to enumerate connected device. This accepts one argument which is pointer to pointer to IRAPIEnumDevices interface. We can use this IRAPIEnumDevices interface to start enumerating the devices.

The FindDevices is used to find a particular device. The function accepts a Device ID and a RAPI_GETDEVICEOPCODE enumeration which will always be RAPI_GETDEVICE_NONBLOCKING. The third parameter is an out parameter which will be filled with IRAPIDevice interface.

The UnAdvise is used to cancel the already registered device notification.

The sample is a simple application that lists all the devices connected to the system. The application registers for the device notification and enumerate already connected devices. When a device is connected or disconnected the application add or delete the device from the connected device list.

In the next part, I will try to explain how to manipulate the file system and databases of the connected device.