G
Guest
Hello
I have a Windows CE application written in C# and I need to save the registry.
I use RegistryKey.SetValue(..) to set the register values, however they are
lost after a cold boot unless they are saved.
The target has a HIVE based registry, so the RegSaveKey
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcemain4/html/cmrefRegSaveKey.asp)
method appears to be the right choise for this purpose.
I am however not very familiar with Win32 programming, and don't know how to
use this function in my managed C# application. Could someone please provide
an example of how to use this function in C#?
The method definition could perhaps be something like:
[DllImport("advapi32.dll", EntryPoint = "RegSaveKey")]
public static extern int RegSaveKeyA(int hKey, string lpFile, ref
SECURITY_ATTRIBUTES lpSecurityAttributes);
Now how can 'hKey' which is a "handle to the key where the save operation is
to begin" be defined? What must be done with a RegistryKey to achive this?
And how can 'lpFile' be defined? Is this simply the registry name?
The MSDN documentation finally says that 'lpSecurityAttributes' must be null.
Is it required to define a struct SECURITY_ATTRIBUTES for instance like this:
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public int bInheritHandle;
}
in order to make a proper extern method definition as above, and then pass
'null' when the function is called?
I have a Windows CE application written in C# and I need to save the registry.
I use RegistryKey.SetValue(..) to set the register values, however they are
lost after a cold boot unless they are saved.
The target has a HIVE based registry, so the RegSaveKey
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcemain4/html/cmrefRegSaveKey.asp)
method appears to be the right choise for this purpose.
I am however not very familiar with Win32 programming, and don't know how to
use this function in my managed C# application. Could someone please provide
an example of how to use this function in C#?
The method definition could perhaps be something like:
[DllImport("advapi32.dll", EntryPoint = "RegSaveKey")]
public static extern int RegSaveKeyA(int hKey, string lpFile, ref
SECURITY_ATTRIBUTES lpSecurityAttributes);
Now how can 'hKey' which is a "handle to the key where the save operation is
to begin" be defined? What must be done with a RegistryKey to achive this?
And how can 'lpFile' be defined? Is this simply the registry name?
The MSDN documentation finally says that 'lpSecurityAttributes' must be null.
Is it required to define a struct SECURITY_ATTRIBUTES for instance like this:
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public int bInheritHandle;
}
in order to make a proper extern method definition as above, and then pass
'null' when the function is called?