Persistent Registry and RegFlushKey Questions

B

bbomer

I have a CE device that supports persistent registry. The device
documentation says "To save the registry you must call the Standard
Windows CE API function RegFlushKey(HKEY_LOCAL_MACHINE);"

This is what I have as far as some generic code right now:

[DllImport("coredll.dll", EntryPoint="RegFlushKey", SetLastError=true)]

private static extern uint RegFlushKey(uint hKey);

private void button1_Click(object sender, System.EventArgs e)
{
try
{
long test = RegFlushKey(0x80000002);
System.Diagnostics.Debug.WriteLine(test);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex,"ERROR");
}
}

What does "RegFlushKey" actually do? I have run this code and it
returns "0" which I assume means that it completed without error.
However it doesn't seem to do anything as the registry is restored to
the original upon reboot.

The device documentation mentions a "CEREG.BIN" file, but I can't find
that anywhere. I have built the CE image using platform builder, do I
need to do something there to enable persistent registry?

Note: device is a Kontron MOPSlcd7 Pentium III based PC/104
 
D

Daniel Moth

Contact your device vendor and confirm that they support regflushkey. A big
clue that it works (other than observing changes you made before calling it
being there after a reset) is the time it takes to return. At least on our
unit, if you have changed a big number of keys/values and then call it you
get a noticeable 1-3 second delay.

Cheers
Daniel
 
P

Paul G. Tobey [eMVP]

Well, what it does actually depends on *how* the OEM implemented the
persistent registry. There are two basic ways: hive-based and OEM-based.
For the OEM-based case, which is the way everything worked back in the CE
3.0 days, your call to RegFlushKey() calls a function set up by the OEM
during the boot process. When that function returns the whole registry has
been written to wherever the OEM keeps it. The function would be set up in
OEMInit(), if you can look at the OEM's implementation of that and see if
they are setting pWriteRegistryToOEM somewhere (it's a function pointer).
Note that, in this case, the OEM also has to set pReadRegistryFromOEM in
order to get the registry read at startup.

In the hive-based case, the OS itself decides whether anything in the
registry has changed or not when you call RegFlushKey() and sends the
changes to the hive, which is stored somewhere in the filesystem. There are
numerous settings that you have to make to cause hive-based registry to
work.

You should probably read the Platform Builder documentation on the subject,
search in microsoft.public.windowsce.platbuilder, etc. This question has
nothing to do with .NET CF, obviously.

Paul T.
 
M

manjushri

i am working on win ce. i am succeeded in basic win ce image.but unable to
save settings.i have used hive based registry.plz help me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top