Windows CE devices may or may not persist the registry when power is removed or through a hard reset. The decision is up to the OEM to implement a way to persist the registry. So your device may lose your registry settings. The good news is that many Windows CE devices do have a way to persist the registry. Microsoft provides two methods for the OEM to implement registry persistence:
1.       Hive based registry – in this method, the Filesys is set up with a non-volatile disk to save the registry. This is probably the only way that is still being implemented on devices today, primarily because it is easy to implement.
2.       WriteRegistryToOEM/ReadRegistryFromOEM – in this method, the OEM implements these two functions in the kernel to save and restore the registry. This method pre-dates the hive based registry that was introduced in Windows CE 4.0.
These provide the OS with a method for saving the registry to non-volatile storage. It is up to you to request that the system persist the registry when needed. Many Windows CE devices use flash memory to persist the registry, and flash memory is relatively slow so automatically persisting can come with a performance hit. The OEM can configure filesys to automatically persist the registry when changes are made, but this may not be set up so don’t rely on it unless you know that it is set up.
Your application should request that the registry be persisted when appropriate by calling RegFlushKey(). RegFlushKey() takes one parameter; a handle to a registry key. It can be passed one of the predefined keys like HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER or the key that was being used to write to the registry. The application should call RegFlushKey() after writing a set of registry values rather than after each write because it is more efficient to call it after writing a set of values.
If your system is using hive based registry, it will persist any registry changes when the system suspends. So if it is important to quickly suspend, then your application must call RegFlushKey() when writing to the registry. If the registry has already been persisted, then the data on disk does not need to be updated when the system suspends. On the other hand, suspending the system is a handy way to persist the registry when using an application, like the control panel applets, that don’t call RegFlushKey().
A handy application to have in your tool bag is a simple application that calls RegFlushKey().  You can use this while editing the registry or setting things up in the Control Panel to save your settings.
Copyright © 2008 – Bruce Eitman
All Rights Reserved