public object GetValue (RegistryKey rkey, string name, object defaultValue, RegistryValueOptions options)
{
RegistryValueKind type = 0;
int size = 0;
object obj = null;
IntPtr handle = GetHandle (rkey);
int result = RegQueryValueEx (handle, name, IntPtr.Zero, ref type, IntPtr.Zero, ref size);
if (result == Win32ResultCode.FileNotFound || result == Win32ResultCode.MarkedForDeletion) {
return defaultValue;
}
if (result != Win32ResultCode.MoreData && result != Win32ResultCode.Success ) {
GenerateException (result);
}
if (type == RegistryValueKind.String) {
byte[] data;
result = GetBinaryValue (rkey, name, type, out data, size);
obj = RegistryKey.DecodeString (data);
} else if (type == RegistryValueKind.ExpandString) {
byte [] data;
result = GetBinaryValue (rkey, name, type, out data, size);
obj = RegistryKey.DecodeString (data);
if ((options & RegistryValueOptions.DoNotExpandEnvironmentNames) == 0)
obj = Environment.ExpandEnvironmentVariables ((string) obj);
} else if (type == RegistryValueKind.DWord) {
int data = 0;
result = RegQueryValueEx (handle, name, IntPtr.Zero, ref type, ref data, ref size);
obj = data;
} else if (type == RegistryValueKind.Binary) {
byte[] data;
result = GetBinaryValue (rkey, name, type, out data, size);
obj = data;
} else if (type == RegistryValueKind.MultiString) {
obj = null;
byte[] data;
result = GetBinaryValue (rkey, name, type, out data, size);
if (result == Win32ResultCode.Success)
obj = RegistryKey.DecodeString (data).Split ('\0');
} else {
// should never get here
throw new SystemException ();
}
// check result codes again:
if (result != Win32ResultCode.Success)
{
GenerateException (result);
}
return obj;
}