Download the source code

In the part 1 of Using RAPI series, I explained how to enumerate the connected device and get the details. This part of the series explains how to enumerate the database on the device.

When we enumerate the device using IRAPIDesktop::EnumDevices and IRAPIEnumDevices::Next we get a pointer to the IRAPIDevice that represents a particular device. The IRAPIDevice has a method CreateSession which is used to create a session. The syntax of CreateSession is:

HRESULT CreateSession(IRAPISession** ppISession);

This function create an IRAPISession which can be used to perform operations on the connected device. Once the session is created, you should call the CeRapiInit method of the IRAPISession interface. This will initialize the communication to the connected device. It is very important to call this method, otherwise all other methods will fail.

To enumerate all the mounted databases on the device, we can use the methods CeFindFirstDatabaseEx and CeFindNextDatabaseEx of the IRAPISession interface. The CeFindFirstDatabaseEx returns a handle to the enumeration. The CeFindNextDatabaseEx method returns a CEOID which is an identifier of the database. To get the information about the database we can call CeOidGetInfoEx method of the IRAPISession. This will return the information such as name, number of records, database type, etc… CeFindNextDatabaseEx function returns 0 when it is finished with the enumeration.

The sample application presented here lists all databases that are on the device memory and display the name and number of records. The application is created in Visual Studio 2008 using MFC. In the next part I will try to explain how to enumerate file system.