471,330 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Registry SetValue stores double as REG_SZ

using Microsoft.Win32;
RegistryKey key = Registry.LocalMachine;
key = key.OpenSubKey(".....");
...
key = key.OpenSubKey("PCF", true);
double aDoubleValue = 0.25;
key.SetValue("testkey", aDoubleValue);

testkey pre-existed as a DWORD value and after the setvalue becomes a
REG_SZ type. Even tried casting the aDoubleValue, but no change.

Whats wrong with SetValue?

Thanks in advance.
Chuck

Jul 30 '05 #1
1 5466
Hello Chuck,
testkey pre-existed as a DWORD value and after the setvalue becomes a
REG_SZ type. Even tried casting the aDoubleValue, but no change.


The native types for registry values are strings, binary values and DWORDs
(integers). There is no native type for storing a floating point value. If
you give the SetValue method a double value, it gets converted to a string.
So, the method works as expected.

You should either round or convert the value to an Int32 first, or store it
as a binary value if a string won't do. For example:

--------------------------------
Microsoft.Win32.RegistryKey key =
Registry.CurrentUser.OpenSubKey("Software\\ACME",t rue);
double myValue = 123.45;
key.SetValue("My Value",System.Convert.ToInt32(myValue));
key.Close();

--------------------------------

Hope this helps.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
Jul 31 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Yogi_Bear_79 | last post: by
3 posts views Thread by David Gacek | last post: by
3 posts views Thread by Joe Delphi | last post: by
1 post views Thread by ChuckD_Duncan | last post: by
3 posts views Thread by Aussie Rules | last post: by
9 posts views Thread by Newbie Coder | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.