Using the Registry
The Windows CE registry stores data about applications, drivers, user preferences, and other configuration settings. For example, the default preferences of a user for Pocket Word are stored in the registry. The registry is organized in a hierarchical system of keys and values. A key is similar to a directory, and can contain values and other keys. Windows CE supports three root keys. The following table shows the three root keys that Windows CE supports, and what type of data you should store under those keys.
|HKEY_LOCAL_MACHINE||Hardware and driver configuration data|
|HKEY_CURRENT_USER||User configuration data|
|HKEY_CLASSES_ROOT||OLE and file-type matching configuration data|
A value is the basic piece of data that is stored in the registry, and it can be a variety of types, including string or binary. Each value has a name and an associated piece of data. For example, a device that is running the Windows CE Handheld PC, Professional Edition, software uses Wrap to Window in the HKEY_LOCAL_MACHINE\Software\Microsoft\Pocket Word\Settings key to store a numeric value.
The following table describes the different limits in the registry.
|Key or value name length||255 characters|
|Data size||4 KB|
|Key hierarchy depth||Up to 16 nested subkeys|
When programming with the registry, try to keep name and data size small. Note that registry values in Windows CE take up less memory than registry keys. Design your registry hierarchy to use as few keys as possible.
The Windows CE registry exports the Win32 registry functions for applications to call to record and access run-time and other data. Use the registry to store data that your application needs for each session. For example, you can save the state of your application during the shutdown process. Upon startup, your application can reinstate the previous settings. The registry is used also for system initialization and is always present in RAM. Effective with version 2.10, the registry can be loaded from, and stored to, another persistent storage device.
Note Windows CE implements the registry as a RAM-based heap file. If the RAM loses power, the registry data can be lost if the OEM has not implemented a registry backup procedure. Windows CE then must reload the initial registry from ROM.